OpenRTM-aist  1.2.2
PortBase.h
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef RTC_PORTBASE_H
21 #define RTC_PORTBASE_H
22 
23 #include <rtm/RTC.h>
24 
25 #include <string>
26 #include <vector>
27 #include <coil/Guard.h>
28 #include <coil/Mutex.h>
29 #include <rtm/idl/RTCSkel.h>
30 #include <rtm/CORBA_SeqUtil.h>
31 #include <rtm/NVUtil.h>
32 #include <rtm/SystemLogger.h>
34 #include <iostream>
35 #include <rtm/DirectPortBase.h>
36 
37 #ifdef WIN32
38 #pragma warning( disable : 4290 )
39 #endif
40 
41 namespace RTC
42 {
43  class ConnectionCallback;
44 
135  class PortBase
136  : public virtual POA_RTC::PortService,
137  public virtual PortableServer::RefCountServantBase
138  {
139  public:
165  PortBase(const char* name = "");
166 
184  virtual ~PortBase(void);
185 
237  virtual PortProfile* get_port_profile()
238  throw (CORBA::SystemException);
239 
265  const PortProfile& getPortProfile() const;
266 
319  virtual ConnectorProfileList* get_connector_profiles()
320  throw (CORBA::SystemException);
321 
361  virtual ConnectorProfile* get_connector_profile(const char* connector_id)
362  throw (CORBA::SystemException);
363 
521  virtual ReturnCode_t connect(ConnectorProfile& connector_profile)
522  throw (CORBA::SystemException);
523 
639  virtual ReturnCode_t notify_connect(ConnectorProfile& connector_profile)
640  throw (CORBA::SystemException);
641 
707  virtual ReturnCode_t disconnect(const char* connector_id)
708  throw (CORBA::SystemException);
709 
798  virtual ReturnCode_t notify_disconnect(const char* connector_id)
799  throw (CORBA::SystemException);
800 
820  virtual ReturnCode_t disconnect_all()
821  throw (CORBA::SystemException);
822 
823  //============================================================
824  // Local operations
825  //============================================================
842  virtual void activateInterfaces() = 0;
843 
860  virtual void deactivateInterfaces() = 0;
861 
881  void setName(const char* name);
882 
900  const char* getName() const;
901 
919  const PortProfile& getProfile() const;
920 
942  void setPortRef(PortService_ptr port_ref);
943 
965  PortService_ptr getPortRef() const;
966 
986  void setOwner(RTObject_ptr owner);
987 
988  //============================================================
989  // callbacks
990  //============================================================
1035  void setOnPublishInterfaces(ConnectionCallback* on_publish);
1036 
1081  void setOnSubscribeInterfaces(ConnectionCallback* on_subscribe);
1082 
1134  void setOnConnected(ConnectionCallback* on_connected);
1135 
1181  void setOnUnsubscribeInterfaces(ConnectionCallback* on_subscribe);
1182 
1226  void setOnDisconnected(ConnectionCallback* on_disconnected);
1227 
1252  void setOnConnectionLost(ConnectionCallback* on_connection_lost);
1253 
1274  void setPortConnectListenerHolder(PortConnectListeners* portconnListeners);
1275 
1289  virtual DirectPortBase* getDirectPort();
1290  //============================================================
1291  // protected operations
1292  //============================================================
1293  protected:
1360  virtual ReturnCode_t
1361  publishInterfaces(ConnectorProfile& connector_profile) = 0;
1362 
1389  virtual ReturnCode_t connectNext(ConnectorProfile& connector_profile);
1390 
1417  virtual ReturnCode_t disconnectNext(ConnectorProfile& connector_profile);
1418 
1482  virtual ReturnCode_t
1483  subscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
1484 
1522  virtual void
1523  unsubscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
1524 
1540  virtual void setConnectionLimit(int limit_value);
1541 
1562  virtual ReturnCode_t _publishInterfaces(void);
1563  //============================================================
1564  // protected utility functions
1565  //============================================================
1592  bool isEmptyId(const ConnectorProfile& connector_profile) const;
1593 
1613  const std::string getUUID() const;
1614 
1634  void setUUID(ConnectorProfile& connector_profile) const;
1635 
1661  bool isExistingConnId(const char* id);
1662 
1692  ConnectorProfile findConnProfile(const char* id);
1693 
1722  CORBA::Long findConnProfileIndex(const char* id);
1723 
1751  void updateConnectorProfile(const ConnectorProfile& connector_profile);
1752 
1782  bool eraseConnectorProfile(const char* id);
1783 
1833  bool appendInterface(const char* name, const char* type_name,
1834  PortInterfacePolarity pol);
1835 
1865  bool deleteInterface(const char* name, PortInterfacePolarity pol);
1866 
1890  template <class ValueType>
1891  void addProperty(const char* key, ValueType value)
1892  {
1894  NVUtil::newNV(key, value));
1895  }
1896 
1922  void appendProperty(const char* key, const char* value)
1923  {
1924  NVUtil::appendStringValue(m_profile.properties, key, value);
1925  }
1934  protected:
1952  void updateConnectors();
1953 
1971 #ifndef ORB_IS_RTORB
1972  bool checkPorts(::RTC::PortServiceList& ports);
1973 #else // ORB_IS_RTORB
1974  bool checkPorts(RTC_PortServiceList& ports);
1975 #endif // ORB_IS_RTORB
1976 
1977 
1978  inline void onNotifyConnect(const char* portname,
1979  RTC::ConnectorProfile& profile)
1980  {
1981  if (m_portconnListeners != NULL)
1982  {
1984  portconnect_[ON_NOTIFY_CONNECT].notify(portname, profile);
1985  }
1986  }
1987 
1988  inline void onNotifyDisconnect(const char* portname,
1989  RTC::ConnectorProfile& profile)
1990  {
1991  if (m_portconnListeners != NULL)
1992  {
1994  portconnect_[ON_NOTIFY_DISCONNECT].notify(portname, profile);
1995  }
1996  }
1997  inline void onUnsubscribeInterfaces(const char* portname,
1998  RTC::ConnectorProfile& profile)
1999  {
2000  if (m_portconnListeners != NULL)
2001  {
2003  portconnect_[ON_UNSUBSCRIBE_INTERFACES].notify(portname, profile);
2004  }
2005  }
2006 
2007  inline void onPublishInterfaces(const char* portname,
2008  RTC::ConnectorProfile& profile,
2009  ReturnCode_t ret)
2010  {
2011  if (m_portconnListeners != NULL)
2012  {
2014  portconnret_[ON_PUBLISH_INTERFACES].notify(portname,
2015  profile, ret);
2016  }
2017  }
2018 
2019  inline void onConnectNextport(const char* portname,
2020  RTC::ConnectorProfile& profile,
2021  ReturnCode_t ret)
2022  {
2023  if (m_portconnListeners != NULL)
2024  {
2026  portconnret_[ON_CONNECT_NEXTPORT].notify(portname,
2027  profile, ret);
2028  }
2029  }
2030 
2031  inline void onSubscribeInterfaces(const char* portname,
2032  RTC::ConnectorProfile& profile,
2033  ReturnCode_t ret)
2034  {
2035  if (m_portconnListeners != NULL)
2036  {
2038  portconnret_[ON_SUBSCRIBE_INTERFACES].notify(portname,
2039  profile, ret);
2040  }
2041  }
2042 
2043  inline void onConnected(const char* portname,
2044  RTC::ConnectorProfile& profile,
2045  ReturnCode_t ret)
2046  {
2047  if (m_portconnListeners != NULL)
2048  {
2050  portconnret_[ON_CONNECTED].notify(portname, profile, ret);
2051  }
2052  }
2053 
2054  inline void onDisconnectNextport(const char* portname,
2055  RTC::ConnectorProfile& profile,
2056  ReturnCode_t ret)
2057  {
2058  if (m_portconnListeners != NULL)
2059  {
2061  portconnret_[ON_DISCONNECT_NEXT].notify(portname, profile, ret);
2062  }
2063  }
2064 
2065  inline void onDisconnected(const char* portname,
2066  RTC::ConnectorProfile& profile,
2067  ReturnCode_t ret)
2068  {
2069  if (m_portconnListeners != NULL)
2070  {
2072  portconnret_[ON_DISCONNECTED].notify(portname, profile, ret);
2073  }
2074  }
2075 
2076  protected:
2084  mutable Logger rtclog;
2092  PortProfile m_profile;
2093 
2101  RTC::PortService_var m_objref;
2112 
2120  std::string m_ownerInstanceName;
2121 
2130 
2203 
2219 
2234 
2236 
2237  //============================================================
2238  // Functor
2239  //============================================================
2248  {
2249  find_conn_id(const char* id) : m_id(id) {};
2250  bool operator()(const ConnectorProfile& cprof)
2251  {
2252  return m_id == std::string(cprof.connector_id);
2253  }
2254  std::string m_id;
2255  }; // struct find_conn_id
2256 
2265  {
2266  find_port_ref(PortService_ptr port_ref) : m_port(port_ref) {};
2267  bool operator()(PortService_ptr port_ref)
2268  {
2269  return m_port->_is_equivalent(port_ref);
2270  }
2271  PortService_ptr m_port;
2272  }; // struct find_port_ref
2273 
2282  {
2283  find_interface(const char* name, PortInterfacePolarity pol)
2284  : m_name(name), m_pol(pol)
2285  {}
2286 
2287  bool operator()(const PortInterfaceProfile& prof)
2288  {
2289  CORBA::String_var name(CORBA::string_dup(prof.instance_name));
2290  return ((m_name == (const char *)name) && (m_pol == prof.polarity));
2291  }
2292  std::string m_name;
2293  PortInterfacePolarity m_pol;
2294  }; // struct find_interface
2295  }; // class PortBase
2296 }; // namespace RTC
2297 
2298 #ifdef WIN32
2299 #pragma warning( default : 4290 )
2300 #endif
2301 
2302 #endif // RTC_PORTBASE_H
RTC::PortBase::onSubscribeInterfaces
void onSubscribeInterfaces(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Definition: PortBase.h:2031
RTC::ON_CONNECT_NEXTPORT
@ ON_CONNECT_NEXTPORT
Definition: PortConnectListener.h:164
RTC::PortBase::_publishInterfaces
virtual ReturnCode_t _publishInterfaces(void)
Publish interface information.
RTC::ON_NOTIFY_CONNECT
@ ON_NOTIFY_CONNECT
Definition: PortConnectListener.h:51
RTC::ON_DISCONNECT_NEXT
@ ON_DISCONNECT_NEXT
Definition: PortConnectListener.h:167
RTC::PortBase::onDisconnectNextport
void onDisconnectNextport(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Definition: PortBase.h:2054
RTC::PortBase::onNotifyConnect
void onNotifyConnect(const char *portname, RTC::ConnectorProfile &profile)
Definition: PortBase.h:1978
RTC::PortBase::deactivateInterfaces
virtual void deactivateInterfaces()=0
Deactivate all Port interfaces.
RTC::PortBase::setOnConnectionLost
void setOnConnectionLost(ConnectionCallback *on_connection_lost)
Setting callback called on connection lost.
RTC::PortBase::connect
virtual ReturnCode_t connect(ConnectorProfile &connector_profile)
[CORBA interface] Connect the Port
RTC::PortBase::onDisconnected
void onDisconnected(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Definition: PortBase.h:2065
RTC::PortBase::setOnPublishInterfaces
void setOnPublishInterfaces(ConnectionCallback *on_publish)
Setting callback called on publish interfaces.
RTC::ON_PUBLISH_INTERFACES
@ ON_PUBLISH_INTERFACES
Definition: PortConnectListener.h:163
coil::Mutex
Mutex class.
Definition: Mutex.h:40
RTC::PortBase::m_connectionLimit
int m_connectionLimit
The maximum number of connections.
Definition: PortBase.h:2129
RTC::PortBase::setConnectionLimit
virtual void setConnectionLimit(int limit_value)
Set the maximum number of connections.
RTC::PortBase::m_onConnectionLost
ConnectionCallback * m_onConnectionLost
Callback functor objects.
Definition: PortBase.h:2218
RTC::PortBase::setPortConnectListenerHolder
void setPortConnectListenerHolder(PortConnectListeners *portconnListeners)
Setting PortConnectListener holder.
RTC::PortBase::m_onPublishInterfaces
ConnectionCallback * m_onPublishInterfaces
Callback functor objects.
Definition: PortBase.h:2145
RTC::PortBase::unsubscribeInterfaces
virtual void unsubscribeInterfaces(const ConnectorProfile &connector_profile)=0
Disconnect interface connection.
RTC::PortBase::get_connector_profile
virtual ConnectorProfile * get_connector_profile(const char *connector_id)
[CORBA interface] Get the ConnectorProfile
RTC::PortBase::isExistingConnId
bool isExistingConnId(const char *id)
Check whether the given id exists in stored ConnectorProfiles.
RTC::PortBase::m_portconnListeners
PortConnectListeners * m_portconnListeners
PortConnectListener holder.
Definition: PortBase.h:2233
RTC::PortBase::appendProperty
void appendProperty(const char *key, const char *value)
Append NameValue data to PortProfile's properties.
Definition: PortBase.h:1922
RTC::PortBase::eraseConnectorProfile
bool eraseConnectorProfile(const char *id)
Delete the ConnectorProfile.
RTC::PortBase::find_port_ref::m_port
PortService_ptr m_port
Definition: PortBase.h:2271
RTC::PortBase::getUUID
const std::string getUUID() const
Generate the UUID.
RTC::PortBase::activateInterfaces
virtual void activateInterfaces()=0
Activate all Port interfaces.
RTC::PortBase::onNotifyDisconnect
void onNotifyDisconnect(const char *portname, RTC::ConnectorProfile &profile)
Definition: PortBase.h:1988
RTC::PortBase::m_objref
RTC::PortService_var m_objref
Object Reference of the Port.
Definition: PortBase.h:2101
RTC::PortBase::find_interface::find_interface
find_interface(const char *name, PortInterfacePolarity pol)
Definition: PortBase.h:2283
RTC::PortBase::find_interface
Functor to find interface from name and polarity.
Definition: PortBase.h:2281
RTC::PortBase::m_directport
DirectPortBase * m_directport
Definition: PortBase.h:2235
RTC::PortBase::onUnsubscribeInterfaces
void onUnsubscribeInterfaces(const char *portname, RTC::ConnectorProfile &profile)
Definition: PortBase.h:1997
RTC::PortBase::find_conn_id::find_conn_id
find_conn_id(const char *id)
Definition: PortBase.h:2249
RTC::PortBase::appendInterface
bool appendInterface(const char *name, const char *type_name, PortInterfacePolarity pol)
Append an interface to the PortInterfaceProfile.
RTC::PortBase::m_onUnsubscribeInterfaces
ConnectionCallback * m_onUnsubscribeInterfaces
Callback functor objects.
Definition: PortBase.h:2188
RTC::PortBase::find_interface::operator()
bool operator()(const PortInterfaceProfile &prof)
Definition: PortBase.h:2287
CORBA_SeqUtil.h
CORBA sequence utility template functions.
RTC::PortBase::m_onDisconnected
ConnectionCallback * m_onDisconnected
Callback functor objects.
Definition: PortBase.h:2202
CORBA_SeqUtil::push_back
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
Definition: CORBA_SeqUtil.h:175
RTC::PortBase::deleteInterface
bool deleteInterface(const char *name, PortInterfacePolarity pol)
Delete the interface registration from the PortInterfaceProfile.
RTC::PortBase::onPublishInterfaces
void onPublishInterfaces(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Definition: PortBase.h:2007
RTC::PortBase::Guard
coil::Guard< coil::Mutex > Guard
Definition: PortBase.h:2111
RTC::PortBase::find_port_ref::find_port_ref
find_port_ref(PortService_ptr port_ref)
Definition: PortBase.h:2266
RTC::ON_NOTIFY_DISCONNECT
@ ON_NOTIFY_DISCONNECT
Definition: PortConnectListener.h:52
Guard.h
Guard template class.
RTC::PortBase::setOnDisconnected
void setOnDisconnected(ConnectionCallback *on_disconnected)
Setting callback called on disconnected.
RTC::ConnectionCallback
Callback functor abstract for connect/notify_connect() funcs.
Definition: PortCallback.h:55
RTC::ON_CONNECTED
@ ON_CONNECTED
Definition: PortConnectListener.h:166
RTC::DirectPortBase
Definition: DirectPortBase.h:46
RTC::PortConnectListeners
PortConnectListeners class.
Definition: PortConnectListener.h:487
RTC::PortBase::find_port_ref::operator()
bool operator()(PortService_ptr port_ref)
Definition: PortBase.h:2267
NVUtil::newNV
SDOPackage::NameValue newNV(const char *name, Value value)
Create NameValue.
Definition: NVUtil.h:79
RTC::PortBase::notify_disconnect
virtual ReturnCode_t notify_disconnect(const char *connector_id)
[CORBA interface] Notify the Ports disconnection
RTC::PortBase::updateConnectorProfile
void updateConnectorProfile(const ConnectorProfile &connector_profile)
Append or update the ConnectorProfile list.
RTC::PortBase::m_properties
coil::Properties m_properties
Properties.
Definition: PortBase.h:1933
RTC::PortBase::disconnect_all
virtual ReturnCode_t disconnect_all()
[CORBA interface] Disconnect the All Ports
RTC::PortBase::find_conn_id
Functor to find a ConnectorProfile named id.
Definition: PortBase.h:2247
RTC::PortBase::disconnectNext
virtual ReturnCode_t disconnectNext(ConnectorProfile &connector_profile)
Call notify_disconnect() of the next Port.
RTC::PortBase::setOnSubscribeInterfaces
void setOnSubscribeInterfaces(ConnectionCallback *on_subscribe)
Setting callback called on publish interfaces.
RTC::PortBase::getPortProfile
const PortProfile & getPortProfile() const
Get the PortProfile of the Port.
RTC::PortBase::m_profile_mutex
coil::Mutex m_profile_mutex
Mutex of PortProfile.
Definition: PortBase.h:2109
RTC::Logger
Logger class.
Definition: SystemLogger.h:99
RTC::ON_SUBSCRIBE_INTERFACES
@ ON_SUBSCRIBE_INTERFACES
Definition: PortConnectListener.h:165
RTC::PortBase::find_port_ref
Functor to find the object reference that is identical port_ref.
Definition: PortBase.h:2264
RTC::PortBase::getName
const char * getName() const
Get the name of this Port.
RTC::PortBase::connectNext
virtual ReturnCode_t connectNext(ConnectorProfile &connector_profile)
Call notify_connect() of the next Port.
RTC::PortBase::m_ownerInstanceName
std::string m_ownerInstanceName
Instance name.
Definition: PortBase.h:2120
RTC::PortBase::addProperty
void addProperty(const char *key, ValueType value)
Add NameValue data to PortProfile's properties.
Definition: PortBase.h:1891
RTC::PortBase::getPortRef
PortService_ptr getPortRef() const
Get the object reference of this Port.
NVUtil::appendStringValue
bool appendStringValue(SDOPackage::NVList &nv, const char *name, const char *value)
Append the specified string to element of NVList.
coil::Properties
Class represents a set of properties.
Definition: Properties.h:101
PortConnectListener.h
port's internal action listener classes
RTC::PortBase
Port base class.
Definition: PortBase.h:135
RTC::PortBase::rtclog
Logger rtclog
Logger stream.
Definition: PortBase.h:2084
RTC::PortBase::subscribeInterfaces
virtual ReturnCode_t subscribeInterfaces(const ConnectorProfile &connector_profile)=0
Publish interface information.
RTC::PortBase::onConnectNextport
void onConnectNextport(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Definition: PortBase.h:2019
RTC::PortBase::get_connector_profiles
virtual ConnectorProfileList * get_connector_profiles()
[CORBA interface] Get the ConnectorProfileList of the Port
NVUtil.h
NameValue and NVList utility functions.
RTC::PortBase::setPortRef
void setPortRef(PortService_ptr port_ref)
Set the object reference of this Port.
RTC::PortBase::~PortBase
virtual ~PortBase(void)
Destructor.
Mutex.h
RTC::PortBase::onConnected
void onConnected(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Definition: PortBase.h:2043
coil::Guard< coil::Mutex >
RTC::PortBase::m_onSubscribeInterfaces
ConnectionCallback * m_onSubscribeInterfaces
Callback functor objects.
Definition: PortBase.h:2159
RTC::PortBase::updateConnectors
void updateConnectors()
Disconnect ports that doesn't exist.
RTC::PortBase::m_connectorsMutex
coil::Mutex m_connectorsMutex
Definition: PortBase.h:2110
RTC::PortBase::setUUID
void setUUID(ConnectorProfile &connector_profile) const
Generate and set the UUID to the ConnectorProfile.
RTC::PortBase::find_interface::m_pol
PortInterfacePolarity m_pol
Definition: PortBase.h:2293
RTC::PortBase::disconnect
virtual ReturnCode_t disconnect(const char *connector_id)
[CORBA interface] Disconnect the Port
RTC::PortBase::find_conn_id::m_id
std::string m_id
Definition: PortBase.h:2254
RTC::PortBase::m_onConnected
ConnectionCallback * m_onConnected
Callback functor objects.
Definition: PortBase.h:2174
RTC::PortBase::getProfile
const PortProfile & getProfile() const
Get the PortProfile of the Port.
RTC::PortBase::publishInterfaces
virtual ReturnCode_t publishInterfaces(ConnectorProfile &connector_profile)=0
Publish interface information.
RTC::PortBase::getDirectPort
virtual DirectPortBase * getDirectPort()
RTC::PortBase::findConnProfile
ConnectorProfile findConnProfile(const char *id)
Find ConnectorProfile with id.
RTC::PortBase::checkPorts
bool checkPorts(::RTC::PortServiceList &ports)
Existence of ports.
RTC
RT-Component.
RTC::ON_DISCONNECTED
@ ON_DISCONNECTED
Definition: PortConnectListener.h:168
RTC::PortBase::setName
void setName(const char *name)
Set the name of this Port.
RTC::PortBase::get_port_profile
virtual PortProfile * get_port_profile()
[CORBA interface] Get the PortProfile of the Port
RTC::PortBase::notify_connect
virtual ReturnCode_t notify_connect(ConnectorProfile &connector_profile)
[CORBA interface] Notify the Ports connection
RTC.h
RTComponent header.
RTC::PortBase::find_conn_id::operator()
bool operator()(const ConnectorProfile &cprof)
Definition: PortBase.h:2250
RTC::PortBase::setOwner
void setOwner(RTObject_ptr owner)
Set the owner RTObject of the Port.
RTC::PortBase::find_interface::m_name
std::string m_name
Definition: PortBase.h:2292
RTC::PortBase::PortBase
PortBase(const char *name="")
Constructor.
RTC::ON_UNSUBSCRIBE_INTERFACES
@ ON_UNSUBSCRIBE_INTERFACES
Definition: PortConnectListener.h:53
RTC::PortBase::setOnUnsubscribeInterfaces
void setOnUnsubscribeInterfaces(ConnectionCallback *on_subscribe)
Setting callback called on unsubscribe interfaces.
RTC::PortBase::setOnConnected
void setOnConnected(ConnectionCallback *on_connected)
Setting callback called on connection established.
RTC::PortBase::isEmptyId
bool isEmptyId(const ConnectorProfile &connector_profile) const
Check whether connector_id of ConnectorProfile is empty.
SystemLogger.h
RT component logger class.
RTC::PortBase::findConnProfileIndex
CORBA::Long findConnProfileIndex(const char *id)
Find ConnectorProfile with id.
RTC::PortBase::m_profile
PortProfile m_profile
PortProfile of the Port.
Definition: PortBase.h:2092
DirectPortBase.h
DirectPortBase class.