Remote Call Framework 3.2
ServerStub.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_SERVERSTUB_HPP
20 #define INCLUDE_RCF_SERVERSTUB_HPP
21 
22 #include <map>
23 #include <memory>
24 #include <vector>
25 
26 #include <RCF/Config.hpp>
27 #include <RCF/Export.hpp>
28 #include <RCF/RcfClient.hpp>
29 #include <RCF/RcfSession.hpp>
30 #include <RCF/ThreadLibrary.hpp>
31 #include <RCF/Tools.hpp>
32 
33 namespace RCF {
34 
35  class I_RcfClient;
36  typedef std::shared_ptr<I_RcfClient> RcfClientPtr;
37  class RcfSession;
38 
39  class MethodInvocationRequest;
40 
41  class ServerMethodBase
42  {
43  public:
44  virtual void callMethod(int fnId, RcfSession& session) = 0;
45  };
46  typedef std::shared_ptr<ServerMethodBase> ServerMethodPtr;
47 
48  class ClientStub;
49  typedef std::shared_ptr<ClientStub> ClientStubPtr;
50 
51  RCF_EXPORT void setCurrentCallDesc(
52  std::string & desc,
53  RCF::MethodInvocationRequest & request,
54  const char * szFunc,
55  const char * szArity);
56 
57  class RCF_EXPORT StubAccess
58  {
59  public:
60 
61 #ifdef _MSC_VER
62 #pragma warning( push )
63 #pragma warning( disable: 4702 )
64 #endif
65 
66  void logBeginRemoteCall(const std::string& callDesc);
67 
68  template<typename RcfClientT, typename IdT, typename ImplementationT>
69  void callMethod(
70  RcfClientT & rcfClient,
71  const IdT & id,
72  RcfSession & session,
73  ImplementationT & t)
74  {
75  setCurrentCallDesc(
76  session.mCurrentCallDesc,
77  session.mRequest,
78  rcfClient.getFunctionName(id),
79  rcfClient.getArity(id));
80 
81  logBeginRemoteCall(session.mCurrentCallDesc);
82 
83  rcfClient.callMethod(id, session, t);
84  }
85 
86 #ifdef _MSC_VER
87 #pragma warning( pop )
88 #endif
89 
90  };
91 
92  template<typename RcfClientT, typename ImplementationT>
93  inline void callMethod(
94  RcfClientT & rcfClient,
95  ImplementationT & t,
96  int fnId,
97  RcfSession & session)
98  {
99  switch (fnId) {
100  case 0: StubAccess().callMethod(rcfClient, Int< 0>(), session, t); break;
101  case 1: StubAccess().callMethod(rcfClient, Int< 1>(), session, t); break;
102  case 2: StubAccess().callMethod(rcfClient, Int< 2>(), session, t); break;
103  case 3: StubAccess().callMethod(rcfClient, Int< 3>(), session, t); break;
104  case 4: StubAccess().callMethod(rcfClient, Int< 4>(), session, t); break;
105  case 5: StubAccess().callMethod(rcfClient, Int< 5>(), session, t); break;
106  case 6: StubAccess().callMethod(rcfClient, Int< 6>(), session, t); break;
107  case 7: StubAccess().callMethod(rcfClient, Int< 7>(), session, t); break;
108  case 8: StubAccess().callMethod(rcfClient, Int< 8>(), session, t); break;
109  case 9: StubAccess().callMethod(rcfClient, Int< 9>(), session, t); break;
110  case 10: StubAccess().callMethod(rcfClient, Int< 10>(), session, t); break;
111  case 11: StubAccess().callMethod(rcfClient, Int< 11>(), session, t); break;
112  case 12: StubAccess().callMethod(rcfClient, Int< 12>(), session, t); break;
113  case 13: StubAccess().callMethod(rcfClient, Int< 13>(), session, t); break;
114  case 14: StubAccess().callMethod(rcfClient, Int< 14>(), session, t); break;
115  case 15: StubAccess().callMethod(rcfClient, Int< 15>(), session, t); break;
116  case 16: StubAccess().callMethod(rcfClient, Int< 16>(), session, t); break;
117  case 17: StubAccess().callMethod(rcfClient, Int< 17>(), session, t); break;
118  case 18: StubAccess().callMethod(rcfClient, Int< 18>(), session, t); break;
119  case 19: StubAccess().callMethod(rcfClient, Int< 19>(), session, t); break;
120  case 20: StubAccess().callMethod(rcfClient, Int< 20>(), session, t); break;
121  case 21: StubAccess().callMethod(rcfClient, Int< 21>(), session, t); break;
122  case 22: StubAccess().callMethod(rcfClient, Int< 22>(), session, t); break;
123  case 23: StubAccess().callMethod(rcfClient, Int< 23>(), session, t); break;
124  case 24: StubAccess().callMethod(rcfClient, Int< 24>(), session, t); break;
125  case 25: StubAccess().callMethod(rcfClient, Int< 25>(), session, t); break;
126  case 26: StubAccess().callMethod(rcfClient, Int< 26>(), session, t); break;
127  case 27: StubAccess().callMethod(rcfClient, Int< 27>(), session, t); break;
128  case 28: StubAccess().callMethod(rcfClient, Int< 28>(), session, t); break;
129  case 29: StubAccess().callMethod(rcfClient, Int< 29>(), session, t); break;
130  case 30: StubAccess().callMethod(rcfClient, Int< 30>(), session, t); break;
131  case 31: StubAccess().callMethod(rcfClient, Int< 31>(), session, t); break;
132  case 32: StubAccess().callMethod(rcfClient, Int< 32>(), session, t); break;
133  case 33: StubAccess().callMethod(rcfClient, Int< 33>(), session, t); break;
134  case 34: StubAccess().callMethod(rcfClient, Int< 34>(), session, t); break;
135  case 35: StubAccess().callMethod(rcfClient, Int< 35>(), session, t); break;
136  case 36: StubAccess().callMethod(rcfClient, Int< 36>(), session, t); break;
137  case 37: StubAccess().callMethod(rcfClient, Int< 37>(), session, t); break;
138  case 38: StubAccess().callMethod(rcfClient, Int< 38>(), session, t); break;
139  case 39: StubAccess().callMethod(rcfClient, Int< 39>(), session, t); break;
140  case 40: StubAccess().callMethod(rcfClient, Int< 40>(), session, t); break;
141  case 41: StubAccess().callMethod(rcfClient, Int< 41>(), session, t); break;
142  case 42: StubAccess().callMethod(rcfClient, Int< 42>(), session, t); break;
143  case 43: StubAccess().callMethod(rcfClient, Int< 43>(), session, t); break;
144  case 44: StubAccess().callMethod(rcfClient, Int< 44>(), session, t); break;
145  case 45: StubAccess().callMethod(rcfClient, Int< 45>(), session, t); break;
146  case 46: StubAccess().callMethod(rcfClient, Int< 46>(), session, t); break;
147  case 47: StubAccess().callMethod(rcfClient, Int< 47>(), session, t); break;
148  case 48: StubAccess().callMethod(rcfClient, Int< 48>(), session, t); break;
149  case 49: StubAccess().callMethod(rcfClient, Int< 49>(), session, t); break;
150  case 50: StubAccess().callMethod(rcfClient, Int< 50>(), session, t); break;
151  case 51: StubAccess().callMethod(rcfClient, Int< 51>(), session, t); break;
152  case 52: StubAccess().callMethod(rcfClient, Int< 52>(), session, t); break;
153  case 53: StubAccess().callMethod(rcfClient, Int< 53>(), session, t); break;
154  case 54: StubAccess().callMethod(rcfClient, Int< 54>(), session, t); break;
155  case 55: StubAccess().callMethod(rcfClient, Int< 55>(), session, t); break;
156  case 56: StubAccess().callMethod(rcfClient, Int< 56>(), session, t); break;
157  case 57: StubAccess().callMethod(rcfClient, Int< 57>(), session, t); break;
158  case 58: StubAccess().callMethod(rcfClient, Int< 58>(), session, t); break;
159  case 59: StubAccess().callMethod(rcfClient, Int< 59>(), session, t); break;
160  case 60: StubAccess().callMethod(rcfClient, Int< 60>(), session, t); break;
161  case 61: StubAccess().callMethod(rcfClient, Int< 61>(), session, t); break;
162  case 62: StubAccess().callMethod(rcfClient, Int< 62>(), session, t); break;
163  case 63: StubAccess().callMethod(rcfClient, Int< 63>(), session, t); break;
164  case 64: StubAccess().callMethod(rcfClient, Int< 64>(), session, t); break;
165  case 65: StubAccess().callMethod(rcfClient, Int< 65>(), session, t); break;
166  case 66: StubAccess().callMethod(rcfClient, Int< 66>(), session, t); break;
167  case 67: StubAccess().callMethod(rcfClient, Int< 67>(), session, t); break;
168  case 68: StubAccess().callMethod(rcfClient, Int< 68>(), session, t); break;
169  case 69: StubAccess().callMethod(rcfClient, Int< 69>(), session, t); break;
170  case 70: StubAccess().callMethod(rcfClient, Int< 70>(), session, t); break;
171  case 71: StubAccess().callMethod(rcfClient, Int< 71>(), session, t); break;
172  case 72: StubAccess().callMethod(rcfClient, Int< 72>(), session, t); break;
173  case 73: StubAccess().callMethod(rcfClient, Int< 73>(), session, t); break;
174  case 74: StubAccess().callMethod(rcfClient, Int< 74>(), session, t); break;
175  case 75: StubAccess().callMethod(rcfClient, Int< 75>(), session, t); break;
176  case 76: StubAccess().callMethod(rcfClient, Int< 76>(), session, t); break;
177  case 77: StubAccess().callMethod(rcfClient, Int< 77>(), session, t); break;
178  case 78: StubAccess().callMethod(rcfClient, Int< 78>(), session, t); break;
179  case 79: StubAccess().callMethod(rcfClient, Int< 79>(), session, t); break;
180  case 80: StubAccess().callMethod(rcfClient, Int< 80>(), session, t); break;
181  case 81: StubAccess().callMethod(rcfClient, Int< 81>(), session, t); break;
182  case 82: StubAccess().callMethod(rcfClient, Int< 82>(), session, t); break;
183  case 83: StubAccess().callMethod(rcfClient, Int< 83>(), session, t); break;
184  case 84: StubAccess().callMethod(rcfClient, Int< 84>(), session, t); break;
185  case 85: StubAccess().callMethod(rcfClient, Int< 85>(), session, t); break;
186  case 86: StubAccess().callMethod(rcfClient, Int< 86>(), session, t); break;
187  case 87: StubAccess().callMethod(rcfClient, Int< 87>(), session, t); break;
188  case 88: StubAccess().callMethod(rcfClient, Int< 88>(), session, t); break;
189  case 89: StubAccess().callMethod(rcfClient, Int< 89>(), session, t); break;
190  case 90: StubAccess().callMethod(rcfClient, Int< 90>(), session, t); break;
191  case 91: StubAccess().callMethod(rcfClient, Int< 91>(), session, t); break;
192  case 92: StubAccess().callMethod(rcfClient, Int< 92>(), session, t); break;
193  case 93: StubAccess().callMethod(rcfClient, Int< 93>(), session, t); break;
194  case 94: StubAccess().callMethod(rcfClient, Int< 94>(), session, t); break;
195  case 95: StubAccess().callMethod(rcfClient, Int< 95>(), session, t); break;
196  case 96: StubAccess().callMethod(rcfClient, Int< 96>(), session, t); break;
197  case 97: StubAccess().callMethod(rcfClient, Int< 97>(), session, t); break;
198  case 98: StubAccess().callMethod(rcfClient, Int< 98>(), session, t); break;
199  case 99: StubAccess().callMethod(rcfClient, Int< 99>(), session, t); break;
200  case 100: StubAccess().callMethod(rcfClient, Int<100>(), session, t); break;
201  case 101: StubAccess().callMethod(rcfClient, Int<101>(), session, t); break;
202  case 102: StubAccess().callMethod(rcfClient, Int<102>(), session, t); break;
203  case 103: StubAccess().callMethod(rcfClient, Int<103>(), session, t); break;
204  case 104: StubAccess().callMethod(rcfClient, Int<104>(), session, t); break;
205  case 105: StubAccess().callMethod(rcfClient, Int<105>(), session, t); break;
206  case 106: StubAccess().callMethod(rcfClient, Int<106>(), session, t); break;
207  case 107: StubAccess().callMethod(rcfClient, Int<107>(), session, t); break;
208  case 108: StubAccess().callMethod(rcfClient, Int<108>(), session, t); break;
209  case 109: StubAccess().callMethod(rcfClient, Int<109>(), session, t); break;
210  case 110: StubAccess().callMethod(rcfClient, Int<110>(), session, t); break;
211  case 111: StubAccess().callMethod(rcfClient, Int<111>(), session, t); break;
212  case 112: StubAccess().callMethod(rcfClient, Int<112>(), session, t); break;
213  case 113: StubAccess().callMethod(rcfClient, Int<113>(), session, t); break;
214  case 114: StubAccess().callMethod(rcfClient, Int<114>(), session, t); break;
215  case 115: StubAccess().callMethod(rcfClient, Int<115>(), session, t); break;
216  case 116: StubAccess().callMethod(rcfClient, Int<116>(), session, t); break;
217  case 117: StubAccess().callMethod(rcfClient, Int<117>(), session, t); break;
218  case 118: StubAccess().callMethod(rcfClient, Int<118>(), session, t); break;
219  case 119: StubAccess().callMethod(rcfClient, Int<119>(), session, t); break;
220  case 120: StubAccess().callMethod(rcfClient, Int<120>(), session, t); break;
221  case 121: StubAccess().callMethod(rcfClient, Int<121>(), session, t); break;
222  case 122: StubAccess().callMethod(rcfClient, Int<122>(), session, t); break;
223  case 123: StubAccess().callMethod(rcfClient, Int<123>(), session, t); break;
224  case 124: StubAccess().callMethod(rcfClient, Int<124>(), session, t); break;
225  case 125: StubAccess().callMethod(rcfClient, Int<125>(), session, t); break;
226  case 126: StubAccess().callMethod(rcfClient, Int<126>(), session, t); break;
227  case 127: StubAccess().callMethod(rcfClient, Int<127>(), session, t); break;
228  case 128: StubAccess().callMethod(rcfClient, Int<128>(), session, t); break;
229  case 129: StubAccess().callMethod(rcfClient, Int<129>(), session, t); break;
230  case 130: StubAccess().callMethod(rcfClient, Int<130>(), session, t); break;
231  case 131: StubAccess().callMethod(rcfClient, Int<131>(), session, t); break;
232  case 132: StubAccess().callMethod(rcfClient, Int<132>(), session, t); break;
233  case 133: StubAccess().callMethod(rcfClient, Int<133>(), session, t); break;
234  case 134: StubAccess().callMethod(rcfClient, Int<134>(), session, t); break;
235  case 135: StubAccess().callMethod(rcfClient, Int<135>(), session, t); break;
236  case 136: StubAccess().callMethod(rcfClient, Int<136>(), session, t); break;
237  case 137: StubAccess().callMethod(rcfClient, Int<137>(), session, t); break;
238  case 138: StubAccess().callMethod(rcfClient, Int<138>(), session, t); break;
239  case 139: StubAccess().callMethod(rcfClient, Int<139>(), session, t); break;
240  case 140: StubAccess().callMethod(rcfClient, Int<140>(), session, t); break;
241  case 141: StubAccess().callMethod(rcfClient, Int<141>(), session, t); break;
242  case 142: StubAccess().callMethod(rcfClient, Int<142>(), session, t); break;
243  case 143: StubAccess().callMethod(rcfClient, Int<143>(), session, t); break;
244  case 144: StubAccess().callMethod(rcfClient, Int<144>(), session, t); break;
245  case 145: StubAccess().callMethod(rcfClient, Int<145>(), session, t); break;
246  case 146: StubAccess().callMethod(rcfClient, Int<146>(), session, t); break;
247  case 147: StubAccess().callMethod(rcfClient, Int<147>(), session, t); break;
248  case 148: StubAccess().callMethod(rcfClient, Int<148>(), session, t); break;
249  case 149: StubAccess().callMethod(rcfClient, Int<149>(), session, t); break;
250  case 150: StubAccess().callMethod(rcfClient, Int<150>(), session, t); break;
251  case 151: StubAccess().callMethod(rcfClient, Int<151>(), session, t); break;
252  case 152: StubAccess().callMethod(rcfClient, Int<152>(), session, t); break;
253  case 153: StubAccess().callMethod(rcfClient, Int<153>(), session, t); break;
254  case 154: StubAccess().callMethod(rcfClient, Int<154>(), session, t); break;
255  case 155: StubAccess().callMethod(rcfClient, Int<155>(), session, t); break;
256  case 156: StubAccess().callMethod(rcfClient, Int<156>(), session, t); break;
257  case 157: StubAccess().callMethod(rcfClient, Int<157>(), session, t); break;
258  case 158: StubAccess().callMethod(rcfClient, Int<158>(), session, t); break;
259  case 159: StubAccess().callMethod(rcfClient, Int<159>(), session, t); break;
260  case 160: StubAccess().callMethod(rcfClient, Int<160>(), session, t); break;
261  case 161: StubAccess().callMethod(rcfClient, Int<161>(), session, t); break;
262  case 162: StubAccess().callMethod(rcfClient, Int<162>(), session, t); break;
263  case 163: StubAccess().callMethod(rcfClient, Int<163>(), session, t); break;
264  case 164: StubAccess().callMethod(rcfClient, Int<164>(), session, t); break;
265  case 165: StubAccess().callMethod(rcfClient, Int<165>(), session, t); break;
266  case 166: StubAccess().callMethod(rcfClient, Int<166>(), session, t); break;
267  case 167: StubAccess().callMethod(rcfClient, Int<167>(), session, t); break;
268  case 168: StubAccess().callMethod(rcfClient, Int<168>(), session, t); break;
269  case 169: StubAccess().callMethod(rcfClient, Int<169>(), session, t); break;
270  case 170: StubAccess().callMethod(rcfClient, Int<170>(), session, t); break;
271  case 171: StubAccess().callMethod(rcfClient, Int<171>(), session, t); break;
272  case 172: StubAccess().callMethod(rcfClient, Int<172>(), session, t); break;
273  case 173: StubAccess().callMethod(rcfClient, Int<173>(), session, t); break;
274  case 174: StubAccess().callMethod(rcfClient, Int<174>(), session, t); break;
275  case 175: StubAccess().callMethod(rcfClient, Int<175>(), session, t); break;
276  case 176: StubAccess().callMethod(rcfClient, Int<176>(), session, t); break;
277  case 177: StubAccess().callMethod(rcfClient, Int<177>(), session, t); break;
278  case 178: StubAccess().callMethod(rcfClient, Int<178>(), session, t); break;
279  case 179: StubAccess().callMethod(rcfClient, Int<179>(), session, t); break;
280  case 180: StubAccess().callMethod(rcfClient, Int<180>(), session, t); break;
281  case 181: StubAccess().callMethod(rcfClient, Int<181>(), session, t); break;
282  case 182: StubAccess().callMethod(rcfClient, Int<182>(), session, t); break;
283  case 183: StubAccess().callMethod(rcfClient, Int<183>(), session, t); break;
284  case 184: StubAccess().callMethod(rcfClient, Int<184>(), session, t); break;
285  case 185: StubAccess().callMethod(rcfClient, Int<185>(), session, t); break;
286  case 186: StubAccess().callMethod(rcfClient, Int<186>(), session, t); break;
287  case 187: StubAccess().callMethod(rcfClient, Int<187>(), session, t); break;
288  case 188: StubAccess().callMethod(rcfClient, Int<188>(), session, t); break;
289  case 189: StubAccess().callMethod(rcfClient, Int<189>(), session, t); break;
290  case 190: StubAccess().callMethod(rcfClient, Int<190>(), session, t); break;
291  case 191: StubAccess().callMethod(rcfClient, Int<191>(), session, t); break;
292  case 192: StubAccess().callMethod(rcfClient, Int<192>(), session, t); break;
293  case 193: StubAccess().callMethod(rcfClient, Int<193>(), session, t); break;
294  case 194: StubAccess().callMethod(rcfClient, Int<194>(), session, t); break;
295  case 195: StubAccess().callMethod(rcfClient, Int<195>(), session, t); break;
296  case 196: StubAccess().callMethod(rcfClient, Int<196>(), session, t); break;
297  case 197: StubAccess().callMethod(rcfClient, Int<197>(), session, t); break;
298  case 198: StubAccess().callMethod(rcfClient, Int<198>(), session, t); break;
299  case 199: StubAccess().callMethod(rcfClient, Int<199>(), session, t); break;
300  case 200: StubAccess().callMethod(rcfClient, Int<200>(), session, t); break;
301 
302  default: RCF_THROW(Exception(RcfError_FnId, fnId));
303  }
304  }
305 
306  template<typename RcfClientT, typename RefWrapperT>
307  class ServerMethod : public ServerMethodBase
308  {
309  public:
310  ServerMethod(RcfClientT &rcfClient, RefWrapperT refWrapper) :
311  mRcfClient(rcfClient),
312  mRefWrapper(refWrapper)
313  {}
314 
315  void callMethod(int fnId, RcfSession & session)
316  {
317  RCF::callMethod(mRcfClient, mRefWrapper.get(), fnId, session);
318  }
319 
320  private:
321  RcfClientT & mRcfClient;
322  RefWrapperT mRefWrapper;
323  };
324 
326  class RCF_EXPORT ServerBinding
327  {
328  public:
329 
332  void setAccessControl(AccessControlCallback cbAccessControl);
333 
334  template<typename RcfClientT, typename RefWrapperT>
335  void addServerMethods(RcfClientT &rcfClient, RefWrapperT refWrapper)
336  {
337  mServerMethodPtr.reset(
338  new ServerMethod<RcfClientT, RefWrapperT>(
339  rcfClient,
340  refWrapper));
341  }
342 
343  private:
344 
345  friend class RcfServer;
346  friend class RcfSession;
347 
348  void callMethod(
349  int fnId,
350  RcfSession & session);
351 
352  private:
353  Mutex mMutex;
354  ServerMethodPtr mServerMethodPtr;
355  AccessControlCallback mCbAccessControl;
356  };
357 
358  template<typename InterfaceT, typename ImplementationT, typename ImplementationPtrT>
359  RcfClientPtr createServerStub(
360  InterfaceT *,
361  ImplementationT *,
362  ImplementationPtrT px)
363  {
364  typedef typename InterfaceT::RcfClientT RcfClientT;
365  return RcfClientPtr( new RcfClientT(
367  px,
368  (TrueType *)NULL));
369  }
370 
371 } // namespace RCF
372 
373 #endif // ! INCLUDE_RCF_SERVERSTUB_HPP
Represents the binding of a server-side servant object to a RCF interface.
Definition: ServerStub.hpp:326
Represents a server side session, associated with a client connection.
Definition: RcfSession.hpp:65
std::function< bool(int)> AccessControlCallback
Describes a user-provided function for determining whether a client connections should be able to acc...
Definition: RcfFwd.hpp:328
std::shared_ptr< ServerBinding > ServerBindingPtr
Reference counted wrapper for RCF::ServerBinding.
Definition: RcfFwd.hpp:249
Provides RCF server-side functionality.
Definition: RcfServer.hpp:54
Definition: AmiIoHandler.hpp:24