22 #include <coil/UUID.h> 40 m_ownerInstanceName(
"unknown"),
41 m_connectionLimit(-1),
42 m_onPublishInterfaces(0),
43 m_onSubscribeInterfaces(0),
45 m_onUnsubscribeInterfaces(0),
47 m_onConnectionLost(0),
48 m_portconnListeners(NULL)
56 m_profile.name = CORBA::string_dup(portname.c_str());
76 PortableServer::ObjectId_var oid = _default_POA()->servant_to_id(
this);
77 _default_POA()->deactivate_object(oid);
79 catch (PortableServer::POA::ServantNotActive &e)
83 catch (PortableServer::POA::WrongPolicy &e)
101 throw (CORBA::SystemException)
107 PortProfile_var prof;
134 throw (CORBA::SystemException)
141 ConnectorProfileList_var conn_prof;
143 return conn_prof._retn();
154 throw (CORBA::SystemException)
156 RTC_TRACE((
"get_connector_profile(%s)", connector_id));
165 ConnectorProfile_var conn_prof;
166 conn_prof =
new ConnectorProfile();
167 return conn_prof._retn();
169 ConnectorProfile_var conn_prof;
170 conn_prof =
new ConnectorProfile(
m_profile.connector_profiles[index]);
171 return conn_prof._retn();
182 throw (CORBA::SystemException)
198 RTC_ERROR((
"Connection already exists."));
205 RTC::PortService_ptr p;
206 p = connector_profile.ports[(CORBA::ULong)0];
210 RTC_ERROR((
"Connection failed. cleanup."));
230 throw (CORBA::SystemException)
240 if (retval[0] != RTC::RTC_OK)
242 RTC_ERROR((
"publishInterfaces() in notify_connect() failed."));
247 (*m_onPublishInterfaces)(connector_profile);
253 if (retval[1] != RTC::RTC_OK)
255 RTC_ERROR((
"connectNext() in notify_connect() failed."));
263 (*m_onSubscribeInterfaces)(connector_profile);
267 if (retval[2] != RTC::RTC_OK)
269 RTC_ERROR((
"subscribeInterfaces() in notify_connect() failed."));
290 for (
int i(0), len(
sizeof(retval)/
sizeof(
ReturnCode_t)); i < len; ++i)
292 if (retval[i] != RTC::RTC_OK)
302 (*m_onConnected)(connector_profile);
321 RTC_PARANOID((
"Connected number has reached the limitation."));
340 throw (CORBA::SystemException)
342 RTC_TRACE((
"disconnect(%s)", connector_id));
347 RTC_ERROR((
"Invalid connector id: %s", connector_id));
351 ConnectorProfile prof;
357 if (prof.ports.length() < 1)
359 RTC_FATAL((
"ConnectorProfile has empty port list."));
363 for (CORBA::ULong i(0), len(prof.ports.length()); i < len; ++i)
365 RTC::PortService_var p(prof.ports[i]);
368 return p->notify_disconnect(connector_id);
370 catch (CORBA::SystemException &e)
373 RTC_WARN((
"Exception caught: minor code(%d).", e.minor()));;
374 #else // ORB_IS_RTORB 376 #endif // ORB_IS_RTORB 381 RTC_WARN((
"Unknown exception caught."));;
385 RTC_ERROR((
"notify_disconnect() for all ports failed."));
397 throw (CORBA::SystemException)
399 RTC_TRACE((
"notify_disconnect(%s)", connector_id));
407 RTC_ERROR((
"Invalid connector id: %s", connector_id));
411 ConnectorProfile& prof(
m_profile.connector_profiles[(CORBA::ULong)index]);
419 (*m_onUnsubscribeInterfaces)(prof);
426 (*m_onDisconnected)(prof);
431 #else // ORB_IS_RTORB 432 CORBA::ULong len(
m_profile.connector_profiles.length());
433 if (index < (CORBA::Long)len)
435 for (CORBA::ULong i(index); i < len - 1; ++i)
440 m_profile.connector_profiles._length=len-1;
442 #endif // ORB_IS_RTORB 455 throw (CORBA::SystemException)
466 CORBA::ULong len(plist.length());
467 RTC_DEBUG((
"disconnecting %d connections.", len));
468 for (CORBA::ULong i(0); i < len; ++i)
471 tmpret =this->
disconnect(plist[i].connector_id);
492 m_profile.name = CORBA::string_dup(name);
561 RTC::ComponentProfile_var prof = owner->get_component_profile();
568 std::string portname((
const char*)
m_profile.name);
573 m_profile.owner = RTC::RTObject::_duplicate(owner);
574 m_profile.name = CORBA::string_dup(portname.c_str());
634 if (++index < static_cast<CORBA::Long>(connector_profile.ports.length()))
636 RTC::PortService_ptr p;
637 p = connector_profile.ports[
index];
638 return p->notify_connect(connector_profile);
659 if (index == cprof.ports.length() - 1)
664 CORBA::ULong len = cprof.ports.length();
667 for (CORBA::ULong i(index); i < len; ++i)
669 RTC::PortService_var p;
673 return p->notify_disconnect(cprof.connector_id);
675 catch (CORBA::SystemException& e)
678 RTC_WARN((
"Exception caught: minor code.", e.minor()));
679 #else // ORB_IS_RTORB 681 #endif // ORB_IS_RTORB 686 RTC_WARN((
"Unknown exception caught."));
717 return connector_profile.connector_id[(CORBA::ULong)0] == 0;
734 return std::string((
const char*)
uuid->to_string());
746 connector_profile.connector_id = CORBA::string_dup(
getUUID().c_str());
747 assert(connector_profile.connector_id[(CORBA::ULong)0] != 0);
828 if (index < 0)
return false;
842 const char* type_name,
849 if (index >= 0)
return false;
851 PortInterfaceProfile prof;
852 prof.instance_name = CORBA::string_dup(instance_name);
853 prof.type_name = CORBA::string_dup(type_name);
873 if (index < 0)
return false;
888 std::vector<std::string> connector_ids;
895 for (CORBA::ULong i(0); i < clist.length(); ++i)
899 const char*
id(clist[i].connector_id);
900 connector_ids.push_back(
id);
901 RTC_WARN((
"Dead connection: %s",
id));
904 #else // ORB_IS_RTORB 908 for (CORBA::ULong i(0); i < clist->length(); ++i)
912 const char*
id((*clist)[i].connector_id);
913 connector_ids.push_back(
id);
914 RTC_WARN((
"Dead connection: %s",
id));
918 #endif // ORB_IS_RTORB 920 std::vector<std::string>::iterator it, it_end;
922 for (std::vector<std::string>::iterator it(connector_ids.begin());
923 it != connector_ids.end(); ++it)
938 #else // ORB_IS_RTORB 940 #endif // ORB_IS_RTORB 942 for (CORBA::ULong i(0), len(ports.length()); i < len; ++i)
946 if (ports[i]->_non_existent())
948 RTC_WARN((
"Dead Port reference detected."));
virtual ReturnCode_t connectNext(ConnectorProfile &connector_profile)
Call notify_connect() of the next Port.
RTC's Port base class.
void setOnSubscribeInterfaces(ConnectionCallback *on_subscribe)
Setting callback called on publish interfaces.
bool isEmptyId(const ConnectorProfile &connector_profile) const
Check whether connector_id of ConnectorProfile is empty.
#define RTC_ERROR(fmt)
Error log output macro.
void onPublishInterfaces(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
void erase(CorbaSequence &seq, CORBA::ULong index)
Erase the element of the specified index.
virtual ConnectorProfileList * get_connector_profiles()
[CORBA interface] Get the ConnectorProfileList of the Port
void setUUID(ConnectorProfile &connector_profile) const
Generate and set the UUID to the ConnectorProfile.
virtual ReturnCode_t notify_connect(ConnectorProfile &connector_profile)
[CORBA interface] Notify the Ports connection
std::string m_ownerInstanceName
Instance name.
ConnectionCallback * m_onSubscribeInterfaces
Callback functor objects.
ConnectionCallback * m_onUnsubscribeInterfaces
Callback functor objects.
void onNotifyConnect(const char *portname, RTC::ConnectorProfile &profile)
void onDisconnectNextport(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
PortService_ptr getPortRef()
Get the object reference of this Port.
coil::Mutex m_connectorsMutex
coil::Mutex m_profile_mutex
Mutex of PortProfile.
Functor to find a ConnectorProfile named id.
void setOnPublishInterfaces(ConnectionCallback *on_publish)
Setting callback called on publish interfaces.
void init()
Initialization.
ConnectionCallback * m_onDisconnected
Callback functor objects.
void onDisconnected(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
void setOnConnected(ConnectionCallback *on_connected)
Setting callback called on connection established.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
virtual ReturnCode_t connect(ConnectorProfile &connector_profile)
[CORBA interface] Connect the Port
const char * getName() const
Get the name of this Port.
void setOwner(RTObject_ptr owner)
Set the owner RTObject of the Port.
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
bool deleteInterface(const char *name, PortInterfacePolarity pol)
Delete the interface registration from the PortInterfaceProfile.
void setName(const char *name)
Set suffix of date/time string of header.
void setOnUnsubscribeInterfaces(ConnectionCallback *on_subscribe)
Setting callback called on unsubscribe interfaces.
virtual ~PortBase(void)
Destructor.
Functor to find interface from name and polarity.
void setPortRef(PortService_ptr port_ref)
Set the object reference of this Port.
#define RTC_WARN(fmt)
Warning log output macro.
#define RTC_FATAL(fmt)
Error log output macro.
#define RTC_PARANOID(fmt)
Paranoid level log output macro.
void onConnectNextport(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
std::vector< std::string > vstring
virtual ReturnCode_t disconnect(const char *connector_id)
[CORBA interface] Disconnect the Port
coil::UUID * generateUUID(ACE_UINT16 version=0x0001, u_char variant=0x80)
std::vector< ConnectorProfile * > ConnectorProfileList
#define RTC_DEBUG(fmt)
Debug level log output macro.
ConnectionCallback * m_onConnected
Callback functor objects.
void setPortConnectListenerHolder(PortConnectListeners *portconnListeners)
Setting PortConnectListener holder.
PortConnectListeners class.
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
virtual ReturnCode_t notify_disconnect(const char *connector_id)
[CORBA interface] Notify the Ports disconnection
PortBase(const char *name="")
Constructor.
void onConnected(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
virtual ConnectorProfile * get_connector_profile(const char *connector_id)
[CORBA interface] Get the ConnectorProfile
CORBA::Long findConnProfileIndex(const char *id)
Find ConnectorProfile with id.
const PortProfile & getProfile() const
Get the PortProfile of the Port.
void setOnConnectionLost(ConnectionCallback *on_connection_lost)
Setting callback called on connection lost.
virtual void unsubscribeInterfaces(const ConnectorProfile &connector_profile)=0
Disconnect interface connection.
void updateConnectors()
Disconnect ports that doesn't exist.
virtual PortProfile * get_port_profile()
[CORBA interface] Get the PortProfile of the Port
PortProfile m_profile
PortProfile of the Port.
virtual ReturnCode_t publishInterfaces(ConnectorProfile &connector_profile)=0
Publish interface information.
PortConnectListeners * m_portconnListeners
PortConnectListener holder.
bool eraseConnectorProfile(const char *id)
Delete the ConnectorProfile.
std::vector< IPortService * > PortServiceList
void onUnsubscribeInterfaces(const char *portname, RTC::ConnectorProfile &profile)
bool isExistingConnId(const char *id)
Check whether the given id exists in stored ConnectorProfiles.
bool appendInterface(const char *name, const char *type_name, PortInterfacePolarity pol)
Append an interface to the PortInterfaceProfile.
virtual ReturnCode_t subscribeInterfaces(const ConnectorProfile &connector_profile)=0
Publish interface information.
void onSubscribeInterfaces(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
void onNotifyDisconnect(const char *portname, RTC::ConnectorProfile &profile)
int m_connectionLimit
The maximum number of connections.
RTC::PortService_var m_objref
Object Reference of the Port.
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
ConnectionCallback * m_onConnectionLost
Callback functor objects.
virtual ReturnCode_t disconnect_all()
[CORBA interface] Disconnect the All Ports
const std::string getUUID() const
Generate the UUID.
ConnectionCallback * m_onPublishInterfaces
Callback functor objects.
virtual ReturnCode_t disconnectNext(ConnectorProfile &connector_profile)
Call notify_disconnect() of the next Port.
bool checkPorts(::RTC::PortServiceList &ports)
Existence of ports.
Functor to find the object reference that is identical port_ref.
void updateConnectorProfile(const ConnectorProfile &connector_profile)
Append or update the ConnectorProfile list.
Callback functor abstract for connect/notify_connect() funcs.
void setName(const char *name)
Set the name of this Port.
ConnectorProfile findConnProfile(const char *id)
Find ConnectorProfile with id.
virtual ReturnCode_t _publishInterfaces(void)
Publish interface information.
void setOnDisconnected(ConnectionCallback *on_disconnected)
Setting callback called on disconnected.
virtual void setConnectionLimit(int limit_value)
Set the maximum number of connections.
Logger rtclog
Logger stream.
const PortProfile & getPortProfile() const
Get the PortProfile of the Port.