00001 #ifndef THROTTLED_TRANSPORT_PUBLISHER_H 00002 #define THROTTLED_TRANSPORT_PUBLISHER_H 00003 00004 00005 #include <message_transport/simple_publisher_plugin.h> 00006 #include <throttled_transport/throttler.h> 00007 00008 namespace throttled_transport { 00009 00010 template <class Base> 00011 class ThrottledPublisher : 00012 public message_transport::SimplePublisherPlugin<Base,Base> 00013 { 00014 public: 00015 ThrottledPublisher() : 00016 message_transport::SimplePublisherPlugin<Base,Base>(){} 00017 virtual ~ThrottledPublisher() {} 00018 00019 virtual std::string getTransportName() const 00020 { 00021 return "throttled"; 00022 } 00023 protected: 00024 virtual void publish(const Base& message, 00025 const typename message_transport::SimplePublisherPlugin<Base,Base>::PublishFn& publish_fn) const { 00026 00027 size_t datasize = ros::serialization::serializationLength(message); 00028 if (throttler.can_publish(datasize)) { 00029 publish_fn(message); 00030 } 00031 } 00032 00033 mutable Throttler throttler; 00034 }; 00035 00036 00037 } //namespace throttled_transport 00038 00039 00040 #endif // THROTTLED_TRANSPORT_PUBLISHER_H