[IMPROVE] Launch timer support several apps
authorAlexander Aksenov <a.aksenov@samsung.com>
Mon, 25 Nov 2013 14:29:52 +0000 (18:29 +0400)
committerAlexander Aksenov <a.aksenov@samsung.com>
Tue, 26 Nov 2013 15:11:42 +0000 (19:11 +0400)
Timer time = apps count * per-app launch time.
Timer is stopped after last app starts.

Change-Id: Ib4326d4c9b4edc39c21c33f6fead4f854a51bc67
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
daemon/daemon.c
daemon/daemon.h
daemon/main.c

index 0a394e2..d6ce462 100644 (file)
@@ -241,16 +241,22 @@ static void setEmptyTargetSlot(int index)
 // =============================================================================
 
 //start application launch timer function
-static int start_app_launch_timer()
+static int start_app_launch_timer(int apps_count)
 {
        int res = 0;
        struct epoll_event ev;
 
+       if (apps_count <= 0) {
+               res = -1;
+               LOGE("Wrong apps_count!\n");
+               return res;
+       }
+
        manager.app_launch_timerfd =
            timerfd_create(CLOCK_REALTIME, TFD_CLOEXEC);
        if (manager.app_launch_timerfd > 0) {
                struct itimerspec ctime;
-               ctime.it_value.tv_sec = MAX_APP_LAUNCH_TIME;
+               ctime.it_value.tv_sec = MAX_APP_LAUNCH_TIME * apps_count;
                ctime.it_value.tv_nsec = 0;
                ctime.it_interval.tv_sec = 0;
                ctime.it_interval.tv_nsec = 0;
@@ -293,6 +299,21 @@ static int stop_app_launch_timer()
        return 0;
 }
 
+static inline void inc_apps_to_run()
+{
+               manager.apps_to_run++;
+}
+
+static inline void dec_apps_to_run()
+{
+               manager.apps_to_run--;
+}
+
+static inline int get_apps_to_run()
+{
+               return manager.apps_to_run;
+}
+
 int kill_app_by_info(const struct app_info_t *app_info)
 {
        int res = 0;
@@ -336,6 +357,8 @@ static int exec_app(const struct app_info_t *app_info)
                if (exec_app_tizen(app_info->app_id, app_info->exe_path)) {
                        LOGE("Cannot exec tizen app %s\n", app_info->app_id);
                        res = -1;
+               } else {
+                       inc_apps_to_run();
                }
                break;
        case APP_TYPE_RUNNING:
@@ -346,6 +369,8 @@ static int exec_app(const struct app_info_t *app_info)
                if (exec_app_common(app_info->exe_path)) {
                        LOGE("Cannot exec common app %s\n", app_info->exe_path);
                        res = -1;
+               } else {
+                       inc_apps_to_run();
                }
                break;
        default:
@@ -354,10 +379,6 @@ static int exec_app(const struct app_info_t *app_info)
                break;
        }
 
-       if (res == 0 && app_info->app_type != APP_TYPE_RUNNING)
-               if (start_app_launch_timer() < 0)
-                       res = -1;
-
        LOGI("ret=%d\n", res);
        return res;
 }
@@ -468,6 +489,11 @@ int start_profiling()
                app_info = app_info_get_next(&app);
        }
 
+       if (start_app_launch_timer(get_apps_to_run()) < 0) {
+               res = -1;
+               goto recording_stop;
+       }
+
        goto exit;
 
  recording_stop:
@@ -748,8 +774,9 @@ static int targetServerHandler(int efd)
                        goto TARGET_CONNECT_FAIL;
                }
 
-               if (manager.app_launch_timerfd >= 0) {
-                       LOGI("release launch timer\n");
+               dec_apps_to_run();
+
+               if ((manager.app_launch_timerfd > 0) && (get_apps_to_run() == 0)) {
                        if (stop_app_launch_timer() < 0)
                                LOGE("cannot stop app launch timer\n");
                }
index fb1c956..05ddeb4 100644 (file)
@@ -184,6 +184,7 @@ typedef struct
        int host_server_socket;
        int target_server_socket;
        int target_count;
+       int apps_to_run;
        unsigned int config_flag;
        int app_launch_timerfd;
        int connect_timeout_timerfd;
index 830fe5c..ca61b34 100644 (file)
@@ -63,6 +63,7 @@ __da_manager manager =
        .host_server_socket = -1,
        .target_server_socket = -1,
        .target_count = 0,
+       .apps_to_run = 0,
        .config_flag = 0,
        .app_launch_timerfd = -1,
        .connect_timeout_timerfd = -1,