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 
36 #ifdef WIN32
37 #pragma warning( disable : 4290 )
38 #endif
39 
40 namespace RTC
41 {
42  class ConnectionCallback;
43 
134  class PortBase
135  : public virtual POA_RTC::PortService,
136  public virtual PortableServer::RefCountServantBase
137  {
138  public:
164  PortBase(const char* name = "");
165 
183  virtual ~PortBase(void);
184 
236  virtual PortProfile* get_port_profile()
237  throw (CORBA::SystemException);
238 
264  const PortProfile& getPortProfile() const;
265 
319  throw (CORBA::SystemException);
320 
360  virtual ConnectorProfile* get_connector_profile(const char* connector_id)
361  throw (CORBA::SystemException);
362 
520  virtual ReturnCode_t connect(ConnectorProfile& connector_profile)
521  throw (CORBA::SystemException);
522 
638  virtual ReturnCode_t notify_connect(ConnectorProfile& connector_profile)
639  throw (CORBA::SystemException);
640 
706  virtual ReturnCode_t disconnect(const char* connector_id)
707  throw (CORBA::SystemException);
708 
797  virtual ReturnCode_t notify_disconnect(const char* connector_id)
798  throw (CORBA::SystemException);
799 
819  virtual ReturnCode_t disconnect_all()
820  throw (CORBA::SystemException);
821 
822  //============================================================
823  // Local operations
824  //============================================================
841  virtual void activateInterfaces() = 0;
842 
859  virtual void deactivateInterfaces() = 0;
860 
880  void setName(const char* name);
881 
899  const char* getName() const;
900 
918  const PortProfile& getProfile() const;
919 
941  void setPortRef(PortService_ptr port_ref);
942 
964  PortService_ptr getPortRef();
965 
985  void setOwner(RTObject_ptr owner);
986 
987  //============================================================
988  // callbacks
989  //============================================================
1034  void setOnPublishInterfaces(ConnectionCallback* on_publish);
1035 
1080  void setOnSubscribeInterfaces(ConnectionCallback* on_subscribe);
1081 
1133  void setOnConnected(ConnectionCallback* on_connected);
1134 
1180  void setOnUnsubscribeInterfaces(ConnectionCallback* on_subscribe);
1181 
1225  void setOnDisconnected(ConnectionCallback* on_disconnected);
1226 
1251  void setOnConnectionLost(ConnectionCallback* on_connection_lost);
1252 
1273  void setPortConnectListenerHolder(PortConnectListeners* portconnListeners);
1274 
1275  //============================================================
1276  // protected operations
1277  //============================================================
1278  protected:
1345  virtual ReturnCode_t
1346  publishInterfaces(ConnectorProfile& connector_profile) = 0;
1347 
1374  virtual ReturnCode_t connectNext(ConnectorProfile& connector_profile);
1375 
1402  virtual ReturnCode_t disconnectNext(ConnectorProfile& connector_profile);
1403 
1467  virtual ReturnCode_t
1468  subscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
1469 
1507  virtual void
1508  unsubscribeInterfaces(const ConnectorProfile& connector_profile) = 0;
1509 
1525  virtual void setConnectionLimit(int limit_value);
1526 
1547  virtual ReturnCode_t _publishInterfaces(void);
1548  //============================================================
1549  // protected utility functions
1550  //============================================================
1577  bool isEmptyId(const ConnectorProfile& connector_profile) const;
1578 
1598  const std::string getUUID() const;
1599 
1619  void setUUID(ConnectorProfile& connector_profile) const;
1620 
1646  bool isExistingConnId(const char* id);
1647 
1677  ConnectorProfile findConnProfile(const char* id);
1678 
1707  CORBA::Long findConnProfileIndex(const char* id);
1708 
1736  void updateConnectorProfile(const ConnectorProfile& connector_profile);
1737 
1767  bool eraseConnectorProfile(const char* id);
1768 
1818  bool appendInterface(const char* name, const char* type_name,
1819  PortInterfacePolarity pol);
1820 
1850  bool deleteInterface(const char* name, PortInterfacePolarity pol);
1851 
1875  template <class ValueType>
1876  void addProperty(const char* key, ValueType value)
1877  {
1879  NVUtil::newNV(key, value));
1880  }
1881 
1907  void appendProperty(const char* key, const char* value)
1908  {
1909  NVUtil::appendStringValue(m_profile.properties, key, value);
1910  }
1911 
1912  protected:
1930  void updateConnectors();
1931 
1949 #ifndef ORB_IS_RTORB
1950  bool checkPorts(::RTC::PortServiceList& ports);
1951 #else // ORB_IS_RTORB
1952  bool checkPorts(RTC_PortServiceList& ports);
1953 #endif // ORB_IS_RTORB
1954 
1955 
1956  inline void onNotifyConnect(const char* portname,
1957  RTC::ConnectorProfile& profile)
1958  {
1959  if (m_portconnListeners != NULL)
1960  {
1962  portconnect_[ON_NOTIFY_CONNECT].notify(portname, profile);
1963  }
1964  }
1965 
1966  inline void onNotifyDisconnect(const char* portname,
1967  RTC::ConnectorProfile& profile)
1968  {
1969  if (m_portconnListeners != NULL)
1970  {
1972  portconnect_[ON_NOTIFY_DISCONNECT].notify(portname, profile);
1973  }
1974  }
1975  inline void onUnsubscribeInterfaces(const char* portname,
1976  RTC::ConnectorProfile& profile)
1977  {
1978  if (m_portconnListeners != NULL)
1979  {
1981  portconnect_[ON_UNSUBSCRIBE_INTERFACES].notify(portname, profile);
1982  }
1983  }
1984 
1985  inline void onPublishInterfaces(const char* portname,
1986  RTC::ConnectorProfile& profile,
1987  ReturnCode_t ret)
1988  {
1989  if (m_portconnListeners != NULL)
1990  {
1992  portconnret_[ON_PUBLISH_INTERFACES].notify(portname,
1993  profile, ret);
1994  }
1995  }
1996 
1997  inline void onConnectNextport(const char* portname,
1998  RTC::ConnectorProfile& profile,
1999  ReturnCode_t ret)
2000  {
2001  if (m_portconnListeners != NULL)
2002  {
2004  portconnret_[ON_CONNECT_NEXTPORT].notify(portname,
2005  profile, ret);
2006  }
2007  }
2008 
2009  inline void onSubscribeInterfaces(const char* portname,
2010  RTC::ConnectorProfile& profile,
2011  ReturnCode_t ret)
2012  {
2013  if (m_portconnListeners != NULL)
2014  {
2016  portconnret_[ON_SUBSCRIBE_INTERFACES].notify(portname,
2017  profile, ret);
2018  }
2019  }
2020 
2021  inline void onConnected(const char* portname,
2022  RTC::ConnectorProfile& profile,
2023  ReturnCode_t ret)
2024  {
2025  if (m_portconnListeners != NULL)
2026  {
2028  portconnret_[ON_CONNECTED].notify(portname, profile, ret);
2029  }
2030  }
2031 
2032  inline void onDisconnectNextport(const char* portname,
2033  RTC::ConnectorProfile& profile,
2034  ReturnCode_t ret)
2035  {
2036  if (m_portconnListeners != NULL)
2037  {
2039  portconnret_[ON_DISCONNECT_NEXT].notify(portname, profile, ret);
2040  }
2041  }
2042 
2043  inline void onDisconnected(const char* portname,
2044  RTC::ConnectorProfile& profile,
2045  ReturnCode_t ret)
2046  {
2047  if (m_portconnListeners != NULL)
2048  {
2050  portconnret_[ON_DISCONNECTED].notify(portname, profile, ret);
2051  }
2052  }
2053 
2054  protected:
2062  mutable Logger rtclog;
2070  PortProfile m_profile;
2071 
2079  RTC::PortService_var m_objref;
2090 
2098  std::string m_ownerInstanceName;
2099 
2108 
2181 
2197 
2212 
2213  //============================================================
2214  // Functor
2215  //============================================================
2224  {
2225  find_conn_id(const char* id) : m_id(id) {};
2226  bool operator()(const ConnectorProfile& cprof)
2227  {
2228  return m_id == std::string(cprof.connector_id);
2229  }
2230  std::string m_id;
2231  }; // struct find_conn_id
2232 
2241  {
2242  find_port_ref(PortService_ptr port_ref) : m_port(port_ref) {};
2243  bool operator()(PortService_ptr port_ref)
2244  {
2245  return m_port->_is_equivalent(port_ref);
2246  }
2247  PortService_ptr m_port;
2248  }; // struct find_port_ref
2249 
2258  {
2259  find_interface(const char* name, PortInterfacePolarity pol)
2260  : m_name(name), m_pol(pol)
2261  {}
2262 
2263  bool operator()(const PortInterfaceProfile& prof)
2264  {
2265  CORBA::String_var name(CORBA::string_dup(prof.instance_name));
2266  return ((m_name == (const char *)name) && (m_pol == prof.polarity));
2267  }
2268  std::string m_name;
2270  }; // struct find_interface
2271  }; // class PortBase
2272 }; // namespace RTC
2273 
2274 #ifdef WIN32
2275 #pragma warning( default : 4290 )
2276 #endif
2277 
2278 #endif // RTC_PORTBASE_H
SDOPackage::NameValue newNV(const char *name, Value value)
Create NameValue.
Definition: NVUtil.h:79
virtual ReturnCode_t connectNext(ConnectorProfile &connector_profile)
Call notify_connect() of the next Port.
Definition: PortBase.cpp:626
void setOnSubscribeInterfaces(ConnectionCallback *on_subscribe)
Setting callback called on publish interfaces.
Definition: PortBase.cpp:584
bool isEmptyId(const ConnectorProfile &connector_profile) const
Check whether connector_id of ConnectorProfile is empty.
Definition: PortBase.cpp:715
void onPublishInterfaces(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Definition: PortBase.h:1985
coil::Guard< coil::Mutex > Guard
Definition: PortBase.h:2089
virtual ConnectorProfileList * get_connector_profiles()
[CORBA interface] Get the ConnectorProfileList of the Port
Definition: PortBase.cpp:133
RT-Component.
PortInterfacePolarity m_pol
Definition: PortBase.h:2269
void setUUID(ConnectorProfile &connector_profile) const
Generate and set the UUID to the ConnectorProfile.
Definition: PortBase.cpp:744
virtual ReturnCode_t notify_connect(ConnectorProfile &connector_profile)
[CORBA interface] Notify the Ports connection
Definition: PortBase.cpp:229
std::string m_ownerInstanceName
Instance name.
Definition: PortBase.h:2098
bool operator()(const PortInterfaceProfile &prof)
Definition: PortBase.h:2263
ConnectionCallback * m_onSubscribeInterfaces
Callback functor objects.
Definition: PortBase.h:2137
ConnectionCallback * m_onUnsubscribeInterfaces
Callback functor objects.
Definition: PortBase.h:2166
void onNotifyConnect(const char *portname, RTC::ConnectorProfile &profile)
Definition: PortBase.h:1956
Mutex class.
RT component logger class.
void onDisconnectNextport(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Definition: PortBase.h:2032
find_interface(const char *name, PortInterfacePolarity pol)
Definition: PortBase.h:2259
PortService_ptr getPortRef()
Get the object reference of this Port.
Definition: PortBase.cpp:545
coil::Mutex m_connectorsMutex
Definition: PortBase.h:2088
coil::Mutex m_profile_mutex
Mutex of PortProfile.
Definition: PortBase.h:2087
ReturnCode_t
Definition: doil.h:53
Functor to find a ConnectorProfile named id.
Definition: PortBase.h:2223
bool appendStringValue(SDOPackage::NVList &nv, const char *name, const char *value)
Append the specified string to element of NVList.
Definition: NVUtil.cpp:313
void setOnPublishInterfaces(ConnectionCallback *on_publish)
Setting callback called on publish interfaces.
Definition: PortBase.cpp:579
ConnectionCallback * m_onDisconnected
Callback functor objects.
Definition: PortBase.h:2180
void onDisconnected(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Definition: PortBase.h:2043
void setOnConnected(ConnectionCallback *on_connected)
Setting callback called on connection established.
Definition: PortBase.cpp:589
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
virtual ReturnCode_t connect(ConnectorProfile &connector_profile)
[CORBA interface] Connect the Port
Definition: PortBase.cpp:181
const char * getName() const
Get the name of this Port.
Definition: PortBase.cpp:504
void setOwner(RTObject_ptr owner)
Set the owner RTObject of the Port.
Definition: PortBase.cpp:559
bool deleteInterface(const char *name, PortInterfacePolarity pol)
Delete the interface registration from the PortInterfaceProfile.
Definition: PortBase.cpp:867
bool operator()(PortService_ptr port_ref)
Definition: PortBase.h:2243
void setOnUnsubscribeInterfaces(ConnectionCallback *on_subscribe)
Setting callback called on unsubscribe interfaces.
Definition: PortBase.cpp:594
virtual ~PortBase(void)
Destructor.
Definition: PortBase.cpp:71
Functor to find interface from name and polarity.
Definition: PortBase.h:2257
virtual void activateInterfaces()=0
Activate all Port interfaces.
void setPortRef(PortService_ptr port_ref)
Set the object reference of this Port.
Definition: PortBase.cpp:531
bool operator()(const ConnectorProfile &cprof)
Definition: PortBase.h:2226
void onConnectNextport(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Definition: PortBase.h:1997
virtual ReturnCode_t disconnect(const char *connector_id)
[CORBA interface] Disconnect the Port
Definition: PortBase.cpp:339
std::vector< ConnectorProfile * > ConnectorProfileList
Definition: IPortService.h:50
void appendProperty(const char *key, const char *value)
Append NameValue data to PortProfile&#39;s properties.
Definition: PortBase.h:1907
ConnectionCallback * m_onConnected
Callback functor objects.
Definition: PortBase.h:2152
void setPortConnectListenerHolder(PortConnectListeners *portconnListeners)
Setting PortConnectListener holder.
Definition: PortBase.cpp:610
PortService_ptr m_port
Definition: PortBase.h:2247
PortConnectListeners class.
virtual ReturnCode_t notify_disconnect(const char *connector_id)
[CORBA interface] Notify the Ports disconnection
Definition: PortBase.cpp:396
NameValue and NVList utility functions.
PortBase(const char *name="")
Constructor.
Definition: PortBase.cpp:38
CORBA sequence utility template functions.
void onConnected(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Definition: PortBase.h:2021
virtual ConnectorProfile * get_connector_profile(const char *connector_id)
[CORBA interface] Get the ConnectorProfile
Definition: PortBase.cpp:153
CORBA::Long findConnProfileIndex(const char *id)
Find ConnectorProfile with id.
Definition: PortBase.cpp:785
const PortProfile & getProfile() const
Get the PortProfile of the Port.
Definition: PortBase.cpp:517
void setOnConnectionLost(ConnectionCallback *on_connection_lost)
Setting callback called on connection lost.
Definition: PortBase.cpp:604
virtual void unsubscribeInterfaces(const ConnectorProfile &connector_profile)=0
Disconnect interface connection.
void updateConnectors()
Disconnect ports that doesn&#39;t exist.
Definition: PortBase.cpp:886
virtual PortProfile * get_port_profile()
[CORBA interface] Get the PortProfile of the Port
Definition: PortBase.cpp:100
PortProfile m_profile
PortProfile of the Port.
Definition: PortBase.h:2070
virtual ReturnCode_t publishInterfaces(ConnectorProfile &connector_profile)=0
Publish interface information.
PortConnectListeners * m_portconnListeners
PortConnectListener holder.
Definition: PortBase.h:2211
bool eraseConnectorProfile(const char *id)
Delete the ConnectorProfile.
Definition: PortBase.cpp:823
find_conn_id(const char *id)
Definition: PortBase.h:2225
std::vector< IPortService * > PortServiceList
Definition: IPortService.h:39
void onUnsubscribeInterfaces(const char *portname, RTC::ConnectorProfile &profile)
Definition: PortBase.h:1975
bool isExistingConnId(const char *id)
Check whether the given id exists in stored ConnectorProfiles.
Definition: PortBase.cpp:757
virtual void deactivateInterfaces()=0
Deactivate all Port interfaces.
bool appendInterface(const char *name, const char *type_name, PortInterfacePolarity pol)
Append an interface to the PortInterfaceProfile.
Definition: PortBase.cpp:841
virtual ReturnCode_t subscribeInterfaces(const ConnectorProfile &connector_profile)=0
Publish interface information.
void onSubscribeInterfaces(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Definition: PortBase.h:2009
void onNotifyDisconnect(const char *portname, RTC::ConnectorProfile &profile)
Definition: PortBase.h:1966
int m_connectionLimit
The maximum number of connections.
Definition: PortBase.h:2107
RTC::PortService_var m_objref
Object Reference of the Port.
Definition: PortBase.h:2079
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
RTComponent header.
ConnectionCallback * m_onConnectionLost
Callback functor objects.
Definition: PortBase.h:2196
find_port_ref(PortService_ptr port_ref)
Definition: PortBase.h:2242
virtual ReturnCode_t disconnect_all()
[CORBA interface] Disconnect the All Ports
Definition: PortBase.cpp:454
const std::string getUUID() const
Generate the UUID.
Definition: PortBase.cpp:728
void addProperty(const char *key, ValueType value)
Add NameValue data to PortProfile&#39;s properties.
Definition: PortBase.h:1876
ConnectionCallback * m_onPublishInterfaces
Callback functor objects.
Definition: PortBase.h:2123
virtual ReturnCode_t disconnectNext(ConnectorProfile &connector_profile)
Call notify_disconnect() of the next Port.
Definition: PortBase.cpp:650
bool checkPorts(::RTC::PortServiceList &ports)
Existence of ports.
Definition: PortBase.cpp:937
Functor to find the object reference that is identical port_ref.
Definition: PortBase.h:2240
void updateConnectorProfile(const ConnectorProfile &connector_profile)
Append or update the ConnectorProfile list.
Definition: PortBase.cpp:799
Callback functor abstract for connect/notify_connect() funcs.
Definition: PortCallback.h:55
void setName(const char *name)
Set the name of this Port.
Definition: PortBase.cpp:488
ConnectorProfile findConnProfile(const char *id)
Find ConnectorProfile with id.
Definition: PortBase.cpp:770
port&#39;s internal action listener classes
virtual ReturnCode_t _publishInterfaces(void)
Publish interface information.
Definition: PortBase.cpp:315
void setOnDisconnected(ConnectionCallback *on_disconnected)
Setting callback called on disconnected.
Definition: PortBase.cpp:599
virtual void setConnectionLimit(int limit_value)
Set the maximum number of connections.
Definition: PortBase.cpp:700
Logger rtclog
Logger stream.
Definition: PortBase.h:2062
PortInterfacePolarity
Definition: IRTC.h:55
const PortProfile & getPortProfile() const
Get the PortProfile of the Port.
Definition: PortBase.cpp:119


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