Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "PortInterface.hpp"
00040 #include "InputPortInterface.hpp"
00041 #include "OutputPortInterface.hpp"
00042 #include "DataFlowInterface.hpp"
00043 #include "../internal/ConnInputEndPoint.hpp"
00044 #include "../Logger.hpp"
00045 #include <exception>
00046 #include <stdexcept>
00047
00048 using namespace RTT;
00049 using namespace RTT::detail;
00050 using namespace std;
00051
00052
00053 InputPortInterface::InputPortInterface(std::string const& name, ConnPolicy const& default_policy)
00054 : PortInterface(name)
00055 , cmanager(this)
00056 , default_policy( default_policy )
00057 #ifdef ORO_SIGNALLING_PORTS
00058 , new_data_on_port_event(0)
00059 #else
00060 , msignal_interface(false)
00061 #endif
00062 {}
00063
00064 InputPortInterface::~InputPortInterface()
00065 {
00066 cmanager.disconnect();
00067 #ifdef ORO_SIGNALLING_PORTS
00068 if ( new_data_on_port_event) {
00069 delete new_data_on_port_event;
00070 }
00071 #endif
00072 }
00073
00074 ConnPolicy InputPortInterface::getDefaultPolicy() const
00075 { return default_policy; }
00076
00077 #ifdef ORO_SIGNALLING_PORTS
00078 InputPortInterface::NewDataOnPortEvent* InputPortInterface::getNewDataOnPortEvent()
00079 {
00080 if (!new_data_on_port_event)
00081 new_data_on_port_event = new NewDataOnPortEvent();
00082 return new_data_on_port_event;
00083 }
00084 #endif
00085 bool InputPortInterface::connectTo(PortInterface* other, ConnPolicy const& policy)
00086 {
00087 OutputPortInterface* output = dynamic_cast<OutputPortInterface*>(other);
00088 if (! output) {
00089 log(Error) << "InputPort "<< getName() <<" could not connect to "<< other->getName() << ": not an Output port." <<endlog();
00090 return false;
00091 }
00092 return output->createConnection(*this, policy);
00093 }
00094
00095 bool InputPortInterface::connectTo(PortInterface* other)
00096 {
00097 return connectTo(other, default_policy);
00098 }
00099
00100 bool InputPortInterface::addConnection(ConnID* port_id, ChannelElementBase::shared_ptr channel_output, const ConnPolicy& policy)
00101 {
00102
00103 cmanager.addConnection( port_id, channel_output, policy);
00104 return true;
00105 }
00106
00107 bool InputPortInterface::channelReady(ChannelElementBase::shared_ptr channel, RTT::ConnPolicy const& policy)
00108 {
00109
00110 if ( channel ) {
00111 internal::ConnID* cid = channel->getConnID();
00112 if (cid ) {
00113 this->addConnection(cid, channel, policy);
00114 if ( channel->inputReady() )
00115 return true;
00116 } else {
00117 log(Error) << "Can't add ChannelElement which is not a ConnInputEndPoint to Port "<< this->getName() <<endlog();
00118 }
00119 }
00120 if (channel) {
00121
00122
00123
00124
00125
00126 channel->disconnect(false);
00127 channel->disconnect(true);
00128 }
00129
00130 return false;
00131 }
00132
00133 bool InputPortInterface::removeConnection(ConnID* conn)
00134 {
00135 return cmanager.removeConnection(conn);
00136 }
00137
00138 #ifndef ORO_SIGNALLING_PORTS
00139 void InputPortInterface::signal()
00140 {
00141 if (iface && msignal_interface)
00142 iface->dataOnPort(this);
00143 }
00144 void InputPortInterface::signalInterface(bool true_false)
00145 {
00146 msignal_interface = true_false;
00147 }
00148 #endif
00149 FlowStatus InputPortInterface::read(DataSourceBase::shared_ptr source, bool copy_old_data)
00150 { throw std::runtime_error("calling default InputPortInterface::read(datasource) implementation"); }
00152 bool InputPortInterface::connected() const
00153 { return cmanager.connected(); }
00154
00155 void InputPortInterface::clear()
00156 {
00157 cmanager.clear();
00158 }
00159
00160 void InputPortInterface::disconnect()
00161 {
00162 cmanager.disconnect();
00163 }
00164
00165 bool InputPortInterface::disconnect(PortInterface* port)
00166 {
00167 return cmanager.disconnect(port);
00168 }
00169
00170 base::ChannelElementBase::shared_ptr InputPortInterface::buildRemoteChannelOutput(
00171 base::OutputPortInterface& output_port,
00172 types::TypeInfo const* type_info,
00173 base::InputPortInterface& input, const ConnPolicy& policy)
00174 {
00175 return base::ChannelElementBase::shared_ptr();
00176 }
00177