[PATCH] manager: send network-manager state change signals

Kalle Valo kalle.valo at canonical.com
Tue Jan 18 01:01:11 PST 2011


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 |   49 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/src/manager.c b/src/manager.c
index 0f66560..728a828 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -27,6 +27,14 @@
 
 #include "connman.h"
 
+enum {
+	NM_STATE_UNKNOWN = 0,
+	NM_STATE_ASLEEP,
+	NM_STATE_CONNECTING,
+	NM_STATE_CONNECTED,
+	NM_STATE_DISCONNECTED
+};
+
 static DBusMessage *get_properties(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
@@ -303,10 +311,43 @@ 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 (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 +725,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)
 {




More information about the connman mailing list