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, 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>

Source

pub fn name(&self) -> &str

Source

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

Source

pub fn server(&self) -> &Server

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 del_prop_async<Names: ToNamesNotAll>( &self, names: Names, ) -> impl Future<Output = Result<()>> + Send

Delete the given properties of this device.

Source

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

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

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.

Source

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.

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<()>

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.

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<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.

Source

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.

Source

pub fn commands(&self) -> Vec<Ref<'_, Command<M>>>

Every command of the interface of this device.

Source

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.

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 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) -> 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>

Source§

fn name(&self) -> &str

The name of that device.
Source§

fn class(&self) -> &dyn AnyClass

The class of that device.
Source§

fn init(&self) -> BoxFuture<'_, Result<()>>

Initialize that device: its model, if it has one, is deleted, and a new one is built by the init function of its class, on the pool of the server when that may block. This only fails when the initialization never ran to its end, its function having panicked: one that failed is kept by the device instead.
Source§

fn withdraw(&self) -> BoxFuture<'_, Result<()>>

Stop serving that device, for good, and delete its model, if it has one, giving it back to the delete function of its class so that it may release what it owns: what a device goes through once it is removed from its server, or when the server shuts down. Not to be confused with the deletion of the model alone, which is also what an initialization starts with, see Dev::init. Read more
Source§

fn serve(&self) -> Result<Arc<str>>

Start serving that device through the backend of its server, giving back the ITR it is reached at. This is quick and never blocks, see crate::backend::BackendServer::add.
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> 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