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.
26 #include "feedback-internal.h"
27 #include "feedback-str.h"
28 #include "feedback-log.h"
32 #define API __attribute__ ((visibility("default")))
39 static void feedback_callstatus_cb(keynode_t *key, void* data)
41 callstatus = vconf_keynode_get_int(key);
44 static feedback_pattern_e get_alert_on_call_key(feedback_pattern_e pattern)
47 case FEEDBACK_PATTERN_MESSAGE:
48 case FEEDBACK_PATTERN_EMAIL:
49 case FEEDBACK_PATTERN_WAKEUP:
50 case FEEDBACK_PATTERN_SCHEDULE:
51 case FEEDBACK_PATTERN_TIMER:
52 case FEEDBACK_PATTERN_GENERAL:
53 case FEEDBACK_PATTERN_CHARGERCONN:
54 case FEEDBACK_PATTERN_FULLCHARGED:
55 case FEEDBACK_PATTERN_LOWBATT:
56 return (feedback_pattern_e)(pattern+1);
64 API int feedback_initialize()
69 return FEEDBACK_ERROR_NONE;
71 /* check call status */
72 if (vconf_get_int(VCONFKEY_CALL_STATE, &callstatus) < 0)
73 FEEDBACK_ERROR("vconf_get_int(VCONFKEY_CALL_STATE, &callstatus) ==> FAIL!!");
75 /* add watch for status value */
76 vconf_notify_key_changed(VCONFKEY_CALL_STATE, feedback_callstatus_cb, NULL);
78 /* initialize device */
82 return FEEDBACK_ERROR_NONE;
85 API int feedback_deinitialize()
88 return FEEDBACK_ERROR_NOT_INITIALIZED;
90 vconf_ignore_key_changed(VCONFKEY_CALL_STATE, feedback_callstatus_cb);
92 /* deinitialize device */
96 return FEEDBACK_ERROR_NONE;
99 API int feedback_play(feedback_pattern_e pattern)
101 /* check initialize */
103 FEEDBACK_ERROR("Not initialized");
104 return FEEDBACK_ERROR_NOT_INITIALIZED;
107 if (pattern < FEEDBACK_PATTERN_NONE || pattern >= FEEDBACK_PATTERN_END) {
108 FEEDBACK_ERROR("Invalid parameter : pattern(%d)", pattern);
109 return FEEDBACK_ERROR_INVALID_PARAMETER;
112 if (pattern == FEEDBACK_PATTERN_NONE) {
113 FEEDBACK_LOG("pattern is NONE");
114 return FEEDBACK_ERROR_NONE;
117 /* in case of call connected or connecting */
118 if (callstatus != VCONFKEY_CALL_OFF) {
119 pattern = get_alert_on_call_key(pattern);
120 FEEDBACK_LOG("Call status is connected or connecting. pattern changed : %s", str_pattern[pattern]);
123 /* play all device */
124 devices_play(pattern);
126 return FEEDBACK_ERROR_NONE;
129 API int feedback_play_type(feedback_type_e type, feedback_pattern_e pattern)
131 const struct device_ops *dev;
134 /* check initialize */
136 FEEDBACK_ERROR("Not initialized");
137 return FEEDBACK_ERROR_NOT_INITIALIZED;
140 if (type <= FEEDBACK_TYPE_NONE || type >= FEEDBACK_TYPE_END) {
141 FEEDBACK_ERROR("Invalid parameter : type(%d)", type);
142 return FEEDBACK_ERROR_INVALID_PARAMETER;
145 if (pattern < FEEDBACK_PATTERN_NONE || pattern >= FEEDBACK_PATTERN_END) {
146 FEEDBACK_ERROR("Invalid parameter : pattern(%d)", pattern);
147 return FEEDBACK_ERROR_INVALID_PARAMETER;
150 if (pattern == FEEDBACK_PATTERN_NONE) {
151 FEEDBACK_LOG("pattern is NONE");
152 return FEEDBACK_ERROR_NONE;
155 /* in case of call connected or connecting */
156 if (callstatus != VCONFKEY_CALL_OFF) {
157 pattern = get_alert_on_call_key(pattern);
158 FEEDBACK_LOG("Call status is connected or connecting. pattern changed : %s", str_pattern[pattern]);
161 /* play proper device */
162 dev = find_device(type);
164 err = dev->play(pattern);
166 FEEDBACK_ERROR("fail to play sound");
169 return FEEDBACK_ERROR_NONE;
172 API int feedback_get_resource_path(feedback_type_e type, feedback_pattern_e pattern, char** path)
174 const struct device_ops *dev;
175 char buf[PATH_MAX] = {0,};
179 FEEDBACK_ERROR("Invalid parameter : path(NULL)");
180 return FEEDBACK_ERROR_INVALID_PARAMETER;
183 if (type <= FEEDBACK_TYPE_NONE || type >= FEEDBACK_TYPE_END) {
184 FEEDBACK_ERROR("Invalid parameter : type(%d)", type);
185 return FEEDBACK_ERROR_INVALID_PARAMETER;
188 if (pattern <= FEEDBACK_PATTERN_NONE || pattern >= FEEDBACK_PATTERN_END) {
189 FEEDBACK_ERROR("Invalid parameter : pattern(%d)", pattern);
190 return FEEDBACK_ERROR_INVALID_PARAMETER;
193 /* proper device get path */
194 dev = find_device(type);
196 err = dev->get_path(pattern, buf, sizeof(buf));
198 return FEEDBACK_ERROR_OPERATION_FAILED;
202 return FEEDBACK_ERROR_NONE;
205 API int feedback_set_resource_path(feedback_type_e type, feedback_pattern_e pattern, char *path)
207 const struct device_ops *dev;
211 FEEDBACK_ERROR("Invalid parameter : path(NULL)");
212 return FEEDBACK_ERROR_INVALID_PARAMETER;
215 if (type <= FEEDBACK_TYPE_NONE || type >= FEEDBACK_TYPE_END) {
216 FEEDBACK_ERROR("Invalid parameter : type(%d)", type);
217 return FEEDBACK_ERROR_INVALID_PARAMETER;
220 if (pattern <= FEEDBACK_PATTERN_NONE || pattern >= FEEDBACK_PATTERN_END) {
221 FEEDBACK_ERROR("Invalid parameter : pattern(%d)", pattern);
222 return FEEDBACK_ERROR_INVALID_PARAMETER;
225 /* proper device set path */
226 dev = find_device(type);
228 err = dev->set_path(pattern, path);
230 return FEEDBACK_ERROR_OPERATION_FAILED;
233 return FEEDBACK_ERROR_NONE;