-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rtt_roscomm: shortcut ROS spinner callback queue
The patch introduces a new "queue" without a queue to bypass the global CallbackQueue of ROS for the subscriptions of Orocos messages. Instead, the network thread will immediately execute the callback, and will pass it to the global CallbackQueue only in case that it fails to execute with TryAgain status. Helper functions are provided to generate a subscriber with a custom implementation of CallbackQueueInterface. This method is chosen for the subscribers of the message transporter.
- Loading branch information
1 parent
c65cf80
commit 8129810
Showing
4 changed files
with
266 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
232 changes: 232 additions & 0 deletions
232
rtt_roscomm/include/rtt_roscomm/passthrough_callback_queue.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
|
||
#ifndef RTT_ROSCOMM__PASSTHROUGH_CALLBACK_QUEUE_HPP_ | ||
#define RTT_ROSCOMM__PASSTHROUGH_CALLBACK_QUEUE_HPP_ | ||
|
||
#include <ros/ros.h> | ||
#include <ros/callback_queue_interface.h> | ||
#include <ros/subscription_queue.h> | ||
#include <ros/callback_queue.h> | ||
|
||
namespace rtt_roscomm { | ||
class PassthroughCallbackQueue: public ros::CallbackQueueInterface | ||
{ | ||
public: | ||
PassthroughCallbackQueue(); | ||
|
||
/** | ||
* Implementation of ros::CallbackQueueInterface::addCallback() | ||
* | ||
* @param callback aaa | ||
* @param owner_id aaa | ||
* | ||
* @return void | ||
*/ | ||
virtual void addCallback( | ||
const ros::CallbackInterfacePtr &callback, | ||
uint64_t owner_id=0); | ||
|
||
/** | ||
* Implementation of ros::CallbackQueueInterface::removeByID() | ||
* | ||
* @param owner_id aaa | ||
* | ||
* @return void | ||
*/ | ||
virtual void removeByID(uint64_t owner_id); | ||
|
||
private: | ||
|
||
/** | ||
* Port where to write the message | ||
*/ | ||
// base::PortInterface* output_port_ptr_; | ||
|
||
}; // class PassthroughCallbackQueue | ||
|
||
/** | ||
* Helpers to generate subscribers with a custom ros::CallbackQueueInterface | ||
*/ | ||
|
||
// template<class M, class T> | ||
// ros::Subscriber subscribe(const std::string& topic, uint32_t queue_size, | ||
// void(T::*fp)(const boost::shared_ptr<M const>&) const, T* obj, | ||
// ros::CallbackQueueInterface* cq, ros::NodeHandle& nh, | ||
// const TransportHints& transport_hints = ros::TransportHints()) | ||
// { | ||
// ros::SubscribeOptions ops; | ||
// ops.template init<M>(topic, queue_size, boost::bind(fp, obj, _1)); | ||
// ops.transport_hints = transport_hints; | ||
// ops.callback_queue = cq; | ||
// return nh.subscribe(ops); | ||
// } | ||
|
||
template<class M, class T> | ||
ros::Subscriber subscribe( | ||
ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, | ||
const std::string& topic, uint32_t queue_size, void(T::*fp)(M), T* obj, | ||
const ros::TransportHints& transport_hints = ros::TransportHints()) | ||
{ | ||
ros::SubscribeOptions ops; | ||
ops.template initByFullCallbackType<M>(topic, queue_size, boost::bind(fp, obj, _1)); | ||
ops.transport_hints = transport_hints; | ||
ops.callback_queue = cq; | ||
return nh.subscribe(ops); | ||
} | ||
|
||
/// and the const version | ||
template<class M, class T> | ||
ros::Subscriber subscribe( | ||
ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, | ||
const std::string& topic, uint32_t queue_size, void(T::*fp)(M) const, T* obj, | ||
const ros::TransportHints& transport_hints = ros::TransportHints()) | ||
{ | ||
ros::SubscribeOptions ops; | ||
ops.template initByFullCallbackType<M>(topic, queue_size, boost::bind(fp, obj, _1)); | ||
ops.transport_hints = transport_hints; | ||
ops.callback_queue = cq; | ||
return nh.subscribe(ops); | ||
} | ||
template<class M, class T> | ||
ros::Subscriber subscribe( | ||
ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, | ||
const std::string& topic, uint32_t queue_size, | ||
void(T::*fp)(const boost::shared_ptr<M const>&), T* obj, | ||
const ros::TransportHints& transport_hints = ros::TransportHints()) | ||
{ | ||
ros::SubscribeOptions ops; | ||
ops.template init<M>(topic, queue_size, boost::bind(fp, obj, _1)); | ||
ops.transport_hints = transport_hints; | ||
ops.callback_queue = cq; | ||
return nh.subscribe(ops); | ||
} | ||
template<class M, class T> | ||
ros::Subscriber subscribe( | ||
ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, | ||
const std::string& topic, uint32_t queue_size, | ||
void(T::*fp)(const boost::shared_ptr<M const>&) const, T* obj, | ||
const ros::TransportHints& transport_hints = ros::TransportHints()) | ||
{ | ||
ros::SubscribeOptions ops; | ||
ops.template init<M>(topic, queue_size, boost::bind(fp, obj, _1)); | ||
ops.transport_hints = transport_hints; | ||
ops.callback_queue = cq; | ||
return nh.subscribe(ops); | ||
} | ||
template<class M, class T> | ||
ros::Subscriber subscribe( | ||
ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, | ||
const std::string& topic, uint32_t queue_size, void(T::*fp)(M), | ||
const boost::shared_ptr<T>& obj, | ||
const ros::TransportHints& transport_hints = ros::TransportHints()) | ||
{ | ||
ros::SubscribeOptions ops; | ||
ops.template initByFullCallbackType<M>(topic, queue_size, boost::bind(fp, obj.get(), _1)); | ||
ops.tracked_object = obj; | ||
ops.transport_hints = transport_hints; | ||
ops.callback_queue = cq; | ||
return nh.subscribe(ops); | ||
} | ||
|
||
template<class M, class T> | ||
ros::Subscriber subscribe( | ||
ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, | ||
const std::string& topic, uint32_t queue_size, void(T::*fp)(M) const, | ||
const boost::shared_ptr<T>& obj, | ||
const ros::TransportHints& transport_hints = ros::TransportHints()) | ||
{ | ||
ros::SubscribeOptions ops; | ||
ops.template initByFullCallbackType<M>(topic, queue_size, boost::bind(fp, obj.get(), _1)); | ||
ops.tracked_object = obj; | ||
ops.transport_hints = transport_hints; | ||
ops.callback_queue = cq; | ||
return nh.subscribe(ops); | ||
} | ||
template<class M, class T> | ||
ros::Subscriber subscribe( | ||
ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, | ||
const std::string& topic, uint32_t queue_size, | ||
void(T::*fp)(const boost::shared_ptr<M const>&), | ||
const boost::shared_ptr<T>& obj, | ||
const ros::TransportHints& transport_hints = ros::TransportHints()) | ||
{ | ||
ros::SubscribeOptions ops; | ||
ops.template init<M>(topic, queue_size, boost::bind(fp, obj.get(), _1)); | ||
ops.tracked_object = obj; | ||
ops.transport_hints = transport_hints; | ||
ops.callback_queue = cq; | ||
return nh.subscribe(ops); | ||
} | ||
template<class M, class T> | ||
ros::Subscriber subscribe( | ||
ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, | ||
const std::string& topic, uint32_t queue_size, | ||
void(T::*fp)(const boost::shared_ptr<M const>&) const, | ||
const boost::shared_ptr<T>& obj, | ||
const ros::TransportHints& transport_hints = ros::TransportHints()) | ||
{ | ||
ros::SubscribeOptions ops; | ||
ops.template init<M>(topic, queue_size, boost::bind(fp, obj.get(), _1)); | ||
ops.tracked_object = obj; | ||
ops.transport_hints = transport_hints; | ||
ops.callback_queue = cq; | ||
return nh.subscribe(ops); | ||
} | ||
template<class M> | ||
ros::Subscriber subscribe( | ||
ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, | ||
const std::string& topic, uint32_t queue_size, void(*fp)(M), | ||
const ros::TransportHints& transport_hints = ros::TransportHints()) | ||
{ | ||
ros::SubscribeOptions ops; | ||
ops.template initByFullCallbackType<M>(topic, queue_size, fp); | ||
ops.transport_hints = transport_hints; | ||
ops.callback_queue = cq; | ||
return nh.subscribe(ops); | ||
} | ||
template<class M> | ||
ros::Subscriber subscribe( | ||
ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, | ||
const std::string& topic, uint32_t queue_size, | ||
void(*fp)(const boost::shared_ptr<M const>&), | ||
const ros::TransportHints& transport_hints = ros::TransportHints()) | ||
{ | ||
ros::SubscribeOptions ops; | ||
ops.template init<M>(topic, queue_size, fp); | ||
ops.transport_hints = transport_hints; | ||
ops.callback_queue = cq; | ||
return nh.subscribe(ops); | ||
} | ||
template<class M> | ||
ros::Subscriber subscribe( | ||
ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, | ||
const std::string& topic, uint32_t queue_size, | ||
const boost::function<void (const boost::shared_ptr<M const>&)>& callback, | ||
const ros::VoidConstPtr& tracked_object = ros::VoidConstPtr(), | ||
const ros::TransportHints& transport_hints = ros::TransportHints()) | ||
{ | ||
ros::SubscribeOptions ops; | ||
ops.template init<M>(topic, queue_size, callback); | ||
ops.tracked_object = tracked_object; | ||
ops.transport_hints = transport_hints; | ||
ops.callback_queue = cq; | ||
return nh.subscribe(ops); | ||
} | ||
template<class M, class C> | ||
ros::Subscriber subscribe( | ||
ros::NodeHandle& nh, ros::CallbackQueueInterface* cq, | ||
const std::string& topic, uint32_t queue_size, | ||
const boost::function<void (C)>& callback, | ||
const ros::VoidConstPtr& tracked_object = ros::VoidConstPtr(), | ||
const ros::TransportHints& transport_hints = ros::TransportHints()) | ||
{ | ||
ros::SubscribeOptions ops; | ||
ops.template initByFullCallbackType<C>(topic, queue_size, callback); | ||
ops.tracked_object = tracked_object; | ||
ops.transport_hints = transport_hints; | ||
ops.callback_queue = cq; | ||
return nh.subscribe(ops); | ||
} | ||
|
||
} // namespace rtt_roscomm | ||
|
||
#endif // RTT_ROSCOMM__PASSTHROUGH_CALLBACK_QUEUE_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
#include "rtt_roscomm/passthrough_callback_queue.hpp" | ||
|
||
namespace rtt_roscomm { | ||
|
||
PassthroughCallbackQueue::PassthroughCallbackQueue() | ||
{} | ||
|
||
void PassthroughCallbackQueue::addCallback( | ||
const ros::CallbackInterfacePtr &callback, | ||
uint64_t owner_id) | ||
{ | ||
// Call CallbackInterface::CallResult SubscriptionQueue::call() | ||
if (ros::CallbackInterface::TryAgain == callback->call()) { | ||
ros::getGlobalCallbackQueue()->addCallback(callback, owner_id); | ||
} | ||
} | ||
|
||
void PassthroughCallbackQueue::removeByID(uint64_t owner_id) | ||
{ | ||
} | ||
|
||
} // namespace rtt_roscomm | ||
|