mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nigel Cunningham <nigel@suspend2.net>
To: linux-kernel@vger.kernel.org
Subject: [Suspend2][ 09/21] [Suspend2] Update progress bar.
Date: Tue, 27 Jun 2006 14:41:43 +1000	[thread overview]
Message-ID: <20060627044141.14883.48602.stgit@nigel.suspend2.net> (raw)
In-Reply-To: <20060627044112.14883.55823.stgit@nigel.suspend2.net>

Update the progress bar (if userui is displaying one), and possbly display
some text in the bar itself (eg a/b MB written).

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/ui.c |   73 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 2f779a5..b01c89b 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -210,3 +210,76 @@ static unsigned long userui_memory_neede
 	return (128 * PAGE_SIZE);
 }
 
+/* suspend_update_status
+ *
+ * Description: Update the progress bar and (if on) in-bar message.
+ * Arguments:	UL value, maximum: Current progress percentage (value/max).
+ * 		const char *fmt, ...: Message to be displayed in the middle
+ * 		of the progress bar.
+ * 		Note that a NULL message does not mean that any previous
+ * 		message is erased! For that, you need suspend_prepare_status with
+ * 		clearbar on.
+ * Returns:	Unsigned long: The next value where status needs to be updated.
+ * 		This is to reduce unnecessary calls to update_status.
+ */
+unsigned long suspend_update_status(unsigned long value, unsigned long maximum,
+		const char *fmt, ...)
+{
+	static int last_step = -1;
+	struct userui_msg_params msg;
+	int bitshift;
+	int this_step;
+	unsigned long next_update;
+
+	if (ui_helper_data.pid == -1)
+		return 0;
+
+	if ((!maximum) || (!progress_granularity))
+		return maximum;
+
+	if (value < 0)
+		value = 0;
+
+	if (value > maximum)
+		value = maximum;
+
+	/* Try to avoid math problems - we can't do 64 bit math here
+	 * (and shouldn't need it - anyone got screen resolution
+	 * of 65536 pixels or more?) */
+	bitshift = fls(maximum) - 16;
+	if (bitshift > 0) {
+		unsigned long temp_maximum = maximum >> bitshift;
+		unsigned long temp_value = value >> bitshift;
+		this_step = (int)
+			(temp_value * progress_granularity / temp_maximum);
+		next_update = (((this_step + 1) * temp_maximum /
+					progress_granularity) + 1) << bitshift;
+	} else {
+		this_step = (int) (value * progress_granularity / maximum);
+		next_update = ((this_step + 1) * maximum /
+				progress_granularity) + 1;
+	}
+
+	if (this_step == last_step)
+		return next_update;
+
+	memset(&msg, 0, sizeof(msg));
+
+	msg.a = this_step;
+	msg.b = progress_granularity;
+
+	if (fmt) {
+		va_list args;
+		va_start(args, fmt);
+		vsnprintf(msg.text, sizeof(msg.text), fmt, args);
+		va_end(args);
+		msg.text[sizeof(msg.text)-1] = '\0';
+	}
+
+	suspend_send_netlink_message(&ui_helper_data, USERUI_MSG_PROGRESS,
+			&msg, sizeof(msg));
+	last_step = this_step;
+
+	return next_update;
+}
+

--
Nigel Cunningham		nigel at suspend2 dot net

  parent reply	other threads:[~2006-06-27  4:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-27  4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
2006-06-27  4:41 ` [Suspend2][ 01/21] [Suspend2] User interface c header Nigel Cunningham
2006-06-27  4:41 ` [Suspend2][ 02/21] [Suspend2] Modify action state Nigel Cunningham
2006-06-27  4:41 ` [Suspend2][ 03/21] [Suspend2] Tell userspace to redraw the screen Nigel Cunningham
2006-06-27  4:41 ` [Suspend2][ 04/21] [Suspend2] Process abort request Nigel Cunningham
2006-06-27  4:41 ` [Suspend2][ 05/21] [Suspend2] Receive a message from the userui Nigel Cunningham
2006-06-27  4:41 ` [Suspend2][ 06/21] [Suspend2] Get userui storage needed Nigel Cunningham
2006-06-27  4:41 ` [Suspend2][ 07/21] [Suspend2] Serialise userui configuration info Nigel Cunningham
2006-06-27  4:41 ` [Suspend2][ 08/21] [Suspend2] Get amount of memory needed for userui Nigel Cunningham
2006-06-27  4:41 ` Nigel Cunningham [this message]
2006-06-27  4:41 ` [Suspend2][ 10/21] [Suspend2] __suspend_message Nigel Cunningham
2006-06-27  4:41 ` [Suspend2][ 11/21] [Suspend2] Wait for keypress Nigel Cunningham
2006-06-27  4:41 ` [Suspend2][ 12/21] [Suspend2] Abort a cycle Nigel Cunningham
2006-06-27  4:41 ` [Suspend2][ 13/21] [Suspend2] Main message output Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 14/21] [Suspend2] Conditionally pause Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 15/21] [Suspend2] Prepare ui for work Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 16/21] [Suspend2] Cleanup console after suspending Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 17/21] [Suspend2] Early boot message support Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 18/21] [Suspend2] Userspace proc entries Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 19/21] [Suspend2] Operations for userspace interface module Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 20/21] [Suspend2] Load time initialisation for user interface code Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 21/21] [Suspend2] kernel/power/ui.h Nigel Cunningham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060627044141.14883.48602.stgit@nigel.suspend2.net \
    --to=nigel@suspend2.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome