Controller

Struct Controller 

Source
pub struct Controller { /* private fields */ }
Expand description

A controller for interacting with tosca devices.

The main functionalities include:

  • Discovering tosca devices on the network and registering them in memory.
  • Sending requests to a specific device identified by its ID, awaiting a response, and forwarding it directly to the caller.
  • Controlling request sending by allowing or blocking requests based on the defined privacy policy.

Implementations§

Source§

impl Controller

Source

pub fn new(discovery: Discovery) -> Self

Creates a Controller from a Discovery configuration.

Source

pub fn from_devices(discovery: Discovery, devices: Devices) -> Self

Creates a Controller from a Discovery configuration and an initial set of Devices.

This method is useful when Devices are retrieved from database.

Source

pub fn policy(self, privacy_policy: Policy) -> Self

Defines a Policy while constructing a Controller.

Source

pub fn change_policy(&mut self, privacy_policy: Policy)

Changes the Policy.

Source

pub async fn discover(&mut self) -> Result<(), Error>

Discovers all available Devices on the network.

§Errors
§Discovery Errors

During the discovery process, common errors include:

  • Inability to connect to the network
  • Failure to disable a particular network interface
  • Issues terminating the discovery process.
§Sending Requests Errors

When sending a request to a device to retrieve its structure description and routes, network failures or timeouts may prevent the request from being sent and affect the returned response as well.

Source

pub async fn start_event_receivers( &mut self, buffer_size: usize, ) -> Result<Receiver<EventPayload>, Error>

Starts asynchronous event receiver tasks for all Devices that support 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 Receiver is dropped, all tasks terminate automatically.

§Errors
  • No event receiver tasks has started
  • An error occurred while subscribing to the broker topic of a device.
Source

pub const fn devices(&self) -> &Devices

Returns an immutable reference to Devices.

Source

pub const fn devices_mut(&mut self) -> &mut Devices

Returns a mutable reference to Devices.

Source

pub fn device(&self, id: usize) -> Result<DeviceSender<'_>, Error>

Builds a DeviceSender for the Device with the given identifier.

§Errors

An error is returned if no devices are found or if the given index does not exist.

Source

pub async fn shutdown(self)

Shuts down the Controller, stopping all asynchronous tasks and releasing all associated resources.

§Note

For a graceful shutdown, this method must be called before dropping the Controller.

Trait Implementations§

Source§

impl Debug for Controller

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Controller

Source§

fn eq(&self, other: &Controller) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Controller

Auto Trait Implementations§

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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