InputPort.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Oct 22 11:59:08 CEST 2009 InputPort.hpp
3 
4  InputPort.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_INPUT_PORT_HPP
40 #define ORO_INPUT_PORT_HPP
41 
43 #include "internal/Channels.hpp"
45 #include "Service.hpp"
46 #include "OperationCaller.hpp"
47 
48 #include "OutputPort.hpp"
49 
50 namespace RTT
51 {
62  template<typename T>
64  {
65  private:
68 
69  virtual bool connectionAdded( base::ChannelElementBase::shared_ptr channel_input, ConnPolicy const& policy ) { return true; }
70 
77  InputPort(InputPort const& orig);
78  InputPort& operator=(InputPort const& orig);
79 
80  public:
81  InputPort(std::string const& name = "unnamed", ConnPolicy const& default_policy = ConnPolicy())
83  , endpoint(new internal::ConnOutputEndpoint<T>(this))
84  {}
85 
86  virtual ~InputPort() { disconnect(); }
87 
91  void clear()
92  {
93  getEndpoint()->getReadEndpoint()->clear();
94  }
95 
98  { return read(source, true); }
99 
101  {
103  boost::dynamic_pointer_cast< internal::AssignableDataSource<T> >(source);
104  if (! ds)
105  {
106  log(Error) << "trying to read to an incompatible data source" << endlog();
107  return NoData;
108  }
109  RTT::FlowStatus status = read(ds->set(), copy_old_data);
110  traceRead(status);
111  return status;
112  }
113 
120  FlowStatus readNewest(base::DataSourceBase::shared_ptr source, bool copy_old_data = true)
121  {
123  boost::dynamic_pointer_cast< internal::AssignableDataSource<T> >(source);
124  if (! ds)
125  {
126  log(Error) << "trying to read to an incompatible data source" << endlog();
127  return NoData;
128  }
129  return readNewest(ds->set(), copy_old_data);
130  }
131 
134  { return read(sample, true); }
135 
147  FlowStatus read(typename base::ChannelElement<T>::reference_t sample, bool copy_old_data)
148  {
149  return getEndpoint()->getReadEndpoint()->read(sample, copy_old_data);
150  }
151 
158  FlowStatus readNewest(typename base::ChannelElement<T>::reference_t sample, bool copy_old_data = true)
159  {
160  FlowStatus result = read(sample, copy_old_data);
161  if (result != RTT::NewData)
162  return result;
163 
164  while (read(sample, false) == RTT::NewData);
165  return RTT::NewData;
166  }
167 
176  void getDataSample(T& sample)
177  {
178  sample = getEndpoint()->getReadEndpoint()->data_sample();
179  }
180 
182  virtual const types::TypeInfo* getTypeInfo() const
184 
188  virtual base::PortInterface* clone() const
189  { return new InputPort<T>(this->getName()); }
190 
197  { return new OutputPort<T>(this->getName()); }
198 
203  {
204  return new internal::InputPortSource<T>(*this);
205  }
206 
207  virtual bool createStream(ConnPolicy const& policy)
208  {
209  return internal::ConnFactory::createStream(*this, policy);
210  }
211 
212 #ifndef ORO_DISABLE_PORT_DATA_SCRIPTING
213 
218  {
220  // Force resolution on the overloaded write method
221  typedef FlowStatus (InputPort<T>::*ReadSample)(typename base::ChannelElement<T>::reference_t);
222  ReadSample read_m = &InputPort<T>::read;
223  object->addSynchronousOperation("read", read_m, this).doc("Reads a sample from the port.").arg("sample", "");
224  object->addSynchronousOperation("clear", &InputPortInterface::clear, this).doc("Clears any remaining data in this port. After a clear, a read() will return NoData if no writes happened in between.");
225  return object;
226  }
227 #endif
228 
230  {
231  assert(endpoint);
232  return endpoint.get();
233  }
234 
236  {
237  return getEndpoint()->getSharedBuffer();
238  }
239  };
240 }
241 
242 #endif
243 
boost::intrusive_ptr< ChannelElement< T > > shared_ptr
InputPort(InputPort const &orig)
virtual const types::TypeInfo * getTypeInfo() const
Definition: InputPort.hpp:182
The base class for all internal data representations.
FlowStatus read(typename base::ChannelElement< T >::reference_t sample, bool copy_old_data)
Definition: InputPort.hpp:147
virtual base::PortInterface * antiClone() const
Definition: InputPort.hpp:196
virtual void set(param_t t)=0
FlowStatus
Definition: FlowStatus.hpp:56
virtual base::ChannelElement< T >::shared_ptr getSharedBuffer() const
Definition: InputPort.hpp:235
FlowStatus readNewest(base::DataSourceBase::shared_ptr source, bool copy_old_data=true)
Definition: InputPort.hpp:120
const std::string & getName() const
void traceRead(RTT::FlowStatus status)
FlowStatus read(base::DataSourceBase::shared_ptr source, bool copy_old_data)
Definition: InputPort.hpp:100
FlowStatus read(base::DataSourceBase::shared_ptr source)
Definition: InputPort.hpp:97
virtual internal::ConnOutputEndpoint< T > * getEndpoint() const
Definition: InputPort.hpp:229
virtual bool connectionAdded(base::ChannelElementBase::shared_ptr channel_input, ConnPolicy const &policy)
Definition: InputPort.hpp:69
FlowStatus readNewest(typename base::ChannelElement< T >::reference_t sample, bool copy_old_data=true)
Definition: InputPort.hpp:158
virtual base::PortInterface * clone() const
Definition: InputPort.hpp:188
virtual Service * createPortObject()
virtual ~InputPort()
Definition: InputPort.hpp:86
static bool createStream(OutputPort< T > &output_port, ConnPolicy const &policy)
InputPort & operator=(InputPort const &orig)
boost::call_traits< T >::reference reference_t
InputPort(std::string const &name="unnamed", ConnPolicy const &default_policy=ConnPolicy())
Definition: InputPort.hpp:81
boost::intrusive_ptr< ChannelElementBase > shared_ptr
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
Definition: DataSource.hpp:198
static const types::TypeInfo * getTypeInfo()
virtual Service * createPortObject()
Definition: InputPort.hpp:217
boost::intrusive_ptr< ConnOutputEndpoint< T > > shared_ptr
boost::intrusive_ptr< DataSourceBase > shared_ptr
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
PortInterface & doc(const std::string &desc)
FlowStatus read(typename base::ChannelElement< T >::reference_t sample)
Definition: InputPort.hpp:133
static Logger & log()
Definition: Logger.hpp:350
virtual bool createStream(ConnPolicy const &policy)
Definition: InputPort.hpp:207
static Logger::LogFunction endlog()
Definition: Logger.hpp:362
internal::ConnOutputEndpoint< T >::shared_ptr endpoint
Definition: InputPort.hpp:67
base::DataSourceBase * getDataSource()
Definition: InputPort.hpp:202
void getDataSample(T &sample)
Definition: InputPort.hpp:176


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