wifi: expose LastScan as milliseconds not seconds

This doesn't wrap around in 68 years of uptime and is consistent with
o.fd.NM.Checkpoint.Created.
This commit is contained in:
Lubomir Rintel 2018-06-15 13:57:30 +02:00 committed by Thomas Haller
parent 1c0aa397b3
commit 07fd0502f6
11 changed files with 53 additions and 52 deletions

View file

@ -2770,7 +2770,7 @@ wifi_list_aps (NMDeviceWifi *wifi,
gboolean needs_rescan;
WifiListData *data;
needs_rescan = rescan_cutoff < 0 || (rescan_cutoff > 0 && nm_device_wifi_get_last_scan (wifi) < rescan_cutoff);
needs_rescan = rescan_cutoff < 0 || (rescan_cutoff > 0 && nm_device_wifi_get_last_scan (wifi) < (rescan_cutoff * 1000));
if (needs_rescan) {
data = g_slice_new0 (WifiListData);

View file

@ -99,12 +99,12 @@
<!--
LastScan:
The timestamp (in CLOCK_BOOTTIME seconds) for the last finished network scan.
The timestamp (in CLOCK_BOOTTIME milliseconds) for the last finished network scan.
A value of -1 means the device never scanned for access points.
Since: 1.12
-->
<property name="LastScan" type="i" access="read"/>
<property name="LastScan" type="x" access="read"/>
<!--
PropertiesChanged:

View file

@ -59,7 +59,7 @@ typedef struct {
NMAccessPoint *active_ap;
NMDeviceWifiCapabilities wireless_caps;
GPtrArray *aps;
gint last_scan;
gint64 last_scan;
RequestScanInfo *scan_info;
} NMDeviceWifiPrivate;
@ -273,19 +273,19 @@ nm_device_wifi_get_access_point_by_path (NMDeviceWifi *device,
* nm_device_wifi_get_last_scan:
* @device: a #NMDeviceWifi
*
* Returns the timestamp (in CLOCK_BOOTTIME seconds) for the last finished
* Returns the timestamp (in CLOCK_BOOTTIME milliseconds) for the last finished
* network scan. A value of -1 means the device never scanned for access points.
*
* Returns: the last scan time in seconds
*
* Since: 1.12
**/
gint
gint64
nm_device_wifi_get_last_scan (NMDeviceWifi *device)
{
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), -1);
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), -1);
return NM_DEVICE_WIFI_GET_PRIVATE (device)->last_scan;
return NM_DEVICE_WIFI_GET_PRIVATE (device)->last_scan;
}
static GVariant *
@ -721,7 +721,7 @@ get_property (GObject *object,
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_device_wifi_get_access_points (self)));
break;
case PROP_LAST_SCAN:
g_value_set_int (value, nm_device_wifi_get_last_scan (self));
g_value_set_int64 (value, nm_device_wifi_get_last_scan (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -935,10 +935,10 @@ nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class)
**/
g_object_class_install_property
(object_class, PROP_LAST_SCAN,
g_param_spec_int (NM_DEVICE_WIFI_LAST_SCAN, "", "",
-1, G_MAXINT, -1,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
g_param_spec_int64 (NM_DEVICE_WIFI_LAST_SCAN, "", "",
-1, G_MAXINT64, -1,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/* signals */

View file

@ -78,8 +78,8 @@ NMAccessPoint * nm_device_wifi_get_access_point_by_path (NMDeviceWifi *
const GPtrArray * nm_device_wifi_get_access_points (NMDeviceWifi *device);
NM_AVAILABLE_IN_1_2
gint nm_device_wifi_get_last_scan (NMDeviceWifi *device);
NM_AVAILABLE_IN_1_12
gint64 nm_device_wifi_get_last_scan (NMDeviceWifi *device);
gboolean nm_device_wifi_request_scan (NMDeviceWifi *device,
GCancellable *cancellable,

View file

@ -520,8 +520,9 @@ void _nm_utils_strv_sort (const char **strv, gssize len);
/*****************************************************************************/
#define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000)
#define NM_UTILS_NS_PER_MSEC ((gint64) 1000000)
#define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000)
#define NM_UTILS_NS_PER_MSEC ((gint64) 1000000)
#define NM_UTILS_MSEC_PER_SECOND ((gint64) 1000)
#define NM_UTILS_NS_TO_MSEC_CEIL(nsec) (((nsec) + (NM_UTILS_NS_PER_MSEC - 1)) / NM_UTILS_NS_PER_MSEC)
/*****************************************************************************/

View file

@ -80,7 +80,7 @@ typedef struct {
bool can_connect:1;
bool scanning:1;
bool scan_requested:1;
gint32 last_scan;
gint64 last_scan;
} NMDeviceIwdPrivate;
struct _NMDeviceIwd {
@ -865,7 +865,7 @@ scan_cb (GObject *source, GAsyncResult *res, gpointer user_data)
priv = NM_DEVICE_IWD_GET_PRIVATE (self);
priv->scan_requested = FALSE;
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
priv->last_scan = nm_utils_get_monotonic_timestamp_ms ();
_notify (self, PROP_LAST_SCAN);
/* On success, priv->scanning becomes true right before or right
@ -1535,10 +1535,10 @@ get_property (GObject *object, guint prop_id,
g_value_set_boolean (value, priv->scanning);
break;
case PROP_LAST_SCAN:
g_value_set_int (value,
priv->last_scan > 0
? (gint) nm_utils_monotonic_timestamp_as_boottime (priv->last_scan, NM_UTILS_NS_PER_SECOND)
: -1);
g_value_set_int64 (value,
priv->last_scan > 0
? nm_utils_monotonic_timestamp_as_boottime (priv->last_scan, NM_UTILS_NS_PER_MSEC)
: (gint64) -1);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -1920,9 +1920,9 @@ nm_device_iwd_class_init (NMDeviceIwdClass *klass)
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_LAST_SCAN] =
g_param_spec_int (NM_DEVICE_IWD_LAST_SCAN, "", "",
-1, G_MAXINT, -1,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_param_spec_int64 (NM_DEVICE_IWD_LAST_SCAN, "", "",
-1, G_MAXINT64, -1,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);

View file

@ -97,8 +97,8 @@ typedef struct {
bool ssid_found:1;
bool is_scanning:1;
gint32 last_scan;
gint32 scheduled_scan_time;
gint64 last_scan; /* milliseconds */
gint32 scheduled_scan_time; /* seconds */
guint8 scan_interval; /* seconds */
guint pending_scan_id;
guint ap_dump_id;
@ -1127,7 +1127,7 @@ _nm_device_wifi_request_scan (NMDeviceWifi *self,
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
NMDevice *device = NM_DEVICE (self);
gint32 last_scan;
gint64 last_scan;
if ( !priv->enabled
|| !priv->sup_iface
@ -1148,8 +1148,8 @@ _nm_device_wifi_request_scan (NMDeviceWifi *self,
return;
}
last_scan = nm_supplicant_interface_get_last_scan_time (priv->sup_iface);
if (last_scan && (nm_utils_get_monotonic_timestamp_s () - last_scan) < 10) {
last_scan = nm_supplicant_interface_get_last_scan (priv->sup_iface);
if (last_scan && (nm_utils_get_monotonic_timestamp_ms () - last_scan) < 10 * NM_UTILS_MSEC_PER_SECOND) {
g_dbus_method_invocation_return_error_literal (invocation,
NM_DEVICE_ERROR,
NM_DEVICE_ERROR_NOT_ALLOWED,
@ -1423,7 +1423,7 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface,
_LOGD (LOGD_WIFI, "wifi-scan: scan-done callback: %s", success ? "successful" : "failed");
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
priv->last_scan = nm_utils_get_monotonic_timestamp_ms ();
_notify (self, PROP_LAST_SCAN);
schedule_scan (self, success);
@ -1447,9 +1447,9 @@ ap_list_dump (gpointer user_data)
NMWifiAP *ap;
gint32 now_s = nm_utils_get_monotonic_timestamp_s ();
_LOGD (LOGD_WIFI_SCAN, "APs: [now:%u last:%u next:%u]",
_LOGD (LOGD_WIFI_SCAN, "APs: [now:%u last:%" G_GINT64_FORMAT " next:%u]",
now_s,
priv->last_scan,
priv->last_scan / NM_UTILS_MSEC_PER_SECOND,
priv->scheduled_scan_time);
c_list_for_each_entry (ap, &priv->aps_lst_head, aps_lst)
_ap_dump (self, LOGL_DEBUG, ap, "dump", now_s);
@ -3185,10 +3185,10 @@ get_property (GObject *object, guint prop_id,
g_value_set_boolean (value, priv->is_scanning);
break;
case PROP_LAST_SCAN:
g_value_set_int (value,
priv->last_scan > 0
? (gint) nm_utils_monotonic_timestamp_as_boottime (priv->last_scan, NM_UTILS_NS_PER_SECOND)
: -1);
g_value_set_int64 (value,
priv->last_scan > 0
? nm_utils_monotonic_timestamp_as_boottime (priv->last_scan, NM_UTILS_NS_PER_MSEC)
: (gint64) -1);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -3369,9 +3369,9 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_LAST_SCAN] =
g_param_spec_int (NM_DEVICE_WIFI_LAST_SCAN, "", "",
-1, G_MAXINT, -1,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_param_spec_int64 (NM_DEVICE_WIFI_LAST_SCAN, "", "",
-1, G_MAXINT64, -1,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);

View file

@ -200,7 +200,7 @@ const NMDBusInterfaceInfoExtended nm_interface_info_device_wireless = {
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("AccessPoints", "ao", NM_DEVICE_WIFI_ACCESS_POINTS),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("ActiveAccessPoint", "o", NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("WirelessCapabilities", "u", NM_DEVICE_WIFI_CAPABILITIES),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE ("LastScan", "i", NM_DEVICE_WIFI_LAST_SCAN),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE ("LastScan", "x", NM_DEVICE_WIFI_LAST_SCAN),
),
),
.legacy_property_changed = TRUE,

View file

@ -129,7 +129,7 @@ typedef struct {
GHashTable * bss_proxies;
char * current_bss;
gint32 last_scan; /* timestamp as returned by nm_utils_get_monotonic_timestamp_s() */
gint64 last_scan; /* timestamp as returned by nm_utils_get_monotonic_timestamp_ms() */
} NMSupplicantInterfacePrivate;
@ -209,7 +209,7 @@ bss_proxy_properties_changed_cb (GDBusProxy *proxy,
NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);
if (priv->scanning)
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
priv->last_scan = nm_utils_get_monotonic_timestamp_ms ();
g_signal_emit (self, signals[BSS_UPDATED], 0,
g_dbus_proxy_get_object_path (proxy),
@ -344,7 +344,7 @@ set_state (NMSupplicantInterface *self, NMSupplicantInterfaceState new_state)
if ( priv->state == NM_SUPPLICANT_INTERFACE_STATE_SCANNING
|| old_state == NM_SUPPLICANT_INTERFACE_STATE_SCANNING)
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
priv->last_scan = nm_utils_get_monotonic_timestamp_ms ();
/* Disconnect reason is no longer relevant when not in the DISCONNECTED state */
if (priv->state != NM_SUPPLICANT_INTERFACE_STATE_DISCONNECTED)
@ -406,7 +406,7 @@ set_scanning (NMSupplicantInterface *self, gboolean new_scanning)
/* Cache time of last scan completion */
if (priv->scanning == FALSE)
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
priv->last_scan = nm_utils_get_monotonic_timestamp_ms ();
_notify (self, PROP_SCANNING);
}
@ -438,8 +438,8 @@ nm_supplicant_interface_get_current_bss (NMSupplicantInterface *self)
return priv->state >= NM_SUPPLICANT_INTERFACE_STATE_READY ? priv->current_bss : NULL;
}
gint32
nm_supplicant_interface_get_last_scan_time (NMSupplicantInterface *self)
gint64
nm_supplicant_interface_get_last_scan (NMSupplicantInterface *self)
{
return NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self)->last_scan;
}
@ -987,7 +987,7 @@ wpas_iface_scan_done (GDBusProxy *proxy,
NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);
/* Cache last scan completed time */
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
priv->last_scan = nm_utils_get_monotonic_timestamp_ms ();
priv->scan_done_success |= success;
scan_done_emit_signal (self);
}
@ -1002,7 +1002,7 @@ wpas_iface_bss_added (GDBusProxy *proxy,
NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);
if (priv->scanning)
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
priv->last_scan = nm_utils_get_monotonic_timestamp_ms ();
bss_add_new (self, path);
}

View file

@ -110,7 +110,7 @@ gboolean nm_supplicant_interface_get_scanning (NMSupplicantInterface *self);
const char *nm_supplicant_interface_get_current_bss (NMSupplicantInterface *self);
gint32 nm_supplicant_interface_get_last_scan_time (NMSupplicantInterface *self);
gint64 nm_supplicant_interface_get_last_scan (NMSupplicantInterface *self);
const char *nm_supplicant_interface_get_ifname (NMSupplicantInterface *self);

View file

@ -924,7 +924,7 @@ class WifiDevice(Device):
PRP_WIFI_WIRELESS_CAPABILITIES: dbus.UInt32(0xFF),
PRP_WIFI_ACCESS_POINTS: ExportedObj.to_path_array(self.aps),
PRP_WIFI_ACTIVE_ACCESS_POINT: ExportedObj.to_path(None),
PRP_WIFI_LAST_SCAN: dbus.Int32(0x70000000),
PRP_WIFI_LAST_SCAN: dbus.Int64(0x7000000000000000),
}
self.dbus_interface_add(IFACE_WIFI, props, WifiDevice.PropertiesChanged)