4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <libsyscommon/list.h>
23 #include "feedback-ids.h"
27 static GList *dev_head;
29 void add_device(const struct device_ops *dev)
31 SYS_G_LIST_APPEND(dev_head, (struct device_ops*)dev);
34 //LCOV_EXCL_START System Error
35 void remove_device(const struct device_ops *dev)
37 SYS_G_LIST_REMOVE(dev_head, (struct device_ops*)dev);
41 const struct device_ops *find_device(int type)
44 const struct device_ops *dev;
46 SYS_G_LIST_FOREACH(dev_head, elem, dev) {
47 if (dev->type == type)
53 void devices_init(void)
56 const struct device_ops *dev;
58 SYS_G_LIST_FOREACH(dev_head, elem, dev) {
59 _D("[%s] initialize", dev->name);
65 void devices_exit(void)
68 const struct device_ops *dev;
70 SYS_G_LIST_FOREACH(dev_head, elem, dev) {
71 _D("[%s] deinitialize", dev->name);
78 int devices_play(int pattern, bool always)
81 const struct device_ops *dev;
82 int ret, prev = -EPERM;
84 SYS_G_LIST_FOREACH(dev_head, elem, dev) {
86 ret = dev->play(pattern, always);
87 if ((prev < 0 && ret == 0) ||
88 (prev == 0 && ret < 0))
90 else if ((prev < 0 && ret == -ENOTSUP) ||
91 (prev == -ENOTSUP && ret < 0))
103 int devices_play_soundpath(int pattern, const char *soundpath, bool always)
106 const struct device_ops *dev;
107 int ret, prev = -EPERM;
109 SYS_G_LIST_FOREACH(dev_head, elem, dev) {
110 if (dev->type == FEEDBACK_TYPE_SOUND) {
112 ret = dev->play_path(pattern, soundpath, always);
114 continue; //LCOV_EXCL_LINE
117 ret = dev->play(pattern, always);
119 continue; //LCOV_EXCL_LINE
122 if ((prev < 0 && ret == 0) ||
123 (prev == 0 && ret < 0))
125 else if ((prev < 0 && ret == -ENOTSUP) ||
126 (prev == -ENOTSUP && ret < 0))
137 int devices_stop(void)
140 const struct device_ops *dev;
143 SYS_G_LIST_FOREACH(dev_head, elem, dev) {
152 int devices_stop_by_type(feedback_type_e feedback_type)
155 const struct device_ops *dev;
157 SYS_G_LIST_FOREACH(dev_head, elem, dev) {
158 if (dev->type == feedback_type)