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 #include "PortConnectionLock.hpp"
45 
46 namespace RTT
47 { namespace internal {
48 
57  template<typename T>
59  {
60  private:
62 
63  public:
65  typedef boost::intrusive_ptr<ConnOutputEndpoint<T> > shared_ptr;
66 
76  : port(port)
77  {
78  }
79 
81  {
82  }
83 
92  bool channelReady(base::ChannelElementBase::shared_ptr const& channel, ConnPolicy const& policy, ConnID *conn_id)
93  {
94  // cid is deleted/owned by the ConnectionManager.
95  if ( channel ) {
96  if (!conn_id) conn_id = new internal::SimpleConnID();
97  if ( channel->inputReady(this) ) {
98  port->addConnection(conn_id, channel, policy);
99  return true;
100  }
101  }
102 
103  return false;
104  }
105 
111  virtual WriteStatus write(typename Base::param_t sample)
112  {
113  WriteStatus result = Base::write(sample);
114  if (result == WriteSuccess) {
115  if (!signal()) {
116  return WriteFailure;
117  }
118  } else if (result == NotConnected) {
119  // A ConnOutputEndPoint is always connected: If Base::write(sample) returned NotConnected the port
120  // does not have a shared input buffer and you cannot write into this ChannelElement, but it still
121  // should be considered as connected.
122  // @sa OutputPort::connectionAdded()
123  result = WriteFailure;
124  }
125  return result;
126  }
127 
128  using Base::disconnect;
129 
130  virtual bool disconnect(const base::ChannelElementBase::shared_ptr& channel, bool forward)
131  {
132  InputPort<T>* port = this->port;
133  PortConnectionLock lock(port);
134 
135 // // Lock port connections if the request is coming from the remote end (forward == true)
136 // PortConnectionLock lock(forward ? port : 0);
137 
138  if (port && channel && forward)
139  {
140  port->getManager()->removeConnection(channel.get(), /* disconnect = */ false);
141  }
142 
143  // Call the base class: it does the common cleanup
144  if (!Base::disconnect(channel, forward)) {
145  return false;
146  }
147 
148  // If this was the last connection, remove the buffer, too.
149  // For forward == true this was already done by the base class.
150  if (!this->connected() && !forward) {
151  Base::disconnect(0, true);
152  }
153 
154  return true;
155  }
156 
157  virtual bool signal()
158  {
159  InputPort<T>* port = this->port;
160 #ifdef ORO_SIGNALLING_PORTS
161  if (port && port->new_data_on_port_event)
162  (*port->new_data_on_port_event)(port);
163 #else
164  if (port )
165  port->signal();
166 #endif
167  return true;
168  }
169 
170  virtual base::PortInterface* getPort() const {
171  return this->port;
172  }
173 
175  {
176  return this;
177  }
178 
180  {
181  return this->getOutput();
182  }
183 
185  {
187  if (buffer) {
188  return buffer;
189  } else {
190  return this;
191  }
192  }
193 
194  std::string getElementName() const {
195  return std::string("ConnOutputEndpoint");
196  }
197 
198  };
199 
200 }}
201 
202 #endif
203 
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)
virtual base::ChannelElement< T >::shared_ptr getSharedBuffer()
base::MultipleInputsChannelElement< T > Base
base::ChannelElement< T >::shared_ptr getReadEndpoint()
virtual base::PortInterface * getPort() const
virtual internal::ConnectionManager * getManager()
virtual bool disconnect(ChannelElementBase::shared_ptr const &channel, bool forward=true)
virtual base::ChannelElementBase::shared_ptr getOutputEndPoint()
ConnOutputEndpoint(InputPort< T > *port)
boost::intrusive_ptr< ChannelElementBase > shared_ptr
bool channelReady(base::ChannelElementBase::shared_ptr const &channel, ConnPolicy const &policy, ConnID *conn_id)
virtual bool disconnect(const base::ChannelElementBase::shared_ptr &channel, bool forward)
boost::intrusive_ptr< ConnOutputEndpoint< T > > shared_ptr
virtual WriteStatus write(param_t sample)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
WriteStatus
Definition: FlowStatus.hpp:66
virtual WriteStatus write(typename Base::param_t sample)


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:22