pub struct Dev<M: Model> { /* private fields */ }Expand description
The handle to a device from within its own execution functions, giving access to the device outside of its model.
A device can be served while having no model: until it is initialized, or when its initialization failed. It is then in UNKNOWN or FAULT state, with a status describing why it has no model. The idea behind this is that the Init command, that delete-then-init a device, might fail, however we don’t want to stop serving the device for that. This also allows a server to start if any of its devices fails to init, the device will be available but it will not be usable in any way, it will just be possible to call Init and try to fix it, individually from the other devices that might be running.
Implementations§
Source§impl<M: Model> Dev<M>
impl<M: Model> Dev<M>
pub fn name(&self) -> &str
pub fn class(&self) -> &Class<M>
pub fn server(&self) -> &Server
Sourcepub async fn list_prop_async(&self, filter: &str) -> Result<Spectrum<str>>
pub async fn list_prop_async(&self, filter: &str) -> Result<Spectrum<str>>
The names of the properties of this device that match the given filter.
Sourcepub fn list_prop(&self, filter: &str) -> Result<Spectrum<str>>
pub fn list_prop(&self, filter: &str) -> Result<Spectrum<str>>
The names of the properties of this device, see Self::list_prop_async.
Sourcepub fn get_prop_async<Spec, Names: ToNames>(
&self,
names: Names,
) -> impl Future<Output = Result<Spec::Output>> + Sendwhere
Spec: GetPropSpec<Names>,
pub fn get_prop_async<Spec, Names: ToNames>(
&self,
names: Names,
) -> impl Future<Output = Result<Spec::Output>> + Sendwhere
Spec: GetPropSpec<Names>,
The properties of this device, parsed into the shape the given names ask for, see
crate::database::DatabaseProxy::get_dev_prop.
Sourcepub fn get_prop<Spec, Names: ToNames>(
&self,
names: Names,
) -> Result<Spec::Output>where
Spec: GetPropSpec<Names>,
pub fn get_prop<Spec, Names: ToNames>(
&self,
names: Names,
) -> Result<Spec::Output>where
Spec: GetPropSpec<Names>,
The properties of this device, see Self::get_prop_async.
Sourcepub fn set_prop_async<'a, Spec>(
&'a self,
spec: Spec,
) -> impl Future<Output = Result<()>> + Sendwhere
Spec: SetPropSpec<'a>,
pub fn set_prop_async<'a, Spec>(
&'a self,
spec: Spec,
) -> impl Future<Output = Result<()>> + Sendwhere
Spec: SetPropSpec<'a>,
Write the given properties of this device.
Sourcepub fn set_prop<'a, Spec>(&'a self, spec: Spec) -> Result<()>where
Spec: SetPropSpec<'a>,
pub fn set_prop<'a, Spec>(&'a self, spec: Spec) -> Result<()>where
Spec: SetPropSpec<'a>,
Write the given properties of this device, see Self::set_prop_async.
Sourcepub fn del_prop_async<Names: ToNamesNotAll>(
&self,
names: Names,
) -> impl Future<Output = Result<()>> + Send
pub fn del_prop_async<Names: ToNamesNotAll>( &self, names: Names, ) -> impl Future<Output = Result<()>> + Send
Delete the given properties of this device.
Sourcepub fn del_prop<Names: ToNamesNotAll>(&self, names: Names) -> Result<()>
pub fn del_prop<Names: ToNamesNotAll>(&self, names: Names) -> Result<()>
Delete the given properties of this device, see Self::del_prop_async.
Sourcepub fn add_command(&self, def: CommandDef<M>) -> Result<()>
pub fn add_command(&self, def: CommandDef<M>) -> Result<()>
Add a command to that device only, from its definition, which is what a device
whose interface depends on its properties does at initialization; a command every
device of the class has is defined on the class instead, see ClassDef::command.
A name the class already defines is refused rather than shadowed: the device was given every command of its class before its initialization ran.
Sourcepub fn remove_command(&self, name: &str) -> bool
pub fn remove_command(&self, name: &str) -> bool
Remove a command from that device, telling whether it was defined.
Sourcepub fn add_attr(&self, def: AttrDef<M>) -> Result<()>
pub fn add_attr(&self, def: AttrDef<M>) -> Result<()>
Add an attribute to that device only, from its definition, see
Self::add_command and ClassDef::attr.
An attribute added by the initialization of the device is configured from the database once the initialization returns. One added at any other time keeps the configuration of its definition.
Sourcepub async fn set_attr_w_value_async(
&self,
name: &str,
value: impl IntoValue,
) -> Result<()>
pub async fn set_attr_w_value_async( &self, name: &str, value: impl IntoValue, ) -> Result<()>
Give the attribute of that name a new set point without writing it, which every read
gives back as its write value from then on, and which the database remembers if the
attribute is memorized, see AttrMemorized.
This is for a device whose set point changes by itself, a motor stopped short of its target for instance, so that a client and the next initialization find the value the device actually works towards.
Sourcepub fn set_attr_w_value(&self, name: &str, value: impl IntoValue) -> Result<()>
pub fn set_attr_w_value(&self, name: &str, value: impl IntoValue) -> Result<()>
Give the attribute of that name a new set point, see Self::set_attr_w_value_async,
which must therefore never run in an asynchronous handler. Giving up after the
timeout of the database of the server, which is what it waits for.
Sourcepub async fn set_attr_config_async(
&self,
name: &str,
config: &AttrConfig,
) -> Result<()>
pub async fn set_attr_config_async( &self, name: &str, config: &AttrConfig, ) -> Result<()>
Change the configuration of the attribute of that name, given as the whole of it,
which is what a client changing it does: refused if it is incoherent, stored in the
database, and pushed to the subscribers of the configuration of that attribute. Its
current configuration is the one Attr::config gives.
Sourcepub fn set_attr_config(&self, name: &str, config: &AttrConfig) -> Result<()>
pub fn set_attr_config(&self, name: &str, config: &AttrConfig) -> Result<()>
Change the configuration of the attribute of that name, see
Self::set_attr_config_async, which must therefore never run in an asynchronous
handler. Giving up after the timeout of the database of the server, which is what it
waits for.
Sourcepub fn set_auto_alarm_states(&self, states: &[DevState])
pub fn set_auto_alarm_states(&self, states: &[DevState])
Set the states in which this device is put in ALARM when one of its attributes is in
alarm, which is only DevState::On unless set otherwise, an empty list leaving
the state of the device to its state function alone.
When the state function gives one of those states, the attributes that have any alarm configured are read, and a single one of them in alarm or in warning makes the device ALARM, its status telling which and why, the way cppTango does. Getting the state of the device then borrows its model the way reading those attributes does.
Sourcepub fn remove_attr(&self, name: &str) -> bool
pub fn remove_attr(&self, name: &str) -> bool
Remove an attribute from that device, telling whether it was defined.
Sourcepub fn get_command(&self, name: &str) -> Option<Ref<'_, Command<M>>>
pub fn get_command(&self, name: &str) -> Option<Ref<'_, Command<M>>>
The command of that name on this device, absent when it has none of that name.
Every request on a command goes through this, and it is borrowed rather than kept: the interface store is unlocked as soon as the command is out of it, because a handler is free to change the interface of its own device, and that store is the lock taken under the model, never around it.
Sourcepub fn get_attr(&self, name: &str) -> Option<Ref<'_, Attr<M>>>
pub fn get_attr(&self, name: &str) -> Option<Ref<'_, Attr<M>>>
The attribute of that name on this device, reached the way Self::get_command
reaches a command.
Sourcepub fn commands(&self) -> Vec<Ref<'_, Command<M>>>
pub fn commands(&self) -> Vec<Ref<'_, Command<M>>>
Every command of the interface of this device.
Sourcepub fn attrs(&self) -> Vec<Ref<'_, Attr<M>>>
pub fn attrs(&self) -> Vec<Ref<'_, Attr<M>>>
Every attribute of the interface of this device.
TODO: The order is the one of the interface store, which is a hash map and therefore arbitrary; a client reading a whole interface expects a stable one.
Sourcepub fn push_attr_event(
&self,
name: &str,
event: AttrValueEvent,
read: Result<AttrRead<Value>>,
) -> Result<()>
pub fn push_attr_event( &self, name: &str, event: AttrValueEvent, read: Result<AttrRead<Value>>, ) -> Result<()>
Push an event of that kind for the attribute of that name, the state and the status
included: a reading, or the error reading it, failing if the device has no such
attribute, or if that attribute does not declare it pushes such events, see
AttrDef::push_change_event. See the methods below for what a device pushes most.
A reading with no write value is given the set point of its attribute, and one with a write value makes it the set point, the way a read does, so that an event and a read of a writable attribute carry the same, as with cppTango.
Sourcepub fn push_change_event(&self, name: &str, value: impl IntoValue) -> Result<()>
pub fn push_change_event(&self, name: &str, value: impl IntoValue) -> Result<()>
Push a change event for the attribute of that name, a value of a valid quality read
now, see Self::push_attr_event.
Sourcepub fn push_archive_event(
&self,
name: &str,
value: impl IntoValue,
) -> Result<()>
pub fn push_archive_event( &self, name: &str, value: impl IntoValue, ) -> Result<()>
Push an archive event for the attribute of that name, see Self::push_change_event.
Sourcepub fn push_user_event(&self, name: &str, value: impl IntoValue) -> Result<()>
pub fn push_user_event(&self, name: &str, value: impl IntoValue) -> Result<()>
Push a user event for the attribute of that name, see Self::push_change_event.
Sourcepub fn push_alarm_event(&self, name: &str, value: impl IntoValue) -> Result<()>
pub fn push_alarm_event(&self, name: &str, value: impl IntoValue) -> Result<()>
Push an alarm event for the attribute of that name, see Self::push_change_event.
Sourcepub fn push_data_ready_event(&self, name: &str) -> Result<()>
pub fn push_data_ready_event(&self, name: &str) -> Result<()>
Push that the attribute of that name is ready to be read, failing if the device has no such attribute.
Trait Implementations§
Source§impl<M: Model> AnyDev for Dev<M>
impl<M: Model> AnyDev for Dev<M>
Source§fn init(&self) -> BoxFuture<'_, Result<()>>
fn init(&self) -> BoxFuture<'_, Result<()>>
Source§fn withdraw(&self) -> BoxFuture<'_, Result<()>>
fn withdraw(&self) -> BoxFuture<'_, Result<()>>
Dev::init. Read more