]> code.delx.au - pulseaudio/blobdiff - src/modules/reserve-monitor.c
alsa: Log some output if we disable tsched for BATCH devices
[pulseaudio] / src / modules / reserve-monitor.c
index 4097a6f091ed26f37ecac48be4fc05253c0db80a..70de870ac95e00b1b0a883818d758b5ed5324263 100644 (file)
@@ -32,6 +32,7 @@
 #include <assert.h>
 
 #include "reserve-monitor.h"
+#include "reserve.h"
 
 struct rm_monitor {
        int ref;
@@ -59,6 +60,23 @@ struct rm_monitor {
        "member='NameOwnerChanged',"            \
        "arg0='%s'"
 
+static unsigned get_busy(
+       DBusConnection *c,
+       const char *name_owner) {
+
+       const char *un;
+
+       if (!name_owner || !*name_owner)
+               return FALSE;
+
+       /* If we ourselves own the device, then don't consider this 'busy' */
+       if ((un = dbus_bus_get_unique_name(c)))
+               if (strcmp(name_owner, un) == 0)
+                       return FALSE;
+
+       return TRUE;
+}
+
 static DBusHandlerResult filter_handler(
        DBusConnection *c,
        DBusMessage *s,
@@ -87,16 +105,7 @@ static DBusHandlerResult filter_handler(
                if (strcmp(name, m->service_name) == 0) {
                        unsigned old_busy = m->busy;
 
-                       m->busy = !!(new && *new);
-
-                       /* If we ourselves own the device, then don't consider this 'busy' */
-                       if (m->busy) {
-                               const char *un;
-
-                               if ((un = dbus_bus_get_unique_name(c)))
-                                       if (strcmp(new, un) == 0)
-                                               m->busy = FALSE;
-                       }
+                       m->busy = get_busy(c, new);
 
                        if (m->busy != old_busy && m->change_cb) {
                                m->ref++;
@@ -115,11 +124,12 @@ invalid:
 int rm_watch(
        rm_monitor **_m,
        DBusConnection *connection,
-       const char*device_name,
+       const char *device_name,
        rm_change_cb_t change_cb,
        DBusError *error)  {
 
        rm_monitor *m = NULL;
+       char *name_owner;
        int r;
        DBusError _error;
 
@@ -178,12 +188,11 @@ int rm_watch(
 
        m->matching = 1;
 
-       m->busy = dbus_bus_name_has_owner(m->connection, m->service_name, error);
-
-       if (dbus_error_is_set(error)) {
-               r = -EIO;
+       if ((r = rd_dbus_get_name_owner(m->connection, m->service_name, &name_owner, error)) < 0)
                goto fail;
-       }
+
+       m->busy = get_busy(m->connection, name_owner);
+       free(name_owner);
 
        *_m = m;
        return 0;