File geoclue-use-libnm-glib.patch of Package geoclue
diff -up geoclue-0.12.0/src/connectivity-networkmanager.c.use-libnm-glib geoclue-0.12.0/src/connectivity-networkmanager.c
--- geoclue-0.12.0/src/connectivity-networkmanager.c.use-libnm-glib 2010-02-19 06:40:40.000000000 -0600
+++ geoclue-0.12.0/src/connectivity-networkmanager.c 2011-03-07 17:36:15.324220841 -0600
@@ -27,11 +27,19 @@
#include <dbus/dbus-glib.h>
+#include <string.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
#include <NetworkManager.h> /*for DBus strings */
-#ifdef HAVE_NETWORK_MANAGER
#include <nm-client.h>
#include <nm-device-wifi.h>
+#include <nm-setting-ip4-config.h>
+
+#if !defined(NM_CHECK_VERSION)
+#define NM_CHECK_VERSION(x,y,z) 0
#endif
#include "connectivity-networkmanager.h"
@@ -48,7 +56,7 @@ static int
get_status (GeoclueConnectivity *iface)
{
GeoclueNetworkManager *nm = GEOCLUE_NETWORKMANAGER (iface);
-
+
return nm->status;
}
@@ -57,7 +65,7 @@ get_ap_mac (GeoclueConnectivity *iface)
{
GeoclueNetworkManager *self = GEOCLUE_NETWORKMANAGER (iface);
- return self->cache_ap_mac;
+ return g_strdup (self->cache_ap_mac);
}
static void
@@ -89,16 +97,12 @@ cache_ap_mac (GeoclueNetworkManager *sel
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++) {
+ for (i = 0; devices != NULL && i < devices->len; i++) {
NMDevice *device = g_ptr_array_index (devices, i);
if (NM_IS_DEVICE_WIFI (device)) {
get_best_ap (self, device);
@@ -107,19 +111,10 @@ cache_ap_mac (GeoclueNetworkManager *sel
}
static void
-finalize (GObject *object)
-{
- /* free everything */
-
- ((GObjectClass *) geoclue_networkmanager_parent_class)->finalize (object);
-}
-
-static void
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);
@@ -132,7 +127,6 @@ geoclue_networkmanager_class_init (Geocl
{
GObjectClass *o_class = (GObjectClass *) klass;
- o_class->finalize = finalize;
o_class->dispose = dispose;
}
@@ -144,11 +138,20 @@ nmstate_to_geocluenetworkstatus (NMState
return GEOCLUE_CONNECTIVITY_UNKNOWN;
case NM_STATE_ASLEEP:
case NM_STATE_DISCONNECTED:
+#if NM_CHECK_VERSION(0,8,992)
+ case NM_STATE_DISCONNECTING:
+#endif
return GEOCLUE_CONNECTIVITY_OFFLINE;
case NM_STATE_CONNECTING:
return GEOCLUE_CONNECTIVITY_ACQUIRING;
+#if NM_CHECK_VERSION(0,8,992)
+ case NM_STATE_CONNECTED_LOCAL:
+ case NM_STATE_CONNECTED_SITE:
+ case NM_STATE_CONNECTED_GLOBAL:
+#else
case NM_STATE_CONNECTED:
+#endif
return GEOCLUE_CONNECTIVITY_ONLINE;
default:
g_warning ("Unknown NMStatus: %d", status);
return GEOCLUE_CONNECTIVITY_UNKNOWN;
@@ -156,66 +158,52 @@ nmstate_to_geocluenetworkstatus (NMState
}
static void
-geoclue_networkmanager_state_changed (DBusGProxy *proxy,
- NMState status,
- gpointer userdata)
+update_status (GeoclueNetworkManager *self, gboolean do_signal)
{
- GeoclueNetworkManager *self = GEOCLUE_NETWORKMANAGER (userdata);
- GeoclueNetworkStatus gc_status;
-
- gc_status = nmstate_to_geocluenetworkstatus (status);
-
- if (gc_status != self->status) {
+ GeoclueNetworkStatus old_status;
+ NMState state;
+
+ old_status = self->status;
+
+ if (nm_client_get_manager_running (self->client)) {
+ state = nm_client_get_state (self->client);
+ self->status = nmstate_to_geocluenetworkstatus (state);
cache_ap_mac (self);
- self->status = gc_status;
+ } else {
+ self->status = GEOCLUE_CONNECTIVITY_OFFLINE;
+ }
+
+ if ((self->status != old_status) && do_signal) {
geoclue_connectivity_emit_status_changed (GEOCLUE_CONNECTIVITY (self),
self->status);
}
}
-
-#define NM_DBUS_SIGNAL_STATE_CHANGE "StateChange"
+static void
+nm_update_status_cb (GObject *obj, GParamSpec *spec, gpointer userdata)
+{
+ update_status (GEOCLUE_NETWORKMANAGER (userdata), TRUE);
+}
static void
geoclue_networkmanager_init (GeoclueNetworkManager *self)
{
- GError *error = NULL;
- DBusGProxy *proxy;
- NMState state;
-
self->status = GEOCLUE_CONNECTIVITY_UNKNOWN;
-
- self->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (self->connection == NULL) {
- g_warning ("%s was unable to create a connection to D-Bus: %s",
- G_OBJECT_TYPE_NAME (self), error->message);
- g_error_free (error);
+ self->client = nm_client_new ();
+ if (self->client == NULL) {
+ g_warning ("%s was unable to create a connection to NetworkManager",
+ G_OBJECT_TYPE_NAME (self));
return;
}
-
- proxy = dbus_g_proxy_new_for_name (self->connection,
- NM_DBUS_SERVICE,
- NM_DBUS_PATH,
- NM_DBUS_INTERFACE);
- dbus_g_proxy_add_signal (proxy, NM_DBUS_SIGNAL_STATE_CHANGE,
- G_TYPE_UINT, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (proxy, NM_DBUS_SIGNAL_STATE_CHANGE,
- G_CALLBACK (geoclue_networkmanager_state_changed),
- self, NULL);
-
- if (dbus_g_proxy_call (proxy, "state", &error,
- G_TYPE_INVALID,
- G_TYPE_UINT, &state, G_TYPE_INVALID)){
- self->status = nmstate_to_geocluenetworkstatus (state);
- } else {
- 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);
-}
+ g_signal_connect (G_OBJECT (self->client), "notify::running",
+ G_CALLBACK (nm_update_status_cb), self);
+ g_signal_connect (G_OBJECT (self->client), "notify::state",
+ G_CALLBACK (nm_update_status_cb), self);
+ /* get initial status */
+ update_status (self, FALSE);
+}
static void
geoclue_networkmanager_connectivity_init (GeoclueConnectivityInterface *iface)