[tracker/wip/carlosg/tracker-3.0-api-breaks: 24/100] libtracker-sparql: Make TrackerSparqlConnection generate TrackerNotifiers
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/tracker-3.0-api-breaks: 24/100] libtracker-sparql: Make TrackerSparqlConnection generate TrackerNotifiers
- Date: Mon, 17 Feb 2020 18:10:49 +0000 (UTC)
commit 8661e13923cfaeab5088d79eaec5173d04a29236
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Dec 20 16:32:05 2019 +0100
libtracker-sparql: Make TrackerSparqlConnection generate TrackerNotifiers
There's now a tracker_sparql_connection_create_notifier() vmethod that
subclasses may implement. This makes the relation between a notifier and
a sparql connection direct, instead of completely undefined.
.../reference/libtracker-sparql/migrating-2to3.xml | 6 +
.../libtracker-sparql-intermediate-c.vapi | 4 +-
src/libtracker-sparql/tracker-connection.vala | 5 +
src/libtracker-sparql/tracker-notifier.c | 144 +++------------------
src/libtracker-sparql/tracker-notifier.h | 5 -
5 files changed, 29 insertions(+), 135 deletions(-)
---
diff --git a/docs/reference/libtracker-sparql/migrating-2to3.xml
b/docs/reference/libtracker-sparql/migrating-2to3.xml
index 3dbb64972..a23477eb2 100644
--- a/docs/reference/libtracker-sparql/migrating-2to3.xml
+++ b/docs/reference/libtracker-sparql/migrating-2to3.xml
@@ -127,4 +127,10 @@ ORDER BY DESC ?count
those elements in place. Other ontologies might have similar concepts.
</para>
</section>
+ <section>
+ <title>No tracker_notifier_new()</title>
+ <para>
+ Notifiers are now created through tracker_sparql_connection_create_notifier().
+ </para>
+ </section>
</chapter>
diff --git a/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
b/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
index 74fa7c0b0..79cdf310d 100644
--- a/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
+++ b/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
@@ -84,9 +84,7 @@ namespace Tracker {
}
[CCode (cheader_filename = "libtracker-sparql/tracker-notifier.h")]
- public class Notifier : GLib.Object, GLib.Initable {
- public Notifier (string[] classes, NotifierFlags flags, GLib.Cancellable? cancellable) throws
GLib.Error;
-
+ public class Notifier : GLib.Object {
public class NotifierEvent {
public enum Type {
CREATE,
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index 712bc3d08..084a1688b 100644
--- a/src/libtracker-sparql/tracker-connection.vala
+++ b/src/libtracker-sparql/tracker-connection.vala
@@ -552,4 +552,9 @@ public abstract class Tracker.Sparql.Connection : Object {
warning ("Interface 'query_statement' not implemented");
return null;
}
+
+ public virtual Tracker.Notifier? create_notifier (Tracker.NotifierFlags flags) {
+ warning ("Interface 'create_notifier' not implemented");
+ return null;
+ }
}
diff --git a/src/libtracker-sparql/tracker-notifier.c b/src/libtracker-sparql/tracker-notifier.c
index fc867744a..37b3224ce 100644
--- a/src/libtracker-sparql/tracker-notifier.c
+++ b/src/libtracker-sparql/tracker-notifier.c
@@ -24,11 +24,9 @@
*
* #TrackerNotifier is an object that receives notifications about
* changes to the Tracker database. A #TrackerNotifier is created
- * through tracker_notifier_new(), passing the RDF types that are
- * relevant to the caller, and possible different #TrackerNotifierFlags
- * to change #TrackerNotifier behavior. After the notifier is created,
- * events can be listened for by connecting to the #TrackerNotifier::events
- * signal. This object was added in Tracker 1.12.
+ * through tracker_sparql_connection_create_notifier(), after the notifier
+ * is created, events can be listened for by connecting to the
+ * #TrackerNotifier::events signal. This object was added in Tracker 1.12.
*
* #TrackerNotifier is tracker:id centric, the ID can be
* obtained from every event through tracker_notifier_event_get_id().
@@ -85,8 +83,6 @@ struct _TrackerNotifierPrivate {
TrackerSparqlConnection *connection;
TrackerNotifierFlags flags;
GHashTable *subscriptions; /* guint -> TrackerNotifierSubscription */
- gchar **expanded_classes;
- gchar **classes;
};
struct _TrackerNotifierEventCache {
@@ -105,7 +101,7 @@ struct _TrackerNotifierEvent {
enum {
PROP_0,
- PROP_CLASSES,
+ PROP_CONNECTION,
PROP_FLAGS,
N_PROPS
};
@@ -117,12 +113,8 @@ enum {
static guint signals[N_SIGNALS] = { 0 };
-static void tracker_notifier_initable_iface_init (GInitableIface *iface);
-
G_DEFINE_TYPE_WITH_CODE (TrackerNotifier, tracker_notifier, G_TYPE_OBJECT,
- G_ADD_PRIVATE (TrackerNotifier)
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- tracker_notifier_initable_iface_init))
+ G_ADD_PRIVATE (TrackerNotifier))
static TrackerNotifierSubscription *
tracker_notifier_subscription_new (GDBusConnection *connection,
@@ -440,78 +432,6 @@ graph_updated_cb (GDBusConnection *connection,
tracker_notifier_event_cache_free (cache);
}
-static gboolean
-expand_class_iris (TrackerNotifier *notifier,
- GCancellable *cancellable,
- GError **error)
-{
- TrackerNotifierPrivate *priv;
- TrackerSparqlCursor *cursor;
- GArray *expanded;
- GString *sparql;
- gint i, n_classes;
-
- priv = tracker_notifier_get_instance_private (notifier);
-
- if (!priv->classes) {
- priv->expanded_classes = NULL;
- return TRUE;
- }
-
- n_classes = g_strv_length (priv->classes);
-
- sparql = g_string_new ("SELECT ");
- for (i = 0; i < n_classes; i++)
- g_string_append_printf (sparql, "%s ", priv->classes[i]);
- g_string_append_printf (sparql, "{}");
-
- cursor = tracker_sparql_connection_query (priv->connection, sparql->str,
- cancellable, error);
- g_string_free (sparql, TRUE);
-
- if (!cursor)
- return FALSE;
- if (!tracker_sparql_cursor_next (cursor, cancellable, error))
- return FALSE;
-
- expanded = g_array_new (TRUE, TRUE, sizeof (gchar*));
-
- for (i = 0; i < tracker_sparql_cursor_get_n_columns (cursor); i++) {
- gchar *str = g_strdup (tracker_sparql_cursor_get_string (cursor, i, NULL));
- g_array_append_val (expanded, str);
- }
-
- priv->expanded_classes = (gchar **) g_array_free (expanded, FALSE);
- g_object_unref (cursor);
-
- return TRUE;
-}
-
-static gboolean
-tracker_notifier_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- TrackerNotifier *notifier = TRACKER_NOTIFIER (initable);
- TrackerNotifierPrivate *priv;
-
- priv = tracker_notifier_get_instance_private (notifier);
- priv->connection = tracker_sparql_connection_get (cancellable, error);
- if (!priv->connection)
- return FALSE;
-
- if (!expand_class_iris (notifier, cancellable, error))
- return FALSE;
-
- return TRUE;
-}
-
-static void
-tracker_notifier_initable_iface_init (GInitableIface *iface)
-{
- iface->init = tracker_notifier_initable_init;
-}
-
static void
tracker_notifier_set_property (GObject *object,
guint prop_id,
@@ -522,8 +442,8 @@ tracker_notifier_set_property (GObject *object,
TrackerNotifierPrivate *priv = tracker_notifier_get_instance_private (notifier);
switch (prop_id) {
- case PROP_CLASSES:
- priv->classes = g_value_dup_boxed (value);
+ case PROP_CONNECTION:
+ priv->connection = g_value_dup_object (value);
break;
case PROP_FLAGS:
priv->flags = g_value_get_flags (value);
@@ -544,8 +464,8 @@ tracker_notifier_get_property (GObject *object,
TrackerNotifierPrivate *priv = tracker_notifier_get_instance_private (notifier);
switch (prop_id) {
- case PROP_CLASSES:
- g_value_set_boxed (value, priv->classes);
+ case PROP_CONNECTION:
+ g_value_set_object (value, priv->connection);
break;
case PROP_FLAGS:
g_value_set_flags (value, priv->flags);
@@ -567,8 +487,6 @@ tracker_notifier_finalize (GObject *object)
g_object_unref (priv->connection);
g_hash_table_unref (priv->subscriptions);
- g_strfreev (priv->expanded_classes);
- g_strfreev (priv->classes);
G_OBJECT_CLASS (tracker_notifier_parent_class)->finalize (object);
}
@@ -604,14 +522,14 @@ tracker_notifier_class_init (TrackerNotifierClass *klass)
*
* RDF classes to listen notifications about.
*/
- pspecs[PROP_CLASSES] =
- g_param_spec_boxed ("classes",
- "Classes",
- "Classes",
- G_TYPE_STRV,
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS |
- G_PARAM_CONSTRUCT_ONLY);
+ pspecs[PROP_CONNECTION] =
+ g_param_spec_object ("connection",
+ "SPARQL connection",
+ "SPARQL connection",
+ TRACKER_SPARQL_TYPE_CONNECTION,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_CONSTRUCT_ONLY);
/**
* TrackerNotifier:flags:
*
@@ -640,34 +558,6 @@ tracker_notifier_init (TrackerNotifier *notifier)
(GDestroyNotify) tracker_notifier_subscription_free);
}
-/**
- * tracker_notifier_new:
- * @classes: (array zero-terminated=1) (allow-none): Array of RDF classes to
- * receive notifications from, or %NULL for all.
- * @flags: flags affecting the notifier behavior
- * @cancellable: Cancellable for the operation
- * @error: location for the possible resulting error.
- *
- * Creates a new notifier, events can be listened through the
- * TrackerNotifier::events signal.
- *
- * Returns: (nullable): a newly created #TrackerNotifier, %NULL on error.
- *
- * Since: 1.12
- **/
-TrackerNotifier*
-tracker_notifier_new (const gchar * const *classes,
- TrackerNotifierFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- return g_initable_new (TRACKER_TYPE_NOTIFIER,
- cancellable, error,
- "classes", classes,
- "flags", flags,
- NULL);
-}
-
guint
tracker_notifier_signal_subscribe (TrackerNotifier *notifier,
GDBusConnection *connection,
diff --git a/src/libtracker-sparql/tracker-notifier.h b/src/libtracker-sparql/tracker-notifier.h
index 8e0458556..4262f1402 100644
--- a/src/libtracker-sparql/tracker-notifier.h
+++ b/src/libtracker-sparql/tracker-notifier.h
@@ -68,11 +68,6 @@ typedef enum {
TRACKER_NOTIFIER_EVENT_UPDATE
} TrackerNotifierEventType;
-TrackerNotifier * tracker_notifier_new (const gchar * const *classes,
- TrackerNotifierFlags flags,
- GCancellable *cancellable,
- GError **error);
-
guint tracker_notifier_signal_subscribe (TrackerNotifier *notifier,
GDBusConnection *connection,
const gchar *service,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]