summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>2016-02-15 13:27:06 +0100
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>2016-07-01 16:51:00 +0100
commit7d60eab3cb255e7cd5d618e7671134ce6bb9a822 (patch)
tree9f9686a033a949e2e75c77868dc26ce19b8b36fc
parent91c85609d2cf449d3e985f69efaffd3d2395914a (diff)
downloadgeoclue-7d60eab3cb255e7cd5d618e7671134ce6bb9a822.tar.gz
service-client: Add a TimeThreshold property
If the time since the last update is below the threshold, it won't emit the LocationUpdated signal. The default value is 0. When TimeThreshold is zero, it always emits the signal. https://bugs.freedesktop.org/show_bug.cgi?id=94460
-rw-r--r--src/gclue-service-client.c42
-rw-r--r--src/org.freedesktop.GeoClue2.Client.xml13
2 files changed, 54 insertions, 1 deletions
diff --git a/src/gclue-service-client.c b/src/gclue-service-client.c
index 6043776..eecf090 100644
--- a/src/gclue-service-client.c
+++ b/src/gclue-service-client.c
@@ -53,6 +53,7 @@ struct _GClueServiceClientPrivate
GClueServiceLocation *location;
GClueServiceLocation *prev_location;
guint distance_threshold;
+ guint time_threshold;
GClueLocator *locator;
@@ -143,10 +144,45 @@ distance_below_threshold (GClueServiceClient *client,
}
static gboolean
+time_below_threshold (GClueServiceClient *client,
+ GClueLocation *location)
+{
+ GClueServiceClientPrivate *priv = client->priv;
+ GClueLocation *cur_location;
+ gint64 cur_ts, ts;
+ guint64 diff_ts;
+
+ if (priv->time_threshold == 0)
+ return FALSE;
+
+ g_object_get (priv->location,
+ "location", &cur_location,
+ NULL);
+
+ cur_ts = geocode_location_get_timestamp
+ (GEOCODE_LOCATION (cur_location));
+ ts = geocode_location_get_timestamp (GEOCODE_LOCATION (location));
+ diff_ts = ABS (ts - cur_ts);
+
+ g_object_unref (cur_location);
+
+ if (diff_ts < priv->time_threshold) {
+ g_debug ("Time difference between previous and new location"
+ " is %" G_GUINT64_FORMAT " seconds and"
+ " below threshold of %" G_GUINT32_FORMAT " seconds.",
+ diff_ts, priv->time_threshold);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
below_threshold (GClueServiceClient *client,
GClueLocation *location)
{
- return distance_below_threshold (client, location)
+ return (distance_below_threshold (client, location) ||
+ time_below_threshold (client, location));
}
static gboolean
@@ -663,6 +699,10 @@ gclue_service_client_handle_set_property (GDBusConnection *connection,
priv->distance_threshold = gclue_dbus_client_get_distance_threshold
(client);
g_debug ("New distance threshold: %u", priv->distance_threshold);
+ } else if (ret && strcmp (property_name, "TimeThreshold") == 0) {
+ priv->time_threshold = gclue_dbus_client_get_time_threshold
+ (client);
+ g_debug ("New time threshold: %u", priv->time_threshold);
}
return ret;
diff --git a/src/org.freedesktop.GeoClue2.Client.xml b/src/org.freedesktop.GeoClue2.Client.xml
index c754d5b..d7d45d1 100644
--- a/src/org.freedesktop.GeoClue2.Client.xml
+++ b/src/org.freedesktop.GeoClue2.Client.xml
@@ -45,6 +45,19 @@
</property>
<!--
+ TimeThreshold:
+
+ Contains the current time threshold in seconds. This value is used
+ by the service when it gets new location info. If the time since the
+ last update is below the threshold, it won't emit the LocationUpdated
+ signal. The default value is 0. When TimeThreshold is zero, it always
+ emits the signal.
+ -->
+ <property name="TimeThreshold" type="u" access="readwrite">
+ <annotation name="org.freedesktop.Accounts.DefaultValue" value="0"/>
+ </property>
+
+ <!--
DesktopId:
The desktop file id (the basename of the desktop file). This property