From ab62d9697b98faf1ef955df03a939014ab50902b Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 25 Oct 2016 20:44:24 +0900 Subject: [PATCH] Rearrange launch order to safely control the case that the DB file is not accessible Change-Id: I7832bcf2455c2129cd1a06925bf730eae8f1759b Signed-off-by: Mu-Woong Lee --- src/Server.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Server.cpp b/src/Server.cpp index 8c2afe9..34d4fe2 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -20,12 +20,16 @@ #include #include +#include #include "DBusServer.h" #include "ContextManager.h" #include "policy/PolicyManager.h" #include "trigger/Trigger.h" #include "Server.h" +#define RUN(L) g_main_loop_run((L)) +#define QUIT(L) if (g_main_loop_is_running((L)) == TRUE) g_main_loop_quit((L)) + static GMainLoop *mainloop = NULL; static bool started = false; @@ -38,9 +42,6 @@ static ctx::trigger::Trigger *__contextTrigger = NULL; /* TODO: re-organize activation & deactivation processes */ void ctx::Server::initialize() { - _I("Init MainLoop"); - mainloop = g_main_loop_new(NULL, FALSE); - _I("Init Dbus Connection"); __dbusHandle = new(std::nothrow) ctx::DBusServer(); IF_FAIL_VOID_TAG(__dbusHandle, _E, "Memory allocation failed"); @@ -48,7 +49,7 @@ void ctx::Server::initialize() // Start the main loop _I(CYAN("Launching Context-Service")); - g_main_loop_run(mainloop); + RUN(mainloop); } void ctx::Server::activate() @@ -57,6 +58,9 @@ void ctx::Server::activate() bool result = false; + _I("Init Database Manager"); + IF_FAIL_CATCH(DatabaseManager::__init()); + _I("Init Context Manager"); __contextMgr = new(std::nothrow) ctx::ContextManager(); IF_FAIL_CATCH_TAG(__contextMgr, _E, "Memory allocation failed"); @@ -81,12 +85,13 @@ CATCH: _E(RED("Launching Failed")); // Stop the main loop - g_main_loop_quit(mainloop); + QUIT(mainloop); } void ctx::Server::release() { _I(CYAN("Terminating Context-Service")); + started = false; _I("Release Policy Manager"); delete __policyMgr; @@ -99,11 +104,8 @@ void ctx::Server::release() if (__contextMgr) __contextMgr->release(); - _I("Release Dbus Connection"); - if (__dbusHandle) - __dbusHandle->__release(); - - g_main_loop_unref(mainloop); + _I("Release Database Manager"); + DatabaseManager::__release(); delete __contextTrigger; delete __contextMgr; @@ -135,7 +137,7 @@ static void __signalHandler(int signo) _I("SIGNAL %d received", signo); // Stop the main loop - g_main_loop_quit(mainloop); + QUIT(mainloop); } int main(int argc, char* argv[]) @@ -154,8 +156,13 @@ int main(int argc, char* argv[]) g_type_init(); #endif + _I("Init MainLoop"); + mainloop = g_main_loop_new(NULL, FALSE); + ctx::Server::initialize(); ctx::Server::release(); + g_main_loop_unref(mainloop); + return EXIT_SUCCESS; } -- 2.7.4