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.
22 #include "feedback-internal.h"
23 #include "feedback-log.h"
26 #define MAX_PATH_LENGTH 256
27 #define NOT_ASSIGNED NULL
30 #define API __attribute__ ((visibility("default")))
33 static feedback_h feedback_handle = NOT_ASSIGNED;
35 API int feedback_initialize()
39 if (feedback_handle != NOT_ASSIGNED) {
40 FEEDBACK_LOG("Already initialized");
41 return FEEDBACK_ERROR_NONE;
44 /* initialize device */
47 err = feedback_init(&feedback_handle);
48 if (FEEDBACK_FAILED(err)) {
49 FEEDBACK_ERROR("feedback_init is failed");
50 return FEEDBACK_ERROR_OPERATION_FAILED;
53 return FEEDBACK_ERROR_NONE;
56 API int feedback_deinitialize()
60 if (feedback_handle == NOT_ASSIGNED) {
61 FEEDBACK_ERROR("Not initialized");
62 return FEEDBACK_ERROR_NOT_INITIALIZED;
65 /* deinitialize device */
68 err = feedback_fini(feedback_handle);
69 if (FEEDBACK_FAILED(err)) {
70 FEEDBACK_ERROR("feedback_fini is failed");
71 return FEEDBACK_ERROR_OPERATION_FAILED;
74 feedback_handle = NOT_ASSIGNED;
75 return FEEDBACK_ERROR_NONE;
78 API int feedback_play(feedback_pattern_e pattern)
82 if (feedback_handle == NOT_ASSIGNED) {
83 FEEDBACK_ERROR("Not initialized");
84 return FEEDBACK_ERROR_NOT_INITIALIZED;
87 if (pattern < FEEDBACK_PATTERN_NONE || pattern >= FEEDBACK_PATTERN_END) {
88 FEEDBACK_ERROR("Invalid parameter : pattern(%d)", pattern);
89 return FEEDBACK_ERROR_INVALID_PARAMETER;
92 if (pattern == FEEDBACK_PATTERN_NONE) {
93 FEEDBACK_LOG("pattern is NONE");
94 return FEEDBACK_ERROR_NONE;
98 devices_play(pattern);
100 err = feedback_play_vibration(feedback_handle, pattern);
101 if (FEEDBACK_FAILED(err)) {
102 FEEDBACK_ERROR("feedback_play_vibration is failed");
103 return FEEDBACK_ERROR_OPERATION_FAILED;
106 return FEEDBACK_ERROR_NONE;
109 API int feedback_play_type(feedback_type_e type, feedback_pattern_e pattern)
111 const struct device_ops *dev;
114 if (feedback_handle == NOT_ASSIGNED) {
115 FEEDBACK_ERROR("Not initialized");
116 return FEEDBACK_ERROR_NOT_INITIALIZED;
119 if (type <= FEEDBACK_TYPE_NONE || type >= FEEDBACK_TYPE_END) {
120 FEEDBACK_ERROR("Invalid parameter : type(%d)", type);
121 return FEEDBACK_ERROR_INVALID_PARAMETER;
124 if (pattern < FEEDBACK_PATTERN_NONE || pattern >= FEEDBACK_PATTERN_END) {
125 FEEDBACK_ERROR("Invalid parameter : pattern(%d)", pattern);
126 return FEEDBACK_ERROR_INVALID_PARAMETER;
129 if (pattern == FEEDBACK_PATTERN_NONE) {
130 FEEDBACK_LOG("pattern is NONE");
131 return FEEDBACK_ERROR_NONE;
135 case FEEDBACK_TYPE_SOUND:
136 dev = find_device(type);
138 err = dev->play(pattern);
140 FEEDBACK_ERROR("feedback_play_sound is failed");
143 case FEEDBACK_TYPE_VIBRATION:
144 err = feedback_play_vibration(feedback_handle, pattern);
145 if (FEEDBACK_FAILED(err))
146 FEEDBACK_ERROR("feedback_play(type:%d) is failed", type);
149 FEEDBACK_ERROR("Invalid parameter : type(%d)", type);
150 return FEEDBACK_ERROR_INVALID_PARAMETER;
153 return FEEDBACK_ERROR_NONE;
156 API int feedback_get_resource_path(feedback_type_e type, feedback_pattern_e pattern, char** path)
158 const struct device_ops *dev;
160 char buf[MAX_PATH_LENGTH] = {0,};
163 FEEDBACK_ERROR("Invalid parameter : path(NULL)");
164 return FEEDBACK_ERROR_INVALID_PARAMETER;
167 if (type <= FEEDBACK_TYPE_NONE || type >= FEEDBACK_TYPE_END) {
168 FEEDBACK_ERROR("Invalid parameter : type(%d)", type);
169 return FEEDBACK_ERROR_INVALID_PARAMETER;
172 if (pattern <= FEEDBACK_PATTERN_NONE || pattern >= FEEDBACK_PATTERN_END) {
173 FEEDBACK_ERROR("Invalid parameter : pattern(%d)", pattern);
174 return FEEDBACK_ERROR_INVALID_PARAMETER;
177 if (type == FEEDBACK_TYPE_SOUND) {
178 dev = find_device(type);
180 err = dev->get_path(pattern, buf, sizeof(buf));
181 } else if (type == FEEDBACK_TYPE_VIBRATION)
182 err = feedback_get_path(type, pattern, buf, MAX_PATH_LENGTH);
184 if (FEEDBACK_FAILED(err)) {
185 FEEDBACK_ERROR("feedback_get_path is failed");
186 return FEEDBACK_ERROR_OPERATION_FAILED;
190 return FEEDBACK_ERROR_NONE;
193 API int feedback_set_resource_path(feedback_type_e type, feedback_pattern_e pattern, char* path)
195 const struct device_ops *dev;
199 FEEDBACK_ERROR("Invalid parameter : path(NULL)");
200 return FEEDBACK_ERROR_INVALID_PARAMETER;
203 if (type <= FEEDBACK_TYPE_NONE || type >= FEEDBACK_TYPE_END) {
204 FEEDBACK_ERROR("Invalid parameter : type(%d)", type);
205 return FEEDBACK_ERROR_INVALID_PARAMETER;
208 if (pattern <= FEEDBACK_PATTERN_NONE || pattern >= FEEDBACK_PATTERN_END) {
209 FEEDBACK_ERROR("Invalid parameter : pattern(%d)", pattern);
210 return FEEDBACK_ERROR_INVALID_PARAMETER;
213 if (type == FEEDBACK_TYPE_SOUND) {
214 dev = find_device(type);
216 err = dev->set_path(pattern, path);
217 } else if (type == FEEDBACK_TYPE_VIBRATION)
218 err = feedback_set_path(type, pattern, path);
220 if (FEEDBACK_FAILED(err)) {
221 FEEDBACK_ERROR("feedback_set_path is failed");
222 return FEEDBACK_ERROR_OPERATION_FAILED;
225 return FEEDBACK_ERROR_NONE;