blob: 17ba7cc2d4f497246ac04565f2a748a248c6e208 [file]
// 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.
#include <lib/async-loop/cpp/loop.h>
#include <lib/sys/cpp/component_context.h>
#include <lib/syslog/cpp/macros.h>
#include <unistd.h>
#include <examples/${series_flat_case}/${variant_flat_case}/cpp/fidl.h>
#include <examples/fidl/new/${series_snake_case}/${variant_snake_case}/hlcpp/client/config.h>
int main(int argc, const char** argv) {
FX_LOGS(INFO) << "Started";
// Retrieve component configuration.
auto conf = config::Config::TakeFromStartupHandle();
// Start up an async loop.
async::Loop loop(&kAsyncLoopConfigNeverAttachToThread);
async_dispatcher_t* dispatcher = loop.dispatcher();
// Connect to the protocol inside the component's namespace, then create an asynchronous client
// using the newly-established connection.
examples::${series_flat_case}::${variant_flat_case}::${protocol_pascal_case}Ptr ${protocol_snake_case}_proxy;
auto context = sys::ComponentContext::Create();
context->svc()->Connect(${protocol_snake_case}_proxy.NewRequest(dispatcher));
FX_LOGS(INFO) << "Outgoing connection enabled";
// TODO(${dns}): Add any event sending protocol lambdas here. Each lambda should be set lik3
// |${protocol_snake_case}_proxy.events.EVENT_NAME = [](...) {...}`.
${protocol_snake_case}_proxy.set_error_handler([&loop](zx_status_t status) {
FX_LOGS(ERROR) << "Shutdown unexpectedly";
loop.Quit();
});
// TODO(${dns}): Read config from the |conf| to process script events, and thereby make calls
// to the server, here.
// TODO(https://fxbug.dev/42156498): We need to sleep here to make sure all logs get drained. Once the
// referenced bug has been resolved, we can remove the sleep.
sleep(2);
return 0;
}