Refactor recv_thread 89/162389/1
authorAlexander Aksenov <a.aksenov@samsung.com>
Wed, 4 Oct 2017 19:20:31 +0000 (22:20 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 30 Nov 2017 09:45:19 +0000 (12:45 +0300)
Change-Id: I2159b02c311e9d07dd17a6cb48318d38b7fc9ce4
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
helper/libdaprobe.c

index 602b995..c99cdf9 100755 (executable)
@@ -315,6 +315,50 @@ pid_t _gettid()
        return gTid;
 }
 
+
+/* 0 - continue reading, 1 - break */
+static int msg_handler(log_t *log)
+{
+       if (log->type == APP_MSG_CAPTURE_SCREEN) {
+               capture_screen_call();
+       } else if (log->type == APP_MSG_CONFIG) {
+               _configure((char *)log->data);
+       } else if (log->type == APP_MSG_TARGET_BINS) {
+               _process_target_bins((char *)log->data, log->length);
+       } else if (log->type == APP_MSG_STOP) {
+               /* Do leaks check if LSan is enabled. */
+               lsan_do_leak_check();
+
+               /* Send acknowlege message to manager */
+               printLog(log, APP_MSG_STOP);
+               application_exit();
+
+               return 1;
+       } else if (log->type == APP_MSG_STOP_WITHOUT_KILL) {
+               /* Do leaks check if LSan is enabled. */
+               lsan_do_leak_check();
+
+               /* Send acknowlege message to manager */
+               printLog(log, APP_MSG_STOP);
+               _uninit_();
+
+               return 1;
+       } else if (log->type == APP_MSG_GET_UI_HIERARCHY) {
+               PRINTMSG("APP_MSG_GET_UI_HIERARCHY");
+               /* do nothing */
+       } else if (log->type == APP_MSG_GET_UI_SCREENSHOT) {
+               PRINTMSG("APP_MSG_GET_UI_SCREENSHOT");
+               /* do nothing */
+       } else if (log->type == APP_MSG_GET_UI_HIERARCHY_CANCEL) {
+               PRINTMSG("APP_MSG_GET_UI_HIERARCHY_CANCEL");
+               /* do nothing */
+       } else {
+               PRINTERR("recv unknown message. id = (%d)", log->type);
+       }
+
+       return 0;
+}
+
 static void *recv_thread(void __unused * data)
 {
        fd_set readfds, workfds;
@@ -360,8 +404,6 @@ static void *recv_thread(void __unused * data)
                        continue;
                } else if (FD_ISSET(gTraceInfo.socket.daemonSock, &workfds)) {
                        int ret;
-                       const char *data_buf;
-                       size_t data_size;
 
                        ret = read_log(gTraceInfo.socket.daemonSock, &log);
                        if (ret) {
@@ -371,45 +413,9 @@ static void *recv_thread(void __unused * data)
                                return NULL;
                        }
 
-                       data_buf = log.data;
-                       data_size = log.length;
-                       if (log.type == APP_MSG_CAPTURE_SCREEN) {
-                               capture_screen_call();
-                       } else if (log.type == APP_MSG_CONFIG) {
-                               _configure((char *)data_buf);
-                       } else if (log.type == APP_MSG_TARGET_BINS) {
-                               _process_target_bins((char *)data_buf, data_size);
-                       } else if (log.type == APP_MSG_STOP) {
-                               /* Do leaks check if LSan is enabled. */
-                               lsan_do_leak_check();
-
-                               /* Send acknowlege message to manager */
-                               printLog(&log, APP_MSG_STOP);
-
-                               application_exit();
+                       if (msg_handler(&log))
                                break;
-                       } else if (log.type == APP_MSG_STOP_WITHOUT_KILL) {
-                               /* Do leaks check if LSan is enabled. */
-                               lsan_do_leak_check();
-
-                               /* Send acknowlege message to manager */
-                               printLog(&log, APP_MSG_STOP);
 
-                               _uninit_();
-                               break;
-                       } else if(log.type == APP_MSG_GET_UI_HIERARCHY) {
-                               PRINTMSG("APP_MSG_GET_UI_HIERARCHY");
-                               /* do nothing */
-                       } else if(log.type == APP_MSG_GET_UI_SCREENSHOT) {
-                               PRINTMSG("APP_MSG_GET_UI_SCREENSHOT");
-                               /* do nothing */
-                       } else if(log.type == APP_MSG_GET_UI_HIERARCHY_CANCEL) {
-                               PRINTMSG("APP_MSG_GET_UI_HIERARCHY_CANCEL");
-                               /* do nothing */
-                       } else {
-                               PRINTERR("recv unknown message. id = (%d)",
-                                        log.type);
-                       }
                } else { /* unknown case */
                        continue;
                }