blob: 46639ba1e32cf9054badcae9d48fc1248474f878 [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 "composite_sample.h"
#include <fidl/fuchsia.driver.compat/cpp/wire.h>
#include <lib/driver/component/cpp/service_client.h>
namespace composite_sample {
zx::result<> CompositeSampleDriver::Start() {
auto result = PrintTopologicalPath("acpi-GFBY");
if (result.is_error()) {
FDF_SLOG(ERROR, "Failed to print topological path for \"acpi-GFBY\"",
KV("status", result.status_string()));
return result.take_error();
}
result = PrintTopologicalPath("acpi-GFRT");
if (result.is_error()) {
FDF_SLOG(ERROR, "Failed to print topological path for \"acpi-GFBY\"",
KV("status", result.status_string()));
return result.take_error();
}
return zx::ok();
}
// Print the topological path for a given parent device node.
zx::result<> CompositeSampleDriver::PrintTopologicalPath(std::string_view name) {
// Connect to the parent device node.
auto parent =
driver::Connect<fuchsia_driver_compat::Service::Device>(*context().incoming(), name);
if (parent.is_error()) {
FDF_SLOG(ERROR, "Failed to open compat service device", KV("status", parent.status_string()));
return parent.take_error();
}
// Retrieve the path of the device node from the `fuchsia.driver.compat` service
auto client = fidl::WireSyncClient(std::move(parent.value()));
auto path_result = client->GetTopologicalPath();
if (!path_result.ok()) {
FDF_SLOG(ERROR, "Failed to get topological path", KV("status", path_result.status_string()));
return zx::error(path_result.status());
}
std::string path(path_result->path.get());
FDF_SLOG(INFO, "Topological path", KV("instance_name", std::string(name).c_str()),
KV("path", path.c_str()));
return zx::ok();
}
} // namespace composite_sample
FUCHSIA_DRIVER_RECORD_CPP_V2(driver::Record<composite_sample::CompositeSampleDriver>);