[PATCH 2/2] wifi: expose the last_seen property for a NMAccessPoint
- From: Mathieu Trudel-Lapierre <mathieu trudel-lapierre canonical com>
- To: networkmanager-list gnome org
- Cc: Mathieu Trudel-Lapierre <mathieu trudel-lapierre canonical com>
- Subject: [PATCH 2/2] wifi: expose the last_seen property for a NMAccessPoint
- Date: Tue, 21 Apr 2015 11:48:26 -0400
---
introspection/nm-access-point.xml | 3 +++
libnm-glib/libnm-glib.ver | 1 +
libnm-glib/nm-access-point.c | 36 ++++++++++++++++++++++++++++++++++++
libnm-glib/nm-access-point.h | 2 ++
src/devices/wifi/nm-device-wifi.c | 2 +-
src/devices/wifi/nm-wifi-ap.c | 38 +++++++++++++++++++++++++++++++-------
src/devices/wifi/nm-wifi-ap.h | 5 +++--
7 files changed, 77 insertions(+), 10 deletions(-)
diff --git a/introspection/nm-access-point.xml b/introspection/nm-access-point.xml
index 21f238f..6bb6152 100644
--- a/introspection/nm-access-point.xml
+++ b/introspection/nm-access-point.xml
@@ -30,6 +30,9 @@
<property name="Strength" type="y" access="read">
<tp:docstring>The current signal quality of the access point, in percent.</tp:docstring>
</property>
+ <property name="LastSeen" type="u" access="read">
+ <tp:docstring>The timestamp (in CLOCK_BOOTTIME seconds) for the last time the access point was found
in scan results.</tp:docstring>
+ </property>
<signal name="PropertiesChanged">
<arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver
index 9219c4a..dc982e5 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 abf61cc..39a0c1e 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;
+ guint32 last_seen;
} NMAccessPointPrivate;
enum {
@@ -67,6 +68,7 @@ enum {
PROP_MAX_BITRATE,
PROP_STRENGTH,
PROP_BSSID,
+ PROP_LAST_SEEN,
LAST_PROP
};
@@ -266,6 +268,23 @@ nm_access_point_get_strength (NMAccessPoint *ap)
}
/**
+ * nm_access_point_get_last_seen:
+ * @ap: a #NMAccessPoint
+ *
+ * Gets the last seen timestamp for the access point.
+ *
+ * Returns: the last seen time in seconds
+ **/
+guint32
+nm_access_point_get_last_seen (NMAccessPoint *ap)
+{
+ g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0);
+
+ _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
@@ -482,6 +501,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_uint (value, nm_access_point_get_last_seen (ap));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -512,6 +534,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 +694,17 @@ nm_access_point_class_init (NMAccessPointClass *ap_class)
0, G_MAXUINT8, 0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NMAccessPoint:last-seen:
+ *
+ * The last seen timestamp of the access point.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_LAST_SEEN,
+ g_param_spec_uint (NM_ACCESS_POINT_LAST_SEEN,
+ "Last Seen",
+ "Last Seen",
+ 0, G_MAXUINT32, 0,
+ G_PARAM_READABLE));
}
diff --git a/libnm-glib/nm-access-point.h b/libnm-glib/nm-access-point.h
index d3150f8..6c7a049 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,7 @@ 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);
+guint32 nm_access_point_get_last_seen (NMAccessPoint *ap);
GSList * nm_access_point_filter_connections (NMAccessPoint *ap,
const GSList *connections);
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index 1361bd8..989b755 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -1558,7 +1558,7 @@ cull_scan_list (NMDeviceWifi *self)
g_hash_table_iter_init (&iter, priv->aps);
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &ap)) {
const guint prune_interval_s = SCAN_INTERVAL_MAX * 3;
- gint32 last_seen;
+ guint32 last_seen;
/* Don't cull the associated AP or manually created APs */
if (ap == priv->current_ap)
diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c
index c891fc7..ad2631d 100644
--- a/src/devices/wifi/nm-wifi-ap.c
+++ b/src/devices/wifi/nm-wifi-ap.c
@@ -62,7 +62,7 @@ typedef struct
/* Non-scanned attributes */
gboolean fake; /* Whether or not the AP is from a scan */
gboolean hotspot; /* Whether the AP is a local device's hotspot network */
- gint32 last_seen; /* Timestamp when the AP was seen lastly (obtained via
nm_utils_get_monotonic_timestamp_s()) */
+ guint32 last_seen; /* Timestamp when the AP was seen lastly (obtained via
nm_utils_get_monotonic_timestamp_s()) */
} NMAccessPointPrivate;
#define NM_AP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP, NMAccessPointPrivate))
@@ -80,6 +80,7 @@ enum {
PROP_MODE,
PROP_MAX_BITRATE,
PROP_STRENGTH,
+ PROP_LAST_SEEN,
LAST_PROP
};
@@ -147,6 +148,9 @@ set_property (GObject *object, guint prop_id,
break;
case PROP_HW_ADDRESS:
break;
+ case PROP_LAST_SEEN:
+ nm_ap_set_last_seen (ap, g_value_get_uint (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -195,6 +199,11 @@ get_property (GObject *object, guint prop_id,
case PROP_STRENGTH:
g_value_set_schar (value, priv->strength);
break;
+ case PROP_LAST_SEEN:
+ g_value_set_uint (value,
+ nm_utils_monotonic_timestamp_as_boottime (priv->last_seen,
+ NM_UTILS_NS_PER_SECOND));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -294,6 +303,14 @@ nm_ap_class_init (NMAccessPointClass *ap_class)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_LAST_SEEN,
+ g_param_spec_uint (NM_AP_LAST_SEEN,
+ "Last Seen",
+ "Last Seen",
+ 0, G_MAXUINT32, 0,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (ap_class),
&dbus_glib_nm_access_point_object_info);
@@ -460,7 +477,7 @@ nm_ap_update_from_properties (NMAccessPoint *ap,
if (!nm_ap_get_supplicant_path (ap))
nm_ap_set_supplicant_path (ap, supplicant_path);
- nm_ap_set_last_seen (ap, nm_utils_get_monotonic_timestamp_s ());
+ nm_ap_set_last_seen (ap, (guint32) nm_utils_get_monotonic_timestamp_s());
g_object_thaw_notify (G_OBJECT (ap));
}
@@ -718,7 +735,7 @@ nm_ap_dump (NMAccessPoint *ap, const char *prefix)
nm_log_dbg (LOGD_WIFI_SCAN, " quality %d", priv->strength);
nm_log_dbg (LOGD_WIFI_SCAN, " frequency %d", priv->freq);
nm_log_dbg (LOGD_WIFI_SCAN, " max rate %d", priv->max_bitrate);
- nm_log_dbg (LOGD_WIFI_SCAN, " last-seen %d", (int) priv->last_seen);
+ nm_log_dbg (LOGD_WIFI_SCAN, " last-seen %d", priv->last_seen);
}
const char *
@@ -1052,20 +1069,27 @@ void nm_ap_set_fake (NMAccessPoint *ap, gboolean fake)
* APs older than a certain date are dropped from the list.
*
*/
-gint32
+guint32
nm_ap_get_last_seen (const NMAccessPoint *ap)
{
- g_return_val_if_fail (NM_IS_AP (ap), FALSE);
+ g_return_val_if_fail (NM_IS_AP (ap), 0);
return NM_AP_GET_PRIVATE (ap)->last_seen;
}
void
-nm_ap_set_last_seen (NMAccessPoint *ap, gint32 last_seen)
+nm_ap_set_last_seen (NMAccessPoint *ap, guint32 last_seen)
{
+ NMAccessPointPrivate *priv;
+
g_return_if_fail (NM_IS_AP (ap));
- NM_AP_GET_PRIVATE (ap)->last_seen = last_seen;
+ priv = NM_AP_GET_PRIVATE (ap);
+
+ if (priv->last_seen != last_seen) {
+ priv->last_seen = last_seen;
+ g_object_notify (G_OBJECT (ap), NM_AP_LAST_SEEN);
+ }
}
static guint
diff --git a/src/devices/wifi/nm-wifi-ap.h b/src/devices/wifi/nm-wifi-ap.h
index bcbf7ee..fbf4231 100644
--- a/src/devices/wifi/nm-wifi-ap.h
+++ b/src/devices/wifi/nm-wifi-ap.h
@@ -43,6 +43,7 @@
#define NM_AP_MODE "mode"
#define NM_AP_MAX_BITRATE "max-bitrate"
#define NM_AP_STRENGTH "strength"
+#define NM_AP_LAST_SEEN "last-seen"
typedef struct {
GObject parent;
@@ -104,8 +105,8 @@ void nm_ap_set_max_bitrate (NMAccessPoint *ap, guint32 bitrate);
gboolean nm_ap_get_fake (const NMAccessPoint *ap);
void nm_ap_set_fake (NMAccessPoint *ap, gboolean fake);
-gint32 nm_ap_get_last_seen (const NMAccessPoint *ap);
-void nm_ap_set_last_seen (NMAccessPoint *ap, gint32 last_seen);
+guint32 nm_ap_get_last_seen (const NMAccessPoint *ap);
+void nm_ap_set_last_seen (NMAccessPoint *ap, guint32 last_seen);
gboolean nm_ap_check_compatible (NMAccessPoint *self,
NMConnection *connection);
--
2.1.4
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]