Struct rupnp::Service

source ·
pub struct Service { /* private fields */ }
Expand description

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§

source§

impl Service

source

pub fn service_type(&self) -> &URN

Returns the URN of this service.

source

pub fn service_id(&self) -> &str

Returns the Service Identifier.

source

pub async fn scpd(&self, url: &Uri) -> Result<SCPD, Error>

Fetches the SCPD of this service.

source

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

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);
source

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

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);
    }
}
source

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

Renew a subscription made with the subscribe method.

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

source

pub async fn unsubscribe(&self, url: &Uri, sid: &str) -> Result<(), Error>

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§

source§

impl Clone for Service

source§

fn clone(&self) -> Service

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Service

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more