basic.hpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2015 Aldebaran
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 
00018 #ifndef BASIC_PUBLISHER_HPP
00019 #define BASIC_PUBLISHER_HPP
00020 
00021 #include <string>
00022 
00023 /*
00024 * ROS includes
00025 */
00026 #include <ros/ros.h>
00027 
00028 namespace naoqi
00029 {
00030 namespace publisher
00031 {
00032 
00033 template<class T>
00034 class BasicPublisher
00035 {
00036 
00037 public:
00038   BasicPublisher( const std::string& topic ):
00039     topic_( topic ),
00040     is_initialized_( false )
00041   {}
00042 
00043   virtual ~BasicPublisher() {}
00044 
00045   inline std::string topic() const
00046   {
00047     return topic_;
00048   }
00049 
00050   inline bool isInitialized() const
00051   {
00052     return is_initialized_;
00053   }
00054 
00055   virtual inline bool isSubscribed() const
00056   {
00057     if (is_initialized_ == false) return false;
00058       return pub_.getNumSubscribers() > 0;
00059   }
00060 
00061   virtual void publish( const T& msg )
00062   {
00063     pub_.publish( msg );
00064   }
00065 
00066   virtual void reset( ros::NodeHandle& nh )
00067   {
00068     pub_ = nh.advertise<T>( this->topic_, 10 );
00069     is_initialized_ = true;
00070   }
00071 
00072 protected:
00073   std::string topic_;
00074 
00075   bool is_initialized_;
00076 
00078   ros::Publisher pub_;
00079 }; // class
00080 
00081 } // publisher
00082 } // naoqi
00083 
00084 #endif


naoqi_driver
Author(s): Karsten Knese
autogenerated on Sun Sep 17 2017 02:57:14