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 "../Logger.hpp"
00043
00044 using namespace RTT;
00045 using namespace detail;
00046 using namespace std;
00047
00048
00049 InputPortInterface::InputPortInterface(std::string const& name, ConnPolicy const& default_policy)
00050 : PortInterface(name)
00051 , cmanager(this)
00052 , default_policy( default_policy )
00053 , new_data_on_port_event(0) {}
00054
00055 InputPortInterface::~InputPortInterface()
00056 {
00057 cmanager.disconnect();
00058 if ( new_data_on_port_event) {
00059 delete new_data_on_port_event;
00060 }
00061 }
00062
00063 ConnPolicy InputPortInterface::getDefaultPolicy() const
00064 { return default_policy; }
00065
00066 InputPortInterface::NewDataOnPortEvent* InputPortInterface::getNewDataOnPortEvent()
00067 {
00068 if (!new_data_on_port_event)
00069 new_data_on_port_event = new NewDataOnPortEvent();
00070 return new_data_on_port_event;
00071 }
00072
00073 bool InputPortInterface::connectTo(PortInterface* other, ConnPolicy const& policy)
00074 {
00075 OutputPortInterface* output = dynamic_cast<OutputPortInterface*>(other);
00076 if (! output) {
00077 log(Error) << "InputPort "<< getName() <<" could not connect to "<< other->getName() << ": not an Output port." <<endlog();
00078 return false;
00079 }
00080 return output->createConnection(*this, policy);
00081 }
00082
00083 bool InputPortInterface::connectTo(PortInterface* other)
00084 {
00085 return connectTo(other, default_policy);
00086 }
00087
00088 bool InputPortInterface::addConnection(ConnID* port_id, ChannelElementBase::shared_ptr channel_output, const ConnPolicy& policy)
00089 {
00090
00091 cmanager.addConnection( port_id, channel_output, policy);
00092 return true;
00093 }
00094
00095 bool InputPortInterface::channelReady(ChannelElementBase::shared_ptr channel)
00096 {
00097 if ( channel && channel->inputReady() )
00098 return true;
00099 if (channel) {
00100
00101
00102
00103
00104
00105 channel->disconnect(false);
00106 channel->disconnect(true);
00107 }
00108
00109 return false;
00110 }
00111
00112 bool InputPortInterface::removeConnection(ConnID* conn)
00113 {
00114 return cmanager.removeConnection(conn);
00115 }
00116
00117 FlowStatus InputPortInterface::read(DataSourceBase::shared_ptr source, bool copy_old_data)
00118 { throw std::runtime_error("calling default InputPortInterface::read(datasource) implementation"); }
00120 bool InputPortInterface::connected() const
00121 { return cmanager.connected(); }
00122
00123 void InputPortInterface::clear()
00124 {
00125 cmanager.clear();
00126 }
00127
00128 void InputPortInterface::disconnect()
00129 {
00130 cmanager.disconnect();
00131 }
00132
00133 bool InputPortInterface::disconnect(PortInterface* port)
00134 {
00135 return cmanager.disconnect(port);
00136 }
00137