Add overloaded Request for non-blocking calls using abstract types #386
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🎉 New feature
Summary
Add an overloaded Request method to the class Node that accepts references to abstract request and response types, specifically the type
google::protobuf::Message
.The addition is to support a non-blocking version of the service call used in
cmdServiceReq
(gz-transport/src/cmd/gz.hh). The existing Request methods accepting a callback function all require a concrete type as they callRequest().GetTypeName()
andResponse().GetTypeName()
. This does not work when the request or response types are the abstract base classgoogle::protobuf::Message
. The instance calls_request->GetTypeName()
and_response->GetTypeName()
on the other hand are valid, and this is what the new overload function uses.There is also a change to the template specialisation of
ReqHandler
to support callbacks.Test it
Tasks
main
because of ABI changes.gz-transport
The current use case is in a downstream project providing python bindings for gz-msgs and gz-transport: https://github.com/srmainwaring/gz-python/tree/srmainwaring/service-request
At present only blocking service requests are supported. The Python bindings use the same approach as the
gz service
command line tools. This PR allows asynchronous callbacks as well. The example below is for a service that allows the PID settings of a joint controller to be updated in Python at runtime. Both blocking and non-blocking versions of the call are demonstrated.Expected console output:
% ~/Code/osrf/gz_garden_ws/src/gz-python/python/pid_service.py Blocking service call Non-blocking service call Result: True Response: p_gain_optional { data: 0.3 } i_gain_optional { } d_gain_optional { } i_max_optional { data: 1.0 } i_min_optional { data: -1.0 } limit_optional { data: 10.0 } Done
Expected
gz sim
output (using a modified version of the ArduPilot plugin: srmainwaring/ardupilot_gazebo-1@c938fd5):Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.