Go to the documentation of this file.00001
00019 #ifndef DOIL_ORB_MANAGER_H
00020 #define DOIL_ORB_MANAGER_H
00021
00022 #include <string>
00023 #include <vector>
00024 #include <coil/Mutex.h>
00025 #include <doil/doil.h>
00026 #include <doil/ObjectManager.h>
00027 #include <doil/IORB.h>
00028
00029 namespace doil
00030 {
00031 class ORBManager
00032 {
00033 public:
00041 static ORBManager* init(coil::Properties prop)
00042 throw();
00043
00051 static ORBManager& instance()
00052 throw();
00053
00069 virtual void shutdown() throw();
00070
00085 ReturnCode_t addORB(IORB* orb) throw();
00086
00102 IORB* getORB(const char* name) throw();
00103
00119 const std::vector<IORB*> getORBs() throw();
00120
00136 const std::vector<std::string> availableORBs() throw();
00137
00158 IORB* deleteORB(const char* name) throw();
00159
00160
00161
00176 virtual ReturnCodes activateObject(ImplBase* impl,
00177 const char* orbname = "") throw();
00191 virtual ReturnCodes deactivateObject(ImplBase* impl,
00192 const char* orbname = "") throw();
00193
00207 virtual ReturnCodes deactivateObject(const char* name,
00208 const char* orbname = "") throw();
00209
00228 ReturnCode_t deleteObject(ImplBase* impl) throw();
00229
00248 ReturnCode_t deleteObject(const char* name) throw();
00249
00263 const std::vector<ImplBase*> getObjects() throw();
00264
00278 ImplBase* getObject(const char* name) throw();
00279
00280 protected:
00281
00282
00283
00284 private:
00285 ORBManager(){}
00286 ORBManager(const ORBManager&);
00287 ORBManager& operator=(const ORBManager&);
00288 ~ORBManager(){}
00289
00290
00291
00292
00293
00294 private:
00295
00296 static ORBManager* manager;
00297 static coil::Mutex mutex;
00298
00299
00300
00301
00302 class ORBPred
00303 {
00304 public:
00305 ORBPred(const char* name)
00306 : m_name(name)
00307 {
00308 }
00309 ORBPred(IORB* orb)
00310 : m_name(orb->name())
00311 {
00312 }
00313 bool operator()(IORB* orb)
00314 {
00315 return m_name == orb->name();
00316 }
00317 std::string m_name;
00318 };
00319
00320 typedef ObjectManager<const char*, IORB, ORBPred> ORBMap;
00321 ORBMap m_orbs;
00322
00323
00324
00325
00326
00327
00328
00329 class ImplPred
00330 {
00331 public:
00332 ImplPred(const char* name)
00333 : m_name(name)
00334 {
00335 }
00336 ImplPred(ImplBase* impl)
00337 : m_name(impl->name())
00338 {
00339 }
00340 bool operator()(ImplBase* impl)
00341 {
00342 return m_name == impl->name();
00343 }
00344 std::string m_name;
00345 };
00346
00347 typedef ObjectManager<const char*, ImplBase, ImplPred> ImplMap;
00348 ImplMap m_impls;
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362 class orb_shutdown
00363 {
00364 public:
00365 void operator()(IORB* orb)
00366 {
00367 orb->shutdown();
00368 }
00369 };
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384 class collect_orbs
00385 {
00386 public:
00387 void operator()(IORB* orb)
00388 {
00389 orbs_.push_back(orb);
00390 }
00391 std::vector<IORB*> orbs_;
00392 };
00393
00394 class available_orbs
00395 {
00396 public:
00397 void operator()(IORB* orb)
00398 {
00399 orbs_.push_back(orb->name());
00400 }
00401 std::vector<std::string> orbs_;
00402 };
00403
00411 class activate_impl
00412 {
00413 public:
00414 activate_impl(ImplBase* impl,
00415 const char* orbname = "")
00416 : m_impl(impl), m_orbname(orbname)
00417 {
00418 }
00419 void operator()(IORB* orb)
00420 {
00421 if (m_orbname.empty() || m_orbname == orb->name())
00422 {
00423 ReturnCode_t ret = orb->activateObject(m_impl);
00424 retcodes_.push_back(orb->name(), ret);
00425 }
00426 }
00427 ReturnCodes retcodes_;
00428 private:
00429 ImplBase* m_impl;
00430 std::string m_orbname;
00431 };
00432
00433
00441 class deactivate_impl
00442 {
00443 public:
00444 deactivate_impl(ImplBase* impl, const char* orbname = "")
00445 : m_impl(impl), m_orbname(orbname)
00446 {
00447 }
00448 void operator()(IORB* orb)
00449 {
00450 if (m_orbname.empty() || m_orbname == orb->name())
00451 {
00452 ReturnCode_t ret = orb->deactivateObject(m_impl);
00453 retcodes_.push_back(orb->name(), ret);
00454 }
00455 }
00456 ReturnCodes retcodes_;
00457 private:
00458 ImplBase* m_impl;
00459 std::string m_orbname;
00460 };
00461
00462 class deactivate_by_name
00463 {
00464 public:
00465 deactivate_by_name(const char* name, const char* orbname = "")
00466 : m_name(name), m_orbname(orbname)
00467 {
00468 }
00469 void operator()(IORB* orb)
00470 {
00471 if (m_orbname.empty() || m_orbname == orb->name())
00472 {
00473 ReturnCode_t ret(orb->deactivateObject(m_name.c_str()));
00474 retcodes_.push_back(orb->name(), ret);
00475 }
00476 }
00477 ReturnCodes retcodes_;
00478 std::string m_name;
00479 std::string m_orbname;
00480 };
00481
00482 class collect_impl
00483 {
00484 public:
00485 collect_impl()
00486 {
00487 }
00488 void operator()(ImplBase* impl)
00489 {
00490 impls_.push_back(impl);
00491 }
00492 std::vector<ImplBase*> impls_;
00493 };
00494 };
00495 };
00496 #endif // DOIL_ORB_MANAGER_H