RCFProto
 All Classes Functions Typedefs
MethodInvocation.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2013, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 2.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_RCF_METHODINVOCATION_HPP
20 #define INCLUDE_RCF_METHODINVOCATION_HPP
21 
22 #include <string>
23 #include <vector>
24 
25 #include <boost/shared_ptr.hpp>
26 
27 #include <RCF/Filter.hpp>
28 #include <RCF/ByteBuffer.hpp>
29 #include <RCF/Export.hpp>
30 #include <RCF/Exception.hpp>
31 #include <RCF/SerializationProtocol_Base.hpp>
32 #include <RCF/Token.hpp>
33 
34 namespace RCF {
35 
36  class RcfServer;
37  class ClientStub;
38  class StubEntry;
39  typedef boost::shared_ptr<StubEntry> StubEntryPtr;
40  class RcfSession;
41  typedef boost::shared_ptr<RcfSession> RcfSessionPtr;
42  class SerializationProtocolIn;
43  class SerializationProtocolOut;
44 
45  class MethodInvocationResponse;
46  class MethodInvocationRequest;
47 
48  // message types
49  static const int Descriptor_Error = 0;
50  static const int Descriptor_Request = 1;
51  static const int Descriptor_Response = 2;
52  static const int Descriptor_FilteredPayload = 3;
53 
54  void encodeServerError(RcfServer & server, ByteBuffer & byteBuffer, int error);
55  void encodeServerError(RcfServer & server, ByteBuffer & byteBuffer, int error, int arg0, int arg1);
56 
57  class Protobufs;
58 
59  class RemoteCallRequest
60  {
61  public:
62 
63  RemoteCallRequest(const MethodInvocationRequest & req);
64 
65  std::string mServantBindingName;
66  std::string mInterfaceName;
67  int mFnId;
68  bool mOneway;
69  SerializationProtocol mSerializationProtocol;
70  int mRuntimeVersion;
71  int mArchiveVersion;
72  boost::uint32_t mPingBackIntervalMs;
73  bool mUseNativeWstringSerialization;
74  bool mEnableSfPointerTracking;
75 
76  };
77 
78  class RCF_EXPORT MethodInvocationRequest : boost::noncopyable
79  {
80  public:
81  MethodInvocationRequest();
82 
83  void init(
84  int runtimeVersion);
85 
86  void init(
87  const MethodInvocationRequest & rhs);
88 
89  void init(
90  const Token & token,
91  const std::string & service,
92  const std::string & subInterface,
93  int fnId,
94  SerializationProtocol serializationProtocol,
95  MarshalingProtocol marshalingProtocol,
96  bool oneway,
97  bool close,
98  int runtimeVersion,
99  bool ignoreRuntimeVersion,
100  boost::uint32_t pingBackIntervalMs,
101  int archiveVersion,
102  bool useNativeWstringSerialization,
103  bool enableSfPointerTracking);
104 
105  Token getToken() const;
106  const std::string & getSubInterface() const;
107  int getFnId() const;
108  bool getOneway() const;
109  bool getClose() const;
110  const std::string & getService() const;
111  void setService(const std::string &service);
112  int getPingBackIntervalMs();
113 
114  ByteBuffer encodeRequestHeader();
115 
116  void encodeRequest(
117  const std::vector<ByteBuffer> & buffers,
118  std::vector<ByteBuffer> & message,
119  const std::vector<FilterPtr> & filters);
120 
121  bool decodeRequest(
122  const ByteBuffer & message,
123  ByteBuffer & messageBody,
124  RcfSessionPtr rcfSessionPtr,
125  RcfServer & rcfServer);
126 
127  bool encodeResponse(
128  const RemoteException * pRe,
129  ByteBuffer & buffer,
130  bool enableSfPointerTracking);
131 
132  void decodeResponse(
133  const ByteBuffer & message,
134  ByteBuffer & buffer,
135  MethodInvocationResponse & response,
136  const std::vector<FilterPtr> & filters);
137 
138  StubEntryPtr locateStubEntryPtr(
139  RcfServer & rcfServer);
140 
141  private:
142 
143  friend class RcfSession;
144  friend class ClientStub;
145  friend class RemoteCallRequest;
146 
147  void decodeFromMessage(
148  const ByteBuffer & message,
149  ByteBuffer & buffer,
150  RcfServer * pRcfServer,
151  RcfSessionPtr rcfSessionPtr,
152  const std::vector<FilterPtr> & existingFilters);
153 
154  void encodeToMessage(
155  std::vector<ByteBuffer> & message,
156  const std::vector<ByteBuffer> & buffers,
157  const std::vector<FilterPtr> & filters);
158 
159  Token mToken;
160  std::string mSubInterface;
161  int mFnId;
162  SerializationProtocol mSerializationProtocol;
163  MarshalingProtocol mMarshalingProtocol;
164  bool mOneway;
165  bool mClose;
166  std::string mService;
167  boost::uint32_t mRuntimeVersion;
168  bool mIgnoreRuntimeVersion; // Legacy field, no longer used.
169  int mPingBackIntervalMs;
170  boost::uint32_t mArchiveVersion;
171  ByteBuffer mRequestUserData;
172  ByteBuffer mResponseUserData;
173  bool mUseNativeWstringSerialization;
174  bool mEnableSfPointerTracking;
175  ByteBuffer mOutOfBandRequest;
176  ByteBuffer mOutOfBandResponse;
177 
178  boost::shared_ptr<std::vector<char> > mVecPtr;
179 
180 
181  friend RCF::MemOstream& operator<<(RCF::MemOstream& os, const MethodInvocationRequest& r)
182  {
183  os
184  << NAMEVALUE(r.mToken)
185  << NAMEVALUE(r.mSubInterface)
186  << NAMEVALUE(r.mFnId)
187  << NAMEVALUE(r.mSerializationProtocol)
188  << NAMEVALUE(r.mMarshalingProtocol)
189  << NAMEVALUE(r.mOneway)
190  << NAMEVALUE(r.mClose)
191  << NAMEVALUE(r.mService)
192  << NAMEVALUE(r.mRuntimeVersion)
193  << NAMEVALUE(r.mPingBackIntervalMs)
194  << NAMEVALUE(r.mArchiveVersion);
195 
196  return os;
197  }
198  };
199 
200  class RCF_EXPORT MethodInvocationResponse
201  {
202  public:
203  MethodInvocationResponse();
204 
205  bool isException() const;
206  bool isError() const;
207  int getError() const;
208  int getArg0() const;
209  int getArg1() const;
210  bool getEnableSfPointerTracking() const;
211 
212  std::auto_ptr<RemoteException> getExceptionPtr();
213 
214  private:
215  friend class MethodInvocationRequest;
216 
217 
218  typedef std::auto_ptr<RemoteException> RemoteExceptionPtr;
219 
220  bool mException;
221  RemoteExceptionPtr mExceptionPtr;
222  bool mError;
223  int mErrorCode;
224  int mArg0;
225  int mArg1;
226  bool mEnableSfPointerTracking;
227 
228  friend RCF::MemOstream& operator<<(RCF::MemOstream& os, const MethodInvocationResponse& r)
229  {
230  os << NAMEVALUE(r.mException);
231  if (r.mExceptionPtr.get())
232  {
233  os << NAMEVALUE(*r.mExceptionPtr);
234  }
235 
236  os << NAMEVALUE(r.mError);
237  if (r.mError)
238  {
239  os << NAMEVALUE(r.mErrorCode);
240  os << NAMEVALUE(r.mArg0);
241  os << NAMEVALUE(r.mArg1);
242  }
243 
244  return os;
245  }
246  };
247 
248  // Out of band messages
249 
250  enum OobMessageType
251  {
252  Omt_RequestTransportFilters = 1,
253  Omt_CreateCallbackConnection = 2,
254  Omt_RequestSubscription = 3
255  };
256 
257  class OobMessage;
258  typedef boost::shared_ptr<OobMessage> OobMessagePtr;
259  typedef boost::shared_ptr< std::vector<char> > VecPtr;
260 
261  class RCF_EXPORT OobMessage
262  {
263  public:
264 
265  OobMessage(int runtimeVersion);
266  virtual ~OobMessage();
267 
268  virtual OobMessageType getMessageType() = 0;
269 
270  virtual void encodeRequest(ByteBuffer & buffer) = 0;
271  virtual void decodeRequest(const ByteBuffer & buffer, std::size_t & pos) = 0;
272 
273  virtual void encodeResponse(ByteBuffer & buffer);
274  virtual void decodeResponse(const ByteBuffer & buffer);
275 
276  protected:
277  void encodeRequestCommon(VecPtr vecPtr, std::size_t & pos);
278 
279  public:
280  static OobMessagePtr decodeRequestCommon(const ByteBuffer & buffer);
281 
282  protected:
283  void encodeResponseCommon(VecPtr vecPtr, std::size_t & pos);
284  void decodeResponseCommon(const ByteBuffer & buffer, std::size_t & pos);
285 
286  int mRuntimeVersion;
287 
288  public:
289 
290  // Common return values.
291  boost::uint32_t mResponseError;
292  std::string mResponseErrorString;
293  };
294 
295  class RCF_EXPORT OobRequestTransportFilters : public OobMessage
296  {
297  public:
298  OobRequestTransportFilters(int runtimeVersion);
299 
300  OobRequestTransportFilters(
301  int runtimeVersion,
302  const std::vector<FilterPtr> &filters);
303 
304  virtual OobMessageType getMessageType();
305  virtual void encodeRequest(ByteBuffer & buffer);
306  virtual void decodeRequest(const ByteBuffer & buffer, std::size_t & pos);
307 
308  std::vector<boost::int32_t> mFilterIds;
309  };
310 
311  class RCF_EXPORT OobCreateCallbackConnection : public OobMessage
312  {
313  public:
314  OobCreateCallbackConnection(int runtimeVersion);
315 
316  virtual OobMessageType getMessageType();
317  virtual void encodeRequest(ByteBuffer & buffer);
318  virtual void decodeRequest(const ByteBuffer & buffer, std::size_t & pos);
319  };
320 
321  class RCF_EXPORT OobRequestSubscription : public OobMessage
322  {
323  public:
324  OobRequestSubscription(int runtimeVersion);
325 
326  OobRequestSubscription(
327  int runtimeVersion,
328  const std::string & publisherName,
329  boost::uint32_t subToPubPingIntervalMs);
330 
331  virtual OobMessageType getMessageType();
332  virtual void encodeRequest(ByteBuffer & buffer);
333  virtual void decodeRequest(const ByteBuffer & buffer, std::size_t & pos);
334  virtual void encodeResponse(ByteBuffer & buffer);
335  virtual void decodeResponse(const ByteBuffer & buffer);
336 
337 
338  std::string mPublisherName;
339  boost::uint32_t mSubToPubPingIntervalMs;
340  boost::uint32_t mPubToSubPingIntervalMs;
341  };
342 
343 
344 } // namespace RCF
345 
346 #endif // ! INCLUDE_RCF_METHODINVOCATION_HPP