pub struct CommandDef<M: Model> { /* private fields */ }Expand description
A builder for defining a command of a device.
Implementations§
Source§impl<M: Model> CommandDef<M>
impl<M: Model> CommandDef<M>
Sourcepub fn new<N>(name: N) -> Self
pub fn new<N>(name: N) -> Self
Create a new command definition, without any execution function.
Sourcepub fn in_doc<D>(self, doc: D) -> Self
pub fn in_doc<D>(self, doc: D) -> Self
Set the documentation of the command argument (argin).
A command has no description of its own, Tango only telling a client what each side of it is, so what the command does has to be said in one of these two.
Sourcepub fn display_level(self, level: DisplayLevel) -> Self
pub fn display_level(self, level: DisplayLevel) -> Self
Set the display level of the command, DisplayLevel::Expert keeping it out of
the panels an operator is shown without keeping it from anyone who asks for it.
Sourcepub fn polled(self, period: Duration) -> Self
pub fn polled(self, period: Duration) -> Self
Ask for the command to be polled at that period, its result being recorded in its
history, which a request from the cache is answered with, see super::Command.
Only a command that takes no argument can be polled, there being no argument for the server to invent.
This period comes second: a command the polled_cmd property of the device lists
is polled at the period the property gives, and one it does not list at this one.
The admin device changes it while the device runs, writing the property along, but
a command removed from the polling this way is polled at this period again from the
next initialization of the device, the property having no way to say it is not.
Sourcepub fn in_kind(self, kind: CommandDataKind) -> Self
pub fn in_kind(self, kind: CommandDataKind) -> Self
Set the advertised kind of the command argument (argin). This is only needed for
the execution functions that take a raw Value argument, the typed ones derive
it from their input type.
§Panics
If the argument kind has already been defined, explicitly or by an execution function, as a different kind.
Sourcepub fn out_kind(self, kind: CommandDataKind) -> Self
pub fn out_kind(self, kind: CommandDataKind) -> Self
Sourcepub fn exec_with<F>(self, func: F) -> Self
pub fn exec_with<F>(self, func: F) -> Self
Define the execution function of this command, with a shared access to the model.
This is the raw form of Self::exec: the closure is given the argument
Value as-is and returns one, converting what it borrows from the model itself,
which is what makes a closure usable for such a result. Because no input and output
types are involved, the advertised kinds have to be given with Self::in_kind
and Self::out_kind.
Sourcepub fn exec<F, I>(self, func: F) -> Self
pub fn exec<F, I>(self, func: F) -> Self
Define the execution function of this command, with a shared access to the model, which allows parallel execution of such functions.
The argument and result types are taken from the ExecShared implementation of
the function. The result may borrow from the model, being converted into a value
before the model is released, which requires a function item generic over the
model lifetime, typically an associated method of the model.
§Panics
If either advertised kind has already been defined as a different kind, see
Self::in_kind and Self::out_kind.
Sourcepub fn exec_exclusive_with<F>(self, func: F) -> Self
pub fn exec_exclusive_with<F>(self, func: F) -> Self
Define the execution function of this command, with an exclusive access to the
model. This is the raw form of Self::exec_exclusive, see Self::exec_with.
Sourcepub fn exec_exclusive<F, I>(self, func: F) -> Self
pub fn exec_exclusive<F, I>(self, func: F) -> Self
Define the execution function of this command, with an exclusive access to the model, therefore no other command or attribute can access it in parallel.
See Self::exec for the constraints on the argument and result types, this one
is only different in that its function item takes the model by exclusive reference.
§Panics
If either advertised kind has already been defined as a different kind, see
Self::in_kind and Self::out_kind.
Sourcepub fn exec_async_with<F>(self, func: F) -> Self
pub fn exec_async_with<F>(self, func: F) -> Self
Define the execution function of this command, asynchronously and with a shared
access to the model. This is the raw form of Self::exec_async, for a closure
that boxes its future itself, see Self::exec_with.
Sourcepub fn exec_async<F, I>(self, func: F) -> Self
pub fn exec_async<F, I>(self, func: F) -> Self
Define the execution function of this command, asynchronously and with a shared
access to the model, typically an async fn method of the model.
This is what a command forwarding its execution to other devices is written as:
it holds no thread while it waits on them, and may wait on many of them at once.
The future is polled by the server itself, so it must never block, see
ClassDef::state_async.
§Panics
If either advertised kind has already been defined as a different kind, see
Self::in_kind and Self::out_kind.
Sourcepub fn exec_exclusive_async_with<F>(self, func: F) -> Self
pub fn exec_exclusive_async_with<F>(self, func: F) -> Self
Define the execution function of this command, asynchronously and with an
exclusive access to the model. This is the raw form of Self::exec_exclusive_async,
see Self::exec_async_with.
Sourcepub fn exec_exclusive_async<F, I>(self, func: F) -> Self
pub fn exec_exclusive_async<F, I>(self, func: F) -> Self
Define the execution function of this command, asynchronously and with an
exclusive access to the model, which no other command or attribute can then access
until the future completes. See Self::exec_async.
§Panics
If either advertised kind has already been defined as a different kind, see
Self::in_kind and Self::out_kind.