blob: 7bfcb2cbd659422bef1857d435bd63d9dfa6537c [file] [log] [blame]
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// [START imports]
#include <fidl/examples.routing.echo/cpp/fidl.h>
#include <lib/component/incoming/cpp/protocol.h>
#include <lib/syslog/cpp/macros.h>
#include <cstdlib>
#include <iostream>
#include <string>
// [END imports]
// [START main_body]
int main(int argc, const char *argv[], char *envp[]) {
// [START_EXCLUDE silent]
// TODO(fxbug.dev/97170): Consider migrating to async FIDL API
// [END_EXCLUDE]
// Connect to FIDL protocol
zx::result client_end = component::Connect<examples_routing_echo::Echo>();
if (!client_end.is_ok()) {
FX_LOGST(ERROR, "echo_client")
<< "Error connecting to Echo protocol: " << client_end.status_string();
return -1;
}
fidl::SyncClient client{std::move(*client_end)};
// Send messages over FIDL interface for each argument
for (int i = 1; i < argc; i++) {
fidl::Result result = client->EchoString({argv[i]});
ZX_ASSERT(result.is_ok());
auto response = result->response();
if (!response.has_value()) {
FX_LOGST(INFO, "echo_client") << "echo_string got empty result";
} else {
FX_LOGST(INFO, "echo_client") << "Server response: " << response->c_str();
}
}
return 0;
}
// [END main_body]