dbus2 / zbus-old

Rust D-Bus crate.
https://gitlab.freedesktop.org/dbus/zbus
Other
49 stars 13 forks source link

Add Proxy owner changed stream #236

Closed zeenix closed 1 year ago

zeenix commented 2 years ago

In GitLab by @elmarco on Dec 16, 2021, 21:50

This would be useful to track when a proxy got disconnected or reconnected from the destination.

Something like that should be fine, however future streams give me some headache, help welcome:


pub type OwnerChangedStream = FIXME;

    /// Get a stream to receive destination owner changed events.
    pub async fn receive_owner_changed(&self) -> Result<OwnerChangedStream> {
        use futures_util::StreamExt;
        use std::future::ready;

        let dbus_proxy = fdo::DBusProxy::builder(self.connection())
            .cache_properties(CacheProperties::No)
            .build()
            .await?;
        let proxy = self.clone();
        Ok(dbus_proxy
            .receive_name_owner_changed()
            .await?
            .filter_map(|signal| {
                let args = signal.args().unwrap();

                if args.name() != proxy.destination() {
                    return ready(None);
                }

                ready(Some(args.new_owner))
            }))
    }
zeenix commented 2 years ago

mentioned in commit 80aa4b6b93e97e89766609071cc9161a03098028