blob: 82f5ff3a22d4c41a7ba5592a830faf747e38dac1 [file] [log] [blame]
// Copyright 2021 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/example_driver/example_driver.h"
#include <fidl/fuchsia.driver.compat/cpp/wire.h>
namespace fdf {
using namespace fuchsia_driver_framework;
} // namespace fdf
namespace example_driver {
namespace {
namespace fio = fuchsia_io;
zx::status<fidl::ClientEnd<fuchsia_driver_compat::Device>> ConnectToParentDevice(
const driver::Namespace* ns, std::string_view name) {
auto result = ns->OpenService<fuchsia_driver_compat::Service>(name);
if (result.is_error()) {
return result.take_error();
}
return result.value().connect_device();
}
} // namespace
// static
zx::status<std::unique_ptr<ExampleDriver>> ExampleDriver::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<ExampleDriver>(dispatcher->async_dispatcher(), std::move(node),
std::move(ns), std::move(logger));
auto result = driver->Run(dispatcher->async_dispatcher(), std::move(start_args.outgoing_dir()));
if (result.is_error()) {
return result.take_error();
}
return zx::ok(std::move(driver));
}
zx::status<> ExampleDriver::Run(async_dispatcher* dispatcher,
fidl::ServerEnd<fio::Directory> outgoing_dir) {
// Connect to parent.
auto parent = ConnectToParentDevice(&ns_, "default");
if (parent.status_value() != ZX_OK) {
FDF_SLOG(ERROR, "Failed to connect to parent", KV("status", parent.status_string()));
return parent.take_error();
}
FDF_SLOG(INFO, "**** Hello world ****");
return zx::ok();
}
} // namespace example_driver
FUCHSIA_DRIVER_RECORD_CPP_V1(example_driver::ExampleDriver);