[tracker/wip/carlosg/notifier-service-queries: 9/12] libtracker-sparql: Add object_path arg to DBus subscription notifier API



commit 6b69c2f1fb596856b6d99d1544cf36d818606ae5
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Jun 21 15:02:05 2020 +0200

    libtracker-sparql: Add object_path arg to DBus subscription notifier API
    
    This API complements the tracker_sparql_connection_bus_new() API allowing
    to provide an object path. If one side allows this, the other should too.

 src/libtracker-bus/tracker-bus.vala                |  2 +-
 .../libtracker-sparql-intermediate-c.vapi          |  2 +-
 src/libtracker-sparql/tracker-notifier.c           | 29 +++++++++++++++++++---
 src/libtracker-sparql/tracker-notifier.h           |  1 +
 4 files changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index da4d008e6..72069873f 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -281,7 +281,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
                                                              "connection", this,
                                                              null);
 
-               notifier.signal_subscribe (this.bus, this.dbus_name, null);
+               notifier.signal_subscribe (this.bus, this.dbus_name, null, null);
 
                return notifier;
        }
diff --git a/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi 
b/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
index d3bdbae4e..e4a0a9aae 100644
--- a/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
+++ b/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
@@ -215,7 +215,7 @@ namespace Tracker {
                        public string get_location ();
                }
 
-               public uint signal_subscribe (GLib.DBusConnection dbus_conn, string dbus_name, string? graph);
+               public uint signal_subscribe (GLib.DBusConnection dbus_conn, string dbus_name, string? 
object_path, string? graph);
                public void signal_unsubscribe (uint handler_id);
        }
 
diff --git a/src/libtracker-sparql/tracker-notifier.c b/src/libtracker-sparql/tracker-notifier.c
index 5d83720cd..7601e1aea 100644
--- a/src/libtracker-sparql/tracker-notifier.c
+++ b/src/libtracker-sparql/tracker-notifier.c
@@ -80,6 +80,7 @@ struct _TrackerNotifierSubscription {
        GDBusConnection *connection;
        TrackerNotifier *notifier;
        gchar *service;
+       gchar *object_path;
        guint handler_id;
 };
 
@@ -116,13 +117,16 @@ enum {
 
 static guint signals[N_SIGNALS] = { 0 };
 
+#define DEFAULT_OBJECT_PATH "/org/freedesktop/Tracker3/Endpoint"
+
 G_DEFINE_TYPE_WITH_CODE (TrackerNotifier, tracker_notifier, G_TYPE_OBJECT,
                          G_ADD_PRIVATE (TrackerNotifier))
 
 static TrackerNotifierSubscription *
 tracker_notifier_subscription_new (TrackerNotifier *notifier,
                                    GDBusConnection *connection,
-                                   const gchar     *service)
+                                   const gchar     *service,
+                                   const gchar     *object_path)
 {
        TrackerNotifierSubscription *subscription;
 
@@ -130,6 +134,7 @@ tracker_notifier_subscription_new (TrackerNotifier *notifier,
        subscription->connection = g_object_ref (connection);
        subscription->notifier = notifier;
        subscription->service = g_strdup (service);
+       subscription->object_path = g_strdup (object_path);
 
        return subscription;
 }
@@ -141,6 +146,7 @@ tracker_notifier_subscription_free (TrackerNotifierSubscription *subscription)
                                              subscription->handler_id);
        g_object_unref (subscription->connection);
        g_free (subscription->service);
+       g_free (subscription->object_path);
        g_free (subscription);
 }
 
@@ -293,6 +299,16 @@ tracker_notifier_event_cache_take_events (TrackerNotifierEventCache *cache)
        return events;
 }
 
+static gchar *
+compose_uri (const gchar *service,
+             const gchar *object_path)
+{
+       if (object_path && g_strcmp0 (object_path, DEFAULT_OBJECT_PATH) != 0)
+               return g_strdup_printf ("dbus:%s:%s", service, object_path);
+       else
+               return g_strdup_printf ("dbus:%s", service);
+}
+
 static gboolean
 tracker_notifier_emit_events (TrackerNotifierEventCache *cache)
 {
@@ -462,7 +478,7 @@ graph_updated_cb (GDBusConnection *connection,
 
        g_variant_get (parameters, "(sa{ii})", &graph, &events);
 
-       service = g_strdup_printf ("dbus:%s", subscription->service);
+       service = compose_uri (subscription->service, subscription->object_path);
        cache = _tracker_notifier_event_cache_new (notifier, service, graph);
        g_free (service);
 
@@ -589,6 +605,7 @@ guint
 tracker_notifier_signal_subscribe (TrackerNotifier *notifier,
                                    GDBusConnection *connection,
                                    const gchar     *service,
+                                   const gchar     *object_path,
                                    const gchar     *graph)
 {
        TrackerNotifierSubscription *subscription;
@@ -600,13 +617,17 @@ tracker_notifier_signal_subscribe (TrackerNotifier *notifier,
 
        priv = tracker_notifier_get_instance_private (notifier);
 
-       subscription = tracker_notifier_subscription_new (notifier, connection, service);
+       subscription = tracker_notifier_subscription_new (notifier, connection,
+                                                         service, object_path);
+       if (!object_path)
+               object_path = DEFAULT_OBJECT_PATH;
+
        subscription->handler_id =
                g_dbus_connection_signal_subscribe (connection,
                                                    service,
                                                    "org.freedesktop.Tracker3.Endpoint",
                                                    "GraphUpdated",
-                                                   "/org/freedesktop/Tracker3/Endpoint",
+                                                   object_path,
                                                    graph,
                                                    G_DBUS_SIGNAL_FLAGS_NONE,
                                                    graph_updated_cb,
diff --git a/src/libtracker-sparql/tracker-notifier.h b/src/libtracker-sparql/tracker-notifier.h
index e1d49c0ba..32de938cd 100644
--- a/src/libtracker-sparql/tracker-notifier.h
+++ b/src/libtracker-sparql/tracker-notifier.h
@@ -53,6 +53,7 @@ TRACKER_AVAILABLE_IN_ALL
 guint tracker_notifier_signal_subscribe   (TrackerNotifier *notifier,
                                            GDBusConnection *connection,
                                            const gchar     *service,
+                                           const gchar     *object_path,
                                            const gchar     *graph);
 TRACKER_AVAILABLE_IN_ALL
 void  tracker_notifier_signal_unsubscribe (TrackerNotifier *notifier,


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