[FIX] Start app on web profiling 26/44426/3
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Tue, 21 Jul 2015 18:23:51 +0000 (21:23 +0300)
committerDmitry Kovalenko <d.kovalenko@samsung.com>
Tue, 21 Jul 2015 18:29:53 +0000 (11:29 -0700)
Move port obtaining to separate thread

Change-Id: Idea7367d56168af8cc3adecb1b57267d41ee8b9e
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
daemon/da_protocol.c
daemon/daemon.c
daemon/wsi.c
daemon/wsi.h

index 907458d..6942860 100644 (file)
@@ -661,8 +661,7 @@ enum ErrorCode stop_all_no_lock(void)
        // stop all only if it has not been called yet
        if (check_running_status(&prof_session)) {
                if (is_feature_enabled(FL_WEB_PROFILING)) {
-                       wsi_stop_profiling();
-                       wsi_destroy();
+                       wsi_stop();
                }
 
                msg = gen_stop_msg();
index aaea1b6..aa4170e 100644 (file)
@@ -67,8 +67,6 @@
 #define DA_READELF_PATH                        "/home/developer/sdk_tools/da/readelf"
 #define SCREENSHOT_DIR                 "/tmp/da"
 
-#define WSI_HOST                       "127.0.0.1"
-
 #define MAX_APP_LAUNCH_TIME            60
 #define MAX_CONNECT_TIMEOUT_TIME       5*60
 
@@ -289,15 +287,8 @@ static int exec_app(const struct app_info_t *app_info)
                        break;
                }
 
-               if (wsi_init(WSI_HOST, 0)) {
-                       LOGE("Cannot init web application profiling\n");
-                       res = -1;
-               } else {
-                       if (wsi_start_profiling()) {
-                               LOGE("Cannot start web application profiling\n");
-                               res = -1;
-                       }
-               }
+               wsi_start();
+
                break;
        default:
                LOGE("Unknown app type %d\n", app_info->app_type);
index 8fff6d7..e884e81 100644 (file)
@@ -58,12 +58,15 @@ enum protocol_names {
        PROTOCOL_PROFILING
 };
 
+const char WSI_HOST[] = "127.0.0.1";
 struct libwebsocket_context *context;
 struct libwebsocket *wsi;
 
 int pstate = PSTATE_DEFAULT;
 int request_id = 1;
 
+static void wsi_destroy(void);
+
 static int set_profile_info(const char *path, const char *info)
 {
        FILE *fp;
@@ -383,7 +386,7 @@ static void *handle_ws_responses(void *arg)
        return NULL;
 }
 
-int wsi_init(const char *address, int port)
+static int wsi_init(const char *address, int port)
 {
        if (!port) {
                char buf[sizeof(struct msg_t) + sizeof(uint32_t)];
@@ -408,7 +411,7 @@ int wsi_init(const char *address, int port)
        return 0;
 }
 
-void wsi_destroy(void)
+static void wsi_destroy(void)
 {
        if (CHKSTAT(pstate, PSTATE_CONNECTED)) {
                if (CHKSTAT(pstate, PSTATE_WAIT_ACK))
@@ -420,7 +423,7 @@ void wsi_destroy(void)
        }
 }
 
-int wsi_start_profiling(void)
+static int wsi_start_profiling(void)
 {
        pthread_t tid;
 
@@ -435,10 +438,45 @@ int wsi_start_profiling(void)
        return 0;
 }
 
-void wsi_stop_profiling(void)
+static void wsi_stop_profiling(void)
 {
        if (CHKSTAT(pstate, PSTATE_CONNECTED)) {
                send_request("Profiler.stop");
                send_request("Profiler.disable");
        }
 }
+
+static void *do_start(void *arg)
+{
+       if (wsi_init(WSI_HOST, 0)) {
+               LOGE("Cannot init web application profiling\n");
+               goto out;
+       }
+
+       if (wsi_start_profiling())
+               LOGE("Cannot start web application profiling\n");
+
+out:
+       return NULL;
+}
+
+int wsi_start(void)
+{
+       int ret;
+       pthread_t t;
+
+       /* FIXME: call pthread_joun() */
+       ret = pthread_create(&t, NULL, &do_start, NULL);
+       if (ret) {
+               LOGE("Can't create do_start thread\n");
+               destroy_wsi_conn(context);
+       }
+
+       return ret;
+}
+
+void wsi_stop(void)
+{
+       wsi_stop_profiling();
+       wsi_destroy();
+}
index 5fea0f1..fca7ab0 100644 (file)
@@ -38,9 +38,8 @@ enum web_prof_state_t {
 int wsi_set_profile(const struct app_info_t *app_info);
 int wsi_set_smack_rules(const struct app_info_t *app_info);
 int wsi_enable_profiling(enum web_prof_state_t mode);
-int wsi_init(const char *address, int port);
-int wsi_start_profiling(void);
-void wsi_destroy(void);
-void wsi_stop_profiling(void);
+
+int wsi_start(void);
+void wsi_stop(void);
 
 #endif /* WSI_H_ */