summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-06 15:17:20 (GMT)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-08 13:43:42 (GMT)
commit39642885084c5dd4bfaab34fd622aa72abb896d1 (patch)
treec8e6ad49b8b2de2978a23baba04693746540ec99
parentef6a9b7ecce489f18a1912789f7d303ff73d5732 (diff)
downloadtraprain-39642885084c5dd4bfaab34fd622aa72abb896d1.tar.gz
traprain-39642885084c5dd4bfaab34fd622aa72abb896d1.tar.xz
client: use a _TrpLanguagesMap to store the segment descriptions
The introduction of 'geo_desc_hash' isn't great, but it's just temporary while refactoring. I'll get rid of it in a few commits. Signed-off-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk> Differential Revision: https://phabricator.apertis.org/D4203
-rw-r--r--traprain-client/route-internal.h5
-rw-r--r--traprain-client/route.c56
-rw-r--r--traprain-common/languages-map-internal.h2
3 files changed, 29 insertions, 34 deletions
diff --git a/traprain-client/route-internal.h b/traprain-client/route-internal.h
index 6b52278..d856172 100644
--- a/traprain-client/route-internal.h
+++ b/traprain-client/route-internal.h
@@ -24,8 +24,9 @@ struct _TrpClientRoute
TrpOrgApertisNavigation1Route *proxy; /* owned */
- GHashTable /* <guint> -> <owned GHashTable *> */ *geo_desc; /* owned */
- _TrpLanguagesMap *title; /* owned */
+ GHashTable /* <guint> -> <owned _TrpLanguagesMap *> */ *geo_desc; /* owned */
+ GHashTable /* <guint> -> <owned GHashTable *> */ *geo_desc_hash; /* owned */
+ _TrpLanguagesMap *title; /* owned */
/* ID used by TrpClientNavigation to identify route objects which are no
* longer exposed by the service and so can be destroyed. */
diff --git a/traprain-client/route.c b/traprain-client/route.c
index bbce8f6..7485ffa 100644
--- a/traprain-client/route.c
+++ b/traprain-client/route.c
@@ -38,7 +38,8 @@ trp_client_route_dispose (GObject *object)
g_clear_object (&self->proxy);
g_clear_pointer (&self->geo_desc, g_hash_table_unref);
- g_clear_pointer (&self->title, g_array_unref);
+ g_clear_pointer (&self->geo_desc_hash, g_hash_table_unref);
+ g_clear_pointer (&self->title, _trp_languages_map_unref);
G_OBJECT_CLASS (trp_client_route_parent_class)
->dispose (object);
@@ -91,23 +92,6 @@ trp_client_route_get_total_time (TrpClientRoute *self)
return trp_org_apertis_navigation1_route_get_total_time (self->proxy);
}
-static GHashTable *
-build_ass_hash_table (GVariant *v)
-{
- GHashTable *h;
- GVariantIter *iter;
- gchar *key, *value;
-
- h = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
-
- g_variant_get (v, "a{ss}", &iter);
- while (g_variant_iter_next (iter, "{ss}", &key, &value))
- g_hash_table_insert (h, key, value);
- g_variant_iter_free (iter);
-
- return h;
-}
-
/**
* trp_client_route_get_titles:
* @self: a #TrpClientRoute
@@ -212,13 +196,20 @@ trp_client_route_get_segment (TrpClientRoute *self, guint index, gdouble *lat, g
if (descriptions)
{
- *descriptions = g_hash_table_lookup (self->geo_desc, GUINT_TO_POINTER (index));
- if (*descriptions == NULL)
- {
- *descriptions = g_hash_table_new (NULL, NULL);
- /* transfer ownership */
- g_hash_table_insert (self->geo_desc, GUINT_TO_POINTER (index), *descriptions);
- }
+ _TrpLanguagesMap *map;
+
+ *descriptions = g_hash_table_lookup (self->geo_desc_hash, GUINT_TO_POINTER (index));
+ if (*descriptions != NULL)
+ return;
+
+ map = g_hash_table_lookup (self->geo_desc, GUINT_TO_POINTER (index));
+ if (map != NULL)
+ *descriptions = _trp_languages_map_to_hash (map);
+ else
+ *descriptions = g_hash_table_new (NULL, NULL);
+
+ /* transfer ownership */
+ g_hash_table_insert (self->geo_desc_hash, GUINT_TO_POINTER (index), *descriptions);
}
}
@@ -243,13 +234,13 @@ trp_client_route_get_segment_in_language (TrpClientRoute *self, guint index, con
if (description)
{
- GHashTable *h;
+ _TrpLanguagesMap *map;
g_return_if_fail (language != NULL);
- h = g_hash_table_lookup (self->geo_desc, GUINT_TO_POINTER (index));
- if (h != NULL)
- *description = g_hash_table_lookup (h, language);
+ map = g_hash_table_lookup (self->geo_desc, GUINT_TO_POINTER (index));
+ if (map != NULL)
+ *description = _trp_languages_map_lookup (map, language);
else
*description = NULL;
}
@@ -263,15 +254,15 @@ build_geometry_descriptions (TrpClientRoute *self)
guint i;
GHashTable *result;
- result = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_hash_table_unref);
+ result = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) _trp_languages_map_unref);
v = trp_org_apertis_navigation1_route_get_geometry_descriptions (self->proxy);
g_variant_get (v, "a{ua{ss}}", &iter);
while (g_variant_iter_next (iter, "{u@a{ss}}", &i, &desc))
{
- g_hash_table_insert (result, GUINT_TO_POINTER (i), build_ass_hash_table (desc));
- g_variant_unref (desc);
+ g_hash_table_insert (result, GUINT_TO_POINTER (i),
+ _trp_languages_map_new_from_variant (desc));
}
return result;
@@ -301,6 +292,7 @@ _trp_client_route_new (TrpOrgApertisNavigation1Route *proxy)
/* Convert all the geometry descriptions variants to array to save us from
* iterating on all of them in trp_client_route_get_segment(). */
self->geo_desc = build_geometry_descriptions (self);
+ self->geo_desc_hash = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_hash_table_unref);
return self;
}
diff --git a/traprain-common/languages-map-internal.h b/traprain-common/languages-map-internal.h
index 30f9c80..a09123a 100644
--- a/traprain-common/languages-map-internal.h
+++ b/traprain-common/languages-map-internal.h
@@ -17,6 +17,8 @@ G_BEGIN_DECLS
typedef GArray /*<owned _TrpLanguageString>*/ _TrpLanguagesMap;
+#define _trp_languages_map_unref g_array_unref
+
_TrpLanguagesMap *_trp_languages_map_new (void);
_TrpLanguagesMap *_trp_languages_map_new_from_variant (GVariant *v);