[tracker-miners/wip/carlosg/tracker-3.0-api-breaks: 15/40] rss: Use TrackerNotifier to listen to mfo:FeedChannel changes



commit 4e6932912437d48999a0300db7c629e7b3cbb065
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Dec 24 13:03:35 2019 +0100

    rss: Use TrackerNotifier to listen to mfo:FeedChannel changes
    
    Replaces the direct usage of GraphUpdated.

 src/miners/rss/tracker-miner-rss.c | 181 ++++++++++---------------------------
 1 file changed, 48 insertions(+), 133 deletions(-)
---
diff --git a/src/miners/rss/tracker-miner-rss.c b/src/miners/rss/tracker-miner-rss.c
index e36678d08..a32fcc7da 100644
--- a/src/miners/rss/tracker-miner-rss.c
+++ b/src/miners/rss/tracker-miner-rss.c
@@ -49,8 +49,7 @@ struct _TrackerMinerRSSPrivate {
        GHashTable *channel_updates;
        GHashTable *channels;
 
-       gint rdf_type_id;
-       gint mfo_feed_channel_id;
+       TrackerNotifier *notifier;
 };
 
 typedef struct {
@@ -72,12 +71,10 @@ typedef struct {
        GHashTable *items;
 } FeedItemListInsertData;
 
-static void         graph_updated_cb                (GDBusConnection       *connection,
-                                                     const gchar           *sender_name,
-                                                     const gchar           *object_path,
-                                                     const gchar           *interface_name,
-                                                     const gchar           *signal_name,
-                                                     GVariant              *parameters,
+static void         notifier_events_cb              (TrackerNotifier       *notifier,
+                                                     const gchar           *service,
+                                                     const gchar           *graph,
+                                                     GPtrArray             *events,
                                                      gpointer               user_data);
 static void         miner_started                   (TrackerMiner          *miner);
 static void         miner_stopped                   (TrackerMiner          *miner);
@@ -167,6 +164,20 @@ parse_html_text (const gchar *html)
        return g_string_free (string, FALSE);
 }
 
+static void
+tracker_miner_rss_constructed (GObject *object)
+{
+       TrackerMinerRSSPrivate *priv;
+       TrackerSparqlConnection *connection;
+
+       priv = TRACKER_MINER_RSS_GET_PRIVATE (object);
+       connection = tracker_miner_get_connection (TRACKER_MINER (object));
+
+       priv->notifier = tracker_sparql_connection_create_notifier (connection, 0);
+       g_signal_connect (priv->notifier, "events",
+                         G_CALLBACK (notifier_events_cb), object);
+}
+
 static void
 tracker_miner_rss_finalize (GObject *object)
 {
@@ -177,9 +188,7 @@ tracker_miner_rss_finalize (GObject *object)
        priv->stopped = TRUE;
        g_free (priv->last_status);
        g_object_unref (priv->pool);
-
-       g_dbus_connection_signal_unsubscribe (priv->connection, priv->graph_updated_id);
-       g_object_unref (priv->connection);
+       g_object_unref (priv->notifier);
 
        g_hash_table_unref (priv->channel_updates);
        g_hash_table_unref (priv->channels);
@@ -187,36 +196,6 @@ tracker_miner_rss_finalize (GObject *object)
        G_OBJECT_CLASS (tracker_miner_rss_parent_class)->finalize (object);
 }
 
-static gint
-get_class_id (TrackerSparqlConnection *conn,
-              const gchar             *class)
-{
-       TrackerSparqlCursor *cursor;
-       GError *error = NULL;
-       gchar *query;
-       gint id = -1;
-
-       query = g_strdup_printf ("select tracker:id (%s) {}", class);
-       cursor = tracker_sparql_connection_query (conn, query, NULL, &error);
-       g_free (query);
-
-       if (error) {
-               g_critical ("Could not get class ID for '%s': %s\n",
-                           class, error->message);
-               g_error_free (error);
-               return -1;
-       }
-
-       if (tracker_sparql_cursor_next (cursor, NULL, NULL))
-               id = tracker_sparql_cursor_get_integer (cursor, 0);
-       else
-               g_critical ("'%s' didn't resolve to a known class ID", class);
-
-       g_object_unref (cursor);
-
-       return id;
-}
-
 static gboolean
 miner_connected (TrackerMinerOnline *miner,
                 TrackerNetworkType  network)
@@ -232,6 +211,7 @@ tracker_miner_rss_class_init (TrackerMinerRSSClass *klass)
        TrackerMinerOnlineClass *miner_online_class = TRACKER_MINER_ONLINE_CLASS (klass);
 
        object_class->finalize = tracker_miner_rss_finalize;
+       object_class->constructed = tracker_miner_rss_constructed;
 
        miner_class->started = miner_started;
        miner_class->stopped = miner_stopped;
@@ -244,24 +224,12 @@ tracker_miner_rss_class_init (TrackerMinerRSSClass *klass)
 static void
 tracker_miner_rss_init (TrackerMinerRSS *object)
 {
-       GError *error = NULL;
        TrackerMinerRSSPrivate *priv;
-       TrackerDomainOntology *domain_ontology;
-       gchar *dbus_name;
 
        g_message ("Initializing...");
 
        priv = TRACKER_MINER_RSS_GET_PRIVATE (object);
 
-       priv->connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &error);
-
-       if (!priv->connection) {
-               g_critical ("Could not connect to the D-Bus session bus, %s",
-                           error ? error->message : "no error given.");
-               g_error_free (error);
-               return;
-       }
-
        /* Key object reference is cleaned up in value destroy func */
        priv->channel_updates = g_hash_table_new_full (g_direct_hash,
                                                       g_direct_equal,
@@ -274,27 +242,6 @@ tracker_miner_rss_init (TrackerMinerRSS *object)
        g_signal_connect (priv->pool, "feed-fetching", G_CALLBACK (feed_fetching_cb), object);
        g_signal_connect (priv->pool, "feed-ready", G_CALLBACK (feed_ready_cb), object);
        priv->now_fetching = 0;
-
-       g_message ("Listening for GraphUpdated changes on D-Bus interface...");
-       g_message ("  arg0:'%s'", TRACKER_PREFIX_MFO "FeedChannel");
-
-       domain_ontology = tracker_domain_ontology_new (tracker_sparql_connection_get_domain (),
-                                                      NULL, NULL);
-       dbus_name = tracker_domain_ontology_get_domain (domain_ontology, NULL);
-
-       priv->graph_updated_id =
-               g_dbus_connection_signal_subscribe  (priv->connection,
-                                                    dbus_name,
-                                                    "org.freedesktop.Tracker1.Resources",
-                                                    "GraphUpdated",
-                                                    "/org/freedesktop/Tracker1/Resources",
-                                                    TRACKER_PREFIX_MFO "FeedChannel",
-                                                    G_DBUS_SIGNAL_FLAGS_NONE,
-                                                    graph_updated_cb,
-                                                    object,
-                                                    NULL);
-       g_free (dbus_name);
-       tracker_domain_ontology_unref (domain_ontology);
 }
 
 static void
@@ -377,70 +324,42 @@ delete_message_channels (TrackerMinerRSS *miner,
 }
 
 static void
-handle_deletes (TrackerMinerRSS *miner,
-                GVariantIter    *iter)
+notifier_events_cb (TrackerNotifier *notifier,
+                    const gchar     *service,
+                    const gchar     *graph,
+                    GPtrArray       *events,
+                    gpointer         user_data)
 {
-       GArray *deleted = g_array_new (FALSE, FALSE, sizeof (gint));
-       gint graph, subject, pred, object;
-       TrackerMinerRSSPrivate *priv;
-
-       priv = TRACKER_MINER_RSS_GET_PRIVATE (miner);
-
-       while (g_variant_iter_next (iter, "(iiii)",
-                                   &graph, &subject, &pred, &object)) {
-               if (pred == priv->rdf_type_id &&
-                   object == priv->mfo_feed_channel_id) {
-                       g_array_append_val (deleted, subject);
-               }
-       }
-
-       if (deleted->len > 0)
-               delete_message_channels (miner, deleted);
+       TrackerMinerRSS *miner = user_data;
+       GArray *inserted, *deleted;
+       gint i;
 
-       g_array_free (deleted, TRUE);
-}
+       inserted = g_array_new (FALSE, FALSE, sizeof (gint));
+       deleted = g_array_new (FALSE, FALSE, sizeof (gint));
 
-static void
-handle_updates (TrackerMinerRSS *miner,
-                GVariantIter    *iter)
-{
-       GArray *updated = g_array_new (FALSE, FALSE, sizeof (gint));
-       gint graph, subject, pred, object;
-       TrackerMinerRSSPrivate *priv;
+       for (i = 0; i < events->len; i++) {
+               TrackerNotifierEvent *event;
+               TrackerNotifierEventType event_type;
+               gint64 id;
 
-       priv = TRACKER_MINER_RSS_GET_PRIVATE (miner);
+               event = g_ptr_array_index (events, i);
+               event_type = tracker_notifier_event_get_event_type (event);
+               id = tracker_notifier_event_get_id (event);
 
-       while (g_variant_iter_next (iter, "(iiii)",
-                                   &graph, &subject, &pred, &object)) {
-               if (pred == priv->rdf_type_id &&
-                   object == priv->mfo_feed_channel_id) {
-                       g_array_append_val (updated, subject);
+               if (event_type == TRACKER_NOTIFIER_EVENT_CREATE) {
+                       g_array_append_val (inserted, id);
+               } else if (event_type == TRACKER_NOTIFIER_EVENT_DELETE) {
+                       g_array_append_val (deleted, id);
                }
        }
 
-       if (updated->len > 0)
-               retrieve_and_schedule_feeds (miner, updated);
-
-       g_array_free (updated, TRUE);
-}
+       if (deleted->len > 0)
+               delete_message_channels (miner, deleted);
+       if (inserted->len > 0)
+               retrieve_and_schedule_feeds (miner, inserted);
 
-static void
-graph_updated_cb (GDBusConnection *connection,
-                  const gchar     *sender_name,
-                  const gchar     *object_path,
-                  const gchar     *interface_name,
-                  const gchar     *signal_name,
-                  GVariant        *parameters,
-                  gpointer         user_data)
-{
-       TrackerMinerRSS *miner = TRACKER_MINER_RSS (user_data);
-       GVariantIter *deletes, *updates;
-
-       g_variant_get (parameters, "(&sa(iiii)a(iiii))", NULL, &deletes, &updates);
-       handle_deletes (miner, deletes);
-       handle_updates (miner, updates);
-       g_variant_iter_free (deletes);
-       g_variant_iter_free (updates);
+       g_array_unref (inserted);
+       g_array_unref (deleted);
 }
 
 static FeedChannelUpdateData *
@@ -1261,14 +1180,10 @@ static void
 miner_started (TrackerMiner *miner)
 {
        TrackerMinerRSSPrivate *priv;
-       TrackerSparqlConnection *conn;
 
        g_object_set (miner, "progress", 0.0, "status", "Initializing", NULL);
 
        priv = TRACKER_MINER_RSS_GET_PRIVATE (miner);
-       conn = tracker_miner_get_connection (miner);
-       priv->rdf_type_id = get_class_id (conn, "rdf:type");
-       priv->mfo_feed_channel_id = get_class_id (conn, "mfo:FeedChannel");
        retrieve_and_schedule_feeds (TRACKER_MINER_RSS (miner), NULL);
        grss_feeds_pool_switch (priv->pool, TRUE);
 }


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