Commit aeb5f8dd authored by Keith Preston's avatar Keith Preston

Bug #22378: Add options with Netowkr Manager to get better AP MAC detection

parent d18b4e68
......@@ -77,7 +77,7 @@ if test "x$HAVE_CONIC" = "xyes"; then
fi
PKG_CHECK_MODULES(NETWORK_MANAGER, [
NetworkManager
NetworkManager libnm_glib
], HAVE_NETWORK_MANAGER=yes, HAVE_NETWORK_MANAGER=no)
if test "x$HAVE_NETWORK_MANAGER" = "xyes"; then
CONNECTIVITY="Network Manager"
......
......@@ -28,6 +28,12 @@
#include <dbus/dbus-glib.h>
#include <NetworkManager.h> /*for DBus strings */
#ifdef HAVE_NETWORK_MANAGER
#include <nm-client.h>
#include <nm-device-wifi.h>
#endif
#include "connectivity-networkmanager.h"
static void geoclue_networkmanager_connectivity_init (GeoclueConnectivityInterface *iface);
......@@ -46,6 +52,59 @@ get_status (GeoclueConnectivity *iface)
return nm->status;
}
static char *
get_ap_mac (GeoclueConnectivity *iface)
{
GeoclueNetworkManager *self = GEOCLUE_NETWORKMANAGER (iface);
return self->cache_ap_mac;
}
static void
get_best_ap (GeoclueNetworkManager *self, NMDevice *device)
{
const GPtrArray *aps;
guint i;
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));
if (aps == NULL || aps->len == 0)
return;
for (i = 0; i < aps->len; i++) {
NMAccessPoint *ap = NM_ACCESS_POINT (g_ptr_array_index (aps, i));
int strength;
strength = nm_access_point_get_strength (ap);
if (strength > self->ap_strength) {
g_free (self->cache_ap_mac);
self->cache_ap_mac = g_strdup (nm_access_point_get_hw_address (ap));
self->ap_strength = strength;
}
}
}
static void
cache_ap_mac (GeoclueNetworkManager *self)
{
const GPtrArray *devices;
guint i;
devices = nm_client_get_devices (self->client);
if (devices == NULL) {
g_free (self->cache_ap_mac);
self->cache_ap_mac = NULL;
}
g_free (self->cache_ap_mac);
self->cache_ap_mac = NULL;
self->ap_strength = 0;
for (i = 0; i < devices->len; i++) {
NMDevice *device = g_ptr_array_index (devices, i);
if (NM_IS_DEVICE_WIFI (device)) {
get_best_ap (self, device);
}
}
}
static void
finalize (GObject *object)
......@@ -61,6 +120,10 @@ dispose (GObject *object)
GeoclueNetworkManager *self = GEOCLUE_NETWORKMANAGER (object);
dbus_g_connection_unref (self->connection);
g_free (self->cache_ap_mac);
self->cache_ap_mac = NULL;
g_object_unref (self->client);
self->client = NULL;
((GObjectClass *) geoclue_networkmanager_parent_class)->dispose (object);
}
......@@ -103,6 +166,7 @@ geoclue_networkmanager_state_changed (DBusGProxy *proxy,
gc_status = nmstate_to_geocluenetworkstatus (status);
if (gc_status != self->status) {
cache_ap_mac (self);
self->status = gc_status;
geoclue_connectivity_emit_status_changed (GEOCLUE_CONNECTIVITY (self),
self->status);
......@@ -147,6 +211,9 @@ geoclue_networkmanager_init (GeoclueNetworkManager *self)
g_warning ("Could not get connectivity state from NetworkManager: %s", error->message);
g_error_free (error);
}
self->client = nm_client_new ();
cache_ap_mac (self);
}
......@@ -154,6 +221,7 @@ static void
geoclue_networkmanager_connectivity_init (GeoclueConnectivityInterface *iface)
{
iface->get_status = get_status;
iface->get_ap_mac = get_ap_mac;
}
#endif /* HAVE_NETWORK_MANAGER */
......@@ -4,12 +4,29 @@
*
* Author: Jussi Kukkonen <jku@o-hand.com>
* Copyright 2007 by Garmin Ltd. or its subsidiaries
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#ifndef _CONNECTIVITY_NETWORKMANAGER_H
#define _CONNECTIVITY_NETWORKMANAGER_H
#include <glib-object.h>
#include <nm-client.h>
#include "connectivity.h"
......@@ -24,6 +41,9 @@ typedef struct {
/* private */
GeoclueNetworkStatus status;
DBusGConnection *connection;
NMClient *client;
char *cache_ap_mac;
int ap_strength;
} GeoclueNetworkManager;
typedef struct {
......
......@@ -77,6 +77,14 @@ geoclue_connectivity_get_status (GeoclueConnectivity *self)
return GEOCLUE_CONNECTIVITY_GET_INTERFACE (self)->get_status (self);
}
char *
geoclue_connectivity_get_ap_mac (GeoclueConnectivity *self)
{
if (GEOCLUE_CONNECTIVITY_GET_INTERFACE (self)->get_ap_mac != NULL)
return GEOCLUE_CONNECTIVITY_GET_INTERFACE (self)->get_ap_mac (self);
return NULL;
}
void
geoclue_connectivity_emit_status_changed (GeoclueConnectivity *self,
GeoclueNetworkStatus status)
......
......@@ -4,6 +4,22 @@
*
* Author: Jussi Kukkonen <jku@o-hand.com>
* Copyright 2007 by Garmin Ltd. or its subsidiaries
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#ifndef _GEOCLUE_CONNECTIVITY_H
......@@ -32,6 +48,7 @@ struct _GeoclueConnectivityInterface {
/* vtable */
int (*get_status) (GeoclueConnectivity *self);
char * (*get_ap_mac) (GeoclueConnectivity *self);
};
GType geoclue_connectivity_get_type (void);
......@@ -39,6 +56,8 @@ GType geoclue_connectivity_get_type (void);
GeoclueNetworkStatus geoclue_connectivity_get_status (GeoclueConnectivity *self);
char *geoclue_connectivity_get_ap_mac (GeoclueConnectivity *self);
void
geoclue_connectivity_emit_status_changed (GeoclueConnectivity *self,
GeoclueNetworkStatus status);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment