template <typename Driver>

class Suspendable

Defined at line 88 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 value it uses calls

to `SetLevel` to levels 0 and 1 to drive calls to `BeforeSuspend` and

`AfterResume`, respectively. Otherwise 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 95 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 104 of file ../../sdk/lib/driver/power/cpp/suspend.h

void ~Suspendable<Driver> ()

Defined at line 106 of file ../../sdk/lib/driver/power/cpp/suspend.h

zx::result<> InitializeSuspend (async_dispatcher_t * dispatcher, fdf::Namespace & incoming, std::string_view name)

Defined at line 108 of file ../../sdk/lib/driver/power/cpp/suspend.h