[libgweather/benzea/wip-variant-backend] fixup! Add new GVariant schema, header and database generator
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather/benzea/wip-variant-backend] fixup! Add new GVariant schema, header and database generator
- Date: Mon, 27 Apr 2020 09:30:53 +0000 (UTC)
commit 4fca0e4918ff5c4ff3edc66fbfc70b0600cd188d
Author: Benjamin Berg <bberg redhat com>
Date: Mon Apr 27 11:30:40 2020 +0200
fixup! Add new GVariant schema, header and database generator
data/gen-locations-variant.py | 6 +++++-
libgweather/gweather-db.h | 26 +++++++++++++++++++-------
libgweather/gweather-location.c | 6 ++++++
libgweather/gweather.gv | 3 +++
4 files changed, 33 insertions(+), 8 deletions(-)
---
diff --git a/data/gen-locations-variant.py b/data/gen-locations-variant.py
index 82278c31..76952b67 100755
--- a/data/gen-locations-variant.py
+++ b/data/gen-locations-variant.py
@@ -16,6 +16,9 @@ assert root.attrib['format'] == "1.0"
# Maybe types are annyoing, so use an invalid idx
INVALID_IDX = 0xffff
+# GWthDB01 as an integer
+magic = 0x5747687442443130
+
levels = {
'gweather' : 0,
'region' : 1,
@@ -180,7 +183,8 @@ loc_by_metar_var = [(loc.findtext('code'), locations.index(loc)) for loc in loc_
timezones_var = [(tz.get('id'), tz_variant(tz)) for tz in timezones]
locations_var = [loc_variant(loc) for loc in locations]
-res = GLib.Variant("(a{sq}a{sq}a{s((ss)as)}a((ss)ss(dd)ssqyqqaqaq))", (
+res = GLib.Variant("(ta{sq}a{sq}a{s((ss)as)}a((ss)ss(dd)ssqyqqaqaq))", (
+ magic,
loc_by_country_var,
loc_by_metar_var,
timezones_var,
diff --git a/libgweather/gweather-db.h b/libgweather/gweather-db.h
index 51b2a929..7a8faed7 100644
--- a/libgweather/gweather-db.h
+++ b/libgweather/gweather-db.h
@@ -1975,7 +1975,7 @@ db_arrayof_location_print (DbArrayofLocationRef v, gboolean type_annotate)
}
/************** DbWorld *******************/
-#define DB_WORLD_TYPESTRING "(a{sq}a{sq}a{s((ss)as)}a((ss)ss(dd)ssqyqqaqaq))"
+#define DB_WORLD_TYPESTRING "(ta{sq}a{sq}a{s((ss)as)}a((ss)ss(dd)ssqyqqaqaq))"
#define DB_WORLD_TYPEFORMAT ((const GVariantType *) DB_WORLD_TYPESTRING)
typedef struct {
@@ -2038,13 +2038,23 @@ db_world_from_variant (DbVariantRef v)
return db_world_from_data (child.base, child.size);
}
-#define DB_WORLD_INDEXOF_LOC_BY_COUNTRY 0
+#define DB_WORLD_INDEXOF_MAGIC 0
+
+static inline guint64
+db_world_get_magic (DbWorldRef v)
+{
+ guint offset = ((7) & (~(gsize)7)) + 0;
+ g_assert (offset + 8 < v.size);
+ return (guint64)G_STRUCT_MEMBER(guint64, v.base, offset);
+}
+
+#define DB_WORLD_INDEXOF_LOC_BY_COUNTRY 1
static inline DbWorldLocByCountryRef
db_world_get_loc_by_country (DbWorldRef v)
{
guint offset_size = Db_ref_get_offset_size (v.size);
- guint offset = ((1) & (~(gsize)1)) + 0;
+ guint offset = ((7) & (~(gsize)7)) + 8;
gsize start = offset;
gsize end = DB_REF_READ_FRAME_OFFSET(v, 0);
g_assert (start <= end);
@@ -2052,7 +2062,7 @@ db_world_get_loc_by_country (DbWorldRef v)
return (DbWorldLocByCountryRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
}
-#define DB_WORLD_INDEXOF_LOC_BY_METAR 1
+#define DB_WORLD_INDEXOF_LOC_BY_METAR 2
static inline DbWorldLocByMetarRef
db_world_get_loc_by_metar (DbWorldRef v)
@@ -2067,7 +2077,7 @@ db_world_get_loc_by_metar (DbWorldRef v)
return (DbWorldLocByMetarRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
}
-#define DB_WORLD_INDEXOF_TIMEZONES 2
+#define DB_WORLD_INDEXOF_TIMEZONES 3
static inline DbWorldTimezonesRef
db_world_get_timezones (DbWorldRef v)
@@ -2082,7 +2092,7 @@ db_world_get_timezones (DbWorldRef v)
return (DbWorldTimezonesRef) { G_STRUCT_MEMBER_P(v.base, start), end - start };
}
-#define DB_WORLD_INDEXOF_LOCATIONS 3
+#define DB_WORLD_INDEXOF_LOCATIONS 4
static inline DbArrayofLocationRef
db_world_get_locations (DbWorldRef v)
@@ -2100,7 +2110,9 @@ db_world_get_locations (DbWorldRef v)
static inline GString *
db_world_format (DbWorldRef v, GString *s, gboolean type_annotate)
{
- g_string_append (s, "(");
+ g_string_append_printf (s, "(%s%"G_GUINT64_FORMAT", ",
+ type_annotate ? "uint64 " : "",
+ db_world_get_magic (v));
db_world_loc_by_country_format (db_world_get_loc_by_country (v), s, type_annotate);
g_string_append (s, ", ");
db_world_loc_by_metar_format (db_world_get_loc_by_metar (v), s, type_annotate);
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index 1780590a..fa7135e8 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -246,6 +246,12 @@ gweather_location_dup_world ()
world_db = g_new0 (GWeatherDb, 1);
world_db->map = map;
world_db->world = db_world_from_data (g_mapped_file_get_contents (map), g_mapped_file_get_length
(map));
+ /* This is GWeathDB01 */
+ if (db_world_get_magic (world_db->world) != 0x5747687442443130) {
+ g_mapped_file_unref (world_db->map);
+ g_free (world_db);
+ return NULL;
+ }
world_db->locations_keepalive = g_ptr_array_new_with_free_func ((GDestroyNotify)
_gweather_location_unref_no_check);
world_db->timezones_keepalive = g_ptr_array_new_with_free_func ((GDestroyNotify)
gweather_timezone_unref);
diff --git a/libgweather/gweather.gv b/libgweather/gweather.gv
index 3013399b..897ea689 100644
--- a/libgweather/gweather.gv
+++ b/libgweather/gweather.gv
@@ -35,6 +35,9 @@ type Location {
};
type World {
+ /* The magic value ends up right at the start of the file. */
+ magic: uint64;
+
loc_by_country: [sorted string] uint16;
loc_by_metar: [sorted string] uint16;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]