tizen 2.3 release
[framework/system/deviced.git] / src / apps / apps.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <vconf.h>
20 #include "core/log.h"
21 #include "apps.h"
22 #include "core/devices.h"
23 #include "core/list.h"
24
25 static dd_list *apps_head = NULL;
26
27 void add_apps(const struct apps_ops *dev)
28 {
29         _I("add %s", dev->name);
30         DD_LIST_APPEND(apps_head, (void*)dev);
31 }
32
33 void remove_apps(const struct apps_ops *dev)
34 {
35         DD_LIST_REMOVE(apps_head, (void*)dev);
36 }
37
38 static void apps_init(void *data)
39 {
40         const struct apps_ops*dev;
41         dd_list *elem;
42         struct apps_data *input_data;
43         static int initialized =0;
44
45         if (!initialized) {
46                 DD_LIST_FOREACH(apps_head, elem, dev) {
47                         _D("[%s] initialize", dev->name);
48                         if (dev->init)
49                                 dev->init();
50                 }
51                 initialized = 1;
52                 return;
53         }
54
55         input_data = (struct apps_data *)data;
56         if (input_data == NULL || input_data->name == NULL)
57                 return;
58
59         DD_LIST_FOREACH(apps_head, elem, dev) {
60                 if (!strncmp(dev->name, (char *)input_data->name, strlen(dev->name))) {
61                         if (dev->launch)
62                                 dev->launch(data);
63                         break;
64                 }
65         }
66 }
67
68 static void apps_exit(void *data)
69 {
70         const struct apps_ops*dev;
71         dd_list *elem;
72         struct apps_data *input_data;
73
74         input_data = (struct apps_data *)data;
75         if (input_data == NULL || input_data->name == NULL)
76                 return;
77
78         DD_LIST_FOREACH(apps_head, elem, dev) {
79                 if (!strncmp(dev->name, (char *)input_data->name, strlen(dev->name))) {
80                         if (dev->terminate)
81                                 dev->terminate(data);
82                         break;
83                 }
84         }
85 }
86
87 static const struct device_ops apps_device_ops = {
88         .priority = DEVICE_PRIORITY_NORMAL,
89         .name     = "apps",
90         .init     = apps_init,
91         .exit     = apps_exit,
92 };
93
94 DEVICE_OPS_REGISTER(&apps_device_ops)