[tracker/wip/carlosg/tracker-3.0-api-breaks: 95/95] libtracker-sparql: Add tracker_sparql_connection_close_async/finish
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/tracker-3.0-api-breaks: 95/95] libtracker-sparql: Add tracker_sparql_connection_close_async/finish
- Date: Fri, 14 Feb 2020 13:38:36 +0000 (UTC)
commit 615425eb6ca329b3bb937dbf0931c7d69d83d870
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Feb 12 14:08:24 2020 +0100
libtracker-sparql: Add tracker_sparql_connection_close_async/finish
Since it may be "expensive" with a big amount of pending requests, add
an async variant so it doesn't have to block the main loop.
.../libtracker-sparql-sections.txt | 2 +
src/libtracker-bus/tracker-bus.vala | 4 ++
src/libtracker-direct/tracker-direct.c | 36 +++++++++++++++
src/libtracker-remote/tracker-remote.vala | 4 ++
.../libtracker-sparql-intermediate-c.vapi | 1 +
src/libtracker-sparql/tracker-connection.c | 51 ++++++++++++++++++++++
src/libtracker-sparql/tracker-connection.h | 11 +++++
src/libtracker-sparql/tracker-private.h | 7 +++
8 files changed, 116 insertions(+)
---
diff --git a/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
b/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
index f5e01b572..0856947f6 100644
--- a/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
+++ b/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
@@ -120,6 +120,8 @@ tracker_sparql_connection_update_blank_finish
tracker_sparql_connection_get_namespace_manager
tracker_sparql_connection_create_notifier
tracker_sparql_connection_close
+tracker_sparql_connection_close_async
+tracker_sparql_connection_close_finish
<SUBSECTION Standard>
TrackerSparqlConnectionClass
TRACKER_SPARQL_CONNECTION
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index 72e21f770..03b3030f1 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -272,4 +272,8 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
public override void close () {
}
+
+ public async override bool close_async () throws GLib.IOError {
+ return true;
+ }
}
diff --git a/src/libtracker-direct/tracker-direct.c b/src/libtracker-direct/tracker-direct.c
index 8527f9672..25d8670ba 100644
--- a/src/libtracker-direct/tracker-direct.c
+++ b/src/libtracker-direct/tracker-direct.c
@@ -940,6 +940,40 @@ tracker_direct_connection_close (TrackerSparqlConnection *self)
}
}
+void
+async_close_thread_func (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ if (g_task_return_error_if_cancelled (task))
+ return;
+
+ tracker_sparql_connection_close (source_object);
+ g_task_return_boolean (task, TRUE);
+}
+
+void
+tracker_direct_connection_close_async (TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+
+ task = g_task_new (connection, cancellable, callback, user_data);
+ g_task_run_in_thread (task, async_close_thread_func);
+ g_object_unref (task);
+}
+
+gboolean
+tracker_direct_connection_close_finish (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error)
+{
+ return g_task_propagate_boolean (G_TASK (res), error);
+}
+
static void
tracker_direct_connection_class_init (TrackerDirectConnectionClass *klass)
{
@@ -968,6 +1002,8 @@ tracker_direct_connection_class_init (TrackerDirectConnectionClass *klass)
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;
+ sparql_connection_class->close_async = tracker_direct_connection_close_async;
+ sparql_connection_class->close_finish = tracker_direct_connection_close_finish;
props[PROP_FLAGS] =
g_param_spec_flags ("flags",
diff --git a/src/libtracker-remote/tracker-remote.vala b/src/libtracker-remote/tracker-remote.vala
index 7d083b12a..206c237fc 100644
--- a/src/libtracker-remote/tracker-remote.vala
+++ b/src/libtracker-remote/tracker-remote.vala
@@ -90,4 +90,8 @@ public class Tracker.Remote.Connection : Tracker.Sparql.Connection {
public override void close () {
}
+
+ public async override bool close_async () throws GLib.IOError {
+ return true;
+ }
}
diff --git a/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
b/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
index bebd6f82b..bc513d2e6 100644
--- a/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
+++ b/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
@@ -90,6 +90,7 @@ namespace Tracker {
public virtual Notifier? create_notifier (NotifierFlags flags);
public virtual void close ();
+ public async virtual bool close_async () throws GLib.IOError;
}
[CCode (cheader_filename = "libtracker-sparql/tracker-statement.h")]
diff --git a/src/libtracker-sparql/tracker-connection.c b/src/libtracker-sparql/tracker-connection.c
index d5ba6ce31..0280f94db 100644
--- a/src/libtracker-sparql/tracker-connection.c
+++ b/src/libtracker-sparql/tracker-connection.c
@@ -577,3 +577,54 @@ tracker_sparql_connection_close (TrackerSparqlConnection *connection)
TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->close (connection);
}
+
+/**
+ * tracker_sparql_connection_close_async:
+ * @connection: a #TrackerSparqlConnection
+ * @cancellable: a #GCancellable, or %NULL
+ * @callback: user-defined #GAsyncReadyCallback to be called when
+ * asynchronous operation is finished.
+ * @user_data: user-defined data to be passed to @callback
+ *
+ * Closes a connection asynchronously. No other API calls than g_object_unref()
+ * should happen after this call. See tracker_sparql_connection_close() for more
+ * information.
+ *
+ * Since: 3.0
+ **/
+void
+tracker_sparql_connection_close_async (TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection));
+
+ TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->close_async (connection,
+ cancellable,
+ callback,
+ user_data);
+}
+
+/**
+ * tracker_sparql_connection_close_finish:
+ * @connection: a #TrackerSparqlConnection
+ * @result: the #GAsyncResult
+ * @error: pointer to a #GError
+ *
+ * Finishes the asynchronous connection close.
+ *
+ * Returns: %FALSE if some error occurred, %TRUE otherwise
+ *
+ * Since: 3.0
+ **/
+gboolean
+tracker_sparql_connection_close_finish (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection), FALSE);
+
+ return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->close_finish (connection,
+ res, error);
+}
diff --git a/src/libtracker-sparql/tracker-connection.h b/src/libtracker-sparql/tracker-connection.h
index 01cd9f076..f35d22acb 100644
--- a/src/libtracker-sparql/tracker-connection.h
+++ b/src/libtracker-sparql/tracker-connection.h
@@ -205,4 +205,15 @@ TrackerNotifier * tracker_sparql_connection_create_notifier (TrackerSparqlConnec
TRACKER_AVAILABLE_IN_ALL
void tracker_sparql_connection_close (TrackerSparqlConnection *connection);
+TRACKER_AVAILABLE_IN_ALL
+void tracker_sparql_connection_close_async (TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+TRACKER_AVAILABLE_IN_ALL
+gboolean tracker_sparql_connection_close_finish (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error);
+
#endif /* __TRACKER_SPARQL_CONNECTION_H__ */
diff --git a/src/libtracker-sparql/tracker-private.h b/src/libtracker-sparql/tracker-private.h
index 9d4060b04..3ac055746 100644
--- a/src/libtracker-sparql/tracker-private.h
+++ b/src/libtracker-sparql/tracker-private.h
@@ -87,6 +87,13 @@ struct _TrackerSparqlConnectionClass
TrackerNotifierFlags flags);
void (* close) (TrackerSparqlConnection *connection);
+ void (* close_async) (TrackerSparqlConnection *connection,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ gboolean (* close_finish) (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error);
};
typedef struct _TrackerSparqlCursorClass TrackerSparqlCursorClass;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]