Initialize Tizen 2.3
[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                 initialized = 1;
47                 return;
48         }
49
50         input_data = (struct apps_data *)data;
51         if (input_data == NULL || input_data->name == NULL)
52                 return;
53
54         DD_LIST_FOREACH(apps_head, elem, dev) {
55                 if (!strncmp(dev->name, (char *)input_data->name, strlen(dev->name))) {
56                         if (dev->launch)
57                                 dev->launch(data);
58                         break;
59                 }
60         }
61 }
62
63 static void apps_exit(void *data)
64 {
65         const struct apps_ops*dev;
66         dd_list *elem;
67         struct apps_data *input_data;
68
69         input_data = (struct apps_data *)data;
70         if (input_data == NULL || input_data->name == NULL)
71                 return;
72
73         DD_LIST_FOREACH(apps_head, elem, dev) {
74                 if (!strncmp(dev->name, (char *)input_data->name, strlen(dev->name))) {
75                         if (dev->terminate)
76                                 dev->terminate(data);
77                         break;
78                 }
79         }
80 }
81
82 static const struct device_ops apps_device_ops = {
83         .priority = DEVICE_PRIORITY_NORMAL,
84         .name     = "apps",
85         .init     = apps_init,
86         .exit     = apps_exit,
87 };
88
89 DEVICE_OPS_REGISTER(&apps_device_ops)