OpenRTMUtil.cpp
Go to the documentation of this file.
1 #include <rtm/CorbaNaming.h>
2 #include "OpenRTMUtil.h"
3 
4 int connectPorts(RTC::PortService_ptr outPort, RTC::PortService_ptr inPort)
5 {
6  RTC::ConnectorProfileList_var connectorProfiles = inPort->get_connector_profiles();
7  for(CORBA::ULong i=0; i < connectorProfiles->length(); ++i){
8  RTC::ConnectorProfile& connectorProfile = connectorProfiles[i];
9  RTC::PortServiceList& connectedPorts = connectorProfile.ports;
10 
11  for(CORBA::ULong j=0; j < connectedPorts.length(); ++j){
12  RTC::PortService_ptr connectedPortRef = connectedPorts[j];
13  if(connectedPortRef->_is_equivalent(outPort)){
14  return 1;
15  }
16  }
17  }
18  // connect ports
19  RTC::ConnectorProfile cprof;
20  cprof.connector_id = "";
21  cprof.name = CORBA::string_dup("connector0");
22  cprof.ports.length(2);
23  cprof.ports[0] = RTC::PortService::_duplicate(inPort);
24  cprof.ports[1] = RTC::PortService::_duplicate(outPort);
25 
26  CORBA_SeqUtil::push_back(cprof.properties,
27  NVUtil::newNV("dataport.dataflow_type",
28  "Push"));
29  CORBA_SeqUtil::push_back(cprof.properties,
30  NVUtil::newNV("dataport.interface_type",
31  "corba_cdr"));
32  CORBA_SeqUtil::push_back(cprof.properties,
33  NVUtil::newNV("dataport.subscription_type",
34  "flush"));
35  RTC::ReturnCode_t result = inPort->connect(cprof);
36 
37  if(result == RTC::RTC_OK)
38  return 0;
39  else
40  return -1;
41 }
42 
44 {
45  RTC::ExecutionContextList_var eclist = pRtc->get_owned_contexts();
46  for(CORBA::ULong i=0; i < eclist->length(); ++i){
47  if(!CORBA::is_nil(eclist[i])){
48  eclist[i]->activate_component(pRtc->getObjRef());
49  break;
50  }
51  }
52 }
53 
55 {
56  RTC::ExecutionContextList_var eclist = pRtc->get_owned_contexts();
57  for(CORBA::ULong i=0; i < eclist->length(); ++i){
58  if(!CORBA::is_nil(eclist[i])){
59  eclist[i]->deactivate_component(pRtc->getObjRef());
60  break;
61  }
62  }
63 }
64 
65 const char *getServiceIOR(RTC::RTObject_var rtc,
66  const char *sname)
67 {
68  const char *ior = NULL;
69 
70  RTC::PortServiceList ports;
71  ports = *(rtc->get_ports());
72 
73  RTC::ComponentProfile* cprof;
74  cprof = rtc->get_component_profile();
75  std::string portname = std::string(cprof->instance_name) + "." + sname;
76 
77  for(unsigned int i=0; i < ports.length(); i++)
78  {
79  RTC::PortService_var port = ports[i];
80  RTC::PortProfile* prof = port->get_port_profile();
81  if(std::string(prof->name) == portname)
82  {
83  RTC::ConnectorProfile connProfile;
84  connProfile.name = "noname";
85  connProfile.connector_id = "";
86  connProfile.ports.length(1);
87  connProfile.ports[0] = port;
88  port->connect(connProfile);
89 
90  connProfile.properties[0].value >>= ior;
91 
92  port->disconnect(connProfile.connector_id);
93 
94  return ior;
95  }
96  }
97 
98  return ior;
99 }
100 
101 void setConfiguration(RTC::RTObject_var rtc,
102  const std::string& name, const std::string& value)
103 {
104  SDOPackage::Configuration_ptr cfg = rtc->get_configuration();
105  SDOPackage::ConfigurationSetList_var cfgsets
106  = cfg->get_configuration_sets();
107  if (cfgsets->length()==0){
108  std::cerr << "configuration set is not found" << std::endl;
109  return;
110  }
111  SDOPackage::ConfigurationSet& cfgset = cfgsets[0];
112  SDOPackage::NVList& nv = cfgset.configuration_data;
113  for (size_t i=0; i<nv.length(); i++){
114  if (std::string(nv[i].name) == name){
115  nv[i].value <<= value.c_str();
116  cfg->set_configuration_set_values(cfgset);
117  cfg->activate_configuration_set("default");
118  return;
119  }
120  }
121  std::cerr << "can't find property(" << name << ")" << std::endl;
122 }
123 
124 RTC::RTObject_var findRTC(const std::string &rtcName)
125 {
127  std::string nameServer = manager.getConfig()["corba.nameservers"];
128  int comPos = nameServer.find(",");
129  if (comPos < 0){
130  comPos = nameServer.length();
131  }
132  nameServer = nameServer.substr(0, comPos);
133  RTC::CorbaNaming naming(manager.getORB(), nameServer.c_str());
134  CosNaming::Name name;
135  name.length(1);
136  name[0].id = CORBA::string_dup(rtcName.c_str());
137  name[0].kind = CORBA::string_dup("rtc");
138  try{
139  CORBA::Object_ptr obj = naming.resolve(name);
140  return RTC::RTObject::_narrow(obj);
141  }catch(...){
142  return NULL;
143  }
144 }
145 
SDOPackage::NameValue newNV(const char *name, Value value)
ior
png_infop png_charpp name
manager
CORBA::ORB_ptr getORB()
png_uint_32 i
static Manager & instance()
const char * getServiceIOR(RTC::RTObject_var rtc, const char *sname)
Definition: OpenRTMUtil.cpp:65
nv
coil::Properties & getConfig()
void setConfiguration(RTC::RTObject_var rtc, const std::string &name, const std::string &value)
RTObject_ptr getObjRef() const
virtual ExecutionContextList * get_owned_contexts()
int connectPorts(RTC::PortService_ptr outPort, RTC::PortService_ptr inPort)
Definition: OpenRTMUtil.cpp:4
naming
RTC::RTObject_var findRTC(const std::string &rtcName)
void push_back(CorbaSequence &seq, SequenceElement elem)
void activateRtc(RTC::RtcBase *pRtc)
Definition: OpenRTMUtil.cpp:43
obj
void deactivateRtc(RTC::RtcBase *pRtc)
Definition: OpenRTMUtil.cpp:54


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Sat Dec 17 2022 03:52:20