channel_elem_base.cpp
Go to the documentation of this file.
00001 /* 
00002  *  channel_element_base.cpp - micros base 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 #include "micros_rtt/oro/channel_data_element.hpp"
00020 #include "micros_rtt/oro/oro_arch.h"
00021 
00022 namespace micros_rtt
00023 {
00024 
00025 ChannelElementBase::ChannelElementBase()
00026     : input(0)
00027 {
00028   ORO_ATOMIC_SETUP(&refcount,0);
00029 }
00030 
00031 ChannelElementBase::~ChannelElementBase()
00032 {
00033   ORO_ATOMIC_CLEANUP(&refcount);
00034 }
00035 
00036 ChannelElementBase::shared_ptr ChannelElementBase::getInput()
00037 { 
00038 //  RTT::os::MutexLock lock(inout_lock);
00039   return ChannelElementBase::shared_ptr(input);
00040 }
00041 
00042 ChannelElementBase::shared_ptr ChannelElementBase::getOutput()
00043 { 
00044   //RTT::os::MutexLock lock(inout_lock);
00045   return ChannelElementBase::shared_ptr(output);
00046 }
00047 
00048 void ChannelElementBase::setOutput(shared_ptr output)
00049 {
00050   this->output = output;
00051   if (output)
00052     output->input = this;
00053 }
00054 
00055 void ChannelElementBase::disconnect(bool forward)
00056 {
00057   if (forward)
00058   {
00059     shared_ptr output = getOutput();
00060     if (output)
00061       output->disconnect(true);
00062   }
00063   else
00064   {
00065     shared_ptr input = getInput();
00066     if (input)
00067       input->disconnect(false);
00068   }
00069 
00070 //  { RTT::os::MutexLock lock(inout_lock);
00071     this->input = 0;
00072     this->output = 0;
00073 //  }
00074 }
00075 
00076 ChannelElementBase::shared_ptr ChannelElementBase::getInputEndPoint()
00077 {
00078   shared_ptr input = getInput();
00079   return input ? input->getInputEndPoint() : this;
00080 }
00081 ChannelElementBase::shared_ptr ChannelElementBase::getOutputEndPoint()
00082 {
00083   shared_ptr output = getOutput();
00084   return output ? output->getOutputEndPoint() : this;
00085 }
00086 
00087 bool ChannelElementBase::inputReady()
00088 {
00089   // we go against the data stream
00090   shared_ptr input = getInput();
00091   if (input)
00092     return input->inputReady();
00093   return false;
00094 }
00095 
00096 void ChannelElementBase::clear()
00097 {
00098   shared_ptr input = getInput();
00099   if (input)
00100     input->clear();
00101 }
00102 
00103 bool ChannelElementBase::signal()
00104 {
00105   shared_ptr output = getOutput();
00106   if (output)
00107     return output->signal();
00108   return true;
00109 }
00110 
00111 void ChannelElementBase::ref()
00112 {
00113   oro_atomic_inc(&refcount);
00114 }
00115 
00116 void ChannelElementBase::deref()
00117 {
00118   if ( oro_atomic_dec_and_test(&refcount) ) delete this;
00119 }
00120 
00121 void intrusive_ptr_add_ref( ChannelElementBase* p )
00122 { p->ref(); }
00123 
00124 void intrusive_ptr_release( ChannelElementBase* p )
00125 { p->deref(); }
00126 
00127 }


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