00001 #ifndef ROSRTT_CHANNEL_DATA_ELEMENT_HPP 00002 #define ROSRTT_CHANNEL_DATA_ELEMENT_HPP 00003 00004 #include "channel_element.hpp" 00005 #include "data_lockfree.hpp" 00006 00007 namespace hpcl_rtt 00008 { 00009 00011 template<typename T> 00012 class ChannelDataElement : public ChannelElement<T> 00013 { 00014 bool written, mread; 00015 typename DataObjectLockFree<T>::shared_ptr data; 00016 00017 public: 00018 typedef typename ChannelElement<T>::param_t param_t; 00019 typedef typename ChannelElement<T>::reference_t reference_t; 00020 00021 ChannelDataElement(typename DataObjectLockFree<T>::shared_ptr sample) 00022 : written(false), mread(false), data(sample) {} 00023 00026 virtual bool write(param_t sample) 00027 { 00028 data->Set(sample); 00029 written = true; 00030 mread = false; 00031 return this->signal(); 00032 } 00033 00038 virtual FlowStatus read(reference_t sample, bool copy_old_data) 00039 { 00040 if (written) 00041 { 00042 if ( !mread ) { 00043 data->Get(sample); 00044 mread = true; 00045 return NewData; 00046 } 00047 00048 if(copy_old_data) 00049 data->Get(sample); 00050 00051 return OldData; 00052 } 00053 return NoData; 00054 } 00055 00059 virtual void clear() 00060 { 00061 written = false; 00062 mread = false; 00063 ChannelElement<T>::clear(); 00064 } 00065 00066 virtual bool data_sample(param_t sample) 00067 { 00068 data->data_sample(sample); 00069 return ChannelElement<T>::data_sample(sample); 00070 } 00071 00072 virtual T data_sample() 00073 { 00074 return data->Get(); 00075 } 00076 00077 }; 00078 00079 } 00080 00081 #endif 00082