pub struct Device { /* private fields */ }Expand description
A tosca device.
Implementations§
Source§impl Device
impl Device
Sourcepub fn new(
network_info: NetworkInformation,
description: Description,
route_configs: RouteConfigs,
) -> Self
pub fn new( network_info: NetworkInformation, description: Description, route_configs: RouteConfigs, ) -> Self
Creates a Device from NetworkInformation, Description,
and RouteConfigs.
This method can be useful when creating a device from data stored in a database.
Sourcepub const fn network_info(&self) -> &NetworkInformation
pub const fn network_info(&self) -> &NetworkInformation
Returns an immutable reference to NetworkInformation.
Sourcepub const fn description(&self) -> &Description
pub const fn description(&self) -> &Description
Returns an immutable reference to Description.
Sourcepub fn events_metadata(&self) -> Option<&EventsDescription>
pub fn events_metadata(&self) -> Option<&EventsDescription>
Returns an immutable reference to EventsDescription.
If None, the device does not support events.
Sourcepub fn requests_info(&self) -> Vec<RequestInfo<'_>>
pub fn requests_info(&self) -> Vec<RequestInfo<'_>>
Returns a RequestInfo vector containing the information
for each request.
Sourcepub fn requests_count(&self) -> usize
pub fn requests_count(&self) -> usize
Returns the total number of requests associated with the device.
Sourcepub const fn has_events(&self) -> bool
pub const fn has_events(&self) -> bool
Checks if a Device supports events.
Sourcepub const fn is_event_receiver_running(&self) -> bool
pub const fn is_event_receiver_running(&self) -> bool
Checks if the event receiver is currently running.
Always returns false if the Device does not support events.
Sourcepub async fn start_event_receiver(
&mut self,
id: usize,
buffer_size: usize,
) -> Result<Receiver<ToscaEvents>>
pub async fn start_event_receiver( &mut self, id: usize, buffer_size: usize, ) -> Result<Receiver<ToscaEvents>>
Starts the asynchronous event receiver if the Device supports
events.
An event receiver task connects to the broker of a device
and subscribes to its topic.
When a device transmits an event to the broker, the task retrieves the
event payload from the broker, parses the data, and sends the relevant
content to the Receiver returned by this method.
The buffer_size parameter specifies how many messages the event
receiver buffer can hold.
When the buffer is full, subsequent send attempts will wait until
a message is consumed from the channel.
When the returned Receiver is dropped, the event receiver task
terminates automatically.
§Errors
- The device does not support events
- The event receiver task has already been started
- An error occurred while attempting to subscribe to the broker topic