[tracker/tracker-0.10] tracker-control: Add command line switch for new pause-for-process APIs



commit 683c9a838ccf3181e863ae1145b00ead03609cfc
Author: Martyn Russell <martyn lanedo com>
Date:   Mon May 16 12:22:55 2011 +0100

    tracker-control: Add command line switch for new pause-for-process APIs
    
    To test the libtracker-miner APIs and allow callers to pause until the
    process is killed, this has been added to tracker-control.

 docs/manpages/tracker-control.1              |    7 +++
 src/tracker-control/tracker-control-miners.c |   54 +++++++++++++++++++++----
 2 files changed, 52 insertions(+), 9 deletions(-)
---
diff --git a/docs/manpages/tracker-control.1 b/docs/manpages/tracker-control.1
index 73b3525..632cf5d 100644
--- a/docs/manpages/tracker-control.1
+++ b/docs/manpages/tracker-control.1
@@ -162,6 +162,13 @@ pauses have been resumed will it continue. If successful, a cookie
 will be given to uniquely identify the request. This cookie is used to
 resume the pause at a later stage.
 .TP
+.B \-\-pause-for-process=REASON
+This works exactly the same way as
+.B \-\-pause
+with the exception that it only keeps the pause active while the
+calling process is alive. As soon as you press Ctrl+C the pause is
+resumed automatically.
+.TP
 .B \-\-resume=COOKIE
 The COOKIE is given by a successful
 .B \-\-pause
diff --git a/src/tracker-control/tracker-control-miners.c b/src/tracker-control/tracker-control-miners.c
index 00fe1fc..4abe518 100644
--- a/src/tracker-control/tracker-control-miners.c
+++ b/src/tracker-control/tracker-control-miners.c
@@ -34,6 +34,7 @@ static const gchar **reindex_mime_types;
 static gchar *index_file;
 static gchar *miner_name;
 static gchar *pause_reason;
+static gchar *pause_for_process_reason;
 static gint resume_cookie = -1;
 static gboolean list_miners_running;
 static gboolean list_miners_available;
@@ -44,6 +45,7 @@ static gboolean pause_details;
 	 index_file || \
 	 miner_name || \
 	 pause_reason || \
+	 pause_for_process_reason || \
 	 resume_cookie != -1 || \
 	 list_miners_running || \
 	 list_miners_available || \
@@ -60,6 +62,10 @@ static GOptionEntry entries[] = {
 	  N_("Pause a miner (you must use this with --miner)"),
 	  N_("REASON")
 	},
+	{ "pause-for-process", 0 , 0, G_OPTION_ARG_STRING, &pause_for_process_reason,
+	  N_("Pause a miner while the calling process is alive or until resumed (you must use this with --miner)"),
+	  N_("REASON")
+	},
 	{ "resume", 0 , 0, G_OPTION_ARG_INT, &resume_cookie,
 	  N_("Resume a miner (you must use this with --miner)"),
 	  N_("COOKIE")
@@ -91,7 +97,8 @@ tracker_control_miners_options_enabled (void)
 
 static gint
 miner_pause (const gchar *miner,
-             const gchar *reason)
+             const gchar *reason,
+             gboolean     for_process)
 {
 	TrackerMinerManager *manager;
 	GError *error = NULL;
@@ -114,10 +121,18 @@ miner_pause (const gchar *miner,
 	g_print ("%s\n", str);
 	g_free (str);
 
-	if (!tracker_miner_manager_pause (manager, miner, reason, &cookie)) {
-		g_printerr (_("Could not pause miner: %s"), miner);
-		g_printerr ("\n");
-		return EXIT_FAILURE;
+	if (for_process) {
+		if (!tracker_miner_manager_pause_for_process (manager, miner, reason, &cookie)) {
+			g_printerr (_("Could not pause miner: %s"), miner);
+			g_printerr ("\n");
+			return EXIT_FAILURE;
+		}
+	} else {
+		if (!tracker_miner_manager_pause (manager, miner, reason, &cookie)) {
+			g_printerr (_("Could not pause miner: %s"), miner);
+			g_printerr ("\n");
+			return EXIT_FAILURE;
+		}
 	}
 
 	str = g_strdup_printf (_("Cookie is %d"), cookie);
@@ -125,6 +140,10 @@ miner_pause (const gchar *miner,
 	g_free (str);
 	g_object_unref (manager);
 
+	if (for_process) {
+		g_print ("%s\n", _("Press Ctrl+C to end pause"));
+	}
+
 	return EXIT_SUCCESS;
 }
 
@@ -319,7 +338,7 @@ miner_get_details (TrackerMinerManager  *manager,
 	return TRUE;
 }
 
-static gboolean
+static gint
 miner_pause_details (void)
 {
 	TrackerMinerManager *manager;
@@ -424,13 +443,13 @@ tracker_control_miners_run (void)
 		return EXIT_FAILURE;
 	}
 
-	if ((pause_reason || resume_cookie != -1) && !miner_name) {
+	if ((pause_reason || pause_for_process_reason  || resume_cookie != -1) && !miner_name) {
 		g_printerr ("%s\n",
 		            _("You must provide the miner for pause or resume commands"));
 		return EXIT_FAILURE;
 	}
 
-	if ((!pause_reason && resume_cookie == -1) && miner_name) {
+	if ((!pause_reason && !pause_for_process_reason && resume_cookie == -1) && miner_name) {
 		g_printerr ("%s\n",
 		            _("You must provide a pause or resume command for the miner"));
 		return EXIT_FAILURE;
@@ -452,7 +471,24 @@ tracker_control_miners_run (void)
 	}
 
 	if (pause_reason) {
-		return miner_pause (miner_name, pause_reason);
+		return miner_pause (miner_name, pause_reason, FALSE);
+	}
+
+	if (pause_for_process_reason) {
+		gint retval;
+
+		retval = miner_pause (miner_name, pause_for_process_reason, TRUE);
+
+		if (retval == EXIT_SUCCESS) {
+			GMainLoop *main_loop;
+
+			main_loop = g_main_loop_new (NULL, FALSE);
+			/* Block until Ctrl+C */
+			g_main_loop_run (main_loop);
+			g_object_unref (main_loop);
+		}
+
+		return retval;
 	}
 
 	if (resume_cookie != -1) {



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