From 5031dbbfcdf250863f30af1d6893a3c82848bdb4 Mon Sep 17 00:00:00 2001 From: Alexander Aksenov Date: Wed, 4 Oct 2017 22:20:31 +0300 Subject: [PATCH] Refactor recv_thread Change-Id: I2159b02c311e9d07dd17a6cb48318d38b7fc9ce4 Signed-off-by: Alexander Aksenov --- helper/libdaprobe.c | 84 ++++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/helper/libdaprobe.c b/helper/libdaprobe.c index 602b995..c99cdf9 100755 --- a/helper/libdaprobe.c +++ b/helper/libdaprobe.c @@ -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; } -- 2.7.4