Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
Change narrowing to OpenRTM::ExtTrigExecutionContextService to narrow…
Browse files Browse the repository at this point in the history
… to RTC::ExecutionContextService. #201
  • Loading branch information
ga-sakamoto committed Dec 16, 2017
1 parent 19a5140 commit 8afd1d3
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 34 deletions.
39 changes: 31 additions & 8 deletions src/OpenRTMPlugin/ControllerRTCItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class ControllerRTCItemImpl
public:
ControllerRTCItem* self;
RTC::RtcBase* rtc = 0;
OpenRTM::ExtTrigExecutionContextService_var execContext;
RTC::ExecutionContextService_var execContext;
OpenRTM::ExtTrigExecutionContextService_var execContextExt;
bool isChoreonoidExecutionContext;

int periodicRateProperty;
Expand Down Expand Up @@ -386,12 +387,12 @@ bool ControllerRTCItemImpl::createRTCmain()
periodicRate = boost::lexical_cast<int>(rtc->getProperties()["exec_cxt.periodic.rate"]);
}

execContext = OpenRTM::ExtTrigExecutionContextService::_nil();
execContext = RTC::ExecutionContextService::_nil();
isChoreonoidExecutionContext = false;
RTC::ExecutionContextList_var eclist = rtc->get_owned_contexts();
for(CORBA::ULong i=0; i < eclist->length(); ++i){
if(!CORBA::is_nil(eclist[i])){
execContext = OpenRTM::ExtTrigExecutionContextService::_narrow(eclist[i]);
execContext = RTC::ExecutionContextService::_narrow(eclist[i]);
isChoreonoidExecutionContext = execContextType.is(CHOREONOID_EXECUTION_CONTEXT);
break;
}
Expand Down Expand Up @@ -446,16 +447,26 @@ bool ControllerRTCItemImpl::start()
if(!CORBA::is_nil(execContext)){
RTC::ReturnCode_t result = RTC::RTC_OK;
RTC::LifeCycleState state = execContext->get_component_state(rtc->getObjRef());
if (CORBA::is_nil(execContextExt)) {
execContextExt = OpenRTM::ExtTrigExecutionContextService::_narrow(execContext);
}

if(state == RTC::ERROR_STATE){
result = execContext->reset_component(rtc->getObjRef());
execContext->tick();
if (!CORBA::is_nil(execContextExt)) {
execContextExt->tick();
}
} else if(state == RTC::ACTIVE_STATE){
result = execContext->deactivate_component(rtc->getObjRef());
execContext->tick();
if (!CORBA::is_nil(execContextExt)) {
execContextExt->tick();
}
}
if(result == RTC::RTC_OK){
result = execContext->activate_component(rtc->getObjRef());
execContext->tick();
if (!CORBA::is_nil(execContextExt)) {
execContextExt->tick();
}
}
if(result == RTC::RTC_OK){
isReady = true;
Expand All @@ -482,7 +493,14 @@ void ControllerRTCItem::input()
bool ControllerRTCItem::control()
{
if(impl->isChoreonoidExecutionContext){
impl->execContext->tick();
if (!CORBA::is_nil(impl->execContext)) {
if (CORBA::is_nil(impl->execContextExt)) {
impl->execContextExt = OpenRTM::ExtTrigExecutionContextService::_narrow(impl->execContext);
}
if (!CORBA::is_nil(impl->execContextExt)) {
impl->execContextExt->tick();
}
}
}
return true;
}
Expand All @@ -508,7 +526,12 @@ void ControllerRTCItemImpl::stop()
} else {
execContext->deactivate_component(rtc->getObjRef());
}
execContext->tick();
if (CORBA::is_nil(execContextExt)) {
execContextExt = OpenRTM::ExtTrigExecutionContextService::_narrow(execContext);
}
if (!CORBA::is_nil(execContextExt)) {
execContextExt->tick();
}
}


Expand Down
56 changes: 35 additions & 21 deletions src/OpenRTMPlugin/deprecated/BodyRTCItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,12 @@ void BodyRTCItem::createRTC(BodyPtr body)
virtualRobotRTC = dynamic_cast<VirtualRobotRTC*>(rtc);
virtualRobotRTC->createPorts(bridgeConf);

virtualRobotEC = OpenRTM::ExtTrigExecutionContextService::_nil();
virtualRobotExtEC = OpenRTM::ExtTrigExecutionContextService::_nil();
virtualRobotEC = RTC::ExecutionContextService::_nil();
RTC::ExecutionContextList_var eclist = virtualRobotRTC->get_owned_contexts();
for(CORBA::ULong i=0; i < eclist->length(); ++i){
if(!CORBA::is_nil(eclist[i])){
virtualRobotEC = OpenRTM::ExtTrigExecutionContextService::_narrow(eclist[i]);
virtualRobotEC = RTC::ExecutionContextService::_narrow(eclist[i]);
break;
}
}
Expand Down Expand Up @@ -368,26 +369,31 @@ void BodyRTCItem::input()

bool BodyRTCItem::control()
{
// tick the execution context of the connected RTCs
virtualRobotRTC->writeDataToOutPorts(controlTime_, timeStep_);
// tick the execution context of the connected RTCs
virtualRobotRTC->writeDataToOutPorts(controlTime_, timeStep_);

if(!CORBA::is_nil(virtualRobotEC)){
executionCycleCounter += timeStep_;
if(executionCycleCounter + timeStep_ / 2.0 > executionCycle){
if(!CORBA::is_nil(virtualRobotEC)){
executionCycleCounter += timeStep_;
if(executionCycleCounter + timeStep_ / 2.0 > executionCycle){

#ifdef ENABLE_SIMULATION_PROFILING
timer.begin();
timer.begin();
#endif

virtualRobotEC->tick();
if (CORBA::is_nil(virtualRobotExtEC)) {
virtualRobotExtEC = OpenRTM::ExtTrigExecutionContextService::_narrow(virtualRobotEC);
}
if (!CORBA::is_nil(virtualRobotExtEC)) {
virtualRobotExtEC->tick();
}

#ifdef ENABLE_SIMULATION_PROFILING
bodyRTCTime = timer.measure();
bodyRTCTime = timer.measure();
#endif

executionCycleCounter -= executionCycle;
}
}
executionCycleCounter -= executionCycle;
}
}

#ifdef ENABLE_SIMULATION_PROFILING
timer.begin();
Expand All @@ -398,8 +404,13 @@ bool BodyRTCItem::control()
if(!CORBA::is_nil(rtcInfo->execContext)){
rtcInfo->timeRateCounter += rtcInfo->timeRate;
if(rtcInfo->timeRateCounter + rtcInfo->timeRate/2.0 > 1.0){
rtcInfo->execContext->tick();
rtcInfo->timeRateCounter -= 1.0;
if (CORBA::is_nil(rtcInfo->execContextExt)) {
rtcInfo->execContextExt = OpenRTM::ExtTrigExecutionContextService::_narrow(rtcInfo->execContext);
}
if (!CORBA::is_nil(rtcInfo->execContextExt)) {
rtcInfo->execContextExt->tick();
rtcInfo->timeRateCounter -= 1.0;
}
}
}
}
Expand Down Expand Up @@ -750,12 +761,12 @@ BodyRTCItem::RtcInfoPtr BodyRTCItem::addRtcVectorWithConnection(RTC::RTObject_va
RTC::ExecutionContextList_var eclist = rtcInfo->rtcRef->get_owned_contexts();
for(CORBA::ULong i=0; i < eclist->length(); ++i){
if(!CORBA::is_nil(eclist[i])){
rtcInfo->execContext = OpenRTM::ExtTrigExecutionContextService::_narrow(eclist[i]);
rtcInfo->execContext = RTC::ExecutionContextService::_narrow(eclist[i]);
SDOPackage::NVList& properties = rtcInfo->rtcRef->get_component_profile()->properties;
const char* ec_type(0);
NVUtil::find(properties, "exec_cxt.periodic.type") >>= ec_type;
if(!CORBA::is_nil(rtcInfo->execContext)){
mv->putln(_("detected the ExtTrigExecutionContext"));
mv->putln(_("detected the ExecutionContext"));
}
break;
}
Expand Down Expand Up @@ -795,7 +806,7 @@ void BodyRTCItem::activateComponents()

void BodyRTCItem::deactivateComponents()
{
std::vector<OpenRTM::ExtTrigExecutionContextService_var> vecExecContext;
std::vector<RTC::ExecutionContextService_var> vecExecContext;

for(RtcInfoVector::iterator p = rtcInfoVector.begin(); p != rtcInfoVector.end(); ++p){
RtcInfoPtr& rtcInfo = *p;
Expand All @@ -808,7 +819,7 @@ void BodyRTCItem::deactivateComponents()
RTC::ExecutionContextList_var eclist = virtualRobotRTC->get_owned_contexts();
for(CORBA::ULong i=0; i < eclist->length(); ++i){
if(!CORBA::is_nil(eclist[i])){
OpenRTM::ExtTrigExecutionContextService_var execContext = OpenRTM::ExtTrigExecutionContextService::_narrow(eclist[i]);
RTC::ExecutionContextService_var execContext = RTC::ExecutionContextService::_narrow(eclist[i]);
if(!CORBA::is_nil(execContext)){
execContext->deactivate_component(virtualRobotRTC->getObjRef());
vecExecContext.push_back(execContext);
Expand All @@ -817,10 +828,13 @@ void BodyRTCItem::deactivateComponents()
}
}

for( std::vector<OpenRTM::ExtTrigExecutionContextService_var>::iterator ite = vecExecContext.begin();
for( std::vector<RTC::ExecutionContextService_var>::iterator ite = vecExecContext.begin();
ite != vecExecContext.end(); ++ite ){
if(!CORBA::is_nil( *ite )){
(*ite)->tick();
OpenRTM::ExtTrigExecutionContextService_var extEC = OpenRTM::ExtTrigExecutionContextService::_narrow(*ite);
if (!CORBA::is_nil(extEC)) {
extEC->tick();
}
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/OpenRTMPlugin/deprecated/BodyRTCItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ class CNOID_EXPORT BodyRTCItem : public ControllerItem
RTC::CorbaNaming* naming;
BridgeConf* bridgeConf;
VirtualRobotRTC* virtualRobotRTC;
OpenRTM::ExtTrigExecutionContextService_var virtualRobotEC;

RTC::ExecutionContextService_var virtualRobotEC;
OpenRTM::ExtTrigExecutionContextService_var virtualRobotExtEC;

Selection configMode;
bool autoConnect;
RTComponent* rtcomp;
Expand All @@ -110,7 +111,8 @@ class CNOID_EXPORT BodyRTCItem : public ControllerItem
{
RTC::RTObject_var rtcRef;
PortMap portMap;
OpenRTM::ExtTrigExecutionContextService_var execContext;
RTC::ExecutionContextService_var execContext;
OpenRTM::ExtTrigExecutionContextService_var execContextExt;
double timeRate;
double timeRateCounter;
};
Expand Down
4 changes: 2 additions & 2 deletions src/OpenRTMPlugin/deprecated/VirtualRobotRTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ void VirtualRobotRTC::addConnectedRtcs(RTC::PortService_ptr portRef, RTC::RTCLis
for(CORBA::ULong k=0; k < execServices->length(); k++) {
RTC::ExecutionContext_var execContext = execServices[k];

OpenRTM::ExtTrigExecutionContextService_var extTrigExecContext =
OpenRTM::ExtTrigExecutionContextService::_narrow(execContext);
RTC::ExecutionContextService_var extTrigExecContext =
RTC::ExecutionContextService::_narrow(execContext);

if(!CORBA::is_nil(extTrigExecContext)){
CORBA::ULong n = rtcList.length();
Expand Down

0 comments on commit 8afd1d3

Please sign in to comment.