[tracker/data-provider-monitor-interface: 2/3] libtracker-miner: Moved monitor_{add|remove} to TrackerDataProvider
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/data-provider-monitor-interface: 2/3] libtracker-miner: Moved monitor_{add|remove} to TrackerDataProvider
- Date: Mon, 22 Dec 2014 17:36:22 +0000 (UTC)
commit c24aa2cfdfecaf725c82893f9e0ef676092b6f28
Author: Martyn Russell <martyn lanedo com>
Date: Mon Dec 22 16:00:36 2014 +0000
libtracker-miner: Moved monitor_{add|remove} to TrackerDataProvider
Now TrackerMonitor is a part-implementation for that interface managed in
TrackerFileDataProvider
src/libtracker-miner/tracker-crawler.c | 16 +---
src/libtracker-miner/tracker-data-provider.c | 136 +++++++++++++++++++++
src/libtracker-miner/tracker-data-provider.h | 23 +++-
src/libtracker-miner/tracker-file-data-provider.c | 38 ++++++
src/libtracker-miner/tracker-file-notifier.c | 73 ++++++-----
5 files changed, 237 insertions(+), 49 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-crawler.c b/src/libtracker-miner/tracker-crawler.c
index 4b5da1e..a0e886d 100644
--- a/src/libtracker-miner/tracker-crawler.c
+++ b/src/libtracker-miner/tracker-crawler.c
@@ -339,27 +339,13 @@ TrackerCrawler *
tracker_crawler_new (TrackerDataProvider *data_provider)
{
TrackerCrawler *crawler;
- TrackerDataProvider *default_data_provider = NULL;
- if (G_LIKELY (!data_provider)) {
- /* Default to the file data_provider if none is passed */
- data_provider = default_data_provider = tracker_file_data_provider_new ();
- }
+ g_return_val_if_fail (TRACKER_IS_DATA_PROVIDER (data_provider), NULL);
crawler = g_object_new (TRACKER_TYPE_CRAWLER,
"data-provider", data_provider,
NULL);
- /* When a data provider is passed to us, we add a reference in
- * the set_properties() function for this class, however, if
- * we create the data provider, we also have the original
- * reference for the created object which needs to be cleared
- * up here.
- */
- if (default_data_provider) {
- g_object_unref (default_data_provider);
- }
-
return crawler;
}
diff --git a/src/libtracker-miner/tracker-data-provider.c b/src/libtracker-miner/tracker-data-provider.c
index b9fe97d..58cf630 100644
--- a/src/libtracker-miner/tracker-data-provider.c
+++ b/src/libtracker-miner/tracker-data-provider.c
@@ -55,6 +55,62 @@ G_DEFINE_INTERFACE (TrackerDataProvider, tracker_data_provider, G_TYPE_OBJECT)
static void
tracker_data_provider_default_init (TrackerDataProviderInterface *iface)
{
+ g_signal_new ("item-created",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TrackerDataProviderIface, item_created),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE,
+ 2,
+ G_TYPE_OBJECT,
+ G_TYPE_BOOLEAN);
+
+ g_signal_new ("item-updated",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TrackerDataProviderIface, item_updated),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE,
+ 2,
+ G_TYPE_OBJECT,
+ G_TYPE_BOOLEAN);
+
+ g_signal_new ("item-attribute-updated",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TrackerDataProviderIface, item_attribute_updated),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE,
+ 2,
+ G_TYPE_OBJECT,
+ G_TYPE_BOOLEAN);
+
+ g_signal_new ("item-deleted",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TrackerDataProviderIface, item_deleted),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE,
+ 2,
+ G_TYPE_OBJECT,
+ G_TYPE_BOOLEAN);
+
+ g_signal_new ("item-moved",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TrackerDataProviderIface, item_moved),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE,
+ 4,
+ G_TYPE_OBJECT,
+ G_TYPE_OBJECT,
+ G_TYPE_BOOLEAN,
+ G_TYPE_BOOLEAN);
}
/**
@@ -357,3 +413,83 @@ tracker_data_provider_end_finish (TrackerDataProvider *data_provider,
return (* iface->end_finish) (data_provider, result, error);
}
+
+/**
+ * tracker_data_provider_monitor_add:
+ * @data_provider: a #TrackerDataProvider
+ * @container: a #GFile
+ * @error: location to store the error occurring, or %NULL to ignore
+ *
+ * Tells @data_provider to monitor changes on @container. This is very
+ * similar to the g_file_monitor_file() API. This is called depending
+ * on the flags passed to tracker_data_provider_begin() and
+ * tracker_data_provider_begin_async() where
+ * #TRACKER_DIRECTORY_FLAG_MONITOR can be passed.
+ *
+ * Returns: %TRUE on success, otherwise %FALSE and @error is set.
+ *
+ * Since: 1.4
+ **/
+gboolean
+tracker_data_provider_monitor_add (TrackerDataProvider *data_provider,
+ GFile *container,
+ GError **error)
+{
+ TrackerDataProviderIface *iface;
+
+ g_return_val_if_fail (TRACKER_IS_DATA_PROVIDER (data_provider), FALSE);
+ g_return_val_if_fail (G_IS_FILE (container), FALSE);
+
+ iface = TRACKER_DATA_PROVIDER_GET_IFACE (data_provider);
+
+ if (iface->monitor_add == NULL) {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ _("Operation not supported"));
+ return FALSE;
+ }
+
+ return (* iface->monitor_add) (data_provider, container, error);
+}
+
+/**
+ * tracker_data_provider_monitor_remove:
+ * @data_provider: a #TrackerDataProvider
+ * @container: a #GFile
+ * @recursively: Remove monitors on all containers below @container too
+ * @error: location to store the error occurring, or %NULL to ignore
+ *
+ * Tells @data_provider to stop monitoring changes on @container. This
+ * is very similar to the g_file_monitor_file() API. This may be called
+ * depending on the flags passed to tracker_data_provider_begin() and
+ * tracker_data_provider_begin_async() where
+ * #TRACKER_DIRECTORY_FLAG_MONITOR can be passed.
+ *
+ * Returns: %TRUE on success, otherwise %FALSE and @error is set.
+ *
+ * Since: 1.4
+ **/
+gboolean
+tracker_data_provider_monitor_remove (TrackerDataProvider *data_provider,
+ GFile *container,
+ gboolean recursively,
+ GError **error)
+{
+ TrackerDataProviderIface *iface;
+
+ g_return_val_if_fail (TRACKER_IS_DATA_PROVIDER (data_provider), FALSE);
+ g_return_val_if_fail (G_IS_FILE (container), FALSE);
+
+ iface = TRACKER_DATA_PROVIDER_GET_IFACE (data_provider);
+
+ if (iface->monitor_remove == NULL) {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ _("Operation not supported"));
+ return FALSE;
+ }
+
+ return (* iface->monitor_remove) (data_provider, container, recursively, error);
+}
diff --git a/src/libtracker-miner/tracker-data-provider.h b/src/libtracker-miner/tracker-data-provider.h
index deab933..bcd4204 100644
--- a/src/libtracker-miner/tracker-data-provider.h
+++ b/src/libtracker-miner/tracker-data-provider.h
@@ -63,6 +63,10 @@ typedef struct _TrackerDataProviderIface TrackerDataProviderIface;
* Completed using @end_finish.
* @end_finish: Called when the data_provider is completing the
* asynchronous operation provided by @end_async.
+ * @add_monitor: Called when the data_provider is asked to monitor a
+ * container for changes.
+ * @remove_monitor: Called when the data_provider is asked to stop
+ * monitoring a container for changes.
* @item_created: Signalled when an item is created in a monitored
* container. This can be another container or object itself. A
* container could be a directory and an object could be a file in
@@ -124,6 +128,15 @@ struct _TrackerDataProviderIface {
GAsyncResult *result,
GError **error);
+ /* Monitoring API - to tell data provider you're interested */
+ gboolean (* monitor_add) (TrackerDataProvider *data_provider,
+ GFile *container,
+ GError **error);
+ gboolean (* monitor_remove) (TrackerDataProvider *data_provider,
+ GFile *container,
+ gboolean recursively,
+ GError **error);
+
/* Monitoring Signals - for container/object change notification */
void (* item_created) (TrackerDataProvider *data_provider,
GFile *file,
@@ -146,8 +159,6 @@ struct _TrackerDataProviderIface {
/*< private >*/
/* Padding for future expansion */
void (*_tracker_reserved1) (void);
- void (*_tracker_reserved2) (void);
- void (*_tracker_reserved3) (void);
};
GType tracker_data_provider_get_type (void) G_GNUC_CONST;
@@ -182,6 +193,14 @@ gboolean tracker_data_provider_end_finish (TrackerDataProvider
GAsyncResult *result,
GError **error);
+gboolean tracker_data_provider_monitor_add (TrackerDataProvider *data_provider,
+ GFile *container,
+ GError **error);
+gboolean tracker_data_provider_monitor_remove (TrackerDataProvider *data_provider,
+ GFile *container,
+ gboolean recursively,
+ GError **error);
+
G_END_DECLS
#endif /* __LIBTRACKER_MINER_DATA_PROVIDER_H__ */
diff --git a/src/libtracker-miner/tracker-file-data-provider.c
b/src/libtracker-miner/tracker-file-data-provider.c
index 2b2e125..d9b2bdc 100644
--- a/src/libtracker-miner/tracker-file-data-provider.c
+++ b/src/libtracker-miner/tracker-file-data-provider.c
@@ -23,11 +23,13 @@
#include "tracker-file-enumerator.h"
#include "tracker-file-data-provider.h"
+#include "tracker-monitor.h"
static void tracker_file_data_provider_file_iface_init (TrackerDataProviderIface *iface);
struct _TrackerFileDataProvider {
GObject parent_instance;
+ TrackerMonitor *monitor;
};
typedef struct {
@@ -71,6 +73,7 @@ tracker_file_data_provider_class_init (TrackerFileDataProviderClass *klass)
static void
tracker_file_data_provider_init (TrackerFileDataProvider *fe)
{
+ fe->monitor = tracker_monitor_new ();
}
static BeginData *
@@ -279,6 +282,39 @@ file_data_provider_end_finish (TrackerDataProvider *data_provider,
return g_task_propagate_boolean (G_TASK (result), error);
}
+static gboolean
+file_data_provider_monitor_add (TrackerDataProvider *data_provider,
+ GFile *container,
+ GError **error)
+{
+ TrackerFileDataProvider *fdp;
+
+ g_return_val_if_fail (TRACKER_IS_FILE_DATA_PROVIDER (data_provider), FALSE);
+
+ fdp = TRACKER_FILE_DATA_PROVIDER (data_provider);
+
+ return tracker_monitor_add (fdp->monitor, container);
+}
+
+static gboolean
+file_data_provider_monitor_remove (TrackerDataProvider *data_provider,
+ GFile *container,
+ gboolean recursively,
+ GError **error)
+{
+ TrackerFileDataProvider *fdp;
+
+ g_return_val_if_fail (TRACKER_IS_FILE_DATA_PROVIDER (data_provider), FALSE);
+
+ fdp = TRACKER_FILE_DATA_PROVIDER (data_provider);
+
+ if (G_LIKELY (recursively)) {
+ return tracker_monitor_remove_recursively (fdp->monitor, container);
+ } else {
+ return tracker_monitor_remove (fdp->monitor, container);
+ }
+}
+
static void
tracker_file_data_provider_file_iface_init (TrackerDataProviderIface *iface)
{
@@ -288,6 +324,8 @@ tracker_file_data_provider_file_iface_init (TrackerDataProviderIface *iface)
iface->end = file_data_provider_end;
iface->end_async = file_data_provider_end_async;
iface->end_finish = file_data_provider_end_finish;
+ iface->monitor_add = file_data_provider_monitor_add;
+ iface->monitor_remove = file_data_provider_monitor_remove;
}
/**
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index 1cddc56..c91468d 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -25,6 +25,7 @@
#include <libtracker-sparql/tracker-sparql.h>
#include "tracker-file-notifier.h"
+#include "tracker-file-data-provider.h"
#include "tracker-file-system.h"
#include "tracker-crawler.h"
#include "tracker-monitor.h"
@@ -74,7 +75,6 @@ typedef struct {
GCancellable *cancellable;
TrackerCrawler *crawler;
- TrackerMonitor *monitor;
TrackerDataProvider *data_provider;
GTimer *timer;
@@ -118,7 +118,7 @@ tracker_file_notifier_set_property (GObject *object,
switch (prop_id) {
case PROP_INDEXING_TREE:
priv->indexing_tree = g_value_dup_object (value);
- tracker_monitor_set_indexing_tree (priv->monitor,
+ tracker_monitor_set_indexing_tree (priv->data_provider,
priv->indexing_tree);
break;
case PROP_DATA_PROVIDER:
@@ -252,9 +252,9 @@ crawler_check_directory_contents_cb (TrackerCrawler *crawler,
add_monitor = (parent_flags & TRACKER_DIRECTORY_FLAG_MONITOR) != 0;
if (add_monitor) {
- tracker_monitor_add (priv->monitor, canonical);
+ tracker_data_provider_monitor_add (priv->data_provider, canonical, NULL);
} else {
- tracker_monitor_remove (priv->monitor, canonical);
+ tracker_data_provider_monitor_remove (priv->data_provider, canonical, FALSE, NULL);
}
}
@@ -1139,7 +1139,7 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
if (!is_source_monitored) {
if (is_directory) {
/* Remove monitors if any */
- tracker_monitor_remove_recursively (priv->monitor, file);
+ tracker_data_provider_monitor_remove (priv->data_provider, file, TRUE, NULL);
/* If should recurse, crawl other_file, as content is "new" */
file = tracker_file_system_get_file (priv->file_system,
@@ -1177,8 +1177,10 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
/* Destination location should be indexed as if new */
/* Remove monitors if any */
if (is_directory) {
- tracker_monitor_remove_recursively (priv->monitor,
- file);
+ tracker_data_provider_monitor_remove (priv->data_provider,
+ file,
+ TRUE,
+ NULL);
}
if (should_process_other) {
@@ -1205,8 +1207,10 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
} else if (!should_process_other) {
/* Delete original location as it moves to be non indexable */
if (is_directory) {
- tracker_monitor_remove_recursively (priv->monitor,
- file);
+ tracker_data_provider_monitor_remove (priv->data_provider,
+ file,
+ TRUE,
+ NULL);
}
g_signal_emit (notifier, signals[FILE_DELETED], 0, file);
@@ -1216,8 +1220,10 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
gboolean dest_is_recursive, source_is_recursive;
TrackerDirectoryFlags source_flags;
- tracker_monitor_move (priv->monitor,
- file, other_file);
+ tracker_monitor_move (priv->data_provider,
+ file,
+ other_file,
+ NULL);
tracker_indexing_tree_get_root (priv->indexing_tree,
file, &source_flags);
@@ -1349,7 +1355,7 @@ indexing_tree_directory_removed (TrackerIndexingTree *indexing_tree,
/* Remove monitors if any */
/* FIXME: How do we handle this with 3rd party data_providers? */
- tracker_monitor_remove_recursively (priv->monitor, directory);
+ tracker_data_provider_monitor_remove (priv->data_provider, directory, TRUE, NULL);
/* Remove all files from cache */
tracker_file_system_forget_files (priv->file_system, directory,
@@ -1372,7 +1378,6 @@ tracker_file_notifier_finalize (GObject *object)
}
g_object_unref (priv->crawler);
- g_object_unref (priv->monitor);
g_object_unref (priv->file_system);
g_object_unref (priv->cancellable);
g_object_unref (priv->connection);
@@ -1409,6 +1414,29 @@ tracker_file_notifier_constructed (GObject *object)
g_signal_connect (priv->indexing_tree, "directory-removed",
G_CALLBACK (indexing_tree_directory_removed), object);
+ /* Make sure we have a data provider, either provided or fallback */
+ if (G_LIKELY (!priv->data_provider)) {
+ /* Default to the file data_provider if none is passed */
+ priv->data_provider = (TrackerDataProvider*) tracker_file_data_provider_new ();
+ }
+
+ /* Set up monitor */
+ g_signal_connect (priv->data_provider, "item-created",
+ G_CALLBACK (monitor_item_created_cb),
+ object);
+ g_signal_connect (priv->data_provider, "item-updated",
+ G_CALLBACK (monitor_item_updated_cb),
+ object);
+ g_signal_connect (priv->data_provider, "item-attribute-updated",
+ G_CALLBACK (monitor_item_attribute_updated_cb),
+ object);
+ g_signal_connect (priv->data_provider, "item-deleted",
+ G_CALLBACK (monitor_item_deleted_cb),
+ object);
+ g_signal_connect (priv->data_provider, "item-moved",
+ G_CALLBACK (monitor_item_moved_cb),
+ object);
+
/* Set up crawler */
priv->crawler = tracker_crawler_new (priv->data_provider);
tracker_crawler_set_file_attributes (priv->crawler,
@@ -1570,25 +1598,6 @@ tracker_file_notifier_init (TrackerFileNotifier *notifier)
priv->timer = g_timer_new ();
priv->stopped = TRUE;
-
- /* Set up monitor */
- priv->monitor = tracker_monitor_new ();
-
- g_signal_connect (priv->monitor, "item-created",
- G_CALLBACK (monitor_item_created_cb),
- notifier);
- g_signal_connect (priv->monitor, "item-updated",
- G_CALLBACK (monitor_item_updated_cb),
- notifier);
- g_signal_connect (priv->monitor, "item-attribute-updated",
- G_CALLBACK (monitor_item_attribute_updated_cb),
- notifier);
- g_signal_connect (priv->monitor, "item-deleted",
- G_CALLBACK (monitor_item_deleted_cb),
- notifier);
- g_signal_connect (priv->monitor, "item-moved",
- G_CALLBACK (monitor_item_moved_cb),
- notifier);
}
TrackerFileNotifier *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]