pub struct ManagedSubscription { /* private fields */ }Expand description
A managed UPnP subscription with lifecycle management
This struct wraps the low-level subscription operations and provides:
- Expiration tracking
- Manual renewal with proper state updates
- Proper cleanup on drop
- Thread-safe state management
§Example
use sonos_api::{SonosClient, Service};
let client = SonosClient::new();
let subscription = client.create_managed_subscription(
"192.168.1.100",
Service::AVTransport,
"http://192.168.1.50:8080/callback",
1800
)?;
// Check if renewal is needed
if subscription.needs_renewal() {
subscription.renew()?;
}
// Clean up when done
subscription.unsubscribe()?;Implementations§
Source§impl ManagedSubscription
impl ManagedSubscription
Sourcepub fn subscription_id(&self) -> &str
pub fn subscription_id(&self) -> &str
Get the subscription ID
Sourcepub fn needs_renewal(&self) -> bool
pub fn needs_renewal(&self) -> bool
Check if the subscription needs renewal
Returns true if the subscription is active and will expire within the renewal threshold (5 minutes by default).
Sourcepub fn time_until_renewal(&self) -> Option<Duration>
pub fn time_until_renewal(&self) -> Option<Duration>
Get the time until renewal is needed
Returns Some(duration) if renewal is needed within the threshold,
None if renewal is not needed or subscription is inactive.
Sourcepub fn expires_at(&self) -> SystemTime
pub fn expires_at(&self) -> SystemTime
Get when the subscription expires
Sourcepub fn renew(&self) -> Result<()>
pub fn renew(&self) -> Result<()>
Manually renew the subscription
This sends a renewal request to the device and updates the internal expiration time based on the response.
§Returns
Ok(()) if renewal succeeded, Err(ApiError) if it failed.
§Errors
ApiError::SubscriptionExpiredif the subscription has already expired- Network or device errors from the renewal request
Sourcepub fn unsubscribe(&self) -> Result<()>
pub fn unsubscribe(&self) -> Result<()>
Unsubscribe and clean up the subscription
This sends an unsubscribe request to the device and marks the subscription as inactive. After calling this method, the subscription should not be used for any further operations.
§Returns
Ok(()) if unsubscribe succeeded, Err(ApiError) if it failed.
Note that the subscription is marked inactive regardless of the result.