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