Struct omnisensor::sensor::Sensor
source · [−]pub struct Sensor {Show 16 fields
pub name: String,
dbuspath: Arc<SensorPath>,
pub kind: SensorType,
poll_interval: Duration,
pub power_state: PowerState,
pub thresholds: [Option<Threshold>; 5],
scale: f64,
errcount: usize,
cache: SignalProp<f64>,
minvalue: SignalProp<f64>,
maxvalue: SignalProp<f64>,
available: SignalProp<bool>,
functional: SignalProp<bool>,
associations: SignalProp<Vec<(String, String, String)>>,
mode: SensorMode,
iotask: Option<SensorIOTask>,
}
Expand description
The top-level representation of a sensor.
Fields
name: String
The globally-unique name of the sensor.
dbuspath: Arc<SensorPath>
The dbus path of the sensor object.
kind: SensorType
The type of the sensor.
poll_interval: Duration
The period of the sensor polling loop.
power_state: PowerState
The host power state in which this sensor is enabled.
thresholds: [Option<Threshold>; 5]
Threshold values (warning, critical, etc.) for the sensor.
scale: f64
A multiplicative scaling factor for readings from the sensor.
This is only the config-specified scaling factor (converted to a multiplier); scaling to convert sysfs hwmon values to the desired units (e.g. 0.001 to convert a sysfs millivolt value to volts) happens elsewhere.
errcount: usize
The number of failed update attempts since the last successful one.
cache: SignalProp<f64>
The dbus property that provides the sensor’s value.
minvalue: SignalProp<f64>
The dbus property that provides the sensor’s minimum value.
maxvalue: SignalProp<f64>
The dbus property that provides the sensor’s maximum value.
available: SignalProp<bool>
The dbus property that provides the sensor’s availability state.
functional: SignalProp<bool>
The dbus property that provides the sensor’s functionality state.
associations: SignalProp<Vec<(String, String, String)>>
The dbus property that provides the sensor’s associations.
mode: SensorMode
The sensor’s dbus RO/RW mode.
iotask: Option<SensorIOTask>
The sensor’s running I/O task.
This is Some
when the sensor is active and None
when it’s inactive
(e.g. when the host’s current power state doesn’t match the sensor’s
power_state
).
Implementations
sourceimpl Sensor
impl Sensor
sourcepub fn new(
cfgpath: &InventoryPath,
name: &str,
kind: SensorType,
intfs: &SensorIntfData,
conn: &Arc<SyncConnection>,
mode: SensorMode
) -> Self
pub fn new(
cfgpath: &InventoryPath,
name: &str,
kind: SensorType,
intfs: &SensorIntfData,
conn: &Arc<SyncConnection>,
mode: SensorMode
) -> Self
Construct a new Sensor
with the given parameters.
It will initially be disabled (no running I/O task); it can subsequently be
enabled by a call to its activate()
method.
sourcepub fn with_poll_interval(self, poll_interval: Duration) -> Self
pub fn with_poll_interval(self, poll_interval: Duration) -> Self
Set the sensor’s poll_interval
.
sourcepub fn with_power_state(self, power_state: PowerState) -> Self
pub fn with_power_state(self, power_state: PowerState) -> Self
Set the sensor’s power_state
.
sourcepub fn with_thresholds_from(
self,
cfg: &[ThresholdConfig],
threshold_intfs: &[SensorIntf<ThresholdIntfMsgFns>; 5],
conn: &Arc<SyncConnection>
) -> Self
pub fn with_thresholds_from(
self,
cfg: &[ThresholdConfig],
threshold_intfs: &[SensorIntf<ThresholdIntfMsgFns>; 5],
conn: &Arc<SyncConnection>
) -> Self
Set the sensor’s thresholds
.
The thresholds are constructed from the provided config data, interfaces, and dbus connection.
sourcepub fn with_scale(self, scale: f64) -> Self
pub fn with_scale(self, scale: f64) -> Self
Set the sensor’s scale
.
sourcepub fn with_maxval(self, max: f64) -> Self
pub fn with_maxval(self, max: f64) -> Self
Set the sensor’s maxvalue
.
sourcepub fn with_minval(self, min: f64) -> Self
pub fn with_minval(self, min: f64) -> Self
Set the sensor’s minvalue
.
sourceasync fn set_value(&mut self, newval: f64)
async fn set_value(&mut self, newval: f64)
Set the sensor’s cache
d value and update the state of its
thresholds
.
sourcepub async fn activate(sensor: &Arc<Mutex<Sensor>>, ioctx: SensorIOCtx)
pub async fn activate(sensor: &Arc<Mutex<Sensor>>, ioctx: SensorIOCtx)
Start a sensor’s update task using the provided ioctx
and mark it available.
This is an associated function rather than a method on self
because it needs
to pass a weak reference to itself into the future that gets spawned as
Sensor::iotask
, and we need an Arc
for that.
sourcepub async fn deactivate(&mut self)
pub async fn deactivate(&mut self)
Stop a sensor’s update task and mark it unavailable.
sourcepub fn add_to_dbus(
&self,
cr: &SyncMutex<Crossroads>,
sensor_intfs: &SensorIntfData,
cbdata: &Arc<Mutex<Sensor>>
)
pub fn add_to_dbus(
&self,
cr: &SyncMutex<Crossroads>,
sensor_intfs: &SensorIntfData,
cbdata: &Arc<Mutex<Sensor>>
)
Publish a sensor’s properties on dbus.
cbdata
must contain self
. (Perhaps this should instead be an associated
function that just takes that instead of both separately.)