single_subscriber_publisher.h
Go to the documentation of this file.
00001 #ifndef MESSAGE_TRANSPORT_SINGLE_SUBSCRIBER_PUBLISHER
00002 #define MESSAGE_TRANSPORT_SINGLE_SUBSCRIBER_PUBLISHER
00003 
00004 #include <ros/ros.h>
00005 #include <boost/noncopyable.hpp>
00006 #include <boost/function.hpp>
00007 
00008 namespace message_transport {
00009 
00014         template <class M>
00015                 class SingleSubscriberPublisher : boost::noncopyable
00016         {
00017                 public:
00018                         typedef boost::function<uint32_t()> GetNumSubscribersFn;
00019                         typedef boost::function<void(const M&)> PublishFn;
00020                         typedef boost::function<void(const SingleSubscriberPublisher<M>&)> StatusCB;
00021 
00022                         SingleSubscriberPublisher(const std::string& caller_id, const std::string& topic,
00023                                         const GetNumSubscribersFn& num_subscribers_fn,
00024                                         const PublishFn& publish_fn)
00025                                 : caller_id_(caller_id), topic_(topic),
00026                                 num_subscribers_fn_(num_subscribers_fn),
00027                                 publish_fn_(publish_fn) { }
00028 
00029                         std::string getSubscriberName() const
00030                         {
00031                                 return caller_id_;
00032                         }
00033 
00034                         std::string getTopic() const
00035                         {
00036                                 return topic_;
00037                         }
00038 
00039                         uint32_t getNumSubscribers() const
00040                         {
00041                                 return num_subscribers_fn_();
00042                         }
00043 
00044                         void publish(const M& message) const
00045                         {
00046                                 publish_fn_(message);
00047                         }
00048 
00049                         void publish(const typename M::ConstPtr& message) const
00050                         {
00051                                 publish_fn_(*message);
00052                         }
00053 
00054                 private:
00055                         std::string caller_id_;
00056                         std::string topic_;
00057                         GetNumSubscribersFn num_subscribers_fn_;
00058                         PublishFn publish_fn_;
00059 
00060                         friend class Publisher; // to get publish_fn_ directly
00061                         friend class PublisherImplGen; // to get publish_fn_ directly
00062         };
00063 
00064 
00065 } //namespace message_transport
00066 
00067 #endif


message_transport_common
Author(s): Cedric Pradalier
autogenerated on Sat Dec 28 2013 16:56:55