Skip to main content

ManagedSubscription

Struct ManagedSubscription 

Source
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

Source

pub fn subscription_id(&self) -> &str

Get the subscription ID

Source

pub fn is_active(&self) -> bool

Check if the subscription is still active and not expired

Source

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).

Source

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.

Source

pub fn expires_at(&self) -> SystemTime

Get when the subscription expires

Source

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::SubscriptionExpired if the subscription has already expired
  • Network or device errors from the renewal request
Source

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.

Trait Implementations§

Source§

impl Debug for ManagedSubscription

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for ManagedSubscription

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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, U> Into<U> for T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.