Orocos Real-Time Toolkit  2.8.3
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 
45 namespace RTT { namespace internal {
46 
49  template<typename T>
51  {
52  bool written, mread;
54 
55  public:
58 
60  : written(false), mread(false), data(sample) {}
61 
64  virtual bool write(param_t sample)
65  {
66  data->Set(sample);
67  written = true;
68  mread = false;
69  return this->signal();
70  }
71 
76  virtual FlowStatus read(reference_t sample, bool copy_old_data)
77  {
78  if (written)
79  {
80  if ( !mread ) {
81  data->Get(sample);
82  mread = true;
83  return NewData;
84  }
85 
86  if(copy_old_data)
87  data->Get(sample);
88 
89  return OldData;
90  }
91  return NoData;
92  }
93 
97  virtual void clear()
98  {
99  written = false;
100  mread = false;
102  }
103 
104  virtual bool data_sample(param_t sample)
105  {
106  data->data_sample(sample);
108  }
109 
110  virtual T data_sample()
111  {
112  return data->Get();
113  }
114 
115  virtual std::string getElementName() const
116  {
117  return "ChannelDataElement";
118  };
119  };
120 }}
121 
122 #endif
123 
boost::call_traits< T >::param_type param_t
virtual void data_sample(const DataType &sample)=0
Provides a data sample to initialize this data object.
boost::shared_ptr< DataObjectInterface< T > > shared_ptr
Used for shared_ptr management.
virtual void clear()
Clears any data stored by the channel.
ChannelDataElement(typename base::DataObjectInterface< T >::shared_ptr sample)
virtual void clear()
Resets the stored sample.
virtual bool data_sample(param_t sample)
Provides a data sample to initialize this connection.
FlowStatus
Returns the status of a data flow read.
Definition: FlowStatus.hpp:54
virtual bool write(param_t sample)
Update the data sample stored in this element.
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.
boost::call_traits< T >::reference reference_t
virtual value_t data_sample()
virtual std::string getElementName() const
Returns the class name of this element.
virtual void Get(DataType &pull) const =0
Get a copy of the Data of this data object.
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 void Set(const DataType &push)=0
Set the data to a certain value.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
base::ChannelElement< T >::param_t param_t
base::ChannelElement< T >::reference_t reference_t