[tracker/data-provider-monitor-interface: 8/10] libtracker-miner: Add remaining monitor APIs to DataProvider interface
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/data-provider-monitor-interface: 8/10] libtracker-miner: Add remaining monitor APIs to DataProvider interface
- Date: Wed, 14 Jan 2015 17:04:57 +0000 (UTC)
commit e76506689768c01ce5dc71794ab699bbad614e3a
Author: Martyn Russell <martyn lanedo com>
Date: Wed Jan 14 14:12:33 2015 +0000
libtracker-miner: Add remaining monitor APIs to DataProvider interface
These are needed for many of the unit tests.
src/libtracker-miner/tracker-data-provider.c | 143 ++++++++++++++++++++
src/libtracker-miner/tracker-data-provider.h | 44 ++++++-
src/libtracker-miner/tracker-file-notifier.c | 9 +-
.../libtracker-miner/tracker-file-notifier-test.c | 12 ++-
4 files changed, 201 insertions(+), 7 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-data-provider.c b/src/libtracker-miner/tracker-data-provider.c
index 8f7fa90..ce36823 100644
--- a/src/libtracker-miner/tracker-data-provider.c
+++ b/src/libtracker-miner/tracker-data-provider.c
@@ -495,6 +495,149 @@ tracker_data_provider_monitor_remove (TrackerDataProvider *data_provider,
}
/**
+ * tracker_data_provider_monitor_move:
+ * @data_provider: a #TrackerDataProvider
+ * @container_from: a #GFile
+ * @container_to: a #GFile
+ * @error: location to store the error occurring, or %NULL to ignore
+ *
+ * Tells @data_provider to move @container_from to @container_to.
+ * Typically used for file systems where a folder or directory is
+ * moved.
+ *
+ * Returns: %TRUE on success, otherwise %FALSE and @error is set.
+ *
+ * Since: 1.4
+ **/
+gboolean
+tracker_data_provider_monitor_move (TrackerDataProvider *data_provider,
+ GFile *container_from,
+ GFile *container_to,
+ 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_from), FALSE);
+ g_return_val_if_fail (G_IS_FILE (container_to), FALSE);
+
+ iface = TRACKER_DATA_PROVIDER_GET_IFACE (data_provider);
+
+ if (iface->monitor_move == NULL) {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ _("Operation not supported"));
+ return FALSE;
+ }
+
+ return (* iface->monitor_move) (data_provider, container_from, container_to, error);
+}
+
+/**
+ * tracker_data_provider_is_monitored:
+ * @data_provider: a #TrackerDataProvider
+ * @container: a #GFile
+ * @error: location to store the error occurring, or %NULL to ignore
+ *
+ * Asks if @data_provider is monitoring changes to @container.
+ *
+ * Returns: %TRUE on success, otherwise %FALSE and @error is set.
+ *
+ * Since: 1.4
+ **/
+gboolean
+tracker_data_provider_is_monitored (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->is_monitored == NULL) {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ _("Operation not supported"));
+ return FALSE;
+ }
+
+ return (* iface->is_monitored) (data_provider, container, error);
+}
+
+/**
+ * tracker_data_provider_is_monitored_by_path:
+ * @data_provider: a #TrackerDataProvider
+ * @container: a string
+ * @error: location to store the error occurring, or %NULL to ignore
+ *
+ * The same as tracker_data_provider_is_monitored() but takes a string
+ * to represent the path instead.
+ *
+ * Returns: %TRUE on success, otherwise %FALSE and @error is set.
+ *
+ * Since: 1.4
+ **/
+gboolean
+tracker_data_provider_is_monitored_by_path (TrackerDataProvider *data_provider,
+ const gchar *container,
+ GError **error)
+{
+ TrackerDataProviderIface *iface;
+
+ g_return_val_if_fail (TRACKER_IS_DATA_PROVIDER (data_provider), FALSE);
+ g_return_val_if_fail (container != NULL, FALSE);
+
+ iface = TRACKER_DATA_PROVIDER_GET_IFACE (data_provider);
+
+ if (iface->is_monitored_by_path == NULL) {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ _("Operation not supported"));
+ return FALSE;
+ }
+
+ return (* iface->is_monitored_by_path) (data_provider, container, error);
+}
+
+/**
+ * tracker_data_provider_monitor_count:
+ * @data_provider: a #TrackerDataProvider
+ * @error: location to store the error occurring, or %NULL to ignore
+ *
+ * Asks the @data_provider how many containers are being monitored.
+ *
+ * Returns: A value of 0 or higher on success, otherwise @error is set.
+ *
+ * Since: 1.4
+ **/
+guint
+tracker_data_provider_monitor_count (TrackerDataProvider *data_provider,
+ GError **error)
+{
+ TrackerDataProviderIface *iface;
+
+ g_return_val_if_fail (TRACKER_IS_DATA_PROVIDER (data_provider), 0);
+
+ iface = TRACKER_DATA_PROVIDER_GET_IFACE (data_provider);
+
+ if (iface->monitor_count == NULL) {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ _("Operation not supported"));
+ return FALSE;
+ }
+
+ return (* iface->monitor_count) (data_provider, error);
+}
+
+/**
* tracker_data_provider_set_indexing_tree:
* @data_provider: a #TrackerDataProvider
* @indexing_tree: a #TrackerIndexingTree
diff --git a/src/libtracker-miner/tracker-data-provider.h b/src/libtracker-miner/tracker-data-provider.h
index d2fbd1f..c360089 100644
--- a/src/libtracker-miner/tracker-data-provider.h
+++ b/src/libtracker-miner/tracker-data-provider.h
@@ -64,10 +64,19 @@ 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
+ * @monitor_add: Called when the data_provider is asked to monitor a
* container for changes.
- * @remove_monitor: Called when the data_provider is asked to stop
+ * @monitor_remove: Called when the data_provider is asked to stop
* monitoring a container for changes.
+ * @monitor_move: Called when the data_provider is asked to move a
+ * monitor from one place to another. This can happen on a file system
+ * when a directory is moved for example.
+ * @is_monitored: Called to find out if data_provider is monitoring
+ * changes for container.
+ * @is_monitored_by_path: The same as @is_monitored, only using a path
+ * string instead of a #GFile.
+ * @monitor_count: Called to find out number of containers monitored
+ * by the data_provider.
* @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
@@ -137,6 +146,20 @@ struct _TrackerDataProviderIface {
GFile *container,
gboolean recursively,
GError **error);
+ gboolean (* monitor_move) (TrackerDataProvider *data_provider,
+ GFile *container_from,
+ GFile *container_to,
+ GError **error);
+ gboolean (* is_monitored) (TrackerDataProvider *data_provider,
+ GFile *container,
+ GError **error);
+
+ gboolean (* is_monitored_by_path)
+ (TrackerDataProvider *data_provider,
+ const gchar *container,
+ GError **error);
+ guint (* monitor_count) (TrackerDataProvider *data_provider,
+ GError **error);
/* Monitoring Signals - for container/object change notification */
void (* item_created) (TrackerDataProvider *data_provider,
@@ -170,6 +193,7 @@ struct _TrackerDataProviderIface {
GType tracker_data_provider_get_type (void) G_GNUC_CONST;
+/* Crawler API */
TrackerEnumerator *tracker_data_provider_begin (TrackerDataProvider *data_provider,
GFile *url,
const gchar *attributes,
@@ -201,6 +225,7 @@ gboolean tracker_data_provider_end_finish (TrackerDataProvider
GAsyncResult *result,
GError **error);
+/* Monitor API */
gboolean tracker_data_provider_monitor_add (TrackerDataProvider *data_provider,
GFile *container,
GError **error);
@@ -208,7 +233,22 @@ gboolean tracker_data_provider_monitor_remove (TrackerDataProvider *
GFile *container,
gboolean recursively,
GError **error);
+gboolean tracker_data_provider_monitor_move (TrackerDataProvider *data_provider,
+ GFile *container_from,
+ GFile *container_to,
+ GError **error);
+gboolean tracker_data_provider_is_monitored (TrackerDataProvider *data_provider,
+ GFile *container,
+ GError **error);
+
+gboolean tracker_data_provider_is_monitored_by_path
+ (TrackerDataProvider *data_provider,
+ const gchar *container,
+ GError **error);
+guint tracker_data_provider_monitor_count (TrackerDataProvider *data_provider,
+ GError **error);
+/* Indexing Tree API */
gboolean tracker_data_provider_set_indexing_tree
(TrackerDataProvider *data_provider,
TrackerIndexingTree *indexing_tree,
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index 10cfba4..3a040a0 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -1233,10 +1233,11 @@ monitor_item_moved_cb (TrackerDataProvider *data_provider,
gboolean dest_is_recursive, source_is_recursive;
TrackerDirectoryFlags source_flags;
- tracker_monitor_move (priv->data_provider,
- file,
- other_file,
- NULL);
+ /* FIXME: Check ERROR value here */
+ tracker_data_provider_monitor_move (priv->data_provider,
+ file,
+ other_file,
+ NULL);
tracker_indexing_tree_get_root (indexing_tree, file, &source_flags);
source_is_recursive = (source_flags & TRACKER_DIRECTORY_FLAG_RECURSE) != 0;
diff --git a/tests/libtracker-miner/tracker-file-notifier-test.c
b/tests/libtracker-miner/tracker-file-notifier-test.c
index 20825f5..5a99f59 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;
+ TrackerDataProvider *data_provider;
TrackerIndexingTree *indexing_tree;
GMainLoop *main_loop;
@@ -261,6 +262,8 @@ static void
test_common_context_setup (TestCommonContext *fixture,
gconstpointer data)
{
+ GError *error = NULL;
+
fixture->test_path = g_build_filename (g_get_tmp_dir (),
"tracker-test-XXXXXX",
NULL);
@@ -277,8 +280,15 @@ test_common_context_setup (TestCommonContext *fixture,
fixture->indexing_tree = tracker_indexing_tree_new ();
tracker_indexing_tree_set_filter_hidden (fixture->indexing_tree, TRUE);
+ fixture->data_provider = tracker_file_data_provider_new ();
+ tracker_data_provider_set_indexing_tree (fixture->data_provider,
+ fixture->indexing_tree,
+ &error);
+
+ g_assert_no_error (error);
+
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->data_provider);
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]