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




commit 65211f077c96a593e66701e6cb834edc8077ea71
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,
                         G_TYPE_OBJECT)
@@ -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);
 }
 
 gboolean
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) {
        case TRACKER_SERIALIZER_FORMAT_JSON:
-               type = TRACKER_TYPE_SERIALIZER_JSON;
+               type = g_type_from_name ("TrackerSerializerJson");
+               if (type == 0)
+                       type = TRACKER_TYPE_SERIALIZER_JSON;
                break;
        case TRACKER_SERIALIZER_FORMAT_XML:
-               type = TRACKER_TYPE_SERIALIZER_XML;
+               type = g_type_from_name ("TrackerSerializerXml");
+               if (type == 0)
+                       type = TRACKER_TYPE_SERIALIZER_XML;
                break;
        default:
                g_warn_if_reached ();


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