CorbaPort.h
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef RTC_CORBAPORT_H
21 #define RTC_CORBAPORT_H
22 
23 #include <rtm/PortBase.h>
24 #include <rtm/CorbaConsumer.h>
25 #include <rtm/NVUtil.h>
26 #include <list>
27 
42 namespace RTC
43 {
620  class CorbaPort
621  : public PortBase
622  {
623  public:
650  CorbaPort(const char* name);
651 
663  virtual ~CorbaPort(void);
664 
692  void init(coil::Properties& prop);
693 
732  bool registerProvider(const char* instance_name, const char* type_name,
733  PortableServer::RefCountServantBase& provider);
734 
776  bool registerConsumer(const char* instance_name, const char* type_name,
777  CorbaConsumerBase& consumer);
778 
779  protected:
861  virtual ReturnCode_t
862  publishInterfaces(ConnectorProfile& connector_profile);
863 
996  virtual ReturnCode_t
997  subscribeInterfaces(const ConnectorProfile& connector_profile);
998 
1020  virtual void
1021  unsubscribeInterfaces(const ConnectorProfile& connector_profile);
1022 
1023  //============================================================
1024  // Local operations
1025  //============================================================
1042  virtual void activateInterfaces();
1043 
1060  virtual void deactivateInterfaces();
1061 
1062  protected:
1071 
1072  private:
1073  class CorbaConsumerHolder;
1104  virtual bool findProvider(const NVList& nv, CorbaConsumerHolder& cons,
1105  std::string& iorstr);
1106 
1141  virtual bool findProviderOld(const NVList&nv, CorbaConsumerHolder& cons,
1142  std::string& iorstr);
1143 
1171  bool setObject(const std::string& ior, CorbaConsumerHolder& cons);
1172 
1199  bool releaseObject(const std::string& ior, CorbaConsumerHolder& cons);
1200 
1201  private:
1218  {
1219  public:
1220  CorbaProviderHolder(const char* type_name,
1221  const char* instance_name,
1222  PortableServer::RefCountServantBase* servant)
1223  : m_typeName(type_name),
1224  m_instanceName(instance_name),
1225  m_servant(servant),
1226  m_ior()
1227  {
1228 #ifndef ORB_IS_RTORB
1229  m_oid = Manager::instance().getPOA()->servant_to_id(m_servant);
1230  try
1231  {
1233  getPOA()->activate_object_with_id(m_oid, m_servant);
1234  }
1235  catch(...)
1236  {
1237  ;
1238  }
1239  CORBA::Object_var obj;
1240  obj = Manager::instance().getPOA()->id_to_reference(m_oid);
1241  CORBA::ORB_ptr orb = Manager::instance().getORB();
1242  CORBA::String_var ior_var = orb->object_to_string(obj);
1243  m_ior = ior_var;
1244  deactivate();
1245 #else // ORB_IS_RTORB
1246  // why RtORB does not activate object by __this()
1247  // and does not deactivate at the end of ctor?
1248  m_oid = Manager::instance().getPOA()->servant_to_id(m_servant);
1249  CORBA::Object_var obj;
1250  obj = CORBA::Object_var(m_servant->__this());
1251  CORBA::ORB_ptr orb = Manager::instance().getORB();
1252  CORBA::String_var ior_var = orb->object_to_string(obj);
1253  m_ior = ior_var;
1254 #endif // ORB_IS_RTORB
1255  }
1257  {
1258  deactivate();
1259  }
1260  std::string instanceName() { return m_instanceName; }
1261  std::string typeName() { return m_typeName; }
1262  std::string ior() { return m_ior; }
1263  std::string descriptor() { return m_typeName + "." + m_instanceName; }
1264 
1265  void activate()
1266  {
1267  try
1268  {
1270  getPOA()->activate_object_with_id(m_oid, m_servant);
1271  }
1272  catch(const ::PortableServer::POA::ServantAlreadyActive &)
1273  {
1274  ; // do nothing
1275  }
1276  catch(...)
1277  {
1278  ; // do nothing
1279  }
1280  }
1281  void deactivate()
1282  {
1283  try
1284  {
1285  Manager::instance().getPOA()->deactivate_object(m_oid);
1286  }
1287  catch(...)
1288  {
1289  ; // do nothing
1290  }
1291  }
1292  private:
1293  std::string m_typeName;
1294  std::string m_instanceName;
1295  PortableServer::RefCountServantBase* m_servant;
1296  PortableServer::ObjectId_var m_oid;
1297  std::string m_ior;
1298  };
1299 
1307  typedef std::vector<CorbaProviderHolder> CorbaProviderList;
1308  CorbaProviderList m_providers;
1309 
1318  {
1319  public:
1320  CorbaConsumerHolder(const char* type_name,
1321  const char* instance_name,
1322  CorbaConsumerBase* consumer)
1323  : m_typeName(type_name),
1324  m_instanceName(instance_name),
1325  m_consumer(consumer),
1326  m_ior("")
1327  {
1328  }
1329  std::string instanceName() { return m_instanceName; }
1330  std::string typeName() { return m_typeName; }
1331  std::string descriptor() { return m_typeName + "." + m_instanceName; }
1332 
1333  bool setObject(const char* ior)
1334  {
1335  m_ior = ior;
1336  CORBA::ORB_ptr orb = ::RTC::Manager::instance().getORB();
1337  CORBA::Object_var obj = orb->string_to_object(ior);
1338  if (CORBA::is_nil(obj))
1339  {
1340  return false;
1341  }
1342 
1343  return m_consumer->setObject(obj.in());
1344  }
1346  {
1347  m_consumer->releaseObject();
1348  }
1349  const std::string& getIor()
1350  {
1351  return m_ior;
1352  }
1353  private:
1354  std::string m_typeName;
1355  std::string m_instanceName;
1357  std::string m_ior;
1358  };
1359  typedef std::vector<CorbaConsumerHolder> CorbaConsumerList;
1360  CorbaConsumerList m_consumers;
1361 
1362  // functors
1371  {
1372  unsubscribe(CorbaConsumerList& consumers)
1373  : m_consumers(consumers)
1374  {
1375  }
1376 
1377  void operator()(const SDOPackage::NameValue& nv)
1378  {
1379  for (CorbaConsumerList::iterator it(m_consumers.begin());
1380  it != m_consumers.end(); ++it)
1381  {
1382  std::string name(nv.name);
1383  if (it->descriptor() == (const char*)nv.name)
1384  {
1385  it->releaseObject();
1386  }
1387  }
1388  }
1389  CorbaConsumerList& m_consumers;
1390  };
1391  };
1392 };
1393 #endif // RTC_CORBAPORT_H
RTC&#39;s Port base class.
CORBA Consumer class.
RT-Component.
virtual ReturnCode_t publishInterfaces(ConnectorProfile &connector_profile)
Publish information about interfaces.
Definition: CorbaPort.cpp:192
coil::Properties m_properties
Properties.
Definition: CorbaPort.h:1070
std::vector< CorbaProviderHolder > CorbaProviderList
vector to stored Providers&#39; information
Definition: CorbaPort.h:1307
std::vector< CorbaConsumerHolder > CorbaConsumerList
Definition: CorbaPort.h:1359
void operator()(const SDOPackage::NameValue &nv)
Definition: CorbaPort.h:1377
CorbaPort(const char *name)
Constructor.
Definition: CorbaPort.cpp:36
PortableServer::POA_ptr getPOA()
Get a pointer to RootPOA held by Manager.
Definition: Manager.cpp:845
PortableServer::ObjectId_var m_oid
Definition: CorbaPort.h:1296
unsubscribe(CorbaConsumerList &consumers)
Definition: CorbaPort.h:1372
ReturnCode_t
Definition: doil.h:53
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
void init(coil::Properties &prop)
Initializing properties.
Definition: CorbaPort.cpp:60
CorbaProviderList m_providers
Definition: CorbaPort.h:1308
CORBA::ORB_ptr getORB()
Get the pointer to ORB.
Definition: Manager.cpp:832
static Manager & instance()
Get instance of the manager.
Definition: Manager.cpp:140
CorbaConsumerBase * m_consumer
Definition: CorbaPort.h:1356
virtual ~CorbaPort(void)
Virtual destructor.
Definition: CorbaPort.cpp:49
bool setObject(const char *ior)
Definition: CorbaPort.h:1333
The structure to be stored Consumer information.
Definition: CorbaPort.h:1317
CorbaConsumerHolder(const char *type_name, const char *instance_name, CorbaConsumerBase *consumer)
Definition: CorbaPort.h:1320
NameValue and NVList utility functions.
The structure to be stored Provider information.
Definition: CorbaPort.h:1217
Functor to release Consumer&#39;s object.
Definition: CorbaPort.h:1370
PortableServer::RefCountServantBase * m_servant
Definition: CorbaPort.h:1295
const std::string & getIor()
Definition: CorbaPort.h:1349
virtual void unsubscribeInterfaces(const ConnectorProfile &connector_profile)
Unsubscribe interfaces.
Definition: CorbaPort.cpp:312
virtual void deactivateInterfaces()
Deactivate all Port interfaces.
Definition: CorbaPort.cpp:171
prop
Organization::get_organization_property ();.
bool setObject(const std::string &ior, CorbaConsumerHolder &cons)
Setting IOR to Consumer.
Definition: CorbaPort.cpp:414
virtual ReturnCode_t subscribeInterfaces(const ConnectorProfile &connector_profile)
Subscribe to interface.
Definition: CorbaPort.cpp:256
Class represents a set of properties.
Definition: Properties.h:101
virtual bool findProvider(const NVList &nv, CorbaConsumerHolder &cons, std::string &iorstr)
Find out a provider corresponding to the consumer from NVList.
Definition: CorbaPort.cpp:345
CorbaConsumerList m_consumers
Definition: CorbaPort.h:1360
virtual bool findProviderOld(const NVList &nv, CorbaConsumerHolder &cons, std::string &iorstr)
Find out a provider corresponding to the consumer from NVList.
Definition: CorbaPort.cpp:386
bool releaseObject(const std::string &ior, CorbaConsumerHolder &cons)
Releasing Consumer Object.
Definition: CorbaPort.cpp:442
bool registerConsumer(const char *instance_name, const char *type_name, CorbaConsumerBase &consumer)
Register the consumer.
Definition: CorbaPort.cpp:125
virtual void activateInterfaces()
Activate all Port interfaces.
Definition: CorbaPort.cpp:154
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)
Register the provider.
Definition: CorbaPort.cpp:90
CorbaProviderHolder(const char *type_name, const char *instance_name, PortableServer::RefCountServantBase *servant)
Definition: CorbaPort.h:1220
CorbaConsumerList & m_consumers
Definition: CorbaPort.h:1389


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:25:58