RCFProto
 All Classes Functions Typedefs
ServerStub.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_SERVERSTUB_HPP
20 #define INCLUDE_RCF_SERVERSTUB_HPP
21 
22 #include <map>
23 #include <memory>
24 #include <vector>
25 
26 #include <boost/shared_ptr.hpp>
27 
28 #include <RCF/Config.hpp>
29 #include <RCF/Export.hpp>
30 #include <RCF/GetInterfaceName.hpp>
31 #include <RCF/RcfClient.hpp>
32 #include <RCF/RcfSession.hpp>
33 #include <RCF/SerializationProtocol.hpp>
34 #include <RCF/Token.hpp>
35 
36 // NB: occurrences of "interface" in this file have been replaced with "interface_", due to obscure bugs with Visual C++
37 
38 namespace RCF {
39 
40  class I_RcfClient;
41  typedef boost::shared_ptr<I_RcfClient> RcfClientPtr;
42 
43  template<typename T>
44  class I_Deref
45  {
46  public:
47  virtual ~I_Deref() {}
48  virtual T &deref() = 0;
49  };
50 
51  template<typename T>
52  class DerefObj : public I_Deref<T>
53  {
54  public:
55  DerefObj(T &t) :
56  mT(t)
57  {}
58 
59  T &deref()
60  {
61  return mT;
62  }
63 
64  private:
65  T &mT;
66  };
67 
68  template<typename T>
69  class DerefSharedPtr : public I_Deref<T>
70  {
71  public:
72  DerefSharedPtr(boost::shared_ptr<T> tPtr) :
73  mTPtr(tPtr)
74  {}
75 
76  T &deref()
77  {
78  return *mTPtr;
79  }
80 
81  private:
82  boost::shared_ptr<T> mTPtr;
83  };
84 
85  RCF_EXPORT void setCurrentCallDesc(
86  std::string & desc,
87  RCF::MethodInvocationRequest & request,
88  const char * szFunc,
89  const char * szArity);
90 
91  class StubAccess
92  {
93  public:
94 
95 #ifdef _MSC_VER
96 #pragma warning( push )
97 #pragma warning( disable: 4702 )
98 #endif
99 
100  template<typename InterfaceT, typename IdT, typename ImplementationT>
101  void invoke(
102  InterfaceT & interface_,
103  const IdT & id,
104  RcfSession & session,
105  ImplementationT & t)
106  {
107  setCurrentCallDesc(
108  session.mCurrentCallDesc,
109  session.mRequest,
110  interface_.getFunctionName(id),
111  interface_.getArity(id));
112 
113  RCF_LOG_2() << "RcfServer - begin remote call. " << session.mCurrentCallDesc;
114  interface_.invoke(id, session, t);
115  }
116 
117 #ifdef _MSC_VER
118 #pragma warning( pop )
119 #endif
120 
121  template<typename InterfaceT, typename DerefPtrT>
122  void registerInvokeFunctors(
123  InterfaceT & interface_,
124  InvokeFunctorMap & invokeFunctorMap,
125  DerefPtrT derefPtr)
126  {
127  interface_.registerInvokeFunctors(invokeFunctorMap, derefPtr);
128  }
129 
130  template<typename RcfClientT>
131  ClientStubPtr getClientStubPtr(const RcfClientT &rcfClient)
132  {
133  return rcfClient.mClientStubPtr;
134  }
135 
136  };
137 
138  template<typename InterfaceT, typename ImplementationT>
139  inline void invoke(
140  InterfaceT & interface_,
141  ImplementationT & t,
142  int fnId,
143  RcfSession & session)
144  {
145  switch (fnId) {
146  case 0: StubAccess().invoke(interface_, boost::mpl::int_< 0>(), session, t); break;
147  case 1: StubAccess().invoke(interface_, boost::mpl::int_< 1>(), session, t); break;
148  case 2: StubAccess().invoke(interface_, boost::mpl::int_< 2>(), session, t); break;
149  case 3: StubAccess().invoke(interface_, boost::mpl::int_< 3>(), session, t); break;
150  case 4: StubAccess().invoke(interface_, boost::mpl::int_< 4>(), session, t); break;
151  case 5: StubAccess().invoke(interface_, boost::mpl::int_< 5>(), session, t); break;
152  case 6: StubAccess().invoke(interface_, boost::mpl::int_< 6>(), session, t); break;
153  case 7: StubAccess().invoke(interface_, boost::mpl::int_< 7>(), session, t); break;
154  case 8: StubAccess().invoke(interface_, boost::mpl::int_< 8>(), session, t); break;
155  case 9: StubAccess().invoke(interface_, boost::mpl::int_< 9>(), session, t); break;
156  case 10: StubAccess().invoke(interface_, boost::mpl::int_< 10>(), session, t); break;
157  case 11: StubAccess().invoke(interface_, boost::mpl::int_< 11>(), session, t); break;
158  case 12: StubAccess().invoke(interface_, boost::mpl::int_< 12>(), session, t); break;
159  case 13: StubAccess().invoke(interface_, boost::mpl::int_< 13>(), session, t); break;
160  case 14: StubAccess().invoke(interface_, boost::mpl::int_< 14>(), session, t); break;
161  case 15: StubAccess().invoke(interface_, boost::mpl::int_< 15>(), session, t); break;
162  case 16: StubAccess().invoke(interface_, boost::mpl::int_< 16>(), session, t); break;
163  case 17: StubAccess().invoke(interface_, boost::mpl::int_< 17>(), session, t); break;
164  case 18: StubAccess().invoke(interface_, boost::mpl::int_< 18>(), session, t); break;
165  case 19: StubAccess().invoke(interface_, boost::mpl::int_< 19>(), session, t); break;
166  case 20: StubAccess().invoke(interface_, boost::mpl::int_< 20>(), session, t); break;
167  case 21: StubAccess().invoke(interface_, boost::mpl::int_< 21>(), session, t); break;
168  case 22: StubAccess().invoke(interface_, boost::mpl::int_< 22>(), session, t); break;
169  case 23: StubAccess().invoke(interface_, boost::mpl::int_< 23>(), session, t); break;
170  case 24: StubAccess().invoke(interface_, boost::mpl::int_< 24>(), session, t); break;
171  case 25: StubAccess().invoke(interface_, boost::mpl::int_< 25>(), session, t); break;
172  case 26: StubAccess().invoke(interface_, boost::mpl::int_< 26>(), session, t); break;
173  case 27: StubAccess().invoke(interface_, boost::mpl::int_< 27>(), session, t); break;
174  case 28: StubAccess().invoke(interface_, boost::mpl::int_< 28>(), session, t); break;
175  case 29: StubAccess().invoke(interface_, boost::mpl::int_< 29>(), session, t); break;
176  case 30: StubAccess().invoke(interface_, boost::mpl::int_< 30>(), session, t); break;
177  case 31: StubAccess().invoke(interface_, boost::mpl::int_< 31>(), session, t); break;
178  case 32: StubAccess().invoke(interface_, boost::mpl::int_< 32>(), session, t); break;
179  case 33: StubAccess().invoke(interface_, boost::mpl::int_< 33>(), session, t); break;
180  case 34: StubAccess().invoke(interface_, boost::mpl::int_< 34>(), session, t); break;
181  case 35: StubAccess().invoke(interface_, boost::mpl::int_< 35>(), session, t); break;
182  case 36: StubAccess().invoke(interface_, boost::mpl::int_< 36>(), session, t); break;
183  case 37: StubAccess().invoke(interface_, boost::mpl::int_< 37>(), session, t); break;
184  case 38: StubAccess().invoke(interface_, boost::mpl::int_< 38>(), session, t); break;
185  case 39: StubAccess().invoke(interface_, boost::mpl::int_< 39>(), session, t); break;
186  case 40: StubAccess().invoke(interface_, boost::mpl::int_< 40>(), session, t); break;
187  case 41: StubAccess().invoke(interface_, boost::mpl::int_< 41>(), session, t); break;
188  case 42: StubAccess().invoke(interface_, boost::mpl::int_< 42>(), session, t); break;
189  case 43: StubAccess().invoke(interface_, boost::mpl::int_< 43>(), session, t); break;
190  case 44: StubAccess().invoke(interface_, boost::mpl::int_< 44>(), session, t); break;
191  case 45: StubAccess().invoke(interface_, boost::mpl::int_< 45>(), session, t); break;
192  case 46: StubAccess().invoke(interface_, boost::mpl::int_< 46>(), session, t); break;
193  case 47: StubAccess().invoke(interface_, boost::mpl::int_< 47>(), session, t); break;
194  case 48: StubAccess().invoke(interface_, boost::mpl::int_< 48>(), session, t); break;
195  case 49: StubAccess().invoke(interface_, boost::mpl::int_< 49>(), session, t); break;
196  case 50: StubAccess().invoke(interface_, boost::mpl::int_< 50>(), session, t); break;
197  case 51: StubAccess().invoke(interface_, boost::mpl::int_< 51>(), session, t); break;
198  case 52: StubAccess().invoke(interface_, boost::mpl::int_< 52>(), session, t); break;
199  case 53: StubAccess().invoke(interface_, boost::mpl::int_< 53>(), session, t); break;
200  case 54: StubAccess().invoke(interface_, boost::mpl::int_< 54>(), session, t); break;
201  case 55: StubAccess().invoke(interface_, boost::mpl::int_< 55>(), session, t); break;
202  case 56: StubAccess().invoke(interface_, boost::mpl::int_< 56>(), session, t); break;
203  case 57: StubAccess().invoke(interface_, boost::mpl::int_< 57>(), session, t); break;
204  case 58: StubAccess().invoke(interface_, boost::mpl::int_< 58>(), session, t); break;
205  case 59: StubAccess().invoke(interface_, boost::mpl::int_< 59>(), session, t); break;
206  case 60: StubAccess().invoke(interface_, boost::mpl::int_< 60>(), session, t); break;
207  case 61: StubAccess().invoke(interface_, boost::mpl::int_< 61>(), session, t); break;
208  case 62: StubAccess().invoke(interface_, boost::mpl::int_< 62>(), session, t); break;
209  case 63: StubAccess().invoke(interface_, boost::mpl::int_< 63>(), session, t); break;
210  case 64: StubAccess().invoke(interface_, boost::mpl::int_< 64>(), session, t); break;
211  case 65: StubAccess().invoke(interface_, boost::mpl::int_< 65>(), session, t); break;
212  case 66: StubAccess().invoke(interface_, boost::mpl::int_< 66>(), session, t); break;
213  case 67: StubAccess().invoke(interface_, boost::mpl::int_< 67>(), session, t); break;
214  case 68: StubAccess().invoke(interface_, boost::mpl::int_< 68>(), session, t); break;
215  case 69: StubAccess().invoke(interface_, boost::mpl::int_< 69>(), session, t); break;
216  case 70: StubAccess().invoke(interface_, boost::mpl::int_< 70>(), session, t); break;
217  case 71: StubAccess().invoke(interface_, boost::mpl::int_< 71>(), session, t); break;
218  case 72: StubAccess().invoke(interface_, boost::mpl::int_< 72>(), session, t); break;
219  case 73: StubAccess().invoke(interface_, boost::mpl::int_< 73>(), session, t); break;
220  case 74: StubAccess().invoke(interface_, boost::mpl::int_< 74>(), session, t); break;
221  case 75: StubAccess().invoke(interface_, boost::mpl::int_< 75>(), session, t); break;
222  case 76: StubAccess().invoke(interface_, boost::mpl::int_< 76>(), session, t); break;
223  case 77: StubAccess().invoke(interface_, boost::mpl::int_< 77>(), session, t); break;
224  case 78: StubAccess().invoke(interface_, boost::mpl::int_< 78>(), session, t); break;
225  case 79: StubAccess().invoke(interface_, boost::mpl::int_< 79>(), session, t); break;
226  case 80: StubAccess().invoke(interface_, boost::mpl::int_< 80>(), session, t); break;
227  case 81: StubAccess().invoke(interface_, boost::mpl::int_< 81>(), session, t); break;
228  case 82: StubAccess().invoke(interface_, boost::mpl::int_< 82>(), session, t); break;
229  case 83: StubAccess().invoke(interface_, boost::mpl::int_< 83>(), session, t); break;
230  case 84: StubAccess().invoke(interface_, boost::mpl::int_< 84>(), session, t); break;
231  case 85: StubAccess().invoke(interface_, boost::mpl::int_< 85>(), session, t); break;
232  case 86: StubAccess().invoke(interface_, boost::mpl::int_< 86>(), session, t); break;
233  case 87: StubAccess().invoke(interface_, boost::mpl::int_< 87>(), session, t); break;
234  case 88: StubAccess().invoke(interface_, boost::mpl::int_< 88>(), session, t); break;
235  case 89: StubAccess().invoke(interface_, boost::mpl::int_< 89>(), session, t); break;
236  case 90: StubAccess().invoke(interface_, boost::mpl::int_< 90>(), session, t); break;
237  case 91: StubAccess().invoke(interface_, boost::mpl::int_< 91>(), session, t); break;
238  case 92: StubAccess().invoke(interface_, boost::mpl::int_< 92>(), session, t); break;
239  case 93: StubAccess().invoke(interface_, boost::mpl::int_< 93>(), session, t); break;
240  case 94: StubAccess().invoke(interface_, boost::mpl::int_< 94>(), session, t); break;
241  case 95: StubAccess().invoke(interface_, boost::mpl::int_< 95>(), session, t); break;
242  case 96: StubAccess().invoke(interface_, boost::mpl::int_< 96>(), session, t); break;
243  case 97: StubAccess().invoke(interface_, boost::mpl::int_< 97>(), session, t); break;
244  case 98: StubAccess().invoke(interface_, boost::mpl::int_< 98>(), session, t); break;
245  case 99: StubAccess().invoke(interface_, boost::mpl::int_< 99>(), session, t); break;
246  case 100: StubAccess().invoke(interface_, boost::mpl::int_<100>(), session, t); break;
247  case 101: StubAccess().invoke(interface_, boost::mpl::int_<101>(), session, t); break;
248  case 102: StubAccess().invoke(interface_, boost::mpl::int_<102>(), session, t); break;
249  case 103: StubAccess().invoke(interface_, boost::mpl::int_<103>(), session, t); break;
250  case 104: StubAccess().invoke(interface_, boost::mpl::int_<104>(), session, t); break;
251  case 105: StubAccess().invoke(interface_, boost::mpl::int_<105>(), session, t); break;
252  case 106: StubAccess().invoke(interface_, boost::mpl::int_<106>(), session, t); break;
253  case 107: StubAccess().invoke(interface_, boost::mpl::int_<107>(), session, t); break;
254  case 108: StubAccess().invoke(interface_, boost::mpl::int_<108>(), session, t); break;
255  case 109: StubAccess().invoke(interface_, boost::mpl::int_<109>(), session, t); break;
256  case 110: StubAccess().invoke(interface_, boost::mpl::int_<110>(), session, t); break;
257  case 111: StubAccess().invoke(interface_, boost::mpl::int_<111>(), session, t); break;
258  case 112: StubAccess().invoke(interface_, boost::mpl::int_<112>(), session, t); break;
259  case 113: StubAccess().invoke(interface_, boost::mpl::int_<113>(), session, t); break;
260  case 114: StubAccess().invoke(interface_, boost::mpl::int_<114>(), session, t); break;
261  case 115: StubAccess().invoke(interface_, boost::mpl::int_<115>(), session, t); break;
262  case 116: StubAccess().invoke(interface_, boost::mpl::int_<116>(), session, t); break;
263  case 117: StubAccess().invoke(interface_, boost::mpl::int_<117>(), session, t); break;
264  case 118: StubAccess().invoke(interface_, boost::mpl::int_<118>(), session, t); break;
265  case 119: StubAccess().invoke(interface_, boost::mpl::int_<119>(), session, t); break;
266  case 120: StubAccess().invoke(interface_, boost::mpl::int_<120>(), session, t); break;
267  case 121: StubAccess().invoke(interface_, boost::mpl::int_<121>(), session, t); break;
268  case 122: StubAccess().invoke(interface_, boost::mpl::int_<122>(), session, t); break;
269  case 123: StubAccess().invoke(interface_, boost::mpl::int_<123>(), session, t); break;
270  case 124: StubAccess().invoke(interface_, boost::mpl::int_<124>(), session, t); break;
271  case 125: StubAccess().invoke(interface_, boost::mpl::int_<125>(), session, t); break;
272  case 126: StubAccess().invoke(interface_, boost::mpl::int_<126>(), session, t); break;
273  case 127: StubAccess().invoke(interface_, boost::mpl::int_<127>(), session, t); break;
274  case 128: StubAccess().invoke(interface_, boost::mpl::int_<128>(), session, t); break;
275  case 129: StubAccess().invoke(interface_, boost::mpl::int_<129>(), session, t); break;
276  case 130: StubAccess().invoke(interface_, boost::mpl::int_<130>(), session, t); break;
277  case 131: StubAccess().invoke(interface_, boost::mpl::int_<131>(), session, t); break;
278  case 132: StubAccess().invoke(interface_, boost::mpl::int_<132>(), session, t); break;
279  case 133: StubAccess().invoke(interface_, boost::mpl::int_<133>(), session, t); break;
280  case 134: StubAccess().invoke(interface_, boost::mpl::int_<134>(), session, t); break;
281  case 135: StubAccess().invoke(interface_, boost::mpl::int_<135>(), session, t); break;
282  case 136: StubAccess().invoke(interface_, boost::mpl::int_<136>(), session, t); break;
283  case 137: StubAccess().invoke(interface_, boost::mpl::int_<137>(), session, t); break;
284  case 138: StubAccess().invoke(interface_, boost::mpl::int_<138>(), session, t); break;
285  case 139: StubAccess().invoke(interface_, boost::mpl::int_<139>(), session, t); break;
286  case 140: StubAccess().invoke(interface_, boost::mpl::int_<140>(), session, t); break;
287  case 141: StubAccess().invoke(interface_, boost::mpl::int_<141>(), session, t); break;
288  case 142: StubAccess().invoke(interface_, boost::mpl::int_<142>(), session, t); break;
289  case 143: StubAccess().invoke(interface_, boost::mpl::int_<143>(), session, t); break;
290  case 144: StubAccess().invoke(interface_, boost::mpl::int_<144>(), session, t); break;
291  case 145: StubAccess().invoke(interface_, boost::mpl::int_<145>(), session, t); break;
292  case 146: StubAccess().invoke(interface_, boost::mpl::int_<146>(), session, t); break;
293  case 147: StubAccess().invoke(interface_, boost::mpl::int_<147>(), session, t); break;
294  case 148: StubAccess().invoke(interface_, boost::mpl::int_<148>(), session, t); break;
295  case 149: StubAccess().invoke(interface_, boost::mpl::int_<149>(), session, t); break;
296  case 150: StubAccess().invoke(interface_, boost::mpl::int_<150>(), session, t); break;
297  case 151: StubAccess().invoke(interface_, boost::mpl::int_<151>(), session, t); break;
298  case 152: StubAccess().invoke(interface_, boost::mpl::int_<152>(), session, t); break;
299  case 153: StubAccess().invoke(interface_, boost::mpl::int_<153>(), session, t); break;
300  case 154: StubAccess().invoke(interface_, boost::mpl::int_<154>(), session, t); break;
301  case 155: StubAccess().invoke(interface_, boost::mpl::int_<155>(), session, t); break;
302  case 156: StubAccess().invoke(interface_, boost::mpl::int_<156>(), session, t); break;
303  case 157: StubAccess().invoke(interface_, boost::mpl::int_<157>(), session, t); break;
304  case 158: StubAccess().invoke(interface_, boost::mpl::int_<158>(), session, t); break;
305  case 159: StubAccess().invoke(interface_, boost::mpl::int_<159>(), session, t); break;
306  case 160: StubAccess().invoke(interface_, boost::mpl::int_<160>(), session, t); break;
307  case 161: StubAccess().invoke(interface_, boost::mpl::int_<161>(), session, t); break;
308  case 162: StubAccess().invoke(interface_, boost::mpl::int_<162>(), session, t); break;
309  case 163: StubAccess().invoke(interface_, boost::mpl::int_<163>(), session, t); break;
310  case 164: StubAccess().invoke(interface_, boost::mpl::int_<164>(), session, t); break;
311  case 165: StubAccess().invoke(interface_, boost::mpl::int_<165>(), session, t); break;
312  case 166: StubAccess().invoke(interface_, boost::mpl::int_<166>(), session, t); break;
313  case 167: StubAccess().invoke(interface_, boost::mpl::int_<167>(), session, t); break;
314  case 168: StubAccess().invoke(interface_, boost::mpl::int_<168>(), session, t); break;
315  case 169: StubAccess().invoke(interface_, boost::mpl::int_<169>(), session, t); break;
316  case 170: StubAccess().invoke(interface_, boost::mpl::int_<170>(), session, t); break;
317  case 171: StubAccess().invoke(interface_, boost::mpl::int_<171>(), session, t); break;
318  case 172: StubAccess().invoke(interface_, boost::mpl::int_<172>(), session, t); break;
319  case 173: StubAccess().invoke(interface_, boost::mpl::int_<173>(), session, t); break;
320  case 174: StubAccess().invoke(interface_, boost::mpl::int_<174>(), session, t); break;
321  case 175: StubAccess().invoke(interface_, boost::mpl::int_<175>(), session, t); break;
322  case 176: StubAccess().invoke(interface_, boost::mpl::int_<176>(), session, t); break;
323  case 177: StubAccess().invoke(interface_, boost::mpl::int_<177>(), session, t); break;
324  case 178: StubAccess().invoke(interface_, boost::mpl::int_<178>(), session, t); break;
325  case 179: StubAccess().invoke(interface_, boost::mpl::int_<179>(), session, t); break;
326  case 180: StubAccess().invoke(interface_, boost::mpl::int_<180>(), session, t); break;
327  case 181: StubAccess().invoke(interface_, boost::mpl::int_<181>(), session, t); break;
328  case 182: StubAccess().invoke(interface_, boost::mpl::int_<182>(), session, t); break;
329  case 183: StubAccess().invoke(interface_, boost::mpl::int_<183>(), session, t); break;
330  case 184: StubAccess().invoke(interface_, boost::mpl::int_<184>(), session, t); break;
331  case 185: StubAccess().invoke(interface_, boost::mpl::int_<185>(), session, t); break;
332  case 186: StubAccess().invoke(interface_, boost::mpl::int_<186>(), session, t); break;
333  case 187: StubAccess().invoke(interface_, boost::mpl::int_<187>(), session, t); break;
334  case 188: StubAccess().invoke(interface_, boost::mpl::int_<188>(), session, t); break;
335  case 189: StubAccess().invoke(interface_, boost::mpl::int_<189>(), session, t); break;
336  case 190: StubAccess().invoke(interface_, boost::mpl::int_<190>(), session, t); break;
337  case 191: StubAccess().invoke(interface_, boost::mpl::int_<191>(), session, t); break;
338  case 192: StubAccess().invoke(interface_, boost::mpl::int_<192>(), session, t); break;
339  case 193: StubAccess().invoke(interface_, boost::mpl::int_<193>(), session, t); break;
340  case 194: StubAccess().invoke(interface_, boost::mpl::int_<194>(), session, t); break;
341  case 195: StubAccess().invoke(interface_, boost::mpl::int_<195>(), session, t); break;
342  case 196: StubAccess().invoke(interface_, boost::mpl::int_<196>(), session, t); break;
343  case 197: StubAccess().invoke(interface_, boost::mpl::int_<197>(), session, t); break;
344  case 198: StubAccess().invoke(interface_, boost::mpl::int_<198>(), session, t); break;
345  case 199: StubAccess().invoke(interface_, boost::mpl::int_<199>(), session, t); break;
346  case 200: StubAccess().invoke(interface_, boost::mpl::int_<200>(), session, t); break;
347 
348  default: RCF_THROW(Exception(_RcfError_FnId(fnId)));
349  }
350  }
351 
352  template<typename InterfaceT, typename DerefPtrT>
353  class InterfaceInvocator
354  {
355  public:
356  InterfaceInvocator(InterfaceT &interface_, DerefPtrT derefPtr) :
357  mInterface(interface_),
358  mDerefPtr(derefPtr)
359  {}
360 
361  void operator()(
362  int fnId,
363  RcfSession & session)
364  {
365  invoke<InterfaceT>(mInterface, mDerefPtr->deref(), fnId, session);
366  }
367 
368  private:
369  InterfaceT & mInterface;
370  DerefPtrT mDerefPtr;
371  };
372 
373  template<typename InterfaceT, typename DerefPtrT>
374  void registerInvokeFunctors(
375  InterfaceT & interface_,
376  InvokeFunctorMap & invokeFunctorMap,
377  DerefPtrT derefPtr)
378  {
379  // NB: same interface may occur more than once in the inheritance hierarchy of another interface, and in
380  // that case, via overwriting, only one InterfaceInvocator is registered, so only the functions in one of the interfaces will ever be called.
381  // But it doesn't matter, since even if an interface occurs several times in the inheritance hierarchy, each occurrence
382  // of the interface will be bound to derefPtr in exactly the same way.
383 
384  typedef typename InterfaceT::Interface Interface;
385  std::string interfaceName = ::RCF::getInterfaceName( (Interface *) NULL);
386 
387  invokeFunctorMap[ interfaceName ] =
388  InterfaceInvocator<InterfaceT, DerefPtrT>(interface_, derefPtr);
389  }
390 
391  class ServerBinding;
392 
393  typedef boost::shared_ptr<ServerBinding> ServerBindingPtr;
394 
395  class RCF_EXPORT ServerBinding
396  {
397  public:
398 
399  typedef boost::function<bool(int)> CbAccessControl;
400 
401  void setAccessControl(CbAccessControl cbAccessControl);
402 
403  template<typename InterfaceT, typename DerefPtrT>
404  void registerInvokeFunctors(InterfaceT &interface_, DerefPtrT derefPtr)
405  {
406  StubAccess access;
407  access.registerInvokeFunctors(
408  interface_,
409  mInvokeFunctorMap,
410  derefPtr);
411  }
412 
413  private:
414 
415  friend class RcfServer;
416  friend class RcfSession;
417 
418  void invoke(
419  const std::string & subInterface,
420  int fnId,
421  RcfSession & session);
422 
423  private:
424 
425  Mutex mMutex;
426 
427  // TODO: too much overhead per server stub?
428  InvokeFunctorMap mInvokeFunctorMap;
429 
430  CbAccessControl mCbAccessControl;
431  };
432 
433  template<typename InterfaceT, typename ImplementationT, typename ImplementationPtrT>
434  RcfClientPtr createServerStub(
435  InterfaceT *,
436  ImplementationT *,
437  ImplementationPtrT px)
438  {
439  typedef typename InterfaceT::RcfClientT RcfClientT;
440  return RcfClientPtr( new RcfClientT(
441  ServerBindingPtr(new ServerBinding()),
442  px,
443  (TrueType *)NULL));
444  }
445 
446 } // namespace RCF
447 
448 #endif // ! INCLUDE_RCF_SERVERSTUB_HPP