bool RTSConnectionExt::connect() { DDEBUG("RTSConnection::connect"); if (!sourcePort || !targetPort) { return false; } if (!sourcePort->port || !targetPort->port || CORBA::is_nil(sourcePort->port) || sourcePort->port->_non_existent() || CORBA::is_nil(targetPort->port) || targetPort->port->_non_existent()) { DDEBUG("RTSConnection::connect False"); return false; } if (sourcePort->isConnectedWith(targetPort)) { return false; } ConnectorProfile cprof; cprof.connector_id = CORBA::string_dup(id.c_str()); cprof.name = CORBA::string_dup(name.c_str()); cprof.ports.length(2); cprof.ports[0] = PortService::_duplicate(sourcePort->port); cprof.ports[1] = PortService::_duplicate(targetPort->port); for (int index = 0; index < propList.size(); index++) { NamedValueExtPtr param = propList[index]; CORBA_SeqUtil::push_back( cprof.properties, NVUtil::newNV(param->name_.c_str(), param->value_.c_str())); } RTC::ReturnCode_t result = sourcePort->port->connect(cprof); if (result == RTC::RTC_OK) { PortProfile_var portprofile = sourcePort->port->get_port_profile(); ConnectorProfileList connections = portprofile->connector_profiles; for (CORBA::ULong i = 0; i < connections.length(); i++) { ConnectorProfile& connector = connections[i]; PortServiceList& connectedPorts = connector.ports; for (CORBA::ULong j = 0; j < connectedPorts.length(); ++j) { PortService_ptr connectedPortRef = connectedPorts[j]; if (connectedPortRef->_is_equivalent(targetPort->port)) { id = string(connector.connector_id); isAlive_ = true; DDEBUG("RTSConnection::connect End"); return true; } } } return false; } DDEBUG("connect Error"); return false; }
bool RTSPortExt::isConnectedWith(RTSPortExt* target) { if (!port || !target->port || CORBA::is_nil(port) || port->_non_existent() || CORBA::is_nil(target->port) || target->port->_non_existent()) { return false; } ConnectorProfileList_var connectorProfiles = port->get_connector_profiles(); for (CORBA::ULong i = 0; i < connectorProfiles->length(); ++i) { ConnectorProfile& connectorProfile = connectorProfiles[i]; PortServiceList& connectedPorts = connectorProfile.ports; for (CORBA::ULong j = 0; j < connectedPorts.length(); ++j) { PortService_ptr connectedPortRef = connectedPorts[j]; if (connectedPortRef->_is_equivalent(target->port)) { return true; } } } return false; }