This email list is read-only.  Emails sent to this list will be discarded
----------------------------------
 gdbus/gdbus.h        |   10 +++-
 gdbus/mainloop.c     |    4 +-
 gdbus/watch.c        |   60 ++++++++++++++++--------
 plugins/bluetooth.c  |  124 ++++++++++++--------------------------------------
 plugins/supplicant.c |   12 +----
 plugins/supplicant.h |    2 +-
 plugins/wifi.c       |   35 +++++++++++++-
 src/agent.c          |    2 +-
 src/main.c           |    2 +-
 9 files changed, 116 insertions(+), 135 deletions(-)

New commits:
commit 176fe9f20467f7c4bd493c437d6e9d5acd2ebb48
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Fri Oct 17 22:10:02 2008 +0200

    Add watch for monitoring wpa_supplicant

commit 19e56a613e70233a2e07217745dbf93b041c0b53
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Fri Oct 17 19:34:57 2008 +0200

    Let the Bluetooth plugin listen on service changes

commit 3a3a82ac1e3f16fe7b8d582bcce968921ecad8c3
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Fri Oct 17 19:29:35 2008 +0200

    Fix disconnect callback declaration

commit 9fed97d6e749e022976d5a56a65f548ea17ce429
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Fri Oct 17 19:14:25 2008 +0200

    Add g_dbus_add_service_watch() implementation

commit f9074a6cd08a45628e2c20d14a70aa1698de01b8
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Fri Oct 17 18:34:18 2008 +0200

    Fix agent disconnect callback declaration

commit 0fe3d5e4406c2c086a2fa3f5ae695d187eb03ead
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Fri Oct 17 18:31:50 2008 +0200

    Fix connection disconnect function

commit ae470f3badc8e832f21b946c82eec97e4104fd36
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Fri Oct 17 18:26:13 2008 +0200

    Change declaration of GDBusWatchFunction


Diff in this email is a maximum of 400 lines.
diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index b44bc86..818a36f 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -31,7 +31,8 @@ extern "C" {
 #include <dbus/dbus.h>
 #include <glib.h>
 
-typedef void (* GDBusWatchFunction) (void *user_data);
+typedef void (* GDBusWatchFunction) (DBusConnection *connection,
+                                                       void *user_data);
 
 typedef gboolean (* GDBusSignalFunction) (DBusConnection *connection,
                                        DBusMessage *message, void *user_data);
@@ -116,8 +117,11 @@ gboolean g_dbus_emit_signal_valist(DBusConnection 
*connection,
                                const char *path, const char *interface,
                                const char *name, int type, va_list args);
 
-guint g_dbus_add_disconnect_watch(DBusConnection *connection,
-                               const char *name,
+guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
+                               GDBusWatchFunction connect,
+                               GDBusWatchFunction disconnect,
+                               void *user_data, GDBusDestroyFunction destroy);
+guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
                                GDBusWatchFunction function,
                                void *user_data, GDBusDestroyFunction destroy);
 guint g_dbus_add_signal_watch(DBusConnection *connection,
diff --git a/gdbus/mainloop.c b/gdbus/mainloop.c
index b50d83c..d38bd63 100644
--- a/gdbus/mainloop.c
+++ b/gdbus/mainloop.c
@@ -60,7 +60,7 @@ struct server_info {
 };
 
 struct disconnect_data {
-       void (*disconnect_cb)(void *);
+       GDBusWatchFunction disconnect_cb;
        void *user_data;
 };
 
@@ -72,8 +72,8 @@ static DBusHandlerResult disconnect_filter(DBusConnection 
*conn,
        if (dbus_message_is_signal(msg,
                        DBUS_INTERFACE_LOCAL, "Disconnected") == TRUE) {
                error("Got disconnected from the system message bus");
+               dc_data->disconnect_cb(conn, dc_data->user_data);
                dbus_connection_unref(conn);
-               dc_data->disconnect_cb(dc_data->user_data);
        }
 
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
diff --git a/gdbus/watch.c b/gdbus/watch.c
index fb0bef3..ec3be64 100644
--- a/gdbus/watch.c
+++ b/gdbus/watch.c
@@ -41,7 +41,8 @@ static guint listener_id = 0;
 static GSList *name_listeners = NULL;
 
 struct name_callback {
-       GDBusWatchFunction func;
+       GDBusWatchFunction conn_func;
+       GDBusWatchFunction disc_func;
        void *user_data;
        guint id;
 };
@@ -73,14 +74,13 @@ static struct name_data *name_data_find(DBusConnection 
*connection,
        return NULL;
 }
 
-static struct name_callback *name_callback_find(GSList *callbacks,
-                                       GDBusWatchFunction func, void 
*user_data)
+static struct name_callback *name_callback_find(GSList *callbacks, guint id)
 {
        GSList *current;
 
        for (current = callbacks; current != NULL; current = current->next) {
                struct name_callback *cb = current->data;
-               if (cb->func == func && cb->user_data == user_data)
+               if (cb->id == id)
                        return cb;
        }
 
@@ -93,8 +93,8 @@ static void name_data_call_and_free(struct name_data *data)
 
        for (l = data->callbacks; l != NULL; l = l->next) {
                struct name_callback *cb = l->data;
-               if (cb->func)
-                       cb->func(cb->user_data);
+               if (cb->disc_func)
+                       cb->disc_func(data->connection, cb->user_data);
                g_free(cb);
        }
 
@@ -116,7 +116,9 @@ static void name_data_free(struct name_data *data)
 }
 
 static int name_data_add(DBusConnection *connection, const char *name,
-                               GDBusWatchFunction func, void *user_data, guint 
id)
+                                               GDBusWatchFunction connect,
+                                               GDBusWatchFunction disconnect,
+                                               void *user_data, guint id)
 {
        int first = 1;
        struct name_data *data = NULL;
@@ -124,7 +126,8 @@ static int name_data_add(DBusConnection *connection, const 
char *name,
 
        cb = g_new(struct name_callback, 1);
 
-       cb->func = func;
+       cb->conn_func = connect;
+       cb->disc_func = disconnect;
        cb->user_data = user_data;
        cb->id = id;
 
@@ -147,7 +150,7 @@ done:
 }
 
 static void name_data_remove(DBusConnection *connection,
-                       const char *name, GDBusWatchFunction func, void 
*user_data)
+                                       const char *name, guint id)
 {
        struct name_data *data;
        struct name_callback *cb = NULL;
@@ -156,7 +159,7 @@ static void name_data_remove(DBusConnection *connection,
        if (!data)
                return;
 
-       cb = name_callback_find(data->callbacks, func, user_data);
+       cb = name_callback_find(data->callbacks, id);
        if (cb) {
                data->callbacks = g_slist_remove(data->callbacks, cb);
                g_free(cb);
@@ -220,6 +223,7 @@ static DBusHandlerResult name_exit_filter(DBusConnection 
*connection,
        GSList *l;
        struct name_data *data;
        char *name, *old, *new;
+       int keep = 0;
 
        if (!dbus_message_is_signal(message, DBUS_INTERFACE_DBUS,
                                                        "NameOwnerChanged"))
@@ -234,10 +238,6 @@ static DBusHandlerResult name_exit_filter(DBusConnection 
*connection,
                return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
        }
 
-       /* We are not interested of service creations */
-       if (*new != '\0')
-               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
        data = name_data_find(connection, name);
        if (!data) {
                error("Got NameOwnerChanged signal for %s which has no 
listeners", name);
@@ -246,9 +246,20 @@ static DBusHandlerResult name_exit_filter(DBusConnection 
*connection,
 
        for (l = data->callbacks; l != NULL; l = l->next) {
                struct name_callback *cb = l->data;
-               cb->func(cb->user_data);
+               if (*new == '\0') {
+                       if (cb->disc_func)
+                               cb->disc_func(connection, cb->user_data);
+               } else {
+                       if (cb->conn_func)
+                               cb->conn_func(connection, cb->user_data);
+               }
+               if (cb->conn_func && cb->disc_func)
+                       keep = 1;
        }
 
+       if (keep)
+               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
        name_listeners = g_slist_remove(name_listeners, data);
        name_data_free(data);
 
@@ -257,9 +268,9 @@ static DBusHandlerResult name_exit_filter(DBusConnection 
*connection,
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
-guint g_dbus_add_disconnect_watch(DBusConnection *connection,
-                               const char *name,
-                               GDBusWatchFunction func,
+guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
+                               GDBusWatchFunction connect,
+                               GDBusWatchFunction disconnect,
                                void *user_data, GDBusDestroyFunction destroy)
 {
        int first;
@@ -273,7 +284,8 @@ guint g_dbus_add_disconnect_watch(DBusConnection 
*connection,
        }
 
        listener_id++;
-       first = name_data_add(connection, name, func, user_data, listener_id);
+       first = name_data_add(connection, name, connect, disconnect,
+                                               user_data, listener_id);
        /* The filter is already added if this is not the first callback
         * registration for the name */
        if (!first)
@@ -283,7 +295,7 @@ guint g_dbus_add_disconnect_watch(DBusConnection 
*connection,
                debug("name_listener_add(%s)", name);
 
                if (!add_match(connection, name)) {
-                       name_data_remove(connection, name, func, user_data);
+                       name_data_remove(connection, name, listener_id);
                        return 0;
                }
        }
@@ -291,6 +303,14 @@ guint g_dbus_add_disconnect_watch(DBusConnection 
*connection,
        return listener_id;
 }
 
+guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
+                               GDBusWatchFunction func,
+                               void *user_data, GDBusDestroyFunction destroy)
+{
+       return g_dbus_add_service_watch(connection, name, NULL, func,
+                                                       user_data, destroy);
+}
+
 guint g_dbus_add_signal_watch(DBusConnection *connection,
                                const char *rule, GDBusSignalFunction function,
                                void *user_data, GDBusDestroyFunction destroy)
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 2d0d7ad..d519ac9 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -23,114 +23,47 @@
 #include <config.h>
 #endif
 
+#include <errno.h>
+
 #include <gdbus.h>
 
 #include <connman/plugin.h>
-#include <connman/driver.h>
+#include <connman/device.h>
 #include <connman/log.h>
 
 #define BLUEZ_SERVICE "org.bluez"
 
-#define MANAGER_INTERFACE "org.bluez.Manager"
-#define MANAGER_PATH "/"
-
-static GStaticMutex element_mutex = G_STATIC_MUTEX_INIT;
-static GSList *element_list = NULL;
-
-static void create_element(DBusConnection *conn, const char *path)
+static int bluetooth_probe(struct connman_device *device)
 {
-       struct connman_element *element;
-
-       DBG("conn %p path %s", conn, path);
-
-       element = connman_element_create(NULL);
+       DBG("device %p", device);
 
-       element->name = g_path_get_basename(path);
-       element->type = CONNMAN_ELEMENT_TYPE_DEVICE;
-       element->subtype = CONNMAN_ELEMENT_SUBTYPE_BLUETOOTH;
-
-       g_static_mutex_lock(&element_mutex);
-
-       connman_element_register(element, NULL);
-
-       element_list = g_slist_append(element_list, element);
-
-       g_static_mutex_unlock(&element_mutex);
+       return 0;
 }
 
-static gboolean bluetooth_signal(DBusConnection *conn,
-                                       DBusMessage *msg, void *data)
+static void bluetooth_remove(struct connman_device *device)
 {
-       const char *sender, *interface, *member;
-
-       DBG("conn %p msg %p", conn, msg);
-
-       sender = dbus_message_get_sender(msg);
-       interface = dbus_message_get_interface(msg);
-       member = dbus_message_get_member(msg);
-
-       DBG("sender %s name %s.%s", sender, interface, member);
-
-       return TRUE;
+       DBG("device %p", device);
 }
 
-static void list_adapters(DBusConnection *conn)
-{
-       DBusMessage *msg, *reply;
-       char **paths = NULL;
-       int i, num = 0;
-
-       DBG("conn %p");
-
-       msg = dbus_message_new_method_call(BLUEZ_SERVICE, MANAGER_PATH,
-                                       MANAGER_INTERFACE, "ListAdapters");
-       if (!msg) {
-               connman_error("ListAdpaters message alloction failed");
-               return;
-       }
-
-       reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, NULL);
-
-       dbus_message_unref(msg);
-
-       if (!reply) {
-               connman_error("ListAdapters method call failed");
-               return;
-       }
-
-       dbus_message_get_args(reply, NULL, DBUS_TYPE_ARRAY, 
DBUS_TYPE_OBJECT_PATH,
-                                               &paths, &num, 
DBUS_TYPE_INVALID);
-
-       for (i = 0; i < num; i++)
-               create_element(conn, paths[i]);
-
-       g_strfreev(paths);
-
-       dbus_message_unref(reply);
-}
+static struct connman_device_driver bluetooth_driver = {
+       .name   = "bluetooth",
+       .type   = CONNMAN_DEVICE_TYPE_BLUETOOTH,
+       .probe  = bluetooth_probe,
+       .remove = bluetooth_remove,
+};
 
-static int bluetooth_probe(struct connman_element *element)
+static void bluetooth_connect(DBusConnection *connection, void *user_data)
 {
-       DBG("element %p name %s", element, element->name);
-
-       return 0;
+       DBG("connection %p", connection);
 }
 
-static void bluetooth_remove(struct connman_element *element)
+static void bluetooth_disconnect(DBusConnection *connection, void *user_data)
 {
-       DBG("element %p name %s", element, element->name);
+       DBG("connection %p", connection);
 }
 
-static struct connman_driver bluetooth_driver = {
-       .name           = "bluetooth",
-       .type           = CONNMAN_ELEMENT_TYPE_DEVICE,
-       .subtype        = CONNMAN_ELEMENT_SUBTYPE_BLUETOOTH,
-       .probe          = bluetooth_probe,
-       .remove         = bluetooth_remove,
-};
-
 static DBusConnection *connection;
-static guint signal;
+static guint watch;
 
 static int bluetooth_init(void)
 {
@@ -140,25 +73,28 @@ static int bluetooth_init(void)
        if (connection == NULL)
                return -EIO;
 
-       signal = g_dbus_add_signal_watch(connection, "sender=org.bluez",
-                                               bluetooth_signal, NULL, NULL);
-
-       err = connman_driver_register(&bluetooth_driver);
+       err = connman_device_driver_register(&bluetooth_driver);
        if (err < 0) {
                dbus_connection_unref(connection);
-               return err;
+               return -EIO;
        }
 
-       list_adapters(connection);
+       watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE,
+                       bluetooth_connect, bluetooth_disconnect, NULL, NULL);
+       if (watch == 0) {
+               connman_device_driver_unregister(&bluetooth_driver);
+               dbus_connection_unref(connection);
+               return -EIO;
+       }
 
        return 0;
 }
 
 static void bluetooth_exit(void)
 {
-       connman_driver_unregister(&bluetooth_driver);
+       g_dbus_remove_watch(connection, watch);
 
-       g_dbus_remove_watch(connection, signal);
+       connman_device_driver_unregister(&bluetooth_driver);
 
        dbus_connection_unref(connection);
 }
diff --git a/plugins/supplicant.c b/plugins/supplicant.c
index de56f8d..260d24f 100644
--- a/plugins/supplicant.c
+++ b/plugins/supplicant.c
@@ -1049,11 +1049,9 @@ int __supplicant_disconnect(struct connman_element 
*element)
_______________________________________________
Commits mailing list
[email protected]
https://lists.moblin.org/mailman/listinfo/commits

Reply via email to