Orocos Real-Time Toolkit  2.9.0
ConnOutputEndPoint.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Oct 22 11:59:08 CEST 2009 ConnOutputEndPoint.hpp
3 
4  ConnOutputEndPoint.hpp - 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 #ifndef ORO_CONN_OUTPUT_ENDPOINT_HPP
40 #define ORO_CONN_OUTPUT_ENDPOINT_HPP
41 
42 #include "Channels.hpp"
43 #include "ConnID.hpp"
44 
45 namespace RTT
46 { namespace internal {
47 
56  template<typename T>
58  {
59  private:
60  InputPort<T>* port;
61 
62  public:
64  typedef boost::intrusive_ptr<ConnOutputEndpoint<T> > shared_ptr;
65 
75  : port(port)
76  {
77  }
78 
80  {
81  }
82 
91  bool channelReady(base::ChannelElementBase::shared_ptr const& channel, ConnPolicy const& policy, ConnID *conn_id)
92  {
93  // cid is deleted/owned by the ConnectionManager.
94  if ( channel ) {
95  if (!conn_id) conn_id = new internal::SimpleConnID();
96  if ( channel->inputReady(this) ) {
97  port->addConnection(conn_id, channel, policy);
98  return true;
99  }
100  }
101 
102  return false;
103  }
104 
110  virtual WriteStatus write(typename Base::param_t sample)
111  {
112  WriteStatus result = Base::write(sample);
113  if (result == WriteSuccess) {
114  if (!signal()) {
115  return WriteFailure;
116  }
117  } else if (result == NotConnected) {
118  // A ConnOutputEndPoint is always connected: If Base::write(sample) returned NotConnected the port
119  // does not have a shared input buffer and you cannot write into this ChannelElement, but it still
120  // should be considered as connected.
121  // @sa OutputPort::connectionAdded()
122  result = WriteFailure;
123  }
124  return result;
125  }
126 
127  using Base::disconnect;
128 
129  virtual bool disconnect(const base::ChannelElementBase::shared_ptr& channel, bool forward = true)
130  {
131  InputPort<T>* port = this->port;
132  if (port && channel && forward)
133  {
134  port->getManager()->removeConnection(channel.get(), /* disconnect = */ false);
135  }
136 
137  // Call the base class: it does the common cleanup
138  if (!Base::disconnect(channel, forward)) {
139  return false;
140  }
141 
142  // If this was the last connection, remove the buffer, too.
143  // For forward == true this was already done by the base class.
144  if (!this->connected() && !forward) {
145  this->disconnect(true);
146  }
147 
148  return true;
149  }
150 
151  virtual bool signal()
152  {
153  InputPort<T>* port = this->port;
154 #ifdef ORO_SIGNALLING_PORTS
155  if (port && port->new_data_on_port_event)
156  (*port->new_data_on_port_event)(port);
157 #else
158  if (port )
159  port->signal();
160 #endif
161  return true;
162  }
163 
164  virtual base::PortInterface* getPort() const {
165  return this->port;
166  }
167 
169  {
170  return this;
171  }
172 
174  {
175  return this->getOutput();
176  }
177 
179  {
181  if (buffer) {
182  return buffer;
183  } else {
184  return this;
185  }
186  }
187 
188  std::string getElementName() const {
189  return std::string("ConnOutputEndpoint");
190  }
191 
192  };
193 
194 }}
195 
196 #endif
197 
ChannelElement< T >::param_t param_t
boost::intrusive_ptr< ChannelElement< T > > shared_ptr
virtual bool addConnection(internal::ConnID *port_id, ChannelElementBase::shared_ptr channel, ConnPolicy const &policy)
Adds a user created connection to this port.
This is a channel element that represents the output endpoint of a connection, i.e.
virtual base::ChannelElement< T >::shared_ptr getSharedBuffer()
std::string getElementName() const
Returns the class name of this element.
virtual bool disconnect(const base::ChannelElementBase::shared_ptr &channel, bool forward=true)
Overridden implementation of ChannelElementBase::disconnect(forward, channel).
base::MultipleInputsChannelElement< T > Base
A component&#39;s data input port.
Definition: InputPort.hpp:63
base::ChannelElement< T >::shared_ptr getReadEndpoint()
A connection policy object describes how a given connection should behave.
Definition: ConnPolicy.hpp:107
virtual bool signal()
Signals that there is new data available on this channel By default, the channel element forwards the...
virtual base::PortInterface * getPort() const
Gets the port this channel element is connected to.
virtual internal::ConnectionManager * getManager()
Returns the connection manager of this port (if any).
virtual bool disconnect(ChannelElementBase::shared_ptr const &channel, bool forward=true)
Overridden implementation of ChannelElementBase::disconnect(forward, channel).
virtual base::ChannelElementBase::shared_ptr getOutputEndPoint()
Returns the last output channel element of this connection.
ConnOutputEndpoint(InputPort< T > *port)
Creates the connection end that represents the output and attach it to the input. ...
virtual bool connected()
Returns true, if this channel element has at least one input, independent of whether is has an output...
void signal()
The ConnOutputEndpoint signals that new data is available.
boost::intrusive_ptr< ChannelElementBase > shared_ptr
bool channelReady(base::ChannelElementBase::shared_ptr const &channel, ConnPolicy const &policy, ConnID *conn_id)
Call this to indicate that a connection leading to this port is ready to use.
A simplistic id that is only same with its own clones (and clones of clones).
Definition: ConnID.hpp:69
A typed version of MultipleInputsChannelElementBase.
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< ConnOutputEndpoint< T > > shared_ptr
virtual WriteStatus write(param_t sample)
Writes a new sample on this connection.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
The base class of every data flow port.
WriteStatus
Returns the status of a data flow write operation.
Definition: FlowStatus.hpp:66
virtual WriteStatus write(typename Base::param_t sample)
Writes a new sample on this connection This should only be called if this endpoint has a buffer outpu...