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
sourceimpl Service
impl Service
sourcepub fn service_type(&self) -> &URN
pub fn service_type(&self) -> &URN
Returns the URN of this service.
sourcepub fn service_id(&self) -> &str
pub fn service_id(&self) -> &str
Returns the Service Identifier
.
sourcepub async fn action(
&self,
url: &Uri,
action: &str,
payload: &str
) -> Result<HashMap<String, String>, Error>
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);
sourcepub async fn subscribe(
&self,
url: &Uri,
timeout_secs: u32
) -> Result<(String, impl Stream<Item = Result<HashMap<String, String>, Error>>), Error>
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);
}
}
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Service
impl Send for Service
impl Sync for Service
impl Unpin for Service
impl UnwindSafe for Service
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more