[tracker/external-crawler: 4/42] libtracker-miner: Allow FileNotifier to have external crawlers



commit 74b524e6c2221be4a3178d9b1ed78f10e4249a45
Author: Martyn Russell <martyn lanedo com>
Date:   Thu May 1 17:26:13 2014 +0100

    libtracker-miner: Allow FileNotifier to have external crawlers

 src/libtracker-miner/tracker-file-notifier.c       |   89 ++++++++++++++++++--
 src/libtracker-miner/tracker-file-notifier.h       |    7 ++-
 .../libtracker-miner/tracker-file-notifier-test.c  |    2 +-
 3 files changed, 90 insertions(+), 8 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index fb4afbd..17b3bf4 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -37,7 +37,8 @@ static GQuark quark_property_filesystem_mtime = 0;
 
 enum {
        PROP_0,
-       PROP_INDEXING_TREE
+       PROP_INDEXING_TREE,
+       PROP_EXTERNAL_CRAWLER
 };
 
 enum {
@@ -75,6 +76,8 @@ typedef struct {
        TrackerCrawler *crawler;
        TrackerMonitor *monitor;
 
+       gboolean external_crawler;
+
        GTimer *timer;
 
        /* List of pending directory
@@ -114,6 +117,9 @@ tracker_file_notifier_set_property (GObject      *object,
                tracker_monitor_set_indexing_tree (priv->monitor,
                                                   priv->indexing_tree);
                break;
+       case PROP_EXTERNAL_CRAWLER:
+               priv->external_crawler = g_value_get_boolean (value);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -134,6 +140,9 @@ tracker_file_notifier_get_property (GObject    *object,
        case PROP_INDEXING_TREE:
                g_value_set_object (value, priv->indexing_tree);
                break;
+       case PROP_EXTERNAL_CRAWLER:
+               g_value_set_boolean (value, priv->external_crawler);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -379,7 +388,13 @@ file_notifier_add_node_foreach (GNode    *node,
                data->cur_parent = NULL;
        }
 
-       file_info = tracker_crawler_get_file_info (priv->crawler, file);
+       if (priv->external_crawler) {
+               file_info = NULL;
+
+               /* FIXME: get time and set property ... */
+       } else {
+               file_info = tracker_crawler_get_file_info (priv->crawler, file);
+       }
 
        if (file_info) {
                GFileType file_type;
@@ -439,6 +454,8 @@ crawler_directory_crawled_cb (TrackerCrawler *crawler,
        notifier = data.notifier = user_data;
        priv = notifier->priv;
 
+       /* FIXME: Add a call into this periodically when we have external crawlers */
+
        g_node_traverse (tree,
                         G_PRE_ORDER,
                         G_TRAVERSE_ALL,
@@ -557,6 +574,9 @@ crawl_directory_in_current_root (TrackerFileNotifier *notifier)
        gboolean recurse, retval = FALSE;
        GFile *directory;
 
+       if (priv->external_crawler)
+               return TRUE;
+
        if (!priv->current_index_root)
                return FALSE;
 
@@ -836,6 +856,7 @@ crawler_finished_cb (TrackerCrawler *crawler,
 
        directory = g_queue_peek_head (priv->current_index_root->pending_dirs);
 
+       /* FIXME: Do we need some logic here for external crawlers ? */
        if (priv->current_index_root->query_files->len > 0 &&
            (directory == priv->current_index_root->root ||
             tracker_file_system_get_property (priv->file_system,
@@ -1285,7 +1306,10 @@ indexing_tree_directory_removed (TrackerIndexingTree *indexing_tree,
        if (priv->current_index_root &&
            directory == priv->current_index_root->root) {
                /* Directory being currently processed */
-               tracker_crawler_stop (priv->crawler);
+               if (!priv->external_crawler) {
+                       tracker_crawler_stop (priv->crawler);
+               }
+
                g_cancellable_cancel (priv->cancellable);
 
                root_data_free (priv->current_index_root);
@@ -1295,7 +1319,9 @@ indexing_tree_directory_removed (TrackerIndexingTree *indexing_tree,
        }
 
        /* Remove monitors if any */
-       tracker_monitor_remove_recursively (priv->monitor, directory);
+       if (!priv->external_crawler) {
+               tracker_monitor_remove_recursively (priv->monitor, directory);
+       }
 
        /* Remove all files from cache */
        tracker_file_system_forget_files (priv->file_system, directory,
@@ -1434,6 +1460,15 @@ tracker_file_notifier_class_init (TrackerFileNotifierClass *klass)
                                                              TRACKER_TYPE_INDEXING_TREE,
                                                              G_PARAM_READWRITE |
                                                              G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (object_class,
+                                        PROP_EXTERNAL_CRAWLER,
+                                        g_param_spec_boolean ("external-crawler",
+                                                              "External crawler",
+                                                              "Set to TRUE when we don't use the 
TrackerCrawler but feed files by the API",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE |
+                                                              G_PARAM_CONSTRUCT_ONLY));
+
        g_type_class_add_private (object_class,
                                  sizeof (TrackerFileNotifierClass));
 
@@ -1521,12 +1556,14 @@ tracker_file_notifier_init (TrackerFileNotifier *notifier)
 }
 
 TrackerFileNotifier *
-tracker_file_notifier_new (TrackerIndexingTree *indexing_tree)
+tracker_file_notifier_new (TrackerIndexingTree *indexing_tree,
+                           gboolean             external_crawler)
 {
        g_return_val_if_fail (TRACKER_IS_INDEXING_TREE (indexing_tree), NULL);
 
        return g_object_new (TRACKER_TYPE_FILE_NOTIFIER,
                             "indexing-tree", indexing_tree,
+                            "external-crawler", external_crawler,
                             NULL);
 }
 
@@ -1562,7 +1599,10 @@ tracker_file_notifier_stop (TrackerFileNotifier *notifier)
        priv = notifier->priv;
 
        if (!priv->stopped) {
-               tracker_crawler_stop (priv->crawler);
+               if (!priv->external_crawler) {
+                       tracker_crawler_stop (priv->crawler);
+               }
+
                g_cancellable_cancel (priv->cancellable);
                priv->stopped = TRUE;
        }
@@ -1626,3 +1666,40 @@ tracker_file_notifier_get_file_iri (TrackerFileNotifier *notifier,
 
        return iri;
 }
+
+gboolean
+tracker_file_notifier_add_file (TrackerFileNotifier *notifier,
+                                GFile               *file)
+{
+       g_return_val_if_fail (TRACKER_IS_FILE_NOTIFIER (notifier), FALSE);
+       g_return_val_if_fail (G_IS_FILE (file), FALSE);
+
+       /* Hack, we use the created signal here from the
+        * TrackerMonitor, this way, the file is indoctrinated into
+        * the system nicely.
+        */
+       /* FIXME: Get IS DIRECTORY for boolean here */
+       monitor_item_created_cb (NULL, file, FALSE, notifier);
+
+       return TRUE;
+}
+
+gboolean
+tracker_file_notifier_add_files (TrackerFileNotifier *notifier,
+                                 GList               *files)
+{
+       GList *l;
+       gboolean success = TRUE;
+
+       g_return_val_if_fail (TRACKER_IS_FILE_NOTIFIER (notifier), FALSE);
+       g_return_val_if_fail (files != NULL, FALSE);
+       g_return_val_if_fail (g_list_length (files) > 0, FALSE);
+
+       for (l = files; l; l = l->next) {
+               GFile *file = l->data;
+
+               success &= tracker_file_notifier_add_file (notifier, file);
+       }
+
+       return success;
+}
diff --git a/src/libtracker-miner/tracker-file-notifier.h b/src/libtracker-miner/tracker-file-notifier.h
index a55ad8f..1e08319 100644
--- a/src/libtracker-miner/tracker-file-notifier.h
+++ b/src/libtracker-miner/tracker-file-notifier.h
@@ -75,7 +75,8 @@ struct _TrackerFileNotifierClass {
 
 GType         tracker_file_notifier_get_type      (void) G_GNUC_CONST;
 
-TrackerFileNotifier* tracker_file_notifier_new  (TrackerIndexingTree *indexing_tree);
+TrackerFileNotifier* tracker_file_notifier_new  (TrackerIndexingTree *indexing_tree,
+                                                 gboolean             external_crawler);
 
 gboolean      tracker_file_notifier_start (TrackerFileNotifier *notifier);
 void          tracker_file_notifier_stop  (TrackerFileNotifier *notifier);
@@ -84,6 +85,10 @@ gboolean      tracker_file_notifier_is_active (TrackerFileNotifier *notifier);
 const gchar * tracker_file_notifier_get_file_iri (TrackerFileNotifier *notifier,
                                                   GFile               *file,
                                                   gboolean             force);
+gboolean      tracker_file_notifier_add_file (TrackerFileNotifier *notifier,
+                                              GFile               *file);
+gboolean      tracker_file_notifier_add_files (TrackerFileNotifier *notifier,
+                                               GList               *files);
 
 G_END_DECLS
 
diff --git a/tests/libtracker-miner/tracker-file-notifier-test.c 
b/tests/libtracker-miner/tracker-file-notifier-test.c
index ea10a3c..9e48090 100644
--- a/tests/libtracker-miner/tracker-file-notifier-test.c
+++ b/tests/libtracker-miner/tracker-file-notifier-test.c
@@ -278,7 +278,7 @@ 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);
+       fixture->notifier = tracker_file_notifier_new (fixture->indexing_tree, FALSE);
 
        g_signal_connect (fixture->notifier, "file-created",
                          G_CALLBACK (file_notifier_file_created_cb), fixture);


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