[gnome-battery-bench] TestRunner: Move logic for running tests to a separate class
- From: Owen Taylor <otaylor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-battery-bench] TestRunner: Move logic for running tests to a separate class
- Date: Mon, 5 Jan 2015 13:01:20 +0000 (UTC)
commit 46dad23128a3840a8af899a70ce8224c2357d7f6
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Fri Jan 2 12:43:36 2015 -0500
TestRunner: Move logic for running tests to a separate class
Instead of embedding the logic into the application, separate it out
so that we can play back from the command line as well.
configure.ac | 2 +-
src/Makefile.am | 28 ++++---
src/application.c | 213 ++++++++++++++----------------------------------
src/commandline.c | 5 +-
src/power-monitor.c | 4 +-
src/power-monitor.h | 2 +-
src/test-run.h | 2 +
src/test-runner.c | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/test-runner.h | 46 +++++++++++
9 files changed, 353 insertions(+), 171 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8345b31..f2b1389 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,7 +22,7 @@ AC_PROG_CC
AM_PROG_CC_C_O
PKG_CHECK_MODULES([HELPER], [$base_packages polkit-gobject-1])
-PKG_CHECK_MODULES([COMMANDLINE], [$base_packages $x_packages])
+PKG_CHECK_MODULES([COMMANDLINE], [$base_packages $x_packages json-glib-1.0])
PKG_CHECK_MODULES([APPLICATION], [$base_packages $x_packages gtk+-3.0 json-glib-1.0])
GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
diff --git a/src/Makefile.am b/src/Makefile.am
index 619d1dc..5091c0d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,14 +4,10 @@ bin_PROGRAMS=gnome-battery-bench gbb
libexec_PROGRAMS=gnome-battery-bench-helper
base_sources = \
- power-monitor.c \
- power-monitor.h \
- battery-test.c \
- battery-test.h \
- evdev-player.c \
- evdev-player.h \
event-log.c \
event-log.h \
+ evdev-player.c \
+ evdev-player.h \
event-player.c \
event-player.h \
introspection.c \
@@ -21,10 +17,20 @@ base_sources = \
util.c \
util.h
-x_sources = \
+client_sources = \
$(base_sources) \
+ battery-test.c \
+ battery-test.h \
event-recorder.c \
event-recorder.h \
+ power-monitor.c \
+ power-monitor.h \
+ system-state.c \
+ system-state.h \
+ test-run.c \
+ test-run.h \
+ test-runner.c \
+ test-runner.h \
xinput-wait.c \
xinput-wait.h
@@ -32,15 +38,11 @@ gnome_battery_bench_CPPFLAGS = $(APPLICATION_CFLAGS) -DPKGDATADIR=\"$(pkgdatadir
gnome_battery_bench_LDADD = $(APPLICATION_LIBS)
gnome_battery_bench_SOURCES = \
- $(x_sources) \
+ $(client_sources) \
gui.c \
application.c \
power-graphs.c \
power-graphs.h \
- system-state.c \
- system-state.h \
- test-run.c \
- test-run.h \
util-gtk.c \
util-gtk.h \
gnome-battery-bench.gresource.c
@@ -49,7 +51,7 @@ gbb_CPPFLAGS = $(COMMANDLINE_CFLAGS) -DPKGDATADIR=\"$(pkgdatadir)\"
gbb_LDADD = $(COMMANDLINE_LIBS)
gbb_SOURCES = \
- $(x_sources) \
+ $(client_sources) \
commandline.c
gnome_battery_bench_helper_CPPFLAGS = $(HELPER_CFLAGS) -DPKGDATADIR=\"$(pkgdatadir)\"
diff --git a/src/application.c b/src/application.c
index b5fc43d..9112498 100644
--- a/src/application.c
+++ b/src/application.c
@@ -13,32 +13,15 @@
#include "application.h"
#include "battery-test.h"
-#include "remote-player.h"
#include "power-graphs.h"
-#include "power-monitor.h"
-#include "system-state.h"
-#include "test-run.h"
+#include "test-runner.h"
#include "util.h"
-typedef enum {
- DURATION_TIME,
- DURATION_PERCENT
-} DurationType;
-
-typedef enum {
- STATE_STOPPED,
- STATE_PROLOGUE,
- STATE_WAITING,
- STATE_RUNNING,
- STATE_STOPPING,
- STATE_EPILOGUE
-} State;
-
struct _GbbApplication {
GtkApplication parent;
+ GbbTestRunner *runner;
GbbPowerMonitor *monitor;
GbbEventPlayer *player;
- GbbSystemState *system_state;
GFile *log_folder;
@@ -62,8 +45,6 @@ struct _GbbApplication {
GtkWidget *test_graphs;
GtkWidget *log_graphs;
- State state;
- gboolean stop_requested;
gboolean exit_requested;
GbbBatteryTest *test;
@@ -123,20 +104,20 @@ update_labels(GbbApplication *application)
"%s", current_state->online ? "online" : "offline");
char *title = NULL;
- switch (application->state) {
- case STATE_STOPPED:
+ switch (gbb_test_runner_get_phase(application->runner)) {
+ case GBB_TEST_PHASE_STOPPED:
title = g_strdup("GNOME Battery Bench");
break;
- case STATE_PROLOGUE:
+ case GBB_TEST_PHASE_PROLOGUE:
title = g_strdup("GNOME Battery Bench - setting up");
break;
- case STATE_WAITING:
+ case GBB_TEST_PHASE_WAITING:
if (current_state->online)
title = g_strdup("GNOME Battery Bench - disconnect from AC to start");
else
title = g_strdup("GNOME Battery Bench - waiting for data");
break;
- case STATE_RUNNING:
+ case GBB_TEST_PHASE_RUNNING:
{
int h, m, s;
const GbbPowerState *start_state = gbb_test_run_get_start_state(application->run);
@@ -144,10 +125,10 @@ update_labels(GbbApplication *application)
title = g_strdup_printf("GNOME Battery Bench - running (%d:%02d:%02d)", h, m, s);
break;
}
- case STATE_STOPPING:
+ case GBB_TEST_PHASE_STOPPING:
title = g_strdup("GNOME Battery Bench - stopping");
break;
- case STATE_EPILOGUE:
+ case GBB_TEST_PHASE_EPILOGUE:
title = g_strdup("GNOME Battery Bench - cleaning up");
break;
}
@@ -228,19 +209,19 @@ update_sensitive(GbbApplication *application)
gboolean start_sensitive = FALSE;
gboolean controls_sensitive = FALSE;
- switch (application->state) {
- case STATE_STOPPED:
+ switch (gbb_test_runner_get_phase(application->runner)) {
+ case GBB_TEST_PHASE_STOPPED:
start_sensitive = gbb_event_player_is_ready(application->player);
controls_sensitive = TRUE;
break;
- case STATE_PROLOGUE:
- case STATE_WAITING:
- case STATE_RUNNING:
- start_sensitive = !application->stop_requested;
+ case GBB_TEST_PHASE_PROLOGUE:
+ case GBB_TEST_PHASE_WAITING:
+ case GBB_TEST_PHASE_RUNNING:
+ start_sensitive = !gbb_test_runner_get_stop_requested(application->runner);
controls_sensitive = FALSE;
break;
- case STATE_STOPPING:
- case STATE_EPILOGUE:
+ case GBB_TEST_PHASE_STOPPING:
+ case GBB_TEST_PHASE_EPILOGUE:
start_sensitive = FALSE;
controls_sensitive = FALSE;
break;
@@ -253,15 +234,6 @@ update_sensitive(GbbApplication *application)
}
static void
-application_set_state(GbbApplication *application,
- State state)
-{
- application->state = state;
- update_sensitive(application);
- update_labels(application);
-}
-
-static void
on_power_monitor_changed(GbbPowerMonitor *monitor,
GbbApplication *application)
{
@@ -269,18 +241,7 @@ on_power_monitor_changed(GbbPowerMonitor *monitor,
gbb_power_state_free(application->previous_state);
application->previous_state = application->current_state;
- application->current_state = gbb_power_monitor_get_state(monitor);
-
- if (application->state == STATE_WAITING) {
- if (!application->current_state->online) {
- gbb_test_run_set_start_time(application->run, time(NULL));
- gbb_test_run_add(application->run, application->current_state);
- application_set_state(application, STATE_RUNNING);
- gbb_event_player_play_file(application->player, application->test->loop_file);
- }
- } else if (application->state == STATE_RUNNING) {
- gbb_test_run_add(application->run, application->current_state);
- }
+ application->current_state = gbb_power_state_copy(gbb_power_monitor_get_state(monitor));
update_labels(application);
}
@@ -503,67 +464,9 @@ write_run_to_disk(GbbApplication *application,
}
static void
-application_set_stopped(GbbApplication *application)
-{
- application_set_state(application, STATE_STOPPED);
-
- const GbbPowerState *start_state = gbb_test_run_get_start_state(application->run);
- const GbbPowerState *last_state = gbb_test_run_get_last_state(application->run);
- if (last_state != start_state) {
- write_run_to_disk(application, application->run);
- add_run_to_logs(application, application->run);
- }
-
- application->test = NULL;
-
- remove_stop_shortcut(application);
-
- gbb_system_state_restore(application->system_state);
-
- g_object_set(G_OBJECT(application->start_button), "label", "Start", NULL);
-
- if (application->exit_requested)
- gtk_widget_destroy(application->window);
-}
-
-static void
-application_set_epilogue(GbbApplication *application)
-{
- if (application->test->epilogue_file) {
- gbb_event_player_play_file(application->player, application->test->epilogue_file);
- application_set_state(application, STATE_EPILOGUE);
- } else {
- application_set_stopped(application);
- }
-}
-
-static void
-on_player_finished(GbbEventPlayer *player,
- GbbApplication *application)
-{
- if (application->state == STATE_PROLOGUE) {
- application_set_state(application, STATE_WAITING);
-
- if (application->stop_requested) {
- application->stop_requested = FALSE;
- application_stop(application);
- }
- } else if (application->state == STATE_RUNNING) {
- if (gbb_test_run_is_done(application->run))
- application_set_epilogue(application);
- else
- gbb_event_player_play_file(player, application->test->loop_file);
- } else if (application->state == STATE_STOPPING) {
- application_set_epilogue(application);
- } else if (application->state == STATE_EPILOGUE) {
- application_set_stopped(application);
- }
-}
-
-static void
application_start(GbbApplication *application)
{
- if (application->state != STATE_STOPPED)
+ if (gbb_test_runner_get_phase(application->runner) != GBB_TEST_PHASE_STOPPED)
return;
if (application->run) {
@@ -594,39 +497,18 @@ application_start(GbbApplication *application)
gbb_test_run_set_screen_brightness(application->run, screen_brightness);
- gbb_system_state_save(application->system_state);
- gbb_system_state_set_brightnesses(application->system_state,
- screen_brightness,
- 0);
-
gbb_power_graphs_set_test_run(GBB_POWER_GRAPHS(application->test_graphs), application->run);
setup_stop_shortcut(application);
- update_labels(application);
-
- if (application->test->prologue_file) {
- gbb_event_player_play_file(application->player, application->test->prologue_file);
- application_set_state(application, STATE_PROLOGUE);
- } else {
- application_set_state(application, STATE_WAITING);
- }
+ gbb_test_runner_set_run(application->runner, application->run);
+ gbb_test_runner_start(application->runner);
}
static void
application_stop(GbbApplication *application)
{
- if ((application->state == STATE_WAITING || application->state == STATE_RUNNING)) {
- if (application->state == STATE_RUNNING) {
- gbb_event_player_stop(application->player);
- application_set_state(application, STATE_STOPPING);
- } else {
- application_set_epilogue(application);
- }
- } else if (application->state == STATE_PROLOGUE) {
- application->stop_requested = TRUE;
- update_sensitive(application);
- }
+ gbb_test_runner_stop(application->runner);
}
static void
@@ -643,11 +525,13 @@ static void
on_start_button_clicked(GtkWidget *button,
GbbApplication *application)
{
- if (application->state == STATE_STOPPED) {
+ GbbTestPhase phase = gbb_test_runner_get_phase(application->runner);
+
+ if (phase == GBB_TEST_PHASE_STOPPED) {
application_start(application);
- } else if (application->state == STATE_PROLOGUE ||
- application->state == STATE_WAITING ||
- application->state == STATE_RUNNING) {
+ } else if (phase == GBB_TEST_PHASE_PROLOGUE ||
+ phase == GBB_TEST_PHASE_WAITING ||
+ phase == GBB_TEST_PHASE_RUNNING) {
application_stop(application);
}
}
@@ -710,7 +594,7 @@ on_delete_event(GtkWidget *window,
GdkEventAny *event,
GbbApplication *application)
{
- if (application->state == STATE_STOPPED) {
+ if (gbb_test_runner_get_phase(application->runner) == GBB_TEST_PHASE_STOPPED) {
return FALSE;
} else {
application->exit_requested = TRUE;
@@ -951,7 +835,7 @@ gbb_application_activate (GApplication *app)
G_CALLBACK(on_main_stack_notify_visible_child), application);
on_main_stack_notify_visible_child(GTK_STACK(main_stack), NULL, application);
- application->current_state = gbb_power_monitor_get_state(application->monitor);
+ application->current_state = gbb_power_state_copy(gbb_power_monitor_get_state(application->monitor));
g_signal_connect(application->monitor, "changed",
G_CALLBACK(on_power_monitor_changed),
application);
@@ -973,20 +857,47 @@ gbb_application_class_init(GbbApplicationClass *class)
}
static void
+on_runner_phase_changed(GbbTestRunner *runner,
+ GbbApplication *application)
+{
+ if (gbb_test_runner_get_phase(runner) == GBB_TEST_PHASE_STOPPED) {
+ const GbbPowerState *start_state = gbb_test_run_get_start_state(application->run);
+ const GbbPowerState *last_state = gbb_test_run_get_last_state(application->run);
+ if (last_state != start_state) {
+ write_run_to_disk(application, application->run);
+ add_run_to_logs(application, application->run);
+ }
+
+ application->test = NULL;
+
+ remove_stop_shortcut(application);
+
+ g_object_set(G_OBJECT(application->start_button), "label", "Start", NULL);
+
+ if (application->exit_requested)
+ gtk_widget_destroy(application->window);
+ }
+
+ update_sensitive(application);
+ update_labels(application);
+}
+
+static void
gbb_application_init(GbbApplication *application)
{
- application->monitor = gbb_power_monitor_new();
- application->system_state = gbb_system_state_new();
+ application->runner = gbb_test_runner_new();
+ g_signal_connect(application->runner, "phase-changed",
+ G_CALLBACK(on_runner_phase_changed), application);
+
+ application->monitor = gbb_test_runner_get_power_monitor(application->runner);
char *folder_path = g_build_filename(g_get_user_data_dir(), PACKAGE_NAME, "logs", NULL);
application->log_folder = g_file_new_for_path(folder_path);
g_free(folder_path);
- application->player = GBB_EVENT_PLAYER(gbb_remote_player_new("GNOME Battery Bench"));
+ application->player = gbb_test_runner_get_event_player(application->runner);
g_signal_connect(application->player, "ready",
G_CALLBACK(on_player_ready), application);
- g_signal_connect(application->player, "finished",
- G_CALLBACK(on_player_finished), application);
}
GbbApplication *
diff --git a/src/commandline.c b/src/commandline.c
index 8717b7b..db6bdd2 100644
--- a/src/commandline.c
+++ b/src/commandline.c
@@ -103,11 +103,11 @@ static void
on_power_monitor_changed(GbbPowerMonitor *monitor)
{
if (start_state == NULL) {
- start_state = gbb_power_monitor_get_state(monitor);
+ start_state = gbb_power_state_copy(gbb_power_monitor_get_state(monitor));
return;
}
- GbbPowerState *state = gbb_power_monitor_get_state(monitor);
+ const GbbPowerState *state = gbb_power_monitor_get_state(monitor);
GbbPowerStatistics *statistics = gbb_power_statistics_compute(start_state, state);
if (statistics->power >= 0)
@@ -127,7 +127,6 @@ on_power_monitor_changed(GbbPowerMonitor *monitor)
statistics->battery_life_design, h, m, s);
}
- gbb_power_state_free(state);
gbb_power_statistics_free(statistics);
}
diff --git a/src/power-monitor.c b/src/power-monitor.c
index bf104de..e603fd2 100644
--- a/src/power-monitor.c
+++ b/src/power-monitor.c
@@ -415,10 +415,10 @@ gbb_power_monitor_new(void)
return monitor;
}
-GbbPowerState *
+const GbbPowerState *
gbb_power_monitor_get_state (GbbPowerMonitor *monitor)
{
- return gbb_power_state_copy(&monitor->current_state);
+ return &monitor->current_state;
}
GbbPowerStatistics *
diff --git a/src/power-monitor.h b/src/power-monitor.h
index 36677f8..22d4225 100644
--- a/src/power-monitor.h
+++ b/src/power-monitor.h
@@ -40,7 +40,7 @@ GType gbb_power_monitor_get_type(void);
GbbPowerMonitor *gbb_power_monitor_new (void);
-GbbPowerState *gbb_power_monitor_get_state (GbbPowerMonitor *monitor);
+const GbbPowerState *gbb_power_monitor_get_state (GbbPowerMonitor *monitor);
GbbPowerState *gbb_power_state_new (void);
GbbPowerState *gbb_power_state_copy (const GbbPowerState *state);
diff --git a/src/test-run.h b/src/test-run.h
index eac1165..6330c33 100644
--- a/src/test-run.h
+++ b/src/test-run.h
@@ -30,6 +30,8 @@ GbbTestRun *gbb_test_run_new(GbbBatteryTest *test);
GbbTestRun *gbb_test_run_new_from_file(const char *filename,
GError **error);
+GbbBatteryTest *gbb_test_run_get_test(GbbTestRun *run);
+
void gbb_test_run_set_start_time(GbbTestRun *run,
gint64 t);
gint64 gbb_test_run_get_start_time(GbbTestRun *run);
diff --git a/src/test-runner.c b/src/test-runner.c
new file mode 100644
index 0000000..24bb853
--- /dev/null
+++ b/src/test-runner.c
@@ -0,0 +1,222 @@
+/* -*- mode: C; c-file-style: "stroustrup"; indent-tabs-mode: nil; -*- */
+
+#include "remote-player.h"
+#include "system-state.h"
+#include "test-runner.h"
+
+struct _GbbTestRunner {
+ GObject parent;
+
+ GbbPowerMonitor *monitor;
+ GbbEventPlayer *player;
+ GbbSystemState *system_state;
+
+ GbbBatteryTest *test;
+ GbbTestRun *run;
+
+ GbbTestPhase phase;
+ gboolean stop_requested;
+};
+
+struct _GbbTestRunnerClass {
+ GObjectClass parent_class;
+};
+
+enum {
+ PHASE_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
+G_DEFINE_TYPE(GbbTestRunner, gbb_test_runner, G_TYPE_OBJECT)
+
+static void
+runner_set_phase(GbbTestRunner *runner,
+ GbbTestPhase phase)
+{
+ if (runner->phase == phase)
+ return;
+
+ runner->phase = phase;
+ g_signal_emit(runner, signals[PHASE_CHANGED], 0);
+}
+
+static void
+runner_set_stopped(GbbTestRunner *runner)
+{
+ gbb_system_state_restore(runner->system_state);
+
+ runner_set_phase(runner, GBB_TEST_PHASE_STOPPED);
+}
+
+static void
+runner_set_epilogue(GbbTestRunner *runner)
+{
+ if (runner->test->epilogue_file) {
+ gbb_event_player_play_file(runner->player, runner->test->epilogue_file);
+ runner_set_phase(runner, GBB_TEST_PHASE_EPILOGUE);
+ } else {
+ runner_set_stopped(runner);
+ }
+}
+
+static void
+on_player_finished(GbbEventPlayer *player,
+ GbbTestRunner *runner)
+{
+ if (runner->phase == GBB_TEST_PHASE_PROLOGUE) {
+ runner_set_phase(runner, GBB_TEST_PHASE_WAITING);
+
+ if (runner->stop_requested) {
+ runner->stop_requested = FALSE;
+ gbb_test_runner_stop(runner);
+ }
+ } else if (runner->phase == GBB_TEST_PHASE_RUNNING) {
+ if (gbb_test_run_is_done(runner->run))
+ runner_set_epilogue(runner);
+ else
+ gbb_event_player_play_file(player, runner->test->loop_file);
+ } else if (runner->phase == GBB_TEST_PHASE_STOPPING) {
+ runner_set_epilogue(runner);
+ } else if (runner->phase == GBB_TEST_PHASE_EPILOGUE) {
+ runner_set_stopped(runner);
+ }
+}
+
+static void
+on_power_monitor_changed(GbbPowerMonitor *monitor,
+ GbbTestRunner *runner)
+{
+ const GbbPowerState *current_state = gbb_power_monitor_get_state(monitor);
+
+ if (runner->phase == GBB_TEST_PHASE_WAITING) {
+ if (!current_state->online) {
+ gbb_test_run_set_start_time(runner->run, time(NULL));
+ gbb_test_run_add(runner->run, current_state);
+ runner_set_phase(runner, GBB_TEST_PHASE_RUNNING);
+ gbb_event_player_play_file(runner->player, runner->test->loop_file);
+ }
+ } else if (runner->phase == GBB_TEST_PHASE_RUNNING) {
+ gbb_test_run_add(runner->run, current_state);
+ }
+}
+
+static void
+gbb_test_runner_finalize(GObject *object)
+{
+ GbbTestRunner *runner = GBB_TEST_RUNNER(object);
+
+ g_clear_object(&runner->run);
+
+ G_OBJECT_CLASS(gbb_test_runner_parent_class)->finalize(object);
+}
+
+static void
+gbb_test_runner_init(GbbTestRunner *runner)
+{
+ runner->monitor = gbb_power_monitor_new();
+ g_signal_connect(runner->monitor, "changed",
+ G_CALLBACK(on_power_monitor_changed),
+ runner);
+
+ runner->system_state = gbb_system_state_new();
+
+ runner->player = GBB_EVENT_PLAYER(gbb_remote_player_new("GNOME Battery Bench"));
+ g_signal_connect(runner->player, "finished",
+ G_CALLBACK(on_player_finished), runner);
+}
+
+static void
+gbb_test_runner_class_init(GbbTestRunnerClass *run_class)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (run_class);
+
+ gobject_class->finalize = gbb_test_runner_finalize;
+
+ signals[PHASE_CHANGED] =
+ g_signal_new ("phase-changed",
+ GBB_TYPE_TEST_RUNNER,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
+}
+
+GbbTestRunner *
+gbb_test_runner_new(void)
+{
+ GbbTestRunner *runner = g_object_new(GBB_TYPE_TEST_RUNNER, NULL);
+
+ return runner;
+}
+
+GbbPowerMonitor *
+gbb_test_runner_get_power_monitor(GbbTestRunner *runner)
+{
+ return runner->monitor;
+}
+
+GbbEventPlayer *
+gbb_test_runner_get_event_player(GbbTestRunner *runner)
+{
+ return runner->player;
+}
+
+GbbTestPhase
+gbb_test_runner_get_phase(GbbTestRunner *runner)
+{
+ return runner->phase;
+}
+
+gboolean
+gbb_test_runner_get_stop_requested(GbbTestRunner *runner)
+{
+ return runner->stop_requested;
+}
+
+void
+gbb_test_runner_set_run(GbbTestRunner *runner,
+ GbbTestRun *run)
+{
+ g_return_if_fail(runner->phase == GBB_TEST_PHASE_STOPPED);
+
+ g_clear_object(&runner->run);
+
+ runner->run = g_object_ref(run);
+ runner->test = gbb_test_run_get_test(run);
+}
+
+void
+gbb_test_runner_start(GbbTestRunner *runner)
+{
+ g_return_if_fail(runner->phase == GBB_TEST_PHASE_STOPPED);
+ g_return_if_fail(runner->run != NULL);
+
+ gbb_system_state_save(runner->system_state);
+ gbb_system_state_set_brightnesses(runner->system_state,
+ gbb_test_run_get_screen_brightness(runner->run),
+ 0);
+
+ if (runner->test->prologue_file) {
+ gbb_event_player_play_file(runner->player, runner->test->prologue_file);
+ runner_set_phase(runner, GBB_TEST_PHASE_PROLOGUE);
+ } else {
+ runner_set_phase(runner, GBB_TEST_PHASE_WAITING);
+ }
+}
+
+void
+gbb_test_runner_stop(GbbTestRunner *runner)
+{
+ if ((runner->phase == GBB_TEST_PHASE_WAITING || runner->phase == GBB_TEST_PHASE_RUNNING)) {
+ if (runner->phase == GBB_TEST_PHASE_RUNNING) {
+ gbb_event_player_stop(runner->player);
+ runner_set_phase(runner, GBB_TEST_PHASE_STOPPING);
+ } else {
+ runner_set_epilogue(runner);
+ }
+ } else if (runner->phase == GBB_TEST_PHASE_PROLOGUE) {
+ runner->stop_requested = TRUE;
+ }
+}
diff --git a/src/test-runner.h b/src/test-runner.h
new file mode 100644
index 0000000..f36ace3
--- /dev/null
+++ b/src/test-runner.h
@@ -0,0 +1,46 @@
+/* -*- mode: C; c-file-style: "stroustrup"; indent-tabs-mode: nil; -*- */
+
+#ifndef __TEST_RUNNER_H__
+#define __TEST_RUNNER_H__
+
+#include "event-player.h"
+#include "power-monitor.h"
+#include "test-run.h"
+
+typedef struct _GbbTestRunner GbbTestRunner;
+typedef struct _GbbTestRunnerClass GbbTestRunnerClass;
+
+#define GBB_TYPE_TEST_RUNNER (gbb_test_runner_get_type ())
+#define GBB_TEST_RUNNER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GBB_TYPE_TEST_RUNNER, GbbTestRunner))
+#define GBB_TEST_RUNNER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GBB_TYPE_TEST_RUNNER, GbbTestRunnerClass))
+#define GBB_IS_TEST_RUNNER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GBB_TYPE_TEST_RUNNER))
+#define GBB_IS_TEST_RUNNER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GBB_TYPE_TEST_RUNNER))
+#define GBB_TEST_RUNNER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GBB_TYPE_TEST_RUNNER,
GbbTestRunnerClass))
+
+typedef enum {
+ GBB_TEST_PHASE_STOPPED,
+ GBB_TEST_PHASE_PROLOGUE,
+ GBB_TEST_PHASE_WAITING,
+ GBB_TEST_PHASE_RUNNING,
+ GBB_TEST_PHASE_STOPPING,
+ GBB_TEST_PHASE_EPILOGUE
+} GbbTestPhase;
+
+GType gbb_test_runner_get_type(void);
+
+GbbTestRunner *gbb_test_runner_new(void);
+
+GbbPowerMonitor *gbb_test_runner_get_power_monitor(GbbTestRunner *runner);
+GbbEventPlayer *gbb_test_runner_get_event_player (GbbTestRunner *runner);
+
+GbbTestPhase gbb_test_runner_get_phase (GbbTestRunner *runner);
+gboolean gbb_test_runner_get_stop_requested(GbbTestRunner *runner);
+
+void gbb_test_runner_set_run(GbbTestRunner *runner,
+ GbbTestRun *run);
+
+void gbb_test_runner_start(GbbTestRunner *runner);
+void gbb_test_runner_stop (GbbTestRunner *runner);
+
+#endif /* __TEST_RUNNER_H__ */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]