bool DataPool::Connection::addPort(RTT::base::PortInterface *port) { RTT::base::InputPortInterface *inputPort = dynamic_cast<RTT::base::InputPortInterface *>(port); RTT::base::OutputPortInterface *outputPort = dynamic_cast<RTT::base::OutputPortInterface *>(port); if (inputPort) { if (readers.count(inputPort)) { RTT::log(RTT::Error) << "InputPort " << inputPort->getName() << " is already a member of this connection" << RTT::endlog(); return false; } readers.insert(inputPort); this->internalOutputPort->connectTo(inputPort); for(std::set<RTT::base::OutputPortInterface *>::iterator it = writers.begin(); it != writers.end(); ++it) (*it)->connectTo(inputPort); return true; } if (outputPort) { if (writers.count(outputPort)) { RTT::log(RTT::Error) << "OutputPort " << outputPort->getName() << " is already a member of this connection" << RTT::endlog(); return false; } writers.insert(outputPort); outputPort->connectTo(this->internalInputPort); for(std::set<RTT::base::InputPortInterface *>::iterator it = readers.begin(); it != readers.end(); ++it) outputPort->connectTo(*it); return true; } return false; }
// report a specific connection. bool Logger::reportPort(const std::string& component, const std::string& port ) { TaskContext* comp = this->getPeer(component); if ( !comp ) { log(Error) << "no such component " << component << endlog(); return false; } RTT::base::OutputPortInterface* writer = dynamic_cast<RTT::base::OutputPortInterface*>(comp->ports()->getPort(port)); if ( !writer ) { log(Error) << "component " << component << " does not have a port named " << port << ", or it is a read port" << endlog(); return false; } std::string portname(component + "." + port); RTT::base::PortInterface *pi = ports()->getPort(portname); if(pi) // we are already reporting this port { log(Info) << "port " << port << " of component " << component << " is already logged" << endlog(); return true; } // Create the corresponding read port RTT::base::InputPortInterface* reader = static_cast<RTT::base::InputPortInterface*>(writer->antiClone()); reader->setName(portname); writer->createBufferConnection(*reader, 25); return addLoggingPort(reader, portname); }
bool RemoteOutputPort::createConnection( RTT::base::InputPortInterface& sink, RTT::ConnPolicy const& policy ) { try { CConnPolicy cpolicy = toCORBA(policy); // first check if we're connecting to another remote: RemoteInputPort* rip = dynamic_cast<RemoteInputPort*>(&sink); if ( rip ){ CDataFlowInterface_var cdfi = rip->getDataFlowInterface(); if ( dataflow->createConnection( this->getName().c_str(), cdfi.in() , sink.getName().c_str(), cpolicy ) ) { policy.name_id = cpolicy.name_id; return true; } else return false; } // !!! only if sink is local: // this dynamic CDataFlowInterface lookup is tricky, we re/ab-use the DataFlowInterface pointer of sink ! CDataFlowInterface_ptr cdfi = CDataFlowInterface_i::getRemoteInterface( sink.getInterface(), mpoa.in() ); if ( dataflow->createConnection( this->getName().c_str(), cdfi , sink.getName().c_str(), cpolicy ) ) { policy.name_id = cpolicy.name_id; return true; } } catch(CORBA::Exception& e) { log(Error) <<"Remote call to "<< getName() <<".createConnection() failed with a CORBA exception: aborting connection."<<endlog(); log(Error) << CORBA_EXCEPTION_INFO( e ) <<endlog(); return false; } return false; }
RTT::OutputPort<T> &getWriter(RTT::ConnPolicy const& policy) { if(!writer) { writer = dynamic_cast<RTT::OutputPort<T> * >(port->antiClone()); RTT::TaskContext *clientTask = getClientTask(); clientTask->addPort(*writer); port->connectTo(writer, policy); } return *writer; };
void DataPool::Connection::removePort(RTT::base::PortInterface *port) { RTT::base::InputPortInterface *inputPort = dynamic_cast<RTT::base::InputPortInterface *>(port); RTT::base::OutputPortInterface *outputPort = dynamic_cast<RTT::base::OutputPortInterface *>(port); if (inputPort) { this->internalOutputPort->disconnect(inputPort); inputPort->disconnect(); readers.erase(inputPort); } if (outputPort) { this->internalInputPort->disconnect(outputPort); outputPort->disconnect(); writers.erase(outputPort); } }
~InputProxyPort() { removeWriter(); port->disconnect(); }
RTT::OutputPort<T> &getWriter() { return getWriter(port->getDefaultPolicy()); }