Fix gmainloop to run in main context. 92/169092/1
authorseolheui kim <s414.kim@samsung.com>
Fri, 2 Feb 2018 06:38:10 +0000 (15:38 +0900)
committerseolheui kim <s414.kim@samsung.com>
Fri, 2 Feb 2018 06:38:10 +0000 (15:38 +0900)
To receive dbus signals subscribed in main context, replace gmainloop.

Change-Id: I05c08b61ae4165fcbd1a298d26d047af87631b11
Signed-off-by: seolheui kim <s414.kim@samsung.com>
server/main.cpp

index 1a85a3c..04b9a88 100644 (file)
@@ -34,6 +34,29 @@ void signalHandler(int signum)
        exit(0);
 }
 
+class ODEGMainLoop {
+public:
+       ODEGMainLoop() :
+               mainloop(g_main_loop_new(NULL, FALSE), g_main_loop_unref)
+       {
+               handle = std::thread(g_main_loop_run, mainloop.get());
+       }
+
+       ~ODEGMainLoop()
+       {
+               while (!g_main_loop_is_running(mainloop.get())) {
+                       std::this_thread::yield();
+               }
+
+               g_main_loop_quit(mainloop.get());
+               handle.join();
+       }
+
+private:
+       std::unique_ptr<GMainLoop, void(*)(GMainLoop*)> mainloop;
+       std::thread handle;
+};
+
 int main(int argc, char *argv[])
 {
        ::signal(SIGINT, signalHandler);
@@ -41,7 +64,7 @@ int main(int argc, char *argv[])
        ::umask(0);
 
        try {
-               ScopedGMainLoop gmainloop;
+               ODEGMainLoop gmainloop;
                ode::ServerContext server;
                server.start();
        } catch (std::exception &e) {