Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
void RTSPropertiesViewImpl::showConnection(PortService_var port, string id, QTreeWidgetItem* item)//ComponentProfile_var cprofile, string port, string id, QTreeWidgetItem* item)
{
    item->setText(0, _("Connector Profile"));
    item->setIcon(0, QIcon(":/RTSystemEditor/icons/IconConnector.png"));

    if(CORBA::is_nil(port) || port->_non_existent())
        return;
    PortProfile_var portprofile = port->get_port_profile();
    ConnectorProfileList connections = portprofile->connector_profiles;
    for(CORBA::ULong i = 0; i < connections.length(); i++){
        ConnectorProfile connector = connections[i];
        if(id == string(connector.connector_id)){
            PortServiceList& connectedPorts = connector.ports;

            QTreeWidgetItem* conPropChild = new QTreeWidgetItem;
            conPropChild->setText(0, _("Connector ID"));
            conPropChild->setText(1, QString(connector.connector_id));
            item->addChild(conPropChild);

            //conPropChild = new RTSTreeItem(RTSTreeItem::RTS_ITEM_NAME_TYPE);
            conPropChild = new QTreeWidgetItem;
            conPropChild->setText(0, _("Name"));
            conPropChild->setText(1, QString(connector.name));
            // keep the values of connection.
            //this->connItem->name = string(connector.name);
            item->addChild(conPropChild);

            coil::Properties cproperties = NVUtil::toProperties(connector.properties);
            vector<string> names = cproperties.propertyNames();
            for (vector<string>::iterator iter = names.begin(); iter != names.end(); iter++) {
                    // view the attribute of rtc-connection.
                string name = (*iter).c_str();
                //QTreeWidgetItem* connPropChild = judgementType(name);
                conPropChild = new QTreeWidgetItem;
                conPropChild->setText(0, QString(name.c_str()));
                conPropChild->setText(1, QString((cproperties[*iter]).c_str()));
                item->addChild(conPropChild);
            }

            // Show the port informations.
            CORBA::ULong pslen(connectedPorts.length());
            for (CORBA::ULong k = 0; k < pslen; k++) {
                PortService_var pservice = connectedPorts[k];
                PortProfile* pprofile = pservice->get_port_profile();

                showPortConcrete(pprofile, item);
            }
        }
    }

}