move exception handling that process auto level value when create effect is called...
[platform/core/system/haptic-module-tizen.git] / tizen / SIMULATOR / src / haptic.c
1 /*
2  * haptic-module-tizen
3  *
4  * Copyright (c) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jae-young Hwang <j-zero.hwang@samsung.com>
7  *
8  * PROPRIETARY/CONFIDENTIAL
9  *
10  * This software is the confidential and proprietary information of
11  * SAMSUNG ELECTRONICS ("Confidential Information"). You agree and acknowledge
12  * that this software is owned by Samsung and you shall not disclose
13  * such Confidential Information and shall use it only in accordance with the
14  * terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
15  * SAMSUNG make no representations or warranties about the suitability
16  * of the software, either express or implied, including but not limited
17  * to the implied warranties of merchantability, fitness for a particular
18  * purpose,
19  * by licensee arising out of or releated to this software.
20 */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <string.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <fcntl.h>
29
30 #include <haptic_plugin_intf.h>
31 #include "haptic_module_log.h"
32
33 #ifndef EXTAPI
34 #define EXTAPI __attribute__ ((visibility("default")))
35 #endif
36
37 #define DEFAULT_MOTOR_COUNT                     1
38 #define DEFAULT_DEVICE_HANDLE           0x01
39 #define DEFAULT_EFFECT_HANDLE           0x02
40
41 static int _get_device_count(int *count)
42 {
43         if (count == NULL)
44                 return HAPTIC_MODULE_INVALID_ARGUMENT;
45
46         *count = DEFAULT_MOTOR_COUNT;
47         return HAPTIC_MODULE_ERROR_NONE;
48 }
49
50 static int _open_device(int device_index, int *device_handle)
51 {
52         if (device_index < HAPTIC_MODULE_DEVICE_0 || device_index > HAPTIC_MODULE_DEVICE_ALL)
53                 return HAPTIC_MODULE_INVALID_ARGUMENT;
54
55         if (device_handle == NULL)
56                 return HAPTIC_MODULE_INVALID_ARGUMENT;
57
58         *device_handle = DEFAULT_DEVICE_HANDLE;
59         return HAPTIC_MODULE_ERROR_NONE;
60 }
61
62 static int _close_device(int device_handle)
63 {
64         if (device_handle < 0)
65                 return HAPTIC_MODULE_INVALID_ARGUMENT;
66
67         return HAPTIC_MODULE_ERROR_NONE;
68 }
69
70 static int _vibrate_monotone(int device_handle, int duration, int feedback, int priority, int *effect_handle)
71 {
72         if (device_handle < 0)
73                 return HAPTIC_MODULE_INVALID_ARGUMENT;
74
75         if (duration < 0)
76                 return HAPTIC_MODULE_INVALID_ARGUMENT;
77
78         if (feedback < HAPTIC_MODULE_FEEDBACK_MIN || feedback > HAPTIC_MODULE_FEEDBACK_MAX)
79                 return HAPTIC_MODULE_INVALID_ARGUMENT;
80
81         if (priority < HAPTIC_MODULE_PRIORITY_MIN || priority > HAPTIC_MODULE_PRIORITY_HIGH)
82                 return HAPTIC_MODULE_INVALID_ARGUMENT;
83
84         if (effect_handle == NULL)
85                 return HAPTIC_MODULE_INVALID_ARGUMENT;
86
87         if (feedback == HAPTIC_MODULE_FEEDBACK_MIN)
88                 return HAPTIC_MODULE_ERROR_NONE;
89
90         MODULE_LOG("call %s function", __func__);
91
92         *effect_handle = DEFAULT_EFFECT_HANDLE;
93         return HAPTIC_MODULE_ERROR_NONE;
94 }
95
96 static int _vibrate_file(int device_handle, const char *file_path, int iteration, int feedback, int priority, int  *effect_handle)
97 {
98     if (device_handle < 0)
99         return HAPTIC_MODULE_INVALID_ARGUMENT;
100
101     if (file_path == NULL)
102         return HAPTIC_MODULE_INVALID_ARGUMENT;
103
104     if (iteration < HAPTIC_MODULE_ITERATION_ONCE || iteration > HAPTIC_MODULE_ITERATION_INFINITE)
105         return HAPTIC_MODULE_INVALID_ARGUMENT;
106
107     if (feedback < HAPTIC_MODULE_FEEDBACK_MIN || feedback > HAPTIC_MODULE_FEEDBACK_MAX)
108         return HAPTIC_MODULE_INVALID_ARGUMENT;
109
110     if (priority < HAPTIC_MODULE_PRIORITY_MIN || priority > HAPTIC_MODULE_PRIORITY_HIGH)
111         return HAPTIC_MODULE_INVALID_ARGUMENT;
112
113     if (effect_handle == NULL)
114         return HAPTIC_MODULE_INVALID_ARGUMENT;
115
116     if (feedback == HAPTIC_MODULE_FEEDBACK_MIN)
117         return HAPTIC_MODULE_ERROR_NONE;
118
119         MODULE_LOG("call %s function", __func__);
120
121         *effect_handle = DEFAULT_EFFECT_HANDLE;
122         return HAPTIC_MODULE_ERROR_NONE;
123 }
124
125 static int _vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle)
126 {
127     if (device_handle < 0)
128         return HAPTIC_MODULE_INVALID_ARGUMENT;
129
130     if (vibe_buffer == NULL)
131         return HAPTIC_MODULE_INVALID_ARGUMENT;
132
133     if (iteration < HAPTIC_MODULE_ITERATION_ONCE || iteration > HAPTIC_MODULE_ITERATION_INFINITE)
134         return HAPTIC_MODULE_INVALID_ARGUMENT;
135
136     if (feedback < HAPTIC_MODULE_FEEDBACK_MIN || feedback > HAPTIC_MODULE_FEEDBACK_MAX)
137         return HAPTIC_MODULE_INVALID_ARGUMENT;
138
139     if (priority < HAPTIC_MODULE_PRIORITY_MIN || priority > HAPTIC_MODULE_PRIORITY_HIGH)
140         return HAPTIC_MODULE_INVALID_ARGUMENT;
141
142     if (effect_handle == NULL)
143         return HAPTIC_MODULE_INVALID_ARGUMENT;
144
145     if (feedback == HAPTIC_MODULE_FEEDBACK_MIN)
146         return HAPTIC_MODULE_ERROR_NONE;
147
148         MODULE_LOG("call %s function", __func__);
149
150         *effect_handle = DEFAULT_EFFECT_HANDLE;
151         return HAPTIC_MODULE_ERROR_NONE;
152 }
153
154 static int _stop_effect(int device_handle, int effect_handle)
155 {
156     if (device_handle < 0)
157         return HAPTIC_MODULE_INVALID_ARGUMENT;
158
159     if (effect_handle < 0)
160         return HAPTIC_MODULE_INVALID_ARGUMENT;
161
162         MODULE_LOG("call %s function", __func__);
163
164         return HAPTIC_MODULE_ERROR_NONE;
165 }
166
167 static int _stop_all_effects(int device_handle)
168 {
169         if (device_handle < 0)
170                 return HAPTIC_MODULE_INVALID_ARGUMENT;
171
172         MODULE_LOG("call %s function", __func__);
173
174         return HAPTIC_MODULE_ERROR_NONE;
175 }
176
177 static int _pause_effect(int device_handle, int effect_handle)
178 {
179     if (device_handle < 0)
180         return HAPTIC_MODULE_INVALID_ARGUMENT;
181
182     if (effect_handle < 0)
183         return HAPTIC_MODULE_INVALID_ARGUMENT;
184
185         MODULE_LOG("call %s function", __func__);
186
187         return HAPTIC_MODULE_ERROR_NONE;
188 }
189
190 static int _resume_effect(int device_handle, int effect_handle)
191 {
192     if (device_handle < 0)
193         return HAPTIC_MODULE_INVALID_ARGUMENT;
194
195     if (effect_handle < 0)
196         return HAPTIC_MODULE_INVALID_ARGUMENT;
197
198         MODULE_LOG("call %s function", __func__);
199
200         return HAPTIC_MODULE_ERROR_NONE;
201 }
202
203 static int _get_effect_state(int device_handle, int effect_handle, int *effect_state)
204 {
205     if (device_handle < 0)
206         return HAPTIC_MODULE_INVALID_ARGUMENT;
207
208     if (effect_handle < 0)
209         return HAPTIC_MODULE_INVALID_ARGUMENT;
210
211     if (effect_state == NULL)
212         return HAPTIC_MODULE_INVALID_ARGUMENT;
213
214         MODULE_LOG("call %s function", __func__);
215
216         return HAPTIC_MODULE_ERROR_NONE;
217 }
218
219 static int _create_effect(const unsigned char *vibe_buffer, int max_bufsize, haptic_module_effect_element *elem_arr, int max_elemcnt)
220 {
221     if (vibe_buffer == NULL)
222         return HAPTIC_MODULE_INVALID_ARGUMENT;
223
224     if (max_bufsize < 0)
225         return HAPTIC_MODULE_INVALID_ARGUMENT;
226
227     if (elem_arr == NULL)
228         return HAPTIC_MODULE_INVALID_ARGUMENT;
229
230     if (max_elemcnt < 0)
231         return HAPTIC_MODULE_INVALID_ARGUMENT;
232
233         MODULE_LOG("call %s function", __func__);
234
235         return HAPTIC_MODULE_ERROR_NONE;
236 }
237
238 static int _save_effect(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path)
239 {
240     if (vibe_buffer == NULL)
241         return HAPTIC_MODULE_INVALID_ARGUMENT;
242
243     if (max_bufsize < 0)
244         return HAPTIC_MODULE_INVALID_ARGUMENT;
245
246     if (file_path == NULL)
247         return HAPTIC_MODULE_INVALID_ARGUMENT;
248
249         MODULE_LOG("call %s function", __func__);
250
251         return HAPTIC_MODULE_ERROR_NONE;
252 }
253
254 static int _get_file_duration(int device_handle, const char *file_path, int *file_duration)
255 {
256     if (device_handle < 0)
257         return HAPTIC_MODULE_INVALID_ARGUMENT;
258
259     if (file_path == NULL)
260         return HAPTIC_MODULE_INVALID_ARGUMENT;
261
262     if (file_duration == NULL)
263         return HAPTIC_MODULE_INVALID_ARGUMENT;
264
265         MODULE_LOG("call %s function", __func__);
266
267         return HAPTIC_MODULE_ERROR_NONE;
268 }
269
270 static int _get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *buffer_duration)
271 {
272     if (device_handle < 0)
273         return HAPTIC_MODULE_INVALID_ARGUMENT;
274
275     if (vibe_buffer == NULL)
276         return HAPTIC_MODULE_INVALID_ARGUMENT;
277
278     if (buffer_duration == NULL)
279         return HAPTIC_MODULE_INVALID_ARGUMENT;
280
281         MODULE_LOG("call %s function", __func__);
282
283         return HAPTIC_MODULE_ERROR_NONE;
284 }
285
286 static int _convert_binary (void)
287 {
288         MODULE_ERROR("This device is not supported this function(%s)", __func__);
289         return HAPTIC_MODULE_NOT_SUPPORTED;
290 }
291
292 static haptic_plugin_interface haptic_plugin_emul = {
293         .haptic_internal_get_device_count               = _get_device_count,
294         .haptic_internal_open_device            = _open_device,
295         .haptic_internal_close_device           = _close_device,
296         .haptic_internal_vibrate_monotone       = _vibrate_monotone,
297         .haptic_internal_vibrate_file           = _vibrate_file,
298         .haptic_internal_vibrate_buffer         = _vibrate_buffer,
299         .haptic_internal_stop_effect            = _stop_effect,
300         .haptic_internal_stop_all_effects       = _stop_all_effects,
301         .haptic_internal_pause_effect           = _pause_effect,
302         .haptic_internal_resume_effect          = _resume_effect,
303         .haptic_internal_get_effect_state       = _get_effect_state,
304         .haptic_internal_create_effect          = _create_effect,
305         .haptic_internal_save_effect            = _save_effect,
306         .haptic_internal_get_file_duration      = _get_file_duration,
307         .haptic_internal_get_buffer_duration    = _get_buffer_duration,
308         .haptic_internal_convert_binary         = _convert_binary,
309 };
310
311 EXTAPI
312 const haptic_plugin_interface *get_haptic_plugin_interface()
313 {
314         return &haptic_plugin_emul;
315 }