Skip to content

Commit

Permalink
Update main_rpc_client.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
MelamudMichael authored Feb 29, 2024
1 parent 9147523 commit ff9fdeb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions rpc/src/main_rpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,29 @@ UPayload sendRPC(UUri& uri) {
uint8_t buffer[BUFFER_SIZE] = {0};

UPayload payload(buffer, sizeof(buffer), UPayloadType::VALUE);

/* send the RPC request , a future is returned from invokeMethod */
std::future<UPayload> result = ZenohRpcClient::instance().invokeMethod(uri, payload, attributes);

if (!result.valid()) {
spdlog::error("Future is invalid");
return UPayload(nullptr, 0, UPayloadType::UNDEFINED);
}

/* wait for the future to be fullfieled - it is possible also to specify a timeout for the future */
result.wait();

return result.get();
}

/* The sample RPC client applications demonstrates how to send RPC requests and wait for the response -
* The response in this example will be the current time */
int main(int argc, char** argv) {

signal(SIGINT, signalHandler);

UStatus status;
ZenohRpcClient *rpcClient = &ZenohRpcClient::instance();

/* init RPC client */
status = rpcClient->init();
if (UCode::OK != status.code()) {
spdlog::error("init failed");
Expand All @@ -96,6 +99,7 @@ int main(int argc, char** argv) {
sleep(1);
}

/* term RPC client */
status = rpcClient->term();
if (UCode::OK != status.code()) {
spdlog::error("term failed");
Expand Down

0 comments on commit ff9fdeb

Please sign in to comment.