CARMA C++
RemoteObjMethodFunctor.h
1 #ifndef CARMA_CONTROL_REMOTE_OBJ_METHOD_FUNCTOR_H
2 #define CARMA_CONTROL_REMOTE_OBJ_METHOD_FUNCTOR_H
3 
4 
5 #include <string>
6 
8 #include "carma/util/Time.h"
9 
10 
11 namespace carma {
12 namespace control {
13 
14 
15 template < typename T >
16 class RemoteObjMethodFunctorBase {
17  public:
18  RemoteObjMethodFunctorBase(
19  RemoteObjHandleT< T > * remoteObjHandle,
20  const ::std::string & remoteCallString );
21 
22  virtual ~RemoteObjMethodFunctorBase( ) { }
23 
24  void operator()( );
25 
26  private:
27  virtual void makeRemoteCall( typename T::_ptr_type remoteObj ) = 0;
28 
29  RemoteObjHandleT< T > * const remoteObjHandle_;
30  const ::std::string remoteCallString_;
31 };
32 
33 
34 template < typename T >
35 class RemoteObjMethodFunctor0 : public RemoteObjMethodFunctorBase< T > {
36  public:
37  RemoteObjMethodFunctor0(
38  RemoteObjHandleT< T > * remoteObjHandle,
39  const ::std::string & remoteCallString,
40  void (T::*methodPtr)( ) );
41 
42  private:
43  virtual void makeRemoteCall( typename T::_ptr_type remoteObj );
44 
45  void (T::*methodPtr_)( );
46 };
47 
48 
49 template < typename T,
50  typename A0 >
51 class RemoteObjMethodFunctor1 : public RemoteObjMethodFunctorBase< T > {
52  public:
53  RemoteObjMethodFunctor1(
54  RemoteObjHandleT< T > * remoteObjHandle,
55  const ::std::string & remoteCallString,
56  void (T::*methodPtr)( A0 ),
57  const A0 & arg0 );
58 
59  private:
60  virtual void makeRemoteCall( typename T::_ptr_type remoteObj );
61 
62  void (T::*methodPtr_)( A0 );
63  const A0 arg0_;
64 };
65 
66 
67 template < typename T,
68  typename A0,
69  typename A1 >
70 class RemoteObjMethodFunctor2 : public RemoteObjMethodFunctorBase< T > {
71  public:
72  RemoteObjMethodFunctor2(
73  RemoteObjHandleT< T > * remoteObjHandle,
74  const ::std::string & remoteCallString,
75  void (T::*methodPtr)( A0, A1 ),
76  const A0 & arg0,
77  const A1 & arg1 );
78 
79  private:
80  virtual void makeRemoteCall( typename T::_ptr_type remoteObj );
81 
82  void (T::*methodPtr_)( A0, A1 );
83  const A0 arg0_;
84  const A1 arg1_;
85 };
86 
87 
88 template < typename T,
89  typename A0,
90  typename A1,
91  typename A2 >
92 class RemoteObjMethodFunctor3 : public RemoteObjMethodFunctorBase< T > {
93  public:
94  RemoteObjMethodFunctor3(
95  RemoteObjHandleT< T > * remoteObjHandle,
96  const ::std::string & remoteCallString,
97  void (T::*methodPtr)( A0, A1, A2 ),
98  const A0 & arg0,
99  const A1 & arg1,
100  const A2 & arg2 );
101 
102  private:
103  virtual void makeRemoteCall( typename T::_ptr_type remoteObj );
104 
105  void (T::*methodPtr_)( A0, A1, A2 );
106  const A0 arg0_;
107  const A1 arg1_;
108  const A2 arg2_;
109 };
110 
111 
112 template < typename T,
113  typename A0,
114  typename A1,
115  typename A2,
116  typename A3 >
117 class RemoteObjMethodFunctor4 : public RemoteObjMethodFunctorBase< T > {
118  public:
119  RemoteObjMethodFunctor4(
120  RemoteObjHandleT< T > * remoteObjHandle,
121  const ::std::string & remoteCallString,
122  void (T::*methodPtr)( A0, A1, A2, A3 ),
123  const A0 & arg0,
124  const A1 & arg1,
125  const A2 & arg2,
126  const A3 & arg3 );
127 
128  private:
129  virtual void makeRemoteCall( typename T::_ptr_type remoteObj );
130 
131  void (T::*methodPtr_)( A0, A1, A2, A3 );
132  const A0 arg0_;
133  const A1 arg1_;
134  const A2 arg2_;
135  const A3 arg3_;
136 };
137 
138 
139 template < typename T,
140  typename A0,
141  typename A1,
142  typename A2,
143  typename A3,
144  typename A4 >
145 class RemoteObjMethodFunctor5 : public RemoteObjMethodFunctorBase< T > {
146  public:
147  RemoteObjMethodFunctor5(
148  RemoteObjHandleT< T > * remoteObjHandle,
149  const ::std::string & remoteCallString,
150  void (T::*methodPtr)( A0, A1, A2, A3, A4 ),
151  const A0 & arg0,
152  const A1 & arg1,
153  const A2 & arg2,
154  const A3 & arg3,
155  const A4 & arg4 );
156 
157  private:
158  virtual void makeRemoteCall( typename T::_ptr_type remoteObj );
159 
160  void (T::*methodPtr_)( A0, A1, A2, A3, A4 );
161  const A0 arg0_;
162  const A1 arg1_;
163  const A2 arg2_;
164  const A3 arg3_;
165  const A4 arg4_;
166 };
167 
168 
169 template < typename T,
170  typename A0,
171  typename A1,
172  typename A2,
173  typename A3,
174  typename A4,
175  typename A5,
176  typename A6,
177  typename A7,
178  typename A8 >
179 class RemoteObjMethodFunctor9 : public RemoteObjMethodFunctorBase< T > {
180  public:
181  RemoteObjMethodFunctor9(
182  RemoteObjHandleT< T > * remoteObjHandle,
183  const ::std::string & remoteCallString,
184  void (T::*methodPtr)( A0, A1, A2, A3, A4, A5, A6, A7, A8 ),
185  const A0 & arg0,
186  const A1 & arg1,
187  const A2 & arg2,
188  const A3 & arg3,
189  const A4 & arg4,
190  const A5 & arg5,
191  const A6 & arg6,
192  const A7 & arg7,
193  const A8 & arg8 );
194 
195  private:
196  virtual void makeRemoteCall( typename T::_ptr_type remoteObj );
197 
198  void (T::*methodPtr_)( A0, A1, A2, A3, A4, A5, A6, A7, A8 );
199  const A0 arg0_;
200  const A1 arg1_;
201  const A2 arg2_;
202  const A3 arg3_;
203  const A4 arg4_;
204  const A5 arg5_;
205  const A6 arg6_;
206  const A7 arg7_;
207  const A8 arg8_;
208 };
209 // NOTE: Below here is simply implementation
210 
211 
212 template < typename T >
213 RemoteObjMethodFunctorBase< T >::RemoteObjMethodFunctorBase(
214  RemoteObjHandleT< T > * remoteObjHandle,
215  const ::std::string & remoteCallString ) :
216 remoteObjHandle_( remoteObjHandle ),
217 remoteCallString_( remoteCallString ) {
218 }
219 
220 
221 template < typename T >
222 void
223 RemoteObjMethodFunctorBase< T >::operator()( ) {
224  if ( (remoteObjHandle_ != 0) && remoteObjHandle_->isObjReachable( ) ) {
225  try {
226  typename T::_var_type remoteObject = remoteObjHandle_->remoteObj( );
227 
228  if ( CORBA::is_nil( remoteObject ) == false ) {
229  const double sendTime = util::Time::MJD( );
230 
231  makeRemoteCall( remoteObject );
232 
233  remoteObjHandle_->logSentCommandIfNeeded( remoteCallString_,
234  sendTime );
235  }
236  } catch ( const CORBA::Exception & ex ) {
237  remoteObjHandle_->processException( remoteCallString_, ex );
238  }
239  }
240 }
241 
242 
243 template < typename T >
244 RemoteObjMethodFunctor0< T >::RemoteObjMethodFunctor0(
245  RemoteObjHandleT< T > * remoteObjHandle,
246  const ::std::string & remoteCallString,
247  void (T::*methodPtr)( ) ) :
248 RemoteObjMethodFunctorBase< T >( remoteObjHandle, remoteCallString ),
249 methodPtr_( methodPtr ) {
250 }
251 
252 
253 template < typename T,
254  typename A0 >
255 RemoteObjMethodFunctor1< T, A0 >::RemoteObjMethodFunctor1(
256  RemoteObjHandleT< T > * remoteObjHandle,
257  const ::std::string & remoteCallString,
258  void (T::*methodPtr)( A0 ),
259  const A0 & arg0 ) :
260 RemoteObjMethodFunctorBase< T >( remoteObjHandle, remoteCallString ),
261 methodPtr_( methodPtr ),
262 arg0_( arg0 ) {
263 }
264 
265 
266 template < typename T,
267  typename A0,
268  typename A1 >
269 RemoteObjMethodFunctor2< T, A0, A1 >::RemoteObjMethodFunctor2(
270  RemoteObjHandleT< T > * remoteObjHandle,
271  const ::std::string & remoteCallString,
272  void (T::*methodPtr)( A0, A1 ),
273  const A0 & arg0,
274  const A1 & arg1 ) :
275 RemoteObjMethodFunctorBase< T >( remoteObjHandle, remoteCallString ),
276 methodPtr_( methodPtr ),
277 arg0_( arg0 ),
278 arg1_( arg1 ) {
279 }
280 
281 
282 template < typename T,
283  typename A0,
284  typename A1,
285  typename A2 >
286 RemoteObjMethodFunctor3< T, A0, A1, A2 >::RemoteObjMethodFunctor3(
287  RemoteObjHandleT< T > * remoteObjHandle,
288  const ::std::string & remoteCallString,
289  void (T::*methodPtr)( A0, A1, A2 ),
290  const A0 & arg0,
291  const A1 & arg1,
292  const A2 & arg2 ) :
293 RemoteObjMethodFunctorBase< T >( remoteObjHandle, remoteCallString ),
294 methodPtr_( methodPtr ),
295 arg0_( arg0 ),
296 arg1_( arg1 ),
297 arg2_( arg2 ) {
298 }
299 
300 
301 template < typename T,
302  typename A0,
303  typename A1,
304  typename A2,
305  typename A3 >
306 RemoteObjMethodFunctor4< T, A0, A1, A2, A3 >::RemoteObjMethodFunctor4(
307  RemoteObjHandleT< T > * remoteObjHandle,
308  const ::std::string & remoteCallString,
309  void (T::*methodPtr)( A0, A1, A2, A3 ),
310  const A0 & arg0,
311  const A1 & arg1,
312  const A2 & arg2,
313  const A3 & arg3 ) :
314 RemoteObjMethodFunctorBase< T >( remoteObjHandle, remoteCallString ),
315 methodPtr_( methodPtr ),
316 arg0_( arg0 ),
317 arg1_( arg1 ),
318 arg2_( arg2 ),
319 arg3_( arg3 ) {
320 }
321 
322 
323 template < typename T,
324  typename A0,
325  typename A1,
326  typename A2,
327  typename A3,
328  typename A4 >
329 RemoteObjMethodFunctor5< T, A0, A1, A2, A3, A4 >::RemoteObjMethodFunctor5(
330  RemoteObjHandleT< T > * remoteObjHandle,
331  const ::std::string & remoteCallString,
332  void (T::*methodPtr)( A0, A1, A2, A3, A4 ),
333  const A0 & arg0,
334  const A1 & arg1,
335  const A2 & arg2,
336  const A3 & arg3,
337  const A4 & arg4 ) :
338 RemoteObjMethodFunctorBase< T >( remoteObjHandle, remoteCallString ),
339 methodPtr_( methodPtr ),
340 arg0_( arg0 ),
341 arg1_( arg1 ),
342 arg2_( arg2 ),
343 arg3_( arg3 ),
344 arg4_( arg4 ) {
345 }
346 
347 
348 template < typename T,
349  typename A0,
350  typename A1,
351  typename A2,
352  typename A3,
353  typename A4,
354  typename A5,
355  typename A6,
356  typename A7,
357  typename A8 >
358 RemoteObjMethodFunctor9< T, A0, A1, A2, A3, A4, A5, A6, A7, A8 >::RemoteObjMethodFunctor9(
359  RemoteObjHandleT< T > * remoteObjHandle,
360  const ::std::string & remoteCallString,
361  void (T::*methodPtr)( A0, A1, A2, A3, A4, A5, A6, A7, A8 ),
362  const A0 & arg0,
363  const A1 & arg1,
364  const A2 & arg2,
365  const A3 & arg3,
366  const A4 & arg4,
367  const A5 & arg5,
368  const A6 & arg6,
369  const A7 & arg7,
370  const A8 & arg8 ) :
371 RemoteObjMethodFunctorBase< T >( remoteObjHandle, remoteCallString ),
372 methodPtr_( methodPtr ),
373 arg0_( arg0 ),
374 arg1_( arg1 ),
375 arg2_( arg2 ),
376 arg3_( arg3 ),
377 arg4_( arg4 ),
378 arg5_( arg5 ),
379 arg6_( arg6 ),
380 arg7_( arg7 ),
381 arg8_( arg8 ) {
382 }
383 
384 template < typename T >
385 void
386 RemoteObjMethodFunctor0< T >::makeRemoteCall(
387  typename T::_ptr_type remoteObj ) {
388  (remoteObj->*methodPtr_)( );
389 }
390 
391 
392 template < typename T,
393  typename A0 >
394 void
395 RemoteObjMethodFunctor1< T, A0 >::makeRemoteCall(
396  typename T::_ptr_type remoteObj ) {
397  (remoteObj->*methodPtr_)( arg0_ );
398 }
399 
400 
401 template < typename T,
402  typename A0,
403  typename A1 >
404 void
405 RemoteObjMethodFunctor2< T, A0, A1 >::makeRemoteCall(
406  typename T::_ptr_type remoteObj ) {
407  (remoteObj->*methodPtr_)( arg0_, arg1_ );
408 }
409 
410 
411 template < typename T,
412  typename A0,
413  typename A1,
414  typename A2 >
415 void
416 RemoteObjMethodFunctor3< T, A0, A1, A2 >::makeRemoteCall(
417  typename T::_ptr_type remoteObj ) {
418  (remoteObj->*methodPtr_)( arg0_, arg1_, arg2_ );
419 }
420 
421 
422 template < typename T,
423  typename A0,
424  typename A1,
425  typename A2,
426  typename A3 >
427 void
428 RemoteObjMethodFunctor4< T, A0, A1, A2, A3 >::makeRemoteCall(
429  typename T::_ptr_type remoteObj ) {
430  (remoteObj->*methodPtr_)( arg0_, arg1_, arg2_, arg3_ );
431 }
432 
433 
434 template < typename T,
435  typename A0,
436  typename A1,
437  typename A2,
438  typename A3,
439  typename A4 >
440 void
441 RemoteObjMethodFunctor5< T, A0, A1, A2, A3, A4 >::makeRemoteCall(
442  typename T::_ptr_type remoteObj ) {
443  (remoteObj->*methodPtr_)( arg0_, arg1_, arg2_, arg3_, arg4_ );
444 }
445 
446 template < typename T,
447  typename A0,
448  typename A1,
449  typename A2,
450  typename A3,
451  typename A4,
452  typename A5,
453  typename A6,
454  typename A7,
455  typename A8 >
456 void
457 RemoteObjMethodFunctor9< T, A0, A1, A2, A3, A4, A5, A6, A7, A8 >::makeRemoteCall(
458  typename T::_ptr_type remoteObj ) {
459  (remoteObj->*methodPtr_)( arg0_, arg1_, arg2_, arg3_,
460  arg4_, arg5_, arg6_, arg7_, arg8_ );
461 }
462 
463 
464 } // namespace carma::control
465 } // namespace carma
466 
467 
468 #endif
Common time functions.
Manages connection to remote DO.
static double MJD()
Get current MJD.