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>
impl<CB: Callback, T: Timebase> Engine<CB, T>
Sourcepub fn new(random_seed: u32, now: T::Instant) -> Self
pub fn new(random_seed: u32, now: T::Instant) -> Self
Create a new Engine, parameterised by callback type
Sourcepub fn handle_timeout<SCK: TargetedSend>(
&mut self,
socket: &SCK,
now: T::Instant,
)
pub fn handle_timeout<SCK: TargetedSend>( &mut self, socket: &SCK, now: T::Instant, )
Deal with any expired timeouts
Sourcepub fn poll_timeout(&self) -> T::Instant
pub fn poll_timeout(&self) -> T::Instant
Obtain the desired delay before the next call to handle_timeout
Sourcepub fn reset_refresh_timer(&mut self, now: T::Instant)
pub fn reset_refresh_timer(&mut self, now: T::Instant)
Reset the refresh timer (e.g. if network has gone away and come back)
Sourcepub fn refresh<SCK: TargetedSend>(&mut self, socket: &SCK)
pub fn refresh<SCK: TargetedSend>(&mut self, socket: &SCK)
Re-send all announcements
Sourcepub fn subscribe<SCK: TargetedSend>(
&mut self,
notification_type: String,
callback: CB,
socket: &SCK,
)
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.
Sourcepub fn on_data(
&mut self,
buf: &[u8],
wasto: IpAddr,
wasfrom: SocketAddr,
now: T::Instant,
)
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
Sourcepub fn on_new_link_event<SCK: TargetedSend, MCAST: Multicast>(
&mut self,
ix: &InterfaceIndex,
flags: &Flags,
multicast: &MCAST,
search: &SCK,
) -> Result<(), Error>
pub fn on_new_link_event<SCK: TargetedSend, MCAST: Multicast>( &mut self, ix: &InterfaceIndex, flags: &Flags, multicast: &MCAST, search: &SCK, ) -> Result<(), Error>
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.
Sourcepub fn on_del_link_event<MCAST: Multicast>(
&mut self,
ix: &InterfaceIndex,
multicast: &MCAST,
) -> Result<(), Error>
pub fn on_del_link_event<MCAST: Multicast>( &mut self, ix: &InterfaceIndex, multicast: &MCAST, ) -> Result<(), Error>
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.
Sourcepub fn on_new_addr_event<SCK: TargetedSend>(
&mut self,
ix: &InterfaceIndex,
addr: &IpAddr,
search: &SCK,
)
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.
Sourcepub fn on_del_addr_event(&mut self, ix: &InterfaceIndex, addr: &IpAddr)
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.
Sourcepub fn on_network_event<SCK: TargetedSend, MCAST: Multicast>(
&mut self,
e: &NetworkEvent,
multicast: &MCAST,
search: &SCK,
) -> Result<(), Error>
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.
Sourcepub fn advertise<SCK: TargetedSend>(
&mut self,
unique_service_name: String,
advertisement: Advertisement,
socket: &SCK,
)
pub fn advertise<SCK: TargetedSend>( &mut self, unique_service_name: String, advertisement: Advertisement, socket: &SCK, )
Advertise a local resource to SSDP peers
Sourcepub fn deadvertise<SCK: TargetedSend>(
&mut self,
unique_service_name: &str,
socket: &SCK,
)
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.