summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeeshan Ali <zeeshanak@gnome.org>2018-04-17 12:17:15 +0200
committerZeeshan Ali <zeeshanak@gnome.org>2018-04-17 12:30:20 +0200
commitc25451385c92ad604b4efb4ac4ea3b0cf0fc4b2b (patch)
tree2acf3be25dd03104a8cda3be97a29277c85a38e3
parent51b7de3da888f2ab9862480491f35e959288dfb0 (diff)
downloadgeoclue-c25451385c92ad604b4efb4ac4ea3b0cf0fc4b2b.tar.gz
locator: Aggregate time-threshold for sources
Unlike other (real) location sources, Locator instances are unique for each client application. Which means we only need just one time-threshold value so we now provide getter and setter for time-threshold as guint, which is what will be set by the clients, instead of the time-threshold property of the parent class LocationSource (they can still do that if they wish though). https://bugs.freedesktop.org/show_bug.cgi?id=105993
-rw-r--r--src/gclue-locator.c93
-rw-r--r--src/gclue-locator.h3
2 files changed, 95 insertions, 1 deletions
diff --git a/src/gclue-locator.c b/src/gclue-locator.c
index 41d98ea..5a413ae 100644
--- a/src/gclue-locator.c
+++ b/src/gclue-locator.c
@@ -62,6 +62,8 @@ struct _GClueLocatorPrivate
GList *active_sources;
GClueAccuracyLevel accuracy_level;
+
+ guint time_threshold;
};
enum
@@ -226,6 +228,35 @@ on_avail_accuracy_level_changed (GObject *gobject,
}
static void
+reset_time_threshold (GClueLocationSource *source,
+ guint cur_value,
+ guint new_value)
+{
+ GClueMinUINT *threshold;
+
+ threshold = gclue_location_source_get_time_threshold (source);
+
+ gclue_min_uint_exchage_value (threshold, cur_value, new_value);
+}
+
+static void
+on_time_threshold_changed(GObject *gobject,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ GClueMinUINT *threshold = GCLUE_MIN_UINT (gobject);
+ GClueLocator *locator = GCLUE_LOCATOR (user_data);
+ guint value = gclue_min_uint_get_value (threshold);
+ GList *node;
+
+ for (node = locator->priv->sources; node != NULL; node = node->next) {
+ reset_time_threshold (GCLUE_LOCATION_SOURCE (node->data),
+ locator->priv->time_threshold,
+ value);
+ }
+}
+
+static void
gclue_locator_get_property (GObject *object,
guint prop_id,
GValue *value,
@@ -270,11 +301,18 @@ gclue_locator_finalize (GObject *gsource)
G_OBJECT_CLASS (gclue_locator_parent_class)->finalize (gsource);
- for (node = locator->priv->sources; node != NULL; node = node->next)
+ for (node = locator->priv->sources; node != NULL; node = node->next) {
+ GClueMinUINT *threshold;
+
+ threshold = gclue_location_source_get_time_threshold
+ (GCLUE_LOCATION_SOURCE (node->data));
+ gclue_min_uint_drop_value (threshold, priv->time_threshold);
+
g_signal_handlers_disconnect_by_func
(G_OBJECT (node->data),
G_CALLBACK (on_avail_accuracy_level_changed),
locator);
+ }
for (node = locator->priv->active_sources; node != NULL; node = node->next) {
g_signal_handlers_disconnect_by_func
(G_OBJECT (node->data),
@@ -294,6 +332,7 @@ gclue_locator_constructed (GObject *object)
GClueLocationSource *submit_source = NULL;
GClueConfig *gconfig = gclue_config_get_singleton ();
GList *node;
+ GClueMinUINT *threshold;
G_OBJECT_CLASS (gclue_locator_parent_class)->constructed (object);
@@ -331,6 +370,13 @@ gclue_locator_constructed (GObject *object)
gclue_web_source_set_submit_source
(GCLUE_WEB_SOURCE (node->data), submit_source);
}
+
+ threshold = gclue_location_source_get_time_threshold
+ (GCLUE_LOCATION_SOURCE (locator));
+ g_signal_connect (G_OBJECT (threshold),
+ "notify::value",
+ G_CALLBACK (on_time_threshold_changed),
+ locator);
refresh_available_accuracy_level (locator);
}
@@ -466,3 +512,48 @@ gclue_locator_get_accuracy_level (GClueLocator *locator)
return locator->priv->accuracy_level;
}
+
+/**
+ * gclue_locator_get_time_threshold
+ * @locator: a #GClueLocator
+ *
+ * Returns: The current time-threshold in seconds.
+ **/
+guint
+gclue_locator_get_time_threshold (GClueLocator *locator)
+{
+ g_return_val_if_fail (GCLUE_IS_LOCATOR (locator), 0);
+
+ return locator->priv->time_threshold;
+}
+
+/**
+ * gclue_locator_set_time_threshold
+ * @locator: a #GClueLocator
+ * @value: The new threshold value
+ *
+ * Sets the time-threshold to @value.
+ *
+ * Unlike other (real) location sources, Locator instances are unique for each
+ * client application. Which means we only need just one time-threshold value
+ * and hence the reason we have these getter and setters, instead of making use
+ * of the #GClueLocationSource:time-threshold property.
+ **/
+void
+gclue_locator_set_time_threshold (GClueLocator *locator,
+ guint value)
+{
+ g_return_if_fail (GCLUE_IS_LOCATOR (locator));
+
+ if (locator->priv->time_threshold == value) {
+ return;
+ }
+
+ reset_time_threshold (GCLUE_LOCATION_SOURCE (locator),
+ locator->priv->time_threshold,
+ value);
+ locator->priv->time_threshold = value;
+ g_debug ("%s: New time-threshold: %u",
+ G_OBJECT_TYPE_NAME (locator),
+ value);
+}
diff --git a/src/gclue-locator.h b/src/gclue-locator.h
index 9274e34..b67a1c0 100644
--- a/src/gclue-locator.h
+++ b/src/gclue-locator.h
@@ -59,6 +59,9 @@ GType gclue_locator_get_type (void) G_GNUC_CONST;
GClueLocator * gclue_locator_new (GClueAccuracyLevel level);
GClueAccuracyLevel gclue_locator_get_accuracy_level (GClueLocator *locator);
+guint gclue_locator_get_time_threshold (GClueLocator *locator);
+void gclue_locator_set_time_threshold (GClueLocator *locator,
+ guint threshold);
G_END_DECLS