IceManager.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00018 #ifndef DOIL_ICE_ICEMANAGER_H
00019 #define DOIL_ICE_ICEMANAGER_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/ice/Ice.h>
00027 #include <doil/ice/IceServantBase.h>
00028 #include <doil/ObjectManager.h>
00029 
00030 namespace doil
00031 {
00032 namespace Ice
00033 {
00047   class IceManager
00048     : public doil::IORB
00049   {
00050   public:
00058     static IceManager* init(coil::Properties prop)
00059       throw();
00060 
00068     static IceManager& instance()
00069       throw();
00070 
00071     //------------------------------------------------------------
00072     // IORB interfaces
00073     //------------------------------------------------------------
00088     virtual const char* name()
00089       throw();
00090 
00091     virtual void run()
00092       throw();
00093     virtual void shutdown()
00094       throw();
00095 
00119     virtual ReturnCode_t
00120     registerFactory(const char* id,
00121                     doil::ServantNewFunc new_func,
00122                     doil::ServantDeleteFunc delete_func)
00123       throw();
00124 
00154     virtual ReturnCode_t activateObject(doil::ImplBase* impl)
00155       throw();
00156 
00187     virtual ReturnCode_t activateObject(doil::ImplBase* impl,
00188                                         doil::ServantBase* servant)
00189       throw();
00190 
00217     virtual ReturnCode_t deactivateObject(doil::ImplBase* impl)
00218       throw();
00219 
00246     virtual ReturnCode_t deactivateObject(const char* name)
00247       throw();
00248 
00275     virtual ImplBase* getImpl(const char* name)
00276       throw();
00277 
00304     virtual ImplBase* toImpl(doil::ServantBase* servant)
00305       throw();
00306 
00333     virtual ServantBase* getServant(const char* name)
00334       throw();
00335 
00362     virtual ServantBase* toServant(doil::ImplBase* lobj)
00363       throw();
00364 
00365     //------------------------------------------------------------
00366     // IceManager interfaces
00367     //------------------------------------------------------------
00377     doil::ImplBase* toImpl(::Ice::ObjectPrx obj)
00378       throw();
00379 
00389     ::Ice::ObjectPrx getReference(const char* name)
00390       throw();
00391 
00401     ::Ice::ObjectPrx toReference(doil::ImplBase* impl)
00402       throw();
00403 
00413     ::Ice::ObjectPrx toReference(doil::ServantBase* servant)
00414       throw();
00415 
00425     doil::ServantBase* toServant(::Ice::ObjectPrx obj)
00426       throw();
00427 
00428     //------------------------------------------------------------
00429     // Ice functions
00430     //------------------------------------------------------------
00440     ::Ice::CommunicatorPtr getORB()
00441       throw();
00442 
00452     ::Ice::ObjectAdapterPtr getAdapter()
00453       throw();
00454 
00455     //------------------------------------------------------------
00456     // protected functions:
00457     //------------------------------------------------------------
00458   protected:
00476     void initIce(coil::Properties prop);
00477 
00497     std::string createIceOptions();
00498     
00499     //------------------------------------------------------------
00500     // private functions:
00501     //------------------------------------------------------------
00502   private:
00503     // private constructor
00504     IceManager(){}
00505     // private big three
00506     IceManager(const IceManager& cmgr);
00507     IceManager& operator=(const IceManager& rhs);
00508     ~IceManager() throw() {}
00509 
00510     //------------------------------------------------------------
00511     // private data:
00512     //------------------------------------------------------------
00513   private:
00514     // static data member for singleton
00515     static IceManager* manager;
00516     static coil::Mutex mutex;
00517 
00518     // Ice communicator pointer
00519     ::Ice::CommunicatorPtr m_ice;
00520 
00521     // Ice object adapter pointer
00522     ::Ice::ObjectAdapterPtr m_adapter;
00523 
00524     // configuration properties
00525     coil::Properties m_config;
00526 
00527 
00528     // Entry class for active object map
00529     class Entry
00530     {
00531     public:
00532       Entry(ImplBase* impl, IceServantBase* servant,
00533             ::Ice::ObjectPrx objref)
00534         : impl_(impl), servant_(servant), objref_(objref)
00535       {
00536       }
00537       virtual ~Entry()
00538       {
00539       }
00540       ImplBase* impl_;
00541       IceServantBase* servant_;
00542       ::Ice::ObjectPrx objref_;
00543     };
00544 
00545     // Predicate class for active object map
00546     class EntryPred
00547     {
00548     public:
00549       EntryPred(const char* name)
00550         : m_name(name)
00551       {
00552       }
00553       EntryPred(Entry* entry)
00554         : m_name(entry->impl_->name())
00555       {
00556       }
00557       bool operator()(Entry* entry)
00558       {
00559         return m_name == entry->impl_->name();
00560       }
00561       std::string m_name;
00562     };
00563     
00564     // Active object map
00565     typedef ObjectManager<const char*, Entry, EntryPred> ObjectMap;
00566     ObjectMap m_map;
00567 
00568     // Predicate functor for Factory map
00569     class FactoryPred
00570     {
00571     public:
00572       FactoryPred(const char* id) : m_id(id) {}
00573       FactoryPred(ServantFactory* factory) : m_id(factory->id()) {}
00574       bool operator()(ServantFactory* factory)
00575       {
00576         return m_id == factory->id();
00577       }
00578       std::string m_id;
00579     };
00580 
00581     // Servant factory map
00582     ObjectManager<const char*, ServantFactory, FactoryPred> m_factory;
00583 
00584 
00585     class find_by_obj
00586     {
00587     public:
00588       find_by_obj(::Ice::ObjectPrx obj) : result_(NULL), m_obj(obj) {};
00589       void operator()(IceManager::Entry* entry)
00590       {
00591         if (m_obj == (entry->objref_))
00592           {
00593             result_ = entry;
00594           }
00595       }
00596     public:
00597       Entry* result_;
00598     private:
00599       ::Ice::ObjectPrx m_obj;
00600     };
00601 
00602 
00603   };
00604 };
00605 };
00606 
00607 extern "C"
00608 {
00609   void DoilIceInit(coil::Properties& prop);
00610 }
00611 #endif // RTM_Ice_IceMANAGER_H


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