ros / ros_comm

ROS communications-related packages, including core client libraries (roscpp, rospy, roslisp) and graph introspection tools (rostopic, rosnode, rosservice, rosparam).
http://wiki.ros.org/ros_comm
761 stars 912 forks source link

[enhancement request] Add resubsrcibe to {ros, image_transport}::Subscriber #1846

Open kunaltyagi opened 4 years ago

kunaltyagi commented 4 years ago

In implementing a typical connect callback for nodelets, I found the lack of Subscriber::reconnect to be problematic. Implementing a generic data-structure to store the name and callback for multiple subscribers seems counter productive since I'll just be re-implementing similar abstractions as ROS.

Current code:

if (!static_cast<void*>(sub1)) sub1 = nh.subscriber(topic1, qSize, callback1, this);
if (!static_cast<void*>(sub2)) sub2 = it.subscriber(topic2, qSize, callback2, this);

With enhancement:

sub1.reconnect();
sub2.reconnect();

Potential dummy-code implementation:

ros::Subscriber::reconnect() {
  if (static_cast<void*>(*this)) { return; }
  if (impl_) { 
    // grab the details from existing internal data struct and resubscribe
  }
  else {
    // impossible to be here. The impl_ is never deleted in current code
  }
}

This will largely simplify the life of nodelet writers

kunaltyagi commented 4 years ago

Would a PR be entertained?