Struct Engine

Source
pub struct Engine<CB: Callback, T: Timebase> { /* private fields */ }
Expand description

The core of an SSDP implementation

This low-level facility is usually wrapped-up in crate::Service or crate::AsyncService for use in larger programs, but can also be used directly when needed (e.g. on embedded systems).

This struct handles parsing and emitting SSDP messages; it does not own or define the UDP sockets themselves, which are left to its owner. The owner should pass incoming UDP packets to Engine::on_data, and changes to available network interfaces (if required) to Engine::on_network_event.

The notifications will be retransmitted on a timer; the owner of the Engine should, each time incoming packets have been dealt with, call Engine::poll_timeout to determine the Instant when Engine next has work to do, and then once that Instant occurs, call Engine::handle_timeout so that the work can be done. See, for instance, the tokio::select! loop in AsyncService::new_inner.

Implementations§

Source§

impl<CB: Callback, T: Timebase> Engine<CB, T>

Source

pub fn new(random_seed: u32, now: T::Instant) -> Self

Create a new Engine, parameterised by callback type

Source

pub fn handle_timeout<SCK: TargetedSend>( &mut self, socket: &SCK, now: T::Instant, )

Deal with any expired timeouts

Source

pub fn poll_timeout(&self) -> T::Instant

Obtain the desired delay before the next call to handle_timeout

Source

pub fn reset_refresh_timer(&mut self, now: T::Instant)

Reset the refresh timer (e.g. if network has gone away and come back)

Source

pub fn refresh<SCK: TargetedSend>(&mut self, socket: &SCK)

Re-send all announcements

Source

pub fn subscribe<SCK: TargetedSend>( &mut self, notification_type: String, callback: CB, socket: &SCK, )

Subscribe to notifications of a particular service type

And send searches.

Source

pub fn on_data( &mut self, buf: &[u8], wasto: IpAddr, wasfrom: SocketAddr, now: T::Instant, )

Notify the Engine that data is ready on one of its sockets

Notify the Engine of a new network interface

NB. If your network-interface notifications are coming from cotton-netif, you should call the general on_network_event instead of this specific method.

§Errors

Passes on errors from the underlying system-calls for joining multicast groups.

Notify the Engine of a deleted network interface

NB. If your network-interface notifications are coming from cotton-netif, you should call the general on_network_event instead of this specific method.

§Errors

Passes on errors from the underlying system-calls for leaving multicast groups.

Source

pub fn on_new_addr_event<SCK: TargetedSend>( &mut self, ix: &InterfaceIndex, addr: &IpAddr, search: &SCK, )

Notify the Engine of a new IP address

NB. If your IP address notifications are coming from cotton-netif, you should call the general on_network_event instead of this specific method.

Source

pub fn on_del_addr_event(&mut self, ix: &InterfaceIndex, addr: &IpAddr)

Notify the Engine of a deleted IP address

NB. If your IP address notifications are coming from cotton-netif, you should call the general on_network_event instead of this specific method.

Source

pub fn on_network_event<SCK: TargetedSend, MCAST: Multicast>( &mut self, e: &NetworkEvent, multicast: &MCAST, search: &SCK, ) -> Result<(), Error>

Notify the Engine of a network interface change

§Errors

Passes on errors from the underlying system-calls for joining (and leaving) multicast groups.

Source

pub fn advertise<SCK: TargetedSend>( &mut self, unique_service_name: String, advertisement: Advertisement, socket: &SCK, )

Advertise a local resource to SSDP peers

Source

pub fn deadvertise<SCK: TargetedSend>( &mut self, unique_service_name: &str, socket: &SCK, )

Withdraw an advertisement for a local resource

For instance, it is “polite” to call this if shutting down cleanly.

Auto Trait Implementations§

§

impl<CB, T> Freeze for Engine<CB, T>
where <T as Timebase>::Instant: Freeze,

§

impl<CB, T> RefUnwindSafe for Engine<CB, T>

§

impl<CB, T> Send for Engine<CB, T>
where <T as Timebase>::Instant: Send, CB: Send,

§

impl<CB, T> Sync for Engine<CB, T>
where <T as Timebase>::Instant: Sync, CB: Sync,

§

impl<CB, T> Unpin for Engine<CB, T>
where <T as Timebase>::Instant: Unpin, CB: Unpin,

§

impl<CB, T> UnwindSafe for Engine<CB, T>

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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V