From 5a2521275951d2f292e4dbfb16c13cb24e47c36a Mon Sep 17 00:00:00 2001 From: Romain Reignier Date: Wed, 7 Nov 2018 18:02:45 +0100 Subject: [PATCH] Modify Basic example to use both service call APIs --- test/Basic/node.cpp | 46 ++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/test/Basic/node.cpp b/test/Basic/node.cpp index 77a4a9c..05925ac 100644 --- a/test/Basic/node.cpp +++ b/test/Basic/node.cpp @@ -44,20 +44,40 @@ void Node::onTimer() chatter.publish(str_msg); roscpp::GetLoggersRequest req; - serviceClient.call(req, [this](const roscpp::GetLoggers::Response &loggers, bool ok, uint8_t callResult){ - switch(callResult) - { - case rosserial_msgs::ServiceCallResult::NO_EXISTENCE: - std::cout << "Service " << serviceClient.topic_ << " does not exist" << std::endl; - break; - case rosserial_msgs::ServiceCallResult::CALL_FAILED: - std::cout << "Call to service " << serviceClient.topic_ << " failed" << std::endl; + + if(i % 2 == 0) + { + std::cout << "Service client call with bool and uint8_t results API" << std::endl; + serviceClient.call(req, [this](const roscpp::GetLoggers::Response &loggers, bool ok, uint8_t callResult){ + (void)ok; + switch(callResult) + { + case rosserial_msgs::ServiceCallResult::NO_EXISTENCE: + std::cout << "Service " << serviceClient.topic_ << " does not exist" << std::endl; + break; + case rosserial_msgs::ServiceCallResult::CALL_FAILED: + std::cout << "Call to service " << serviceClient.topic_ << " failed" << std::endl; + break; + case rosserial_msgs::ServiceCallResult::SUCCESS: + std::cout << "loggers : " << QJsonDocument(loggers.serializeAsJson()).toJson(QJsonDocument::Indented).toStdString() << std::endl; break; - case rosserial_msgs::ServiceCallResult::SUCCESS: - std::cout << "loggers : " << QJsonDocument(loggers.serializeAsJson()).toJson(QJsonDocument::Indented).toStdString() << std::endl; - break; - } - }); + } + }); + } + else + { + std::cout << "Service client call with only bool result API" << std::endl; + serviceClient.call(req, [this](const roscpp::GetLoggers::Response &loggers, bool ok){ + if(ok) + { + std::cout << "loggers : " << QJsonDocument(loggers.serializeAsJson()).toJson(QJsonDocument::Indented).toStdString() << std::endl; + } + else + { + std::cout << "Call to service " << serviceClient.topic_ << " failed" << std::endl; + } + }); + } } void Node::addTwoInts(const roscpp_tutorials::TwoIntsRequest &req, roscpp_tutorials::TwoIntsResponse &res)