[tracker/wip/carlosg/serialize-api: 5/26] libtracker-sparql: Ensure to register a single instance of serializers

commit fea572ad363f1828ce005a59fe57f32637b5dbdc
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Nov 28 11:54:17 2021 +0100

    libtracker-sparql: Ensure to register a single instance of serializers
    For now, the private TrackerSerializer API was only used in the
    TrackerEndpointHttp object, which is compiled as a loadable module since
    we support linking with soup 2.x and 3.x simultaneously.
    Now that we are introducing usage of this private API from other places
    in code, we risk getting the dreaded "type already registered" errors
    from GType, since each of libtracker-sparql and the soup modules will
    try to register their own.
    Make creation of serializers more lenient wrt the GType lookup, so
    there's no double registration of the same type, and ensure these GTypes
    are initialized from libtracker-sparql so there's no confusion about
    who comes first.
    This is yet another braindead hack about libsoup loadable modules that
    can be removed when we can pick one of them at build time.

 src/libtracker-sparql/tracker-connection.c | 12 ++++++++++++
 src/libtracker-sparql/tracker-serializer.c |  8 ++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/libtracker-sparql/tracker-connection.c b/src/libtracker-sparql/tracker-connection.c
index e2585d440..25009234c 100644
--- a/src/libtracker-sparql/tracker-connection.c
+++ b/src/libtracker-sparql/tracker-connection.c
@@ -60,6 +60,10 @@
 #include "tracker-connection.h"
 #include "tracker-private.h"
+#include "tracker-serializer-json.h"
+#include "tracker-serializer-trig.h"
+#include "tracker-serializer-turtle.h"
+#include "tracker-serializer-xml.h"
 G_DEFINE_ABSTRACT_TYPE (TrackerSparqlConnection, tracker_sparql_connection,
@@ -83,6 +87,14 @@ tracker_sparql_connection_class_init (TrackerSparqlConnectionClass *klass)
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
        object_class->dispose = tracker_sparql_connection_dispose;
+       /* Ensure serializer types, we want all of these initialized before
+        * the remote soup 2/3 modules gets to initialize them.
+        */
+       g_type_ensure (TRACKER_TYPE_SERIALIZER_XML);
+       g_type_ensure (TRACKER_TYPE_SERIALIZER_JSON);
+       g_type_ensure (TRACKER_TYPE_SERIALIZER_TURTLE);
+       g_type_ensure (TRACKER_TYPE_SERIALIZER_TRIG);
diff --git a/src/libtracker-sparql/tracker-serializer.c b/src/libtracker-sparql/tracker-serializer.c
index 4109bfafe..317b621a9 100644
--- a/src/libtracker-sparql/tracker-serializer.c
+++ b/src/libtracker-sparql/tracker-serializer.c
@@ -133,10 +133,14 @@ tracker_serializer_new (TrackerSparqlCursor     *cursor,
        switch (format) {
-               type = TRACKER_TYPE_SERIALIZER_JSON;
+               type = g_type_from_name ("TrackerSerializerJson");
+               if (type == 0)
+                       type = TRACKER_TYPE_SERIALIZER_JSON;
-               type = TRACKER_TYPE_SERIALIZER_XML;
+               type = g_type_from_name ("TrackerSerializerXml");
+               if (type == 0)
+                       type = TRACKER_TYPE_SERIALIZER_XML;
                g_warn_if_reached ();

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]