ros::SubscribeOptions::create doesn't take object T* Obj pointer.

asked 2019-01-25 01:03:09 -0600

cascais gravatar image

updated 2019-01-25 02:48:37 -0600

gvdhoorn gravatar image


SubscribeOptions::create function doesn't support setting class member function as callback function? I cannot see the argument option in its signature.

template<class M >
static SubscribeOptions     create (const std::string &topic, uint32_t queue_size, const boost::function< void(const boost::shared_ptr< M const > &)> &callback, const VoidConstPtr &tracked_object, CallbackQueueInterface *queue)

Like subscribe does below. Is it possible to add a class member function as callback function to the SubscribeOptions?

 Subscriber subscribe(const std::string& topic, uint32_t queue_size, 
                         void(T::*fp)(const boost::shared_ptr<M const>&) const, T* obj, 
                          const TransportHints& transport_hints = TransportHints())
edit retag flag offensive close merge delete


Can you show us how you've tried to use this?

Using member functions should be/is definitely supported, so perhaps you're not providing the correct arguments to the function.

gvdhoorn gravatar imagegvdhoorn ( 2019-01-25 02:49:19 -0600 )edit

@gvdhoorn, I have not tried to use the function yet but from the interface to create SubscribeOptions like pasted in question, I cannot see the possibility to give a pointer to the instance. That's why I assumed it is not supported. Shall I use boost::bind?

cascais gravatar imagecascais ( 2019-01-25 04:56:03 -0600 )edit

Ah, wait. I'd missed you were trying to use SubscribeOptions. The create(..) function does seem to only take the "simple" type of callbacks, but perhaps the initByFullCallbackType(..) function can help there.

I've not used this myself, so I don't know whether it will work, but ..

gvdhoorn gravatar imagegvdhoorn ( 2019-01-25 05:31:58 -0600 )edit

.. the docs say (from here):

Templated initialization, templated on callback parameter type. Supports any callback parameters supported by the SubscriptionCallbackAdapter.

gvdhoorn gravatar imagegvdhoorn ( 2019-01-25 05:32:34 -0600 )edit

@gvdhoorn. Hmm I cannot find the definition of SubscriptionCallbackAdapter..

cascais gravatar imagecascais ( 2019-01-25 05:55:29 -0600 )edit

It's in subscription_callback_helper.h. Docs here. But again: I don't know whether this will work.

gvdhoorn gravatar imagegvdhoorn ( 2019-01-25 05:57:25 -0600 )edit