[tracker/wip/carlosg/domain-ontologies: 75/76] libtracker-miner: Add connection property to TrackerFileNotifier



commit 943dced8b70e06825d7ca2387a64306022bf0a17
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jun 29 16:26:45 2017 +0200

    libtracker-miner: Add connection property to TrackerFileNotifier
    
    So it can be specified from the miner.

 src/libtracker-miner/tracker-file-notifier.c       |   32 ++++++++++++-------
 src/libtracker-miner/tracker-file-notifier.h       |    3 +-
 src/libtracker-miner/tracker-miner-fs.c            |    3 +-
 tests/libtracker-miner/Makefile.am                 |    1 +
 .../libtracker-miner/tracker-file-notifier-test.c  |   13 +++++++-
 5 files changed, 37 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index 139f44e..495685a 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -39,7 +39,8 @@ static gboolean force_check_updated = FALSE;
 enum {
        PROP_0,
        PROP_INDEXING_TREE,
-       PROP_DATA_PROVIDER
+       PROP_DATA_PROVIDER,
+       PROP_CONNECTION
 };
 
 enum {
@@ -130,6 +131,9 @@ tracker_file_notifier_set_property (GObject      *object,
        case PROP_DATA_PROVIDER:
                priv->data_provider = g_value_dup_object (value);
                break;
+       case PROP_CONNECTION:
+               priv->connection = g_value_dup_object (value);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -153,6 +157,9 @@ tracker_file_notifier_get_property (GObject    *object,
        case PROP_DATA_PROVIDER:
                g_value_set_object (value, priv->data_provider);
                break;
+       case PROP_CONNECTION:
+               g_value_set_object (value, priv->connection);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -1775,6 +1782,14 @@ tracker_file_notifier_class_init (TrackerFileNotifierClass *klass)
                                                              TRACKER_TYPE_DATA_PROVIDER,
                                                              G_PARAM_READWRITE |
                                                              G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (object_class,
+                                        PROP_CONNECTION,
+                                        g_param_spec_object ("connection",
+                                                             "Connection",
+                                                             "Connection to use for queries",
+                                                             TRACKER_SPARQL_TYPE_CONNECTION,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY));
 
        g_type_class_add_private (object_class,
                                  sizeof (TrackerFileNotifierClass));
@@ -1798,21 +1813,12 @@ static void
 tracker_file_notifier_init (TrackerFileNotifier *notifier)
 {
        TrackerFileNotifierPrivate *priv;
-       GError *error = NULL;
 
        priv = notifier->priv =
                G_TYPE_INSTANCE_GET_PRIVATE (notifier,
                                             TRACKER_TYPE_FILE_NOTIFIER,
                                             TrackerFileNotifierPrivate);
 
-       priv->connection = tracker_sparql_connection_get (NULL, &error);
-
-       if (error) {
-               g_warning ("Could not get SPARQL connection: %s\n",
-                          error->message);
-               g_error_free (error);
-       }
-
        priv->timer = g_timer_new ();
        priv->stopped = TRUE;
 
@@ -1837,14 +1843,16 @@ tracker_file_notifier_init (TrackerFileNotifier *notifier)
 }
 
 TrackerFileNotifier *
-tracker_file_notifier_new (TrackerIndexingTree  *indexing_tree,
-                           TrackerDataProvider  *data_provider)
+tracker_file_notifier_new (TrackerIndexingTree     *indexing_tree,
+                           TrackerDataProvider     *data_provider,
+                           TrackerSparqlConnection *connection)
 {
        g_return_val_if_fail (TRACKER_IS_INDEXING_TREE (indexing_tree), NULL);
 
        return g_object_new (TRACKER_TYPE_FILE_NOTIFIER,
                             "indexing-tree", indexing_tree,
                             "data-provider", data_provider,
+                            "connection", connection,
                             NULL);
 }
 
diff --git a/src/libtracker-miner/tracker-file-notifier.h b/src/libtracker-miner/tracker-file-notifier.h
index e8ef3a6..f267f5f 100644
--- a/src/libtracker-miner/tracker-file-notifier.h
+++ b/src/libtracker-miner/tracker-file-notifier.h
@@ -80,7 +80,8 @@ GType         tracker_file_notifier_get_type     (void) G_GNUC_CONST;
 
 TrackerFileNotifier *
               tracker_file_notifier_new          (TrackerIndexingTree     *indexing_tree,
-                                                  TrackerDataProvider     *data_provider);
+                                                  TrackerDataProvider     *data_provider,
+                                                  TrackerSparqlConnection *connection);
 
 gboolean      tracker_file_notifier_start        (TrackerFileNotifier     *notifier);
 void          tracker_file_notifier_stop         (TrackerFileNotifier     *notifier);
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index c917249..2944090 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -708,7 +708,8 @@ miner_fs_initable_init (GInitable     *initable,
 
        /* Create the file notifier */
        priv->file_notifier = tracker_file_notifier_new (priv->indexing_tree,
-                                                        priv->data_provider);
+                                                        priv->data_provider,
+                                                        tracker_miner_get_connection (TRACKER_MINER 
(initable)));
 
        if (!priv->file_notifier) {
                g_set_error (error,
diff --git a/tests/libtracker-miner/Makefile.am b/tests/libtracker-miner/Makefile.am
index b8447fb..062d261 100644
--- a/tests/libtracker-miner/Makefile.am
+++ b/tests/libtracker-miner/Makefile.am
@@ -31,6 +31,7 @@ AM_CPPFLAGS = \
        -DLIBEXEC_PATH=\""$(libexecdir)"\" \
        -DTEST_DATA_DIR=\""$(abs_top_srcdir)/tests/libtracker-miner/data"\" \
        -DTEST_MINERS_DIR=\""$(abs_top_srcdir)/tests/libtracker-miner/mock-miners"\" \
+       -DTEST_ONTOLOGIES_DIR=\""$(abs_top_srcdir)/src/ontologies/nepomuk"\" \
        -I$(top_srcdir)/src \
        -I$(top_builddir)/src \
        -I$(top_srcdir)/tests/common \
diff --git a/tests/libtracker-miner/tracker-file-notifier-test.c 
b/tests/libtracker-miner/tracker-file-notifier-test.c
index 20825f5..17ae3d8 100644
--- a/tests/libtracker-miner/tracker-file-notifier-test.c
+++ b/tests/libtracker-miner/tracker-file-notifier-test.c
@@ -43,6 +43,7 @@ typedef struct {
        GFile *test_file;
        gchar *test_path;
 
+       TrackerSparqlConnection *connection;
        TrackerIndexingTree *indexing_tree;
        GMainLoop *main_loop;
 
@@ -261,12 +262,20 @@ static void
 test_common_context_setup (TestCommonContext *fixture,
                            gconstpointer      data)
 {
+       GFile *data_loc, *ontology;
+       GError *error = NULL;
+
        fixture->test_path = g_build_filename (g_get_tmp_dir (),
                                               "tracker-test-XXXXXX",
                                               NULL);
        fixture->test_path = g_mkdtemp (fixture->test_path);
        fixture->test_file = g_file_new_for_path (fixture->test_path);
 
+       data_loc = g_file_get_child (fixture->test_file, ".data");
+       ontology = g_file_new_for_path (TEST_ONTOLOGIES_DIR);
+       fixture->connection = tracker_sparql_connection_local_new (0, data_loc, data_loc, ontology, NULL, 
&error);
+       g_assert_no_error (error);
+
        fixture->ops = NULL;
 
        /* Create basic folders within the test location */
@@ -278,7 +287,8 @@ test_common_context_setup (TestCommonContext *fixture,
        tracker_indexing_tree_set_filter_hidden (fixture->indexing_tree, TRUE);
 
        fixture->main_loop = g_main_loop_new (NULL, FALSE);
-       fixture->notifier = tracker_file_notifier_new (fixture->indexing_tree, FALSE);
+       fixture->notifier = tracker_file_notifier_new (fixture->indexing_tree, FALSE,
+                                                      fixture->connection);
 
        g_signal_connect (fixture->notifier, "file-created",
                          G_CALLBACK (file_notifier_file_created_cb), fixture);
@@ -317,6 +327,7 @@ test_common_context_teardown (TestCommonContext *fixture,
                g_free (fixture->test_path);
        }
 
+       g_clear_object (&fixture->connection);
 }
 
 static gboolean


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