publishers/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 
79 }; // class
80 
81 } // publisher
82 } // naoqi
83 
84 #endif
void publish(const boost::shared_ptr< M > &message) const
virtual void publish(const T &msg)
virtual void reset(ros::NodeHandle &nh)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
uint32_t getNumSubscribers() const
virtual bool isSubscribed() const
BasicPublisher(const std::string &topic)


naoqi_driver
Author(s): Karsten Knese
autogenerated on Sat Feb 15 2020 03:24:26