SimulationExecutionContext.cpp
Go to the documentation of this file.
1 #include <rtm/CorbaNaming.h>
2 #if (!defined(OPENRTM_VERSION042) && !defined(OPENRTM_VERSION110)) || defined(OPENRTM_VERSION_TRUNK)
3 #include <rtm/Manager.h>
4 #endif
6 
7 namespace RTC
8 {
9  ReturnCode_t SimulationExecutionContext::start() throw (CORBA::SystemException)
10  {
11 
12  ReturnCode_t ret = OpenHRPExecutionContext::start();
13  if (ret == RTC_OK){
14  OpenRTM::ExtTrigExecutionContextService_var extTrigExecContext =
15  OpenRTM::ExtTrigExecutionContextService::_narrow(this->getObjRef());
16  m_cg->subscribe(extTrigExecContext, 1.0/get_rate());
17  }
18  return ret;
19  }
20 
21 
22  ReturnCode_t SimulationExecutionContext::stop() throw (CORBA::SystemException)
23  {
24 #if (defined(OPENRTM_VERSION042) || defined(OPENRTM_VERSION110)) && !defined(OPENRTM_VERSION_TRUNK)
25  if (!m_running) return RTC::PRECONDITION_NOT_MET;
26 
27  OpenRTM::ExtTrigExecutionContextService_var extTrigExecContext =
28  OpenRTM::ExtTrigExecutionContextService::_narrow(this->getObjRef());
29  m_cg->unsubscribe(extTrigExecContext);
30 
31  // stop thread
32  m_running = false;
33 
34  // invoke on_shutdown for each comps.
35  std::for_each(m_comps.begin(), m_comps.end(), invoke_on_shutdown());
36 
37  // change EC thread state
38  #ifdef OPENRTM_VERSION_042
39  m_state = false;
40  #else
41  //m_running = false;
42  m_svc = false;
43  #endif
44  return RTC::RTC_OK;
45 #else
46  ReturnCode_t ret = OpenHRPExecutionContext::stop();
47  if (ret == RTC_OK){
48  OpenRTM::ExtTrigExecutionContextService_var extTrigExecContext =
49  OpenRTM::ExtTrigExecutionContextService::_narrow(this->getObjRef());
50  m_cg->unsubscribe(extTrigExecContext);
51  }
52  return RTC::RTC_OK;
53 #endif
54  }
55 
56  OpenHRP::ClockGenerator_var SimulationExecutionContext::m_cg;
57 };
58 
59 void SimulationECInit(RTC::Manager* manager)
60 {
61  RTC::Properties &props = manager->getConfig();
62  RTC::CorbaNaming cn
63  = RTC::CorbaNaming(manager->getORB(), props["corba.nameservers"].c_str());
64  try{
65  CORBA::Object_ptr obj = cn.resolve("ClockGenerator");
66  RTC::SimulationExecutionContext::m_cg = OpenHRP::ClockGenerator::_narrow(obj);
67 
68 #if defined(OPENRTM_VERSION042) || defined(OPENRTM_VERSION110)
69  manager->registerECFactory("SimulationEC",
70  RTC::ECCreate<RTC::SimulationExecutionContext>,
71  RTC::ECDelete<RTC::OpenHRPExecutionContext>);
72 #else
73  RTC::ExecutionContextFactory::
74  instance().addFactory("SimulationEC",
75  ::coil::Creator< ::RTC::ExecutionContextBase,
77  ::coil::Destructor< ::RTC::ExecutionContextBase,
78  ::RTC::OpenHRPExecutionContext>);
79 #endif
80 
81  }catch(RTC::CorbaNaming::NotFound& ex){
82  std::cerr << "SimultationExecutionContext: can not find ClockGenerator"
83  << std::endl;
84  }
85 }
86 
hrpPrep.NotFound
NotFound
Definition: hrpPrep.py:129
start
png_size_t start
Definition: png.h:1493
RTC::SimulationExecutionContext::stop
virtual ReturnCode_t stop()
Definition: SimulationExecutionContext.cpp:22
SimulationECInit
void SimulationECInit(RTC::Manager *manager)
Definition: SimulationExecutionContext.cpp:59
viewSimTest.obj
obj
Definition: viewSimTest.py:6
RTC::SimulationExecutionContext::m_cg
static OpenHRP::ClockGenerator_var m_cg
Definition: SimulationExecutionContext.h:16
RTC::SimulationExecutionContext::start
virtual ReturnCode_t start()
Definition: SimulationExecutionContext.cpp:9
SimulationExecutionContext.h
RTC::SimulationExecutionContext
Definition: SimulationExecutionContext.h:11
RTC
Definition: SimulationExecutionContext.cpp:7


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Wed Sep 7 2022 02:51:04