summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej S. Szmigiero <mail@maciej.szmigiero.name>2022-10-05 23:50:46 +0200
committerMaciej S. Szmigiero <mail@maciej.szmigiero.name>2022-10-06 00:10:45 +0200
commit95ca094d08d63a15a6948706ed2959c3cd1a7c9a (patch)
tree68ed271781666adb47c06954cf4e3abe63c48d0a
parentbc4252ea5c2c4957f713d5136536379713c357ac (diff)
downloadgeoclue-95ca094d08d63a15a6948706ed2959c3cd1a7c9a.tar.gz
location: Add a generic gclue_location_duplicate_fresh() function
Instead of open-coding its equivalent in gclue-wifi.c (future location sources will also make use of this function).
-rw-r--r--src/gclue-location.c27
-rw-r--r--src/gclue-location.h2
-rw-r--r--src/gclue-wifi.c16
3 files changed, 29 insertions, 16 deletions
diff --git a/src/gclue-location.c b/src/gclue-location.c
index cf5ff97..0bc957c 100644
--- a/src/gclue-location.c
+++ b/src/gclue-location.c
@@ -770,7 +770,7 @@ gclue_location_create_from_nmeas (const char *nmeas[],
* gclue_location_duplicate:
* @location: the #GClueLocation instance to duplicate.
*
- * Creates a new copy of @location object.
+ * Creates a new copy of @location object (with the same timestamp).
*
* Returns: a new #GClueLocation object. Use g_object_unref() when done.
**/
@@ -792,6 +792,31 @@ gclue_location_duplicate (GClueLocation *location)
NULL);
}
+/**
+ * gclue_location_duplicate_fresh:
+ * @location: the #GClueLocation instance to duplicate.
+ *
+ * Creates a new copy of @location object with a refreshed timestamp.
+ *
+ * Returns: a new #GClueLocation object. Use g_object_unref() when done.
+ **/
+GClueLocation *
+gclue_location_duplicate_fresh (GClueLocation *location)
+{
+ g_return_val_if_fail (GCLUE_IS_LOCATION (location), NULL);
+
+ return g_object_new
+ (GCLUE_TYPE_LOCATION,
+ "latitude", location->priv->latitude,
+ "longitude", location->priv->longitude,
+ "accuracy", location->priv->accuracy,
+ "altitude", location->priv->altitude,
+ "speed", location->priv->speed,
+ "heading", location->priv->heading,
+ "description", location->priv->description,
+ NULL);
+}
+
const char *
gclue_location_get_description (GClueLocation *loc)
{
diff --git a/src/gclue-location.h b/src/gclue-location.h
index 0db57ac..579995c 100644
--- a/src/gclue-location.h
+++ b/src/gclue-location.h
@@ -146,6 +146,8 @@ GClueLocation *gclue_location_create_from_nmeas
GClueLocation *gclue_location_duplicate
(GClueLocation *location);
+GClueLocation *gclue_location_duplicate_fresh
+ (GClueLocation *location);
void gclue_location_set_description
(GClueLocation *loc,
diff --git a/src/gclue-wifi.c b/src/gclue-wifi.c
index 5d3685b..f872716 100644
--- a/src/gclue-wifi.c
+++ b/src/gclue-wifi.c
@@ -1384,20 +1384,6 @@ static void refresh_task_data_free (gpointer data)
g_slice_free (RefreshTaskData, rdata);
}
-static GClueLocation *
-duplicate_location_new_timestamp (GClueLocation *location)
-{
- return g_object_new (GCLUE_TYPE_LOCATION,
- "latitude", gclue_location_get_latitude (location),
- "longitude", gclue_location_get_longitude (location),
- "accuracy", gclue_location_get_accuracy (location),
- "altitude", gclue_location_get_altitude (location),
- "timestamp", 0,
- "speed", gclue_location_get_speed (location),
- "heading", gclue_location_get_heading (location),
- NULL);
-}
-
static void
gclue_wifi_refresh_async (GClueWebSource *source,
GCancellable *cancellable,
@@ -1423,7 +1409,7 @@ gclue_wifi_refresh_async (GClueWebSource *source,
wifi->priv->cache_hits++;
/* Duplicate the location so its timestamp is updated. */
- new_location = duplicate_location_new_timestamp (cached_location);
+ new_location = gclue_location_duplicate_fresh (cached_location);
gclue_location_source_set_location (GCLUE_LOCATION_SOURCE (source), new_location);
g_task_return_pointer (task, g_steal_pointer (&new_location), g_object_unref);