Fix N_SE-17797 : Running Apps are blinking.
[apps/core/preloaded/taskmanager.git] / src / _genlist.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18
19
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <appcore-efl.h>
23 #include <vconf.h>
24 #include <utilX.h>
25 #include <aul.h>
26 #include <Ecore_X.h>
27 #include <Eina.h>
28 #include <unistd.h>
29 #include <time.h>
30 #include <sys/time.h>
31 #include <pthread.h>
32
33 #include "taskmanager.h"
34 #include "_genlist.h"
35 #include "_util_log.h"
36 #include "_util_efl.h"
37 #include "_logic.h"
38 #include "_cpu.h"
39 #include "_eina.h"
40 #include "_info.h"
41 #include "_progressbar.h"
42
43 pthread_t pt;
44 pthread_cond_t  pc;
45 pthread_mutex_t pm;
46 pthread_mutex_t mutex_for_graph_update = PTHREAD_MUTEX_INITIALIZER;
47 static Elm_Object_Item *g_egi;
48
49 /* group list:gl, data list:dl, button list:bl, no list: nl */
50 static Elm_Genlist_Item_Class itc_gl;
51 static Elm_Genlist_Item_Class itc_hl;
52 static Elm_Genlist_Item_Class itc_dl;
53 static Elm_Genlist_Item_Class itc_bl;
54 static Elm_Genlist_Item_Class itc_nl;
55 static Elm_Genlist_Item_Class itc_separator4;
56 static Elm_Genlist_Item_Class itc_separator2;
57
58 static char *button_text[TS_MAX] = {
59         "IDS_TASKMGR_BUTTON_CLOSE_ALL_APPLICATIONS",
60         "IDS_TASKMGR_BUTTON_CLEAR_HISTORY_ABB"
61 };
62
63 static void end_all_inuse_cb(void *data, Evas_Object *obj, void *event_info);
64 static void delete_all_history_cb(void *data, Evas_Object *obj,
65                                   void *event_info);
66 void (*func_del[TS_MAX]) (void *data, Evas_Object *obj, void *event_info) = {
67 &end_all_inuse_cb, &delete_all_history_cb};
68
69 static void end_inuse_cb(void *data, Evas_Object *obj, void *event_info);
70 static void delete_history_cb(void *data, Evas_Object *obj, void *event_info);
71 void (*func_end[TS_MAX]) (void *data, Evas_Object *obj, void *event_info) = {
72 &end_inuse_cb, &delete_history_cb};
73
74 static char *group_name[TS_MAX] = {
75         "IDS_TASKMGR_HEADER_RUNNING",
76         "IDS_TASKMGR_MBODY_RECENTLY_USED"
77 };
78
79 static char *nolist_text[TS_MAX] = {
80         "IDS_TASKMGR_MBODY_NO_APPS_OPEN",
81         "IDS_TASKMGR_MBODY_NO_RECENTLY_USED_APPS"
82 };
83
84 void taskmanager_free_info(struct _task_info *info);
85 Eina_Bool _update_list(void *data);
86
87 static void clear_genlist(void *data)
88 {
89         ret_if(data == NULL);
90
91         struct appdata *ad = data;
92
93         if (ad->gl) {
94                 elm_genlist_clear(ad->gl);
95         }
96 }
97
98 void clear_task_manager_list(void *data)
99 {
100         ret_if(data == NULL);
101
102         struct appdata *ad = data;
103         _free_einalist_all(ad);
104         clear_genlist(ad);
105 }
106
107 static void app_genlist_item_update(void *data)
108 {
109         ret_if(data == NULL);
110
111         struct appdata *ad = (struct appdata *)data;
112
113         Elm_Object_Item *it_r;
114         Eina_List *realized_item_list, *l_r;
115         unsigned int cnt = 0;
116
117         realized_item_list = elm_genlist_realized_items_get(ad->gl);
118         cnt = eina_list_count(realized_item_list);
119         if (cnt > 0) {
120                 EINA_LIST_FOREACH(realized_item_list, l_r, it_r) {
121                         if (it_r != NULL) {
122                                 elm_genlist_item_update(it_r);
123                         }
124                 }
125         }
126 }
127
128 Eina_Bool alert_app_info(void *data)
129 {
130         retv_if(data == NULL, -1);
131
132         struct appdata *ad = (struct appdata *)data;
133
134         app_genlist_item_update(ad);
135         return ECORE_CALLBACK_CANCEL;
136 }
137
138 static void end_all_inuse_cb(void *data, Evas_Object *obj, void *event_info)
139 {
140         ret_if(data == NULL);
141
142         struct appdata *ad = data;
143         char buf[_BUF_MAX] = { 0, };
144
145         ad->mode = MODE_END_ALL_INUSE;
146         snprintf(buf, sizeof(buf), T_("IDS_TASKMGR_POP_CLOSE_ALL_APPS_Q_THIS_MAY_CAUSE_DATA_TO_BE_LOST"));
147         if (ad->popup_ask) {
148                 evas_object_del(ad->popup_ask);
149                 ad->popup_ask = NULL;
150         }
151         ad->popup_ask = _add_popup_ask(ad->win, buf, ad);
152 }
153
154 static void
155 delete_all_history_cb(void *data, Evas_Object *obj, void *event_info)
156 {
157 _D("func\n");
158         ret_if(data == NULL);
159
160         struct appdata *ad = data;
161         char buf[_BUF_MAX] = { 0, };
162
163         ad->mode = MODE_DEL_ALL_HISTORY;
164         snprintf(buf, sizeof(buf), T_("IDS_TASKMGR_POP_CLEAR_ALL_APP_HISTORY_Q"));
165         if (ad->popup_ask) {
166                 evas_object_del(ad->popup_ask);
167                 ad->popup_ask = NULL;
168         }
169         ad->popup_ask = _add_popup_ask(ad->win, buf, ad);
170 }
171
172 static void end_inuse_cb(void *data, Evas_Object *obj, void *event_info)
173 {
174         ret_if(data == NULL);
175
176         struct _task_info *info_ev = (struct _task_info *)data;
177         struct appdata *ad = info_ev->ad;
178         char buf[_BUF_MAX] = { 0, };
179
180         ad->mode = MODE_END_INUSE;
181         snprintf(buf, _BUF_MAX, T_("IDS_TASKMGR_POP_CLOSE_PS_APP_Q_THIS_MAY_CAUSE_DATA_TO_BE_LOST"), info_ev->app_name);
182         if (ad->popup_ask) {
183                 evas_object_del(ad->popup_ask);
184                 ad->popup_ask = NULL;
185         }
186         ad->popup_ask = _add_popup_ask(ad->win, buf, ad);
187         g_egi = (void *)info_ev->it;
188 }
189
190 static void delete_history_cb(void *data, Evas_Object *obj, void *event_info)
191 {
192         ret_if(data == NULL);
193
194         struct _task_info *info_ev = (struct _task_info *)data;
195         struct appdata *ad = info_ev->ad;
196         char buf[_BUF_MAX] = { 0, };
197
198         ad->mode = MODE_DEL_HISTORY;
199
200         snprintf(buf, _BUF_MAX, T_("IDS_TASKMGR_POP_CLEAR_PS_HISTORY_Q"), info_ev->app_name);
201         if (ad->popup_ask) {
202                 evas_object_del(ad->popup_ask);
203                 ad->popup_ask = NULL;
204         }
205         ad->popup_ask = _add_popup_ask(ad->win, buf, ad);
206         g_egi = (void *)info_ev->it;
207 }
208
209 static void nl_sel(void *data, Evas_Object *obj, void *event_info)
210 {
211 _D("func\n");
212         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
213         elm_genlist_item_selected_set(item, EINA_FALSE);
214         return;
215 }
216
217 static char *nl_text_get(void *data, Evas_Object *obj, const char *part)
218 {
219         char buf[_BUF_MAX] = { 0, };
220
221         if (!strcmp(part, "elm.text")) {
222                 snprintf(buf, sizeof(buf), "%s", T_(nolist_text[(int)data]));
223
224                 return strdup(buf);
225         }
226         return NULL;
227 }
228
229 static void _gl_sel_app(void *data, Evas_Object *obj, void *event_info)
230 {
231 _D("func\n");
232         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
233         struct appdata *ad = (struct appdata *)data;
234         struct _task_info *info;
235         /* parameter to block double click */
236         static int selected = 0;
237         Elm_Object_Item *it = (Elm_Object_Item *) event_info;
238         int ret = -1;
239
240         elm_genlist_item_selected_set(it, EINA_FALSE);
241
242         retm_if(ad == NULL, "Invalid argument: appdata is NULL\n");
243
244         _fini_pthread();
245         if (ad->update_timer) {
246                 ecore_timer_del(ad->update_timer);
247                 ad->update_timer = NULL;
248         }
249
250         if (selected == 1)
251                 return;
252         selected = 1;
253
254         if (item == NULL) {
255                 _E("[Error] Cannot find genlist item\n");
256                 selected = 0;
257                 return;
258         }
259
260         info = (struct _task_info *)elm_object_item_data_get(item);
261         if (info == NULL) {
262                 _E("[Error] Cannot get item data: info\n");
263                 selected = 0;
264                 return;
265         }
266
267         if (info->pid) {
268                 /* when application is alive */
269                 ret = aul_resume_pid(info->pid);
270                 selected = 0;
271         } else {
272                 /* when application is dead */
273                 if (info->pkg_name == NULL) {
274                         util_show_popup_with_message(info->ad->win,
275                                         3.0,
276                                         T_("IDS_TASKMGR_POP_UNABLE_TO_OPEN_APPLICATION"));
277                         selected = 0;
278
279                 } else {
280                         _unset_notification_level(info->ad->win);
281
282                         if (!strcmp(info->pkg_name, "org.tizen.phone")) {
283                                 /* exception : Because dialer doesn't need bundle
284                                  * since being unifyed dialer, voice call and video call
285                                  */
286                                 ret = aul_launch_app(info->pkg_name, NULL);
287                                 selected = 0;
288                         } else {
289                                 ret = aul_launch_app(info->pkg_name, info->b);
290                                 selected = 0;
291                         }
292                 }
293         }
294         if(ret == 0) {
295                 _D("exit after 0.3 sec\n");
296                 ad->exit_timer = ecore_timer_add(0.3, _exit_cb, ad);
297         }
298 }
299
300
301 static Evas_Object *_gl_content_get_app(void *data, Evas_Object *obj,
302                                      const char *part)
303 {
304         struct _task_info *info = (struct _task_info *)data;
305         char buf[_BUF_MAX] = { 0, };
306
307         Evas_Object *icon = NULL;
308         Evas_Object *btn = NULL;
309
310         Evas_Object *rt, *icon_ly = NULL;
311
312         retvm_if(data == NULL, NULL, "Invalid argument: task info is NULL\n");
313
314         if (!strcmp(part, "elm.icon.1")) {
315                 snprintf(buf, sizeof(buf), "%s", info->icn_path);
316                 retvm_if(buf == NULL, NULL, "%s icon is NULL\n", info->app_name);
317                 if (!ecore_file_exists(buf) || strlen(buf) < 4)
318                         snprintf((char *)buf, (size_t) sizeof(buf),
319                                  (const char *)IMAGEDIR "/icon_taskmgr.png");
320
321                 if (!strncmp(&buf[strlen(buf) - 3], "edj", 3)) {
322                         icon_ly = _add_layout(obj, buf, "icon");
323
324                 } else {
325                         icon_ly = elm_icon_add(obj);
326                         elm_icon_file_set(icon_ly, buf, NULL);
327                 }
328
329                 icon = _add_layout(obj, EDJ_NAME, "icon");
330                 retvm_if(icon == NULL, NULL, "Cannot add layout: icon\n");
331
332                 rt = evas_object_rectangle_add(evas_object_evas_get(obj));
333                 retvm_if(rt == NULL, NULL, "Failed to add rectangle\n");
334
335                 evas_object_color_set(rt, 0, 0, 0, 0);
336                 evas_object_size_hint_min_set(rt,
337                                         (int)72 * elm_scale_get(),
338                                         (int)72 * elm_scale_get());
339                 elm_object_part_content_set(icon, "icon_ly", rt);
340
341                 elm_object_part_content_set(icon, "icon", icon_ly);
342
343                 return icon;
344
345         } else if (!strcmp(part, "elm.icon.2")) {
346                 btn = elm_button_add(obj);
347                 elm_object_text_set(btn, S_("IDS_COM_BODY_END"));
348                 elm_object_style_set(btn, "default");
349
350                 evas_object_smart_callback_add(btn, "clicked",
351                                                func_end[info->category], info);
352                 elm_object_focus_set(btn, EINA_FALSE);
353                 evas_object_propagate_events_set(btn, EINA_FALSE);
354
355                 return btn;
356         }
357
358         return NULL;
359 }
360
361 static char *_gl_text_get_app(void *data, Evas_Object *obj, const char *part)
362 {
363         struct _task_info *info = (struct _task_info *)data;
364         char buf[_BUF_MAX] = { 0, };
365         Evas_Object *eo;
366
367         retvm_if(data == NULL, NULL, "Invalid argument: task info is NULL\n");
368         retvm_if(part == NULL, NULL, "Invalid argument: part is NULL\n");
369
370         if (!strcmp(part, "elm.text.1")) {
371                 snprintf(buf, _BUF_MAX, "%s", info->app_name);
372                 return strdup(buf);
373
374         } else if (!strcmp(part, "elm.text.2")) {
375                 if (info->category == TS_INUSE) {
376                         snprintf(buf, _BUF_MAX, "CPU: %.1f%%", info->cpu);
377                         return strdup(buf);
378
379                 } else {
380                         if (info->it) {
381                                 elm_object_signal_emit(info->it, "prog.hide.mem","taskmanager");
382                         }
383                         return NULL;
384                 }
385         }
386         return NULL;
387 }
388
389 static void _bl_sel(void *data, Evas_Object *obj, void *event_info)
390 {
391 _D("func\n");
392         int mode = (int)data;
393         struct appdata *ad;
394         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
395
396         elm_genlist_item_selected_set(item, EINA_FALSE);
397 }
398
399 static char *_bl_text_get(void *data, Evas_Object *obj, const char *part)
400 {
401         if (!strcmp(part, "elm.text")) {
402                 return strdup(T_(button_text[(int)data]));
403
404         }
405         return NULL;
406 }
407
408 static Evas_Object *_bl_content_get(void *data, Evas_Object *obj,
409                                 const char *part)
410 {
411         Evas_Object *btn = NULL;
412         struct appdata *ad = evas_object_data_get(obj, "appdata");
413
414         if (!strcmp(part, "elm.icon")) {
415
416                 btn = elm_button_add(obj);
417                 elm_object_style_set(btn, "default");
418
419                 elm_object_text_set(btn, T_(button_text[(int)data]));
420                 evas_object_smart_callback_add(btn, "clicked",
421                                                func_del[(int)data], ad);
422                 elm_object_focus_set(btn, EINA_FALSE);
423
424                 evas_object_size_hint_min_set(btn, 0, 50);
425                 evas_object_size_hint_max_set(btn, 0, 50);
426                 evas_object_propagate_events_set(btn, EINA_FALSE);
427
428                 return btn;
429
430         }
431         return NULL;
432 }
433
434 static char *_gl_text_get_title(void *data, Evas_Object *obj, const char *part)
435 {
436         char buf[_BUF_MAX];
437
438         if (!strcmp(part, "elm.text")) {
439                 snprintf(buf, sizeof(buf), "%s (%d)",
440                                 T_(group_name[(int)data]), _get_grp_cnt((int)data));
441                 return strdup(buf);
442         }
443         return NULL;
444 }
445
446 static char *_gl_text_get_his(void *data, Evas_Object *obj, const char *part)
447 {
448         struct _task_info *info = (struct _task_info *)data;
449         char buf[_BUF_MAX] = { 0, };
450         Evas_Object *eo;
451
452         if (!strcmp(part, "elm.text")) {
453                 snprintf(buf, _BUF_MAX, "%s", info->app_name);
454                 return strdup(buf);
455         }
456         return NULL;
457 }
458
459 static Evas_Object *_gl_content_get_his(void *data, Evas_Object *obj,
460                                      const char *part)
461 {
462         struct _task_info *info = (struct _task_info *)data;
463         char buf[_BUF_MAX] = { 0, };
464
465         Evas_Object *icon = NULL;
466         Evas_Object *btn = NULL;
467
468         Evas_Object *rt, *icon_ly = NULL;
469         retvm_if(data == NULL, NULL, "Invalid argument: task info is NULL\n");
470
471         if (!strcmp(part, "elm.icon.1")) {
472                 snprintf(buf, sizeof(buf), "%s", info->icn_path);
473                 retvm_if(buf == NULL, NULL, "%s icon is NULL\n", info->app_name);
474                 if (!ecore_file_exists(buf) || strlen(buf) < 4)
475                         snprintf((char *)buf, (size_t) sizeof(buf),
476                                  (const char *)IMAGEDIR "/icon_taskmgr.png");
477
478                 if (!strncmp(&buf[strlen(buf) - 3], "edj", 3)) {
479                         icon_ly = _add_layout(obj, buf, "icon");
480
481                 } else {
482                         icon_ly = elm_icon_add(obj);
483                         elm_icon_file_set(icon_ly, buf, NULL);
484                 }
485
486                 icon = _add_layout(obj, EDJ_NAME, "icon");
487                 retvm_if (icon == NULL, NULL, "Cannot add layout: icon\n");
488
489                 rt = evas_object_rectangle_add(evas_object_evas_get(obj));
490                 retvm_if (rt == NULL, NULL, "Failed to add rectangle\n");
491
492                 evas_object_color_set(rt, 0, 0, 0, 0);
493                 evas_object_size_hint_min_set(rt,
494                                         (int)72 * elm_scale_get(),
495                                         (int)72 * elm_scale_get());
496                 elm_object_part_content_set(icon, "icon_ly", rt);
497
498                 elm_object_part_content_set(icon, "icon", icon_ly);
499
500                 return icon;
501
502         } else if (!strcmp(part, "elm.icon.2")) {
503                 btn = elm_button_add(obj);
504                 elm_object_text_set(btn, S_("IDS_COM_OPT_DELETE"));
505                 elm_object_style_set(btn, "default");
506
507                 evas_object_smart_callback_add(btn, "clicked",
508                                                func_end[info->category], info);
509                 elm_object_focus_set(btn, EINA_FALSE);
510                 evas_object_propagate_events_set(btn, EINA_FALSE);
511
512                 return btn;
513         }
514
515         return NULL;
516
517 }
518
519 void _set_itc(void)
520 {
521         itc_gl.item_style = "grouptitle";
522         itc_gl.func.text_get = _gl_text_get_title;
523
524         itc_dl.item_style = "2text.2icon.7";
525         itc_dl.func.text_get = _gl_text_get_app;
526         itc_dl.func.content_get = _gl_content_get_app;
527
528         itc_hl.item_style = "1text.2icon.4";
529         itc_hl.func.text_get = _gl_text_get_his;
530         itc_hl.func.content_get = _gl_content_get_his;
531
532         itc_separator4.item_style = "dialogue/seperator.4";
533         itc_separator2.item_style = "dialogue/seperator.2";
534
535         itc_bl.item_style = "1icon";
536         itc_bl.func.content_get = _bl_content_get;
537
538         itc_nl.item_style = "1text";
539         itc_nl.func.text_get = nl_text_get;
540
541 }
542
543 int check_genlist(struct appdata *ad)
544 {
545         Elm_Object_Item *egi;
546         struct _task_info *info;
547         int i = 1;
548
549         egi = elm_genlist_first_item_get(ad->gl);
550         while(egi) {
551                 info = (struct _task_info *)elm_object_item_data_get(egi);
552                 if(info) {
553                         _D("%s info[0x%x]\n", (int)info < 3 ? "-" : info->app_name, info);
554                 } else {
555                         _D("group\n");
556                 }
557                 egi = elm_genlist_item_next_get(egi);
558         }
559
560         return 0;
561 }
562
563 int _set_genlist_from_eina(struct appdata *ad)
564 {
565 _D("func\n");
566         Eina_List *l;
567         Elm_Object_Item *git, *item;
568         struct _task_info *info;
569         int i;
570
571         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
572         retvm_if(ad->gl == NULL, -1, "Invalid argument:genlist is NULL\n");
573
574         for (i = 0; i < TS_MAX; i++) {
575                 git = elm_genlist_item_append(ad->gl, &itc_gl,
576                                                  (void *)i, NULL,
577                                                  ELM_GENLIST_ITEM_NONE,
578                                               NULL, NULL);
579                 retvm_if(git == NULL, -1, "Failed append item\n");
580                 elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_NONE);
581
582                 if (eina_list_count(ad->applist[i]) > 0) {
583
584                         item = elm_genlist_item_append(ad->gl, &itc_separator4,
585                                                 NULL, git,
586                                                 ELM_GENLIST_ITEM_NONE,
587                                                 NULL, NULL);
588                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
589
590
591                         item = elm_genlist_item_append(ad->gl, &itc_bl,
592                                                 (void *)i, git,
593                                                 ELM_GENLIST_ITEM_NONE,
594                                                 _bl_sel, (void *)i);
595
596                         item = elm_genlist_item_append(ad->gl, &itc_separator2,
597                                                 NULL, git,
598                                                 ELM_GENLIST_ITEM_NONE,
599                                                 NULL, NULL);
600                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
601
602                         ad->applist[i] = eina_list_nth_list(ad->applist[i], 0);
603                         EINA_LIST_FOREACH(ad->applist[i], l, info) {
604                                 if (info != NULL) {
605                                         info->it = elm_genlist_item_append(ad->gl,
606                                                                     (i == TS_INUSE) ? &itc_dl : &itc_hl,
607                                                                     (void *)info, git,
608                                                                     ELM_GENLIST_ITEM_NONE,
609                                                                     _gl_sel_app, ad);
610                                 }
611                         }
612                 } else {
613                         item = elm_genlist_item_append(ad->gl, &itc_nl,
614                                                 (void *)i, git,
615                                                 ELM_GENLIST_ITEM_NONE,
616                                                 nl_sel, NULL);
617                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
618                 }
619         }
620         return 0;
621 }
622
623 Eina_Bool _update_list(void *data)
624 {
625 _D("func\n");
626         struct appdata *ad = data;
627         Eina_List *l, *l_next;
628         struct _task_info *info;
629
630         pthread_mutex_lock(&mutex_for_graph_update);
631
632         if(ad->applist[TS_INUSE] == NULL) {
633                 _D("inuse is NULL\n");
634                 pthread_mutex_unlock(&mutex_for_graph_update);
635                 ad->update_timer = NULL;
636                 return ECORE_CALLBACK_CANCEL;
637         }
638         ad->applist[TS_INUSE] = eina_list_nth_list(ad->applist[TS_INUSE], 0);
639         _D("%d\n", eina_list_count(ad->applist[TS_INUSE]));
640
641         EINA_LIST_FOREACH_SAFE(ad->applist[TS_INUSE], l, l_next, info) {
642                 elm_genlist_item_fields_update(info->it, "elm.text*", ELM_GENLIST_ITEM_FIELD_TEXT);
643         }
644         pthread_mutex_unlock(&mutex_for_graph_update);
645         return ECORE_CALLBACK_RENEW;
646 }
647
648 void *_update_pthread_cb(void *data)
649 {
650 _D("func\n");
651         struct appdata *ad = data;
652         long tick;
653         int ncpu;
654         Eina_List *l, *l_next;
655         struct _task_info *info;
656
657         while(1) {
658
659                 if (ad->ending == EINA_FALSE) {
660                         if(ad->applist[TS_INUSE] == NULL) {
661                                 _D("in use list is NULL\n");
662                                 return ECORE_CALLBACK_CANCEL;
663                         }
664
665                         _get_sysconf(&ncpu, &tick);
666
667                         ad->applist[TS_INUSE] = eina_list_nth_list(ad->applist[TS_INUSE], 0);
668                         if (eina_list_count(ad->applist[TS_INUSE]) < 1) {
669                                 _D("list count is 0\n");
670                                 return NULL;
671                         }
672
673                         EINA_LIST_FOREACH_SAFE(ad->applist[TS_INUSE], l, l_next, info) {
674                                 if (info) {
675                                         info->cpu = _get_cpu_ratio(info, ncpu, tick);
676                                         _D("%d / %lf\n", info->pid, info->cpu);
677                                 }
678
679                         }
680                         sleep(2);
681                 }
682         }
683
684         return NULL;
685
686 }
687
688 void _set_genlist(struct appdata *ad)
689 {
690 _D("func\n");
691         retm_if(ad == NULL, "Invalid argument: appdata is NULL\n");
692         int ret = AUL_R_ERROR;
693         int retry_cnt = 0;
694         int sleep_value = 1000;
695
696         _init_grp_cnt();
697
698         while (ret != AUL_R_OK && retry_cnt < 5) {
699                 usleep(sleep_value);
700                 ret = aul_app_get_running_app_info(runapp_info_get, ad);
701
702                 if (ret != AUL_R_OK) {
703                         _D("Fail to get running app information from ail");
704                 }
705
706                 retry_cnt++;
707                 sleep_value *= 2;
708         }
709
710         taskmanager_get_history_app_info(ad);
711         _set_genlist_from_eina(ad);
712
713 }
714
715 void _init_pthread(void)
716 {
717         pthread_mutex_init(&pm, NULL);
718         pthread_cond_init(&pc, NULL);
719 }
720
721 void _fini_pthread(void)
722 {
723 _D("func\n");
724         if (pt) {
725                 pthread_cancel(pt);
726         }
727 }
728
729 void refresh_app_info(struct appdata *ad)
730 {
731 _D("func\n");
732         retm_if(ad == NULL, "Invalid argument: appdata is NULL\n");
733
734         _free_einalist_all(ad);
735         clear_genlist(ad);
736
737         _set_genlist(ad);
738
739         alert_app_info(ad);
740
741 }
742
743 void _del_popup_timer(struct appdata *ad)
744 {
745         if (ad->popup_timer) {
746                 ecore_timer_del(ad->popup_timer);
747                 ad->popup_timer = NULL;
748         }
749 }
750
751 void taskmanager_free_info(struct _task_info *info)
752 {
753         if (info) {
754                 if (info->app_name) {
755                         free(info->app_name);
756                         info->app_name = NULL;
757                 }
758                 if (info->pkg_name) {
759                         free(info->pkg_name);
760                         info->pkg_name = NULL;
761                 }
762                 if (info->icn_path) {
763                         free(info->icn_path);
764                         info->icn_path = NULL;
765                 }
766
767                 free(info);
768         }
769 }
770
771 void _restart_pthread(struct appdata *ad)
772 {
773 _D("func\n");
774         pthread_cancel(pt);
775         if (eina_list_count(ad->applist[TS_INUSE]) > 0) {
776
777                 pthread_create(&pt, NULL, _update_pthread_cb, ad);
778                 pthread_detach(pt);
779                 if (ad->update_timer) {
780                         ecore_timer_del(ad->update_timer);
781                         ad->update_timer = NULL;
782                 }
783                 ad->update_timer = ecore_timer_add(2.0, _update_list, ad);
784         }
785 }
786 int response_end_inuse(struct appdata *ad)
787 {
788 _D("func\n");
789         Eina_List *l, *l_next;
790         struct _task_info *info;
791         Elm_Object_Item *egi;
792         Eina_Bool dead = EINA_FALSE;
793
794         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
795
796         ad->ending = EINA_TRUE;
797
798         EINA_LIST_FOREACH_SAFE(ad->applist[TS_INUSE], l, l_next, info) {
799                 _D("applist pid : %d", info->pid);
800                 if (info->it == g_egi) {
801                         _D("matched applist pid : %d", info->pid);
802                         if (info->pid > 0) {
803                                 if (aul_terminate_pid(info->pid) < 0) {
804                                         kill(info->pid, SIGKILL);
805                                         dead = EINA_TRUE;
806                                 }
807                         }
808                         break;
809                 }
810         }
811         ad->ending = EINA_FALSE;
812
813         if(!dead){
814                 _D("matched applist is nothing\n");
815                 _del_progressbar(ad);
816         }
817
818         return 0;
819 }
820
821 Eina_Bool _refresh_idler_cb(void *data)
822 {
823 _D("func\n");
824         struct appdata *ad = (struct appdata *)data;
825         retvm_if(data == NULL, ECORE_CALLBACK_CANCEL, "Invalid argument: appdata is NULL\n:");
826
827         _del_popup_timer(ad);
828         _del_progressbar(ad);
829         refresh_app_info(ad);
830         return ECORE_CALLBACK_CANCEL;
831 }
832
833 int response_end_all_inuse(struct appdata *ad)
834 {
835         Eina_List *l;
836         struct _task_info *info;
837
838         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
839
840         ad->ending = EINA_TRUE;
841
842         if(ad->update_timer) {
843                 ecore_timer_del(ad->update_timer);
844                 ad->update_timer = NULL;
845         }
846
847         ad->endcnt = eina_list_count(ad->applist[TS_INUSE]);
848         _D("set end count (%d)\n", ad->endcnt);
849
850         EINA_LIST_FOREACH(ad->applist[TS_INUSE], l, info) {
851                 if (info != NULL) {
852                         _D("applist pid : %d", info->pid);
853                         if (info->pid > 0) {
854                                 if (aul_terminate_pid(info->pid) < 0) {
855                                         kill(info->pid, SIGKILL);
856                                 }
857                                 _D("terminated\n");
858                         }
859                 }
860         }
861         ad->ending = EINA_FALSE;
862         return 0;
863 }
864
865 int response_del_history(struct appdata *ad)
866 {
867         Eina_List *l, *l_next;
868         struct _task_info *info;
869         Elm_Object_Item *egi;
870
871         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
872
873         _show_progressbar(ad);
874         EINA_LIST_FOREACH_SAFE(ad->applist[TS_HISTORY], l, l_next, info) {
875                 _D("history applist pid : %d", info->pid);
876                 if (info->it == g_egi) {
877
878                         if (rua_init() == -1) {
879                                 break;
880                         }
881                         rua_delete_history_with_pkgname(info->pkg_name);
882                         rua_fini();
883
884                         ad->applist[TS_HISTORY] =
885                             eina_list_remove_list(ad->applist[TS_HISTORY], l);
886
887                         if (info->b) {
888                                 bundle_free(info->b);
889                         }
890
891                         elm_object_item_del(info->it);
892                         taskmanager_free_info(info);
893                         break;
894                 }
895         }
896         alert_app_info(ad);
897         refresh_app_info(ad);
898         _del_popup_timer(ad);
899         _del_progressbar(ad);
900
901         ad->mode = MODE_NONE;
902         return 0;
903 }
904
905 int response_del_all_history(struct appdata *ad)
906 {
907         Eina_List *l;
908         struct _task_info *info;
909
910         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
911
912         if(ad->update_timer) {
913                 _D("update timer is deleted\n");
914                 ecore_timer_del(ad->update_timer);
915                 ad->update_timer = NULL;
916         }
917
918
919         _show_progressbar(ad);
920
921         if (rua_init() == -1) {
922                 return -1;
923         }
924
925         EINA_LIST_FOREACH(ad->applist[TS_HISTORY], l, info) {
926                 if (info != NULL) {
927                         rua_delete_history_with_pkgname(info->pkg_name);
928                 }
929         }
930
931         if (eina_list_count(ad->applist[TS_INUSE]) == 0) {
932                 rua_clear_history();
933         }
934
935         rua_fini();
936         refresh_app_info(ad);
937         _del_popup_timer(ad);
938         _del_progressbar(ad);
939
940         ad->mode = MODE_NONE;
941         return 0;
942 }
943
944 int response_kill_inuse(struct appdata *ad)
945 {
946         Eina_List *l, *l_next;
947         struct _task_info *info;
948         Elm_Object_Item *egi;
949
950         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
951
952         _show_progressbar(ad);
953
954         EINA_LIST_FOREACH_SAFE(ad->applist[TS_INUSE], l, l_next, info) {
955                 _D("kill applist pid : %d", info->pid);
956                 if (info->it == g_egi) {
957                         if (info->pid > 0) {
958                                 kill(info->pid, SIGKILL);
959                         }
960
961                         ad->applist[TS_INUSE] =
962                             eina_list_remove_list(ad->applist[TS_INUSE], l);
963                         taskmanager_free_info(info);
964                         break;
965                 }
966         }
967         refresh_app_info(ad);
968         _del_progressbar(ad);
969
970         return 0;
971 }
972
973 int response_kill_all_inuse(struct appdata *ad)
974 {
975         Eina_List *l;
976         struct _task_info *info;
977
978         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
979
980         _show_progressbar(ad);
981
982         EINA_LIST_FOREACH(ad->applist[TS_INUSE], l, info) {
983                 _D("kill all applist pid : %d", info->pid);
984                 if (info != NULL) {
985                         if (info->pid > 0) {
986                                 kill(info->pid, SIGKILL);
987                         }
988                 }
989         }
990         refresh_app_info(ad);
991         _del_progressbar(ad);
992
993         return 0;
994 }
995