ORBManager.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00019 #include <assert.h>
00020 #include <doil/ORBManager.h>
00021 #include <doil/DefaultConfiguration.h>
00022 
00023 namespace doil
00024 {
00025   // singleton pointer initializer
00026   ORBManager* ORBManager::manager = NULL;
00027   coil::Mutex ORBManager::mutex;
00028 
00029   //------------------------------------------------------------
00030   // public functions
00031   //------------------------------------------------------------
00039   ORBManager* ORBManager::init(coil::Properties prop)
00040     throw()
00041   {
00042     if (!manager)
00043       {
00044         coil::Guard<coil::Mutex> guard(mutex);
00045         if (!manager)
00046           {
00047             manager = new ORBManager();
00048             //            manager->initORBManager(prop);
00049           }
00050       }
00051     return manager;
00052   };
00053 
00061   ORBManager& ORBManager::instance()
00062     throw()
00063   {
00064     return *ORBManager::init(default_config);
00065   }
00066 
00067 
00075   void ORBManager::shutdown() throw()
00076   {
00077     try
00078       {
00079         m_orbs.for_each(orb_shutdown());
00080       }
00081     catch (...)
00082       {
00083         // should never come here
00084         assert(false);
00085         return;
00086       }
00087   }
00088   
00096   ReturnCode_t ORBManager::addORB(IORB* orb) throw()
00097   {
00098     try
00099       {
00100         if (getORB(orb->name()) != NULL) return ALREADY_EXISTS;
00101         m_orbs.registerObject(orb);
00102         return OK;
00103       }
00104     catch (...)
00105       {
00106         // should never come here
00107         assert(false);
00108         return UNKNOWN;
00109       }
00110   }
00111   
00119   IORB* ORBManager::getORB(const char* name) throw()
00120   {
00121     try
00122       {
00123         IORB* orb;
00124         orb = m_orbs.find(name);
00125         if (orb == NULL) return NULL;
00126         return orb;
00127       }
00128     catch (...)
00129       {
00130         // should never come here
00131         assert(false);
00132         return NULL;
00133       }
00134   }
00135   
00143   const std::vector<IORB*> ORBManager::getORBs() throw()
00144   {
00145     try
00146       {
00147         collect_orbs o;
00148         o = m_orbs.for_each(o);
00149         return o.orbs_;
00150       }
00151     catch (...)
00152       {
00153         // should never come here
00154         assert(false);
00155         return std::vector<IORB*>();
00156       }
00157   }
00158   
00166   const std::vector<std::string> ORBManager::availableORBs() throw()
00167   {
00168     try
00169       {
00170         available_orbs o;
00171         o = m_orbs.for_each(o);
00172         return o.orbs_;
00173       }
00174     catch (...)
00175       {
00176         // should never come here
00177         assert(false);
00178         return std::vector<std::string>();
00179       }
00180   }
00181   
00189   IORB* ORBManager::deleteORB(const char* name) throw()
00190   {
00191     if (name == NULL) return NULL;
00192     try
00193       {
00194         return m_orbs.unregisterObject(name);
00195       }
00196     catch (...)
00197       {
00198         // should never come here
00199         assert(false);
00200         return NULL;
00201       }
00202   }
00203   
00211   ReturnCodes
00212   ORBManager::activateObject(ImplBase* impl,
00213                              const char* orbname) throw()
00214   {
00215     if (impl == NULL || orbname == NULL) return ReturnCodes(INVALID_ARGS);
00216     if (getObject(impl->name()) != NULL) return ReturnCodes(ALREADY_EXISTS);
00217 
00218     try
00219       {
00220         activate_impl a(impl, orbname);
00221         a = m_orbs.for_each(a);
00222         return a.retcodes_;
00223       }
00224     catch (...)
00225       {
00226         // should never come here
00227         assert(false);
00228         return ReturnCodes();
00229       }
00230   }
00231   
00239   ReturnCodes
00240   ORBManager::deactivateObject(ImplBase* impl,
00241                                const char* orbname) throw()
00242   {
00243     if (impl == NULL || orbname == NULL) return INVALID_ARGS;
00244     if (getObject(impl->name()) == NULL) return NOT_FOUND;
00245 
00246     try
00247       {
00248         deactivate_impl d(impl, orbname);
00249         d = m_orbs.for_each(d);
00250         return d.retcodes_;
00251       }
00252     catch (...)
00253       {
00254         // should never come here
00255         assert(false);
00256         return ReturnCodes();
00257       }
00258   }
00259   
00260   ReturnCodes
00261   ORBManager::deactivateObject(const char* name,
00262                                const char* orbname) throw()
00263   {
00264     if (name == NULL || orbname == NULL) return INVALID_ARGS;
00265     if (getObject(name) == NULL) return NOT_FOUND;
00266 
00267     try
00268       {
00269         deactivate_by_name d(name, orbname);
00270         d = m_orbs.for_each(d);
00271         return d.retcodes_;
00272       }
00273     catch (...)
00274       {
00275         // should never come here
00276         assert(false);
00277         return ReturnCodes();
00278       }
00279   }
00280   
00281   const std::vector<ImplBase*> ORBManager::getObjects() throw()
00282   {
00283     try
00284       {
00285         collect_impl o;
00286         o = m_impls.for_each(o);
00287         return o.impls_;
00288       }
00289     catch (...)
00290       {
00291         // should never come here
00292         assert(false);
00293         return std::vector<ImplBase*>();
00294       }
00295   }
00296   
00297   
00298   ImplBase* ORBManager::getObject(const char* name) throw()
00299   {
00300     if (name == NULL) return NULL;
00301     try
00302       {
00303         return m_impls.find(name);
00304       }
00305     catch (...)
00306       {
00307         // should never come here
00308         assert(false);
00309         return NULL;
00310       }
00311   }
00312 
00313   //------------------------------------------------------------
00314   // private functions
00315   //------------------------------------------------------------
00316 
00317 };


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:38