fdf_component/
lib.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Wrappers around the mechanisms of driver registration for the driver
6//! framework for implementing startup and shutdown of the driver in rust.
7
8#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
9
10use core::future::Future;
11
12use zx::Status;
13
14mod context;
15mod incoming;
16pub mod macros;
17mod node;
18mod server;
19pub mod testing;
20
21pub use context::*;
22pub use incoming::*;
23pub use node::*;
24
25/// Entry points into a driver for starting and stopping.
26///
27/// Driver authors should implement this trait, taking information from the [`DriverContext`]
28/// passed to the [`Driver::start`] method to set up, and then tearing down any resources they use
29/// in the [`Driver::stop`] method.
30pub trait Driver: Sized + Send + 'static {
31    /// The name of the driver as it will appear in logs
32    const NAME: &str;
33
34    /// This will be called when the driver is started.
35    ///
36    /// The given [`DriverContext`] contains information and functionality necessary to get at the
37    /// driver's incoming and outgoing namespaces, add child nodes in the driver topology, and
38    /// manage dispatchers.
39    ///
40    /// In order for the driver to be properly considered started, it must return [`Status::OK`]
41    /// and bind the client end for the [`DriverStartArgs::node`] given in
42    /// [`DriverContext::start_args`].
43    fn start(context: DriverContext) -> impl Future<Output = Result<Self, Status>> + Send;
44
45    /// This will be called when the driver has been asked to stop, and should do any
46    /// asynchronous cleanup necessary before the driver is fully shut down.
47    ///
48    /// Note: The driver will not be considered fully stopped until the node client end bound in
49    /// [`Driver::start`] has been closed.
50    fn stop(&self) -> impl Future<Output = ()> + Send;
51}