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
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 !Freeze for Service
impl RefUnwindSafe for Service
impl Send for Service
impl Sync for Service
impl Unpin for Service
impl UnwindSafe for Service
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more