Move websocket server starting code from init() to run() 21/230521/2
authorJi-hoon Lee <dalton.lee@samsung.com>
Fri, 10 Apr 2020 08:16:43 +0000 (17:16 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Fri, 10 Apr 2020 08:20:11 +0000 (08:20 +0000)
Since the run() method would not be called under
.NET environment, this will help avoid executing
unnecessary service in certain situations.

Change-Id: Iff27f0b7cf591fd3e358ea8c063b43adca7e91b0

src/legacy_support/web_helper_agent.h
src/legacy_support/websocket.cpp
src/legacy_support/websocket.h
src/sclcoreui-efl.cpp

index 408c9d3..c05c572 100644 (file)
@@ -72,6 +72,7 @@ public:
     virtual bool init();
     virtual bool exit();
 
+    virtual bool run() { return false; }
     virtual void signal(int sig);
 
     virtual void on_init() {}
@@ -125,4 +126,4 @@ public:
     static void destroy_web_helper_agent(CWebHelperAgent* agent);
 };
 
-#endif // _WEB_HELPER_AGENT_H_
\ No newline at end of file
+#endif // _WEB_HELPER_AGENT_H_
index 50e24e1..b3ae539 100644 (file)
@@ -213,7 +213,7 @@ static Eina_Bool flush_server_recv_buffer_func(void *user)
            */
         pss->valid = true;
 
-        if (agent->initalized()) {
+        if (agent->initialized()) {
             pss->need_init = true;
             ecore_pipe_write(agent->get_message_pipe(), MESSAGE_LEFT, strlen(MESSAGE_LEFT));
         }
@@ -472,22 +472,8 @@ bool CWebHelperAgentWebSocket::init()
     pthread_mutex_init(&g_ws_query_mutex, NULL);
     pthread_cond_init(&g_ws_query_condition, NULL);
 
-    if (g_ws_server_context) {
-        if (pthread_create(&g_ws_server_thread, NULL, &process_ws_server, NULL) != 0) {
-            g_ws_server_thread = (pthread_t)NULL;
-            ret = false;
-        }
-    } else {
-        LOGE("Failed creating server context : %p", g_ws_server_context);
-        ret = false;
-    }
-
-    on_init();
-
     m_initialized = true;
 
-    test_client_connection();
-
     return ret;
 }
 
@@ -528,6 +514,30 @@ bool CWebHelperAgentWebSocket::exit()
     return true;
 }
 
+bool CWebHelperAgentWebSocket::run()
+{
+    if (!m_initialized) {
+        LOGE("Not initialized");
+        return false;
+    }
+
+    bool ret = false;
+    if (g_ws_server_context) {
+        if (pthread_create(&g_ws_server_thread, NULL, &process_ws_server, NULL) != 0) {
+            g_ws_server_thread = (pthread_t)NULL;
+            ret = false;
+
+            on_init();
+
+            test_client_connection();
+        }
+    } else {
+        LOGE("Failed creating server context : %p", g_ws_server_context);
+        ret = false;
+    }
+    return ret;
+}
+
 void CWebHelperAgentWebSocket::signal(int sig)
 {
     force_exit = 1;
index 8693608..0be56b4 100644 (file)
@@ -231,7 +231,9 @@ public:
     bool init();
     bool exit();
 
-    bool initalized() { return m_initialized; }
+    bool run();
+
+    bool initialized() { return m_initialized; }
 
     void signal(int sig);
 
index 81d0ef1..d6da8dd 100644 (file)
@@ -607,6 +607,12 @@ void CSCLCoreUIEFL::run(const sclchar *display)
 
     LOGD("name : %s\n", appid);
 
+#ifdef WEBSOCKET
+    if (g_websocket.initialized()) {
+        g_websocket.run();
+    }
+#endif
+
     appcore_efl_main(appid, &argc, (char ***)&argv, &ops);
 
     delete [] argv;