[pulseaudio-discuss] [PATCH v1 1/2] reserve: Add support for private D-Bus connections

Mikel Astiz mikel.astiz.oss at gmail.com
Tue Jan 29 01:33:36 PST 2013


From: Mikel Astiz <mikel.astiz at bmw-carit.de>

Extend the reserve-monitor API with a registration mechanism to keep
track of existing private connections. This is necessary because the
monitor should not consider it busy if a device has been owned by us.
---
 src/modules/reserve-monitor.c | 29 +++++++++++++++++++++++++----
 src/modules/reserve-monitor.h |  7 +++++++
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/src/modules/reserve-monitor.c b/src/modules/reserve-monitor.c
index efd24eb..8942de1 100644
--- a/src/modules/reserve-monitor.c
+++ b/src/modules/reserve-monitor.c
@@ -41,6 +41,7 @@ struct rm_monitor {
 	char *match;
 
 	DBusConnection *connection;
+	DBusConnection *rd_private_bus;
 
 	unsigned busy:1;
 	unsigned filtering:1;
@@ -60,7 +61,7 @@ struct rm_monitor {
 	"arg0='%s'"
 
 static unsigned get_busy(
-	DBusConnection *c,
+	rm_monitor *m,
 	const char *name_owner) {
 
 	const char *un;
@@ -69,7 +70,12 @@ static unsigned get_busy(
 		return FALSE;
 
 	/* If we ourselves own the device, then don't consider this 'busy' */
-	if ((un = dbus_bus_get_unique_name(c)))
+	if ((un = dbus_bus_get_unique_name(m->connection)))
+		if (strcmp(name_owner, un) == 0)
+			return FALSE;
+
+	/* Similarly, check if the rd_device owns it */
+	if (m->rd_private_bus && (un = dbus_bus_get_unique_name(m->rd_private_bus)))
 		if (strcmp(name_owner, un) == 0)
 			return FALSE;
 
@@ -104,7 +110,7 @@ static DBusHandlerResult filter_handler(
 		if (strcmp(name, m->service_name) == 0) {
 			unsigned old_busy = m->busy;
 
-			m->busy = get_busy(c, new);
+			m->busy = get_busy(m, new);
 
 			if (m->busy != old_busy && m->change_cb) {
 				m->ref++;
@@ -246,7 +252,7 @@ int rm_watch(
 	if ((r = get_name_owner(m->connection, m->service_name, &name_owner, error)) < 0)
 		goto fail;
 
-	m->busy = get_busy(m->connection, name_owner);
+	m->busy = get_busy(m, name_owner);
 	free(name_owner);
 
 	*_m = m;
@@ -290,6 +296,9 @@ void rm_release(rm_monitor *m) {
 	if (m->connection)
 		dbus_connection_unref(m->connection);
 
+	if (m->rd_private_bus)
+		dbus_connection_unref(m->rd_private_bus);
+
 	free(m);
 }
 
@@ -320,3 +329,15 @@ void* rm_get_userdata(rm_monitor *m) {
 
 	return m->userdata;
 }
+
+void rm_set_rd_private_bus(rm_monitor *m, DBusConnection *c) {
+
+	if (!m)
+		return;
+
+	if (m->rd_private_bus)
+		dbus_connection_unref(m->rd_private_bus);
+
+	if ((m->rd_private_bus = c))
+		dbus_connection_ref(c);
+}
diff --git a/src/modules/reserve-monitor.h b/src/modules/reserve-monitor.h
index 85a7ebb..3823e99 100644
--- a/src/modules/reserve-monitor.h
+++ b/src/modules/reserve-monitor.h
@@ -64,6 +64,13 @@ void rm_set_userdata(rm_monitor *m, void *userdata);
  * userdata was set. */
 void* rm_get_userdata(rm_monitor *m);
 
+/* Registration of the D-Bus connection used by the corresponding rd_device
+ * object. If you create a new DBusConnection for each rd_device (as you
+ * should do, in order to avoid problems with leaked NameLost signals), use
+ * this function to let rm_monitor know about it, so that it can track the
+ * busy status accurately. */
+void rm_set_rd_private_bus(rm_monitor *m, DBusConnection *c);
+
 #ifdef __cplusplus
 }
 #endif
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list