Orocos Real-Time Toolkit
2.5.0
|
00001 /*************************************************************************** 00002 tag: Peter Soetens Thu Oct 22 11:59:08 CEST 2009 ChannelDataElement.hpp 00003 00004 ChannelDataElement.hpp - description 00005 ------------------- 00006 begin : Thu October 22 2009 00007 copyright : (C) 2009 Sylvain Joyeux 00008 email : sylvain.joyeux@m4x.org 00009 00010 *************************************************************************** 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU General Public * 00013 * License as published by the Free Software Foundation; * 00014 * version 2 of the License. * 00015 * * 00016 * As a special exception, you may use this file as part of a free * 00017 * software library without restriction. Specifically, if other files * 00018 * instantiate templates or use macros or inline functions from this * 00019 * file, or you compile this file and link it with other files to * 00020 * produce an executable, this file does not by itself cause the * 00021 * resulting executable to be covered by the GNU General Public * 00022 * License. This exception does not however invalidate any other * 00023 * reasons why the executable file might be covered by the GNU General * 00024 * Public License. * 00025 * * 00026 * This library is distributed in the hope that it will be useful, * 00027 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00029 * Lesser General Public License for more details. * 00030 * * 00031 * You should have received a copy of the GNU General Public * 00032 * License along with this library; if not, write to the Free Software * 00033 * Foundation, Inc., 59 Temple Place, * 00034 * Suite 330, Boston, MA 02111-1307 USA * 00035 * * 00036 ***************************************************************************/ 00037 00038 00039 #ifndef ORO_CHANNEL_DATA_ELEMENT_HPP 00040 #define ORO_CHANNEL_DATA_ELEMENT_HPP 00041 00042 #include "../base/ChannelElement.hpp" 00043 #include "../base/DataObjectInterface.hpp" 00044 00045 namespace RTT { namespace internal { 00046 00049 template<typename T> 00050 class ChannelDataElement : public base::ChannelElement<T> 00051 { 00052 bool written, mread; 00053 typename base::DataObjectInterface<T>::shared_ptr data; 00054 00055 public: 00056 typedef typename base::ChannelElement<T>::param_t param_t; 00057 typedef typename base::ChannelElement<T>::reference_t reference_t; 00058 00059 ChannelDataElement(typename base::DataObjectInterface<T>::shared_ptr sample) 00060 : written(false), mread(false), data(sample) {} 00061 00064 virtual bool write(param_t sample) 00065 { 00066 data->Set(sample); 00067 written = true; 00068 mread = false; 00069 return this->signal(); 00070 } 00071 00076 virtual FlowStatus read(reference_t sample, bool copy_old_data) 00077 { 00078 if (written) 00079 { 00080 if ( !mread ) { 00081 data->Get(sample); 00082 mread = true; 00083 return NewData; 00084 } 00085 00086 if(copy_old_data) 00087 data->Get(sample); 00088 00089 return OldData; 00090 } 00091 return NoData; 00092 } 00093 00097 virtual void clear() 00098 { 00099 written = false; 00100 mread = false; 00101 base::ChannelElement<T>::clear(); 00102 } 00103 00104 virtual bool data_sample(param_t sample) 00105 { 00106 data->data_sample(sample); 00107 return base::ChannelElement<T>::data_sample(sample); 00108 } 00109 00110 }; 00111 }} 00112 00113 #endif 00114