3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
30 #define API __attribute__ ((visibility("default")))
33 static unsigned int init_cnt;
34 static pthread_mutex_t fmutex = PTHREAD_MUTEX_INITIALIZER;
36 API int feedback_initialize(void)
38 pthread_mutex_lock(&fmutex);
40 _E("there is no valid profile module.");
41 pthread_mutex_unlock(&fmutex);
42 return FEEDBACK_ERROR_NOT_SUPPORTED;
46 pthread_mutex_unlock(&fmutex);
47 return FEEDBACK_ERROR_NONE;
50 /* initialize device */
53 /* initialize profile feature */
57 pthread_mutex_unlock(&fmutex);
58 return FEEDBACK_ERROR_NONE;
61 API int feedback_deinitialize(void)
63 pthread_mutex_lock(&fmutex);
65 pthread_mutex_unlock(&fmutex);
66 return FEEDBACK_ERROR_NOT_INITIALIZED;
70 pthread_mutex_unlock(&fmutex);
71 return FEEDBACK_ERROR_NONE;
74 /* deinitialize device */
77 /* deinitialize profile feature */
81 pthread_mutex_unlock(&fmutex);
82 return FEEDBACK_ERROR_NONE;
85 API int feedback_play(feedback_pattern_e pattern)
91 /* check initialize */
92 pthread_mutex_lock(&fmutex);
94 _E("Not initialized");
95 pthread_mutex_unlock(&fmutex);
96 return FEEDBACK_ERROR_NOT_INITIALIZED;
98 pthread_mutex_unlock(&fmutex);
100 if (pattern <= FEEDBACK_PATTERN_NONE ||
101 pattern >= profile->max_pattern) {
102 _E("Invalid parameter : pattern(%d)", pattern);
103 return FEEDBACK_ERROR_INVALID_PARAMETER;
106 /* if you need to switch pattern */
107 if (profile->get_switched_pattern) {
108 result = profile->get_switched_pattern(pattern, &switched);
110 _W("pattern is changed : (%s) -> (%s)",
111 profile->str_pattern[pattern], profile->str_pattern[switched]);
116 /* play all device */
117 err = devices_play(pattern);
119 * devices_play() returns error even if all devices are failed.
120 * It means if to play anything is successful,
121 * this function regards as success.
124 return FEEDBACK_ERROR_NOT_SUPPORTED;
126 return FEEDBACK_ERROR_OPERATION_FAILED;
128 return FEEDBACK_ERROR_NONE;
131 API int feedback_play_type(feedback_type_e type, feedback_pattern_e pattern)
133 const struct device_ops *dev;
138 /* check initialize */
139 pthread_mutex_lock(&fmutex);
141 _E("Not initialized");
142 pthread_mutex_unlock(&fmutex);
143 return FEEDBACK_ERROR_NOT_INITIALIZED;
145 pthread_mutex_unlock(&fmutex);
147 if (type <= FEEDBACK_TYPE_NONE ||
148 type >= profile->max_type) {
149 _E("Invalid parameter : type(%d)", type);
150 return FEEDBACK_ERROR_INVALID_PARAMETER;
153 if (pattern <= FEEDBACK_PATTERN_NONE ||
154 pattern >= profile->max_pattern) {
155 _E("Invalid parameter : pattern(%d)", pattern);
156 return FEEDBACK_ERROR_INVALID_PARAMETER;
159 /* if you need to switch pattern */
160 if (profile->get_switched_pattern) {
161 result = profile->get_switched_pattern(pattern, &switched);
163 _W("pattern is changed : (%s) -> (%s)",
164 profile->str_pattern[pattern], profile->str_pattern[switched]);
169 /* play proper device */
170 dev = find_device(type);
172 _E("Not supported device : type(%s)", profile->str_type[type]);
173 return FEEDBACK_ERROR_NOT_SUPPORTED;
176 err = dev->play(pattern);
178 return FEEDBACK_ERROR_NOT_SUPPORTED;
179 else if (err == -ECOMM)
180 return FEEDBACK_ERROR_PERMISSION_DENIED;
182 return FEEDBACK_ERROR_OPERATION_FAILED;
184 return FEEDBACK_ERROR_NONE;
187 API int feedback_stop(void)
191 /* check initialize */
192 pthread_mutex_lock(&fmutex);
194 _E("Not initialized");
195 pthread_mutex_unlock(&fmutex);
196 return FEEDBACK_ERROR_NOT_INITIALIZED;
198 pthread_mutex_unlock(&fmutex);
200 /* stop all device */
201 err = devices_stop();
203 return FEEDBACK_ERROR_NOT_SUPPORTED;
204 else if (err == -ECOMM)
205 return FEEDBACK_ERROR_PERMISSION_DENIED;
207 return FEEDBACK_ERROR_OPERATION_FAILED;
209 return FEEDBACK_ERROR_NONE;
212 API int feedback_is_supported_pattern(feedback_type_e type, feedback_pattern_e pattern, bool *status)
214 const struct device_ops *dev;
220 /* check initialize */
221 pthread_mutex_lock(&fmutex);
223 _E("Not initialized");
224 pthread_mutex_unlock(&fmutex);
225 return FEEDBACK_ERROR_NOT_INITIALIZED;
227 pthread_mutex_unlock(&fmutex);
230 _E("Invalid parameter : status(NULL)");
231 return FEEDBACK_ERROR_INVALID_PARAMETER;
234 if (type <= FEEDBACK_TYPE_NONE ||
235 type >= profile->max_type) {
236 _E("Invalid parameter : type(%d)", type);
237 return FEEDBACK_ERROR_INVALID_PARAMETER;
240 if (pattern <= FEEDBACK_PATTERN_NONE ||
241 pattern >= profile->max_pattern) {
242 _E("Invalid parameter : pattern(%d)", pattern);
243 return FEEDBACK_ERROR_INVALID_PARAMETER;
246 /* if you need to switch pattern */
247 if (profile->get_switched_pattern) {
248 result = profile->get_switched_pattern(pattern, &switched);
250 _W("pattern is changed : (%s) -> (%s)",
251 profile->str_pattern[pattern], profile->str_pattern[switched]);
256 /* play proper device */
257 dev = find_device(type);
259 _E("Not supported device : type(%s)", profile->str_type[type]);
260 return FEEDBACK_ERROR_NOT_SUPPORTED;
263 err = dev->is_supported(pattern, &supported);
265 _E("fail to invoke is_supported() : pattern(%s)", profile->str_pattern[pattern]);
266 return FEEDBACK_ERROR_OPERATION_FAILED;
271 return FEEDBACK_ERROR_NONE;
275 API int feedback_play_type_by_name(char *type, char *pattern)
277 feedback_type_e etype;
278 feedback_pattern_e epattern;
282 if (!type || !pattern) {
283 _E("Invalid parameter : type(%x), pattern(%x)", type, pattern);
284 return FEEDBACK_ERROR_INVALID_PARAMETER;
287 type_max = profile->max_type;
288 for (etype = 0; etype < type_max; ++etype) {
289 if (!strncmp(type, profile->str_type[etype], strlen(type)))
293 if (etype == type_max) {
294 _E("Invalid parameter : type(%s)", type);
295 return FEEDBACK_ERROR_INVALID_PARAMETER;
298 pattern_max = profile->max_pattern;
299 for (epattern = 0; epattern < pattern_max; ++epattern) {
300 if (!strncmp(pattern, profile->str_pattern[epattern], strlen(pattern)))
304 if (epattern == pattern_max) {
305 _E("Invalid parameter : pattern(%s)", pattern);
306 return FEEDBACK_ERROR_INVALID_PARAMETER;
309 return feedback_play_type(etype, epattern);
312 API int feedback_get_resource_path(feedback_type_e type, feedback_pattern_e pattern, char** path)
314 const struct device_ops *dev;
315 char buf[PATH_MAX] = {0,};
319 _E("Invalid parameter : path(NULL)");
320 return FEEDBACK_ERROR_INVALID_PARAMETER;
323 if (type <= FEEDBACK_TYPE_NONE ||
324 type >= profile->max_type) {
325 _E("Invalid parameter : type(%d)", type);
326 return FEEDBACK_ERROR_INVALID_PARAMETER;
329 if (pattern <= FEEDBACK_PATTERN_NONE ||
330 pattern >= profile->max_pattern) {
331 _E("Invalid parameter : pattern(%d)", pattern);
332 return FEEDBACK_ERROR_INVALID_PARAMETER;
335 /* proper device get path */
336 dev = find_device(type);
338 err = dev->get_path(pattern, buf, sizeof(buf));
340 return FEEDBACK_ERROR_OPERATION_FAILED;
344 return FEEDBACK_ERROR_NONE;
347 API int feedback_set_resource_path(feedback_type_e type, feedback_pattern_e pattern, char *path)
349 const struct device_ops *dev;
352 if (type <= FEEDBACK_TYPE_NONE ||
353 type >= profile->max_type) {
354 _E("Invalid parameter : type(%d)", type);
355 return FEEDBACK_ERROR_INVALID_PARAMETER;
358 if (pattern <= FEEDBACK_PATTERN_NONE ||
359 pattern >= profile->max_pattern) {
360 _E("Invalid parameter : pattern(%d)", pattern);
361 return FEEDBACK_ERROR_INVALID_PARAMETER;
364 /* proper device set path */
365 dev = find_device(type);
367 err = dev->set_path(pattern, path);
369 return FEEDBACK_ERROR_OPERATION_FAILED;
372 return FEEDBACK_ERROR_NONE;