| // 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. |
| |
| #ifndef FUCHSIA_SDK_EXAMPLES_CC_EXAMPLE_DRIVER_H_ |
| #define FUCHSIA_SDK_EXAMPLES_CC_EXAMPLE_DRIVER_H_ |
| |
| #include <fidl/fuchsia.device.fs/cpp/wire.h> |
| #include <fidl/fuchsia.driver.framework/cpp/wire.h> |
| #include <lib/async/dispatcher.h> |
| #include <lib/driver2/namespace.h> |
| #include <lib/driver2/record_cpp.h> |
| #include <lib/driver2/structured_logger.h> |
| #include <lib/fdf/cpp/dispatcher.h> |
| #include <lib/sys/component/llcpp/outgoing_directory.h> |
| #include <lib/zx/status.h> |
| |
| #include <memory> |
| #include <optional> |
| |
| namespace example_driver { |
| |
| class ExampleDriver { |
| public: |
| ExampleDriver(async_dispatcher_t* dispatcher, |
| fidl::WireSharedClient<fuchsia_driver_framework::Node> node, driver::Namespace ns, |
| driver::Logger logger) |
| : outgoing_(component::OutgoingDirectory::Create(dispatcher)), |
| node_(std::move(node)), |
| ns_(std::move(ns)), |
| logger_(std::move(logger)) {} |
| virtual ~ExampleDriver() = default; |
| |
| static constexpr const char* Name() { return "example-driver"; } |
| |
| static zx::status<std::unique_ptr<ExampleDriver>> Start( |
| fuchsia_driver_framework::wire::DriverStartArgs& start_args, |
| fdf::UnownedDispatcher dispatcher, |
| fidl::WireSharedClient<fuchsia_driver_framework::Node> node, driver::Namespace ns, |
| driver::Logger logger); |
| |
| private: |
| zx::status<> Run(async_dispatcher* dispatcher, |
| fidl::ServerEnd<fuchsia_io::Directory> outgoing_dir); |
| |
| component::OutgoingDirectory outgoing_; |
| fidl::WireSharedClient<fuchsia_driver_framework::Node> node_; |
| driver::Namespace ns_; |
| driver::Logger logger_; |
| fidl::WireClient<fuchsia_device_fs::Exporter> exporter_; |
| }; |
| |
| } // namespace example_driver |
| |
| #endif |