InputPortInterface.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Thu Oct 22 11:59:07 CEST 2009  InputPortInterface.cpp
00003 
00004                         InputPortInterface.cpp -  description
00005                            -------------------
00006     begin                : Thu October 22 2009
00007     copyright            : (C) 2009 Sylvain Joyeux
00008     email                : sylvain.joyeux@m4x.org
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
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     // input ports don't check the connection policy.
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     // cid is deleted/owned by the ConnectionManager.
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         // in-the-middle disconnection, we need to inform both ends of
00122         // the channel that it's going to be disposed. Both endpoints
00123         // will inform their ports with a removal request.
00124         // From a design perspective, this removal must be initiated
00125         // by our connection manager and not by us.
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 


rtt
Author(s): RTT Developers
autogenerated on Sat Jun 8 2019 18:46:12