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 "../Logger.hpp"
00044 #include <exception>
00045 #include <stdexcept>
00046
00047 using namespace RTT;
00048 using namespace RTT::detail;
00049 using namespace std;
00050
00051
00052 InputPortInterface::InputPortInterface(std::string const& name, ConnPolicy const& default_policy)
00053 : PortInterface(name)
00054 , cmanager(this)
00055 , default_policy( default_policy )
00056 #ifdef ORO_SIGNALLING_PORTS
00057 , new_data_on_port_event(0)
00058 #else
00059 , msignal_interface(false)
00060 #endif
00061 {}
00062
00063 InputPortInterface::~InputPortInterface()
00064 {
00065 cmanager.disconnect();
00066 #ifdef ORO_SIGNALLING_PORTS
00067 if ( new_data_on_port_event) {
00068 delete new_data_on_port_event;
00069 }
00070 #endif
00071 }
00072
00073 ConnPolicy InputPortInterface::getDefaultPolicy() const
00074 { return default_policy; }
00075
00076 #ifdef ORO_SIGNALLING_PORTS
00077 InputPortInterface::NewDataOnPortEvent* InputPortInterface::getNewDataOnPortEvent()
00078 {
00079 if (!new_data_on_port_event)
00080 new_data_on_port_event = new NewDataOnPortEvent();
00081 return new_data_on_port_event;
00082 }
00083 #endif
00084 bool InputPortInterface::connectTo(PortInterface* other, ConnPolicy const& policy)
00085 {
00086 OutputPortInterface* output = dynamic_cast<OutputPortInterface*>(other);
00087 if (! output) {
00088 log(Error) << "InputPort "<< getName() <<" could not connect to "<< other->getName() << ": not an Output port." <<endlog();
00089 return false;
00090 }
00091 return output->createConnection(*this, policy);
00092 }
00093
00094 bool InputPortInterface::connectTo(PortInterface* other)
00095 {
00096 return connectTo(other, default_policy);
00097 }
00098
00099 bool InputPortInterface::addConnection(ConnID* port_id, ChannelElementBase::shared_ptr channel_output, const ConnPolicy& policy)
00100 {
00101
00102 cmanager.addConnection( port_id, channel_output, policy);
00103 return true;
00104 }
00105
00106 bool InputPortInterface::channelReady(ChannelElementBase::shared_ptr channel)
00107 {
00108 if ( channel && channel->inputReady() )
00109 return true;
00110 if (channel) {
00111
00112
00113
00114
00115
00116 channel->disconnect(false);
00117 channel->disconnect(true);
00118 }
00119
00120 return false;
00121 }
00122
00123 bool InputPortInterface::removeConnection(ConnID* conn)
00124 {
00125 return cmanager.removeConnection(conn);
00126 }
00127
00128 #ifndef ORO_SIGNALLING_PORTS
00129 void InputPortInterface::signal()
00130 {
00131 if (iface && msignal_interface)
00132 iface->dataOnPort(this);
00133 }
00134 void InputPortInterface::signalInterface(bool true_false)
00135 {
00136 msignal_interface = true_false;
00137 }
00138 #endif
00139 FlowStatus InputPortInterface::read(DataSourceBase::shared_ptr source, bool copy_old_data)
00140 { throw std::runtime_error("calling default InputPortInterface::read(datasource) implementation"); }
00142 bool InputPortInterface::connected() const
00143 { return cmanager.connected(); }
00144
00145 void InputPortInterface::clear()
00146 {
00147 cmanager.clear();
00148 }
00149
00150 void InputPortInterface::disconnect()
00151 {
00152 cmanager.disconnect();
00153 }
00154
00155 bool InputPortInterface::disconnect(PortInterface* port)
00156 {
00157 return cmanager.disconnect(port);
00158 }
00159
00160 base::ChannelElementBase::shared_ptr InputPortInterface::buildRemoteChannelOutput(
00161 base::OutputPortInterface& output_port,
00162 types::TypeInfo const* type_info,
00163 base::InputPortInterface& input, const ConnPolicy& policy)
00164 {
00165 return base::ChannelElementBase::shared_ptr();
00166 }
00167