[tracker/writeback-refactor-rebase] miners/fs: Make it possible to enable/disable Writeback
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/writeback-refactor-rebase] miners/fs: Make it possible to enable/disable Writeback
- Date: Fri, 15 Jul 2011 10:16:55 +0000 (UTC)
commit 55872c8c22fae3962d4befc2efa12c0282f18232
Author: Philip Van Hoof <philip codeminded be>
Date: Fri Jul 15 12:03:58 2011 +0200
miners/fs: Make it possible to enable/disable Writeback
src/miners/fs/tracker-config.c | 78 +++++++++++++++++++++++++++++--------
src/miners/fs/tracker-config.h | 3 +
src/miners/fs/tracker-main.c | 4 +-
src/miners/fs/tracker-writeback.c | 67 ++++++++++++++++++++++++++++++-
src/miners/fs/tracker-writeback.h | 1 +
5 files changed, 132 insertions(+), 21 deletions(-)
---
diff --git a/src/miners/fs/tracker-config.c b/src/miners/fs/tracker-config.c
index b2b1c8d..24b098b 100644
--- a/src/miners/fs/tracker-config.c
+++ b/src/miners/fs/tracker-config.c
@@ -44,6 +44,7 @@
#define DEFAULT_LOW_DISK_SPACE_LIMIT 1 /* 0->100 / -1 */
#define DEFAULT_CRAWLING_INTERVAL -1 /* 0->365 / -1 / -2 */
#define DEFAULT_REMOVABLE_DAYS_THRESHOLD 3 /* 1->365 / 0 */
+#define DEFAULT_ENABLE_WRITEBACK TRUE
typedef struct {
GSList *index_recursive_directories;
@@ -95,26 +96,31 @@ enum {
PROP_IGNORED_DIRECTORIES_WITH_CONTENT,
PROP_IGNORED_FILES,
PROP_CRAWLING_INTERVAL,
- PROP_REMOVABLE_DAYS_THRESHOLD
+ PROP_REMOVABLE_DAYS_THRESHOLD,
+
+ /* Monit */
+ PROP_ENABLE_WRITEBACK
+
};
static TrackerConfigMigrationEntry migration[] = {
- { G_TYPE_ENUM, "General", "Verbosity", "verbosity" },
- { G_TYPE_INT, "General", "InitialSleep", "initial-sleep" },
- { G_TYPE_BOOLEAN, "Monitors", "EnableMonitors", "enable-monitors" },
- { G_TYPE_INT, "Indexing", "Throttle", "throttle" },
- { G_TYPE_BOOLEAN, "Indexing", "IndexOnBattery", "index-on-battery" },
- { G_TYPE_BOOLEAN, "Indexing", "IndexOnBatteryFirstTime", "index-on-battery-first-time" },
- { G_TYPE_BOOLEAN, "Indexing", "IndexRemovableMedia", "index-removable-devices" },
- { G_TYPE_BOOLEAN, "Indexing", "IndexOpticalDiscs", "index-optical-discs" },
- { G_TYPE_INT, "Indexing", "LowDiskSpaceLimit", "low-disk-space-limit" },
- { G_TYPE_POINTER, "Indexing", "IndexRecursiveDirectories", "index-recursive-directories" },
- { G_TYPE_POINTER, "Indexing", "IndexSingleDirectories", "index-single-directories" },
- { G_TYPE_POINTER, "Indexing", "IgnoredDirectories", "ignored-directories" },
- { G_TYPE_POINTER, "Indexing", "IgnoredDirectoriesWithContent", "ignored-directories-with-content" },
- { G_TYPE_POINTER, "Indexing", "IgnoredFiles", "ignored-files" },
- { G_TYPE_INT, "Indexing", "CrawlingInterval", "crawling-interval" },
- { G_TYPE_INT, "Indexing", "RemovableDaysThreshold", "removable-days-threshold" },
+ { G_TYPE_ENUM, "General", "Verbosity", "verbosity" },
+ { G_TYPE_INT, "General", "InitialSleep", "initial-sleep" },
+ { G_TYPE_BOOLEAN, "Monitors", "EnableMonitors", "enable-monitors" },
+ { G_TYPE_INT, "Indexing", "Throttle", "throttle" },
+ { G_TYPE_BOOLEAN, "Indexing", "IndexOnBattery", "index-on-battery" },
+ { G_TYPE_BOOLEAN, "Indexing", "IndexOnBatteryFirstTime", "index-on-battery-first-time" },
+ { G_TYPE_BOOLEAN, "Indexing", "IndexRemovableMedia", "index-removable-devices" },
+ { G_TYPE_BOOLEAN, "Indexing", "IndexOpticalDiscs", "index-optical-discs" },
+ { G_TYPE_INT, "Indexing", "LowDiskSpaceLimit", "low-disk-space-limit" },
+ { G_TYPE_POINTER, "Indexing", "IndexRecursiveDirectories", "index-recursive-directories" },
+ { G_TYPE_POINTER, "Indexing", "IndexSingleDirectories", "index-single-directories" },
+ { G_TYPE_POINTER, "Indexing", "IgnoredDirectories", "ignored-directories" },
+ { G_TYPE_POINTER, "Indexing", "IgnoredDirectoriesWithContent", "ignored-directories-with-content" },
+ { G_TYPE_POINTER, "Indexing", "IgnoredFiles", "ignored-files" },
+ { G_TYPE_INT, "Indexing", "CrawlingInterval", "crawling-interval" },
+ { G_TYPE_INT, "Indexing", "RemovableDaysThreshold", "removable-days-threshold" },
+ { G_TYPE_BOOLEAN, "Writeback", "EnableWriteback", "enable-writeback" },
{ 0 }
};
@@ -274,6 +280,15 @@ tracker_config_class_init (TrackerConfigClass *klass)
DEFAULT_REMOVABLE_DAYS_THRESHOLD,
G_PARAM_READWRITE));
+ /* Writeback */
+ g_object_class_install_property (object_class,
+ PROP_ENABLE_MONITORS,
+ g_param_spec_boolean ("enable-writeback",
+ "Enable Writeback",
+ "Set to false to disable writeback",
+ DEFAULT_ENABLE_WRITEBACK,
+ G_PARAM_READWRITE));
+
g_type_class_add_private (object_class, sizeof (TrackerConfigPrivate));
}
@@ -359,6 +374,12 @@ config_set_property (GObject *object,
tracker_config_set_removable_days_threshold (TRACKER_CONFIG (object),
g_value_get_int (value));
break;
+
+ /* Writeback */
+ case PROP_ENABLE_WRITEBACK:
+ tracker_config_set_enable_writeback (TRACKER_CONFIG (object),
+ g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -427,6 +448,11 @@ config_get_property (GObject *object,
case PROP_REMOVABLE_DAYS_THRESHOLD:
g_value_set_int (value, tracker_config_get_removable_days_threshold (config));
break;
+
+ /* Writeback */
+ case PROP_ENABLE_WRITEBACK:
+ g_value_set_boolean (value, tracker_config_get_enable_writeback (config));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -824,6 +850,14 @@ tracker_config_get_enable_monitors (TrackerConfig *config)
return g_settings_get_boolean (G_SETTINGS (config), "enable-monitors");
}
+gboolean
+tracker_config_get_enable_writeback (TrackerConfig *config)
+{
+ g_return_val_if_fail (TRACKER_IS_CONFIG (config), DEFAULT_ENABLE_WRITEBACK);
+
+ return g_settings_get_boolean (G_SETTINGS (config), "enable-writeback");
+}
+
gint
tracker_config_get_throttle (TrackerConfig *config)
{
@@ -1004,6 +1038,16 @@ tracker_config_set_enable_monitors (TrackerConfig *config,
}
void
+tracker_config_set_enable_writeback (TrackerConfig *config,
+ gboolean value)
+{
+ g_return_if_fail (TRACKER_IS_CONFIG (config));
+
+ g_settings_set_boolean (G_SETTINGS (config), "enable-writeback", value);
+ g_object_notify (G_OBJECT (config), "enable-writeback");
+}
+
+void
tracker_config_set_throttle (TrackerConfig *config,
gint value)
{
diff --git a/src/miners/fs/tracker-config.h b/src/miners/fs/tracker-config.h
index 5f629a3..345d41d 100644
--- a/src/miners/fs/tracker-config.h
+++ b/src/miners/fs/tracker-config.h
@@ -69,6 +69,7 @@ GSList * tracker_config_get_ignored_directories_with_content (TrackerConfi
GSList * tracker_config_get_ignored_files (TrackerConfig *config);
gint tracker_config_get_crawling_interval (TrackerConfig *config);
gint tracker_config_get_removable_days_threshold (TrackerConfig *config);
+gboolean tracker_config_get_enable_writeback (TrackerConfig *config);
void tracker_config_set_verbosity (TrackerConfig *config,
gint value);
@@ -104,6 +105,8 @@ void tracker_config_set_crawling_interval (TrackerConfi
gint interval);
void tracker_config_set_removable_days_threshold (TrackerConfig *config,
gint value);
+void tracker_config_set_enable_writeback (TrackerConfig *config,
+ gboolean value);
/*
* Convenience functions:
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 8a91205..00b0626 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -752,7 +752,9 @@ main (gint argc, gchar *argv[])
return EXIT_FAILURE;
}
- tracker_writeback_init (TRACKER_MINER_FILES (miner_files), &error);
+ tracker_writeback_init (TRACKER_MINER_FILES (miner_files),
+ config,
+ &error);
if (error) {
g_critical ("Couldn't create writeback handling: '%s'",
diff --git a/src/miners/fs/tracker-writeback.c b/src/miners/fs/tracker-writeback.c
index 803efa4..be59579 100644
--- a/src/miners/fs/tracker-writeback.c
+++ b/src/miners/fs/tracker-writeback.c
@@ -34,9 +34,14 @@ static TrackerWritebackListener *listener = NULL;
* calls the external tracker-writeback process which does the actual write */
static TrackerWritebackDispatcher *dispatcher = NULL;
-void
-tracker_writeback_init (TrackerMinerFiles *miner_files,
- GError **error)
+static gboolean enabled = FALSE;
+static TrackerMinerFiles *gminer_files = NULL;
+static TrackerConfig *gconfig = NULL;
+static guint gsig = 0;
+
+static void
+initialize_all (TrackerMinerFiles *miner_files,
+ GError **error)
{
GError *internal_error = NULL;
@@ -53,6 +58,50 @@ tracker_writeback_init (TrackerMinerFiles *miner_files,
}
g_propagate_error (error, internal_error);
}
+ enabled = TRUE;
+}
+
+static void
+enable_writeback_cb (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ if (enabled && !tracker_config_get_enable_monitors (gconfig)) {
+ tracker_writeback_shutdown ();
+ }
+
+ if (!enabled && tracker_config_get_enable_monitors (gconfig)) {
+ GError *error = NULL;
+
+ initialize_all (gminer_files, &error);
+
+ if (error) {
+ g_critical ("Can't reenable Writeback: '%s'", error->message);
+ g_error_free (error);
+ }
+ }
+}
+
+void
+tracker_writeback_init (TrackerMinerFiles *miner_files,
+ TrackerConfig *config,
+ GError **error)
+{
+ GError *internal_error = NULL;
+
+ if (tracker_config_get_enable_monitors (config)) {
+ initialize_all (miner_files, &internal_error);
+ }
+
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ } else {
+ gminer_files = g_object_ref (miner_files);
+ gconfig = g_object_ref (config);
+ gsig = g_signal_connect (gconfig, "notify::enable-writeback",
+ G_CALLBACK (enable_writeback_cb),
+ NULL);
+ }
}
void
@@ -67,4 +116,16 @@ tracker_writeback_shutdown (void)
g_object_unref (dispatcher);
dispatcher = NULL;
}
+
+ if (gconfig) {
+ if (gsig) {
+ g_signal_handler_disconnect (gconfig, gsig);
+ }
+ g_object_unref (gconfig);
+ }
+
+ if (gminer_files) {
+ g_object_unref (gminer_files);
+ }
+ enabled = FALSE;
}
diff --git a/src/miners/fs/tracker-writeback.h b/src/miners/fs/tracker-writeback.h
index 0f7408f..b356302 100644
--- a/src/miners/fs/tracker-writeback.h
+++ b/src/miners/fs/tracker-writeback.h
@@ -30,6 +30,7 @@
G_BEGIN_DECLS
void tracker_writeback_init (TrackerMinerFiles *miner_files,
+ TrackerConfig *config,
GError **error);
void tracker_writeback_shutdown (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]