Modified Svace Issue about g_main_loop flow. 70/122470/4 accepted/tizen/3.0/common/20170404.140938 accepted/tizen/3.0/mobile/20170404.084647 accepted/tizen/3.0/tv/20170404.084703 accepted/tizen/3.0/wearable/20170404.084710 submit/tizen_3.0/20170403.114709
authorSegwon <segwon.han@samsung.com>
Fri, 31 Mar 2017 12:30:30 +0000 (21:30 +0900)
committerSegwon <segwon.han@samsung.com>
Mon, 3 Apr 2017 11:29:14 +0000 (20:29 +0900)
Signed-off-by: Segwon <segwon.han@samsung.com>
Change-Id: I86e57e7b07fc6d54b0033df0b93e1a08980f180a

daemon/Server.cpp

index 9bdec13fa1b115f97879eb98667ef6ec0bd0b887..9bb97f84ce43342e92e5f6ddf982cfa62bb0a159 100644 (file)
@@ -31,7 +31,6 @@
 using namespace std;
 
 static GMainLoop *mainLoop = NULL;
-static gboolean started = FALSE;
 static conv::DbusServer *dbusHandle = NULL;
 static conv::DiscoveryManager *discoveryMgr = NULL;
 static conv::ConnectionManager *connectionMgr = NULL;
@@ -43,13 +42,6 @@ void conv::initialize()
 {
        int result;
 
-       if (started) {
-               _D("flowd is started already");
-               return;
-       }
-
-       mainLoop = g_main_loop_new(NULL, FALSE);
-
        _I("Init Discovery Manager");
        discoveryMgr = new(std::nothrow) conv::DiscoveryManager();
        IF_FAIL_CATCH_TAG(discoveryMgr, _E, "Memory allocation failed");
@@ -91,19 +83,13 @@ void conv::initialize()
        result = dbusHandle->init();
        IF_FAIL_CATCH_TAG(result == true, _E, "Initialization Failed");
 
-       _I("Start main loop");
-       started = TRUE;
+       mainLoop = g_main_loop_new(NULL, FALSE);
 
+       _I("Start main loop");
        g_main_loop_run(mainLoop);
 
-       return;
-
 CATCH:
-       _E(RED("Launching Failed"));
-       if (mainLoop) {
-               g_main_loop_quit(mainLoop);
-               mainLoop = NULL;
-       }
+       return;
 }
 
 void conv::release()
@@ -133,7 +119,9 @@ void conv::release()
        if (requestMgr)
                requestMgr->release();
 
-       g_main_loop_unref(mainLoop);
+       if (mainLoop) {
+               g_main_loop_unref(mainLoop);
+       }
 
        delete discoveryMgr;
        delete connectionMgr;
@@ -141,10 +129,8 @@ void conv::release()
        delete clientMgr;
        delete requestMgr;
        delete serviceMgr;
-       started = FALSE;
 }
 
-
 void conv::sendRequest(Request* requestObj)
 {
        _D("send_request requestObj:%x request_mg:%x", requestObj, requestMgr);
@@ -161,10 +147,12 @@ static void signal_handler(int signo)
 {
        _I("SIGNAL %d received", signo);
 
+       if (mainLoop == NULL)
+               return;
+
        // Stop the main loop
-       if (mainLoop) {
+       if (g_main_loop_is_running(mainLoop)) {
                g_main_loop_quit(mainLoop);
-               mainLoop = NULL;
        }
 }
 
@@ -187,5 +175,7 @@ int main(int argc, char **argv)
        conv::initialize();
        conv::release();
 
+       _I(RED("Quit main loop"));
+
        return EXIT_SUCCESS;
 }