From 3b086167ae3c12ae7c907b2dec8a377d54652bb1 Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Thu, 7 May 2020 15:47:15 +0300
Subject: [PATCH] proxy: add _request_destroy() method for destroying remote
 objects

Useful to destroy links and endpoint-links
---
 lib/wp/proxy.c | 31 +++++++++++++++++++++++++++++++
 lib/wp/proxy.h |  3 +++
 2 files changed, 34 insertions(+)

diff --git a/lib/wp/proxy.c b/lib/wp/proxy.c
index 39e50c40..475a7b96 100644
--- a/lib/wp/proxy.c
+++ b/lib/wp/proxy.c
@@ -433,6 +433,7 @@ wp_proxy_class_init (WpProxyClass * klass)
       G_TYPE_NONE, 1, G_TYPE_STRING);
 }
 
+/* private */
 void
 wp_proxy_destroy (WpProxy *self)
 {
@@ -445,6 +446,36 @@ wp_proxy_destroy (WpProxy *self)
     pw_proxy_destroy (priv->pw_proxy);
 }
 
+/**
+ * wp_proxy_request_destroy:
+ * @self: the proxy
+ *
+ * Requests the PipeWire server to destroy the object represented by this proxy.
+ * If the server allows it, the object will be destroyed and the
+ * WpProxy::pw-proxy-destroyed signal will be emitted. If the server does
+ * not allow it, nothing will happen.
+ *
+ * This is mostly useful for destroying #WpLink and #WpEndpointLink objects.
+ */
+void
+wp_proxy_request_destroy (WpProxy * self)
+{
+  WpProxyPrivate *priv;
+  g_autoptr (WpCore) core = NULL;
+  WpRegistry *reg;
+
+  g_return_if_fail (WP_IS_PROXY (self));
+
+  priv = wp_proxy_get_instance_private (self);
+  core = wp_proxy_get_core (self);
+
+  if (priv->pw_proxy && core) {
+    reg = wp_core_get_registry (core);
+    pw_registry_destroy (reg->pw_registry,
+        pw_proxy_get_bound_id (priv->pw_proxy));
+  }
+}
+
 void
 wp_proxy_augment (WpProxy * self,
     WpProxyFeatures ft_wanted, GCancellable * cancellable,
diff --git a/lib/wp/proxy.h b/lib/wp/proxy.h
index 04498dba..98b7f8ec 100644
--- a/lib/wp/proxy.h
+++ b/lib/wp/proxy.h
@@ -98,6 +98,9 @@ struct _WpProxyClass
   void (*control_changed) (WpProxy * self, const char * id_name);
 };
 
+WP_API
+void wp_proxy_request_destroy (WpProxy * self);
+
 /* features API */
 
 WP_API
-- 
GitLab