[packagekit] packagekit: Branch 'master' - 2 commits

Richard Hughes hughsient at kemper.freedesktop.org
Mon Dec 24 16:34:02 PST 2007


 docs/html/img/author-jbowes.png |binary
 docs/html/pk-authors.html       |   17 ++++++++++
 src/pk-time.c                   |   63 ++++++++++++++++++++++++++++++++++------
 src/pk-time.h                   |    6 +++
 4 files changed, 77 insertions(+), 9 deletions(-)

New commits:
commit 95f7d17acf8d2194d6edd312934a602e63cf4d21
Author: James Bowes <jbowes at dangerouslyinc.com>
Date:   Mon Dec 24 10:19:01 2007 -0500

    Add myself to the authors page.

diff --git a/docs/html/img/author-jbowes.png b/docs/html/img/author-jbowes.png
new file mode 100644
index 0000000..59bc037
Binary files /dev/null and b/docs/html/img/author-jbowes.png differ
diff --git a/docs/html/pk-authors.html b/docs/html/pk-authors.html
index dddcf53..e40084d 100644
--- a/docs/html/pk-authors.html
+++ b/docs/html/pk-authors.html
@@ -190,6 +190,23 @@
  </td>
 </tr>
 
+<tr>
+ <td>
+  <img src="img/author-jbowes.png" alt="[img]"/><!-- image should be 120px wide -->
+ </td>
+ <td>
+  <h2>James Bowes</h2>
+  <p>
+   James is a frequent <a href="http://linux.duke.edu/projects/yum/">Yum</a> and
+   <a href="http://fedoraproject.org/">Fedora</a> contributor. He has worked for
+   <a href="http://www.redhat.com/">Red Hat, Inc.</a> since 2006.
+  </p>
+  <p>
+   <b>Responsible for: yum backend, smart backend, pkcon</b>
+  </p>
+ </td>
+</tr>
+
 </table>
 
 <p>Back to the <a href="index.html">main page</a></p>
commit 21faf4869fee7e70a027fe3b1901554e0b91278a
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Dec 24 09:48:00 2007 +0000

    allow changing the average and value limits at runtime in PkTime

diff --git a/src/pk-time.c b/src/pk-time.c
index d751ade..27e5e06 100644
--- a/src/pk-time.c
+++ b/src/pk-time.c
@@ -48,17 +48,21 @@ static void     pk_time_init		(PkTime      *time);
 static void     pk_time_finalize	(GObject     *object);
 
 #define PK_TIME_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_TIME, PkTimePrivate))
-#define PK_TIME_AVERAGE_MIN		4
-#define PK_TIME_AVERAGE_MAX		10
-#define PK_TIME_VALUE_MIN		5
-#define PK_TIME_VALUE_MAX		60*60
+#define PK_TIME_AVERAGE_DEFAULT_MIN		4     /* samples */
+#define PK_TIME_AVERAGE_DEFAULT_MAX		10    /* samples */
+#define PK_TIME_VALUE_DEFAULT_MIN		5     /* s */
+#define PK_TIME_VALUE_DEFAULT_MAX		60*60 /* s */
 
 struct PkTimePrivate
 {
 	guint			 time_offset; /* ms */
+	guint			 last_percentage;
+	guint			 average_min;
+	guint			 average_max;
+	guint			 value_min;
+	guint			 value_max;
 	GPtrArray		*array;
 	GTimer			*timer;
-	guint			 last_percentage;
 };
 
 typedef struct {
@@ -69,6 +73,42 @@ typedef struct {
 G_DEFINE_TYPE (PkTime, pk_time, G_TYPE_OBJECT)
 
 /**
+ * pk_time_set_average_limits:
+ * @time: This class instance
+ * @average_min: the smallest number of samples we will try to average
+ * @average_max: the largest number of past samples we will try to average
+ *
+ * Return value: if we set the average limits correctly
+ **/
+gboolean
+pk_time_set_average_limits (PkTime *time, guint average_min, guint average_max)
+{
+	g_return_val_if_fail (time != NULL, FALSE);
+	g_return_val_if_fail (PK_IS_TIME (time), FALSE);
+	time->priv->average_min = average_min;
+	time->priv->average_max = average_max;
+	return TRUE;
+}
+
+/**
+ * pk_time_set_value_limits:
+ * @time: This class instance
+ * @average_min: the smallest value that is acceptable for time (in seconds)
+ * @average_max: the largest value that is acceptable for time (in seconds)
+ *
+ * Return value: if we set the value limits correctly
+ **/
+gboolean
+pk_time_set_value_limits (PkTime *time, guint value_min, guint value_max)
+{
+	g_return_val_if_fail (time != NULL, FALSE);
+	g_return_val_if_fail (PK_IS_TIME (time), FALSE);
+	time->priv->value_min = value_min;
+	time->priv->value_max = value_max;
+	return TRUE;
+}
+
+/**
  * pk_time_get_elapsed:
  *
  * Returns time running in ms
@@ -140,14 +180,14 @@ pk_time_get_remaining (PkTime *time)
 		} else {
 			grad_ave += grad;
 			averaged++;
-			if (averaged > PK_TIME_AVERAGE_MAX) {
+			if (averaged > time->priv->average_max) {
 				break;
 			}
 		}
 	}
 
 	pk_debug ("averaged %i points", averaged);
-	if (averaged < PK_TIME_AVERAGE_MIN) {
+	if (averaged < time->priv->average_min) {
 		pk_debug ("not enough samples for accurate time: %i", averaged);
 		return 0;
 	}
@@ -170,9 +210,9 @@ pk_time_get_remaining (PkTime *time)
 	estimated /= 1000;
 	pk_debug ("estimated=%f seconds", estimated);
 
-	if (estimated < PK_TIME_VALUE_MIN) {
+	if (estimated < time->priv->value_min) {
 		estimated = 0;
-	} else if (estimated > PK_TIME_VALUE_MAX) {
+	} else if (estimated > time->priv->value_max) {
 		estimated = 0;
 	}
 	return (guint) estimated;
@@ -233,6 +273,11 @@ pk_time_init (PkTime *time)
 	time->priv = PK_TIME_GET_PRIVATE (time);
 	time->priv->time_offset = 0;
 	time->priv->last_percentage = 0;
+	time->priv->average_min = PK_TIME_AVERAGE_DEFAULT_MIN;
+	time->priv->average_max = PK_TIME_AVERAGE_DEFAULT_MAX;
+	time->priv->value_min = PK_TIME_VALUE_DEFAULT_MIN;
+	time->priv->value_max = PK_TIME_VALUE_DEFAULT_MAX;
+
 	time->priv->array = g_ptr_array_new ();
 	time->priv->timer = g_timer_new ();
 }
diff --git a/src/pk-time.h b/src/pk-time.h
index 5e0245f..f91c2de 100644
--- a/src/pk-time.h
+++ b/src/pk-time.h
@@ -55,6 +55,12 @@ gboolean	 pk_time_add_data			(PkTime		*time,
 							 guint		 percentage);
 guint		 pk_time_get_elapsed			(PkTime		*time);
 guint		 pk_time_get_remaining			(PkTime		*time);
+gboolean	 pk_time_set_average_limits		(PkTime		*time,
+							 guint		 average_min,
+							 guint		 average_max);
+gboolean	 pk_time_set_value_limits		(PkTime		*time,
+							 guint		 value_min,
+							 guint		 value_max);
 
 G_END_DECLS
 



More information about the PackageKit mailing list