N_SE-9808 : App terminate issue
[apps/home/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
239         elm_genlist_item_selected_set(it, EINA_FALSE);
240
241         retm_if(ad == NULL, "Invalid argument: appdata is NULL\n");
242
243         _fini_pthread();
244         if (ad->update_timer) {
245                 ecore_timer_del(ad->update_timer);
246                 ad->update_timer = NULL;
247         }
248
249         if (selected == 1)
250                 return;
251         selected = 1;
252
253         if (item == NULL) {
254                 _E("[Error] Cannot find genlist item\n");
255                 selected = 0;
256                 return;
257         }
258
259         info = (struct _task_info *)elm_object_item_data_get(item);
260         if (info == NULL) {
261                 _E("[Error] Cannot get item data: info\n");
262                 selected = 0;
263                 return;
264         }
265
266         if (info->pid) {
267                 /* when application is alive */
268                 aul_resume_pid(info->pid);
269                 selected = 0;
270         } else {
271                 /* when application is dead */
272                 if (info->pkg_name == NULL) {
273                         util_show_popup_with_message(info->ad->win,
274                                         3.0,
275                                         T_("IDS_TASKMGR_POP_UNABLE_TO_OPEN_APPLICATION"));
276                         selected = 0;
277
278                 } else {
279                         _unset_notification_level(info->ad->win);
280
281                         if (!strcmp(info->pkg_name, "org.tizen.phone")) {
282                                 /* exception : Because dialer doesn't need bundle
283                                  * since being unifyed dialer, voice call and video call
284                                  */
285                                 aul_launch_app(info->pkg_name, NULL);
286                                 selected = 0;
287                         } else {
288                                 aul_launch_app(info->pkg_name, info->b);
289                                 selected = 0;
290                         }
291                 }
292         }
293 }
294
295 static Evas_Object *_gl_content_get_app(void *data, Evas_Object *obj,
296                                      const char *part)
297 {
298         struct _task_info *info = (struct _task_info *)data;
299         char buf[_BUF_MAX] = { 0, };
300
301         Evas_Object *icon = NULL;
302         Evas_Object *btn = NULL;
303
304         Evas_Object *rt, *icon_ly = NULL;
305
306         retvm_if(data == NULL, NULL, "Invalid argument: task info is NULL\n");
307
308         if (!strcmp(part, "elm.icon.1")) {
309                 snprintf(buf, sizeof(buf), "%s", info->icn_path);
310                 retvm_if(buf == NULL, NULL, "%s icon is NULL\n", info->app_name);
311                 if (!ecore_file_exists(buf) || strlen(buf) < 4)
312                         snprintf((char *)buf, (size_t) sizeof(buf),
313                                  (const char *)IMAGEDIR "/icon_taskmgr.png");
314
315                 if (!strncmp(&buf[strlen(buf) - 3], "edj", 3)) {
316                         icon_ly = _add_layout(obj, buf, "icon");
317
318                 } else {
319                         icon_ly = elm_icon_add(obj);
320                         elm_icon_file_set(icon_ly, buf, NULL);
321                 }
322
323                 icon = _add_layout(obj, EDJ_NAME, "icon");
324                 retvm_if(icon == NULL, NULL, "Cannot add layout: icon\n");
325
326                 rt = evas_object_rectangle_add(evas_object_evas_get(obj));
327                 retvm_if(rt == NULL, NULL, "Failed to add rectangle\n");
328
329                 evas_object_color_set(rt, 0, 0, 0, 0);
330                 evas_object_size_hint_min_set(rt, 50, 50);
331                 elm_object_part_content_set(icon, "icon_ly", rt);
332
333                 elm_object_part_content_set(icon, "icon", icon_ly);
334
335                 return icon;
336
337         } else if (!strcmp(part, "elm.icon.2")) {
338                 btn = elm_button_add(obj);
339                 elm_object_text_set(btn, S_("IDS_COM_BODY_END"));
340                 elm_object_style_set(btn, "default");
341
342                 evas_object_smart_callback_add(btn, "clicked",
343                                                func_end[info->category], info);
344                 elm_object_focus_set(btn, EINA_FALSE);
345                 evas_object_propagate_events_set(btn, EINA_FALSE);
346
347                 return btn;
348         }
349
350         return NULL;
351 }
352
353 static char *_gl_text_get_app(void *data, Evas_Object *obj, const char *part)
354 {
355         struct _task_info *info = (struct _task_info *)data;
356         char buf[_BUF_MAX] = { 0, };
357         Evas_Object *eo;
358
359         retvm_if(data == NULL, NULL, "Invalid argument: task info is NULL\n");
360         retvm_if(part == NULL, NULL, "Invalid argument: part is NULL\n");
361
362         if (!strcmp(part, "elm.text.1")) {
363                 snprintf(buf, _BUF_MAX, "%s", info->app_name);
364                 return strdup(buf);
365
366         } else if (!strcmp(part, "elm.text.2")) {
367                 if (info->category == TS_INUSE) {
368                         snprintf(buf, _BUF_MAX, "CPU: %.1f%%", info->cpu);
369                         return strdup(buf);
370
371                 } else {
372                         if (info->it) {
373                                 elm_object_signal_emit(info->it, "prog.hide.mem","taskmanager");
374                         }
375                         return NULL;
376                 }
377         }
378         return NULL;
379 }
380
381 static void _bl_sel(void *data, Evas_Object *obj, void *event_info)
382 {
383 _D("func\n");
384         int mode = (int)data;
385         struct appdata *ad;
386         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
387
388         elm_genlist_item_selected_set(item, EINA_FALSE);
389 }
390
391 static char *_bl_text_get(void *data, Evas_Object *obj, const char *part)
392 {
393         if (!strcmp(part, "elm.text")) {
394                 return strdup(T_(button_text[(int)data]));
395
396         }
397         return NULL;
398 }
399
400 static Evas_Object *_bl_content_get(void *data, Evas_Object *obj,
401                                 const char *part)
402 {
403         Evas_Object *btn = NULL;
404         struct appdata *ad = evas_object_data_get(obj, "appdata");
405
406         if (!strcmp(part, "elm.icon")) {
407
408                 btn = elm_button_add(obj);
409                 elm_object_style_set(btn, "default");
410
411                 elm_object_text_set(btn, T_(button_text[(int)data]));
412                 evas_object_smart_callback_add(btn, "clicked",
413                                                func_del[(int)data], ad);
414                 elm_object_focus_set(btn, EINA_FALSE);
415
416                 evas_object_size_hint_min_set(btn, 0, 50);
417                 evas_object_size_hint_max_set(btn, 0, 50);
418                 evas_object_propagate_events_set(btn, EINA_FALSE);
419
420                 return btn;
421
422         }
423         return NULL;
424 }
425
426 static char *_gl_text_get_title(void *data, Evas_Object *obj, const char *part)
427 {
428         char buf[_BUF_MAX];
429
430         if (!strcmp(part, "elm.text")) {
431                 snprintf(buf, sizeof(buf), "%s (%d)",
432                                 T_(group_name[(int)data]), _get_grp_cnt((int)data));
433                 return strdup(buf);
434         }
435         return NULL;
436 }
437
438 static char *_gl_text_get_his(void *data, Evas_Object *obj, const char *part)
439 {
440         struct _task_info *info = (struct _task_info *)data;
441         char buf[_BUF_MAX] = { 0, };
442         Evas_Object *eo;
443
444         if (!strcmp(part, "elm.text")) {
445                 snprintf(buf, _BUF_MAX, "%s", info->app_name);
446                 return strdup(buf);
447         }
448         return NULL;
449 }
450
451 static Evas_Object *_gl_content_get_his(void *data, Evas_Object *obj,
452                                      const char *part)
453 {
454         struct _task_info *info = (struct _task_info *)data;
455         char buf[_BUF_MAX] = { 0, };
456
457         Evas_Object *icon = NULL;
458         Evas_Object *btn = NULL;
459
460         Evas_Object *rt, *icon_ly = NULL;
461         retvm_if(data == NULL, NULL, "Invalid argument: task info is NULL\n");
462
463         if (!strcmp(part, "elm.icon.1")) {
464                 snprintf(buf, sizeof(buf), "%s", info->icn_path);
465                 retvm_if(buf == NULL, NULL, "%s icon is NULL\n", info->app_name);
466                 if (!ecore_file_exists(buf) || strlen(buf) < 4)
467                         snprintf((char *)buf, (size_t) sizeof(buf),
468                                  (const char *)IMAGEDIR "/icon_taskmgr.png");
469
470                 if (!strncmp(&buf[strlen(buf) - 3], "edj", 3)) {
471                         icon_ly = _add_layout(obj, buf, "icon");
472
473                 } else {
474                         icon_ly = elm_icon_add(obj);
475                         elm_icon_file_set(icon_ly, buf, NULL);
476                 }
477
478                 icon = _add_layout(obj, EDJ_NAME, "icon");
479                 retvm_if (icon == NULL, NULL, "Cannot add layout: icon\n");
480
481                 rt = evas_object_rectangle_add(evas_object_evas_get(obj));
482                 retvm_if (rt == NULL, NULL, "Failed to add rectangle\n");
483
484                 evas_object_color_set(rt, 0, 0, 0, 0);
485                 evas_object_size_hint_min_set(rt, 50, 50);
486                 elm_object_part_content_set(icon, "icon_ly", rt);
487
488                 elm_object_part_content_set(icon, "icon", icon_ly);
489
490                 return icon;
491
492         } else if (!strcmp(part, "elm.icon.2")) {
493                 btn = elm_button_add(obj);
494                 elm_object_text_set(btn, S_("IDS_COM_OPT_DELETE"));
495                 elm_object_style_set(btn, "default");
496
497                 evas_object_smart_callback_add(btn, "clicked",
498                                                func_end[info->category], info);
499                 elm_object_focus_set(btn, EINA_FALSE);
500                 evas_object_propagate_events_set(btn, EINA_FALSE);
501
502                 return btn;
503         }
504
505         return NULL;
506
507 }
508
509 void _set_itc(void)
510 {
511         itc_gl.item_style = "grouptitle";
512         itc_gl.func.text_get = _gl_text_get_title;
513
514         itc_dl.item_style = "2text.2icon.7";
515         itc_dl.func.text_get = _gl_text_get_app;
516         itc_dl.func.content_get = _gl_content_get_app;
517
518         itc_hl.item_style = "1text.2icon.4";
519         itc_hl.func.text_get = _gl_text_get_his;
520         itc_hl.func.content_get = _gl_content_get_his;
521
522         itc_separator4.item_style = "dialogue/seperator.4";
523         itc_separator2.item_style = "dialogue/seperator.2";
524
525         itc_bl.item_style = "dialogue/bg/1icon";
526         itc_bl.func.content_get = _bl_content_get;
527
528         itc_nl.item_style = "1text";
529         itc_nl.func.text_get = nl_text_get;
530
531 }
532
533 int check_genlist(struct appdata *ad)
534 {
535         Elm_Object_Item *egi;
536         struct _task_info *info;
537         int i = 1;
538
539         egi = elm_genlist_first_item_get(ad->gl);
540         while(egi) {
541                 info = (struct _task_info *)elm_object_item_data_get(egi);
542                 if(info) {
543                         _D("%s info[0x%x]\n", (int)info < 3 ? "-" : info->app_name, info);
544                 } else {
545                         _D("group\n");
546                 }
547                 egi = elm_genlist_item_next_get(egi);
548         }
549
550         return 0;
551 }
552
553 int _set_genlist_from_eina(struct appdata *ad)
554 {
555 _D("func\n");
556         Eina_List *l;
557         Elm_Object_Item *git, *item;
558         struct _task_info *info;
559         int i;
560
561         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
562         retvm_if(ad->gl == NULL, -1, "Invalid argument:genlist is NULL\n");
563
564         for (i = 0; i < TS_MAX; i++) {
565                 git = elm_genlist_item_append(ad->gl, &itc_gl,
566                                                  (void *)i, NULL,
567                                                  ELM_GENLIST_ITEM_NONE,
568                                               NULL, NULL);
569                 retvm_if(git == NULL, -1, "Failed append item\n");
570                 elm_genlist_item_select_mode_set(git, EINA_TRUE);
571
572                 if (eina_list_count(ad->applist[i]) > 0) {
573
574                         item = elm_genlist_item_append(ad->gl, &itc_separator4,
575                                                 NULL, git,
576                                                 ELM_GENLIST_ITEM_NONE,
577                                                 NULL, NULL);
578                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
579
580
581                         item = elm_genlist_item_append(ad->gl, &itc_bl,
582                                                 (void *)i, git,
583                                                 ELM_GENLIST_ITEM_NONE,
584                                                 _bl_sel, (void *)i);
585
586                         item = elm_genlist_item_append(ad->gl, &itc_separator2,
587                                                 NULL, git,
588                                                 ELM_GENLIST_ITEM_NONE,
589                                                 NULL, NULL);
590                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
591
592                         ad->applist[i] = eina_list_nth_list(ad->applist[i], 0);
593                         EINA_LIST_FOREACH(ad->applist[i], l, info) {
594                                 if (info != NULL) {
595                                         info->it = elm_genlist_item_append(ad->gl,
596                                                                     (i == TS_INUSE) ? &itc_dl : &itc_hl,
597                                                                     (void *)info, git,
598                                                                     ELM_GENLIST_ITEM_NONE,
599                                                                     _gl_sel_app, ad);
600                                 }
601                         }
602                 } else {
603                         item = elm_genlist_item_append(ad->gl, &itc_nl,
604                                                 (void *)i, git,
605                                                 ELM_GENLIST_ITEM_NONE,
606                                                 nl_sel, NULL);
607                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
608                 }
609         }
610         return 0;
611 }
612
613 Eina_Bool _update_list(void *data)
614 {
615 _D("func\n");
616         struct appdata *ad = data;
617         Eina_List *l, *l_next;
618         struct _task_info *info;
619
620         pthread_mutex_lock(&mutex_for_graph_update);
621
622         if(ad->applist[TS_INUSE] == NULL) {
623                 _D("inuse is NULL\n");
624                 return ECORE_CALLBACK_CANCEL;
625         }
626         ad->applist[TS_INUSE] = eina_list_nth_list(ad->applist[TS_INUSE], 0);
627         _D("%d\n", eina_list_count(ad->applist[TS_INUSE]));
628
629         EINA_LIST_FOREACH_SAFE(ad->applist[TS_INUSE], l, l_next, info) {
630                 elm_genlist_item_update(info->it);
631
632         }
633         pthread_mutex_unlock(&mutex_for_graph_update);
634         return ECORE_CALLBACK_RENEW;
635 }
636
637 void *_update_pthread_cb(void *data)
638 {
639 _D("func\n");
640         struct appdata *ad = data;
641         long tick;
642         int ncpu;
643         Eina_List *l, *l_next;
644         struct _task_info *info;
645
646         while(1) {
647
648                 if (ad->ending == EINA_FALSE) {
649                         if(ad->applist[TS_INUSE] == NULL) {
650                                 _D("in use list is NULL\n");
651                                 return ECORE_CALLBACK_CANCEL;
652                         }
653
654                         _get_sysconf(&ncpu, &tick);
655
656                         ad->applist[TS_INUSE] = eina_list_nth_list(ad->applist[TS_INUSE], 0);
657                         if (eina_list_count(ad->applist[TS_INUSE]) < 1) {
658                                 _D("list count is 0\n");
659                                 return NULL;
660                         }
661
662                         EINA_LIST_FOREACH_SAFE(ad->applist[TS_INUSE], l, l_next, info) {
663                                 if (info) {
664                                         info->cpu = _get_cpu_ratio(info, ncpu, tick);
665                                         _D("%d / %lf\n", info->pid, info->cpu);
666                                 }
667
668                         }
669                         sleep(2);
670                 }
671         }
672
673         return NULL;
674
675 }
676
677 void _set_genlist(struct appdata *ad)
678 {
679 _D("func\n");
680         retm_if(ad == NULL, "Invalid argument: appdata is NULL\n");
681         int ret = AUL_R_ERROR;
682
683         _init_grp_cnt();
684
685         while (ret != AUL_R_OK)
686                 ret = aul_app_get_running_app_info(runapp_info_get, ad);
687
688         taskmanager_get_history_app_info(ad);
689         _set_genlist_from_eina(ad);
690
691 }
692
693 void _init_pthread(void)
694 {
695         pthread_mutex_init(&pm, NULL);
696         pthread_cond_init(&pc, NULL);
697 }
698
699 void _fini_pthread(void)
700 {
701 _D("func\n");
702         if (pt) {
703                 pthread_cancel(pt);
704         }
705 }
706
707 void refresh_app_info(struct appdata *ad)
708 {
709 _D("func\n");
710         retm_if(ad == NULL, "Invalid argument: appdata is NULL\n");
711
712         _free_einalist_all(ad);
713         clear_genlist(ad);
714
715         _set_genlist(ad);
716
717         alert_app_info(ad);
718
719 }
720
721 void _del_popup_timer(struct appdata *ad)
722 {
723         if (ad->popup_timer) {
724                 ecore_timer_del(ad->popup_timer);
725                 ad->popup_timer = NULL;
726         }
727 }
728
729 void taskmanager_free_info(struct _task_info *info)
730 {
731         if (info) {
732                 if (info->app_name) {
733                         free(info->app_name);
734                         info->app_name = NULL;
735                 }
736                 if (info->pkg_name) {
737                         free(info->pkg_name);
738                         info->pkg_name = NULL;
739                 }
740                 if (info->icn_path) {
741                         free(info->icn_path);
742                         info->icn_path = NULL;
743                 }
744
745                 free(info);
746         }
747 }
748
749 void _restart_pthread(struct appdata *ad)
750 {
751 _D("func\n");
752         pthread_cancel(pt);
753         if (eina_list_count(ad->applist[TS_INUSE]) > 0) {
754
755                 pthread_create(&pt, NULL, _update_pthread_cb, ad);
756                 pthread_detach(pt);
757                 if (ad->update_timer) {
758                         ecore_timer_del(ad->update_timer);
759                         ad->update_timer = NULL;
760                 }
761                 ad->update_timer = ecore_timer_add(2.0, _update_list, ad);
762         }
763 }
764 int response_end_inuse(struct appdata *ad)
765 {
766 _D("func\n");
767         Eina_List *l, *l_next;
768         struct _task_info *info;
769         Elm_Object_Item *egi;
770
771         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
772
773         ad->ending = EINA_TRUE;
774
775         EINA_LIST_FOREACH_SAFE(ad->applist[TS_INUSE], l, l_next, info) {
776                 _D("applist pid : %d", info->pid);
777                 if (info->it == g_egi) {
778                         _D("matched applist pid : %d", info->pid);
779                         if (info->pid > 0) {
780                                 if (aul_terminate_pid(info->pid) < 0) {
781                                         kill(info->pid, SIGKILL);
782                                 }
783                         }
784                         break;
785                 }
786         }
787         ad->ending = EINA_FALSE;
788
789         return 0;
790 }
791
792 Eina_Bool _refresh_idler_cb(void *data)
793 {
794 _D("func\n");
795         struct appdata *ad = (struct appdata *)data;
796         retvm_if(data == NULL, ECORE_CALLBACK_CANCEL, "Invalid argument: appdata is NULL\n:");
797
798         _del_popup_timer(ad);
799         _del_progressbar(ad);
800         refresh_app_info(ad);
801         return ECORE_CALLBACK_CANCEL;
802 }
803
804 int response_end_all_inuse(struct appdata *ad)
805 {
806         Eina_List *l;
807         struct _task_info *info;
808
809         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
810
811         ad->ending = EINA_TRUE;
812
813         if(ad->update_timer) {
814                 ecore_timer_del(ad->update_timer);
815                 ad->update_timer = NULL;
816         }
817
818         ad->endcnt = eina_list_count(ad->applist[TS_INUSE]);
819         _D("set end count (%d)\n", ad->endcnt);
820
821         EINA_LIST_FOREACH(ad->applist[TS_INUSE], l, info) {
822                 if (info != NULL) {
823                         _D("applist pid : %d", info->pid);
824                         if (info->pid > 0) {
825                                 if (aul_terminate_pid(info->pid) < 0) {
826                                         kill(info->pid, SIGKILL);
827                                 }
828                                 _D("terminated\n");
829                         }
830                 }
831         }
832         ad->ending = EINA_FALSE;
833         return 0;
834 }
835
836 int response_del_history(struct appdata *ad)
837 {
838         Eina_List *l, *l_next;
839         struct _task_info *info;
840         Elm_Object_Item *egi;
841
842         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
843
844         _show_progressbar(ad);
845         EINA_LIST_FOREACH_SAFE(ad->applist[TS_HISTORY], l, l_next, info) {
846                 _D("history applist pid : %d", info->pid);
847                 if (info->it == g_egi) {
848
849                         if (rua_init() == -1) {
850                                 break;
851                         }
852                         rua_delete_history_with_pkgname(info->pkg_name);
853                         rua_fini();
854
855                         ad->applist[TS_HISTORY] =
856                             eina_list_remove_list(ad->applist[TS_HISTORY], l);
857
858                         if (info->b) {
859                                 bundle_free(info->b);
860                         }
861
862                         elm_object_item_del(info->it);
863                         taskmanager_free_info(info);
864                         break;
865                 }
866         }
867         alert_app_info(ad);
868         refresh_app_info(ad);
869         _del_popup_timer(ad);
870         _del_progressbar(ad);
871
872         ad->mode = MODE_NONE;
873         return 0;
874 }
875
876 int response_del_all_history(struct appdata *ad)
877 {
878         Eina_List *l;
879         struct _task_info *info;
880
881         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
882
883         if(ad->update_timer) {
884                 _D("update timer is deleted\n");
885                 ecore_timer_del(ad->update_timer);
886                 ad->update_timer = NULL;
887         }
888
889
890         _show_progressbar(ad);
891
892         if (rua_init() == -1) {
893                 return -1;
894         }
895
896         EINA_LIST_FOREACH(ad->applist[TS_HISTORY], l, info) {
897                 if (info != NULL) {
898                         rua_delete_history_with_pkgname(info->pkg_name);
899                 }
900         }
901
902         if (eina_list_count(ad->applist[TS_INUSE]) == 0) {
903                 rua_clear_history();
904         }
905
906         rua_fini();
907         refresh_app_info(ad);
908         _del_popup_timer(ad);
909         _del_progressbar(ad);
910
911         ad->mode = MODE_NONE;
912         return 0;
913 }
914
915 int response_kill_inuse(struct appdata *ad)
916 {
917         Eina_List *l, *l_next;
918         struct _task_info *info;
919         Elm_Object_Item *egi;
920
921         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
922
923         _show_progressbar(ad);
924
925         EINA_LIST_FOREACH_SAFE(ad->applist[TS_INUSE], l, l_next, info) {
926                 _D("kill applist pid : %d", info->pid);
927                 if (info->it == g_egi) {
928                         if (info->pid > 0) {
929                                 kill(info->pid, SIGKILL);
930                         }
931
932                         ad->applist[TS_INUSE] =
933                             eina_list_remove_list(ad->applist[TS_INUSE], l);
934                         taskmanager_free_info(info);
935                         break;
936                 }
937         }
938         refresh_app_info(ad);
939         _del_progressbar(ad);
940
941         return 0;
942 }
943
944 int response_kill_all_inuse(struct appdata *ad)
945 {
946         Eina_List *l;
947         struct _task_info *info;
948
949         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
950
951         _show_progressbar(ad);
952
953         EINA_LIST_FOREACH(ad->applist[TS_INUSE], l, info) {
954                 _D("kill all applist pid : %d", info->pid);
955                 if (info != NULL) {
956                         if (info->pid > 0) {
957                                 kill(info->pid, SIGKILL);
958                         }
959                 }
960         }
961         refresh_app_info(ad);
962         _del_progressbar(ad);
963
964         return 0;
965 }
966