summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej S. Szmigiero <mail@maciej.szmigiero.name>2022-10-08 18:50:40 +0200
committerMaciej S. Szmigiero <mail@maciej.szmigiero.name>2022-10-11 14:51:41 +0200
commit913c5288263c48928706354f2798367eeb54ccd9 (patch)
tree234eaae6b6e7aeacc03f1e0f280a78899ea3ac06
parentc3e232fa260fa57b7217f6a83c90b9eb2c7dfccb (diff)
downloadgeoclue-913c5288263c48928706354f2798367eeb54ccd9.tar.gz
Add location source description to location
So it's obvious which location source provided them.
-rw-r--r--src/gclue-3g.c24
-rw-r--r--src/gclue-cdma.c3
-rw-r--r--src/gclue-location.c7
-rw-r--r--src/gclue-location.h3
-rw-r--r--src/gclue-mozilla.c34
-rw-r--r--src/gclue-mozilla.h2
-rw-r--r--src/gclue-web-source.c9
-rw-r--r--src/gclue-web-source.h1
-rw-r--r--src/gclue-wifi.c24
9 files changed, 82 insertions, 25 deletions
diff --git a/src/gclue-3g.c b/src/gclue-3g.c
index 5f16046..fef6c93 100644
--- a/src/gclue-3g.c
+++ b/src/gclue-3g.c
@@ -68,6 +68,7 @@ static GClueLocationSourceStopResult
gclue_3g_stop (GClueLocationSource *source);
static SoupMessage *
gclue_3g_create_query (GClueWebSource *web,
+ const char **query_data_description,
GError **error);
static SoupMessage *
gclue_3g_create_submit_query (GClueWebSource *web,
@@ -225,12 +226,22 @@ gclue_3g_get_singleton (GClueAccuracyLevel level)
return source[i];
}
+static gboolean
+g3g_should_skip_bsss (GClue3G *g3g)
+{
+ GClueAccuracyLevel level;
+
+ g_object_get (G_OBJECT (g3g), "accuracy-level", &level, NULL);
+ return gclue_wifi_should_skip_bsss (level);
+}
+
static SoupMessage *
gclue_3g_create_query (GClueWebSource *web,
+ const char **query_data_description,
GError **error)
{
- GClue3GPrivate *priv = GCLUE_3G (web)->priv;
- GClueAccuracyLevel level;
+ GClue3G *g3g = GCLUE_3G (web);
+ GClue3GPrivate *priv = g3g->priv;
gboolean skip_bss;
if (!gclue_mozilla_has_tower (priv->mozilla)) {
@@ -241,14 +252,13 @@ gclue_3g_create_query (GClueWebSource *web,
return NULL; /* Not initialized yet */
}
- g_object_get (G_OBJECT(web), "accuracy-level", &level, NULL);
- skip_bss = gclue_wifi_should_skip_bsss (level);
+ skip_bss = g3g_should_skip_bsss (g3g);
if (skip_bss) {
- g_debug ("Will skip BSSs in query as our accuracy level is %d",
- (int)level);
+ g_debug ("Will skip BSSs in query due to our accuracy level");
}
- return gclue_mozilla_create_query (priv->mozilla, FALSE, skip_bss, error);
+ return gclue_mozilla_create_query (priv->mozilla, FALSE, skip_bss,
+ query_data_description, error);
}
static SoupMessage *
diff --git a/src/gclue-cdma.c b/src/gclue-cdma.c
index a35c07a..602660b 100644
--- a/src/gclue-cdma.c
+++ b/src/gclue-cdma.c
@@ -199,7 +199,8 @@ on_fix_cdma (GClueModem *modem,
location = gclue_location_new (latitude,
longitude,
- 1000); /* Assume 1 km accuracy */
+ 1000, /* Assume 1 km accuracy */
+ "CDMA");
gclue_location_source_set_location (GCLUE_LOCATION_SOURCE (user_data),
location);
diff --git a/src/gclue-location.c b/src/gclue-location.c
index 0bc957c..782d126 100644
--- a/src/gclue-location.c
+++ b/src/gclue-location.c
@@ -546,6 +546,7 @@ parse_error:
* @latitude: a valid latitude
* @longitude: a valid longitude
* @accuracy: accuracy of location in meters
+ * @description: a description for the location
*
* Creates a new #GClueLocation object.
*
@@ -554,12 +555,14 @@ parse_error:
GClueLocation *
gclue_location_new (gdouble latitude,
gdouble longitude,
- gdouble accuracy)
+ gdouble accuracy,
+ const char *description)
{
return g_object_new (GCLUE_TYPE_LOCATION,
"latitude", latitude,
"longitude", longitude,
"accuracy", accuracy,
+ "description", description,
NULL);
}
@@ -642,6 +645,7 @@ gclue_location_create_from_gga (const char *gga, GError **error)
"longitude", longitude,
"accuracy", accuracy,
"timestamp", timestamp,
+ "description", "GPS GGA",
NULL);
if (altitude != GCLUE_LOCATION_ALTITUDE_UNKNOWN)
g_object_set (location, "altitude", altitude, NULL);
@@ -689,6 +693,7 @@ gclue_location_create_from_rmc (const char *rmc,
"timestamp", timestamp,
"speed", speed,
"heading", heading,
+ "description", "GPS RMC",
NULL);
if (prev_location != NULL) {
diff --git a/src/gclue-location.h b/src/gclue-location.h
index 8338002..bbe2daa 100644
--- a/src/gclue-location.h
+++ b/src/gclue-location.h
@@ -145,7 +145,8 @@ GType gclue_location_get_type (void);
GClueLocation *gclue_location_new (gdouble latitude,
gdouble longitude,
- gdouble accuracy);
+ gdouble accuracy,
+ const char *description);
GClueLocation *gclue_location_new_full
(gdouble latitude,
diff --git a/src/gclue-mozilla.c b/src/gclue-mozilla.c
index fee637e..fb89a2b 100644
--- a/src/gclue-mozilla.c
+++ b/src/gclue-mozilla.c
@@ -158,8 +158,10 @@ SoupMessage *
gclue_mozilla_create_query (GClueMozilla *mozilla,
gboolean skip_tower,
gboolean skip_bss,
+ const char **query_data_description,
GError **error)
{
+ gboolean has_tower = FALSE, has_bss = FALSE;
SoupMessage *ret = NULL;
JsonBuilder *builder;
g_autoptr(GList) bss_list = NULL;
@@ -221,6 +223,8 @@ gclue_mozilla_create_query (GClueMozilla *mozilla,
json_builder_end_object (builder);
json_builder_end_array (builder);
+
+ has_tower = TRUE;
}
if (n_non_ignored_bsss >= 2) {
@@ -244,6 +248,8 @@ gclue_mozilla_create_query (GClueMozilla *mozilla,
strength_dbm = wpa_bss_get_signal (bss);
json_builder_add_int_value (builder, strength_dbm);
json_builder_end_object (builder);
+
+ has_bss = TRUE;
}
json_builder_end_array (builder);
}
@@ -267,6 +273,18 @@ gclue_mozilla_create_query (GClueMozilla *mozilla,
data_len);
g_debug ("Sending following request to '%s':\n%s", uri, data);
+ if (query_data_description) {
+ if (has_tower && has_bss) {
+ *query_data_description = "3GPP + WiFi";
+ } else if (has_tower) {
+ *query_data_description = "3GPP";
+ } else if (has_bss) {
+ *query_data_description = "WiFi";
+ } else {
+ *query_data_description = "GeoIP";
+ }
+ }
+
return ret;
}
@@ -293,11 +311,13 @@ parse_server_error (JsonObject *object, GError **error)
GClueLocation *
gclue_mozilla_parse_response (const char *json,
+ const char *location_description,
GError **error)
{
g_autoptr(JsonParser) parser = NULL;
JsonNode *node;
JsonObject *object, *loc_object;
+ g_autofree char *desc_new = NULL;
GClueLocation *location;
gdouble latitude, longitude, accuracy;
@@ -312,13 +332,25 @@ gclue_mozilla_parse_response (const char *json,
if (parse_server_error (object, error))
return NULL;
+ if (json_object_has_member (object, "fallback")) {
+ const char *fallback;
+
+ fallback = json_object_get_string_member (object, "fallback");
+ if (fallback && strlen (fallback)) {
+ desc_new = g_strdup_printf ("%s fallback (from %s data)",
+ fallback, location_description);
+ location_description = desc_new;
+ }
+ }
+
loc_object = json_object_get_object_member (object, "location");
latitude = json_object_get_double_member (loc_object, "lat");
longitude = json_object_get_double_member (loc_object, "lng");
accuracy = json_object_get_double_member (object, "accuracy");
- location = gclue_location_new (latitude, longitude, accuracy);
+ location = gclue_location_new (latitude, longitude, accuracy,
+ location_description);
return location;
}
diff --git a/src/gclue-mozilla.h b/src/gclue-mozilla.h
index c284006..8a258ed 100644
--- a/src/gclue-mozilla.h
+++ b/src/gclue-mozilla.h
@@ -80,9 +80,11 @@ SoupMessage *
gclue_mozilla_create_query (GClueMozilla *mozilla,
gboolean skip_tower,
gboolean skip_bss,
+ const char **query_data_description,
GError **error);
GClueLocation *
gclue_mozilla_parse_response (const char *json,
+ const char *location_description,
GError **error);
SoupMessage *
gclue_mozilla_create_submit_query (GClueMozilla *mozilla,
diff --git a/src/gclue-web-source.c b/src/gclue-web-source.c
index 0ce132b..372bd5f 100644
--- a/src/gclue-web-source.c
+++ b/src/gclue-web-source.c
@@ -48,6 +48,7 @@ struct _GClueWebSourcePrivate {
SoupSession *soup_session;
SoupMessage *query;
+ const char *query_data_description;
gulong network_changed_id;
gulong connectivity_changed_id;
@@ -106,8 +107,8 @@ gclue_web_source_real_refresh_async (GClueWebSource *source,
return;
}
- source->priv->query = GCLUE_WEB_SOURCE_GET_CLASS (source)->create_query (source, &local_error);
-
+ source->priv->query = GCLUE_WEB_SOURCE_GET_CLASS (source)->create_query
+ (source, &source->priv->query_data_description, &local_error);
if (source->priv->query == NULL) {
g_task_return_error (task, g_steal_pointer (&local_error));
return;
@@ -153,7 +154,9 @@ refresh_callback (SoupSession *session,
uri = soup_message_get_uri (query);
str = soup_uri_to_string (uri, FALSE);
g_debug ("Got following response from '%s':\n%s", str, contents);
- location = gclue_mozilla_parse_response (contents, &local_error);
+ location = gclue_mozilla_parse_response (contents,
+ web->priv->query_data_description,
+ &local_error);
if (local_error != NULL) {
g_task_return_error (task, g_steal_pointer (&local_error));
return;
diff --git a/src/gclue-web-source.h b/src/gclue-web-source.h
index aa86e85..59f2b16 100644
--- a/src/gclue-web-source.h
+++ b/src/gclue-web-source.h
@@ -71,6 +71,7 @@ struct _GClueWebSourceClass {
GError **error);
SoupMessage * (*create_query) (GClueWebSource *source,
+ const char **query_data_description,
GError **error);
SoupMessage * (*create_submit_query) (GClueWebSource *source,
GClueLocation *location,
diff --git a/src/gclue-wifi.c b/src/gclue-wifi.c
index 5a1051b..3055545 100644
--- a/src/gclue-wifi.c
+++ b/src/gclue-wifi.c
@@ -162,6 +162,7 @@ struct _GClueWifiPrivate {
static SoupMessage *
gclue_wifi_create_query (GClueWebSource *source,
+ const char **query_data_description,
GError **error);
static SoupMessage *
gclue_wifi_create_submit_query (GClueWebSource *source,
@@ -1099,6 +1100,12 @@ gclue_wifi_get_singleton (GClueAccuracyLevel level)
return wifi[i];
}
+static gboolean
+wifi_should_skip_tower (GClueWifi *wifi)
+{
+ return gclue_3g_should_skip_tower (get_accuracy_level (wifi));
+}
+
/* Can return NULL, signifying an empty BSS list. */
GList *
gclue_wifi_get_bss_list (GClueWifi *wifi)
@@ -1108,12 +1115,11 @@ gclue_wifi_get_bss_list (GClueWifi *wifi)
static SoupMessage *
gclue_wifi_create_query (GClueWebSource *source,
+ const char **query_data_description,
GError **error)
{
GClueWifi *wifi = GCLUE_WIFI (source);
- GClueAccuracyLevel level;
gboolean skip_tower;
- SoupMessage *msg;
if (wifi->priv->interface == NULL) {
goto create_query;
@@ -1129,15 +1135,13 @@ gclue_wifi_create_query (GClueWebSource *source,
}
create_query:
- level = get_accuracy_level (wifi);
- skip_tower = gclue_3g_should_skip_tower (level);
+ skip_tower = wifi_should_skip_tower (wifi);
if (skip_tower) {
- g_debug ("Will skip 3GPP tower in query as our accuracy level is %d",
- (int)level);
+ g_debug ("Will skip 3GPP tower in query due to our accuracy level");
}
- msg = gclue_mozilla_create_query (wifi->priv->mozilla, skip_tower, FALSE, error);
- return msg;
+ return gclue_mozilla_create_query (wifi->priv->mozilla, skip_tower, FALSE,
+ query_data_description, error);
}
static SoupMessage *
@@ -1214,14 +1218,12 @@ static void location_cache_key_fill_tower (GClueWifi *wifi, GClue3GTower *tower)
{
GClueWifiPrivate *priv = wifi->priv;
GClue3GTower *moztower;
- GClueAccuracyLevel level;
memset (tower, 0, sizeof (*tower));
tower->tec = GCLUE_TOWER_TEC_NO_FIX;
moztower = gclue_mozilla_get_tower (priv->mozilla);
- level = get_accuracy_level (wifi);
- if (!moztower || gclue_3g_should_skip_tower (level)) {
+ if (!moztower || wifi_should_skip_tower (wifi)) {
return;
}