max-strength.patch



Clemson University has over 250 hidden AP's all with the same essid. I usually see 2-6 AP's in a scan. In my office, I get a weak signal from the building next door and a strong signal the office. A scan in the office, will list the weak AP first and the strong one second. The AP's in the scan list are transferred to the NM AP list in the same order.

In NMWirelessAppletDbus.c, the function nmwa_dbus_update_device_wireless_networks walks through the NM AP list and makes a new AP list for display in the menu. This function adds to the new list the first occurrence of an AP in the NM AP list. In my office, hovering over the NM icon shows a signal of 85% but when I look at the menu I see a signal strength below 50%. The 85% signal is the AP in my building but the below 50% signal is from the AP next door because it was the first occurrence in the NM AP list.
Users will find this confusing.

The patch below and attached inserts in nmwa_dbus_update_device_wireless_networks a loop which adds to the new list the occurrence of an AP in the NM AP list that has the greatest signal strength.

Pros: simple addition to current code.
Cons: not efficient, but then AP lists are not likely to be long.
________________
--- NMWirelessAppletDbus.c_orig    2005-02-12 16:42:14.000000000 -0500
+++ NMWirelessAppletDbus.c    2005-02-12 17:03:58.000000000 -0500
@@ -969,7 +969,10 @@
    char         *active_network = NULL;
    char        **networks = NULL;
    int          num_items = 0;
-    int          i;
+    int          max_index = 0;
+    gint8          max_strength = 0;
+    gint8          strengthj = 0;
+    int          i, j;
    g_return_if_fail (dev != NULL);

    /* Clear out existing entries in the list */
@@ -1012,10 +1015,24 @@
                    break;
            if (found)
                continue;
+
+            /* begin max code segment */
+            max_index = i;
+ max_strength = nmwa_dbus_get_object_strength (applet, g_strdup (networks[i]));
+            for (j = i+1; j < num_items; j++)
+            {
+ strengthj = nmwa_dbus_get_object_strength (applet, g_strdup (networks[j])); + if ( ( (strcmp(networks[i], networks[j]) == 0) && (strengthj > max_strength) ) )
+                {
+                    max_index = j;
+                    max_strength = strengthj;
+                }
+            }
+            /* end max code segment */
net = wireless_network_new (); /* FIXME: what if net == NULL? */ - net->nm_name = g_strdup (networks[i]);
+            net->nm_name = g_strdup (networks[max_index]);
            net->essid = g_strdup (name);
net->active = active_network ? (strcmp (net->nm_name, active_network) == 0) : FALSE; net->encrypted = nmwa_dbus_get_network_encrypted (applet, net->nm_name);

--
Bill Moss
Professor, Mathematical Sciences
Clemson University

--- NMWirelessAppletDbus.c_orig	2005-02-12 16:42:14.000000000 -0500
+++ NMWirelessAppletDbus.c	2005-02-12 17:03:58.000000000 -0500
@@ -969,7 +969,10 @@
 	char		 *active_network = NULL;
 	char		**networks = NULL;
 	int		  num_items = 0;
-	int		  i;
+	int		  max_index = 0;
+	gint8		  max_strength = 0;
+	gint8		  strengthj = 0;
+	int		  i, j;
 	g_return_if_fail (dev != NULL);
 
 	/* Clear out existing entries in the list */
@@ -1012,10 +1015,24 @@
 					break;
 			if (found)
 				continue;
+
+			/* begin max code segment */
+			max_index = i;
+			max_strength = nmwa_dbus_get_object_strength (applet, g_strdup (networks[i]));
+			for (j = i+1; j < num_items; j++)
+			{
+				strengthj = nmwa_dbus_get_object_strength (applet, g_strdup (networks[j]));
+				if ( ( (strcmp(networks[i], networks[j]) == 0) && (strengthj > max_strength) ) )
+				{
+					max_index = j;
+					max_strength = strengthj;
+				}
+			}
+			/* end max code segment */
 						
 			net = wireless_network_new ();
 			/* FIXME: what if net == NULL? */			
-			net->nm_name = g_strdup (networks[i]);
+			net->nm_name = g_strdup (networks[max_index]);
 			net->essid = g_strdup (name);
 			net->active = active_network ? (strcmp (net->nm_name, active_network) == 0) : FALSE;
 			net->encrypted = nmwa_dbus_get_network_encrypted (applet, net->nm_name);




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