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"
25 #define MAX_PATH_LENGTH 256
26 #define NOT_ASSIGNED NULL
29 #define API __attribute__ ((visibility("default")))
32 static feedback_h feedback_handle = NOT_ASSIGNED;
34 API int feedback_initialize()
38 if (feedback_handle != NOT_ASSIGNED) {
39 FEEDBACK_LOG("Already initialized");
40 return FEEDBACK_ERROR_NONE;
43 err = feedback_init(&feedback_handle);
44 if (FEEDBACK_FAILED(err)) {
45 FEEDBACK_ERROR("feedback_init is failed");
46 return FEEDBACK_ERROR_OPERATION_FAILED;
49 return FEEDBACK_ERROR_NONE;
52 API int feedback_deinitialize()
56 if (feedback_handle == NOT_ASSIGNED) {
57 FEEDBACK_ERROR("Not initialized");
58 return FEEDBACK_ERROR_NOT_INITIALIZED;
61 err = feedback_fini(feedback_handle);
62 if (FEEDBACK_FAILED(err)) {
63 FEEDBACK_ERROR("feedback_fini is failed");
64 return FEEDBACK_ERROR_OPERATION_FAILED;
67 feedback_handle = NOT_ASSIGNED;
68 return FEEDBACK_ERROR_NONE;
71 API int feedback_play(feedback_pattern_e pattern)
75 if (feedback_handle == NOT_ASSIGNED) {
76 FEEDBACK_ERROR("Not initialized");
77 return FEEDBACK_ERROR_NOT_INITIALIZED;
80 if (pattern < FEEDBACK_PATTERN_NONE || pattern >= FEEDBACK_PATTERN_END) {
81 FEEDBACK_ERROR("Invalid parameter : pattern(%d)", pattern);
82 return FEEDBACK_ERROR_INVALID_PARAMETER;
85 if (pattern == FEEDBACK_PATTERN_NONE) {
86 FEEDBACK_LOG("pattern is NONE");
87 return FEEDBACK_ERROR_NONE;
90 err = feedback_play_sound(feedback_handle, pattern);
91 if (FEEDBACK_FAILED(err)) {
92 FEEDBACK_ERROR("feedback_play_sound is failed");
93 return FEEDBACK_ERROR_OPERATION_FAILED;
96 err = feedback_play_vibration(feedback_handle, pattern);
97 if (FEEDBACK_FAILED(err)) {
98 FEEDBACK_ERROR("feedback_play_vibration is failed");
99 return FEEDBACK_ERROR_OPERATION_FAILED;
102 return FEEDBACK_ERROR_NONE;
105 API int feedback_play_type(feedback_type_e type, feedback_pattern_e pattern)
109 if (feedback_handle == NOT_ASSIGNED) {
110 FEEDBACK_ERROR("Not initialized");
111 return FEEDBACK_ERROR_NOT_INITIALIZED;
114 if (type <= FEEDBACK_TYPE_NONE || type >= FEEDBACK_TYPE_END) {
115 FEEDBACK_ERROR("Invalid parameter : type(%d)", type);
116 return FEEDBACK_ERROR_INVALID_PARAMETER;
119 if (pattern < FEEDBACK_PATTERN_NONE || pattern >= FEEDBACK_PATTERN_END) {
120 FEEDBACK_ERROR("Invalid parameter : pattern(%d)", pattern);
121 return FEEDBACK_ERROR_INVALID_PARAMETER;
124 if (pattern == FEEDBACK_PATTERN_NONE) {
125 FEEDBACK_LOG("pattern is NONE");
126 return FEEDBACK_ERROR_NONE;
130 case FEEDBACK_TYPE_SOUND:
131 err = feedback_play_sound(feedback_handle, pattern);
133 case FEEDBACK_TYPE_VIBRATION:
134 err = feedback_play_vibration(feedback_handle, pattern);
137 FEEDBACK_ERROR("Invalid parameter : type(%d)", type);
138 return FEEDBACK_ERROR_INVALID_PARAMETER;
141 if (FEEDBACK_FAILED(err)) {
142 FEEDBACK_ERROR("feedback_play(type:%d) is failed", type);
143 return FEEDBACK_ERROR_OPERATION_FAILED;
146 return FEEDBACK_ERROR_NONE;
149 API int feedback_get_resource_path(feedback_type_e type, feedback_pattern_e pattern, char** path)
152 char buf[MAX_PATH_LENGTH] = {0,};
155 FEEDBACK_ERROR("Invalid parameter : path(NULL)");
156 return FEEDBACK_ERROR_INVALID_PARAMETER;
159 if (type <= FEEDBACK_TYPE_NONE || type >= FEEDBACK_TYPE_END) {
160 FEEDBACK_ERROR("Invalid parameter : type(%d)", type);
161 return FEEDBACK_ERROR_INVALID_PARAMETER;
164 if (pattern <= FEEDBACK_PATTERN_NONE || pattern >= FEEDBACK_PATTERN_END) {
165 FEEDBACK_ERROR("Invalid parameter : pattern(%d)", pattern);
166 return FEEDBACK_ERROR_INVALID_PARAMETER;
169 err = feedback_get_path(type, pattern, buf, MAX_PATH_LENGTH);
170 if (FEEDBACK_FAILED(err)) {
171 FEEDBACK_ERROR("feedback_get_path is failed");
172 return FEEDBACK_ERROR_OPERATION_FAILED;
177 return FEEDBACK_ERROR_NONE;
180 API int feedback_set_resource_path(feedback_type_e type, feedback_pattern_e pattern, char* path)
185 FEEDBACK_ERROR("Invalid parameter : path(NULL)");
186 return FEEDBACK_ERROR_INVALID_PARAMETER;
189 if (type <= FEEDBACK_TYPE_NONE || type >= FEEDBACK_TYPE_END) {
190 FEEDBACK_ERROR("Invalid parameter : type(%d)", type);
191 return FEEDBACK_ERROR_INVALID_PARAMETER;
194 if (pattern <= FEEDBACK_PATTERN_NONE || pattern >= FEEDBACK_PATTERN_END) {
195 FEEDBACK_ERROR("Invalid parameter : pattern(%d)", pattern);
196 return FEEDBACK_ERROR_INVALID_PARAMETER;
199 err = feedback_set_path(type, pattern, path);
200 if (FEEDBACK_FAILED(err)) {
201 FEEDBACK_ERROR("feedback_set_path is failed");
202 return FEEDBACK_ERROR_OPERATION_FAILED;
205 return FEEDBACK_ERROR_NONE;