[gnome-builder] build-result: add timeout source to notify running-time
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] build-result: add timeout source to notify running-time
- Date: Tue, 28 Jun 2016 00:06:28 +0000 (UTC)
commit 0a4582819c9ee97e4e1eb1f3e760a624e0b4d568
Author: Christian Hergert <chergert redhat com>
Date: Thu Jun 23 17:47:29 2016 -0700
build-result: add timeout source to notify running-time
There are a couple of places we need this, so it would be nice to have the
notification source in a single place rather than require consumers to
bring their own polling.
libide/buildsystem/ide-build-result.c | 58 +++++++++++++++++++++++++++++----
1 files changed, 51 insertions(+), 7 deletions(-)
---
diff --git a/libide/buildsystem/ide-build-result.c b/libide/buildsystem/ide-build-result.c
index e7521b4..b065ffe 100644
--- a/libide/buildsystem/ide-build-result.c
+++ b/libide/buildsystem/ide-build-result.c
@@ -51,6 +51,7 @@ typedef struct
GTimer *timer;
gchar *mode;
+ GSource *running_time_source;
guint running : 1;
} IdeBuildResultPrivate;
@@ -68,6 +69,7 @@ enum {
PROP_0,
PROP_MODE,
PROP_RUNNING,
+ PROP_RUNNING_TIME,
LAST_PROP
};
@@ -476,6 +478,8 @@ ide_build_result_finalize (GObject *object)
IdeBuildResult *self = (IdeBuildResult *)object;
IdeBuildResultPrivate *priv = ide_build_result_get_instance_private (self);
+ g_clear_pointer (&priv->running_time_source, g_source_destroy);
+
g_clear_object (&priv->addins);
g_clear_object (&priv->stderr_reader);
@@ -504,12 +508,16 @@ ide_build_result_get_property (GObject *object,
switch (prop_id)
{
+ case PROP_MODE:
+ g_value_take_string (value, ide_build_result_get_mode (self));
+ break;
+
case PROP_RUNNING:
g_value_set_boolean (value, ide_build_result_get_running (self));
break;
- case PROP_MODE:
- g_value_take_string (value, ide_build_result_get_mode (self));
+ case PROP_RUNNING_TIME:
+ g_value_set_int64 (value, ide_build_result_get_running_time (self));
break;
default:
@@ -527,14 +535,14 @@ ide_build_result_set_property (GObject *object,
switch (prop_id)
{
- case PROP_RUNNING:
- ide_build_result_set_running (self, g_value_get_boolean (value));
- break;
-
case PROP_MODE:
ide_build_result_set_mode (self, g_value_get_string (value));
break;
+ case PROP_RUNNING:
+ ide_build_result_set_running (self, g_value_get_boolean (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
@@ -564,6 +572,15 @@ ide_build_result_class_init (IdeBuildResultClass *klass)
FALSE,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
+ properties [PROP_RUNNING_TIME] =
+ g_param_spec_int64 ("running-time",
+ "Running Time",
+ "Duration of the build operation",
+ 0,
+ G_MAXINT64,
+ 0,
+ (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
+
g_object_class_install_properties (object_class, LAST_PROP, properties);
signals [DIAGNOSTIC] =
@@ -654,6 +671,18 @@ ide_build_result_get_running (IdeBuildResult *self)
return priv->running;
}
+static gboolean
+ide_build_result_do_notify_running_time (gpointer user_data)
+{
+ IdeBuildResult *self = user_data;
+
+ g_assert (IDE_IS_BUILD_RESULT (self));
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_RUNNING_TIME]);
+
+ return G_SOURCE_CONTINUE;
+}
+
void
ide_build_result_set_running (IdeBuildResult *self,
gboolean running)
@@ -668,9 +697,24 @@ ide_build_result_set_running (IdeBuildResult *self,
if (priv->running != running)
{
priv->running = running;
+
if (!running)
- g_timer_stop (priv->timer);
+ {
+ g_timer_stop (priv->timer);
+ g_clear_pointer (&priv->running_time_source, g_source_destroy);
+ }
+ else
+ {
+ priv->running_time_source = g_timeout_source_new_seconds (1);
+ g_source_set_name (priv->running_time_source, "[ide] build result running-time notify");
+ g_source_set_callback (priv->running_time_source,
+ ide_build_result_do_notify_running_time,
+ self, NULL);
+ g_source_attach (priv->running_time_source, NULL);
+ }
+
ide_object_notify_in_main (self, properties [PROP_RUNNING]);
+ ide_object_notify_in_main (self, properties [PROP_RUNNING_TIME]);
}
g_mutex_unlock (&priv->mutex);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]