[][src]Struct rupnp::Service

pub struct Service { /* fields omitted */ }

A UPnP Service is the description of endpoints on a device for performing actions and reading the service definition. For a list of actions and state variables the service provides, take a look at scpd.

Implementations

impl Service[src]

pub fn service_type(&self) -> &URN[src]

Returns the URN of this service.

pub fn service_id(&self) -> &str[src]

Returns the Service Identifier.

pub async fn scpd<'_, '_>(&'_ self, url: &'_ Uri) -> Result<SCPD, Error>[src]

Fetches the SCPD of this service.

pub async fn action<'_, '_, '_, '_>(
    &'_ self,
    url: &'_ Uri,
    action: &'_ str,
    payload: &'_ str
) -> Result<HashMap<String, String>, Error>
[src]

Execute some UPnP Action on this service. The URL is usually obtained by the device this service was found on. The payload is xml-formatted data.

Example usage:

use rupnp::ssdp::URN;
use rupnp::Device;

let urn = URN::service("schemas-upnp-org", "RenderingControl", 1);

let device = Device::from_url( some_url ).await?;
let service = device.find_service(&urn)
    .expect("service exists");

let args = "<InstanceID>0</InstanceID><Channel>Master</Channel>";
let response = service.action(device.url(), "GetVolume", args).await?;

let volume = response
    .get("CurrentVolume")
    .expect("exists");

println!("Volume: {}", volume);

pub async fn subscribe<'_, '_>(
    &'_ self,
    url: &'_ Uri,
    timeout_secs: u32
) -> Result<(String, impl Stream<Item = Result<HashMap<String, String>, Error>>), Error>
[src]

Subscribe for state variable changes.

It returns the SID which can be used to unsubscribe to the service and a stream of responses.

Each response is a HashMap of the state variables.

Example usage:

let (_sid, stream) = service.subscribe(device.url(), 300).await?;

while let Some(state_vars) = stream.try_next().await? {
    for (key, value) in state_vars {
        println!("{} => {}", key, value);
    }
}

pub async fn renew_subscription<'_, '_, '_>(
    &'_ self,
    url: &'_ Uri,
    sid: &'_ str,
    timeout_secs: u32
) -> Result<(), Error>
[src]

Renew a subscription made with the subscribe method.

When the sid is invalid, the control point will respond with a 412 Preconditition failed.

pub async fn unsubscribe<'_, '_, '_>(
    &'_ self,
    url: &'_ Uri,
    sid: &'_ str
) -> Result<(), Error>
[src]

Unsubscribe from further event notifications.

The SID is usually obtained by the subscribe method.

When the sid is invalid, the control point will respond with a 412 Preconditition failed.

Trait Implementations

impl Clone for Service[src]

impl Debug for Service[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

impl<T> Instrument for T[src]

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

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.