Orocos Real-Time Toolkit  2.9.0
ChannelDataElement.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Oct 22 11:59:08 CEST 2009 ChannelDataElement.hpp
3 
4  ChannelDataElement.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_CHANNEL_DATA_ELEMENT_HPP
40 #define ORO_CHANNEL_DATA_ELEMENT_HPP
41 
42 #include "../base/ChannelElement.hpp"
43 #include "../base/DataObjectInterface.hpp"
44 #include "../ConnPolicy.hpp"
45 
46 namespace RTT { namespace internal {
47 
50  template<typename T>
52  {
54  const ConnPolicy policy;
55 
56  public:
60 
62  : data(sample), policy(policy) {}
63 
66  virtual WriteStatus write(param_t sample)
67  {
68  if (!data->Set(sample)) return WriteFailure;
69  return this->signal() ? WriteSuccess : NotConnected;
70  }
71 
76  virtual FlowStatus read(reference_t sample, bool copy_old_data)
77  {
78  return data->Get(sample, copy_old_data);
79  }
80 
84  virtual void clear()
85  {
86  data->clear();
88  }
89 
90  virtual WriteStatus data_sample(param_t sample, bool reset = true)
91  {
92  if (!data->data_sample(sample, reset)) return WriteFailure;
93  return base::ChannelElement<T>::data_sample(sample, reset);
94  }
95 
96  virtual value_t data_sample()
97  {
98  return data->data_sample();
99  }
100 
103  virtual const ConnPolicy* getConnPolicy() const
104  {
105  return &policy;
106  }
107 
108  virtual std::string getElementName() const
109  {
110  return "ChannelDataElement";
111  };
112  };
113 }}
114 
115 #endif
116 
virtual WriteStatus write(param_t sample)
Update the data sample stored in this element.
boost::call_traits< T >::param_type param_t
boost::shared_ptr< DataObjectInterface< T > > shared_ptr
Used for shared_ptr management.
virtual void clear()
Clears any data stored by the channel.
virtual WriteStatus data_sample(param_t sample, bool reset=true)
Provides a data sample to initialize this connection.
virtual void clear()
Resets the stored sample.
FlowStatus
Returns the status of a data flow read operation.
Definition: FlowStatus.hpp:56
virtual FlowStatus Get(reference_t pull, bool copy_old_data=true) const =0
Get a copy of the Data of this data object.
base::ChannelElement< T >::value_t value_t
ChannelDataElement(typename base::DataObjectInterface< T >::shared_ptr sample, const ConnPolicy &policy=ConnPolicy())
A connection policy object describes how a given connection should behave.
Definition: ConnPolicy.hpp:107
virtual bool data_sample(param_t sample, bool reset=true)=0
Provides a data sample to initialize this data object.
virtual bool signal()
Signals that there is new data available on this channel By default, the channel element forwards the...
A typed version of ChannelElementBase.
virtual const ConnPolicy * getConnPolicy() const
Returns a pointer to the ConnPolicy that has been used to construct the underlying data object...
boost::call_traits< T >::reference reference_t
virtual value_t data_sample()
virtual std::string getElementName() const
Returns the class name of this element.
A connection element that stores a single data sample.
virtual FlowStatus read(reference_t sample, bool copy_old_data)
Reads the last sample given to write()
virtual bool Set(param_t push)=0
Set the data to a certain value.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
base::ChannelElement< T >::param_t param_t
WriteStatus
Returns the status of a data flow write operation.
Definition: FlowStatus.hpp:66
base::ChannelElement< T >::reference_t reference_t
virtual void clear()=0
Clears any data stored by this data object, so that any subsequent Get() without a new Set() will ret...