how to check if there are waiting messages in a callback queue?
The test case is the following: i receive images from a camera through a callback, and I want to run a loop of processing until a new image arrive. Is there any function that can tell me if there are new messages in the queue? The pseudocode would look like this (i'm looking for new_imagemsg()):
void imagecb(imagemsg)
{
while(!new_imagemsg())
{
optimize(imagemsg);
}
return;
}
I tried the following:
void imagecb(imagemsg)
{
while(static_cast<ros::CallbackQueue*>(nh->getCallbackQueue())->isEmpty())
{
optimize(imagemsg);
}
return;
}
But it looks like the function isEmpty() always returns false when called from inside a callback, which makes me think that the callback is removed once the callback function finishes instead of when it enters. Unfortunately it looks like CallbackQueue doesn't have a getSize function ( i would like to check if the size is bigger than one).
Any other ideas? clearing the queue from inside a callback function doesn't seem to work either, apart from being kind of hacky.