manager: Send network-manager state change signals
authorKalle Valo <kalle.valo@canonical.com>
Tue, 18 Jan 2011 13:01:15 +0000 (15:01 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Sat, 22 Jan 2011 00:25:46 +0000 (01:25 +0100)
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

index 0f66560..6fb54e1 100644 (file)
 
 #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("");