I don't know about doing this in C++ specifically, but at least the Connection header appears to have a field which encodes whether:
publisher is in latching mode (i.e. sends the last value published to new subscribers)
The wiki/rospy/Overview/Publishers and Subscribers: Subscribing to a topic - Connection Information shows how to access this in rospy
.
In roscpp
, you can get the header from the MessageEvent (getConnectionHeader()
, via MessageEvent [ROS 1.1+]).
I would expect rosbag
to have other options to get the connection header though, seeing as it already deals with connections.
Edit: this comment in the issue you commented on links to ros/ros_comm/tools/topic_tools/src/relay.cpp which actually shows how to do this:
boost::shared_ptr<const ros::M_string> const& connection_header =
msg_event.getConnectionHeaderPtr();
[..]
// If the input topic is latched, make the output topic latched, #3385.
bool latch = false;
if (connection_header)
{
ros::M_string::const_iterator it = connection_header->find("latching");
if((it != connection_header->end()) && (it->second == "1"))
{
ROS_DEBUG("input topic is latched; latching output topic to match");
latch = true;
}
}