[tracker/wip/carlosg/serialize-api: 18/26] libtracker-sparql: Add TrackerSparqlStatement API to serialize RDF




commit 2b2cfe7296b0b10a1933ae8343e65a941f8c0aba
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Nov 27 14:04:54 2021 +0100

    libtracker-sparql: Add TrackerSparqlStatement API to serialize RDF
    
    These queries must still be DESCRIBE/CONSTRUCT queries. This allows
    to use all nice features that TrackerSparqlStatement allows (variables,
    loading queries from resources, ...) with serialization queries.

 src/libtracker-sparql/tracker-private.h   |  9 +++++
 src/libtracker-sparql/tracker-statement.c | 66 +++++++++++++++++++++++++++++++
 src/libtracker-sparql/tracker-statement.h | 12 ++++++
 3 files changed, 87 insertions(+)
---
diff --git a/src/libtracker-sparql/tracker-private.h b/src/libtracker-sparql/tracker-private.h
index e5be247f4..2a7fd6d9e 100644
--- a/src/libtracker-sparql/tracker-private.h
+++ b/src/libtracker-sparql/tracker-private.h
@@ -232,6 +232,15 @@ struct _TrackerSparqlStatementClass
                                                   GAsyncResult            *res,
                                                   GError                 **error);
        void (* clear_bindings) (TrackerSparqlStatement *stmt);
+
+        void (* serialize_async) (TrackerSparqlStatement *stmt,
+                                  TrackerRdfFormat        format,
+                                  GCancellable           *cancellable,
+                                  GAsyncReadyCallback     callback,
+                                  gpointer                user_data);
+        GInputStream * (* serialize_finish) (TrackerSparqlStatement  *stmt,
+                                             GAsyncResult            *res,
+                                             GError                 **error);
 };
 
 struct _TrackerNotifierClass {
diff --git a/src/libtracker-sparql/tracker-statement.c b/src/libtracker-sparql/tracker-statement.c
index 261265197..d064456c1 100644
--- a/src/libtracker-sparql/tracker-statement.c
+++ b/src/libtracker-sparql/tracker-statement.c
@@ -398,3 +398,69 @@ tracker_sparql_statement_clear_bindings (TrackerSparqlStatement *stmt)
 
        TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->clear_bindings (stmt);
 }
+
+/**
+ * tracker_sparql_statement_serialize_async:
+ * @stmt: a #TrackerSparqlStatement
+ * @format: RDF format of the serialized data
+ * @cancellable: (nullable): a #GCancellable used to cancel the operation
+ * @callback: user-defined #GAsyncReadyCallback to be called when
+ *            asynchronous operation is finished.
+ * @user_data: user-defined data to be passed to @callback
+ *
+ * Serializes data into the specified RDF format. The query @stmt was
+ * created from must be either a `DESCRIBE` or `CONSTRUCT` query, an
+ * error will be raised otherwise.
+ *
+ * This is an asynchronous operation, @callback will be invoked when the
+ * data is available for reading.
+ *
+ * The SPARQL endpoint may not support the specified format, in that case
+ * an error will be raised.
+ *
+ * Since: 3.3
+ **/
+void
+tracker_sparql_statement_serialize_async (TrackerSparqlStatement *stmt,
+                                          TrackerRdfFormat        format,
+                                          GCancellable           *cancellable,
+                                          GAsyncReadyCallback     callback,
+                                          gpointer                user_data)
+{
+       g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
+       g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+       g_return_if_fail (callback != NULL);
+
+       TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->serialize_async (stmt,
+                                                                   format,
+                                                                   cancellable,
+                                                                   callback,
+                                                                   user_data);
+}
+
+/**
+ * tracker_sparql_statement_serialize_finish:
+ * @stmt: a #TrackerSparqlStatement
+ * @result: the #GAsyncResult
+ * @error: location for returned errors, or %NULL
+ *
+ * Finishes a tracker_sparql_statement_serialize_async() operation.
+ * In case of error, %NULL will be returned and @error will be set.
+ *
+ * Returns: (transfer full): a #GInputStream to read RDF content.
+ *
+ * Since: 3.3
+ **/
+GInputStream *
+tracker_sparql_statement_serialize_finish (TrackerSparqlStatement  *stmt,
+                                           GAsyncResult            *result,
+                                           GError                 **error)
+{
+       g_return_val_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt), NULL);
+       g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
+       g_return_val_if_fail (!error || !*error, NULL);
+
+       return TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->serialize_finish (stmt,
+                                                                           result,
+                                                                           error);
+}
diff --git a/src/libtracker-sparql/tracker-statement.h b/src/libtracker-sparql/tracker-statement.h
index ead440c78..1581343f3 100644
--- a/src/libtracker-sparql/tracker-statement.h
+++ b/src/libtracker-sparql/tracker-statement.h
@@ -91,6 +91,18 @@ TrackerSparqlCursor * tracker_sparql_statement_execute_finish (TrackerSparqlStat
                                                                GAsyncResult            *res,
                                                                GError                 **error);
 
+TRACKER_AVAILABLE_IN_3_3
+void tracker_sparql_statement_serialize_async (TrackerSparqlStatement *stmt,
+                                               TrackerRdfFormat        format,
+                                               GCancellable           *cancellable,
+                                               GAsyncReadyCallback     callback,
+                                               gpointer                user_data);
+
+TRACKER_AVAILABLE_IN_3_3
+GInputStream * tracker_sparql_statement_serialize_finish (TrackerSparqlStatement  *stmt,
+                                                          GAsyncResult            *result,
+                                                          GError                 **error);
+
 TRACKER_AVAILABLE_IN_ALL
 void tracker_sparql_statement_clear_bindings (TrackerSparqlStatement *stmt);
 


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