Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I figured the answer myself. Quoting roscpp wiki , "When the first ros::NodeHandle is created it will call ros::start(), and when the last ros::NodeHandle is destroyed, it will call ros::shutdown()."

So in the first case, when the setMapMetaData() method returns, the NodeHandler n gets destroyed, because it's created within the scope of the method. Since there are no other NodeHandlers created at that moment, ros::shutdown() is called.

In the second case, the method does not return until mapMetaDataSet = true which happens when the callback function is executed. The callback function executes when ros::spin() is called from another class. Then the method returns and the local NodeHandler n is destroyed BUT now there is another NodeHandler created for the same node. Hence ros::shutdown() is not called at that point.

I guess my current implementation, even though it works, is not exactly the best way to get this done. Might do well to use a single NodeHandler that can be passed as an argument to subscribers / publishers etc.