From 2978bc5a40898a8e693b4379eda3c355e997f048 Mon Sep 17 00:00:00 2001 From: Kalle Valo Date: Tue, 18 Jan 2011 15:01:15 +0200 Subject: [PATCH] manager: Send network-manager state change signals When using network-manager compatibility mode in connman applications, for example pidgin and firefox, didn't notice when connman changed states from offline to online (and vice versa) and applications would notice the new state only after restarting them. The problem was that connman wasn't sending StateChanged signals. After adding them pidgin and firefox will notice the new states immeadiately. --- src/manager.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/src/manager.c b/src/manager.c index 0f66560..6fb54e1 100644 --- a/src/manager.c +++ b/src/manager.c @@ -27,6 +27,16 @@ #include "connman.h" +enum { + NM_STATE_UNKNOWN = 0, + NM_STATE_ASLEEP, + NM_STATE_CONNECTING, + NM_STATE_CONNECTED, + NM_STATE_DISCONNECTED +}; + +static gboolean nm_compat = FALSE; + static DBusMessage *get_properties(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -303,10 +313,46 @@ static void technology_notify(enum connman_service_type type, technology_reply(0); } +static void nm_send_signal(const char *name, dbus_uint32_t state) +{ + DBusMessage *signal; + + signal = dbus_message_new_signal(NM_PATH, NM_INTERFACE, name); + if (signal == NULL) + return; + + dbus_message_append_args(signal, DBUS_TYPE_UINT32, &state, + DBUS_TYPE_INVALID); + + g_dbus_send_message(connection, signal); +} + +static void default_changed(struct connman_service *service) +{ + dbus_uint32_t state; + + if (!nm_compat) + return; + + if (service != NULL) + state = NM_STATE_CONNECTED; + else + state = NM_STATE_DISCONNECTED; + + DBG("%p %d", service, state); + + /* older deprecated signal, in case applications still use this */ + nm_send_signal("StateChange", state); + + /* the preferred current signal */ + nm_send_signal("StateChanged", state); +} + static struct connman_notifier technology_notifier = { .name = "manager", .priority = CONNMAN_NOTIFIER_PRIORITY_HIGH, .service_enabled= technology_notify, + .default_changed= default_changed, }; static DBusMessage *enable_technology(DBusConnection *conn, @@ -684,14 +730,6 @@ static DBusMessage *nm_wake(DBusConnection *conn, return reply; } -enum { - NM_STATE_UNKNOWN = 0, - NM_STATE_ASLEEP, - NM_STATE_CONNECTING, - NM_STATE_CONNECTED, - NM_STATE_DISCONNECTED -}; - static DBusMessage *nm_state(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -722,8 +760,6 @@ static GDBusMethodTable nm_methods[] = { { }, }; -static gboolean nm_compat = FALSE; - int __connman_manager_init(gboolean compat) { DBG(""); -- 2.7.4