seperate sound device from feedback internal code
[platform/core/system/libsvi.git] / src / devices.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 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
20 #include <stdio.h>
21 #include <glib.h>
22
23 #include "devices.h"
24 #include "feedback-str.h"
25 #include "feedback-log.h"
26
27 #define DD_LIST_PREPEND(a, b)           \
28         a = g_list_prepend(a, b)
29 #define DD_LIST_APPEND(a, b)            \
30         a = g_list_append(a, b)
31 #define DD_LIST_REMOVE(a, b)            \
32         a = g_list_remove(a, b)
33 #define DD_LIST_FOREACH(head, elem, node)       \
34         for (elem = head; elem && ((node = elem->data) != NULL); elem = elem->next, node = NULL)
35
36 typedef GList dd_list;
37 static dd_list *dev_head;
38
39 void add_device(const struct device_ops *dev)
40 {
41         DD_LIST_APPEND(dev_head, (struct device_ops*)dev);
42 }
43
44 void remove_device(const struct device_ops *dev)
45 {
46         DD_LIST_REMOVE(dev_head, (struct device_ops*)dev);
47 }
48
49 const struct device_ops *find_device(int type)
50 {
51         dd_list *elem;
52         const struct device_ops *dev;
53
54         DD_LIST_FOREACH(dev_head, elem, dev) {
55                 if (dev->type == type)
56                         return dev;
57         }
58         return NULL;
59 }
60
61 void devices_init(void)
62 {
63         dd_list *elem;
64         const struct device_ops *dev;
65
66         DD_LIST_FOREACH(dev_head, elem, dev) {
67                 FEEDBACK_LOG("[%s] initialize", str_type[dev->type]);
68                 if (dev->init)
69                         dev->init();
70         }
71 }
72
73 void devices_exit(void)
74 {
75         dd_list *elem;
76         const struct device_ops *dev;
77
78         DD_LIST_FOREACH(dev_head, elem, dev) {
79                 FEEDBACK_LOG("[%s] deinitialize", str_type[dev->type]);
80                 if (dev->exit)
81                         dev->exit();
82         }
83 }
84
85 void devices_play(int pattern)
86 {
87         dd_list *elem;
88         const struct device_ops *dev;
89
90         DD_LIST_FOREACH(dev_head, elem, dev) {
91                 if (dev->play)
92                         dev->play(pattern);
93         }
94 }