| // 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 "example_driver.h" |
| |
| #include <fidl/fuchsia.driver.compat/cpp/wire.h> |
| #include <lib/driver2/service_client.h> |
| |
| #include "greeter.h" |
| |
| namespace example_driver { |
| |
| zx::result<> ExampleDriver::Start() { |
| // Connect to the parent device node. |
| auto parent = |
| driver::Connect<fuchsia_driver_compat::Service::Device>(*context().incoming()); |
| if (parent.status_value() != ZX_OK) { |
| FDF_SLOG(ERROR, "Failed to connect to parent", KV("status", parent.status_string())); |
| return parent.take_error(); |
| } |
| |
| auto client = fidl::WireSyncClient(std::move(parent.value())); |
| auto topological_path = client->GetTopologicalPath(); |
| if (!topological_path.ok()) { |
| FDF_SLOG(ERROR, "Failed to get topological path", |
| KV("error_desc", topological_path.FormatDescription().c_str())); |
| return zx::error(ZX_ERR_INTERNAL); |
| } |
| |
| FDF_SLOG(INFO, example_driver::greeting(name()).c_str()); |
| FDF_SLOG(INFO, example_driver::greeting(topological_path.value().path.get()).c_str()); |
| return zx::ok(); |
| } |
| |
| } // namespace example_driver |
| |
| FUCHSIA_DRIVER_RECORD_CPP_V2(driver::Record<example_driver::ExampleDriver>); |