summary refs log tree commit diff
path: root/libnm-glib
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2015-08-28 01:13:48 +0200
committerMichael Biebl <biebl@debian.org>2015-08-28 01:13:48 +0200
commit81836c2d44802b4cca833d7775dd627e0797a7e2 (patch)
tree91154e6cefc0465306603f51ec0010d9963bbea4 /libnm-glib
parent50a58f0fabd8a34c1b6108a107e08abe3c1ccd24 (diff)
Imported Upstream version 1.0.6 upstream/1.0.6
Diffstat (limited to 'libnm-glib')
-rw-r--r--libnm-glib/libnm-glib.ver1
-rw-r--r--libnm-glib/nm-access-point.c44
-rw-r--r--libnm-glib/nm-access-point.h3
-rw-r--r--libnm-glib/nm-vpn-plugin.c93
-rw-r--r--libnm-glib/tests/common.c2
5 files changed, 87 insertions, 56 deletions
diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver
index 9219c4a2..dc982e56 100644
--- a/libnm-glib/libnm-glib.ver
+++ b/libnm-glib/libnm-glib.ver
@@ -11,6 +11,7 @@ global:
 	nm_access_point_get_flags;
 	nm_access_point_get_frequency;
 	nm_access_point_get_hw_address;
+	nm_access_point_get_last_seen;
 	nm_access_point_get_max_bitrate;
 	nm_access_point_get_mode;
 	nm_access_point_get_rsn_flags;
diff --git a/libnm-glib/nm-access-point.c b/libnm-glib/nm-access-point.c
index abf61cc9..b980943a 100644
--- a/libnm-glib/nm-access-point.c
+++ b/libnm-glib/nm-access-point.c
@@ -53,6 +53,7 @@ typedef struct {
 	NM80211Mode mode;
 	guint32 max_bitrate;
 	guint8 strength;
+	gint32 last_seen;
 } NMAccessPointPrivate;
 
 enum {
@@ -67,6 +68,7 @@ enum {
 	PROP_MAX_BITRATE,
 	PROP_STRENGTH,
 	PROP_BSSID,
+	PROP_LAST_SEEN,
 
 	LAST_PROP
 };
@@ -266,6 +268,27 @@ nm_access_point_get_strength (NMAccessPoint *ap)
 }
 
 /**
+ * nm_access_point_get_last_seen:
+ * @ap: a #NMAccessPoint
+ *
+ * Returns the timestamp (in CLOCK_BOOTTIME seconds) for the last time the
+ * access point was found in scan results.  A value of -1 means the access
+ * point has not been found in a scan.
+ *
+ * Returns: the last seen time in seconds
+ *
+ * Since: 1.0.6
+ **/
+gint32
+nm_access_point_get_last_seen (NMAccessPoint *ap)
+{
+	g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), -1);
+
+	_nm_object_ensure_inited (NM_OBJECT (ap));
+	return NM_ACCESS_POINT_GET_PRIVATE (ap)->last_seen;
+}
+
+/**
  * nm_access_point_connection_valid:
  * @ap: an #NMAccessPoint to validate @connection against
  * @connection: an #NMConnection to validate against @ap
@@ -416,6 +439,7 @@ nm_access_point_filter_connections (NMAccessPoint *ap, const GSList *connections
 static void
 nm_access_point_init (NMAccessPoint *ap)
 {
+	NM_ACCESS_POINT_GET_PRIVATE (ap)->last_seen = -1;
 }
 
 static void
@@ -482,6 +506,9 @@ get_property (GObject *object,
 	case PROP_STRENGTH:
 		g_value_set_uchar (value, nm_access_point_get_strength (ap));
 		break;
+	case PROP_LAST_SEEN:
+		g_value_set_int (value, nm_access_point_get_last_seen (ap));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -512,6 +539,7 @@ register_properties (NMAccessPoint *ap)
 		{ NM_ACCESS_POINT_MODE,        &priv->mode },
 		{ NM_ACCESS_POINT_MAX_BITRATE, &priv->max_bitrate },
 		{ NM_ACCESS_POINT_STRENGTH,    &priv->strength },
+		{ NM_ACCESS_POINT_LAST_SEEN,   &priv->last_seen },
 		{ NULL },
 	};
 
@@ -671,4 +699,20 @@ nm_access_point_class_init (NMAccessPointClass *ap_class)
 		                     0, G_MAXUINT8, 0,
 		                     G_PARAM_READABLE |
 		                     G_PARAM_STATIC_STRINGS));
+
+	/**
+	 * NMAccessPoint:last-seen:
+	 *
+	 * The timestamp (in CLOCK_BOOTTIME seconds) for the last time the
+	 * access point was found in scan results.  A value of -1 means the
+	 * access point has not been found in a scan.
+	 *
+	 * Since: 1.0.6
+	 **/
+	g_object_class_install_property
+		(object_class, PROP_LAST_SEEN,
+		 g_param_spec_int (NM_ACCESS_POINT_LAST_SEEN, "", "",
+		                   -1, G_MAXINT, -1,
+		                   G_PARAM_READABLE |
+		                   G_PARAM_STATIC_STRINGS));
 }
diff --git a/libnm-glib/nm-access-point.h b/libnm-glib/nm-access-point.h
index d3150f8e..57bd6ed1 100644
--- a/libnm-glib/nm-access-point.h
+++ b/libnm-glib/nm-access-point.h
@@ -46,6 +46,7 @@ G_BEGIN_DECLS
 #define NM_ACCESS_POINT_MODE        "mode"
 #define NM_ACCESS_POINT_MAX_BITRATE "max-bitrate"
 #define NM_ACCESS_POINT_STRENGTH    "strength"
+#define NM_ACCESS_POINT_LAST_SEEN   "last-seen"
 
 /* DEPRECATED */
 #define NM_ACCESS_POINT_HW_ADDRESS  "hw-address"
@@ -80,6 +81,8 @@ guint32                nm_access_point_get_frequency    (NMAccessPoint *ap);
 NM80211Mode            nm_access_point_get_mode         (NMAccessPoint *ap);
 guint32                nm_access_point_get_max_bitrate  (NMAccessPoint *ap);
 guint8                 nm_access_point_get_strength     (NMAccessPoint *ap);
+NM_AVAILABLE_IN_1_0_6
+gint32                 nm_access_point_get_last_seen    (NMAccessPoint *ap);
 
 GSList *               nm_access_point_filter_connections (NMAccessPoint *ap,
                                                            const GSList *connections);
diff --git a/libnm-glib/nm-vpn-plugin.c b/libnm-glib/nm-vpn-plugin.c
index 7848c131..f40ea800 100644
--- a/libnm-glib/nm-vpn-plugin.c
+++ b/libnm-glib/nm-vpn-plugin.c
@@ -28,6 +28,7 @@
 #include "nm-utils.h"
 #include "nm-connection.h"
 #include "nm-dbus-glib-types.h"
+#include "nm-macros-internal.h"
 
 static gboolean impl_vpn_plugin_connect    (NMVPNPlugin *plugin,
                                             GHashTable *connection,
@@ -257,6 +258,7 @@ connect_timer_expired (gpointer data)
 	NMVPNPlugin *plugin = NM_VPN_PLUGIN (data);
 	GError *err = NULL;
 
+	NM_VPN_PLUGIN_GET_PRIVATE (plugin)->connect_timer = 0;
 	g_message ("Connect timer expired, disconnecting.");
 	nm_vpn_plugin_disconnect (plugin, &err);
 	if (err) {
@@ -264,26 +266,38 @@ connect_timer_expired (gpointer data)
 		g_error_free (err);
 	}
 
-	return FALSE;
+	return G_SOURCE_REMOVE;
 }
 
 static gboolean
 quit_timer_expired (gpointer data)
 {
-	NMVPNPlugin *plugin = NM_VPN_PLUGIN (data);
+	NMVPNPlugin *self = NM_VPN_PLUGIN (data);
+
+	NM_VPN_PLUGIN_GET_PRIVATE (self)->quit_timer = 0;
+	nm_vpn_plugin_emit_quit (self);
+	return G_SOURCE_REMOVE;
+}
 
-	nm_vpn_plugin_emit_quit (plugin);
+static void
+schedule_quit_timer (NMVPNPlugin *self)
+{
+	NMVPNPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (self);
 
-	return FALSE;
+	nm_clear_g_source (&priv->quit_timer);
+	priv->quit_timer = g_timeout_add_seconds (NM_VPN_PLUGIN_QUIT_TIMER,
+	                                          quit_timer_expired,
+	                                          self);
 }
 
 static gboolean
 fail_stop (gpointer data)
 {
-	NMVPNPlugin *plugin = NM_VPN_PLUGIN (data);
+	NMVPNPlugin *self = NM_VPN_PLUGIN (data);
 
-	nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPED);
-	return FALSE;
+	NM_VPN_PLUGIN_GET_PRIVATE (self)->fail_stop_id = 0;
+	nm_vpn_plugin_set_state (self, NM_VPN_SERVICE_STATE_STOPPED);
+	return G_SOURCE_REMOVE;
 }
 
 static void
@@ -291,8 +305,7 @@ schedule_fail_stop (NMVPNPlugin *plugin)
 {
 	NMVPNPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
 
-	if (priv->fail_stop_id)
-		g_source_remove (priv->fail_stop_id);
+	nm_clear_g_source (&priv->fail_stop_id);
 	priv->fail_stop_id = g_idle_add (fail_stop, plugin);
 }
 
@@ -409,21 +422,11 @@ nm_vpn_plugin_set_ip6_config (NMVPNPlugin *plugin,
 }
 
 static void
-connect_timer_removed (gpointer data)
-{
-	NM_VPN_PLUGIN_GET_PRIVATE (data)->connect_timer = 0;
-}
-
-static void
 connect_timer_start (NMVPNPlugin *plugin)
 {
 	NMVPNPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
 
-	priv->connect_timer = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
-	                                                  60,
-	                                                  connect_timer_expired,
-	                                                  plugin,
-	                                                  connect_timer_removed);
+	priv->connect_timer = g_timeout_add_seconds (60, connect_timer_expired, plugin);
 }
 
 static gboolean
@@ -547,6 +550,11 @@ impl_vpn_plugin_need_secrets (NMVPNPlugin *plugin,
 
 	ret = TRUE;
 	if (needed) {
+		/* Push back the quit timer so the VPN plugin doesn't quit in the
+		 * middle of asking the user for secrets.
+		 */
+		schedule_quit_timer (plugin);
+
 		g_assert (sn);
 		*setting_name = g_strdup (sn);
 	} else {
@@ -638,8 +646,7 @@ nm_vpn_plugin_secrets_required (NMVPNPlugin *plugin,
 	/* Cancel the connect timer since secrets might take a while.  It'll
 	 * get restarted when the secrets come back via NewSecrets().
 	 */
-	if (priv->connect_timer)
-		g_source_remove (priv->connect_timer);
+	nm_clear_g_source (&priv->connect_timer);
 
 	g_signal_emit (plugin, signals[SECRETS_REQUIRED], 0, message, hints);
 }
@@ -848,10 +855,9 @@ dispose (GObject *object)
 	NMVPNServiceState state;
 	GError *err = NULL;
 
-	if (priv->fail_stop_id) {
-		g_source_remove (priv->fail_stop_id);
-		priv->fail_stop_id = 0;
-	}
+	nm_clear_g_source (&priv->fail_stop_id);
+	nm_clear_g_source (&priv->quit_timer);
+	nm_clear_g_source (&priv->connect_timer);
 
 	state = nm_vpn_plugin_get_state (plugin);
 
@@ -889,46 +895,23 @@ finalize (GObject *object)
 }
 
 static void
-quit_timer_removed (gpointer data)
-{
-	NM_VPN_PLUGIN_GET_PRIVATE (data)->quit_timer = 0;
-}
-
-static void
 state_changed (NMVPNPlugin *plugin, NMVPNServiceState state)
 {
 	NMVPNPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
 
 	switch (state) {
 	case NM_VPN_SERVICE_STATE_STARTING:
-		/* Remove the quit timer. */
-		if (priv->quit_timer)
-			g_source_remove (priv->quit_timer);
-
-		if (priv->fail_stop_id) {
-			g_source_remove (priv->fail_stop_id);
-			priv->fail_stop_id = 0;
-		}
+		nm_clear_g_source (&priv->quit_timer);
+		nm_clear_g_source (&priv->fail_stop_id);
 		break;
 	case NM_VPN_SERVICE_STATE_STOPPED:
-		priv->quit_timer = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
-		                                               NM_VPN_PLUGIN_QUIT_TIMER,
-		                                               quit_timer_expired,
-		                                               plugin,
-		                                               quit_timer_removed);
+		schedule_quit_timer (plugin);
 		break;
 	default:
 		/* Clean up all timers we might have set up. */
-		if (priv->connect_timer)
-			g_source_remove (priv->connect_timer);
-
-		if (priv->quit_timer)
-			g_source_remove (priv->quit_timer);
-
-		if (priv->fail_stop_id) {
-			g_source_remove (priv->fail_stop_id);
-			priv->fail_stop_id = 0;
-		}
+		nm_clear_g_source (&priv->connect_timer);
+		nm_clear_g_source (&priv->quit_timer);
+		nm_clear_g_source (&priv->fail_stop_id);
 		break;
 	}
 }
diff --git a/libnm-glib/tests/common.c b/libnm-glib/tests/common.c
index 540d43af..f071fb5b 100644
--- a/libnm-glib/tests/common.c
+++ b/libnm-glib/tests/common.c
@@ -75,7 +75,7 @@ nm_test_service_init (void)
 	g_assert_no_error (error);
 
 	/* Wait until the service is registered on the bus */
-	for (i = 100; i > 0; i--) {
+	for (i = 1000; i > 0; i--) {
 		if (name_exists (info->bus, "org.freedesktop.NetworkManager"))
 			break;
 		g_usleep (G_USEC_PER_SEC / 50);