SimulationExecutionContext.cpp
Go to the documentation of this file.
00001 #include <rtm/CorbaNaming.h>
00002 #if (!defined(OPENRTM_VERSION042) && !defined(OPENRTM_VERSION110)) || defined(OPENRTM_VERSION_TRUNK)
00003 #include <rtm/Manager.h>
00004 #endif
00005 #include "SimulationExecutionContext.h"
00006 
00007 namespace RTC
00008 {
00009   ReturnCode_t SimulationExecutionContext::start() throw (CORBA::SystemException)
00010   {
00011 
00012     ReturnCode_t ret = OpenHRPExecutionContext::start();
00013     if (ret == RTC_OK){
00014         OpenRTM::ExtTrigExecutionContextService_var extTrigExecContext =
00015                                 OpenRTM::ExtTrigExecutionContextService::_narrow(this->getObjRef());
00016         m_cg->subscribe(extTrigExecContext, 1.0/get_rate());
00017     }
00018     return ret;
00019   }
00020 
00021 
00022   ReturnCode_t SimulationExecutionContext::stop() throw (CORBA::SystemException)
00023   {
00024 #if (defined(OPENRTM_VERSION042) || defined(OPENRTM_VERSION110)) && !defined(OPENRTM_VERSION_TRUNK)
00025     if (!m_running) return RTC::PRECONDITION_NOT_MET;
00026 
00027      OpenRTM::ExtTrigExecutionContextService_var extTrigExecContext =
00028                                 OpenRTM::ExtTrigExecutionContextService::_narrow(this->getObjRef());
00029     m_cg->unsubscribe(extTrigExecContext);
00030 
00031     // stop thread
00032     m_running = false;
00033 
00034     // invoke on_shutdown for each comps.
00035     std::for_each(m_comps.begin(), m_comps.end(), invoke_on_shutdown());
00036 
00037     // change EC thread state
00038   #ifdef OPENRTM_VERSION_042
00039     m_state = false;
00040   #else
00041     //m_running = false;
00042     m_svc = false;
00043   #endif
00044     return RTC::RTC_OK;
00045 #else
00046     ReturnCode_t ret = OpenHRPExecutionContext::stop();
00047     if (ret == RTC_OK){
00048         OpenRTM::ExtTrigExecutionContextService_var extTrigExecContext =
00049                                 OpenRTM::ExtTrigExecutionContextService::_narrow(this->getObjRef());
00050         m_cg->unsubscribe(extTrigExecContext);
00051     }
00052     return RTC::RTC_OK;
00053 #endif
00054   }
00055 
00056   OpenHRP::ClockGenerator_var SimulationExecutionContext::m_cg;
00057 };
00058 
00059 void SimulationECInit(RTC::Manager* manager)
00060 {
00061   RTC::Properties &props = manager->getConfig();
00062   RTC::CorbaNaming cn
00063     = RTC::CorbaNaming(manager->getORB(), props["corba.nameservers"].c_str());
00064   try{
00065     CORBA::Object_ptr obj = cn.resolve("ClockGenerator");
00066     RTC::SimulationExecutionContext::m_cg = OpenHRP::ClockGenerator::_narrow(obj);
00067     
00068 #if defined(OPENRTM_VERSION042) || defined(OPENRTM_VERSION110)
00069     manager->registerECFactory("SimulationEC",
00070                                RTC::ECCreate<RTC::SimulationExecutionContext>,
00071                                RTC::ECDelete<RTC::OpenHRPExecutionContext>);
00072 #else
00073         RTC::ExecutionContextFactory::
00074             instance().addFactory("SimulationEC",
00075                             ::coil::Creator< ::RTC::ExecutionContextBase,
00076                             ::RTC::SimulationExecutionContext>,
00077                             ::coil::Destructor< ::RTC::ExecutionContextBase,
00078                             ::RTC::OpenHRPExecutionContext>);
00079 #endif
00080                        
00081   }catch(RTC::CorbaNaming::NotFound& ex){
00082     std::cerr << "SimultationExecutionContext: can not find ClockGenerator"
00083               << std::endl;
00084   }
00085 }
00086 


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:57