template <typename Driver>
class Suspendable
Defined at line 91 of file ../../sdk/lib/driver/power/cpp/suspend.h
Drivers should use `Suspendable` to implement suspend and resume support for
their driver. The `fuchsia-suspendable` skill in //src/devices/skills for
agents should be able to do the basic integration. Information in that skill
is also a guide for human authors, but a summary is below.
To properly use this mix-in drivers should:
* Update their component manifest and add `suspend_enabled: "true"` to the
program stanza.
* Implement the virtual methods defined here.
* Implement `std::optional
<fidl
::ServerEnd
<fuchsia
_power_broker::ElementRunner>>
take_power_element_runner()` in the driver.
* Call `InitializeSuspend` in their start method, after
`take_power_element_runner()` can return a valid value.
`InitializeSuspend` does one of two things:
1) If suspend is not enabled based on `SuspendEnabled`, it returns
`zx::ok` immediately.
2) If `Driver::take_power_element_runner` returns a valid channel, it
binds an `ElementRunner` server that translates `SetLevel(0)` into
`Suspend()` and `SetLevel(1)` into `Resume()`, and returns `zx::ok`.
The initial `SetLevel(1)` at driver startup is skipped without
calling `Resume()`. If `take_power_element_runner` returns
`std::nullopt`, it returns `ZX_ERR_UNAVAILABLE`.
The typical implementation for `take_power_element_runner()` returns the
value from `DriverContext::take_power_element_runner()` from the
`DriverContext` instance passed to the driver's `Start` hook. The driver
should take the runner from `DriverContext` during `Start` and store and
then return it from the driver's `take_power_element_runner` implementation.
Public Methods
void Suspend (SuspendCompleter completer)
Interface to be implemented.
void Resume (ResumeCompleter completer)
bool SuspendEnabled ()
void Suspendable<Driver> ()
Defined at line 98 of file ../../sdk/lib/driver/power/cpp/suspend.h
bool SuspendActive ()
Returns true if
* suspend was enabled and we did one of the following
* we got a value from `Driver::take_power_element_runner`
Returns false if suspend was disabled or we didn't get a power element runner.
Defined at line 107 of file ../../sdk/lib/driver/power/cpp/suspend.h
void ~Suspendable<Driver> ()
Defined at line 109 of file ../../sdk/lib/driver/power/cpp/suspend.h
zx::result<> InitializeSuspend (async_dispatcher_t *dispatcher,fdf::Namespace &incoming,std::string_viewname)
Defined at line 111 of file ../../sdk/lib/driver/power/cpp/suspend.h