00001 /* 00002 * channel_element.hpp - micros channel 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_ELEMENT_HPP 00020 #define MICROSRTT_CHANNEL_ELEMENT_HPP 00021 00022 #include <boost/intrusive_ptr.hpp> 00023 #include <boost/call_traits.hpp> 00024 #include "micros_rtt/oro/channel_element_base.hpp" 00025 #include "micros_rtt/common.h" 00026 00027 namespace micros_rtt 00028 { 00029 00033 template<typename M> 00034 class ChannelElement : public ChannelElementBase 00035 { 00036 public: 00037 typedef M value_t; 00038 typedef boost::intrusive_ptr< ChannelElement<M> > shared_ptr; 00039 typedef typename boost::call_traits<M>::param_type param_t; 00040 typedef typename boost::call_traits<M>::reference reference_t; 00041 00042 shared_ptr getOutput() 00043 { 00044 return boost::static_pointer_cast< ChannelElement<M> >(ChannelElementBase::getOutput()); 00045 } 00046 00047 shared_ptr getInput() 00048 { 00049 return boost::static_pointer_cast< ChannelElement<M> >(ChannelElementBase::getInput()); 00050 } 00051 00060 virtual bool data_sample(param_t sample) 00061 { 00062 typename ChannelElement<M>::shared_ptr output = boost::static_pointer_cast< ChannelElement<M> >(getOutput()); 00063 if (output) 00064 { 00065 return output->data_sample(sample); 00066 } 00067 return false; 00068 } 00069 00070 virtual value_t data_sample() 00071 { 00072 typename ChannelElement<M>::shared_ptr input = boost::static_pointer_cast< ChannelElement<M> >(getInput()); 00073 if (input) 00074 { 00075 return input->data_sample(); 00076 } 00077 return value_t(); 00078 } 00079 00085 virtual bool write(param_t sample) 00086 { 00087 typename ChannelElement<M>::shared_ptr output = boost::static_pointer_cast< ChannelElement<M> >(getOutput()); 00088 if (output) 00089 { 00090 return output->write(sample); 00091 } 00092 return false; 00093 } 00094 00100 virtual FlowStatus read(reference_t sample, bool copy_old_data) 00101 { 00102 typename ChannelElement<M>::shared_ptr input = this->getInput(); 00103 if (input) 00104 { 00105 return input->read(sample, copy_old_data); 00106 } 00107 else 00108 { 00109 return NewData; 00110 } 00111 } 00112 }; 00113 00114 } 00115 00116 #endif 00117