[tracker/wip/carlosg/local-connection-mapping: 350/353] libtracker-data: Add private API to map local connections




commit e45b01e48a77f996e72c8ae779ebf0d07c793795
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Apr 3 15:43:16 2021 +0200

    libtracker-data: Add private API to map local connections
    
    These will be available via special private:$handle_name URIs.

 src/libtracker-data/tracker-data-manager.c | 24 ++++++++++++++++++------
 src/libtracker-data/tracker-data-manager.h |  3 +++
 2 files changed, 21 insertions(+), 6 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 0a0c44f63..203b83b85 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -149,6 +149,9 @@ static void
 tracker_data_manager_init (TrackerDataManager *manager)
 {
        manager->generation = 1;
+       manager->cached_connections =
+               g_hash_table_new_full (g_str_hash, g_str_equal,
+                                      g_free, g_object_unref);
        g_mutex_init (&manager->connections_lock);
 }
 
@@ -5256,12 +5259,6 @@ tracker_data_manager_get_remote_connection (TrackerDataManager  *data_manager,
 
        g_mutex_lock (&data_manager->connections_lock);
 
-       if (!data_manager->cached_connections) {
-               data_manager->cached_connections =
-                       g_hash_table_new_full (g_str_hash, g_str_equal,
-                                              g_free, g_object_unref);
-       }
-
        connection = g_hash_table_lookup (data_manager->cached_connections, uri);
 
        if (!connection) {
@@ -5330,3 +5327,18 @@ fail:
 
        return connection;
 }
+
+void
+tracker_data_manager_map_connection (TrackerDataManager      *data_manager,
+                                     const gchar             *handle_name,
+                                     TrackerSparqlConnection *connection)
+{
+       gchar *uri;
+
+       uri = g_strdup_printf ("private:%s", handle_name);
+
+       g_mutex_lock (&data_manager->connections_lock);
+       g_hash_table_insert (data_manager->cached_connections,
+                            uri, g_object_ref (connection));
+       g_mutex_unlock (&data_manager->connections_lock);
+}
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index 47f8c07f9..bb4a30e3b 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -116,6 +116,9 @@ gboolean             tracker_data_manager_expand_prefix (TrackerDataManager  *ma
 TrackerSparqlConnection * tracker_data_manager_get_remote_connection (TrackerDataManager  *data_manager,
                                                                       const gchar         *uri,
                                                                       GError             **error);
+void tracker_data_manager_map_connection (TrackerDataManager      *data_manager,
+                                          const gchar             *handle_name,
+                                          TrackerSparqlConnection *connection);
 
 G_END_DECLS
 


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