Broker

Struct Broker 

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

The Broker Interface

This is the primary interface for devices acting as a broker.

Currently the max capacity is fixed with a maximum of 8 clients connected. Each Client may subscribe up to 8 topics. Each Client may register up to 8 shortcodes.

In the future, these limits may be configurable.

As a note, the Broker currently creates a sizable object, due to the fixed upper limits

Implementations§

Source§

impl Broker

Source

pub fn new() -> Self

Create a new broker with no clients attached

Source

pub fn register_client(&mut self, id: &Uuid) -> Result<(), ServerError>

Register a client to the broker

This can be done dynamically, e.g. when a client connects for the first time, e.g. a TCP session is established, or the first packet is received, or can be done ahead-of-time, e.g. when communicating with a fixed set of wired devices.

Clients must be registered before messages from them can be processed.

If an already-registered client is re-registered, they will be reset to an initial connection state, dropping all subscriptions or shortcodes.

Source

pub fn remove_client(&mut self, id: &Uuid) -> Result<(), ServerError>

Remove a client from the broker

This could be necessary if the connection to a client breaks or times out Once removed, no further messages to or from this client will be processed

Source

pub fn reset_client(&mut self, id: &Uuid) -> Result<(), ServerError>

Reset a client registered with the broker, without removing it

This could be necessary if the connection to a client breaks or times out.

Source

pub fn process_msg<'a, 'b: 'a>( &'b mut self, req: &'a Request<'a>, ) -> Result<Vec<Response<'a>, U8>, ServerError>

Process a single message from a client

A message from a client will be processed. If processing this message generates responses that need to be sent (e.g. a publish occurs and subscribed clients should be notified, or if the broker is responding to a request from the client), they will be returned, and the messages should be sent to the appropriate clients.

Requests and Responses are addressed by the Uuid registered for each client

NOTE: If an error occurs, you probably should send a RESET_MESSAGE to that client to force them to reconnect. You may also want to remove_client or reset_client, depending on the situation. This will hopefully be handled automatically in the future.

Trait Implementations§

Source§

impl Default for Broker

Source§

fn default() -> Broker

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Broker

§

impl RefUnwindSafe for Broker

§

impl Send for Broker

§

impl Sync for Broker

§

impl Unpin for Broker

§

impl UnwindSafe for Broker

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, 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> Same for T

Source§

type Output = T

Should always be Self
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.