[][src]Struct rustmo_server::RustmoServer

pub struct RustmoServer { /* fields omitted */ }

Create a RustmoServer and add devices to make them discoverable, and controllable via Alexa.

Each VirtualDevice you wish to expose requires a backing HTTP server (Rustmo takes care of this for you). This is the reason why the various ::add_xxx_device() methods require a port number.

Note that each device must be assigned a unique port number.

RustmoServer also creates a multicast UDP socket listener to implement the SSDP-based device discovery protocol required by Alexa -- this listens on port 1900.

Methods

impl RustmoServer[src]

pub fn new(interface: Ipv4Addr) -> Self[src]

Create a new RustmoServer and listen for SSDP requests on the specified network interface

pub fn add_device<T: VirtualDevice>(
    &mut self,
    name: &str,
    port: u16,
    virtual_device: T
) -> Result<WrappedVirtualDevice, RustmoError>
[src]

Add a VirtualDevice to make it discoverable and controllable.

@name: The word or phrase you'll use when talking to Alexa to control this device @port: The port on which the backing HTTP server will listen for UPNP requests @virtual_device: A VirtualDevice implementation

pub fn add_polling_device<T: VirtualDevice>(
    &mut self,
    name: &str,
    port: u16,
    virtual_device: T
) -> Result<WrappedVirtualDevice, RustmoError>
[src]

Add a VirtualDevice to make it discoverable and controllable.

This version wraps the provided VirtualDevice such that it will poll (via ::check_is_on()), up to 4 seconds, whenever ::turn_on() or ::turn_off() is called.

This form is useful when controlling a physical device that takes a few seconds (but less than 5) for its state to register as changed.

@name: The word or phrase you'll use when talking to Alexa to control this device @port: The port on which the backing HTTP server will listen for UPNP requests @virtual_device: A VirtualDevice implementation

pub fn add_instant_on_device<T: VirtualDevice>(
    &mut self,
    name: &str,
    port: u16,
    virtual_device: T
) -> Result<WrappedVirtualDevice, RustmoError>
[src]

Add a VirtualDevice to make it discoverable and controllable.

This version wraps the provided VirtualDevice and pretends that the ::turn_on() and ::turn_off() calls happen immediately.

This form is useful when controlling a physical device that takes more than 5 seconds for its state to register as changed but is otherwise "guaranteed" to eventually happen.

The implementation detail here is that calls to ::check_is_on() will lie and return "ON" after a call to ::turn_on() until your underlying implementation for ::check_is_on() actually does return "ON".

@name: The word or phrase you'll use when talking to Alexa to control this device @port: The port on which the backing HTTP server will listen for UPNP requests @virtual_device: A VirtualDevice implementation

pub fn add_functional_device<TurnOn, TurnOff, CheckIsOn>(
    &mut self,
    name: &str,
    port: u16,
    turn_on: TurnOn,
    turn_off: TurnOff,
    check_is_on: CheckIsOn
) -> Result<WrappedVirtualDevice, RustmoError> where
    TurnOn: FnMut() -> Result<VirtualDeviceState, VirtualDeviceError> + Sync + Send + 'static,
    TurnOff: FnMut() -> Result<VirtualDeviceState, VirtualDeviceError> + Sync + Send + 'static,
    CheckIsOn: FnMut() -> Result<VirtualDeviceState, VirtualDeviceError> + Sync + Send + 'static, 
[src]

Add an anonymous device to make it discoverable and controllable.

This version allows for the anonymous implementation of a device.

@name: The word or phrase you'll use when talking to Alexa to control this device @port: The port on which the backing HTTP server will listen for UPNP requests @turn_on: A closure that knows how to turn the device on @turn_off: A closure that knows how to turn the device off @check_is_on: A closure that knows how to determine if the device is on or off

pub fn add_device_group(
    &mut self,
    name: &str,
    port: u16,
    devices: Vec<WrappedVirtualDevice>
) -> Result<WrappedVirtualDevice, RustmoError>
[src]

Add a device that is a composite of multiple other devices.

This is useful if you wish to create a "Living Room Lights" device ("Alexa, turn on Living Roomt Lights"), that necessitates controlling multiple other devices that you've already added because they can also be controlled independently.

Note that communication with the list of devices in a device group happens in parallel, so make sure you don't have any kind of state dependencies between devices.

An example of this might be turning a receiver on (one device) and changing its input to "DVD". The receiver would need to be guaranteed "on" before its input source can be changed and this function does not guarantee that.

@name: The word or phrase you'll use when talking to Alexa to control this device @port: The port on which the backing HTTP server will listen for UPNP requests @devices: A vector of WrappedVirtualDevice instances that have previously been added to this RustmoServer

Trait Implementations

impl Drop for RustmoServer[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> Typeable for T where
    T: Any

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

type Err = <U as TryFrom<T>>::Err