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