[xchat-gnome] Bug 646373 - [PATCH] update for recent NetworkManager versions



commit c48996c14452fbaa1cf3128608961b7ab745ff37
Author: Dan Williams <dcbw redhat com>
Date:   Wed Aug 10 17:45:06 2011 +0200

    Bug 646373 - [PATCH] update for recent NetworkManager versions
    
    Update to use NM 0.8.x and later API

 plugins/net-monitor/net-monitor.c |  109 +++++++++----------------------------
 1 files changed, 27 insertions(+), 82 deletions(-)
---
diff --git a/plugins/net-monitor/net-monitor.c b/plugins/net-monitor/net-monitor.c
index 0a65340..fada61c 100644
--- a/plugins/net-monitor/net-monitor.c
+++ b/plugins/net-monitor/net-monitor.c
@@ -23,7 +23,6 @@
  */
 
 #include <config.h>
-#define DBUS_API_SUBJECT_TO_CHANGE
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
@@ -35,9 +34,9 @@
 #include <resolv.h>
 #include "xchat-plugin.h"
 
-#define NET_MONITOR_VERSION     "0.1"
+#define NET_MONITOR_VERSION     "0.2"
 #define NET_MONITOR_NAME        _("Network Monitor")
-#define NET_MONITOR_DESCRIPTION _("NetworkManager connection monitor")
+#define NET_MONITOR_DESCRIPTION _("NetworkManager 0.9.x connection monitor")
 #define NM_SERVICE              "org.freedesktop.NetworkManager"
 #define NM_OBJECT_PATH          "/org/freedesktop/NetworkManager"
 #define NM_INTERFACE            "org.freedesktop.NetworkManager"
@@ -54,13 +53,14 @@ typedef enum
 
 typedef enum
 {
-	NM_STATE_UNKNOWN = 0,
-	NM_STATE_ASLEEP,
-	NM_STATE_CONFIGURE_AP,
-	NM_STATE_CONFIGURE_DEV,
-	NM_STATE_CONFIGURE_IP,
-	NM_STATE_CONNECTED,
-	NM_STATE_DISCONNECTED,
+	NM_STATE_UNKNOWN          = 0,
+	NM_STATE_ASLEEP           = 10,
+	NM_STATE_DISCONNECTED     = 20,
+	NM_STATE_DISCONNECTING    = 30,
+	NM_STATE_CONNECTING       = 40,
+	NM_STATE_CONNECTED_LOCAL  = 50,
+	NM_STATE_CONNECTED_SITE   = 60,
+	NM_STATE_CONNECTED_GLOBAL = 70
 } NetworkManagerState;
 
 enum {
@@ -180,50 +180,6 @@ set_network_mode (NetworkStatus status)
 	}
 }
 
-static NetworkStatus
-check_device_state (const char *path)
-{
-	DBusMessage     *message, *reply;
-	DBusMessageIter  iter;
-	DBusError        error;
-	NetworkStatus    network_mode;
-
-	message = dbus_message_new_method_call (NM_SERVICE, path, NM_INTERFACE, "getLinkActive");
-	if (message == NULL) {
-		g_warning ("Net Monitor: Couldn't allocate dbus message : %s: %s\n", error.name, error.message);
-		/* just guess that we're up */
-		return NETWORK_UP;
-	}
-
-	dbus_error_init (&error);
-	reply = dbus_connection_send_with_reply_and_block (bus, message, -1, &error);
-
-	if (dbus_error_is_set (&error)) {
-		g_warning ("Net Monitor: Error retrieving device state: %s: %s\n", error.name, error.message);
-		network_mode = NETWORK_UP;
-	} else {
-		dbus_message_iter_init (reply, &iter);
-
-		if (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_BOOLEAN) {
-			dbus_bool_t active;
-
-			dbus_message_iter_get_basic (&iter, &active);
-			network_mode = active ? NETWORK_UP : NETWORK_DOWN;
-		} else {
-			g_warning ("Net Monitor: got bad reply from NetworkManager\n");
-			network_mode = NETWORK_UP;
-		}
-	}
-
-	if (reply)
-		dbus_message_unref (reply);
-
-	if (message)
-		dbus_message_unref (message);
-
-	return network_mode;
-}
-
 static void
 determine_network_status ()
 {
@@ -232,7 +188,7 @@ determine_network_status ()
 	DBusError        error;
 	NetworkStatus    network_mode = NETWORK_DOWN;
 
-	message = dbus_message_new_method_call (NM_SERVICE, NM_OBJECT_PATH, NM_INTERFACE, "getDevices");
+	message = dbus_message_new_method_call (NM_SERVICE, NM_OBJECT_PATH, NM_INTERFACE, "state");
 	if (message == NULL) {
 		g_warning ("Net Monitor: Couldn't allocate dbus message : %s: %s\n", error.name, error.message);
 		/* just guess that we're up */
@@ -248,31 +204,25 @@ determine_network_status ()
 		network_mode = NETWORK_UP;
 	} else {
 		dbus_message_iter_init (reply, &iter);
-		if (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_ARRAY) {
-			DBusMessageIter child;
-
-			dbus_message_iter_recurse (&iter, &child);
-
-			while (dbus_message_iter_get_arg_type (&child) != DBUS_TYPE_INVALID) {
-				const char *path;
-				gboolean state;
-
-				/* Check the state of this individual device.  If any one
-				 * device is active, the network is up */
-				dbus_message_iter_get_basic (&child, &path);
-				state = check_device_state (path);
-				if (state == NETWORK_UP)
-					network_mode = NETWORK_UP;
-
-				dbus_message_iter_next (&child);
+		if (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_UINT32) {
+			dbus_uint32_t state;
+
+			dbus_message_iter_get_basic (&iter, &state);
+			if (state == NM_STATE_CONNECTED_LOCAL ||
+			    state == NM_STATE_CONNECTED_SITE ||
+			    state == NM_STATE_CONNECTED_GLOBAL) {
+				network_mode = NETWORK_UP;
+				set_network_mode (network_mode);
+			} else if (state == NM_STATE_DISCONNECTED ) {
+				network_mode = NETWORK_DOWN;
+				set_network_mode (network_mode);
+			} else {
+				g_warning ("Net Monitor: reply from NetworkManager not understood\n");
+				network_mode = NETWORK_DOWN;
 			}
-		} else {
-			g_warning ("Net Monitor: got bad reply from NetworkManager\n");
-			network_mode = NETWORK_UP;
 		}
 	}
 
-	set_network_mode (network_mode);
 
 	if (reply)
 		dbus_message_unref (reply);
@@ -284,16 +234,11 @@ determine_network_status ()
 static DBusHandlerResult
 filter_func (DBusConnection *connection, DBusMessage *message, void *data)
 {
-	if (dbus_message_is_signal (message, NM_INTERFACE, "DeviceNoLongerActive")) {
+	if (dbus_message_is_signal (message, NM_INTERFACE, "StateChanged")) {
 		determine_network_status ();
 		return DBUS_HANDLER_RESULT_HANDLED;
 	}
 
-	if (dbus_message_is_signal (message, NM_INTERFACE, "DeviceNowActive")) {
-		set_network_mode (NETWORK_UP);
-		return DBUS_HANDLER_RESULT_HANDLED;
-	}
-
 	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]