tango/server/mod.rs
1//! This module provides a high-level access to the server-side of Tango.
2
3mod def;
4
5mod server;
6mod class;
7mod dev;
8mod attr;
9mod command;
10mod history;
11mod polling;
12
13mod admin;
14mod terminate;
15
16#[cfg(feature = "cli")]
17mod cli;
18
19pub use def::{ClassDef, CommandDef, AttrDef};
20pub use server::{Server, ServerBuilder, ServerHandle};
21pub use terminate::terminate;
22pub use class::Class;
23pub use dev::Dev;
24pub use command::Command;
25pub use attr::Attr;
26
27#[cfg(feature = "cli")]
28pub use cli::ServerArgs;
29
30use crate::dev::DevState;
31
32
33/// What a device model has to be, gathering in one bound everything a server needs of it:
34/// it is shared between the threads serving the requests.
35///
36/// A model is deleted by being given to the delete function of its class, see
37/// [`ClassDef::delete`], which is where it releases what it holds: before every
38/// initialization but the first, and once its device is no longer served. A model whose
39/// server is dropped without being stopped, see [`Server::stop_async`], is never deleted, and
40/// only dropped with the last reference to its device, which may be held long after. Its
41/// [`Drop`] is therefore only relied upon to free memory, never to release its hardware or
42/// anything else that the new model of a device restarted under the same name takes again.
43///
44/// Every such type is a model, there being nothing to implement: this is the bound the
45/// definitions and the devices are written against rather than a trait a model opts into.
46pub trait Model: Send + Sync + 'static {}
47impl<T: Send + Sync + 'static> Model for T {}
48
49/// The name of the attribute, and of the command, every device gives its state under.
50const STATE_NAME: &str = "State";
51/// The name of the attribute, and of the command, every device gives its status under.
52const STATUS_NAME: &str = "Status";
53/// The name of the command every device is initialized again by.
54const INIT_NAME: &str = "Init";
55/// The names of the attributes every device has whatever its class.
56const RESERVED_ATTRS: &[&str] = &[STATE_NAME, STATUS_NAME];
57/// The names of the commands every device has whatever its class.
58const RESERVED_COMMANDS: &[&str] = &[STATE_NAME, STATUS_NAME, INIT_NAME];
59/// The status of a device that has no model because it has not been initialized yet,
60/// which every device is between the moment it is added and the moment it is synchronized.
61const MISSING_STATUS: &str = "The device is not initialized";
62/// The status of a device whose class derives no status of its own from the model.
63const DEFAULT_STATUS: &str = "Device is on";
64/// The state of a device whose class derives no state of its own from the model, which is
65/// the one every device that has nothing to say of itself is in.
66const DEFAULT_STATE: DevState = DevState::On;
67
68/// How many readings the history of an attribute keeps unless set otherwise, see
69/// [`Attr::set_history_depth`], which is the depth of the polling buffer of cppTango.
70const DEFAULT_HISTORY_DEPTH: usize = 10;
71
72/// The reserved name that name is, if it is one: the state, the status and the
73/// initialization of a device are answered by the server itself, whatever its class and its
74/// devices define, so anything defined under one of those names would never be reached.
75///
76/// Given back in the spelling of the reserved name rather than of the one that was asked
77/// for, the two differing only by their case, so that a refusal can point at both.
78fn reserved_name<'r>(name: &str, reserved: &'r [&'r str]) -> Option<&'r str> {
79 reserved.iter().copied().find(|other| name.eq_ignore_ascii_case(other))
80}