Remote Call Framework 3.2
MethodInvocation.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2020, 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: 3.2
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 <memory>
26 
27 #include <RCF/ByteBuffer.hpp>
28 #include <RCF/Export.hpp>
29 #include <RCF/Exception.hpp>
30 #include <RCF/SerializationProtocol_Base.hpp>
31 
32 namespace RCF {
33 
34  class RcfServer;
35  class ClientStub;
36  class RcfSession;
37  typedef std::shared_ptr<RcfSession> RcfSessionPtr;
38  class SerializationProtocolIn;
39  class SerializationProtocolOut;
40 
41  class MethodInvocationResponse;
42  class MethodInvocationRequest;
43 
44  class ByteBuffer;
45  class Filter;
46  typedef std::shared_ptr<Filter> FilterPtr;
47 
48  class I_RcfClient;
49  typedef std::shared_ptr<I_RcfClient> RcfClientPtr;
50 
51  // message types
52  static const int Descriptor_Error = 0;
53  static const int Descriptor_Request = 1;
54  static const int Descriptor_Response = 2;
55  static const int Descriptor_FilteredPayload = 3;
56 
57  void encodeServerError(RcfServer & server, ByteBuffer & byteBuffer, int error);
58  void encodeServerError(RcfServer & server, ByteBuffer & byteBuffer, int error, int arg0, int arg1);
59 
60  class Protobufs;
61 
64  {
65  public:
66 
67  RemoteCallInfo(const MethodInvocationRequest & req);
68 
70  std::string mServantBindingName;
71 
73  int mFnId;
74 
76  bool mOneway;
77 
80 
83 
86 
88  std::uint32_t mPingBackIntervalMs;
89 
92  };
93 
94  class RCF_EXPORT MethodInvocationRequest : Noncopyable
95  {
96  public:
97  MethodInvocationRequest();
98 
99  void init(
100  int runtimeVersion);
101 
102  void init(
103  const MethodInvocationRequest & rhs);
104 
105  void init(
106  const std::string & service,
107  int fnId,
108  SerializationProtocol serializationProtocol,
109  bool oneway,
110  bool close,
111  int runtimeVersion,
112  bool ignoreRuntimeVersion,
113  std::uint32_t pingBackIntervalMs,
114  int archiveVersion,
115  bool enableSfPointerTracking,
116  bool enableNativeWstringSerialization);
117 
118  int getFnId() const;
119  bool getOneway() const;
120  bool getClose() const;
121  const std::string & getService() const;
122  void setService(const std::string &service);
123  int getPingBackIntervalMs();
124 
125  ByteBuffer encodeRequestHeader();
126 
127  void encodeRequest(
128  const std::vector<ByteBuffer> & buffers,
129  std::vector<ByteBuffer> & message,
130  const std::vector<FilterPtr> & filters);
131 
132  bool decodeRequest(
133  const ByteBuffer & message,
134  ByteBuffer & messageBody,
135  RcfSessionPtr rcfSessionPtr,
136  RcfServer & rcfServer);
137 
138  bool encodeResponse(
139  const RemoteException * pRe,
140  ByteBuffer & buffer,
141  bool enableSfPointerTracking);
142 
143  void decodeResponse(
144  const ByteBuffer & message,
145  ByteBuffer & buffer,
146  MethodInvocationResponse & response,
147  const std::vector<FilterPtr> & filters);
148 
149  RcfClientPtr locateStubEntryPtr(
150  RcfServer & rcfServer);
151 
152  private:
153 
154  friend class RcfSession;
155  friend class ClientStub;
156  friend class RemoteCallInfo;
157 
158  void decodeFromMessage(
159  const ByteBuffer & message,
160  ByteBuffer & buffer,
161  RcfServer * pRcfServer,
162  RcfSessionPtr rcfSessionPtr,
163  const std::vector<FilterPtr> & existingFilters);
164 
165  void encodeToMessage(
166  std::vector<ByteBuffer> & message,
167  const std::vector<ByteBuffer> & buffers,
168  const std::vector<FilterPtr> & filters);
169 
170  std::string mService;
171  int mFnId;
173  bool mOneway;
174  bool mClose;
175  std::uint32_t mRuntimeVersion;
176  bool mIgnoreRuntimeVersion; // Legacy field, no longer used.
178  std::uint32_t mArchiveVersion;
179  ByteBuffer mRequestUserData;
180  ByteBuffer mResponseUserData;
182  bool mEnableNativeWstringSerialization = false;
183  ByteBuffer mOutOfBandRequest;
184  ByteBuffer mOutOfBandResponse;
185 
186  std::shared_ptr<std::vector<char> > mVecPtr;
187 
188 
189  friend RCF::MemOstream& operator<<(RCF::MemOstream& os, const MethodInvocationRequest& r);
190  };
191 
192  class RCF_EXPORT MethodInvocationResponse
193  {
194  public:
195  MethodInvocationResponse();
196 
197  bool isException() const;
198  bool isError() const;
199  int getError() const;
200  int getArg0() const;
201  int getArg1() const;
202  bool getEnableSfPointerTracking() const;
203 
204  std::unique_ptr<RemoteException> getExceptionPtr();
205 
206  private:
207  friend class MethodInvocationRequest;
208 
209 
210  typedef std::unique_ptr<RemoteException> RemoteExceptionPtr;
211 
212  bool mException;
213  RemoteExceptionPtr mExceptionPtr;
214  bool mError;
215  int mErrorCode;
216  int mArg0;
217  int mArg1;
219 
220  friend RCF::MemOstream& operator<<(RCF::MemOstream& os, const MethodInvocationResponse& r);
221  };
222 
223  // Out of band messages
224 
225  enum OobMessageType
226  {
227  Omt_RequestTransportFilters = 1,
228  Omt_CreateCallbackConnection = 2,
229  Omt_RequestSubscription = 3,
230  Omt_RequestProxyConnection = 4,
231  };
232 
233  class OobMessage;
234  typedef std::shared_ptr<OobMessage> OobMessagePtr;
235  typedef std::shared_ptr< std::vector<char> > VecPtr;
236 
237  class RCF_EXPORT OobMessage
238  {
239  public:
240 
241  OobMessage(int runtimeVersion);
242  virtual ~OobMessage();
243 
244  virtual OobMessageType getMessageType() = 0;
245 
246  virtual void encodeRequest(ByteBuffer & buffer) = 0;
247  virtual void decodeRequest(const ByteBuffer & buffer, std::size_t & pos) = 0;
248 
249  virtual void encodeResponse(ByteBuffer & buffer);
250  virtual void decodeResponse(const ByteBuffer & buffer);
251 
252  protected:
253  void encodeRequestCommon(VecPtr vecPtr, std::size_t & pos);
254 
255  public:
256  static OobMessagePtr decodeRequestCommon(const ByteBuffer & buffer);
257 
258  protected:
259  void encodeResponseCommon(VecPtr vecPtr, std::size_t & pos);
260  void decodeResponseCommon(const ByteBuffer & buffer, std::size_t & pos);
261 
262  int mRuntimeVersion;
263 
264  public:
265 
266  // Common return values.
267  std::uint32_t mResponseError;
268  std::string mResponseErrorString;
269  };
270 
271  class RCF_EXPORT OobRequestTransportFilters : public OobMessage
272  {
273  public:
274  OobRequestTransportFilters(int runtimeVersion);
275 
276  OobRequestTransportFilters(
277  int runtimeVersion,
278  const std::vector<FilterPtr> &filters);
279 
280  virtual OobMessageType getMessageType();
281  virtual void encodeRequest(ByteBuffer & buffer);
282  virtual void decodeRequest(const ByteBuffer & buffer, std::size_t & pos);
283 
284  std::vector<std::int32_t> mFilterIds;
285  };
286 
287  class RCF_EXPORT OobCreateCallbackConnection : public OobMessage
288  {
289  public:
290  OobCreateCallbackConnection(int runtimeVersion);
291 
292  virtual OobMessageType getMessageType();
293  virtual void encodeRequest(ByteBuffer & buffer);
294  virtual void decodeRequest(const ByteBuffer & buffer, std::size_t & pos);
295  };
296 
297  class RCF_EXPORT OobRequestSubscription : public OobMessage
298  {
299  public:
300  OobRequestSubscription(int runtimeVersion);
301 
302  OobRequestSubscription(
303  int runtimeVersion,
304  const std::string & publisherName,
305  std::uint32_t subToPubPingIntervalMs);
306 
307  virtual OobMessageType getMessageType();
308  virtual void encodeRequest(ByteBuffer & buffer);
309  virtual void decodeRequest(const ByteBuffer & buffer, std::size_t & pos);
310  virtual void encodeResponse(ByteBuffer & buffer);
311  virtual void decodeResponse(const ByteBuffer & buffer);
312 
313 
314  std::string mPublisherName;
315  std::uint32_t mSubToPubPingIntervalMs;
316  std::uint32_t mPubToSubPingIntervalMs;
317  };
318 
319  class RCF_EXPORT OobRequestProxyConnection : public OobMessage
320  {
321  public:
322  OobRequestProxyConnection(int runtimeVersion);
323 
324  OobRequestProxyConnection(
325  int runtimeVersion,
326  const std::string & proxyEndpointName);
327 
328  virtual OobMessageType getMessageType();
329  virtual void encodeRequest(ByteBuffer & buffer);
330  virtual void decodeRequest(const ByteBuffer & buffer, std::size_t & pos);
331  virtual void encodeResponse(ByteBuffer & buffer);
332  virtual void decodeResponse(const ByteBuffer & buffer);
333 
334  std::string mProxyEndpointName;
335  };
336 
337 
338 } // namespace RCF
339 
340 #endif // ! INCLUDE_RCF_METHODINVOCATION_HPP
Contains details about the currently executing remote call.
Definition: MethodInvocation.hpp:63
Represents a server side session, associated with a client connection.
Definition: RcfSession.hpp:65
SerializationProtocol mSerializationProtocol
Serialization protocol.
Definition: MethodInvocation.hpp:79
Controls the client side of a RCF connection.
Definition: ClientStub.hpp:83
SerializationProtocol
Describes which serialization implementation to use when serializing data structures for a remote cal...
Definition: Enums.hpp:167
std::uint32_t mPingBackIntervalMs
Pingback interval in ms.
Definition: MethodInvocation.hpp:88
int mFnId
RCF interface method ID.
Definition: MethodInvocation.hpp:73
std::string mServantBindingName
Servant binding name.
Definition: MethodInvocation.hpp:70
Provides RCF server-side functionality.
Definition: RcfServer.hpp:54
bool mEnableSfPointerTracking
Whether SF pointer tracking is enabled for serialization of parameters.
Definition: MethodInvocation.hpp:91
Represents an error that occurs on a RCF server and is transmitted back to the client.
Definition: Exception.hpp:153
Definition: ByteBuffer.hpp:40
int mRuntimeVersion
Runtime version.
Definition: MethodInvocation.hpp:82
Definition: AmiIoHandler.hpp:24
int mArchiveVersion
Archive version.
Definition: MethodInvocation.hpp:85
bool mOneway
True if the call is a oneway call.
Definition: MethodInvocation.hpp:76
RCF_EXPORT bool init(RcfConfigT *=nullptr)
Reference-counted initialization of RCF library. May be called multiple times (see deinit())...