publication.hpp
Go to the documentation of this file.
00001 /* 
00002  *  publication.hpp - micros pub connection
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_PUBLICATION_HPP
00020 #define MICROSRTT_PUBLICATION_HPP
00021 
00022 #include "ros/ros.h"
00023 #include "micros_rtt/connection_base.h"
00024 #include "micros_rtt/oro/channel_data_element.hpp"
00025 
00026 namespace micros_rtt
00027 {
00028 
00029 template <class M>
00030 class Publication : public ConnectionBase
00031 {
00032 public:
00033   typedef boost::shared_ptr< Publication<M> > shared_ptr;
00034   
00035   Publication(const std::string& topic) : ConnectionBase(topic) {}
00036   ~Publication() {}
00037 
00038   bool publish(M message)
00039   {
00040     typename ChannelElement<M>::shared_ptr output
00041                 = boost::static_pointer_cast< ChannelElement<M> >(this->getChannelElement());
00042     typename ChannelElement<M>::shared_ptr mq_output
00043                 = boost::static_pointer_cast< ChannelElement<M> >(this->getMQChannelElement());
00044     
00045     if (!(mq_output || output))
00046     {
00047       return false;
00048     }
00049     if (mq_output)
00050     {
00051       mq_output->write(message);
00052     }
00053     if (output)
00054     {
00055       output->write(message);
00056     }
00057     return true;
00058   }
00059 
00060   virtual bool channelReady(ChannelElementBase::shared_ptr channel) {return false;}
00061 
00062   virtual bool mqChannelReady(ChannelElementBase::shared_ptr channel) {return false;}
00063 
00064 };
00065 
00066 }
00067 
00068 #endif


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