bz2_subscriber.h
Go to the documentation of this file.
00001 #ifndef BZ2_MESSAGE_TRANSPORT_SUBSCRIBER_H
00002 #define BZ2_MESSAGE_TRANSPORT_SUBSCRIBER_H
00003 
00004 
00005 #include <string>
00006 
00007 #include <message_transport/simple_subscriber_plugin.h>
00008 #include <bz2_transport/BZ2Packet.h>
00009 #include <bz2_transport/bz2_codec.h>
00010 
00011 namespace bz2_transport {
00012 
00013         template <class Base>
00014         class BZ2Subscriber : public message_transport::SimpleSubscriberPlugin<Base,bz2_transport::BZ2Packet>
00015         {
00016                 public:
00017                         BZ2Subscriber() { }
00018 
00019                         virtual ~BZ2Subscriber() {
00020                                 // close listener
00021                 ROS_INFO("Shutting down BZ2Subscriber");
00022                         }
00023 
00024                         virtual std::string getTransportName() const
00025                         {
00026                                 return "bz2";
00027                         }
00028 
00029                 protected:
00030                         virtual void internalCallback(const bz2_transport::BZ2PacketConstPtr& message,
00031                                         const typename message_transport::SimpleSubscriberPlugin<Base,bz2_transport::BZ2Packet>::Callback& user_cb)
00032                         {
00033 
00034                 boost::shared_array<uint8_t> buffer;
00035                 size_t len;
00036                 if (codec.decompress(*message, buffer, len)) {
00037                     boost::shared_ptr<Base> message_ptr(new Base);
00038                     ros::serialization::IStream in(buffer.get(),len);
00039                     ros::serialization::deserialize(in, *message_ptr);
00040                     if (user_cb && ros::ok()) {
00041                         user_cb(message_ptr);
00042                     }
00043                 }
00044                         }
00045 
00046 
00047             BZ2Codec codec;
00048         };
00049 
00050 } //namespace transport
00051 
00052 #endif // BZ2_MESSAGE_TRANSPORT_SUBSCRIBER_H


bz2_transport
Author(s): Cedric Pradalier
autogenerated on Sat Dec 28 2013 16:57:04