CORBAManager.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00018 #ifndef DOIL_CORBA_CORBAMANAGER_H
00019 #define DOIL_CORBA_CORBAMANAGER_H
00020 
00021 #include <coil/Properties.h>
00022 #include <coil/Mutex.h>
00023 #include <coil/Guard.h>
00024 #include <doil/IORB.h>
00025 #include <doil/ServantFactory.h>
00026 #include <doil/ProxyFactory.h>
00027 #include <doil/corba/CORBA.h>
00028 #include <doil/corba/CORBAServantBase.h>
00029 #include <doil/corba/CORBAProxyBase.h>
00030 #include <doil/ObjectManager.h>
00031 
00032 namespace doil
00033 {
00034 namespace CORBA
00035 {
00049   class CORBAManager
00050     : public doil::IORB
00051   {
00052   public:
00053     //
00054     //for unit tests
00055     //
00056 //    doil::LocalBase* toLocal(::CORBA::Object_ptr& obj);
00057     doil::LocalBase* toLocal(::CORBA::Object_ptr& obj)
00058     {
00059         return NULL;
00060     }
00068     static CORBAManager* init(coil::Properties prop)
00069       throw();
00070 
00078     static CORBAManager& instance()
00079       throw();
00080 
00081     //------------------------------------------------------------
00082     // IORB interfaces
00083     //------------------------------------------------------------
00098     virtual const char* name()
00099       throw();
00100 
00101     virtual void run()
00102       throw();
00103     virtual void shutdown()
00104       throw();
00105 
00129     virtual ReturnCode_t
00130     registerFactory(const char* id,
00131                     doil::ServantNewFunc new_func,
00132                     doil::ServantDeleteFunc delete_func)
00133       throw();
00134 #if 1
00135     //
00136     //for unit tests
00137     //
00138     virtual ReturnCode_t
00139     registerProxyFactory(const char* id,
00140                     doil::ProxyNewFunc new_func,
00141                     doil::ProxyDeleteFunc delete_func)
00142       throw();
00143 #endif
00144 
00173     virtual ReturnCode_t activateObject(doil::ImplBase* impl)
00174       throw();
00175 
00206     virtual ReturnCode_t activateObject(doil::ImplBase* impl,
00207                                         doil::ServantBase* servant)
00208       throw();
00209 
00236     virtual ReturnCode_t deactivateObject(doil::ImplBase* impl)
00237       throw();
00238 
00265     virtual ReturnCode_t deactivateObject(const char* name)
00266       throw();
00267 
00294     virtual ImplBase* getImpl(const char* name)
00295       throw();
00296 
00323     virtual ImplBase* toImpl(doil::ServantBase* servant)
00324       throw();
00325 
00352     virtual ServantBase* getServant(const char* name)
00353       throw();
00354 
00381     virtual ServantBase* toServant(doil::ImplBase* lobj)
00382       throw();
00383 
00384     //------------------------------------------------------------
00385     // CORBAManager interfaces
00386     //------------------------------------------------------------
00396     doil::ImplBase* toImpl(::CORBA::Object_ptr obj)
00397       throw();
00398 
00408     ::CORBA::Object_ptr getReference(const char* name)
00409       throw();
00410 
00420     ::CORBA::Object_ptr toReference(doil::ImplBase* impl)
00421       throw();
00422 
00432     ::CORBA::Object_ptr toReference(doil::ServantBase* servant)
00433       throw();
00434 
00444     doil::ServantBase* toServant(::CORBA::Object_ptr obj)
00445       throw();
00446 
00447     //------------------------------------------------------------
00448     // CORBA functions
00449     //------------------------------------------------------------
00459     ::CORBA::ORB_ptr getORB()
00460       throw();
00461 
00471     ::PortableServer::POA_ptr getPOA()
00472       throw();
00473 
00483     ::PortableServer::POAManager_ptr getPOAManager()
00484       throw();
00485 
00486     //------------------------------------------------------------
00487     // protected functions:
00488     //------------------------------------------------------------
00489   protected:
00507     void initOrb(coil::Properties prop);
00508 
00528     std::string createORBOptions();
00529     
00530     //------------------------------------------------------------
00531     // private functions:
00532     //------------------------------------------------------------
00533   private:
00534     // private constructor
00535     CORBAManager(){}
00536     // private big three
00537     CORBAManager(const CORBAManager& cmgr);
00538     CORBAManager& operator=(const CORBAManager& rhs);
00539     ~CORBAManager() throw() {}
00540 
00541     //------------------------------------------------------------
00542     // private data:
00543     //------------------------------------------------------------
00544   private:
00545     // static data member for singleton
00546     static CORBAManager* manager;
00547     static coil::Mutex mutex;
00548 
00549     // CORBA ORB pointer
00550     ::CORBA::ORB_ptr m_orb;
00551 
00552     // default POA pointer
00553     ::PortableServer::POA_ptr m_poa;
00554 
00555     // POAManager pointer
00556     ::PortableServer::POAManager_ptr m_poaManager;
00557 
00558     // configuration properties
00559     coil::Properties m_config;
00560 
00561 
00562     // Entry class for active object map
00563     class Entry
00564     {
00565     public:
00566       Entry(ImplBase* impl, CORBAServantBase* servant,
00567             ::CORBA::Object_ptr objref)
00568         : impl_(impl), servant_(servant), objref_(objref)
00569       {
00570       }
00571       virtual ~Entry()
00572       {
00573       }
00574       ImplBase* impl_;
00575       CORBAServantBase* servant_;
00576       ::CORBA::Object_ptr objref_;
00577     };
00578 
00579     // Predicate class for active object map
00580     class EntryPred
00581     {
00582     public:
00583       EntryPred(const char* name)
00584         : m_name(name)
00585       {
00586       }
00587       EntryPred(Entry* entry)
00588         : m_name(entry->impl_->name())
00589       {
00590       }
00591       bool operator()(Entry* entry)
00592       {
00593         return m_name == entry->impl_->name();
00594       }
00595       std::string m_name;
00596     };
00597     
00598     // Active object map
00599     ObjectManager<const char*, Entry, EntryPred> m_map;
00600 
00601 
00602 
00603 #if 0
00604     //
00605     // for unit test
00606     //
00607     // Entry class for active object map
00608     class EntryProxy
00609     {
00610     public:
00611       EntryProxy(ImplBase* impl, CORBAProxyBase* proxy,
00612             ::CORBA::Object_ptr objref)
00613         : impl_(impl), proxy_(proxy), objref_(objref)
00614       {
00615       }
00616       virtual ~EntryProxy()
00617       {
00618       }
00619       ImplBase* impl_;
00620       CORBAProxyBase* proxy_;
00621       ::CORBA::Object_ptr objref_;
00622     };
00623 
00624     //
00625     // for unit test
00626     //
00627     // Predicate class for active object map
00628     class EntryPredProxy
00629     {
00630     public:
00631       EntryPredProxy(const char* name)
00632         : m_name(name)
00633       {
00634       }
00635       EntryPredProxy(Entry* entry)
00636         : m_name(entry->impl_->name())
00637       {
00638       }
00639       bool operator()(Entry* entry)
00640       {
00641         return m_name == entry->impl_->name();
00642       }
00643       std::string m_name;
00644     };
00645     
00646     //
00647     // for unit test
00648     //
00649     // Active object map
00650     ObjectManager<const char*, EntryProxy, EntryPredProxy> m_map_proxy;
00651 #endif
00652 
00653     // Predicate functor for Factory map
00654     class FactoryPred
00655     {
00656     public:
00657       FactoryPred(const char* id) : m_id(id) {}
00658       FactoryPred(ServantFactory* factory) : m_id(factory->id()) {}
00659       bool operator()(ServantFactory* factory)
00660       {
00661         return m_id == factory->id();
00662       }
00663       std::string m_id;
00664     };
00665     // Servant factory map
00666     ObjectManager<const char*, ServantFactory, FactoryPred> m_factory;
00667 
00668 #if 1
00669     //
00670     // for unit test
00671     //
00672     // Predicate functor for Factory map
00673     class ProxyFactoryPred
00674     {
00675     public:
00676       ProxyFactoryPred(const char* id) : m_id(id) {}
00677       ProxyFactoryPred(ProxyFactory* factory) : m_id(factory->id()) {}
00678       bool operator()(ProxyFactory* factory)
00679       {
00680         return m_id == factory->id();
00681       }
00682       std::string m_id;
00683     };
00684     //
00685     // for unit test
00686     //
00687     // Servant factory map
00688     ObjectManager<const char*, ProxyFactory, ProxyFactoryPred> m_factory_proxy;
00689 #endif
00690   };
00691 };
00692 };
00693 
00694 extern "C"
00695 {
00696   void DoilCORBAInit(coil::Properties& prop);
00697 }
00698 #endif // RTM_CORBA_CORBAMANAGER_H


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:15