pub struct Context { /* private fields */ }
Expand description
Context implementation
-
selfId
The ID of the device that this context is for. -
local_sensor
The values perceived by the local sensors of the device. -
nbr_sensor
The values perceived by the sensors for each neighbor of the device. -
exports
All the export that are available to the device.
Implementations§
source§impl Context
impl Context
sourcepub fn new(
self_id: i32,
local_sensor: HashMap<SensorId, Rc<Box<dyn Any>>>,
nbr_sensor: HashMap<SensorId, HashMap<i32, Rc<Box<dyn Any>>>>,
exports: HashMap<i32, Export>
) -> Self
pub fn new( self_id: i32, local_sensor: HashMap<SensorId, Rc<Box<dyn Any>>>, nbr_sensor: HashMap<SensorId, HashMap<i32, Rc<Box<dyn Any>>>>, exports: HashMap<i32, Export> ) -> Self
Create new Context of a device from the given parameters.
Arguments
-
self_id
- the ID of the device -
local_sensor
- The values perceived by the local sensors of the device. -
nbr_sensor
- The values perceived by the sensors for each neighbor of the device. -
exports
- All the export that are available to the device.
Returns
The new Context.
pub fn self_id(&self) -> &i32
pub fn exports(&self) -> &HashMap<i32, Export>
sourcepub fn put_export(&mut self, id: i32, data: Export)
pub fn put_export(&mut self, id: i32, data: Export)
Add an export of a device to the context.
Arguments
id
the ID of the devicedata
the export of the device
sourcepub fn read_export_value<A: 'static + FromStr + Clone>(
&self,
id: &i32,
path: &Path
) -> Result<A>
pub fn read_export_value<A: 'static + FromStr + Clone>( &self, id: &i32, path: &Path ) -> Result<A>
Read the value corresponding to the given path from the export of a device.
Arguments
id
the ID of the devicepath
the path to the value
Generic Parameters
A
the type of the value to return. It must have a'static
lifetime.
Returns
An Option
of the value if it exists
pub fn local_sensors(&self) -> &HashMap<SensorId, Rc<Box<dyn Any>>>
sourcepub fn local_sense<A: 'static>(&self, local_sensor_id: &SensorId) -> Option<&A>
pub fn local_sense<A: 'static>(&self, local_sensor_id: &SensorId) -> Option<&A>
Get the value of the given sensor.
Arguments
name
the name of the sensor
Generic Parameters
A
the type of the value to return. It must have a'static
lifetime.
Returns
An Option
of the value if it exists
pub fn nbr_sensors(&self) -> &HashMap<SensorId, HashMap<i32, Rc<Box<dyn Any>>>>
sourcepub fn nbr_sense<A: 'static>(
&self,
sensor_id: &SensorId,
nbr_id: &i32
) -> Option<&A>
pub fn nbr_sense<A: 'static>( &self, sensor_id: &SensorId, nbr_id: &i32 ) -> Option<&A>
Get the value of the given sensor for the given neighbor.
Arguments
sensor_id
the neighbor sensor idnbr_id
the neighbor id
Generic Parameters
A
the type of the value to return. It must have a'static
lifetime.
Returns
An Option
of the value if it exists