[tracker/wip/carlosg/local-connection-mapping: 1/3] libtracker-sparql: Add tracker_sparql_connection_map_connection()
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/local-connection-mapping: 1/3] libtracker-sparql: Add tracker_sparql_connection_map_connection()
- Date: Sun, 12 Dec 2021 16:56:38 +0000 (UTC)
commit 6e4c92592685b2647da5fb8ab75576b8061472d4
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Apr 3 15:43:49 2021 +0200
libtracker-sparql: Add tracker_sparql_connection_map_connection()
This API call allows hooking up a local TrackerSparqlConnection into
another, so it is possible to access other local connections from
one of them. This happens via the SERVICE SPARQL syntax, using
special local:$handle_name URIs.
This may be useful if there is data with different relevance (e.g.
cache vs persistent) that the application is interested in maintaining
separately, but query altogether.
src/libtracker-sparql/direct/tracker-direct.c | 17 +++++++++++
src/libtracker-sparql/tracker-connection.c | 43 +++++++++++++++++++++++++++
src/libtracker-sparql/tracker-connection.h | 5 ++++
src/libtracker-sparql/tracker-private.h | 3 ++
4 files changed, 68 insertions(+)
---
diff --git a/src/libtracker-sparql/direct/tracker-direct.c b/src/libtracker-sparql/direct/tracker-direct.c
index 12e6b1db7..6b7a78165 100644
--- a/src/libtracker-sparql/direct/tracker-direct.c
+++ b/src/libtracker-sparql/direct/tracker-direct.c
@@ -1226,6 +1226,22 @@ tracker_direct_connection_lookup_dbus_service (TrackerSparqlConnection *connect
return TRUE;
}
+static void
+tracker_direct_connection_map_connection (TrackerSparqlConnection *connection,
+ const gchar *handle_name,
+ TrackerSparqlConnection *service_connection)
+{
+ TrackerDirectConnectionPrivate *priv;
+ TrackerDirectConnection *conn;
+
+ conn = TRACKER_DIRECT_CONNECTION (connection);
+ priv = tracker_direct_connection_get_instance_private (conn);
+
+ tracker_data_manager_map_connection (priv->data_manager,
+ handle_name,
+ service_connection);
+}
+
static void
tracker_direct_connection_class_init (TrackerDirectConnectionClass *klass)
{
@@ -1261,6 +1277,7 @@ tracker_direct_connection_class_init (TrackerDirectConnectionClass *klass)
sparql_connection_class->update_resource_finish = tracker_direct_connection_update_resource_finish;
sparql_connection_class->create_batch = tracker_direct_connection_create_batch;
sparql_connection_class->lookup_dbus_service = tracker_direct_connection_lookup_dbus_service;
+ sparql_connection_class->map_connection = tracker_direct_connection_map_connection;
props[PROP_FLAGS] =
g_param_spec_flags ("flags",
diff --git a/src/libtracker-sparql/tracker-connection.c b/src/libtracker-sparql/tracker-connection.c
index e2585d440..b3814d2cc 100644
--- a/src/libtracker-sparql/tracker-connection.c
+++ b/src/libtracker-sparql/tracker-connection.c
@@ -61,6 +61,8 @@
#include "tracker-connection.h"
#include "tracker-private.h"
+#include "direct/tracker-direct.h"
+
G_DEFINE_ABSTRACT_TYPE (TrackerSparqlConnection, tracker_sparql_connection,
G_TYPE_OBJECT)
@@ -858,3 +860,44 @@ tracker_sparql_connection_load_statement_from_gresource (TrackerSparqlConnection
return stmt;
}
+
+/**
+ * tracker_sparql_connection_map_connection:
+ * @connection: a #TrackerSparqlConnection
+ * @handle_name: handle name for @service_connection
+ * @service_connection: a #TrackerSparqlConnection to use from @connection
+ *
+ * Maps @service_connection so it is available as a "private:@handle_name" URI
+ * in @connection. This can be accessed via the SERVICE SPARQL syntax in
+ * queries from @connection. E.g.:
+ *
+ * ```sparql
+ * SELECT ?u {
+ * SERVICE <private:other-connection> {
+ * ?u a rdfs:Resource
+ * }
+ * }
+ * ```
+ *
+ * This is useful to interrelate data from multiple
+ * #TrackerSparqlConnection instances maintained by the same process,
+ * without creating a public endpoint for @service_connection.
+ *
+ * @connection may only be a #TrackerSparqlConnection created via
+ * tracker_sparql_connection_new() and tracker_sparql_connection_new_async().
+ *
+ * Since: 3.3
+ **/
+void
+tracker_sparql_connection_map_connection (TrackerSparqlConnection *connection,
+ const gchar *handle_name,
+ TrackerSparqlConnection *service_connection)
+{
+ g_return_if_fail (TRACKER_IS_DIRECT_CONNECTION (connection));
+ g_return_if_fail (TRACKER_IS_SPARQL_CONNECTION (service_connection));
+ g_return_if_fail (handle_name && *handle_name);
+
+ return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->map_connection (connection,
+ handle_name,
+ service_connection);
+}
diff --git a/src/libtracker-sparql/tracker-connection.h b/src/libtracker-sparql/tracker-connection.h
index 00840cd16..93a759a85 100644
--- a/src/libtracker-sparql/tracker-connection.h
+++ b/src/libtracker-sparql/tracker-connection.h
@@ -218,6 +218,11 @@ TrackerSparqlStatement * tracker_sparql_connection_load_statement_from_gresource
GCancellable
*cancellable,
GError
**error);
+TRACKER_AVAILABLE_IN_3_3
+void tracker_sparql_connection_map_connection (TrackerSparqlConnection *connection,
+ const gchar *handle_name,
+ TrackerSparqlConnection *service_connection);
+
G_END_DECLS
#endif /* __TRACKER_SPARQL_CONNECTION_H__ */
diff --git a/src/libtracker-sparql/tracker-private.h b/src/libtracker-sparql/tracker-private.h
index 448581acd..35cff490a 100644
--- a/src/libtracker-sparql/tracker-private.h
+++ b/src/libtracker-sparql/tracker-private.h
@@ -110,6 +110,9 @@ struct _TrackerSparqlConnectionClass
const gchar *dbus_path,
gchar **name,
gchar **path);
+ void (* map_connection) (TrackerSparqlConnection *connection,
+ const gchar *handle_name,
+ TrackerSparqlConnection *service_connection);
};
struct _TrackerSparqlCursorClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]