I'm assuming you mean the service callback with service function
.
Basically you have to possibilities.
- If you really want to use the
NodeHandle
that is created outside the service callback, make this a member variable (if you are using a class) and just access that, or make it a global variable (if you don't have a class). No need to pass it to the service callback.
- You can just create a new
NodeHandle
in the scope of the service callback. You can have as many NodeHandle
s as you want. And then use this to retrieve the parameter. Again, no need to pass it in.
Thus, my suggestion would be to use 1 if you have a class (obviously, the service callback needs to be a member function of the class as well) and 2 if you don't.
(As both ways are trivial, I'll not provide example code for now.)
Originally posted by mgruhler with karma: 12390 on 2018-07-06
This answer was ACCEPTED on the original site
Post score: 3
Original comments
Comment by yashtrikannad on 2019-11-23:
I am not able to call class member functions in the service. It shows that the callback is not a non-static member of the class. If I try to make the callback function static, I will not be able to access the class members(parameters). So I am not sure if the first option will work?
Comment by ahendrix on 2019-11-24:
You can pass member function pointer and object when creating the service; then the service handler can be a non-static member function and use class members.