Struct RustmoServer

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

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.

Implementations§

Source§

impl RustmoServer

Source

pub fn new(interface: Ipv4Addr) -> Self

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

Source

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

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

Source

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

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

Source

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

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

Source

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,

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

Source

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

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§

Source§

impl Drop for RustmoServer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Err>

Source§

impl<T> Typeable for T
where T: Any,

Source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
Source§

impl<T> ErasedDestructor for T
where T: 'static,