naoqidriver
basic.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Aldebaran
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef BASIC_PUBLISHER_HPP
19 #define BASIC_PUBLISHER_HPP
20 
21 #include <string>
22 
23 /*
24 * ROS includes
25 */
26 #include <ros/ros.h>
27 
28 namespace naoqi
29 {
30 namespace publisher
31 {
32 
33 template<class T>
35 {
36 
37 public:
38  BasicPublisher( const std::string& topic ):
39  topic_( topic ),
40  is_initialized_( false )
41  {}
42 
43  virtual ~BasicPublisher() {}
44 
45  inline std::string topic() const
46  {
47  return topic_;
48  }
49 
50  inline bool isInitialized() const
51  {
52  return is_initialized_;
53  }
54 
55  virtual inline bool isSubscribed() const
56  {
57  if (is_initialized_ == false) return false;
58  return pub_.getNumSubscribers() > 0;
59  }
60 
61  virtual void publish( const T& msg )
62  {
63  pub_.publish( msg );
64  }
65 
66  virtual void reset( ros::NodeHandle& nh )
67  {
68  pub_ = nh.advertise<T>( this->topic_, 10 );
69  is_initialized_ = true;
70  }
71 
72 protected:
73  std::string topic_;
74 
76 
78  ros::Publisher pub_;
79 }; // class
80 
81 } // publisher
82 } // naoqi
83 
84 #endif
std::string topic() const
Definition: basic.hpp:45
bool isInitialized() const
Definition: basic.hpp:50
bool is_initialized_
Definition: basic.hpp:75
Definition: audio.cpp:29
virtual ~BasicPublisher()
Definition: basic.hpp:43
Definition: basic.hpp:34
virtual void publish(const T &msg)
Definition: basic.hpp:61
virtual void reset(ros::NodeHandle &nh)
Definition: basic.hpp:66
std::string topic_
Definition: basic.hpp:73
ros::Publisher pub_
Definition: basic.hpp:78
virtual bool isSubscribed() const
Definition: basic.hpp:55
BasicPublisher(const std::string &topic)
Definition: basic.hpp:38