Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overload for non-blocking service calls. #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/pybind11/gz/transport/_gz_transport_pybind11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,15 @@ void define_transport_node(py::module_ module)
const unsigned int &_timeout,
const std::string &_repType)
{
// see ign-transport/src/cmd/ign.cc L227-240
// see gz-transport/src/cmd/gz.cc L227-240
auto rep = gz::msgs::Factory::New(_repType);
if (!rep)
{
std::cerr << "Unable to create response of type["
<< _repType << "].\n";
return std::make_tuple(false, false);
}

bool result{false};
bool executed = _node.Request(
_service, _request, _timeout, *rep, result);
Expand All @@ -282,8 +282,28 @@ void define_transport_node(py::module_ module)
pybind11::arg("request"),
pybind11::arg("timeout"),
pybind11::arg("rep_type_name"),
"Request a new service without input parameter using"
" a blocking call")
"Request a new service using a blocking call")
// send a service request using the non-blocking interface
// this requires changes to gz-transport Node and ReqHandler.
.def("request", [](
Node &_node,
const std::string &_service,
const google::protobuf::Message &_request,
std::function<void(
const google::protobuf::Message &_reply,
const bool _result)> &_callback,
const std::string &_repType)
{
bool result{false};
bool executed = _node.Request(
_service, _request, _callback, _repType.c_str());
return executed;
},
pybind11::arg("service"),
pybind11::arg("request"),
pybind11::arg("callback"),
pybind11::arg("rep_type_name"),
"Request a new service using a non-blocking call")
.def("service_list", [](
Node &_node)
{
Expand Down