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 
176  boost::shared_ptr<std::vector<char> > mVecPtr;
177 
178 
179  friend std::ostream& operator<<(std::ostream& os, const MethodInvocationRequest& r)
180  {
181  os
182  << NAMEVALUE(r.mToken)
183  << NAMEVALUE(r.mSubInterface)
184  << NAMEVALUE(r.mFnId)
185  << NAMEVALUE(r.mSerializationProtocol)
186  << NAMEVALUE(r.mMarshalingProtocol)
187  << NAMEVALUE(r.mOneway)
188  << NAMEVALUE(r.mClose)
189  << NAMEVALUE(r.mService)
190  << NAMEVALUE(r.mRuntimeVersion)
191  << NAMEVALUE(r.mPingBackIntervalMs)
192  << NAMEVALUE(r.mArchiveVersion);
193 
194  return os;
195  }
196  };
197 
198  class RCF_EXPORT MethodInvocationResponse
199  {
200  public:
201  MethodInvocationResponse();
202 
203  bool isException() const;
204  bool isError() const;
205  int getError() const;
206  int getArg0() const;
207  int getArg1() const;
208  bool getEnableSfPointerTracking() const;
209 
210  std::auto_ptr<RemoteException> getExceptionPtr();
211 
212  private:
213  friend class MethodInvocationRequest;
214 
215 
216  typedef std::auto_ptr<RemoteException> RemoteExceptionPtr;
217 
218  bool mException;
219  RemoteExceptionPtr mExceptionPtr;
220  bool mError;
221  int mErrorCode;
222  int mArg0;
223  int mArg1;
224  bool mEnableSfPointerTracking;
225 
226  friend std::ostream& operator<<(std::ostream& os, const MethodInvocationResponse& r)
227  {
228  os << NAMEVALUE(r.mException);
229  if (r.mExceptionPtr.get())
230  {
231  os << NAMEVALUE(*r.mExceptionPtr);
232  }
233 
234  os << NAMEVALUE(r.mError);
235  if (r.mError)
236  {
237  os << NAMEVALUE(r.mErrorCode);
238  os << NAMEVALUE(r.mArg0);
239  os << NAMEVALUE(r.mArg1);
240  }
241 
242  return os;
243  }
244  };
245 
246 } // namespace RCF
247 
248 #endif // ! INCLUDE_RCF_METHODINVOCATION_HPP