blob: 9f9cacf8b9817bbb01f3ffb5a9bb873bc9376507 [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.
#include "src/bind_library/child-driver.h"
#include <fidl/fuchsia.gizmo.protocol/cpp/wire.h>
namespace fdf {
using namespace fuchsia_driver_framework;
} // namespace fdf
namespace child_driver {
// static
zx::status<std::unique_ptr<ChildDriver>> ChildDriver::Start(fdf::wire::DriverStartArgs& start_args,
fdf::UnownedDispatcher dispatcher,
fidl::WireSharedClient<fdf::Node> node,
driver::Namespace ns,
driver::Logger logger) {
auto driver = std::make_unique<ChildDriver>(dispatcher->async_dispatcher(), std::move(node),
std::move(ns), std::move(logger));
auto result = driver->Run();
if (result.is_error()) {
return result.take_error();
}
return zx::ok(std::move(driver));
}
// private
zx::status<> ChildDriver::Run() {
auto result = ns_.Connect<fuchsia_gizmo_protocol::TestingProtocol>();
if (result.is_error()) {
FDF_SLOG(WARNING, "Failed to connect to TestingProtocol.",
KV("status", result.status_string()));
return result.take_error();
}
auto client = fidl::WireClient(std::move(*result), dispatcher_);
auto get_result = client.sync()->Get();
if (!get_result.ok()) {
FDF_SLOG(WARNING, "Failed to send Get to TestingProtocol.",
KV("status", get_result.error().status_string()));
return zx::error(get_result.error().status());
}
FDF_LOG(INFO, "Succeeded!");
return zx::ok();
}
} // namespace child_driver
FUCHSIA_DRIVER_RECORD_CPP_V1(child_driver::ChildDriver);