ORBManager.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef DOIL_ORB_MANAGER_H
20 #define DOIL_ORB_MANAGER_H
21 
22 #include <string>
23 #include <vector>
24 #include <coil/Mutex.h>
25 #include <doil/doil.h>
26 #include <doil/ObjectManager.h>
27 #include <doil/IORB.h>
28 
29 namespace doil
30 {
31  class ORBManager
32  {
33  public:
42  throw();
43 
51  static ORBManager& instance()
52  throw();
53 
69  virtual void shutdown() throw();
70 
85  ReturnCode_t addORB(IORB* orb) throw();
86 
102  IORB* getORB(const char* name) throw();
103 
119  const std::vector<IORB*> getORBs() throw();
120 
136  const std::vector<std::string> availableORBs() throw();
137 
158  IORB* deleteORB(const char* name) throw();
159 
160  //------------------------------------------------------------
161 
176  virtual ReturnCodes activateObject(ImplBase* impl,
177  const char* orbname = "") throw();
191  virtual ReturnCodes deactivateObject(ImplBase* impl,
192  const char* orbname = "") throw();
193 
207  virtual ReturnCodes deactivateObject(const char* name,
208  const char* orbname = "") throw();
209 
228  ReturnCode_t deleteObject(ImplBase* impl) throw();
229 
248  ReturnCode_t deleteObject(const char* name) throw();
249 
263  const std::vector<ImplBase*> getObjects() throw();
264 
278  ImplBase* getObject(const char* name) throw();
279 
280  protected:
281  //------------------------------------------------------------
282  // private functions
283  //------------------------------------------------------------
284  private:
286  ORBManager(const ORBManager&);
289 
290 
291  //------------------------------------------------------------
292  // private variables
293  //------------------------------------------------------------
294  private:
295  // static data member for singleton
298 
299  //------------------------------------------------------------
300  // ORB map
301  //------------------------------------------------------------
302  class ORBPred
303  {
304  public:
305  ORBPred(const char* name)
306  : m_name(name)
307  {
308  }
309  ORBPred(IORB* orb)
310  : m_name(orb->name())
311  {
312  }
313  bool operator()(IORB* orb)
314  {
315  return m_name == orb->name();
316  }
317  std::string m_name;
318  };
319 
321  ORBMap m_orbs;
322  // end of ORBMap
323  //------------------------------------------------------------
324 
325 
326  //------------------------------------------------------------
327  // impl object map
328  //------------------------------------------------------------
329  class ImplPred
330  {
331  public:
332  ImplPred(const char* name)
333  : m_name(name)
334  {
335  }
337  : m_name(impl->name())
338  {
339  }
340  bool operator()(ImplBase* impl)
341  {
342  return m_name == impl->name();
343  }
344  std::string m_name;
345  };
346 
348  ImplMap m_impls;
349 
350  // std::vector<IORB*> m_orbs;
351  // std::vector<ImplBase*> m_impl;
352  // typedef std::vector<IORB*>::iterator OrbIt;
353  // typedef std::vector<ImplBase*>::iterator ImplIt;
354 
355 
356  //------------------------------------------------------------
357  // functors for IORB operation
358  //------------------------------------------------------------
359 
360  //------------------------------------------------------------
361  // shutdown ORBs
363  {
364  public:
365  void operator()(IORB* orb)
366  {
367  orb->shutdown();
368  }
369  };
370  //
371 // class find_orb
372 // {
373 // public:
374 // find_orb(const char* name) : m_name(name)
375 // {
376 // }
377 // bool operator()(IORB* orb)
378 // {
379 // return m_name == orb->name();
380 // }
381 // std::string m_name;
382 // };
383 
385  {
386  public:
387  void operator()(IORB* orb)
388  {
389  orbs_.push_back(orb);
390  }
391  std::vector<IORB*> orbs_;
392  };
393 
395  {
396  public:
397  void operator()(IORB* orb)
398  {
399  orbs_.push_back(orb->name());
400  }
401  std::vector<std::string> orbs_;
402  };
403 
412  {
413  public:
415  const char* orbname = "")
416  : m_impl(impl), m_orbname(orbname)
417  {
418  }
419  void operator()(IORB* orb)
420  {
421  if (m_orbname.empty() || m_orbname == orb->name())
422  {
423  ReturnCode_t ret = orb->activateObject(m_impl);
424  retcodes_.push_back(orb->name(), ret);
425  }
426  }
428  private:
430  std::string m_orbname;
431  };
432 
433 
442  {
443  public:
444  deactivate_impl(ImplBase* impl, const char* orbname = "")
445  : m_impl(impl), m_orbname(orbname)
446  {
447  }
448  void operator()(IORB* orb)
449  {
450  if (m_orbname.empty() || m_orbname == orb->name())
451  {
452  ReturnCode_t ret = orb->deactivateObject(m_impl);
453  retcodes_.push_back(orb->name(), ret);
454  }
455  }
457  private:
459  std::string m_orbname;
460  };
461 
463  {
464  public:
465  deactivate_by_name(const char* name, const char* orbname = "")
466  : m_name(name), m_orbname(orbname)
467  {
468  }
469  void operator()(IORB* orb)
470  {
471  if (m_orbname.empty() || m_orbname == orb->name())
472  {
473  ReturnCode_t ret(orb->deactivateObject(m_name.c_str()));
474  retcodes_.push_back(orb->name(), ret);
475  }
476  }
478  std::string m_name;
479  std::string m_orbname;
480  };
481 
483  {
484  public:
486  {
487  }
488  void operator()(ImplBase* impl)
489  {
490  impls_.push_back(impl);
491  }
492  std::vector<ImplBase*> impls_;
493  };
494  };
495 }; // namespace doil
496 #endif // DOIL_ORB_MANAGER_H
ObjectManager< const char *, ImplBase, ImplPred > ImplMap
Definition: ORBManager.h:347
std::vector< IORB * > orbs_
Definition: ORBManager.h:391
virtual ReturnCodes deactivateObject(ImplBase *impl, const char *orbname="")
Deactivate object.
Definition: ORBManager.cpp:240
bool operator()(ImplBase *impl)
Definition: ORBManager.h:340
void operator()(ImplBase *impl)
Definition: ORBManager.h:488
A functor to deactivate a given impl object.
Definition: ORBManager.h:441
Mutex class.
ReturnCode_t
Definition: doil.h:53
std::vector< std::string > orbs_
Definition: ORBManager.h:401
virtual void shutdown()
shutdown ORBManager
Definition: ORBManager.cpp:75
ObjectManager< const char *, IORB, ORBPred > ORBMap
Definition: ORBManager.h:320
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
static ORBManager * manager
Definition: ORBManager.h:296
ImplBase * getObject(const char *name)
Delete object.
Definition: ORBManager.cpp:298
ImplPred(ImplBase *impl)
Definition: ORBManager.h:336
ORBManager & operator=(const ORBManager &)
virtual ReturnCode_t deactivateObject(ImplBase *impl)=0
Deactivate object.
static ORBManager & instance()
getting instance
Definition: ORBManager.cpp:61
virtual void shutdown()=0
Shutdown ORB.
IORB * deleteORB(const char *name)
Delete registered ORB by name.
Definition: ORBManager.cpp:189
deactivate_impl(ImplBase *impl, const char *orbname="")
Definition: ORBManager.h:444
virtual const char * name()=0
Getting ORB&#39;s name.
virtual ReturnCode_t activateObject(ImplBase *impl)=0
Activate object.
static coil::Mutex mutex
Definition: ORBManager.h:297
const std::vector< ImplBase * > getObjects()
Delete object.
Definition: ORBManager.cpp:281
prop
Organization::get_organization_property ();.
std::vector< ImplBase * > impls_
Definition: ORBManager.h:492
ReturnCode_t addORB(IORB *orb)
Register an ORB to the ORBManager.
Definition: ORBManager.cpp:96
virtual const char * name()=0
Class represents a set of properties.
Definition: Properties.h:101
activate_impl(ImplBase *impl, const char *orbname="")
Definition: ORBManager.h:414
bool operator()(IORB *orb)
Definition: ORBManager.h:313
const std::vector< std::string > availableORBs()
Get all the ORBs&#39; name that are registered in this ORBManager.
Definition: ORBManager.cpp:166
static ORBManager * init(coil::Properties prop)
initializer
Definition: ORBManager.cpp:39
ImplPred(const char *name)
Definition: ORBManager.h:332
IORB * getORB(const char *name)
Get an ORB that is registered in this ORBManager.
Definition: ORBManager.cpp:119
ORBPred(const char *name)
Definition: ORBManager.h:305
doil
Generic ORB interface.
deactivate_by_name(const char *name, const char *orbname="")
Definition: ORBManager.h:465
ReturnCode_t deleteObject(ImplBase *impl)
Delete object.
virtual ReturnCodes activateObject(ImplBase *impl, const char *orbname="")
Activate object.
Definition: ORBManager.cpp:212
A functor to activate a given impl object.
Definition: ORBManager.h:411
const std::vector< IORB * > getORBs()
Get all the ORBs that are registered in this ORBManager.
Definition: ORBManager.cpp:143


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:25:59