Orocos Real-Time Toolkit  2.8.3
InputPortInterface.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Oct 22 11:59:07 CEST 2009 InputPortInterface.cpp
3 
4  InputPortInterface.cpp - description
5  -------------------
6  begin : Thu October 22 2009
7  copyright : (C) 2009 Sylvain Joyeux
8  email : sylvain.joyeux@m4x.org
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #include "PortInterface.hpp"
40 #include "InputPortInterface.hpp"
41 #include "OutputPortInterface.hpp"
42 #include "DataFlowInterface.hpp"
43 #include "../internal/ConnInputEndPoint.hpp"
44 #include "../Logger.hpp"
45 #include <exception>
46 #include <stdexcept>
47 
48 using namespace RTT;
49 using namespace RTT::detail;
50 using namespace std;
51 
52 
53 InputPortInterface::InputPortInterface(std::string const& name, ConnPolicy const& default_policy)
54 : PortInterface(name)
55  , cmanager(this)
56  , default_policy( default_policy )
57 #ifdef ORO_SIGNALLING_PORTS
58  , new_data_on_port_event(0)
59 #else
60  , msignal_interface(false)
61 #endif
62 {}
63 
65 {
66  cmanager.disconnect();
67 #ifdef ORO_SIGNALLING_PORTS
68  if ( new_data_on_port_event) {
69  delete new_data_on_port_event;
70  }
71 #endif
72 }
73 
75 { return default_policy; }
76 
77 #ifdef ORO_SIGNALLING_PORTS
78 InputPortInterface::NewDataOnPortEvent* InputPortInterface::getNewDataOnPortEvent()
79 {
80  if (!new_data_on_port_event)
81  new_data_on_port_event = new NewDataOnPortEvent();
82  return new_data_on_port_event;
83 }
84 #endif
86 {
87  OutputPortInterface* output = dynamic_cast<OutputPortInterface*>(other);
88  if (! output) {
89  log(Error) << "InputPort "<< getName() <<" could not connect to "<< other->getName() << ": not an Output port." <<endlog();
90  return false;
91  }
92  return output->createConnection(*this, policy);
93 }
94 
96 {
97  return connectTo(other, default_policy);
98 }
99 
101 {
102  // input ports don't check the connection policy.
103  cmanager.addConnection( port_id, channel_output, policy);
104  return true;
105 }
106 
108 {
109  // cid is deleted/owned by the ConnectionManager.
110  if ( channel ) {
111  internal::ConnID* cid = channel->getConnID();
112  if (cid ) {
113  this->addConnection(cid, channel, policy);
114  if ( channel->inputReady() )
115  return true;
116  } else {
117  log(Error) << "Can't add ChannelElement which is not a ConnInputEndPoint to Port "<< this->getName() <<endlog();
118  }
119  }
120  if (channel) {
121  // in-the-middle disconnection, we need to inform both ends of
122  // the channel that it's going to be disposed. Both endpoints
123  // will inform their ports with a removal request.
124  // From a design perspective, this removal must be initiated
125  // by our connection manager and not by us.
126  channel->disconnect(false);
127  channel->disconnect(true);
128  }
129 
130  return false;
131 }
132 
134 {
135  return cmanager.removeConnection(conn);
136 }
137 
138 #ifndef ORO_SIGNALLING_PORTS
140 {
141  if (iface && msignal_interface)
142  iface->dataOnPort(this);
143 }
145 {
146  msignal_interface = true_false;
147 }
148 #endif
150 { throw std::runtime_error("calling default InputPortInterface::read(datasource) implementation"); }
153 { return cmanager.connected(); }
154 
156 {
157  cmanager.clear();
158 }
159 
161 {
162  cmanager.disconnect();
163 }
164 
166 {
167  return cmanager.disconnect(port);
168 }
169 
171  base::OutputPortInterface& output_port,
172  types::TypeInfo const* type_info,
173  base::InputPortInterface& input, const ConnPolicy& policy)
174 {
176 }
177 
The base class of the InputPort.
virtual bool channelReady(base::ChannelElementBase::shared_ptr channel, ConnPolicy const &policy)
Call this to indicate that the connection leading to this port is ready to use.
InputPortInterface(const InputPortInterface &orig)
virtual bool removeConnection(internal::ConnID *cid)
Removes the input channel.
virtual FlowStatus read(DataSourceBase::shared_ptr source, bool copy_old_data=true)
Reads the port and updates the value hold by the given data source.
virtual void disconnect()
Removes any connection that either go to or come from this port and removes all callbacks and cleans ...
ConnPolicy getDefaultPolicy() const
FlowStatus
Returns the status of a data flow read.
Definition: FlowStatus.hpp:54
STL namespace.
const std::string & getName() const
Get the name of this Port.
void signalInterface(bool true_false)
When called with true, will signal the DataFlowInterface when new data is available.
A connection policy object describes how a given connection should behave.
Definition: ConnPolicy.hpp:92
The base class of each OutputPort.
Convenient short notation for every sub-namespace of RTT.
void clear()
Clears the connection.
virtual base::ChannelElementBase::shared_ptr buildRemoteChannelOutput(base::OutputPortInterface &output_port, types::TypeInfo const *type_info, base::InputPortInterface &input, const ConnPolicy &policy)
This method is analoguous to the static ConnFactory::buildChannelOutput.
bool createConnection(InputPortInterface &sink)
Connects this write port to the given read port, using as policy the default policy of the sink port...
A class for representing a user type, and which can build instances of that type. ...
Definition: TypeInfo.hpp:66
virtual bool connectTo(PortInterface *other, ConnPolicy const &policy)
Connects this port with other, using the given policy.
void signal()
The ConnOutputEndpoint signals that new data is available.
boost::intrusive_ptr< ChannelElementBase > shared_ptr
virtual bool addConnection(internal::ConnID *port_id, ChannelElementBase::shared_ptr channel_input, ConnPolicy const &policy)
Adds a user created connection to this port.
virtual bool connected() const
Returns true if this port is connected.
This class is used in places where a permanent representation of a reference to a connection is neede...
Definition: ConnID.hpp:58
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
The base class of every data flow port.