diff options
Diffstat (limited to 'libnm-glib')
| -rw-r--r-- | libnm-glib/libnm-glib.ver | 2 | ||||
| -rw-r--r-- | libnm-glib/libnm_glib.c | 93 | ||||
| -rw-r--r-- | libnm-glib/nm-device-wifi.c | 30 | ||||
| -rw-r--r-- | libnm-glib/nm-device-wimax.c | 25 | ||||
| -rw-r--r-- | libnm-glib/nm-device.c | 202 | ||||
| -rw-r--r-- | libnm-glib/nm-device.h | 3 | ||||
| -rw-r--r-- | libnm-glib/nm-object.c | 31 | ||||
| -rw-r--r-- | libnm-glib/nm-types.c | 56 |
8 files changed, 278 insertions, 164 deletions
diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver index 64ff70ad..f42368b8 100644 --- a/libnm-glib/libnm-glib.ver +++ b/libnm-glib/libnm-glib.ver @@ -66,6 +66,7 @@ global: nm_device_ethernet_get_type; nm_device_ethernet_new; nm_device_filter_connections; + nm_device_get_active_connection; nm_device_get_capabilities; nm_device_get_device_type; nm_device_get_dhcp4_config; @@ -75,6 +76,7 @@ global: nm_device_get_iface; nm_device_get_ip4_config; nm_device_get_ip6_config; + nm_device_get_ip_iface; nm_device_get_managed; nm_device_get_product; nm_device_get_state; diff --git a/libnm-glib/libnm_glib.c b/libnm-glib/libnm_glib.c index 911d0cec..1d755786 100644 --- a/libnm-glib/libnm_glib.c +++ b/libnm-glib/libnm_glib.c @@ -64,14 +64,13 @@ typedef struct libnm_glib_callback } libnm_glib_callback; -static void libnm_glib_schedule_dbus_watcher (libnm_glib_ctx *ctx); -static DBusConnection * libnm_glib_dbus_init (gpointer *user_data, GMainContext *context); -static void libnm_glib_update_state (libnm_glib_ctx *ctx, NMState state); +static void _libnm_glib_schedule_dbus_watcher (libnm_glib_ctx *ctx); +static DBusConnection * _libnm_glib_dbus_init (gpointer *user_data, GMainContext *context); +static void _libnm_glib_update_state (libnm_glib_ctx *ctx, NMState state); static void -libnm_glib_nm_state_cb (DBusPendingCall *pcall, - void *user_data) +_libnm_glib_nm_state_cb (DBusPendingCall *pcall, void *user_data) { DBusMessage * reply; libnm_glib_ctx * ctx = (libnm_glib_ctx *) user_data; @@ -96,7 +95,7 @@ libnm_glib_nm_state_cb (DBusPendingCall *pcall, } if (dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &nm_state, DBUS_TYPE_INVALID)) - libnm_glib_update_state (ctx, nm_state); + _libnm_glib_update_state (ctx, nm_state); dbus_message_unref (reply); @@ -105,7 +104,7 @@ out: } static void -libnm_glib_get_nm_state (libnm_glib_ctx *ctx) +_libnm_glib_get_nm_state (libnm_glib_ctx *ctx) { DBusMessage * message; DBusPendingCall * pcall = NULL; @@ -116,13 +115,13 @@ libnm_glib_get_nm_state (libnm_glib_ctx *ctx) { dbus_connection_send_with_reply (ctx->dbus_con, message, &pcall, -1); if (pcall) - dbus_pending_call_set_notify (pcall, libnm_glib_nm_state_cb, ctx, NULL); + dbus_pending_call_set_notify (pcall, _libnm_glib_nm_state_cb, ctx, NULL); dbus_message_unref (message); } } static gboolean -libnm_glib_callback_helper (gpointer user_data) +_libnm_glib_callback_helper (gpointer user_data) { libnm_glib_callback *cb_data = (libnm_glib_callback *)user_data; @@ -136,8 +135,8 @@ libnm_glib_callback_helper (gpointer user_data) } static void -libnm_glib_schedule_single_callback (libnm_glib_ctx *ctx, - libnm_glib_callback *callback) +_libnm_glib_schedule_single_callback (libnm_glib_ctx *ctx, + libnm_glib_callback *callback) { GSource *source; @@ -147,14 +146,14 @@ libnm_glib_schedule_single_callback (libnm_glib_ctx *ctx, callback->libnm_glib_ctx = ctx; source = g_idle_source_new (); - g_source_set_callback (source, libnm_glib_callback_helper, callback, NULL); + g_source_set_callback (source, _libnm_glib_callback_helper, callback, NULL); g_source_attach (source, callback->gmain_ctx); g_source_unref (source); } static void -libnm_glib_unschedule_single_callback (libnm_glib_ctx *ctx, - libnm_glib_callback *callback) +_libnm_glib_unschedule_single_callback (libnm_glib_ctx *ctx, + libnm_glib_callback *callback) { GSource *source; @@ -167,7 +166,7 @@ libnm_glib_unschedule_single_callback (libnm_glib_ctx *ctx, } static void -libnm_glib_call_callbacks (libnm_glib_ctx *ctx) +_libnm_glib_call_callbacks (libnm_glib_ctx *ctx) { GSList *elem; @@ -178,15 +177,14 @@ libnm_glib_call_callbacks (libnm_glib_ctx *ctx) { libnm_glib_callback *callback = (libnm_glib_callback *)(elem->data); if (callback) - libnm_glib_schedule_single_callback (ctx, callback); + _libnm_glib_schedule_single_callback (ctx, callback); } g_mutex_unlock (ctx->callbacks_lock); } static void -libnm_glib_update_state (libnm_glib_ctx *ctx, - NMState state) +_libnm_glib_update_state (libnm_glib_ctx *ctx, NMState state) { libnm_glib_state old_state; @@ -212,14 +210,14 @@ libnm_glib_update_state (libnm_glib_ctx *ctx, } if (old_state != ctx->nm_state) - libnm_glib_call_callbacks (ctx); + _libnm_glib_call_callbacks (ctx); } static DBusHandlerResult -libnm_glib_dbus_filter (DBusConnection *connection, - DBusMessage *message, - void *user_data) +_libnm_glib_dbus_filter (DBusConnection *connection, + DBusMessage *message, + void *user_data) { libnm_glib_ctx *ctx = (libnm_glib_ctx *)user_data; gboolean handled = TRUE; @@ -237,7 +235,7 @@ libnm_glib_dbus_filter (DBusConnection *connection, dbus_connection_close (ctx->dbus_con); dbus_connection_unref (ctx->dbus_con); ctx->dbus_con = NULL; - libnm_glib_schedule_dbus_watcher (ctx); + _libnm_glib_schedule_dbus_watcher (ctx); } else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) { @@ -258,7 +256,7 @@ libnm_glib_dbus_filter (DBusConnection *connection, gboolean new_owner_good = (new_owner && (strlen (new_owner) > 0)); if (!old_owner_good && new_owner_good) /* Equivalent to old ServiceCreated signal */ - libnm_glib_get_nm_state (ctx); + _libnm_glib_get_nm_state (ctx); else if (old_owner_good && !new_owner_good) /* Equivalent to old ServiceDeleted signal */ ctx->nm_state = LIBNM_NO_NETWORKMANAGER; } @@ -269,14 +267,14 @@ libnm_glib_dbus_filter (DBusConnection *connection, || dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceActivating") || dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DevicesChanged")) { - libnm_glib_get_nm_state (ctx); + _libnm_glib_get_nm_state (ctx); } else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "StateChanged")) { NMState state = NM_STATE_UNKNOWN; dbus_message_get_args (message, &error, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID); - libnm_glib_update_state (ctx, state); + _libnm_glib_update_state (ctx, state); } else handled = FALSE; @@ -295,8 +293,7 @@ libnm_glib_dbus_filter (DBusConnection *connection, * */ static DBusConnection * -libnm_glib_dbus_init (gpointer *user_data, - GMainContext *context) +_libnm_glib_dbus_init (gpointer *user_data, GMainContext *context) { DBusConnection *connection = NULL; DBusError error; @@ -312,7 +309,7 @@ libnm_glib_dbus_init (gpointer *user_data, if (!connection) return NULL; - if (!dbus_connection_add_filter (connection, libnm_glib_dbus_filter, user_data, NULL)) + if (!dbus_connection_add_filter (connection, _libnm_glib_dbus_filter, user_data, NULL)) return (NULL); dbus_connection_set_exit_on_disconnect (connection, FALSE); @@ -348,7 +345,7 @@ libnm_glib_dbus_init (gpointer *user_data, * */ static gboolean -libnm_glib_dbus_watcher (gpointer user_data) +_libnm_glib_dbus_watcher (gpointer user_data) { libnm_glib_ctx *ctx = (libnm_glib_ctx *)user_data; @@ -357,12 +354,12 @@ libnm_glib_dbus_watcher (gpointer user_data) ctx->dbus_watcher = 0; if (!ctx->dbus_con) - ctx->dbus_con = libnm_glib_dbus_init ((gpointer)ctx, ctx->g_main_ctx); + ctx->dbus_con = _libnm_glib_dbus_init ((gpointer)ctx, ctx->g_main_ctx); if (ctx->dbus_con) { /* Get NM's state right away after we reconnect */ - libnm_glib_get_nm_state (ctx); + _libnm_glib_get_nm_state (ctx); ctx->dbus_watch_interval = 1000; } else @@ -373,7 +370,7 @@ libnm_glib_dbus_watcher (gpointer user_data) ctx->dbus_watch_interval = MIN(ctx->dbus_watch_interval + 3000, 60000); /* Reschule ourselves if we _still_ don't have a connection to dbus */ - libnm_glib_schedule_dbus_watcher (ctx); + _libnm_glib_schedule_dbus_watcher (ctx); } return FALSE; @@ -388,14 +385,14 @@ libnm_glib_dbus_watcher (gpointer user_data) * */ static void -libnm_glib_schedule_dbus_watcher (libnm_glib_ctx *ctx) +_libnm_glib_schedule_dbus_watcher (libnm_glib_ctx *ctx) { g_return_if_fail (ctx != NULL); if (ctx->dbus_watcher == 0) { GSource * source = g_timeout_source_new (ctx->dbus_watch_interval); - g_source_set_callback (source, libnm_glib_dbus_watcher, (gpointer) ctx, NULL); + g_source_set_callback (source, _libnm_glib_dbus_watcher, (gpointer) ctx, NULL); ctx->dbus_watcher = g_source_attach (source, ctx->g_main_ctx); g_source_unref (source); } @@ -409,7 +406,7 @@ libnm_glib_schedule_dbus_watcher (libnm_glib_ctx *ctx) * */ static gpointer -libnm_glib_dbus_worker (gpointer user_data) +_libnm_glib_dbus_worker (gpointer user_data) { libnm_glib_ctx *ctx = (libnm_glib_ctx *)user_data; @@ -420,10 +417,10 @@ libnm_glib_dbus_worker (gpointer user_data) * down. Should probably be done by a timeout polling dbus_connection_is_connected() * or by getting connection status out of libdbus or something. */ - if (!(ctx->dbus_con = libnm_glib_dbus_init ((gpointer) ctx, ctx->g_main_ctx))) - libnm_glib_schedule_dbus_watcher (ctx); + if (!(ctx->dbus_con = _libnm_glib_dbus_init ((gpointer) ctx, ctx->g_main_ctx))) + _libnm_glib_schedule_dbus_watcher (ctx); else - libnm_glib_get_nm_state (ctx); + _libnm_glib_get_nm_state (ctx); ctx->thread_inited = TRUE; g_main_loop_run (ctx->g_main_loop); @@ -434,7 +431,7 @@ libnm_glib_dbus_worker (gpointer user_data) static void -libnm_glib_ctx_free (libnm_glib_ctx *ctx) +_libnm_glib_ctx_free (libnm_glib_ctx *ctx) { g_return_if_fail (ctx != NULL); @@ -472,7 +469,7 @@ libnm_glib_ctx_free (libnm_glib_ctx *ctx) static libnm_glib_ctx * -libnm_glib_ctx_new (void) +_libnm_glib_ctx_new (void) { libnm_glib_ctx *ctx = g_malloc0 (sizeof (libnm_glib_ctx)); @@ -487,7 +484,7 @@ libnm_glib_ctx_new (void) return ctx; error: - libnm_glib_ctx_free (ctx); + _libnm_glib_ctx_free (ctx); return NULL; } @@ -502,10 +499,10 @@ libnm_glib_init (void) g_thread_init (NULL); dbus_g_thread_init (); - if (!(ctx = libnm_glib_ctx_new ())) + if (!(ctx = _libnm_glib_ctx_new ())) return NULL; - ctx->thread = g_thread_create (libnm_glib_dbus_worker, ctx, TRUE, NULL); + ctx->thread = g_thread_create (_libnm_glib_dbus_worker, ctx, TRUE, NULL); if (!ctx->thread) goto error; @@ -516,7 +513,7 @@ libnm_glib_init (void) return ctx; error: - libnm_glib_ctx_free (ctx); + _libnm_glib_ctx_free (ctx); return NULL; } @@ -530,7 +527,7 @@ libnm_glib_shutdown (libnm_glib_ctx *ctx) while (!ctx->thread_done) g_usleep (G_USEC_PER_SEC / 20); - libnm_glib_ctx_free (ctx); + _libnm_glib_ctx_free (ctx); } @@ -565,7 +562,7 @@ libnm_glib_register_callback (libnm_glib_ctx *ctx, g_mutex_lock (ctx->callbacks_lock); ctx->callbacks = g_slist_append (ctx->callbacks, callback); - libnm_glib_schedule_single_callback (ctx, callback); + _libnm_glib_schedule_single_callback (ctx, callback); g_mutex_unlock (ctx->callbacks_lock); return (callback->id); @@ -588,7 +585,7 @@ libnm_glib_unregister_callback (libnm_glib_ctx *ctx, libnm_glib_callback *callback = (libnm_glib_callback *)(elem->data); if (callback && (callback->id == id)) { - libnm_glib_unschedule_single_callback (ctx, callback); + _libnm_glib_unschedule_single_callback (ctx, callback); ctx->callbacks = g_slist_remove_link (ctx->callbacks, elem); break; } diff --git a/libnm-glib/nm-device-wifi.c b/libnm-glib/nm-device-wifi.c index d1d9e0b7..9877f94f 100644 --- a/libnm-glib/nm-device-wifi.c +++ b/libnm-glib/nm-device-wifi.c @@ -55,7 +55,7 @@ typedef struct { NM80211Mode mode; guint32 rate; NMAccessPoint *active_ap; - gboolean null_active_ap; + gboolean got_active_ap; NMDeviceWifiCapabilities wireless_caps; GPtrArray *aps; @@ -271,6 +271,7 @@ nm_device_wifi_get_active_access_point (NMDeviceWifi *device) NMDeviceState state; char *path; GValue value = { 0, }; + GError *error = NULL; g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL); @@ -291,21 +292,20 @@ nm_device_wifi_get_active_access_point (NMDeviceWifi *device) } priv = NM_DEVICE_WIFI_GET_PRIVATE (device); - if (priv->active_ap) + if (priv->got_active_ap == TRUE) return priv->active_ap; - if (priv->null_active_ap) - return NULL; path = _nm_object_get_object_path_property (NM_OBJECT (device), - NM_DBUS_INTERFACE_DEVICE_WIRELESS, - DBUS_PROP_ACTIVE_ACCESS_POINT, - NULL); - if (path) { + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + DBUS_PROP_ACTIVE_ACCESS_POINT, + &error); + if (error == NULL) { g_value_init (&value, DBUS_TYPE_G_OBJECT_PATH); g_value_take_boxed (&value, path); demarshal_active_ap (NM_OBJECT (device), NULL, &value, &priv->active_ap); g_value_unset (&value); } + g_clear_error (&error); return priv->active_ap; } @@ -427,9 +427,8 @@ access_point_removed_proxy (DBusGProxy *proxy, char *path, gpointer user_data) if (ap == priv->active_ap) { g_object_unref (priv->active_ap); priv->active_ap = NULL; - priv->null_active_ap = FALSE; - _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT); + priv->rate = 0; _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIFI_BITRATE); } @@ -620,7 +619,6 @@ state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data) if (priv->active_ap) { g_object_unref (priv->active_ap); priv->active_ap = NULL; - priv->null_active_ap = FALSE; } _nm_object_queue_notify (NM_OBJECT (device), NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT); priv->rate = 0; @@ -642,13 +640,11 @@ demarshal_active_ap (NMObject *object, GParamSpec *pspec, GValue *value, gpointe if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) return FALSE; - priv->null_active_ap = FALSE; + priv->got_active_ap = TRUE; - path = g_value_get_boxed (value); - if (path) { - if (!strcmp (path, "/")) - priv->null_active_ap = TRUE; - else { + if (value) { + path = g_value_get_boxed (value); + if (path) { ap = NM_ACCESS_POINT (_nm_object_cache_get (path)); if (!ap) { connection = nm_object_get_connection (object); diff --git a/libnm-glib/nm-device-wimax.c b/libnm-glib/nm-device-wimax.c index 194a36d1..a889583d 100644 --- a/libnm-glib/nm-device-wimax.c +++ b/libnm-glib/nm-device-wimax.c @@ -50,7 +50,7 @@ typedef struct { char *hw_address; NMWimaxNsp *active_nsp; - gboolean null_active_nsp; + gboolean got_active_nsp; GPtrArray *nsps; guint center_freq; @@ -153,6 +153,7 @@ nm_device_wimax_get_active_nsp (NMDeviceWimax *wimax) NMDeviceState state; char *path; GValue value = { 0, }; + GError *error = NULL; g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL); @@ -173,21 +174,20 @@ nm_device_wimax_get_active_nsp (NMDeviceWimax *wimax) } priv = NM_DEVICE_WIMAX_GET_PRIVATE (wimax); - if (priv->active_nsp) + if (priv->got_active_nsp == TRUE) return priv->active_nsp; - if (priv->null_active_nsp) - return NULL; path = _nm_object_get_object_path_property (NM_OBJECT (wimax), NM_DBUS_INTERFACE_DEVICE_WIMAX, DBUS_PROP_ACTIVE_NSP, - NULL); - if (path) { + &error); + if (error == NULL) { g_value_init (&value, DBUS_TYPE_G_OBJECT_PATH); g_value_take_boxed (&value, path); demarshal_active_nsp (NM_OBJECT (wimax), NULL, &value, &priv->active_nsp); g_value_unset (&value); } + g_clear_error (&error); return priv->active_nsp; } @@ -309,8 +309,6 @@ nsp_removed_proxy (DBusGProxy *proxy, char *path, gpointer user_data) if (nsp == priv->active_nsp) { g_object_unref (priv->active_nsp); priv->active_nsp = NULL; - priv->null_active_nsp = FALSE; - _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_ACTIVE_NSP); } @@ -607,7 +605,6 @@ state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data) if (priv->active_nsp) { g_object_unref (priv->active_nsp); priv->active_nsp = NULL; - priv->null_active_nsp = FALSE; } _nm_object_queue_notify (NM_OBJECT (device), NM_DEVICE_WIMAX_ACTIVE_NSP); clear_link_status (self); @@ -634,13 +631,11 @@ demarshal_active_nsp (NMObject *object, GParamSpec *pspec, GValue *value, gpoint if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) return FALSE; - priv->null_active_nsp = FALSE; + priv->got_active_nsp = TRUE; - path = g_value_get_boxed (value); - if (path) { - if (!strcmp (path, "/")) - priv->null_active_nsp = TRUE; - else { + if (value) { + path = g_value_get_boxed (value); + if (path) { nsp = NM_WIMAX_NSP (_nm_object_cache_get (path)); if (!nsp) { connection = nm_object_get_connection (object); diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c index 4167c9a7..3b39c9ec 100644 --- a/libnm-glib/nm-device.c +++ b/libnm-glib/nm-device.c @@ -56,15 +56,18 @@ typedef struct { gboolean managed; gboolean firmware_missing; NMIP4Config *ip4_config; - gboolean null_ip4_config; + gboolean got_ip4_config; NMDHCP4Config *dhcp4_config; - gboolean null_dhcp4_config; + gboolean got_dhcp4_config; NMIP6Config *ip6_config; - gboolean null_ip6_config; + gboolean got_ip6_config; NMDHCP6Config *dhcp6_config; - gboolean null_dhcp6_config; + gboolean got_dhcp6_config; NMDeviceState state; + NMActiveConnection *active_connection; + gboolean got_active_connection; + GUdevClient *client; char *product; char *vendor; @@ -87,6 +90,7 @@ enum { PROP_DHCP6_CONFIG, PROP_IP_INTERFACE, PROP_DEVICE_TYPE, + PROP_ACTIVE_CONNECTION, LAST_PROP }; @@ -119,13 +123,11 @@ demarshal_ip4_config (NMObject *object, GParamSpec *pspec, GValue *value, gpoint if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) return FALSE; - priv->null_ip4_config = FALSE; + priv->got_ip4_config = TRUE; - path = g_value_get_boxed (value); - if (path) { - if (!strcmp (path, "/")) - priv->null_ip4_config = TRUE; - else { + if (value) { + path = g_value_get_boxed (value); + if (path) { config = NM_IP4_CONFIG (_nm_object_cache_get (path)); if (!config) { connection = nm_object_get_connection (object); @@ -157,13 +159,11 @@ demarshal_dhcp4_config (NMObject *object, GParamSpec *pspec, GValue *value, gpoi if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) return FALSE; - priv->null_dhcp4_config = FALSE; + priv->got_dhcp4_config = TRUE; - path = g_value_get_boxed (value); - if (path) { - if (!strcmp (path, "/")) - priv->null_dhcp4_config = TRUE; - else { + if (value) { + path = g_value_get_boxed (value); + if (path) { config = NM_DHCP4_CONFIG (_nm_object_cache_get (path)); if (!config) { connection = nm_object_get_connection (object); @@ -195,13 +195,11 @@ demarshal_ip6_config (NMObject *object, GParamSpec *pspec, GValue *value, gpoint if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) return FALSE; - priv->null_ip6_config = FALSE; + priv->got_ip6_config = TRUE; - path = g_value_get_boxed (value); - if (path) { - if (!strcmp (path, "/")) - priv->null_ip6_config = TRUE; - else { + if (value) { + path = g_value_get_boxed (value); + if (path) { config = NM_IP6_CONFIG (_nm_object_cache_get (path)); if (!config) { connection = nm_object_get_connection (object); @@ -233,13 +231,11 @@ demarshal_dhcp6_config (NMObject *object, GParamSpec *pspec, GValue *value, gpoi if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) return FALSE; - priv->null_dhcp6_config = FALSE; + priv->got_dhcp6_config = TRUE; - path = g_value_get_boxed (value); - if (path) { - if (!strcmp (path, "/")) - priv->null_dhcp6_config = TRUE; - else { + if (value) { + path = g_value_get_boxed (value); + if (path) { config = NM_DHCP6_CONFIG (_nm_object_cache_get (path)); if (!config) { connection = nm_object_get_connection (object); @@ -260,6 +256,42 @@ demarshal_dhcp6_config (NMObject *object, GParamSpec *pspec, GValue *value, gpoi return TRUE; } +static gboolean +demarshal_active_connection (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object); + const char *path; + NMActiveConnection *active = NULL; + DBusGConnection *connection; + + if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) + return FALSE; + + priv->got_active_connection = TRUE; + + if (value) { + path = g_value_get_boxed (value); + if (path) { + active = NM_ACTIVE_CONNECTION (_nm_object_cache_get (path)); + if (!active) { + connection = nm_object_get_connection (object); + active = NM_ACTIVE_CONNECTION (nm_active_connection_new (connection, path)); + } + } + } + + if (priv->active_connection) { + g_object_unref (priv->active_connection); + priv->active_connection = NULL; + } + + if (active) + priv->active_connection = active; + + _nm_object_queue_notify (object, NM_DEVICE_ACTIVE_CONNECTION); + return TRUE; +} + static void register_for_property_changed (NMDevice *device) { @@ -276,6 +308,7 @@ register_for_property_changed (NMDevice *device) { NM_DEVICE_DHCP4_CONFIG, demarshal_dhcp4_config, &priv->dhcp4_config }, { NM_DEVICE_IP6_CONFIG, demarshal_ip6_config, &priv->ip6_config }, { NM_DEVICE_DHCP6_CONFIG, demarshal_dhcp6_config, &priv->dhcp6_config }, + { NM_DEVICE_ACTIVE_CONNECTION,demarshal_active_connection, &priv->active_connection }, { NULL }, }; @@ -365,6 +398,8 @@ dispose (GObject *object) g_object_unref (priv->dhcp6_config); if (priv->client) g_object_unref (priv->client); + if (priv->active_connection) + g_object_unref (priv->active_connection); G_OBJECT_CLASS (nm_device_parent_class)->dispose (object); } @@ -432,6 +467,9 @@ get_property (GObject *object, case PROP_STATE: g_value_set_uint (value, nm_device_get_state (device)); break; + case PROP_ACTIVE_CONNECTION: + g_value_set_object (value, nm_device_get_active_connection (device)); + break; case PROP_PRODUCT: g_value_set_string (value, nm_device_get_product (device)); break; @@ -656,6 +694,19 @@ nm_device_class_init (NMDeviceClass *device_class) G_PARAM_READABLE)); /** + * NMDevice:active-connection: + * + * The #NMActiveConnection object that "owns" this device during activation. + **/ + g_object_class_install_property + (object_class, PROP_ACTIVE_CONNECTION, + g_param_spec_object (NM_DEVICE_ACTIVE_CONNECTION, + "ActiveConnection", + "Active Connection", + NM_TYPE_ACTIVE_CONNECTION, + G_PARAM_READABLE)); + + /** * NMDevice:vendor: * * The vendor string of the device. @@ -998,22 +1049,25 @@ nm_device_get_ip4_config (NMDevice *device) NMDevicePrivate *priv; char *path; GValue value = { 0, }; + GError *error = NULL; g_return_val_if_fail (NM_IS_DEVICE (device), NULL); priv = NM_DEVICE_GET_PRIVATE (device); - if (priv->ip4_config) + if (priv->got_ip4_config == TRUE) return priv->ip4_config; - if (priv->null_ip4_config) - return NULL; - path = _nm_object_get_object_path_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Ip4Config", NULL); - if (path) { + path = _nm_object_get_object_path_property (NM_OBJECT (device), + NM_DBUS_INTERFACE_DEVICE, + "Ip4Config", + &error); + if (error == NULL) { g_value_init (&value, DBUS_TYPE_G_OBJECT_PATH); g_value_take_boxed (&value, path); demarshal_ip4_config (NM_OBJECT (device), NULL, &value, &priv->ip4_config); g_value_unset (&value); } + g_clear_error (&error); return priv->ip4_config; } @@ -1033,22 +1087,25 @@ nm_device_get_dhcp4_config (NMDevice *device) NMDevicePrivate *priv; char *path; GValue value = { 0, }; + GError *error = NULL; g_return_val_if_fail (NM_IS_DEVICE (device), NULL); priv = NM_DEVICE_GET_PRIVATE (device); - if (priv->dhcp4_config) + if (priv->got_dhcp4_config == TRUE) return priv->dhcp4_config; - if (priv->null_dhcp4_config) - return NULL; - path = _nm_object_get_object_path_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Dhcp4Config", NULL); - if (path) { + path = _nm_object_get_object_path_property (NM_OBJECT (device), + NM_DBUS_INTERFACE_DEVICE, + "Dhcp4Config", + &error); + if (error == NULL) { g_value_init (&value, DBUS_TYPE_G_OBJECT_PATH); g_value_take_boxed (&value, path); demarshal_dhcp4_config (NM_OBJECT (device), NULL, &value, &priv->dhcp4_config); g_value_unset (&value); } + g_clear_error (&error); return priv->dhcp4_config; } @@ -1067,22 +1124,25 @@ nm_device_get_ip6_config (NMDevice *device) NMDevicePrivate *priv; char *path; GValue value = { 0, }; + GError *error = NULL; g_return_val_if_fail (NM_IS_DEVICE (device), NULL); priv = NM_DEVICE_GET_PRIVATE (device); - if (priv->ip6_config) + if (priv->got_ip6_config == TRUE) return priv->ip6_config; - if (priv->null_ip6_config) - return NULL; - path = _nm_object_get_object_path_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Ip6Config", NULL); - if (path) { + path = _nm_object_get_object_path_property (NM_OBJECT (device), + NM_DBUS_INTERFACE_DEVICE, + "Ip6Config", + &error); + if (error == NULL) { g_value_init (&value, DBUS_TYPE_G_OBJECT_PATH); g_value_take_boxed (&value, path); demarshal_ip6_config (NM_OBJECT (device), NULL, &value, &priv->ip6_config); g_value_unset (&value); } + g_clear_error (&error); return priv->ip6_config; } @@ -1102,22 +1162,25 @@ nm_device_get_dhcp6_config (NMDevice *device) NMDevicePrivate *priv; char *path; GValue value = { 0, }; + GError *error = NULL; g_return_val_if_fail (NM_IS_DEVICE (device), NULL); priv = NM_DEVICE_GET_PRIVATE (device); - if (priv->dhcp6_config) + if (priv->got_dhcp6_config == TRUE) return priv->dhcp6_config; - if (priv->null_dhcp6_config) - return NULL; - path = _nm_object_get_object_path_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Dhcp6Config", NULL); - if (path) { + path = _nm_object_get_object_path_property (NM_OBJECT (device), + NM_DBUS_INTERFACE_DEVICE, + "Dhcp6Config", + &error); + if (error == NULL) { g_value_init (&value, DBUS_TYPE_G_OBJECT_PATH); g_value_take_boxed (&value, path); demarshal_dhcp6_config (NM_OBJECT (device), NULL, &value, &priv->dhcp6_config); g_value_unset (&value); } + g_clear_error (&error); return priv->dhcp6_config; } @@ -1148,6 +1211,43 @@ nm_device_get_state (NMDevice *device) return priv->state; } +/** + * nm_device_get_active_connection: + * @device: a #NMDevice + * + * Gets the #NMActiveConnection object which owns this device during activation. + * + * Returns: the #NMActiveConnection + **/ +NMActiveConnection * +nm_device_get_active_connection (NMDevice *device) +{ + NMDevicePrivate *priv; + char *path; + GValue value = { 0, }; + GError *error = NULL; + + g_return_val_if_fail (NM_IS_DEVICE (device), NULL); + + priv = NM_DEVICE_GET_PRIVATE (device); + if (priv->got_active_connection == TRUE) + return priv->active_connection; + + path = _nm_object_get_object_path_property (NM_OBJECT (device), + NM_DBUS_INTERFACE_DEVICE, + "ActiveConnection", + &error); + if (error == NULL) { + g_value_init (&value, DBUS_TYPE_G_OBJECT_PATH); + g_value_take_boxed (&value, path); + demarshal_active_connection (NM_OBJECT (device), NULL, &value, &priv->active_connection); + g_value_unset (&value); + } + g_clear_error (&error); + + return priv->active_connection; +} + /* From hostap, Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi> */ static int hex2num (char c) @@ -1203,7 +1303,7 @@ get_decoded_property (GUdevDevice *device, const char *property) } static void -nm_device_update_description (NMDevice *device) +_device_update_description (NMDevice *device) { NMDevicePrivate *priv; const char *subsys[3] = { "net", "tty", NULL }; @@ -1318,7 +1418,7 @@ nm_device_get_product (NMDevice *device) priv = NM_DEVICE_GET_PRIVATE (device); if (!priv->product) - nm_device_update_description (device); + _device_update_description (device); return priv->product; } @@ -1340,7 +1440,7 @@ nm_device_get_vendor (NMDevice *device) priv = NM_DEVICE_GET_PRIVATE (device); if (!priv->vendor) - nm_device_update_description (device); + _device_update_description (device); return priv->vendor; } diff --git a/libnm-glib/nm-device.h b/libnm-glib/nm-device.h index 9d1c6bdb..e21e71b1 100644 --- a/libnm-glib/nm-device.h +++ b/libnm-glib/nm-device.h @@ -34,6 +34,7 @@ #include "nm-ip6-config.h" #include "nm-dhcp6-config.h" #include "nm-connection.h" +#include "nm-active-connection.h" G_BEGIN_DECLS @@ -57,6 +58,7 @@ G_BEGIN_DECLS #define NM_DEVICE_IP6_CONFIG "ip6-config" #define NM_DEVICE_DHCP6_CONFIG "dhcp6-config" #define NM_DEVICE_STATE "state" +#define NM_DEVICE_ACTIVE_CONNECTION "active-connection" #define NM_DEVICE_VENDOR "vendor" #define NM_DEVICE_PRODUCT "product" @@ -102,6 +104,7 @@ NMDHCP4Config * nm_device_get_dhcp4_config (NMDevice *device); NMIP6Config * nm_device_get_ip6_config (NMDevice *device); NMDHCP6Config * nm_device_get_dhcp6_config (NMDevice *device); NMDeviceState nm_device_get_state (NMDevice *device); +NMActiveConnection * nm_device_get_active_connection(NMDevice *device); const char * nm_device_get_product (NMDevice *device); const char * nm_device_get_vendor (NMDevice *device); diff --git a/libnm-glib/nm-object.c b/libnm-glib/nm-object.c index 0b88be2c..614f6afc 100644 --- a/libnm-glib/nm-object.c +++ b/libnm-glib/nm-object.c @@ -333,6 +333,7 @@ handle_property_changed (gpointer key, gpointer data, gpointer user_data) GParamSpec *pspec; gboolean success = FALSE, found = FALSE; GSList *iter; + GValue *value = data; prop_name = wincaps_to_dash ((char *) key); pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (self)), prop_name); @@ -344,12 +345,19 @@ handle_property_changed (gpointer key, gpointer data, gpointer user_data) goto out; } - /* Iterate through the object and it's parents to find the property */ + /* Iterate through the object and its parents to find the property */ for (iter = priv->pcs; iter; iter = g_slist_next (iter)) { pci = g_hash_table_lookup ((GHashTable *) iter->data, prop_name); if (pci) { found = TRUE; - success = (*(pci->func)) (self, pspec, (GValue *) data, pci->field); + + /* Handle NULL object paths */ + if (G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) { + if (g_strcmp0 (g_value_get_boxed (value), "/") == 0) + value = NULL; + } + + success = (*(pci->func)) (self, pspec, value, pci->field); if (success) break; } @@ -453,6 +461,11 @@ _nm_object_demarshal_generic (NMObject *object, char **param = (char **) field; g_free (*param); *param = g_strdup (g_value_get_boxed (value)); + /* Handle "NULL" object paths */ + if (g_strcmp0 (*param, "/") == 0) { + g_free (*param); + *param = NULL; + } } else { success = FALSE; goto done; @@ -558,13 +571,18 @@ _nm_object_get_string_property (NMObject *object, GError **error) { char *str = NULL; + const char *tmp; GValue value = {0,}; if (_nm_object_get_property (object, interface, prop_name, &value, error)) { if (G_VALUE_HOLDS_STRING (&value)) str = g_strdup (g_value_get_string (&value)); - else if (G_VALUE_HOLDS (&value, DBUS_TYPE_G_OBJECT_PATH)) - str = g_strdup (g_value_get_boxed (&value)); + else if (G_VALUE_HOLDS (&value, DBUS_TYPE_G_OBJECT_PATH)) { + tmp = g_value_get_boxed (&value); + /* Handle "NULL" object paths */ + if (g_strcmp0 (tmp, "/") != 0) + str = g_strdup (tmp); + } g_value_unset (&value); } @@ -578,10 +596,13 @@ _nm_object_get_object_path_property (NMObject *object, GError **error) { char *path = NULL; + const char *tmp; GValue value = {0,}; if (_nm_object_get_property (object, interface, prop_name, &value, error)) { - path = g_strdup (g_value_get_boxed (&value)); + tmp = g_value_get_boxed (&value); + if (g_strcmp0 (tmp, "/") != 0) + path = g_strdup (tmp); g_value_unset (&value); } diff --git a/libnm-glib/nm-types.c b/libnm-glib/nm-types.c index a2d6d2b4..6d76787d 100644 --- a/libnm-glib/nm-types.c +++ b/libnm-glib/nm-types.c @@ -31,7 +31,7 @@ #include "nm-setting-ip6-config.h" static gpointer -nm_ssid_copy (GByteArray *src) +_nm_ssid_copy (GByteArray *src) { GByteArray *dest; @@ -41,7 +41,7 @@ nm_ssid_copy (GByteArray *src) } static void -nm_ssid_free (GByteArray *ssid) +_nm_ssid_free (GByteArray *ssid) { g_byte_array_free (ssid, TRUE); } @@ -53,8 +53,8 @@ nm_ssid_get_type (void) if (our_type == 0) our_type = g_boxed_type_register_static (g_intern_static_string ("NMSsid"), - (GBoxedCopyFunc) nm_ssid_copy, - (GBoxedFreeFunc) nm_ssid_free); + (GBoxedCopyFunc) _nm_ssid_copy, + (GBoxedFreeFunc) _nm_ssid_free); return our_type; } @@ -84,7 +84,7 @@ _nm_ssid_demarshal (GValue *value, GByteArray **dest) /*****************************/ static gpointer -nm_uint_array_copy (GArray *src) +_nm_uint_array_copy (GArray *src) { GArray *dest; @@ -94,7 +94,7 @@ nm_uint_array_copy (GArray *src) } static void -nm_uint_array_free (GArray *array) +_nm_uint_array_free (GArray *array) { g_array_free (array, TRUE); } @@ -106,8 +106,8 @@ nm_uint_array_get_type (void) if (our_type == 0) our_type = g_boxed_type_register_static (g_intern_static_string ("NMUintArray"), - (GBoxedCopyFunc) nm_uint_array_copy, - (GBoxedFreeFunc) nm_uint_array_free); + (GBoxedCopyFunc) _nm_uint_array_copy, + (GBoxedFreeFunc) _nm_uint_array_free); return our_type; } @@ -136,7 +136,7 @@ _nm_uint_array_demarshal (GValue *value, GArray **dest) /*****************************/ static gpointer -nm_string_array_copy (GPtrArray *src) +_nm_string_array_copy (GPtrArray *src) { GPtrArray *dest; int i; @@ -148,7 +148,7 @@ nm_string_array_copy (GPtrArray *src) } static void -nm_string_array_free (GPtrArray *array) +_nm_string_array_free (GPtrArray *array) { int i; @@ -164,8 +164,8 @@ nm_string_array_get_type (void) if (our_type == 0) our_type = g_boxed_type_register_static (g_intern_static_string ("NMStringArray"), - (GBoxedCopyFunc) nm_string_array_copy, - (GBoxedFreeFunc) nm_string_array_free); + (GBoxedCopyFunc) _nm_string_array_copy, + (GBoxedFreeFunc) _nm_string_array_free); return our_type; } @@ -197,7 +197,7 @@ _nm_string_array_demarshal (GValue *value, GPtrArray **dest) /*****************************/ static gpointer -nm_object_array_copy (GPtrArray *src) +_nm_object_array_copy (GPtrArray *src) { GPtrArray *dest; int i; @@ -209,7 +209,7 @@ nm_object_array_copy (GPtrArray *src) } static void -nm_object_array_free (GPtrArray *array) +_nm_object_array_free (GPtrArray *array) { int i; @@ -225,8 +225,8 @@ nm_object_array_get_type (void) if (our_type == 0) our_type = g_boxed_type_register_static (g_intern_static_string ("NMObjectArray"), - (GBoxedCopyFunc) nm_object_array_copy, - (GBoxedFreeFunc) nm_object_array_free); + (GBoxedCopyFunc) _nm_object_array_copy, + (GBoxedFreeFunc) _nm_object_array_free); return our_type; } @@ -279,7 +279,7 @@ _nm_object_array_demarshal (GValue *value, /*****************************/ static gpointer -nm_ip6_address_object_array_copy (GPtrArray *src) +_nm_ip6_address_object_array_copy (GPtrArray *src) { GPtrArray *dest; int i; @@ -291,7 +291,7 @@ nm_ip6_address_object_array_copy (GPtrArray *src) } static void -nm_ip6_address_object_array_free (GPtrArray *array) +_nm_ip6_address_object_array_free (GPtrArray *array) { int i; @@ -307,15 +307,15 @@ nm_ip6_address_object_array_get_type (void) if (our_type == 0) our_type = g_boxed_type_register_static (g_intern_static_string ("NMIP6AddressObjectArray"), - (GBoxedCopyFunc) nm_ip6_address_object_array_copy, - (GBoxedFreeFunc) nm_ip6_address_object_array_free); + (GBoxedCopyFunc) _nm_ip6_address_object_array_copy, + (GBoxedFreeFunc) _nm_ip6_address_object_array_free); return our_type; } /*****************************/ static gpointer -nm_ip6_address_array_copy (GPtrArray *src) +_nm_ip6_address_array_copy (GPtrArray *src) { GPtrArray *dest; int i; @@ -333,7 +333,7 @@ nm_ip6_address_array_copy (GPtrArray *src) } static void -nm_ip6_address_array_free (GPtrArray *array) +_nm_ip6_address_array_free (GPtrArray *array) { int i; @@ -349,8 +349,8 @@ nm_ip6_address_array_get_type (void) if (our_type == 0) our_type = g_boxed_type_register_static (g_intern_static_string ("NMIP6AddressArray"), - (GBoxedCopyFunc) nm_ip6_address_array_copy, - (GBoxedFreeFunc) nm_ip6_address_array_free); + (GBoxedCopyFunc) _nm_ip6_address_array_copy, + (GBoxedFreeFunc) _nm_ip6_address_array_free); return our_type; } @@ -388,7 +388,7 @@ _nm_ip6_address_array_demarshal (GValue *value, GSList **dest) /*****************************/ static gpointer -nm_ip6_route_object_array_copy (GPtrArray *src) +_nm_ip6_route_object_array_copy (GPtrArray *src) { GPtrArray *dest; int i; @@ -400,7 +400,7 @@ nm_ip6_route_object_array_copy (GPtrArray *src) } static void -nm_ip6_route_object_array_free (GPtrArray *array) +_nm_ip6_route_object_array_free (GPtrArray *array) { int i; @@ -416,8 +416,8 @@ nm_ip6_route_object_array_get_type (void) if (our_type == 0) our_type = g_boxed_type_register_static (g_intern_static_string ("NMIP6RouteObjectArray"), - (GBoxedCopyFunc) nm_ip6_route_object_array_copy, - (GBoxedFreeFunc) nm_ip6_route_object_array_free); + (GBoxedCopyFunc) _nm_ip6_route_object_array_copy, + (GBoxedFreeFunc) _nm_ip6_route_object_array_free); return our_type; } |