|
| 1 | + |
| 2 | +#ifndef RTT_ROSCOMM__PASSTHROUGH_CALLBACK_QUEUE_HPP_ |
| 3 | +#define RTT_ROSCOMM__PASSTHROUGH_CALLBACK_QUEUE_HPP_ |
| 4 | + |
| 5 | +#include <ros/ros.h> |
| 6 | +#include <ros/callback_queue_interface.h> |
| 7 | +#include <ros/subscription_queue.h> |
| 8 | +#include <ros/callback_queue.h> |
| 9 | + |
| 10 | +namespace rtt_roscomm { |
| 11 | + class PassthroughCallbackQueue: public ros::CallbackQueueInterface |
| 12 | + { |
| 13 | + public: |
| 14 | + PassthroughCallbackQueue(); |
| 15 | + |
| 16 | + /** |
| 17 | + * Implementation of ros::CallbackQueueInterface::addCallback() |
| 18 | + * |
| 19 | + * @param callback aaa |
| 20 | + * @param owner_id aaa |
| 21 | + * |
| 22 | + * @return void |
| 23 | + */ |
| 24 | + virtual void addCallback( |
| 25 | + const ros::CallbackInterfacePtr &callback, |
| 26 | + uint64_t owner_id=0); |
| 27 | + |
| 28 | + /** |
| 29 | + * Implementation of ros::CallbackQueueInterface::removeByID() |
| 30 | + * |
| 31 | + * @param owner_id aaa |
| 32 | + * |
| 33 | + * @return void |
| 34 | + */ |
| 35 | + virtual void removeByID(uint64_t owner_id); |
| 36 | + |
| 37 | + private: |
| 38 | + |
| 39 | + /** |
| 40 | + * Port where to write the message |
| 41 | + */ |
| 42 | + // base::PortInterface* output_port_ptr_; |
| 43 | + |
| 44 | + }; // class PassthroughCallbackQueue |
| 45 | + |
| 46 | + /** |
| 47 | + * Helpers to generate subscribers with a custom ros::CallbackQueueInterface |
| 48 | + */ |
| 49 | + |
| 50 | + // template<class M, class T> |
| 51 | + // ros::Subscriber subscribe(const std::string& topic, uint32_t queue_size, |
| 52 | + // void(T::*fp)(const boost::shared_ptr<M const>&) const, T* obj, |
| 53 | + // ros::CallbackQueueInterface* cq, ros::NodeHandle& nh, |
| 54 | + // const TransportHints& transport_hints = ros::TransportHints()) |
| 55 | + // { |
| 56 | + // ros::SubscribeOptions ops; |
| 57 | + // ops.template init<M>(topic, queue_size, boost::bind(fp, obj, _1)); |
| 58 | + // ops.transport_hints = transport_hints; |
| 59 | + // ops.callback_queue = cq; |
| 60 | + // return nh.subscribe(ops); |
| 61 | + // } |
| 62 | + |
| 63 | + template<class M, class T> |
| 64 | + ros::Subscriber subscribe( |
| 65 | + ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, |
| 66 | + const std::string& topic, uint32_t queue_size, void(T::*fp)(M), T* obj, |
| 67 | + const ros::TransportHints& transport_hints = ros::TransportHints()) |
| 68 | + { |
| 69 | + ros::SubscribeOptions ops; |
| 70 | + ops.template initByFullCallbackType<M>(topic, queue_size, boost::bind(fp, obj, _1)); |
| 71 | + ops.transport_hints = transport_hints; |
| 72 | + ops.callback_queue = cq; |
| 73 | + return nh.subscribe(ops); |
| 74 | + } |
| 75 | + |
| 76 | + /// and the const version |
| 77 | + template<class M, class T> |
| 78 | + ros::Subscriber subscribe( |
| 79 | + ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, |
| 80 | + const std::string& topic, uint32_t queue_size, void(T::*fp)(M) const, T* obj, |
| 81 | + const ros::TransportHints& transport_hints = ros::TransportHints()) |
| 82 | + { |
| 83 | + ros::SubscribeOptions ops; |
| 84 | + ops.template initByFullCallbackType<M>(topic, queue_size, boost::bind(fp, obj, _1)); |
| 85 | + ops.transport_hints = transport_hints; |
| 86 | + ops.callback_queue = cq; |
| 87 | + return nh.subscribe(ops); |
| 88 | + } |
| 89 | + template<class M, class T> |
| 90 | + ros::Subscriber subscribe( |
| 91 | + ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, |
| 92 | + const std::string& topic, uint32_t queue_size, |
| 93 | + void(T::*fp)(const boost::shared_ptr<M const>&), T* obj, |
| 94 | + const ros::TransportHints& transport_hints = ros::TransportHints()) |
| 95 | + { |
| 96 | + ros::SubscribeOptions ops; |
| 97 | + ops.template init<M>(topic, queue_size, boost::bind(fp, obj, _1)); |
| 98 | + ops.transport_hints = transport_hints; |
| 99 | + ops.callback_queue = cq; |
| 100 | + return nh.subscribe(ops); |
| 101 | + } |
| 102 | + template<class M, class T> |
| 103 | + ros::Subscriber subscribe( |
| 104 | + ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, |
| 105 | + const std::string& topic, uint32_t queue_size, |
| 106 | + void(T::*fp)(const boost::shared_ptr<M const>&) const, T* obj, |
| 107 | + const ros::TransportHints& transport_hints = ros::TransportHints()) |
| 108 | + { |
| 109 | + ros::SubscribeOptions ops; |
| 110 | + ops.template init<M>(topic, queue_size, boost::bind(fp, obj, _1)); |
| 111 | + ops.transport_hints = transport_hints; |
| 112 | + ops.callback_queue = cq; |
| 113 | + return nh.subscribe(ops); |
| 114 | + } |
| 115 | + template<class M, class T> |
| 116 | + ros::Subscriber subscribe( |
| 117 | + ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, |
| 118 | + const std::string& topic, uint32_t queue_size, void(T::*fp)(M), |
| 119 | + const boost::shared_ptr<T>& obj, |
| 120 | + const ros::TransportHints& transport_hints = ros::TransportHints()) |
| 121 | + { |
| 122 | + ros::SubscribeOptions ops; |
| 123 | + ops.template initByFullCallbackType<M>(topic, queue_size, boost::bind(fp, obj.get(), _1)); |
| 124 | + ops.tracked_object = obj; |
| 125 | + ops.transport_hints = transport_hints; |
| 126 | + ops.callback_queue = cq; |
| 127 | + return nh.subscribe(ops); |
| 128 | + } |
| 129 | + |
| 130 | + template<class M, class T> |
| 131 | + ros::Subscriber subscribe( |
| 132 | + ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, |
| 133 | + const std::string& topic, uint32_t queue_size, void(T::*fp)(M) const, |
| 134 | + const boost::shared_ptr<T>& obj, |
| 135 | + const ros::TransportHints& transport_hints = ros::TransportHints()) |
| 136 | + { |
| 137 | + ros::SubscribeOptions ops; |
| 138 | + ops.template initByFullCallbackType<M>(topic, queue_size, boost::bind(fp, obj.get(), _1)); |
| 139 | + ops.tracked_object = obj; |
| 140 | + ops.transport_hints = transport_hints; |
| 141 | + ops.callback_queue = cq; |
| 142 | + return nh.subscribe(ops); |
| 143 | + } |
| 144 | + template<class M, class T> |
| 145 | + ros::Subscriber subscribe( |
| 146 | + ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, |
| 147 | + const std::string& topic, uint32_t queue_size, |
| 148 | + void(T::*fp)(const boost::shared_ptr<M const>&), |
| 149 | + const boost::shared_ptr<T>& obj, |
| 150 | + const ros::TransportHints& transport_hints = ros::TransportHints()) |
| 151 | + { |
| 152 | + ros::SubscribeOptions ops; |
| 153 | + ops.template init<M>(topic, queue_size, boost::bind(fp, obj.get(), _1)); |
| 154 | + ops.tracked_object = obj; |
| 155 | + ops.transport_hints = transport_hints; |
| 156 | + ops.callback_queue = cq; |
| 157 | + return nh.subscribe(ops); |
| 158 | + } |
| 159 | + template<class M, class T> |
| 160 | + ros::Subscriber subscribe( |
| 161 | + ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, |
| 162 | + const std::string& topic, uint32_t queue_size, |
| 163 | + void(T::*fp)(const boost::shared_ptr<M const>&) const, |
| 164 | + const boost::shared_ptr<T>& obj, |
| 165 | + const ros::TransportHints& transport_hints = ros::TransportHints()) |
| 166 | + { |
| 167 | + ros::SubscribeOptions ops; |
| 168 | + ops.template init<M>(topic, queue_size, boost::bind(fp, obj.get(), _1)); |
| 169 | + ops.tracked_object = obj; |
| 170 | + ops.transport_hints = transport_hints; |
| 171 | + ops.callback_queue = cq; |
| 172 | + return nh.subscribe(ops); |
| 173 | + } |
| 174 | + template<class M> |
| 175 | + ros::Subscriber subscribe( |
| 176 | + ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, |
| 177 | + const std::string& topic, uint32_t queue_size, void(*fp)(M), |
| 178 | + const ros::TransportHints& transport_hints = ros::TransportHints()) |
| 179 | + { |
| 180 | + ros::SubscribeOptions ops; |
| 181 | + ops.template initByFullCallbackType<M>(topic, queue_size, fp); |
| 182 | + ops.transport_hints = transport_hints; |
| 183 | + ops.callback_queue = cq; |
| 184 | + return nh.subscribe(ops); |
| 185 | + } |
| 186 | + template<class M> |
| 187 | + ros::Subscriber subscribe( |
| 188 | + ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, |
| 189 | + const std::string& topic, uint32_t queue_size, |
| 190 | + void(*fp)(const boost::shared_ptr<M const>&), |
| 191 | + const ros::TransportHints& transport_hints = ros::TransportHints()) |
| 192 | + { |
| 193 | + ros::SubscribeOptions ops; |
| 194 | + ops.template init<M>(topic, queue_size, fp); |
| 195 | + ops.transport_hints = transport_hints; |
| 196 | + ops.callback_queue = cq; |
| 197 | + return nh.subscribe(ops); |
| 198 | + } |
| 199 | + template<class M> |
| 200 | + ros::Subscriber subscribe( |
| 201 | + ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, |
| 202 | + const std::string& topic, uint32_t queue_size, |
| 203 | + const boost::function<void (const boost::shared_ptr<M const>&)>& callback, |
| 204 | + const ros::VoidConstPtr& tracked_object = ros::VoidConstPtr(), |
| 205 | + const ros::TransportHints& transport_hints = ros::TransportHints()) |
| 206 | + { |
| 207 | + ros::SubscribeOptions ops; |
| 208 | + ops.template init<M>(topic, queue_size, callback); |
| 209 | + ops.tracked_object = tracked_object; |
| 210 | + ops.transport_hints = transport_hints; |
| 211 | + ops.callback_queue = cq; |
| 212 | + return nh.subscribe(ops); |
| 213 | + } |
| 214 | + template<class M, class C> |
| 215 | + ros::Subscriber subscribe( |
| 216 | + ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, |
| 217 | + const std::string& topic, uint32_t queue_size, |
| 218 | + const boost::function<void (C)>& callback, |
| 219 | + const ros::VoidConstPtr& tracked_object = ros::VoidConstPtr(), |
| 220 | + const ros::TransportHints& transport_hints = ros::TransportHints()) |
| 221 | + { |
| 222 | + ros::SubscribeOptions ops; |
| 223 | + ops.template initByFullCallbackType<C>(topic, queue_size, callback); |
| 224 | + ops.tracked_object = tracked_object; |
| 225 | + ops.transport_hints = transport_hints; |
| 226 | + ops.callback_queue = cq; |
| 227 | + return nh.subscribe(ops); |
| 228 | + } |
| 229 | + |
| 230 | +} // namespace rtt_roscomm |
| 231 | + |
| 232 | +#endif // RTT_ROSCOMM__PASSTHROUGH_CALLBACK_QUEUE_HPP_ |
0 commit comments