2
* Copyright (C) 2016 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include <mcs/keep_alive.h>
20
#include "glibhelpers.h"
25
void RunMainLoop(const std::chrono::seconds &seconds) {
26
std::shared_ptr<GMainLoop> loop(g_main_loop_new(g_main_context_default(), false), &g_main_loop_unref);
27
g_timeout_add_seconds(seconds.count(), [](gpointer user_data) {
28
auto loop = static_cast<mcs::SharedKeepAlive<GMainLoop>*>(user_data)->ShouldDie();
29
g_main_loop_quit(loop.get());
31
}, new mcs::SharedKeepAlive<GMainLoop>{loop});
32
g_main_loop_run(loop.get());
35
void RunMainLoopIteration() {
36
std::shared_ptr<GMainLoop> loop(g_main_loop_new(g_main_context_default(), false), &g_main_loop_unref);
37
auto context = g_main_loop_get_context(loop.get());
38
g_main_context_iteration(context, TRUE);
42
} // namespace testing