Initialize Tizen 2.3
[framework/appfw/aul-1.git] / am_daemon / ac_status.c
1 /*
2  *  aul
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdlib.h>
23 #include <glib.h>
24 #include <aul.h>
25 #include "aul_util.h"
26 #include "simple_util.h"
27
28 GSList *app_status_info_list = NULL;
29
30 int _add_app_status_info_list(char *appid, int pid)
31 {
32         GSList *iter = NULL;
33         app_status_info_t *info_t = NULL;
34
35         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
36         {
37                 info_t = (app_status_info_t *)iter->data;
38                 if(pid == info_t->pid) {
39                         return 0;
40                 }
41         }
42
43         info_t = malloc(sizeof(app_status_info_t));
44         strncpy(info_t->appid, appid, MAX_PACKAGE_STR_SIZE-1);
45         info_t->status = STATUS_LAUNCHING;
46         info_t->pid = pid;
47         app_status_info_list = g_slist_append(app_status_info_list, info_t);
48
49         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
50         {
51                 info_t = (app_status_info_t *)iter->data;
52
53                 _D("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
54         }
55
56         return 0;
57 }
58
59 int _update_app_status_info_list(int pid, int status)
60 {
61         GSList *iter = NULL;
62         app_status_info_t *info_t = NULL;
63
64         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
65         {
66                 info_t = (app_status_info_t *)iter->data;
67                 if(pid == info_t->pid) {
68                         info_t->status = status;
69                         break;
70                 }
71         }
72
73         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
74         {
75                 info_t = (app_status_info_t *)iter->data;
76
77                 _D("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
78         }
79
80         return 0;
81 }
82
83 int _remove_app_status_info_list(int pid)
84 {
85         GSList *iter = NULL;
86         app_status_info_t *info_t = NULL;
87
88         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
89         {
90                 info_t = (app_status_info_t *)iter->data;
91                 if(pid == info_t->pid) {
92                         app_status_info_list = g_slist_remove(app_status_info_list, info_t);
93                         free(info_t);
94                         break;
95                 }
96         }
97
98         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
99         {
100                 info_t = (app_status_info_t *)iter->data;
101
102                 _D("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
103         }
104
105         return 0;
106 }
107