[tracker/wip/carlosg/domain-ontologies: 99/116] libtracker-control: Add domain argument to tracker_miner_manager_new_full



commit 87d310ba4d34949b6570f97cf8025ec386ff5a65
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Jun 20 20:30:47 2017 +0200

    libtracker-control: Add domain argument to tracker_miner_manager_new_full
    
    I personally prefer using the excuse of the major version bump than adding
    a tracker_miner_manager_new_fuller() variant, as this is clearly a
    construct_only thing. Creating a TrackerMinerManager with an specific
    domain will allow dealing with the miners spawned for it.

 src/libtracker-control/Makefile.am             |    1 +
 src/libtracker-control/tracker-control.vapi    |    2 +-
 src/libtracker-control/tracker-miner-manager.c |   55 ++++++++++++++++++++----
 src/miners/rss/tracker-main.c                  |    1 +
 4 files changed, 49 insertions(+), 10 deletions(-)
---
diff --git a/src/libtracker-control/Makefile.am b/src/libtracker-control/Makefile.am
index 7a3b404..5fe10e5 100644
--- a/src/libtracker-control/Makefile.am
+++ b/src/libtracker-control/Makefile.am
@@ -30,6 +30,7 @@ endif
 
 libtracker_control_@TRACKER_API_VERSION@_la_LIBADD =     \
        $(top_builddir)/src/libtracker-common/libtracker-common.la \
+       $(top_builddir)/src/libtracker-sparql-backend/libtracker-sparql-@TRACKER_API_VERSION@.la \
        -lm                                              \
        $(BUILD_LIBS)                                    \
        $(LIBTRACKER_MINER_LIBS)
diff --git a/src/libtracker-control/tracker-control.vapi b/src/libtracker-control/tracker-control.vapi
index ceba04a..59de817 100644
--- a/src/libtracker-control/tracker-control.vapi
+++ b/src/libtracker-control/tracker-control.vapi
@@ -8,7 +8,7 @@ namespace Tracker {
                public MinerManager ();
                public static GLib.Quark error_quark ();
                [CCode (has_construct_function = false)]
-               public MinerManager.full (bool auto_start) throws GLib.Error;
+               public MinerManager.full (string? domain_name, bool auto_start) throws GLib.Error;
                public GLib.SList<string>? get_available ();
                public unowned string get_description (string miner);
                public unowned string get_display_name (string miner);
diff --git a/src/libtracker-control/tracker-miner-manager.c b/src/libtracker-control/tracker-miner-manager.c
index c3d712c..aaee3d0 100644
--- a/src/libtracker-control/tracker-miner-manager.c
+++ b/src/libtracker-control/tracker-miner-manager.c
@@ -25,6 +25,7 @@
 
 #include <libtracker-common/tracker-dbus.h>
 #include <libtracker-common/tracker-type-utils.h>
+#include <libtracker-common/tracker-domain-ontology.h>
 #include <libtracker-miner/tracker-miner.h>
 
 #include "tracker-miner-manager.h"
@@ -42,7 +43,7 @@
 #define TRACKER_MINER_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_MINER_MANAGER, 
TrackerMinerManagerPrivate))
 
 #define DESKTOP_ENTRY_GROUP "D-BUS Service"
-#define DBUS_NAME_KEY "Name"
+#define DBUS_NAME_SUFFIX_KEY "NameSuffix"
 #define DBUS_PATH_KEY "Path"
 #define DISPLAY_NAME_KEY "DisplayName"
 #define DESCRIPTION_KEY "Comment"
@@ -58,6 +59,7 @@ struct MinerData {
        gchar *dbus_path;
        gchar *display_name;
        gchar *description;
+       gchar *name_suffix;
 
        GDBusConnection *connection;
        guint progress_signal;
@@ -74,6 +76,8 @@ struct TrackerMinerManagerPrivate {
 
        /* Property values */
        gboolean auto_start;
+       gchar *domain_ontology_name;
+       TrackerDomainOntology *domain_ontology;
 };
 
 static void miner_manager_initable_iface_init (GInitableIface         *iface);
@@ -94,7 +98,8 @@ G_DEFINE_TYPE_WITH_CODE (TrackerMinerManager, tracker_miner_manager, G_TYPE_OBJE
 
 enum {
        PROP_0,
-       PROP_AUTO_START
+       PROP_AUTO_START,
+       PROP_DOMAIN_ONTOLOGY
 };
 
 enum {
@@ -124,6 +129,13 @@ tracker_miner_manager_class_init (TrackerMinerManagerClass *klass)
                                                              "If set, auto starts miners when querying their 
status",
                                                               TRUE,
                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (object_class,
+                                        PROP_DOMAIN_ONTOLOGY,
+                                        g_param_spec_string ("domain-ontology",
+                                                             "Domain ontology",
+                                                             "The domain ontology this object controls",
+                                                             NULL,
+                                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
        /**
         * TrackerMinerManager::miner-progress:
@@ -248,6 +260,9 @@ miner_manager_set_property (GObject      *object,
        case PROP_AUTO_START:
                priv->auto_start = g_value_get_boolean (value);
                break;
+       case PROP_DOMAIN_ONTOLOGY:
+               priv->domain_ontology_name = g_value_dup_string (value);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -270,6 +285,9 @@ miner_manager_get_property (GObject    *object,
        case PROP_AUTO_START:
                g_value_set_boolean (value, priv->auto_start);
                break;
+       case PROP_DOMAIN_ONTOLOGY:
+               g_value_set_string (value, priv->domain_ontology_name);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -414,6 +432,13 @@ miner_manager_initable_init (GInitable     *initable,
                return FALSE;
        }
 
+       priv->domain_ontology = tracker_domain_ontology_new (priv->domain_ontology_name,
+                                                            cancellable, &inner_error);
+       if (!priv->domain_ontology) {
+               g_propagate_error (error, inner_error);
+               return FALSE;
+       }
+
        initialize_miners_data (manager);
 
        for (m = priv->miners; m; m = m->next) {
@@ -533,6 +558,7 @@ miner_data_free (MinerData *data)
        g_free (data->dbus_name);
        g_free (data->display_name);
        g_free (data->description);
+       g_free (data->name_suffix);
        g_slice_free (MinerData, data);
 }
 
@@ -550,6 +576,8 @@ miner_manager_finalize (GObject *object)
        g_list_foreach (priv->miners, (GFunc) miner_data_free, NULL);
        g_list_free (priv->miners);
        g_hash_table_unref (priv->miner_proxies);
+       g_free (priv->domain_ontology_name);
+       g_object_unref (priv->domain_ontology);
 
        G_OBJECT_CLASS (tracker_miner_manager_parent_class)->finalize (object);
 }
@@ -602,10 +630,13 @@ tracker_miner_manager_new_full (gboolean   auto_start,
 {
        GError *inner_error = NULL;
        TrackerMinerManager *manager;
+       const gchar *domain_ontology;
 
+       domain_ontology = tracker_sparql_connection_get_domain ();
        manager = g_initable_new (TRACKER_TYPE_MINER_MANAGER,
                                  NULL,
                                  &inner_error,
+                                 "domain-ontology", domain_ontology,
                                  "auto-start", auto_start,
                                  NULL);
        if (inner_error)
@@ -636,6 +667,7 @@ tracker_miner_manager_get_running (TrackerMinerManager *manager)
        GVariant *v;
        GVariantIter *iter;
        const gchar *str = NULL;
+       gchar *prefix;
 
        g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), NULL);
 
@@ -664,9 +696,11 @@ tracker_miner_manager_get_running (TrackerMinerManager *manager)
                return NULL;
        }
 
+       prefix = tracker_domain_ontology_get_domain (priv->domain_ontology, "Miner");
+
        g_variant_get (v, "(as)", &iter);
        while (g_variant_iter_loop (iter, "&s", &str)) {
-               if (!g_str_has_prefix (str, TRACKER_MINER_DBUS_NAME_PREFIX)) {
+               if (!g_str_has_prefix (str, prefix)) {
                        continue;
                }
 
@@ -675,6 +709,7 @@ tracker_miner_manager_get_running (TrackerMinerManager *manager)
 
        g_variant_iter_free (iter);
        g_variant_unref (v);
+       g_free (prefix);
 
        list = g_slist_reverse (list);
 
@@ -688,7 +723,7 @@ check_file (GFile    *file,
        TrackerMinerManager *manager;
        TrackerMinerManagerPrivate *priv;
        GKeyFile *key_file;
-       gchar *path, *dbus_path, *dbus_name, *display_name, *description;
+       gchar *path, *dbus_path, *display_name, *name_suffix, *description;
        GError *error = NULL;
        MinerData *data;
 
@@ -707,15 +742,15 @@ check_file (GFile    *file,
        }
 
        dbus_path = g_key_file_get_string (key_file, DESKTOP_ENTRY_GROUP, DBUS_PATH_KEY, NULL);
-       dbus_name = g_key_file_get_string (key_file, DESKTOP_ENTRY_GROUP, DBUS_NAME_KEY, NULL);
        display_name = g_key_file_get_locale_string (key_file, DESKTOP_ENTRY_GROUP, DISPLAY_NAME_KEY, NULL, 
NULL);
+       name_suffix = g_key_file_get_string (key_file, DESKTOP_ENTRY_GROUP, DBUS_NAME_SUFFIX_KEY, NULL);
 
-       if (!dbus_path || !dbus_name || !display_name) {
-               g_warning ("Essential data (DBusPath, DBusName or Name) are missing in miner .desktop file");
+       if (!dbus_path || !display_name || !name_suffix) {
+               g_warning ("Essential data (DBusPath, NameSuffix or Name) are missing in miner .desktop 
file");
                g_key_file_free (key_file);
                g_free (dbus_path);
                g_free (display_name);
-               g_free (dbus_name);
+               g_free (name_suffix);
                return;
        }
 
@@ -723,7 +758,9 @@ check_file (GFile    *file,
 
        data = g_slice_new0 (MinerData);
        data->dbus_path = dbus_path;
-       data->dbus_name = dbus_name;        /* In .service file as Name */
+       data->name_suffix = name_suffix;
+       data->dbus_name = tracker_domain_ontology_get_domain (priv->domain_ontology,
+                                                             name_suffix);
        data->display_name = display_name;
        data->description = description;    /* In .desktop file as _comment */
 
diff --git a/src/miners/rss/tracker-main.c b/src/miners/rss/tracker-main.c
index 06d9d36..fae4967 100644
--- a/src/miners/rss/tracker-main.c
+++ b/src/miners/rss/tracker-main.c
@@ -67,6 +67,7 @@ main (int argc, char **argv)
        GOptionContext *context;
        TrackerMinerRSS *miner;
        GError *error = NULL;
+       GDBusConnection *connection;
        TrackerMinerProxy *proxy;
        TrackerDomainOntology *domain_ontology;
        gchar *dbus_name;


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