Go to the documentation of this file.00001
00023 #ifndef LISTENER_HELPER_H_
00024 #define LISTENER_HELPER_H_
00025
00026 #include <iostream>
00027 #include <boost/function.hpp>
00028 #include "micros_swarm/packet_type.h"
00029 #include "micros_swarm/serialize.h"
00030
00031 namespace micros_swarm{
00032
00033 class ListenerHelper{
00034 public:
00035 virtual void call(const std::vector<uint8_t>& value_vec)=0;
00036 };
00037
00038 template<typename Type>
00039 class ListenerHelperT : public ListenerHelper{
00040 public:
00041 ListenerHelperT(const std::string& key, const boost::function<void(const Type&)>& callback)
00042 {
00043 key_ = key;
00044 callback_ = callback;
00045 }
00046
00047 virtual void call(const std::vector<uint8_t>& value_vec)
00048 {
00049 callback_(convertType(value_vec));
00050 }
00051
00052 Type convertType(const std::vector<uint8_t>& value_vec)
00053 {
00054 Type value = deserialize_ros<Type>(value_vec);
00055 return value;
00056 }
00057
00058 private:
00059 boost::function<void(const Type&)> callback_;
00060 std::string key_;
00061 };
00062 };
00063 #endif