--- /dev/null
+#ifdef GLIB_ENABLED
+
+#include <murphy/common/glib-glue.h>
+
+struct glib_config_s {
+ GMainLoop *gml;
+};
+
+
+mrp_mainloop_t *glib_mainloop_create(test_config_t *cfg)
+{
+ glib_config_t *glib;
+ mrp_mainloop_t *ml;
+
+ glib = mrp_allocz(sizeof(*glib));
+
+ if (glib != NULL) {
+ glib->gml = g_main_loop_new(NULL, FALSE);
+ ml = mrp_mainloop_glib_get(glib->gml);
+
+ if (ml != NULL) {
+ cfg->glib = glib;
+ cfg->ml = ml;
+
+ return ml;
+ }
+ else {
+ g_main_loop_unref(glib->gml);
+ mrp_free(glib);
+ }
+ }
+
+ return NULL;
+}
+
+
+int glib_mainloop_run(test_config_t *cfg)
+{
+ if (cfg->glib != NULL) {
+ g_main_loop_run(cfg->glib->gml);
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+
+int glib_mainloop_quit(test_config_t *cfg)
+{
+ if (cfg->glib != NULL) {
+ g_main_loop_quit(cfg->glib->gml);
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+
+int glib_mainloop_cleanup(test_config_t *cfg)
+{
+ if (cfg->glib != NULL) {
+ mrp_mainloop_unregister(cfg->ml);
+ mrp_mainloop_destroy(cfg->ml);
+ cfg->ml = NULL;
+
+ g_main_loop_unref(cfg->glib->gml);
+ mrp_free(cfg->glib);
+ cfg->glib = NULL;
+
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+
+#else
+
+
+mrp_mainloop_t *glib_mainloop_create(test_config_t *cfg)
+{
+ MRP_UNUSED(cfg);
+
+ mrp_log_error("glib mainloop support is not available.");
+ exit(1);
+}
+
+
+int glib_mainloop_run(test_config_t *cfg)
+{
+ MRP_UNUSED(cfg);
+
+ mrp_log_error("glib mainloop support is not available.");
+ exit(1);
+}
+
+
+int glib_mainloop_quit(test_config_t *cfg)
+{
+ MRP_UNUSED(cfg);
+
+ mrp_log_error("glib mainloop support is not available.");
+ exit(1);
+}
+
+
+int glib_mainloop_cleanup(test_config_t *cfg)
+{
+ MRP_UNUSED(cfg);
+
+ mrp_log_error("glib mainloop support is not available.");
+ exit(1);
+}
+
+
+#endif
--- /dev/null
+#ifdef PULSE_ENABLED
+
+#include <murphy/common/pulse-glue.h>
+
+struct pulse_config_s {
+ pa_mainloop *pa_main;
+ pa_mainloop_api *pa;
+};
+
+
+mrp_mainloop_t *pulse_mainloop_create(test_config_t *cfg)
+{
+ pulse_config_t *pulse;
+ mrp_mainloop_t *ml;
+
+ pulse = mrp_allocz(sizeof(*pulse));
+
+ if (pulse != NULL) {
+ pulse->pa_main = pa_mainloop_new();
+ pulse->pa = pa_mainloop_get_api(pulse->pa_main);
+ ml = mrp_mainloop_pulse_get(pulse->pa);
+
+ if (ml != NULL) {
+ cfg->pulse = pulse;
+ cfg->ml = ml;
+
+ return ml;
+ }
+ else {
+ pa_mainloop_free(pulse->pa_main);
+ mrp_free(pulse);
+ }
+ }
+
+ return NULL;
+}
+
+
+int pulse_mainloop_run(test_config_t *cfg)
+{
+ int retval;
+
+ if (cfg->pulse && cfg->pulse->pa != NULL) {
+ pa_mainloop_run(cfg->pulse->pa_main, &retval);
+
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+
+int pulse_mainloop_quit(test_config_t *cfg)
+{
+ if (cfg->pulse && cfg->pulse->pa) {
+ pa_mainloop_quit(cfg->pulse->pa_main, 0);
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+
+int pulse_mainloop_cleanup(test_config_t *cfg)
+{
+ if (cfg->pulse != NULL) {
+ mrp_mainloop_unregister(cfg->ml);
+ mrp_mainloop_destroy(cfg->ml);
+ cfg->ml = NULL;
+
+ pa_mainloop_free(cfg->pulse->pa_main);
+ mrp_free(cfg->pulse);
+ cfg->pulse = NULL;
+
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+
+#else
+
+
+mrp_mainloop_t *pulse_mainloop_create(test_config_t *cfg)
+{
+ mrp_log_error("PulseAudio mainloop support is not available.");
+ exit(1);
+}
+
+
+int pulse_mainloop_run(test_config_t *cfg)
+{
+ mrp_log_error("PulseAudio mainloop support is not available.");
+ exit(1);
+}
+
+
+int pulse_mainloop_quit(test_config_t *cfg)
+{
+ mrp_log_error("PulseAudio mainloop support is not available.");
+ exit(1);
+}
+
+
+int pulse_mainloop_cleanup(test_config_t *cfg)
+{
+ mrp_log_error("PulseAudio mainloop support is not available.");
+ exit(1);
+}
+
+
+#endif
#include <murphy/config.h>
#include <murphy/common/macros.h>
+#include <murphy/common/log.h>
#include <murphy/common/mm.h>
#include <murphy/common/mainloop.h>
#define DEFAULT_RUNTIME 30 /* run for 30 seconds */
+enum {
+ MAINLOOP_NATIVE,
+ MAINLOOP_PULSE,
+ MAINLOOP_ECORE,
+ MAINLOOP_GLIB
+};
+
+
+struct pulse_config_s;
+typedef struct pulse_config_s pulse_config_t;
+
+struct ecore_config_s;
+typedef struct ecore_config_s ecore_config_t;
+
+struct glib_config_s;
+typedef struct glib_config_s glib_config_t;
+
+
typedef struct {
int nio;
int log_mask;
const char *log_target;
-#ifdef PULSE_ENABLED
- pa_mainloop *pa_main;
- pa_mainloop_api *pa;
-#endif
-#ifdef ECORE_ENABLED
- int ecore;
-#endif
+ int mainloop_type;
+ mrp_mainloop_t *ml;
+ pulse_config_t *pulse;
+ ecore_config_t *ecore;
+ glib_config_t *glib;
int nrunning;
int runtime;
} test_config_t;
+#include "mainloop-pulse-test.c"
+#include "mainloop-ecore-test.c"
+#include "mainloop-glib-test.c"
+
+
static test_config_t cfg;
+static mrp_mainloop_t *mainloop_create(test_config_t *cfg);
+static void mainloop_run(test_config_t *cfg);
+static void mainloop_quit(test_config_t *cfg);
+static void mainloop_cleanup(test_config_t *cfg);
+
/*
* native timers
if (cfg.nrunning <= 0) {
mrp_del_timer(timer);
-#ifdef PULSE_ENABLED
- if (cfg.pa_main != NULL)
- pa_mainloop_quit(cfg.pa_main, 0);
- else
-#endif
-#ifdef ECORE_ENABLED
- if (cfg.ecore)
- ecore_main_loop_quit();
- else
-#endif
- mrp_mainloop_quit(ml, 0);
+ mainloop_quit(&cfg);
}
}
/*
- * DBUS tests
+ * DBUS tests (quite a mess the whole shebang...)
*/
#define DBUS_PATH "/"
if ((ml = dbus_test.ml = mrp_mainloop_create()) == NULL)
fatal("failed to create mainloop");
+ cfg.ml = ml;
+
if ((conn = dbus_test.conn = connect_to_dbus(NULL)) == NULL)
fatal("failed to connect to DBUS");
#ifdef ECORE_ENABLED
" -e, --ecore use ecore mainloop\n"
#endif
+#ifdef GLIB_ENABLED
+ " -g, --glib use glib mainloop\n"
+#endif
" -h, --help show help on usage\n",
argv0);
#else
# define ECORE_OPTION ""
#endif
+#ifdef GLIB_ENABLED
+# define GLIB_OPTION "g"
+#else
+# define GLIB_OPTION ""
+#endif
-# define OPTIONS "r:i:t:s:I:T:S:M:l:o:vdh"PULSE_OPTION""ECORE_OPTION
+# define OPTIONS "r:i:t:s:I:T:S:M:l:o:vdh" \
+ PULSE_OPTION""ECORE_OPTION""GLIB_OPTION
struct option options[] = {
{ "runtime" , required_argument, NULL, 'r' },
{ "ios" , required_argument, NULL, 'i' },
{ "dbus-signals", required_argument, NULL, 'S' },
{ "dbus-methods", required_argument, NULL, 'M' },
#ifdef PULSE_ENABLED
- { "pulse-main" , no_argument , NULL, 'p' },
+ { "pulse" , no_argument , NULL, 'p' },
#endif
#ifdef ECORE_ENABLED
- { "ecore-main" , no_argument , NULL, 'e' },
+ { "ecore" , no_argument , NULL, 'e' },
+#endif
+#ifdef GLIB_ENABLED
+ { "glib" , no_argument , NULL, 'g' },
#endif
{ "log-level" , required_argument, NULL, 'l' },
{ "log-target" , required_argument, NULL, 'o' },
#ifdef PULSE_ENABLED
case 'p':
- cfg->pa_main = pa_mainloop_new();
- if (cfg->pa_main == NULL) {
- mrp_log_error("Failed to create PulseAudio mainloop.");
- exit(1);
- }
- cfg->pa = pa_mainloop_get_api(cfg->pa_main);
+ cfg->mainloop_type = MAINLOOP_PULSE;
break;
#endif
#ifdef ECORE_ENABLED
case 'e':
- cfg->ecore = TRUE;
+ cfg->mainloop_type = MAINLOOP_ECORE;
+ break;
+#endif
+
+#ifdef GLIB_ENABLED
+ case 'g':
+ cfg->mainloop_type = MAINLOOP_GLIB;
break;
#endif
}
-mrp_mainloop_t *mainloop_create(void)
+static mrp_mainloop_t *mainloop_create(test_config_t *cfg)
{
- mrp_mainloop_t *ml;
+ switch (cfg->mainloop_type) {
+ case MAINLOOP_NATIVE:
+ cfg->ml = mrp_mainloop_create();
+ break;
-#ifdef PULSE_ENABLED
- if (cfg.pa != NULL)
- ml = mrp_mainloop_pulse_get(cfg.pa);
- else
-#endif
-#ifdef ECORE_ENABLED
- if (cfg.ecore)
- ml = mrp_mainloop_ecore_get();
- else
-#endif
- ml = mrp_mainloop_create();
+ case MAINLOOP_PULSE:
+ pulse_mainloop_create(cfg);
+ break;
+
+ case MAINLOOP_ECORE:
+ ecore_mainloop_create(cfg);
+ break;
+
+ case MAINLOOP_GLIB:
+ glib_mainloop_create(cfg);
+ break;
+
+ default:
+ mrp_log_error("Invalid mainloop type 0x%x.", cfg->mainloop_type);
+ exit(1);
+ }
- return ml;
+ if (cfg->ml == NULL) {
+ mrp_log_error("Failed to create mainloop.");
+ exit(1);
+ }
+
+ return cfg->ml;
}
-void mainloop_run(mrp_mainloop_t *ml)
+static void mainloop_run(test_config_t *cfg)
{
-#ifdef PULSE_ENABLED
- if (cfg.pa != NULL) {
- int retval;
+ switch (cfg->mainloop_type) {
+ case MAINLOOP_NATIVE:
+ mrp_mainloop_run(cfg->ml);
+ break;
+
+ case MAINLOOP_PULSE:
+ pulse_mainloop_run(cfg);
+ break;
- pa_mainloop_run(cfg.pa_main, &retval);
- mrp_log_info("PulseAudio mainloop exited with status %d.", retval);
+ case MAINLOOP_ECORE:
+ ecore_mainloop_run(cfg);
+ break;
+
+ case MAINLOOP_GLIB:
+ glib_mainloop_run(cfg);
+ break;
+
+ default:
+ mrp_log_error("Invalid mainloop type 0x%x.", cfg->mainloop_type);
+ exit(1);
}
- else
-#endif
-#ifdef ECORE_ENABLED
- if (cfg.ecore) {
- ecore_main_loop_begin();
- mrp_log_info("EFL/ecore mainloop exited.");
- }
- else
-#endif
- mrp_mainloop_run(ml);
}
-void mainloop_cleanup(mrp_mainloop_t *ml)
+static void mainloop_quit(test_config_t *cfg)
{
-#ifdef PULSE_ENABLED
- if (cfg.pa) {
- mrp_mainloop_unregister(ml);
- pa_mainloop_free(cfg.pa_main);
+ switch (cfg->mainloop_type) {
+ case MAINLOOP_NATIVE:
+ mrp_mainloop_quit(cfg->ml, 0);
+ break;
+
+ case MAINLOOP_PULSE:
+ pulse_mainloop_quit(cfg);
+ break;
+
+ case MAINLOOP_ECORE:
+ ecore_mainloop_quit(cfg);
+ break;
+
+ case MAINLOOP_GLIB:
+ glib_mainloop_quit(cfg);
+ break;
+
+ default:
+ mrp_log_error("Invalid mainloop type 0x%x.", cfg->mainloop_type);
+ exit(1);
}
- else
-#endif
-#ifdef ECORE_ENABLED
- if (cfg.ecore)
- mrp_mainloop_unregister(ml);
-#endif
+}
- mrp_mainloop_destroy(ml);
+
+void mainloop_cleanup(test_config_t *cfg)
+{
+ switch (cfg->mainloop_type) {
+ case MAINLOOP_NATIVE:
+ break;
+
+ case MAINLOOP_PULSE:
+ pulse_mainloop_cleanup(cfg);
+ break;
+
+ case MAINLOOP_ECORE:
+ ecore_mainloop_cleanup(cfg);
+ break;
+
+ case MAINLOOP_GLIB:
+ glib_mainloop_cleanup(cfg);
+ break;
+
+ default:
+ mrp_log_error("Unknown mainloop type (0x%x).", cfg->mainloop_type);
+ exit(1);
+ }
}
mrp_log_set_mask(cfg.log_mask);
mrp_log_set_target(cfg.log_target);
- if ((ml = mainloop_create()) == NULL)
+ ml = mainloop_create(&cfg);
+
+ if (ml == NULL)
fatal("failed to create main loop.");
setup_timers(ml);
if (mrp_add_timer(ml, 1000, check_quit, NULL) == NULL)
fatal("failed to create quit-check timer");
- mainloop_run(ml);
+ mainloop_run(&cfg);
check_io();
check_timers();
if (cfg.ngio > 0 || cfg.ngtimer > 0)
glib_pump_cleanup();
- mainloop_cleanup(ml);
+ mainloop_cleanup(&cfg);
}