Struct wemo::subscriptions::Subscriptions
[−]
[src]
pub struct Subscriptions { /* fields omitted */ }
Subscriptions objects manage Wemo device event notifications. You can register subscriptions against multiple devices; an Iron HTTP server will be started to receive callback notifications from the Wemo devices, and a background thread will handle subscription management. You should only ever need one of these objects.
Methods
impl Subscriptions
[src]
fn new(callback_port: u16, subscription_ttl_sec: u16) -> Self
CTOR. Set the callback port for the HTTP server that will be launched and the subscription TTL.
fn subscribe<F>(&self, host: &str, callback: F) -> Result<(), WemoError> where
F: Fn(Notification) + Sync + Send + 'static,
F: Fn(Notification) + Sync + Send + 'static,
Subscribe to push notifications from a Wemo device. The provided callback is invoked when notifications are received. This should be done after launching the server to avoid missing notifications.
fn unsubscribe(&self, host: &str) -> Result<(), WemoError>
Remove a subscription.
fn start_server(&mut self) -> Result<(), WemoError>
Start the HTTP server so it can begin receiving push notifications. A background thread to resubscribe will also be launched. Calling this function is nonblocking, but it returns a thread guard that will automatically join with the parent once it is dropped.
fn stop_server(&mut self) -> Result<(), WemoError>
Stop the HTTP server from running. Also stops resubscription process. Warning: This may not work the server from listening. See the following issue on Iron/Hyper: https://github.com/hyperium/hyper/issues/338