[tracker/writeback-refactor-0.10: 14/63] miners/fs: Make it possible to enable/disable Writeback



commit 7311361ce1040ee84ed37a544385ab6ad8d2d513
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    |   58 +++++++++++++++++++++++++++++++-
 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, 128 insertions(+), 5 deletions(-)
---
diff --git a/src/miners/fs/tracker-config.c b/src/miners/fs/tracker-config.c
index 2f86af0..fb221bb 100644
--- a/src/miners/fs/tracker-config.c
+++ b/src/miners/fs/tracker-config.c
@@ -38,6 +38,7 @@
 #define GROUP_MONITORS                           "Monitors"
 #define GROUP_INDEXING                           "Indexing"
 #define GROUP_CRAWLING                           "Crawling"
+#define GROUP_WRITEBACK                          "Writeback"
 
 /* Default values */
 #define DEFAULT_VERBOSITY                        0
@@ -51,6 +52,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 {
 	/* General */
@@ -77,6 +79,9 @@ typedef struct {
 	gint	  crawling_interval;
 	gint      removable_days_threshold;
 
+	/* Writeback */
+	gboolean  enable_writeback;
+
 	/* Convenience data */
 	GSList   *ignored_directory_patterns;
 	GSList   *ignored_directory_paths;
@@ -132,7 +137,11 @@ 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 ObjectToKeyFile conversions[] = {
@@ -155,6 +164,7 @@ static ObjectToKeyFile conversions[] = {
 	{ G_TYPE_POINTER, "ignored-files",                    GROUP_INDEXING, "IgnoredFiles"              },
 	{ G_TYPE_INT,	  "crawling-interval",                GROUP_INDEXING, "CrawlingInterval"          },
 	{ G_TYPE_INT,	  "removable-days-threshold",         GROUP_INDEXING, "RemovableDaysThreshold"    }
+	{ G_TYPE_BOOLEAN, "enable-writeback",                 GROUP_WRITEBACK, "EnableWriteback"          },
 };
 
 G_DEFINE_TYPE (TrackerConfig, tracker_config, TRACKER_TYPE_CONFIG_FILE);
@@ -317,6 +327,15 @@ tracker_config_class_init (TrackerConfigClass *klass)
 	                                                   DEFAULT_REMOVABLE_DAYS_THRESHOLD,
 	                                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
+	/* Writeback */
+	g_object_class_install_property (object_class,
+	                                 PROP_ENABLE_WRITEBACK,
+	                                 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));
 }
 
@@ -401,6 +420,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;
@@ -471,6 +496,11 @@ config_get_property (GObject    *object,
 	case PROP_REMOVABLE_DAYS_THRESHOLD:
 		g_value_set_int (value, priv->removable_days_threshold);
 		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;
@@ -1092,6 +1122,18 @@ tracker_config_get_enable_monitors (TrackerConfig *config)
 	return priv->enable_monitors;
 }
 
+gboolean
+tracker_config_get_enable_writeback (TrackerConfig *config)
+{
+	TrackerConfigPrivate *priv;
+
+	g_return_val_if_fail (TRACKER_IS_CONFIG (config), DEFAULT_ENABLE_WRITEBACK);
+
+	priv = TRACKER_CONFIG_GET_PRIVATE (config);
+
+	return priv->enable_writeback;
+}
+
 gint
 tracker_config_get_throttle (TrackerConfig *config)
 {
@@ -1323,6 +1365,20 @@ tracker_config_set_enable_monitors (TrackerConfig *config,
 }
 
 void
+tracker_config_set_enable_writeback (TrackerConfig *config,
+                                     gboolean       value)
+{
+	TrackerConfigPrivate *priv;
+
+	g_return_if_fail (TRACKER_IS_CONFIG (config));
+
+	priv = TRACKER_CONFIG_GET_PRIVATE (config);
+
+	priv->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 5327c5c..24e5da5 100644
--- a/src/miners/fs/tracker-config.h
+++ b/src/miners/fs/tracker-config.h
@@ -70,6 +70,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);
@@ -105,6 +106,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]