diagnosed_pub_sub.hpp
Go to the documentation of this file.
1 #pragma once
2 
11 #include <functional>
12 #include <memory>
13 #include <string>
14 #include <type_traits>
15 
16 #include <boost/function.hpp>
17 #include <boost/shared_ptr.hpp>
18 
20 #include <ros/forwards.h>
21 #include <ros/message_event.h>
22 #include <ros/message_traits.h>
23 #include <ros/node_handle.h>
24 #include <ros/publisher.h>
25 #include <ros/rate.h>
26 #include <ros/subscriber.h>
27 #include <ros/subscribe_options.h>
28 
34 
35 namespace cras
36 {
37 
56 template<class Message, typename Enable = ::std::enable_if_t<::ros::message_traits::IsMessage<Message>::value>>
58 {
59 public:
64  explicit DiagnosedPubSub(const ::std::shared_ptr<::cras::TopicStatus<Message>>& diag);
65 
71  explicit DiagnosedPubSub(const ::std::string& name, const ::cras::TopicStatusParam<Message>& diagParams);
72 
79  const ::cras::SimpleTopicStatusParam<Message>& defaultParams);
80 
86 
87  virtual ~DiagnosedPubSub() = default;
88 
94 
99  virtual ::std::shared_ptr<::cras::TopicStatus<Message>> getDiagnosticTask() const;
100 
101 protected:
109  template <class M = Message, ::std::enable_if_t<::ros::message_traits::HasHeader<M>::value, bool> EnableM = true>
110  void addDelayParams(::cras::SimpleTopicStatusParam<Message>& topicStatusParam,
112 
120  template <class M = Message, ::std::enable_if_t<!::ros::message_traits::HasHeader<M>::value, bool> EnableM = true>
121  void addDelayParams(::cras::SimpleTopicStatusParam<Message>& topicStatusParam,
123 
125  ::std::shared_ptr<::cras::TopicStatus<Message>> diag {nullptr};
126 };
127 
135 template<class Message, typename Enable = ::std::enable_if_t<::ros::message_traits::IsMessage<Message>::value>>
137 {
138 public:
144  DiagnosedPublisher(const ::ros::Publisher &pub, const ::std::shared_ptr<::cras::TopicStatus<Message>>& diag);
145 
152  DiagnosedPublisher(const ::ros::Publisher &pub, const ::std::string& name,
153  const ::cras::TopicStatusParam<Message>& diagParams);
154 
162  DiagnosedPublisher(const ::ros::Publisher &pub, const ::cras::BoundParamHelperPtr& params,
163  const ::cras::SimpleTopicStatusParam<Message>& defaultParams);
164 
171  DiagnosedPublisher(const ::ros::Publisher &pub, const ::cras::BoundParamHelperPtr& params);
172 
173  [[deprecated]]
174  DiagnosedPublisher(const ::ros::Publisher &pub, ::diagnostic_updater::Updater& updater,
176 
177  [[deprecated]]
178  DiagnosedPublisher(const ::ros::Publisher &pub, ::diagnostic_updater::Updater& updater,
179  const ::cras::BoundParamHelperPtr& params, const ::ros::Rate& defaultRate);
180 
181  [[deprecated]]
182  DiagnosedPublisher(const ::ros::Publisher &pub, ::diagnostic_updater::Updater& updater,
183  const ::cras::BoundParamHelperPtr& params, const ::ros::Rate& defaultRate,
184  const ::ros::Rate& defaultMinRate, const ::ros::Rate& defaultMaxRate);
185 
186  [[deprecated]]
187  ::ros::Rate getDesiredRate() const;
188 
193  virtual void publish(const typename Message::Ptr& message);
194 
199  virtual void publish(const Message& message);
200 
205  const ::ros::Publisher& getPublisher() const;
206 
211  ::ros::Publisher& getPublisher();
212 
217  void setPublisher(const ::ros::Publisher& pub);
218 
219 protected:
222 };
223 
229 template<class Message, typename Enable = ::std::enable_if_t<::ros::message_traits::IsMessage<Message>::value>>
231 {
232 public:
245  template <typename M, typename EnableM = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
248  const ::std::string& topic, uint32_t queue_size, void(*cb)(M), ::ros::TransportHints hints = {});
249 
261  const ::cras::SimpleTopicStatusParam<Message>& defaultParams,
262  const ::std::string& topic, uint32_t queue_size,
263  const ::boost::function<void(const ::boost::shared_ptr<Message>&)>& cb, ::ros::TransportHints hints = {});
264 
278  template <typename C, typename EnableC = ::std::enable_if_t<::cras::IsMessageParam<C>::value>>
281  const ::std::string& topic, uint32_t queue_size,
282  const ::boost::function<void(C)>& cb, ::ros::VoidConstPtr obj = {}, ::ros::TransportHints hints = {});
283 
297  template<typename M, class T, typename EnableM = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
300  const ::std::string& topic, uint32_t queue_size, void(T::*cb)(M), T* obj, ::ros::TransportHints hints = {});
301 
315  template<typename M, class T, typename EnableM = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
318  const ::std::string& topic, uint32_t queue_size, void(T::*cb)(M) const, T* obj, ::ros::TransportHints hints = {});
319 
333  template<typename M, class T, typename EnableM = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
336  const ::std::string& topic, uint32_t queue_size, void(T::*cb)(M), const ::boost::shared_ptr<T>& obj,
337  ::ros::TransportHints hints = {});
338 
352  template<typename M, class T, typename EnableM = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
355  const ::std::string& topic, uint32_t queue_size, void(T::*cb)(M) const, const ::boost::shared_ptr<T>& obj,
356  ::ros::TransportHints hints = {});
357 
368  const ::cras::SimpleTopicStatusParam<Message>& defaultParams, ::ros::SubscribeOptions& options);
369 
374  const ::ros::Subscriber& getSubscriber() const;
375 
380  ::ros::Subscriber& getSubscriber();
381 
382 protected:
388  ::boost::function<void(const Message&)> addTick(const ::std::function<void(const Message&)>& fn);
389 
395  ::boost::function<void(const typename Message::Ptr&)> addTick(
396  const ::std::function<void(const typename Message::Ptr&)>& fn);
397 
403  ::boost::function<void(const ::ros::MessageEvent<Message>&)> addTick(
404  const ::std::function<void(const ::ros::MessageEvent<Message>&)>& fn);
405 
414  template <typename T, typename M, typename EnableM = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
415  ::boost::function<void(M)> addTick(const ::std::function<void(M)>& fn, T);
416 
426  template <typename T, typename M, typename EnableM = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
427  ::boost::function<void(M)> addTick(void(T::*fn)(M), T* obj);
428 
438  template <typename T, typename M, typename EnableM = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
439  ::boost::function<void(M)> addTick(void(T::*fn)(M), const ::boost::shared_ptr<T>& obj);
440 
450  template <typename T, typename M, typename EnableM = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
451  ::boost::function<void(M)> addTick(void(T::*fn)(M) const, T* obj);
452 
462  template <typename T, typename M, typename EnableM = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
463  ::boost::function<void(M)> addTick(void(T::*fn)(M) const, const ::boost::shared_ptr<T>& obj);
464 
467 };
468 
469 // Class template deduction guides allow leaving out the type parameter when declaring a DiagnosedSubscriber. C++17 only
470 #if __cpp_deduction_guides
471 
472 template <typename M, typename = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
474  const ::cras::SimpleTopicStatusParam<::cras::BaseMessage<M>>&, const ::std::string&, uint32_t, void(*)(M),
475  ::ros::TransportHints = {})
477 
478 template <typename C, typename = ::std::enable_if_t<::cras::IsMessageParam<C>::value>>
480  const ::cras::SimpleTopicStatusParam<::cras::BaseMessage<C>>&, const ::std::string&, uint32_t,
481  const ::boost::function<void(C)>&, ::ros::VoidConstPtr = {}, ::ros::TransportHints = {})
483 
484 template<typename M, class T, typename = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
486  const ::cras::SimpleTopicStatusParam<::cras::BaseMessage<M>>&, const ::std::string&, uint32_t,
487  void(T::*)(M), T*, ::ros::TransportHints = {})
489 
490 template<typename M, class T, typename = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
492  const ::cras::SimpleTopicStatusParam<::cras::BaseMessage<M>>&, const ::std::string&, uint32_t,
493  void(T::*)(M) const, T*, ::ros::TransportHints = {})
495 
496 template<typename M, class T, typename = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
498  const ::cras::SimpleTopicStatusParam<::cras::BaseMessage<M>>&, const ::std::string&, uint32_t,
499  void(T::*)(M), const ::boost::shared_ptr<T>&, ::ros::TransportHints = {})
501 
502 template<typename M, class T, typename = ::std::enable_if_t<::cras::IsMessageParam<M>::value>>
504  const ::cras::SimpleTopicStatusParam<::cras::BaseMessage<M>>&, const ::std::string&, uint32_t,
505  void(T::*)(M) const, const ::boost::shared_ptr<T>&, ::ros::TransportHints = {})
507 
508 #endif
509 }
510 
511 #include <cras_cpp_common/diag_utils/impl/diagnosed_pub_sub.hpp>
Diagnostic task for topic frequency and timestamp delay (combining FrequencyStatus and TimeStampStatu...
Wrapper for ROS subscriber that automatically diagnoses the rate and delay of received messages...
Utilities for working with ROS message files.
Definitions of parameters for a TopicStatus diagnostic task.
virtual ::std::shared_ptr<::cras::TopicStatus< Message > > getDiagnosticTask() const
Get the topic diagnostic task.
Utilities for working with C++ types.
Diagnostic task for topic frequency and timestamp delay (combining FrequencyStatus and TimeStampStatu...
::std::conditional_t<::ros::message_traits::HasHeader< Message >::value, ::cras::SimpleTopicStatusParamWithHeader, ::cras::SimpleTopicStatusParamNoHeader > SimpleTopicStatusParam
Helper struct for easy brace-initialization of TopicStatusParam objects.
updater
::std::shared_ptr<::cras::BoundParamHelper > BoundParamHelperPtr
DiagnosedPubSub(const ::std::shared_ptr<::cras::TopicStatus< Message >> &diag)
Use the given diagnostic task to diagnose the publisher/subscriber.
options
Base for ROS publisher and subscriber with automatic message rate and delay diagnostics.
typename ::ros::ParameterAdapter< M >::Message BaseMessage
Return the base message type of M (i.e. removes MessageEvent, const, &, shared_ptr etc...
virtual ~DiagnosedPubSub()=default
virtual void attach(::diagnostic_updater::Updater &updater)
Add the diagnostic task to the given updater.
void addDelayParams(::cras::SimpleTopicStatusParam< Message > &topicStatusParam, const ::cras::BoundParamHelperPtr &params)
When configuring from ROS params, load the delay configuration.
Wrapper for ROS publisher that automatically diagnoses the rate and delay of published messages...
Definition: any.hpp:15
Bound param helper (allows omitting the param adapter in each getParam call).
::ros::Publisher publisher
The ROS publisher.
::std::shared_ptr<::cras::TopicStatus< Message > > diag
The diagnostic task.
::ros::Subscriber subscriber
The ROS subscriber.


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Sat Jun 17 2023 02:32:53