channel_data_element.hpp
Go to the documentation of this file.
00001 /* 
00002  *  channel_data_element.hpp - micros channel data element
00003  *  Copyright (C) 2015 Zaile Jiang
00004  *  
00005  *  This program is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU General Public License
00007  *  as published by the Free Software Foundation; either version 2
00008  *  of the License, or (at your option) any later version.
00009  *  
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *  
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018 */
00019 #ifndef MICROSRTT_CHANNEL_DATA_ELEMENT_HPP
00020 #define MICROSRTT_CHANNEL_DATA_ELEMENT_HPP
00021 
00022 #include "micros_rtt/oro/channel_element.hpp"
00023 #include "micros_rtt/oro/data_lockfree.hpp"
00024 
00025 namespace micros_rtt 
00026 {    
00027   
00029 template<typename T>
00030 class ChannelDataElement : public ChannelElement<T>
00031 {
00032   bool written, mread;
00033   typename DataObjectLockFree<T>::shared_ptr data;
00034 
00035 public:
00036   typedef typename ChannelElement<T>::param_t param_t;
00037   typedef typename ChannelElement<T>::reference_t reference_t;
00038 
00039   ChannelDataElement(typename DataObjectLockFree<T>::shared_ptr sample)
00040         : written(false), mread(false), data(sample) {}
00041 
00044   virtual bool write(param_t sample)
00045   {
00046     data->Set(sample);
00047     written = true;
00048     mread = false;
00049     return this->signal();
00050   }
00051 
00056   virtual FlowStatus read(reference_t sample, bool copy_old_data)
00057   {
00058     if (written)
00059     {
00060       if ( !mread ) {
00061         data->Get(sample);
00062         mread = true;
00063         return NewData;
00064       }
00065 
00066       if(copy_old_data)
00067         data->Get(sample);
00068 
00069       return OldData;
00070     }
00071     return NoData;
00072   }
00073 
00077   virtual void clear()
00078   {
00079     written = false;
00080     mread = false;
00081     ChannelElement<T>::clear();
00082   }
00083 
00084   virtual bool data_sample(param_t sample)
00085   {
00086     data->data_sample(sample);
00087     return ChannelElement<T>::data_sample(sample);
00088   }
00089 
00090   virtual T data_sample()
00091   {
00092     return data->Get();
00093   }
00094 
00095 };
00096 
00097 }
00098 
00099 #endif
00100 


micros_rtt
Author(s): Zaile Jiang , Xiaodong Yi , Minglong Li
autogenerated on Sat Jun 8 2019 19:02:21