pub struct ClassDef<M: Model> { /* private fields */ }Expand description
A builder for defining a device model and interface.
Implementations§
Source§impl<M: Model> ClassDef<M>
impl<M: Model> ClassDef<M>
Sourcepub fn new<N, I>(name: N, init: I) -> Self
pub fn new<N, I>(name: N, init: I) -> Self
Create a new device definition, the given function building the model of each device of that class when it is initialized.
Sourcepub fn new_async_with<N, I>(name: N, init: I) -> Self
pub fn new_async_with<N, I>(name: N, init: I) -> Self
Create a new device definition, the given function building the model of each
device of that class asynchronously when it is initialized. This is the raw form of
Self::new_async, for a closure that boxes its future itself.
Sourcepub fn new_async<N, I>(name: N, init: I) -> Self
pub fn new_async<N, I>(name: N, init: I) -> Self
Create a new device definition, the given function building the model of each
device of that class asynchronously when it is initialized, typically an async fn
taking the device.
The model of the device is locked exclusively until the future completes, as it is
for a synchronous one, see Dev::init. The future is polled by the server itself
when nothing else of the initialization may block, so it must never block, see
Self::state_async.
Sourcepub fn new_default<N>(name: N) -> Self
pub fn new_default<N>(name: N) -> Self
Create a new device definition whose model is built with its default value.
Sourcepub fn doc<D>(self, doc: D) -> Self
pub fn doc<D>(self, doc: D) -> Self
Set the description the devices of that class give of themselves, which is what a client asking a device what it is gets back, and what a class defines once for all of its devices.
Sourcepub fn doc_url<U>(self, url: U) -> Self
pub fn doc_url<U>(self, url: U) -> Self
Set where the documentation of that class is, which is what a client shows as the documentation of every device of it: a page describing what the class does, not what one device of it is doing, which is its status.
Sourcepub fn delete<F>(self, delete: F) -> Self
pub fn delete<F>(self, delete: F) -> Self
Define the function called when the model of a device of that class is deleted, which is given the model back so that it may release its resources: before every initialization but the first, which is what the Init command of a device is, and once the device is no longer served.
Sourcepub fn delete_async_with<F>(self, delete: F) -> Self
pub fn delete_async_with<F>(self, delete: F) -> Self
Define the function called when the model of a device of that class is deleted,
asynchronously. This is the raw form of Self::delete_async, for a closure that
boxes its future itself.
Sourcepub fn delete_async<F>(self, delete: F) -> Self
pub fn delete_async<F>(self, delete: F) -> Self
Define the function called when the model of a device of that class is deleted,
asynchronously, typically an async fn taking the model and the device, see
Self::delete.
The model of the device is locked exclusively until the future completes, as it is
for a synchronous one. The future is polled by the server itself when nothing else
of the deletion may block, so it must never block, see Self::state_async.
Sourcepub fn state<F>(self, state: F) -> Self
pub fn state<F>(self, state: F) -> Self
Define the function giving the state of the device, with a shared access to the model, which allows parallel execution of such functions.
Sourcepub fn state_exclusive<F>(self, state: F) -> Self
pub fn state_exclusive<F>(self, state: F) -> Self
Define the function giving the state of the device, with an exclusive access to the model, therefore no other command or attribute can access it in parallel.
Sourcepub fn state_async_with<F>(self, state: F) -> Self
pub fn state_async_with<F>(self, state: F) -> Self
Define the function giving the state of the device, asynchronously and with a
shared access to the model. This is the raw form of Self::state_async, for a
closure that boxes its future itself.
Sourcepub fn state_async<F>(self, state: F) -> Self
pub fn state_async<F>(self, state: F) -> Self
Define the function giving the state of the device, asynchronously and with a
shared access to the model, typically an async fn method of the model.
The model stays borrowed until the future completes, and the future is polled by the server itself, so it must never block: a function that has to wait on anything else than another future offloads that wait to a thread of its own.
Sourcepub fn state_exclusive_async_with<F>(self, state: F) -> Self
pub fn state_exclusive_async_with<F>(self, state: F) -> Self
Define the function giving the state of the device, asynchronously and with an
exclusive access to the model. This is the raw form of Self::state_exclusive_async,
see Self::state_async_with.
Sourcepub fn state_exclusive_async<F>(self, state: F) -> Self
pub fn state_exclusive_async<F>(self, state: F) -> Self
Define the function giving the state of the device, asynchronously and with an
exclusive access to the model, which no other command or attribute can then access
until the future completes. See Self::state_async.
Sourcepub fn status<F>(self, status: F) -> Self
pub fn status<F>(self, status: F) -> Self
Define the function giving the status of the device, with a shared access to the model, the status being allowed to borrow from it.
Sourcepub fn status_exclusive<F>(self, status: F) -> Self
pub fn status_exclusive<F>(self, status: F) -> Self
Define the function giving the status of the device, with an exclusive access to the model, the status being allowed to borrow from it.
Sourcepub fn status_async_with<F>(self, status: F) -> Self
pub fn status_async_with<F>(self, status: F) -> Self
Define the function giving the status of the device, asynchronously and with a
shared access to the model. This is the raw form of Self::status_async, see
Self::state_async_with.
Sourcepub fn status_async<F>(self, status: F) -> Self
pub fn status_async<F>(self, status: F) -> Self
Define the function giving the status of the device, asynchronously and with a
shared access to the model, the status being allowed to borrow from it. See
Self::state_async.
Sourcepub fn status_exclusive_async_with<F>(self, status: F) -> Self
pub fn status_exclusive_async_with<F>(self, status: F) -> Self
Define the function giving the status of the device, asynchronously and with an
exclusive access to the model. This is the raw form of
Self::status_exclusive_async, see Self::state_async_with.
Sourcepub fn status_exclusive_async<F>(self, status: F) -> Self
pub fn status_exclusive_async<F>(self, status: F) -> Self
Define the function giving the status of the device, asynchronously and with an
exclusive access to the model, see Self::state_exclusive_async.
Sourcepub fn command(self, def: CommandDef<M>) -> Self
pub fn command(self, def: CommandDef<M>) -> Self
Define a command every device of that class has, which is what defining a command
usually means: the devices of a class have the same interface, and a device only
adds to its own the part of it that its properties decide, see Dev::add_command.
§Panics
If the class already defines a command of that name, or if the name is one of the
commands the server answers itself, being State, Status and Init.
Sourcepub fn attr(self, def: AttrDef<M>) -> Self
pub fn attr(self, def: AttrDef<M>) -> Self
Define an attribute every device of that class has, see Self::command.
§Panics
If the class already defines an attribute of that name, or if the name is one of
the attributes the server answers itself, being State and Status.
Sourcepub fn state_config(self, config: AttrConfig) -> Self
pub fn state_config(self, config: AttrConfig) -> Self
Set the configuration the State attribute of every device of that class starts from, which the database and clients then override like the one of any attribute. The default one only gives it a label and a description.
§Panics
If the configuration gives a value to a property a state does not support, such as
a bound or an event criterion, see AttrConfig.
Sourcepub fn status_config(self, config: AttrConfig) -> Self
pub fn status_config(self, config: AttrConfig) -> Self
Set the configuration the Status attribute of every device of that class starts
from, see Self::state_config.
§Panics
If the configuration gives a value to a property a string does not support, see
Self::state_config.
Sourcepub fn push_state_events(
self,
change: Option<bool>,
archive: Option<bool>,
) -> Self
pub fn push_state_events( self, change: Option<bool>, archive: Option<bool>, ) -> Self
Declare that the devices of that class push the events of their State themselves,
change and archive, see AttrDef::push_change_event.
Sourcepub fn push_status_events(
self,
change: Option<bool>,
archive: Option<bool>,
) -> Self
pub fn push_status_events( self, change: Option<bool>, archive: Option<bool>, ) -> Self
Declare that the devices of that class push the events of their Status themselves,
see Self::push_state_events.