summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>2015-04-21 11:48:26 -0400
committerDan Williams <dcbw@redhat.com>2015-08-07 12:38:24 -0500
commitcdb8a44a6e669d11e1d7f68cbdb2e576ef3e6eb4 (patch)
tree85a3b4999d474cae758e9bcbf006c00dc3e868d5
parent1b62ff1d2423b5736b15c1a346be0c364c6fd2a7 (diff)
downloadNetworkManager-cdb8a44a6e669d11e1d7f68cbdb2e576ef3e6eb4.tar.gz
wifi: expose the last_seen property for a NMAccessPoint
https://mail.gnome.org/archives/networkmanager-list/2015-April/msg00053.html
-rw-r--r--introspection/nm-access-point.xml7
-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.h2
-rw-r--r--src/devices/wifi/nm-wifi-ap.c25
-rw-r--r--src/devices/wifi/nm-wifi-ap.h1
6 files changed, 78 insertions, 2 deletions
diff --git a/introspection/nm-access-point.xml b/introspection/nm-access-point.xml
index 21f238ffaf..ef5af6ab77 100644
--- a/introspection/nm-access-point.xml
+++ b/introspection/nm-access-point.xml
@@ -30,6 +30,13 @@
<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="i" access="read">
+ <tp:docstring>
+ 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 never been 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 9219c4a2bb..dc982e566b 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 abf61cc923..b980943af0 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 d3150f8eee..d8efad1f93 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);
+gint32 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-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c
index d70dd9a6d2..1485f4c107 100644
--- a/src/devices/wifi/nm-wifi-ap.c
+++ b/src/devices/wifi/nm-wifi-ap.c
@@ -79,6 +79,7 @@ enum {
PROP_MODE,
PROP_MAX_BITRATE,
PROP_STRENGTH,
+ PROP_LAST_SEEN,
LAST_PROP
};
@@ -195,6 +196,12 @@ 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_int (value,
+ priv->last_seen > 0
+ ? (gint) nm_utils_monotonic_timestamp_as_boottime (priv->last_seen, NM_UTILS_NS_PER_SECOND)
+ : -1);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -294,6 +301,13 @@ 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_int (NM_AP_LAST_SEEN, "", "",
+ -1, G_MAXINT, -1,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (ap_class),
&dbus_glib_nm_access_point_object_info);
@@ -1056,7 +1070,7 @@ void nm_ap_set_broadcast (NMAccessPoint *ap, gboolean broadcast)
gint32
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;
}
@@ -1064,9 +1078,16 @@ nm_ap_get_last_seen (const NMAccessPoint *ap)
void
nm_ap_set_last_seen (NMAccessPoint *ap, gint32 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);
+ }
}
gboolean
diff --git a/src/devices/wifi/nm-wifi-ap.h b/src/devices/wifi/nm-wifi-ap.h
index 8ad9acb71b..67d3076922 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;