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")))
35 API int feedback_initialize(void)
38 return FEEDBACK_ERROR_NONE;
41 _E("there is no valid profile module.");
42 return FEEDBACK_ERROR_NOT_SUPPORTED;
45 /* initialize device */
48 /* initialize profile feature */
53 return FEEDBACK_ERROR_NONE;
56 API int feedback_deinitialize(void)
59 return FEEDBACK_ERROR_NOT_INITIALIZED;
61 /* deinitialize device */
64 /* deinitialize profile feature */
69 return FEEDBACK_ERROR_NONE;
72 API int feedback_play(feedback_pattern_e pattern)
78 /* check initialize */
80 _E("Not initialized");
81 return FEEDBACK_ERROR_NOT_INITIALIZED;
84 if (pattern <= FEEDBACK_PATTERN_NONE ||
85 pattern >= profile->max_pattern) {
86 _E("Invalid parameter : pattern(%d)", pattern);
87 return FEEDBACK_ERROR_INVALID_PARAMETER;
90 /* if you need to switch pattern */
91 if (profile->get_switched_pattern) {
92 result = profile->get_switched_pattern(pattern, &switched);
94 _W("pattern is changed : (%s) -> (%s)",
95 profile->str_pattern[pattern], profile->str_pattern[switched]);
100 /* play all device */
101 err = devices_play(pattern);
103 * devices_play() returns error even if all devices are failed.
104 * It means if to play anything is successful,
105 * this function regards as success.
108 return FEEDBACK_ERROR_NOT_SUPPORTED;
110 return FEEDBACK_ERROR_OPERATION_FAILED;
112 return FEEDBACK_ERROR_NONE;
115 API int feedback_play_type(feedback_type_e type, feedback_pattern_e pattern)
117 const struct device_ops *dev;
122 /* check initialize */
124 _E("Not initialized");
125 return FEEDBACK_ERROR_NOT_INITIALIZED;
128 if (type <= FEEDBACK_TYPE_NONE ||
129 type >= profile->max_type) {
130 _E("Invalid parameter : type(%d)", type);
131 return FEEDBACK_ERROR_INVALID_PARAMETER;
134 if (pattern <= FEEDBACK_PATTERN_NONE ||
135 pattern >= profile->max_pattern) {
136 _E("Invalid parameter : pattern(%d)", pattern);
137 return FEEDBACK_ERROR_INVALID_PARAMETER;
140 /* if you need to switch pattern */
141 if (profile->get_switched_pattern) {
142 result = profile->get_switched_pattern(pattern, &switched);
144 _W("pattern is changed : (%s) -> (%s)",
145 profile->str_pattern[pattern], profile->str_pattern[switched]);
150 /* play proper device */
151 dev = find_device(type);
153 _E("Not supported device : type(%s)", profile->str_type[type]);
154 return FEEDBACK_ERROR_NOT_SUPPORTED;
157 err = dev->play(pattern);
159 return FEEDBACK_ERROR_NOT_SUPPORTED;
160 else if (err == -ECOMM)
161 return FEEDBACK_ERROR_PERMISSION_DENIED;
163 return FEEDBACK_ERROR_OPERATION_FAILED;
165 return FEEDBACK_ERROR_NONE;
168 API int feedback_stop(void)
172 /* check initialize */
174 _E("Not initialized");
175 return FEEDBACK_ERROR_NOT_INITIALIZED;
178 /* stop all device */
179 err = devices_stop();
181 return FEEDBACK_ERROR_NOT_SUPPORTED;
182 else if (err == -ECOMM)
183 return FEEDBACK_ERROR_PERMISSION_DENIED;
185 return FEEDBACK_ERROR_OPERATION_FAILED;
187 return FEEDBACK_ERROR_NONE;
190 API int feedback_is_supported_pattern(feedback_type_e type, feedback_pattern_e pattern, bool *status)
192 const struct device_ops *dev;
198 /* check initialize */
200 _E("Not initialized");
201 return FEEDBACK_ERROR_NOT_INITIALIZED;
205 _E("Invalid parameter : status(NULL)");
206 return FEEDBACK_ERROR_INVALID_PARAMETER;
209 if (type <= FEEDBACK_TYPE_NONE ||
210 type >= profile->max_type) {
211 _E("Invalid parameter : type(%d)", type);
212 return FEEDBACK_ERROR_INVALID_PARAMETER;
215 if (pattern <= FEEDBACK_PATTERN_NONE ||
216 pattern >= profile->max_pattern) {
217 _E("Invalid parameter : pattern(%d)", pattern);
218 return FEEDBACK_ERROR_INVALID_PARAMETER;
221 /* if you need to switch pattern */
222 if (profile->get_switched_pattern) {
223 result = profile->get_switched_pattern(pattern, &switched);
225 _W("pattern is changed : (%s) -> (%s)",
226 profile->str_pattern[pattern], profile->str_pattern[switched]);
231 /* play proper device */
232 dev = find_device(type);
234 _E("Not supported device : type(%s)", profile->str_type[type]);
235 return FEEDBACK_ERROR_NOT_SUPPORTED;
238 err = dev->is_supported(pattern, &supported);
240 _E("fail to invoke is_supported() : pattern(%s)", profile->str_pattern[pattern]);
241 return FEEDBACK_ERROR_OPERATION_FAILED;
244 return FEEDBACK_ERROR_NONE;
248 API int feedback_play_type_by_name(char *type, char *pattern)
250 feedback_type_e etype;
251 feedback_pattern_e epattern;
255 if (!type || !pattern) {
256 _E("Invalid parameter : type(%x), pattern(%x)", type, pattern);
257 return FEEDBACK_ERROR_INVALID_PARAMETER;
260 type_max = profile->max_type;
261 for (etype = 0; etype < type_max; ++etype) {
262 if (!strncmp(type, profile->str_type[etype], strlen(type)))
266 if (etype == type_max) {
267 _E("Invalid parameter : type(%s)", type);
268 return FEEDBACK_ERROR_INVALID_PARAMETER;
271 pattern_max = profile->max_pattern;
272 for (epattern = 0; epattern < pattern_max; ++epattern) {
273 if (!strncmp(pattern, profile->str_pattern[epattern], strlen(pattern)))
277 if (epattern == pattern_max) {
278 _E("Invalid parameter : pattern(%d)", pattern);
279 return FEEDBACK_ERROR_INVALID_PARAMETER;
282 return feedback_play_type(etype, epattern);
285 API int feedback_get_resource_path(feedback_type_e type, feedback_pattern_e pattern, char** path)
287 const struct device_ops *dev;
288 char buf[PATH_MAX] = {0,};
292 _E("Invalid parameter : path(NULL)");
293 return FEEDBACK_ERROR_INVALID_PARAMETER;
296 if (type <= FEEDBACK_TYPE_NONE ||
297 type >= profile->max_type) {
298 _E("Invalid parameter : type(%d)", type);
299 return FEEDBACK_ERROR_INVALID_PARAMETER;
302 if (pattern <= FEEDBACK_PATTERN_NONE ||
303 pattern >= profile->max_pattern) {
304 _E("Invalid parameter : pattern(%d)", pattern);
305 return FEEDBACK_ERROR_INVALID_PARAMETER;
308 /* proper device get path */
309 dev = find_device(type);
311 err = dev->get_path(pattern, buf, sizeof(buf));
313 return FEEDBACK_ERROR_OPERATION_FAILED;
317 return FEEDBACK_ERROR_NONE;
320 API int feedback_set_resource_path(feedback_type_e type, feedback_pattern_e pattern, char *path)
322 const struct device_ops *dev;
325 if (type <= FEEDBACK_TYPE_NONE ||
326 type >= profile->max_type) {
327 _E("Invalid parameter : type(%d)", type);
328 return FEEDBACK_ERROR_INVALID_PARAMETER;
331 if (pattern <= FEEDBACK_PATTERN_NONE ||
332 pattern >= profile->max_pattern) {
333 _E("Invalid parameter : pattern(%d)", pattern);
334 return FEEDBACK_ERROR_INVALID_PARAMETER;
337 /* proper device set path */
338 dev = find_device(type);
340 err = dev->set_path(pattern, path);
342 return FEEDBACK_ERROR_OPERATION_FAILED;
345 return FEEDBACK_ERROR_NONE;