Skip to content

Commit

Permalink
Clean
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Agüero <[email protected]>
  • Loading branch information
caguero committed Feb 2, 2024
1 parent 3b0871b commit 07d297e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 59 deletions.
72 changes: 15 additions & 57 deletions src/cmd/gz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,67 +251,25 @@ extern "C" void cmdServiceReq(const char *_service,
Node node;
bool result;

// Request the service.
bool executed = node.Request(_service, *req, _timeout, *rep, result);
if (executed)
if (_timeout == -1)
{
if (result)
std::cout << rep->DebugString() << std::endl;
else
std::cout << "Service call failed" << std::endl;
}
else if (_timeout > 100)
std::cerr << "Service call timed out" << std::endl;
}

//////////////////////////////////////////////////
extern "C" void cmdServiceReqOneway(const char *_service, const char *_reqType,
const char *_reqData)
{
if (!_service)
{
std::cerr << "Service name is null\n";
return;
}

if (!_reqType)
{
std::cerr << "Request type is null\n";
return;
}

if (!_reqData)
{
std::cerr << "Request data is null\n";
return;
// One-way service.
node.Request(_service, *req, 1000, *rep, result);
}

// Create the request, and populate the field with _reqData
auto req = msgs::Factory::New(_reqType, _reqData);
if (!req)
{
std::cerr << "Unable to create request of type[" << _reqType << "] "
<< "with data[" << _reqData << "].\n";
return;
}

// Create the response.
auto rep = msgs::Factory::New("gz.msgs.Empty");
if (!rep)
else
{
std::cerr << "Unable to create response of type[gz.msgs.Empty].\n";
return;
// Two-way service.
bool executed = node.Request(_service, *req, _timeout, *rep, result);
if (executed)
{
if (result)
std::cout << rep->DebugString() << std::endl;
else
std::cout << "Service call failed" << std::endl;
}
else
std::cerr << "Service call timed out" << std::endl;
}

// Create the node.
Node node;
bool result;
int timeout = 1000;

// Request the service.
bool executed = node.Request(_service, *req, timeout, *rep, result);
if (!executed && timeout > 1000)
std::cerr << "Service call failed" << std::endl;
}

//////////////////////////////////////////////////
Expand Down
7 changes: 5 additions & 2 deletions src/cmd/service_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ void runServiceCommand(const ServiceOptions &_opt)
case ServiceCommand::kServiceReq:
if (_opt.repType.empty())
{
cmdServiceReqOneway(_opt.service.c_str(),
_opt.reqType.c_str(), _opt.reqData.c_str());
// One-way service request.
cmdServiceReq(_opt.service.c_str(),
_opt.reqType.c_str(), "gz.msgs.Empty",
-1, _opt.reqData.c_str());
}
else
{
// Two-way service request.
cmdServiceReq(_opt.service.c_str(),
_opt.reqType.c_str(), _opt.repType.c_str(),
_opt.timeout, _opt.reqData.c_str());
Expand Down

0 comments on commit 07d297e

Please sign in to comment.