channel_elem_base.cpp
Go to the documentation of this file.
00001 
00002 #include "hpcl_rtt/oro/channel_data_element.hpp"
00003 #include "hpcl_rtt/oro/oro_arch.h"
00004 //#include "../os/MutexLock.hpp"
00005 
00006 namespace hpcl_rtt
00007 {
00008 
00009 ChannelElementBase::ChannelElementBase()
00010     : input(0)
00011 {
00012   ORO_ATOMIC_SETUP(&refcount,0);
00013 }
00014 
00015 ChannelElementBase::~ChannelElementBase()
00016 {
00017   ORO_ATOMIC_CLEANUP(&refcount);
00018 }
00019 
00020 ChannelElementBase::shared_ptr ChannelElementBase::getInput()
00021 { 
00022 //  RTT::os::MutexLock lock(inout_lock);
00023   return ChannelElementBase::shared_ptr(input);
00024 }
00025 
00026 ChannelElementBase::shared_ptr ChannelElementBase::getOutput()
00027 { 
00028   //RTT::os::MutexLock lock(inout_lock);
00029   return ChannelElementBase::shared_ptr(output);
00030 }
00031 
00032 void ChannelElementBase::setOutput(shared_ptr output)
00033 {
00034   this->output = output;
00035   if (output)
00036     output->input = this;
00037 }
00038 
00039 void ChannelElementBase::disconnect(bool forward)
00040 {
00041   if (forward)
00042   {
00043     shared_ptr output = getOutput();
00044     if (output)
00045       output->disconnect(true);
00046   }
00047   else
00048   {
00049     shared_ptr input = getInput();
00050     if (input)
00051       input->disconnect(false);
00052   }
00053 
00054 //  { RTT::os::MutexLock lock(inout_lock);
00055     this->input = 0;
00056     this->output = 0;
00057 //  }
00058 }
00059 
00060 ChannelElementBase::shared_ptr ChannelElementBase::getInputEndPoint()
00061 {
00062   shared_ptr input = getInput();
00063   return input ? input->getInputEndPoint() : this;
00064 }
00065 ChannelElementBase::shared_ptr ChannelElementBase::getOutputEndPoint()
00066 {
00067   shared_ptr output = getOutput();
00068   return output ? output->getOutputEndPoint() : this;
00069 }
00070 
00071 bool ChannelElementBase::inputReady()
00072 {
00073   // we go against the data stream
00074   shared_ptr input = getInput();
00075   if (input)
00076     return input->inputReady();
00077   return false;
00078 }
00079 
00080 void ChannelElementBase::clear()
00081 {
00082   shared_ptr input = getInput();
00083   if (input)
00084     input->clear();
00085 }
00086 
00087 bool ChannelElementBase::signal()
00088 {
00089   shared_ptr output = getOutput();
00090   if (output)
00091     return output->signal();
00092   return true;
00093 }
00094 
00095 void ChannelElementBase::ref()
00096 {
00097   oro_atomic_inc(&refcount);
00098 }
00099 
00100 void ChannelElementBase::deref()
00101 {
00102   if ( oro_atomic_dec_and_test(&refcount) ) delete this;
00103 }
00104 
00105 void intrusive_ptr_add_ref( ChannelElementBase* p )
00106 { p->ref(); }
00107 
00108 void intrusive_ptr_release( ChannelElementBase* p )
00109 { p->deref(); }
00110 
00111 }


hpcl_rtt
Author(s): sukha
autogenerated on Thu Aug 27 2015 16:43:53