diff options
author | Thomas Haller <thaller@redhat.com> | 2015-12-21 14:16:35 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-12-25 20:36:43 +0100 |
commit | 766f31507b02c4721bdbabdc79755ff23652d6c6 (patch) | |
tree | 64c2d2bdf326d11770481a623cdcaea90fbdff22 /shared | |
parent | c7d4d67d535d4db9c853b04b6ead34d6b1428a88 (diff) | |
download | NetworkManager-766f31507b02c4721bdbabdc79755ff23652d6c6.tar.gz |
nmtst: add nmtst_main_loop_run()
Diffstat (limited to 'shared')
-rw-r--r-- | shared/nm-test-utils.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/shared/nm-test-utils.h b/shared/nm-test-utils.h index 28ae56fee7..27a8d16422 100644 --- a/shared/nm-test-utils.h +++ b/shared/nm-test-utils.h @@ -733,6 +733,45 @@ nmtst_rand_perm (GRand *rand, void *dst, const void *src, gsize elmt_size, gsize return dst; } +/*****************************************************************************/ + +inline static gboolean +_nmtst_main_loop_run_timeout (gpointer user_data) +{ + GMainLoop **p_loop = user_data; + + g_assert (p_loop); + g_assert (*p_loop); + + g_main_loop_quit (*p_loop); + *p_loop = NULL; + + return G_SOURCE_REMOVE; +} + +inline static gboolean +nmtst_main_loop_run (GMainLoop *loop, int timeout_ms) +{ + GSource *source = NULL; + guint id = 0; + GMainLoop *loopx = loop; + + if (timeout_ms > 0) { + source = g_timeout_source_new (timeout_ms); + g_source_set_callback (source, _nmtst_main_loop_run_timeout, &loopx, NULL); + id = g_source_attach (source, g_main_loop_get_context (loop)); + g_assert (id); + g_source_unref (source); + } + + g_main_loop_run (loop); + + /* if the timeout was reached, return FALSE. */ + return loopx != NULL; +} + +/*****************************************************************************/ + inline static const char * nmtst_get_sudo_cmd (void) { |