Skip to main content

Dev

Struct Dev 

Source
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, which deletes then initializes 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>

Source

pub fn name(&self) -> &str

The name of this device.

Source

pub fn class(&self) -> &Class<M>

The class this device is an instance of.

Source

pub fn server(&self) -> &Server

The server serving this device.

Source

pub fn is_withdrawn(&self) -> bool

Whether this device is gone for good: removed from its server and deleted, or its server ended. Nothing of it is served from then on, and pushing events or setting anything of its attributes fails, which is how a thread of its own learns to stop. A device added again under the same name, which is what a restart is, is another device, which this one never becomes.

Source

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.

Source

pub fn list_prop(&self, filter: &str) -> Result<Spectrum<str>>

The names of the properties of this device, see Self::list_prop_async.

Source

pub fn get_prop_async<Spec, Names: ToNames>( &self, names: Names, ) -> impl Future<Output = Result<Spec::Output>> + Send
where Spec: GetPropSpec<Names>,

The properties of this device, parsed into the shape the given names ask for, see crate::database::DatabaseProxy::get_dev_prop.

Source

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.

Source

pub fn set_prop_async<'a, Spec>( &'a self, spec: Spec, ) -> impl Future<Output = Result<()>> + Send
where Spec: SetPropSpec<'a>,

Write the given properties of this device.

Source

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.

Source

pub fn delete_prop_async<Names: ToNamesNotAll>( &self, names: Names, ) -> impl Future<Output = Result<()>> + Send

Delete the given properties of this device.

Source

pub fn delete_prop<Names: ToNamesNotAll>(&self, names: Names) -> Result<()>

Delete the given properties of this device, see Self::delete_prop_async.

Source

pub fn arc(&self) -> Arc<Self> ⓘ

This device, shared, which is how a handler, only given a reference to it, hands it to a thread of its own. Holding it does not keep it served, see Self::is_withdrawn.

Source

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.

Source

pub fn remove_command(&self, name: &str) -> bool

Remove a command from that device, telling whether it was defined.

Source

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.

Source

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. An attribute that cannot be written, the State and the Status included, is refused.

Source

pub fn set_attr_w_value(&self, name: &str, value: impl IntoValue) -> Result<()>

The blocking form of Self::set_attr_w_value_async, which must never run in an asynchronous handler; it gives up after the timeout of the database of the server.

Source

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.

Source

pub fn set_attr_config(&self, name: &str, config: &AttrConfig) -> Result<()>

The blocking form of Self::set_attr_config_async, which must never run in an asynchronous handler; it gives up after the timeout of the database of the server.

Source

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.

Source

pub fn remove_attr(&self, name: &str) -> bool

Remove an attribute from that device, telling whether it was defined.

Source

pub fn get_command(&self, name: &str) -> Option<Arc<Command<M>>>

The command of that name on this device, absent when it has none of that name: the State, the Status and the Init every device has, whatever its class defines, or else one of its interface.

Every request on a command goes through this, and it is shared rather than borrowed from the interface store: 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.

Source

pub fn get_attr(&self, name: &str) -> Option<Arc<Attr<M>>>

The attribute of that name on this device, the State and the Status included, reached the way Self::get_command reaches a command.

Source

pub fn commands(&self) -> Vec<Arc<Command<M>>>

Every command of this device: the three every device has first, then its whole interface.

Source

pub fn attrs(&self) -> Vec<Arc<Attr<M>>>

Every attribute of this device: the two every device has first, then its whole interface.

TODO: The order of the interface 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.

Source

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 must have a read value, so an attribute that cannot be read pushes none, and be of a valid quality for the state and the status. 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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn push_data_ready_event(&self, name: &str, counter: i32) -> Result<()>

Push that the attribute of that name is ready to be read, with a counter of the device’s own telling which of its readings it is, see AttrReady. This fails if the device has no such attribute, or does not declare it announced, see AttrDef::push_data_ready_event.

Trait Implementations§

Source§

impl<M: Model> Debug for Dev<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<M> !Freeze for Dev<M>

§

impl<M> !RefUnwindSafe for Dev<M>

§

impl<M> !UnwindSafe for Dev<M>

§

impl<M> Forget for Dev<M>

§

impl<M> Send for Dev<M>
where Weak<Dev<M>>: Send, Arc<Class<M>>: Send, Mutex<DevMutable<M>>: Send, RwLock<Option<Result<M, Error>>>: Send,

§

impl<M> Sync for Dev<M>
where Weak<Dev<M>>: Sync, Arc<Class<M>>: Sync, Mutex<DevMutable<M>>: Sync, RwLock<Option<Result<M, Error>>>: Sync,

§

impl<M> Unpin for Dev<M>
where Weak<Dev<M>>: Unpin, Arc<Class<M>>: Unpin, Mutex<DevMutable<M>>: Unpin, RwLock<Option<Result<M, Error>>>: Unpin,

§

impl<M> UnsafeUnpin for Dev<M>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Model for T
where T: Send + Sync + 'static,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more