mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
publisher_handler.h
Go to the documentation of this file.
1 
5 #ifndef PUBLISHER_HANDLER_H
6 #define PUBLISHER_HANDLER_H
7 
8 #include <ros/ros.h>
9 #include <ros/package.h>
10 
11 #include <atomic>
12 #include <string>
13 #include <mutex>
14 
15 namespace mrs_lib
16 {
17 
18 /* class PublisherHandler_impl //{ */
19 
23 template <class TopicType>
25 
26 public:
31 
36 
45  PublisherHandler_impl(ros::NodeHandle& nh, const std::string& address, const unsigned int& buffer_size = 1, const bool& latch = false,
46  const double& rate = 0.0);
47 
54  void publish(const TopicType& msg);
55 
61  void publish(const boost::shared_ptr<TopicType>& msg);
62 
68  void publish(const boost::shared_ptr<TopicType const>& msg);
69 
75  unsigned int getNumSubscribers(void);
76 
77 private:
78  ros::Publisher publisher_;
79  std::mutex mutex_publisher_;
80  std::atomic<bool> publisher_initialized_;
81 
82  bool throttle_ = false;
83  double throttle_min_dt_;
84  ros::Time last_time_published_;
85 };
86 
87 //}
88 
89 /* class PublisherHandler //{ */
90 
94 template <class TopicType>
96 
97 public:
102 
107 
116 
122  PublisherHandler(const PublisherHandler& other);
123 
132  PublisherHandler(ros::NodeHandle& nh, const std::string& address, const unsigned int& buffer_size = 1, const bool& latch = false, const double& rate = 0);
133 
139  void publish(const TopicType& msg);
140 
146  void publish(const boost::shared_ptr<TopicType>& msg);
147 
153  void publish(const boost::shared_ptr<TopicType const>& msg);
154 
160  unsigned int getNumSubscribers(void);
161 
162 private:
163  std::shared_ptr<PublisherHandler_impl<TopicType>> impl_;
164 };
165 
166 //}
167 
168 } // namespace mrs_lib
169 
170 #include <mrs_lib/impl/publisher_handler.hpp>
171 
172 #endif // PUBLISHER_HANDLER_H
mrs_lib::PublisherHandler::PublisherHandler
PublisherHandler(void)
generic constructor
Definition: publisher_handler.h:101
mrs_lib::PublisherHandler::publish
void publish(const TopicType &msg)
publish message
Definition: publisher_handler.hpp:209
mrs_lib::PublisherHandler_impl::publish
void publish(const TopicType &msg)
publish message
Definition: publisher_handler.hpp:54
mrs_lib::PublisherHandler::~PublisherHandler
~PublisherHandler(void)
generic destructor
Definition: publisher_handler.h:106
mrs_lib::PublisherHandler::operator=
PublisherHandler & operator=(const PublisherHandler &other)
operator=
Definition: publisher_handler.hpp:168
mrs_lib
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition: attitude_converter.h:29
mrs_lib::PublisherHandler_impl
implementation of the publisher handler
Definition: publisher_handler.h:24
mrs_lib::PublisherHandler_impl::getNumSubscribers
unsigned int getNumSubscribers(void)
get number of subscribers
Definition: publisher_handler.hpp:150
mrs_lib::PublisherHandler_impl::~PublisherHandler_impl
~PublisherHandler_impl(void)
default destructor
Definition: publisher_handler.h:35
mrs_lib::PublisherHandler
user wrapper of the publisher handler implementation
Definition: publisher_handler.h:95
mrs_lib::PublisherHandler::getNumSubscribers
unsigned int getNumSubscribers(void)
get number of subscribers
Definition: publisher_handler.hpp:239
mrs_lib::PublisherHandler_impl::PublisherHandler_impl
PublisherHandler_impl(void)
default constructor
Definition: publisher_handler.hpp:14