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