[tracker/wip/carlosg/tracker-3.0-api-breaks: 46/56] libtracker-sparql: Add tracker_sparql_connection_close()



commit cc82ce2613d6b139443487bed16ea009d0cacc3c
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Dec 30 19:11:23 2019 +0100

    libtracker-sparql: Add tracker_sparql_connection_close()
    
    It is important for SPARQL connections created through
    tracker_sparql_connection_new() to be properly disposed so the databases
    may be cleanly closed.
    
    This is usually not a problem, given proper refcount handling, but it
    seems better to offer an explicit function just in case it isn't, or if
    refcounting simply isn't under our control (say, a GC language).

 .../libtracker-sparql-sections.txt                 |  1 +
 src/libtracker-bus/tracker-bus.vala                |  3 +++
 src/libtracker-direct/tracker-direct.c             | 31 +++++++++++++++++++---
 src/libtracker-remote/tracker-remote.vala          |  3 +++
 src/libtracker-sparql/tracker-connection.vala      | 17 ++++++++++++
 5 files changed, 52 insertions(+), 3 deletions(-)
---
diff --git a/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt 
b/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
index 91b0ab2e3..948b63253 100644
--- a/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
+++ b/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
@@ -121,6 +121,7 @@ tracker_sparql_connection_update_blank
 tracker_sparql_connection_update_blank_async
 tracker_sparql_connection_update_blank_finish
 tracker_sparql_connection_get_namespace_manager
+tracker_sparql_connection_close
 <SUBSECTION Standard>
 TrackerSparqlConnectionClass
 TRACKER_SPARQL_CONNECTION
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index 455d274c4..72279a7ef 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -265,4 +265,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 
                return notifier;
        }
+
+       public override void close () {
+       }
 }
diff --git a/src/libtracker-direct/tracker-direct.c b/src/libtracker-direct/tracker-direct.c
index 4991e1a52..34c6a80da 100644
--- a/src/libtracker-direct/tracker-direct.c
+++ b/src/libtracker-direct/tracker-direct.c
@@ -508,7 +508,7 @@ weak_ref_notify (gpointer  data,
 }
 
 static void
-tracker_direct_connection_finalize (GObject *object)
+tracker_direct_connection_dispose (GObject *object)
 {
        TrackerDirectConnectionPrivate *priv;
        TrackerDirectConnection *conn;
@@ -516,16 +516,33 @@ tracker_direct_connection_finalize (GObject *object)
        conn = TRACKER_DIRECT_CONNECTION (object);
        priv = tracker_direct_connection_get_instance_private (conn);
 
-       if (priv->update_thread)
+       if (priv->update_thread) {
                g_thread_pool_free (priv->update_thread, TRUE, TRUE);
-       if (priv->select_pool)
+               priv->update_thread = NULL;
+       }
+
+       if (priv->select_pool) {
                g_thread_pool_free (priv->select_pool, TRUE, FALSE);
+               priv->select_pool = NULL;
+       }
 
        if (priv->data_manager) {
                tracker_data_manager_shutdown (priv->data_manager);
                g_clear_object (&priv->data_manager);
        }
 
+       G_OBJECT_CLASS (tracker_direct_connection_parent_class)->dispose (object);
+}
+
+static void
+tracker_direct_connection_finalize (GObject *object)
+{
+       TrackerDirectConnectionPrivate *priv;
+       TrackerDirectConnection *conn;
+
+       conn = TRACKER_DIRECT_CONNECTION (object);
+       priv = tracker_direct_connection_get_instance_private (conn);
+
        while (priv->notifiers) {
                TrackerNotifier *notifier = priv->notifiers->data;
 
@@ -887,6 +904,12 @@ tracker_direct_connection_create_notifier (TrackerSparqlConnection *self,
        return notifier;
 }
 
+static void
+tracker_direct_connection_close (TrackerSparqlConnection *self)
+{
+       g_object_run_dispose (G_OBJECT (self));
+}
+
 static void
 tracker_direct_connection_class_init (TrackerDirectConnectionClass *klass)
 {
@@ -897,6 +920,7 @@ tracker_direct_connection_class_init (TrackerDirectConnectionClass *klass)
        sparql_connection_class = TRACKER_SPARQL_CONNECTION_CLASS (klass);
 
        object_class->finalize = tracker_direct_connection_finalize;
+       object_class->dispose = tracker_direct_connection_dispose;
        object_class->set_property = tracker_direct_connection_set_property;
        object_class->get_property = tracker_direct_connection_get_property;
 
@@ -914,6 +938,7 @@ tracker_direct_connection_class_init (TrackerDirectConnectionClass *klass)
        sparql_connection_class->update_blank_finish = tracker_direct_connection_update_blank_finish;
        sparql_connection_class->get_namespace_manager = tracker_direct_connection_get_namespace_manager;
        sparql_connection_class->create_notifier = tracker_direct_connection_create_notifier;
+       sparql_connection_class->close = tracker_direct_connection_close;
 
        props[PROP_FLAGS] =
                g_param_spec_enum ("flags",
diff --git a/src/libtracker-remote/tracker-remote.vala b/src/libtracker-remote/tracker-remote.vala
index e5025f6b0..d63ed18f1 100644
--- a/src/libtracker-remote/tracker-remote.vala
+++ b/src/libtracker-remote/tracker-remote.vala
@@ -86,4 +86,7 @@ public class Tracker.Remote.Connection : Tracker.Sparql.Connection {
 
                return create_cursor (message);
        }
+
+       public override void close () {
+       }
 }
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index 8a3ec5c06..44b27264e 100644
--- a/src/libtracker-sparql/tracker-connection.vala
+++ b/src/libtracker-sparql/tracker-connection.vala
@@ -413,4 +413,21 @@ public abstract class Tracker.Sparql.Connection : Object {
                warning ("Interface 'create_notifier' not implemented");
                return null;
        }
+
+       /**
+        * tracker_sparql_connection_close:
+        * @self: a #TrackerSparqlConnection
+        *
+        * Closes a SPARQL connection. No other API calls than g_object_unref()
+        * should happen after this call.
+        *
+        * This call is blocking. All pending updates will be flushed, and the
+        * store databases will be closed orderly. All ongoing SELECT queries
+        * will be cancelled.
+        *
+        * Since: 3.0
+        */
+       public virtual void close () {
+               warning ("Not implemented");
+       }
 }


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