]> code.delx.au - pulseaudio/blobdiff - src/modules/module-console-kit.c
Fix up according to Coding Style
[pulseaudio] / src / modules / module-console-kit.c
index 5a3975fb7d3db53f75e21bf3c07495fd09fe1c67..d52cc2448f6c3cdf307d02ae922e1a1c2c349b2b 100644 (file)
@@ -5,7 +5,7 @@
 
     PulseAudio is free software; you can redistribute it and/or modify
     it under the terms of the GNU Lesser General Public License as published
-    by the Free Software Foundation; either version 2 of the License,
+    by the Free Software Foundation; either version 2.1 of the License,
     or (at your option) any later version.
 
     PulseAudio is distributed in the hope that it will be useful, but
@@ -44,8 +44,8 @@
 #include <pulsecore/namereg.h>
 #include <pulsecore/core-scache.h>
 #include <pulsecore/modargs.h>
+#include <pulsecore/dbus-shared.h>
 
-#include "dbus-util.h"
 #include "module-console-kit-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering");
@@ -63,9 +63,11 @@ struct session {
 };
 
 struct userdata {
+    pa_module *module;
     pa_core *core;
     pa_dbus_connection *connection;
     pa_hashmap *sessions;
+    pa_bool_t filter_added;
 };
 
 static void add_session(struct userdata *u, const char *id) {
@@ -73,9 +75,9 @@ static void add_session(struct userdata *u, const char *id) {
     DBusMessage *m = NULL, *reply = NULL;
     uint32_t uid;
     struct session *session;
-    char *t;
+    pa_client_new_data data;
 
-    dbus_error_init (&error);
+    dbus_error_init(&error);
 
     if (pa_hashmap_get(u->sessions, id)) {
         pa_log_warn("Duplicate session %s, ignoring.", id);
@@ -94,6 +96,8 @@ static void add_session(struct userdata *u, const char *id) {
 
     /* CK 0.3 this changed from int32 to uint32 */
     if (!dbus_message_get_args(reply, &error, DBUS_TYPE_UINT32, &uid, DBUS_TYPE_INVALID)) {
+        dbus_error_free(&error);
+
         if (!dbus_message_get_args(reply, &error, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) {
             pa_log("Failed to parse GetUnixUser() result: %s: %s", error.name, error.message);
             goto fail;
@@ -107,11 +111,19 @@ static void add_session(struct userdata *u, const char *id) {
     session = pa_xnew(struct session, 1);
     session->id = pa_xstrdup(id);
 
-    t = pa_sprintf_malloc("ConsoleKit Session %s", id);
-    session->client = pa_client_new(u->core, __FILE__, t);
-    pa_xfree(t);
-
-    pa_proplist_sets(session->client->proplist, "console-kit.session", id);
+    pa_client_new_data_init(&data);
+    data.module = u->module;
+    data.driver = __FILE__;
+    pa_proplist_setf(data.proplist, PA_PROP_APPLICATION_NAME, "ConsoleKit Session %s", id);
+    pa_proplist_sets(data.proplist, "console-kit.session", id);
+    session->client = pa_client_new(u->core, &data);
+    pa_client_new_data_done(&data);
+
+    if (!session->client) {
+        pa_xfree(session->id);
+        pa_xfree(session);
+        goto fail;
+    }
 
     pa_hashmap_put(u->sessions, session->id, session);
 
@@ -167,6 +179,8 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, vo
 
         /* CK API changed to match spec in 0.3 */
         if (!dbus_message_get_args(message, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
+            dbus_error_free(&error);
+
             if (!dbus_message_get_args(message, &error, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID)) {
                 pa_log_error("Failed to parse SessionAdded message: %s: %s", error.name, error.message);
                 goto finish;
@@ -179,6 +193,8 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, vo
 
         /* CK API changed to match spec in 0.3 */
         if (!dbus_message_get_args(message, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
+            dbus_error_free(&error);
+
             if (!dbus_message_get_args(message, &error, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID)) {
                 pa_log_error("Failed to parse SessionRemoved message: %s: %s", error.name, error.message);
                 goto finish;
@@ -191,7 +207,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, vo
 finish:
     dbus_error_free(&error);
 
-    return DBUS_HANDLER_RESULT_HANDLED;
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
 static int get_session_list(struct userdata *u) {
@@ -285,8 +301,9 @@ int pa__init(pa_module*m) {
         goto fail;
     }
 
-    m->userdata = u = pa_xnew(struct userdata, 1);
+    m->userdata = u = pa_xnew0(struct userdata, 1);
     u->core = m->core;
+    u->module = m;
     u->connection = connection;
     u->sessions = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
 
@@ -295,8 +312,12 @@ int pa__init(pa_module*m) {
         goto fail;
     }
 
-    dbus_bus_add_match(pa_dbus_connection_get(connection), "type='signal',sender='org.freedesktop.ConsoleKit', interface='org.freedesktop.ConsoleKit.Seat'", &error);
-    if (dbus_error_is_set(&error)) {
+    u->filter_added = TRUE;
+
+    if (pa_dbus_add_matches(
+                pa_dbus_connection_get(connection), &error,
+                "type='signal',sender='org.freedesktop.ConsoleKit',interface='org.freedesktop.ConsoleKit.Seat',member='SessionAdded'",
+                "type='signal',sender='org.freedesktop.ConsoleKit',interface='org.freedesktop.ConsoleKit.Seat',member='SessionRemoved'", NULL) < 0) {
         pa_log_error("Unable to subscribe to ConsoleKit signals: %s: %s", error.name, error.message);
         goto fail;
     }
@@ -335,8 +356,17 @@ void pa__done(pa_module *m) {
         pa_hashmap_free(u->sessions, NULL, NULL);
     }
 
-    if (u->connection)
+    if (u->connection) {
+        pa_dbus_remove_matches(
+                pa_dbus_connection_get(u->connection),
+                "type='signal',sender='org.freedesktop.ConsoleKit',interface='org.freedesktop.ConsoleKit.Seat',member='SessionAdded'",
+                "type='signal',sender='org.freedesktop.ConsoleKit',interface='org.freedesktop.ConsoleKit.Seat',member='SessionRemoved'", NULL);
+
+        if (u->filter_added)
+            dbus_connection_remove_filter(pa_dbus_connection_get(u->connection), filter_cb, u);
+
         pa_dbus_connection_unref(u->connection);
+    }
 
     pa_xfree(u);
 }