Add default Smack manifest for devman.spec
[platform/core/system/devman.git] / device_haptic.c
1 /*
2  *  devman
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: DongGi Jang <dg0402.jang@samsung.com>
7  * 
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20 */ 
21
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <string.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <vconf.h>
31 #include <dlfcn.h>
32
33 #include "devlog.h"
34 #include "device_haptic.h"
35 #include "devman.h"
36 #include "devman_haptic.h"
37 #include "devman_haptic_ext.h"
38 #include "devman_haptic_plugin_intf.h"
39 /* START: Will be excluded by removing pattern */
40 #include "device_haptic_tsp4000_pattern.h"
41 /* END: Will be excluded */
42
43 #ifndef EXTAPI
44 #define EXTAPI __attribute__ ((visibility("default")))
45 #endif /* EXTAPI */
46
47 #define HAPTIC_DEVICE_NODE_PATH         "/dev/tspdrv"
48 #define HAPTIC_MODULE_PATH              "/usr/lib/devman/libdevman_haptic.so"
49
50 /* START: Will be removed by removing pattern */
51 #define HAPTIC_PLAY_FILE_EXT            ".ivt"
52 #define HAPTIC_BUILT_IN_FILE_PATH       "/usr/share/immersion"
53
54 struct g_pivt_list_t
55 {
56         char file_name[NAME_MAX];
57         unsigned char *ivt_pt;
58         int priority;
59 };
60
61 struct g_pivt_list_t g_haptic_internal_pattern_list[EFFCTVIBE_PATTERN_END] = {
62         /*for BeatUX*/
63         [EFFCTVIBE_TOUCH]                       = { "/01_Touch/touch_20ms_sharp", touch_ivt, 15},
64         [EFFCTVIBE_HW_TOUCH]                    = { "/01_Touch/HW_touch_30ms_sharp", hw_touch_ivt, 15},
65
66         [EFFCTVIBE_NOTIFICATION]                = { "/02_Notification/Notification", noti_ivt, 7},
67         [EFFCTVIBE_INCOMING_CALL01]             = { "/02_Notification/Incoming call_01", incomming_01_ivt, 7},
68         [EFFCTVIBE_INCOMING_CALL02]             = { "/02_Notification/Incoming call_02", incomming_02_ivt, 7},
69         [EFFCTVIBE_INCOMING_CALL03]             = { "/02_Notification/Incoming call_03", incomming_03_ivt, 7},
70
71         [EFFCTVIBE_ALERTS_CALL]                 = { "/03_Operation/Alerts on Call", alerts_call_ivt, 15},
72         [EFFCTVIBE_OPERATION]                   = { "/03_Operation/Operation", operation_ivt, 7},
73         [EFFCTVIBE_SILENT_MODE]                 = { "/03_Operation/Silent mode", silent_ivt, 7},
74 };
75 /* END: Will be removed */
76
77 static int has_haptic_module = -1;
78 static int master_callback_enable = 0;
79 static int setting_fb_level = -1;
80 static int device_handle_count = 0;
81
82 /* Device Manager Haptic Plugin Interface */
83 static void *dlopen_handle;
84 static const devman_haptic_plugin_interface *plugin_intf;
85
86 enum {
87         MODE_DEFAULT = 0x0000,
88         MODE_FEEDBACK_LEVEL_CHECK_DISABLE = 0x0001,
89 };
90
91 /* START of Static Function Section */
92 static int __get_master_strength_value()
93 {
94         int input_strength = 0;
95
96         switch (setting_fb_level) {
97                 case SETTING_VIB_FEEDBACK_LEVEL0:
98                         DBG("get setting value = 0 , so can not vibe");
99                         return 0;
100                         break;
101                 case SETTING_VIB_FEEDBACK_LEVEL1:
102                         input_strength = VIBE_FEEDBACK_LEVEL_1;
103                         break;
104
105                 case SETTING_VIB_FEEDBACK_LEVEL2:
106                         input_strength = VIBE_FEEDBACK_LEVEL_2;
107                         break;
108
109                 case SETTING_VIB_FEEDBACK_LEVEL3:
110                         input_strength = VIBE_FEEDBACK_LEVEL_3;
111                         break;
112
113                 case SETTING_VIB_FEEDBACK_LEVEL4:
114                         input_strength = VIBE_FEEDBACK_LEVEL_4;
115                         break;
116
117                 case SETTING_VIB_FEEDBACK_LEVEL5:
118                         input_strength = VIBE_FEEDBACK_LEVEL_5;
119                         break;
120
121                 default:
122                         ERR("error get VCONF_SETAPPL_VIB_FEEDBACK_INT value (= %d) invalid", setting_fb_level);
123                         return -2;
124                         break;
125         }
126
127         return input_strength;
128 }
129
130 static int __convert_strength_level(int base_level)
131 {
132         int convert_strength = 0;
133
134         switch (base_level) {
135                 case 0:
136                         ERR("Input base_level == 0(:%d)\n", base_level);
137                         break;
138
139                 case HAPTIC_FEEDBACK_LEVEL_1:
140                         convert_strength = VIBE_FEEDBACK_LEVEL_1;
141                         break;
142
143                 case HAPTIC_FEEDBACK_LEVEL_2:
144                         convert_strength = VIBE_FEEDBACK_LEVEL_2;
145                         break;
146
147                 case HAPTIC_FEEDBACK_LEVEL_3:
148                         convert_strength = VIBE_FEEDBACK_LEVEL_3;
149                         break;
150
151                 case HAPTIC_FEEDBACK_LEVEL_4:
152                         convert_strength = VIBE_FEEDBACK_LEVEL_4;
153                         break;
154
155                 case HAPTIC_FEEDBACK_LEVEL_5:
156                         convert_strength = VIBE_FEEDBACK_LEVEL_5;
157                         break;
158
159                 default:
160                         ERR("error invalid convertable value (%d)", base_level);
161                         return -2;
162         }
163
164         return convert_strength;
165 }
166
167 static void __haptic_changed_cb(keynode_t *node, void *data)
168 {
169         int feedback_level;
170
171         DBG("[haptic_changed_cb] changed key = %s\n",
172                         vconf_keynode_get_name(node));
173
174         if (vconf_keynode_get_type(node) == VCONF_TYPE_INT) {
175
176                 feedback_level = vconf_keynode_get_int(node);
177
178                 if (feedback_level == -1) {
179                         ERR(" [haptic_changed_cb] Err vconf_keynode_get_int fail from key in haptic_changed_cb : %s , fail state : %d ,so set default level", vconf_keynode_get_name(node), feedback_level);
180                         return;
181                 }
182                 DBG("[haptic_changed_cb] get value : %d , from key : %s",
183                                 feedback_level, vconf_keynode_get_name(node));
184
185                 setting_fb_level = feedback_level;
186         } else {
187                 ERR("[haptic_changed_cb] Err changed key_type miss-match!!  read_type : %d", vconf_keynode_get_type(node));
188         }
189 }
190 /* END of Static Function Section */
191
192
193 /* START: devman_haptic APIs */
194         EXTAPI
195 int device_haptic_open(haptic_dev_idx dev_idx, unsigned int mode)
196 {
197         int status;
198         int device_index = dev_idx >> 1;
199         int device_handle;
200
201         if (device_handle_count == 0) {
202                 if (has_haptic_module == 1) {
203                         plugin_intf->haptic_internal_prepare_node();
204
205                         if (plugin_intf->haptic_internal_initialize() < 0) {
206                                 ERR("plugin_intf->haptic_internal_initialize() failed");
207                                 return HAPTIC_FAIL;
208                         }
209                 }
210
211                 if (mode & MODE_FEEDBACK_LEVEL_CHECK_DISABLE) {
212                         pid_t cpid;
213                         cpid = getpid();
214                         DBG("NOT USE MAIN VIB_FEEDBACK_CHECK ROUTINE !!, at pid : %d", cpid);
215                         setting_fb_level = SETTING_VIB_FEEDBACK_LEVEL3;
216                 } else if (master_callback_enable == 0) {
217                         status = vconf_get_int(VCONFKEY_SETAPPL_VIB_FEEDBACK_INT, &setting_fb_level);
218                         if (status < 0) {
219                                 DBG(" vconf_get_int fail from key : %s , fail state : %d ,so set default level", VCONFKEY_SETAPPL_VIB_FEEDBACK_INT, status);
220                                 setting_fb_level = SETTING_VIB_FEEDBACK_LEVEL3;
221                         }
222                         DBG("get value : %d , from key : %s", setting_fb_level, VCONFKEY_SETAPPL_VIB_FEEDBACK_INT);
223
224                         status = vconf_notify_key_changed (VCONFKEY_SETAPPL_VIB_FEEDBACK_INT, __haptic_changed_cb, NULL);
225                         if (status < 0) {
226                                 ERR("Device_haptic_open vconf_notify_key_changed fail\n");
227                                 return HAPTIC_FAIL;
228                         }
229
230                         master_callback_enable = 1;
231                 }
232         }
233
234         if (has_haptic_module == 1) {
235                 if (dev_idx == DEV_IDX_ALL) {
236                         status = plugin_intf->haptic_internal_open_composite_device(NULL, device_index, &device_handle);
237                         if(HAPTIC_FAILED(status)) {
238                                 ERR("plugin_intf->haptic_internal_open_composite_device() Failed: %d", status);
239                                 return HAPTIC_FAIL; 
240                         }
241                 } else {
242                         status = plugin_intf->haptic_internal_open_device(device_index, &device_handle);
243                         if(HAPTIC_FAILED(status)) {
244                                 ERR("plugin_intf->haptic_internal_open_device() Failed: %d", status);
245                                 return HAPTIC_FAIL;
246                         }
247                 }
248
249                 ++device_handle_count;
250                 return device_handle;
251         }
252
253         ++device_handle_count;
254         return DEFAULT_DEVICE_HANDLE;
255 }
256
257         EXTAPI
258 int device_haptic_close(int device_handle)
259 {
260         int status;
261
262         if (device_handle_count == 0) {
263                 ERR("Haptic device already closed");
264                 return HAPTIC_NOT_OPENED;
265         }
266
267         if (has_haptic_module == 1) {
268                 status = plugin_intf->haptic_internal_close_device(device_handle);
269                 if(HAPTIC_FAILED(status)) {
270                         ERR("plugin_intf->haptic_internal_close_device(0) fail: %d", status);
271                         return HAPTIC_FAIL;
272                 }
273         }
274
275         --device_handle_count;
276         if (device_handle_count == 0) {
277                 if (has_haptic_module == 1) {
278                         status = plugin_intf->haptic_internal_terminate();
279                         if(HAPTIC_FAILED(status)) {
280                                 ERR("plugin_intf->haptic_internal_terminate(0) fail: %d", status);
281                                 return HAPTIC_FAIL;
282                         }
283                 }
284
285                 if (master_callback_enable == 1) {
286                         status = vconf_ignore_key_changed(VCONFKEY_SETAPPL_VIB_FEEDBACK_INT, __haptic_changed_cb);
287                         if (status < 0) {
288                                 ERR("Device_haptic_close vconf_ignore_key_changed fail\n");
289                                 return HAPTIC_FAIL;
290                         }
291                         master_callback_enable = 0;
292                 }
293         }
294
295         return HAPTIC_SUCCESS;
296 }
297
298         EXTAPI
299 int device_haptic_play_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback_level)
300 {
301         int input_feedback_level;
302
303         if (device_handle_count == 0) {
304                 ERR("Haptic device is not opened yet");
305                 return HAPTIC_NOT_OPENED;
306         }
307
308         if (has_haptic_module == 0) {
309                 ERR("%s() is not supported without specific haptic module", __func__);
310                 return HAPTIC_NOT_SUPPORTED;
311         }
312
313         if (feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
314                 input_feedback_level = __get_master_strength_value();
315         } else {
316                 input_feedback_level = __convert_strength_level(feedback_level);
317         }
318
319         return plugin_intf->haptic_internal_play_buffer(device_handle, vibe_buffer, iteration, input_feedback_level, HAPTIC_MIN_DEVICE_PRIORITY);
320 }
321
322         EXTAPI
323 int device_haptic_play_file(int device_handle, const char *file_name, int iteration, int feedback_level)
324 {
325         int input_feedback_level;
326
327         if (device_handle_count == 0) {
328                 ERR("Haptic device is not opened yet");
329                 return HAPTIC_NOT_OPENED;
330         }
331
332         if (has_haptic_module == 0) {
333                 ERR("%s() is not supported without specific haptic module", __func__);
334                 return HAPTIC_NOT_SUPPORTED;
335         }
336
337         if (feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
338                 input_feedback_level = __get_master_strength_value();
339         } else {
340                 input_feedback_level = __convert_strength_level(feedback_level);
341         }
342
343         return plugin_intf->haptic_internal_play_file(device_handle, file_name, iteration, input_feedback_level, HAPTIC_MIN_DEVICE_PRIORITY);
344 }
345
346         EXTAPI
347 int device_haptic_play_pattern(int device_handle, int pattern, int iteration, int feedback_level)
348 {
349         char file_name[NAME_MAX];
350         int priority = -1;
351         int input_feedback_level;
352
353         if (device_handle_count == 0) {
354                 ERR("Haptic device is not opened yet");
355                 return HAPTIC_NOT_OPENED;
356         }
357
358         if (has_haptic_module == 0) {
359                 ERR("%s() is not supported without specific haptic module", __func__);
360                 return HAPTIC_NOT_SUPPORTED;
361         }
362
363         if (feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
364                 input_feedback_level = __get_master_strength_value();
365         } else {
366                 input_feedback_level = __convert_strength_level(feedback_level);
367         }
368
369         /* Set Priority */
370         if (!g_haptic_internal_pattern_list[pattern].priority) {
371                 priority = HAPTIC_MIN_DEVICE_PRIORITY;
372         } else {
373                 priority = g_haptic_internal_pattern_list[pattern].priority;
374         }
375
376         if (!g_haptic_internal_pattern_list[pattern].ivt_pt) {
377                 /* Pass filename insted of buffer pointer */
378                 if (0 > snprintf(file_name, NAME_MAX, "%s%s%s", HAPTIC_BUILT_IN_FILE_PATH, g_haptic_internal_pattern_list[pattern].file_name, HAPTIC_PLAY_FILE_EXT))
379                 {
380                         ERR("snprintf fail in EFFCTVIBE_SET_EFFECT_TYPE");
381                         return HAPTIC_FAIL;
382                 }
383
384                 return plugin_intf->haptic_internal_play_file(device_handle, file_name, iteration, input_feedback_level, HAPTIC_MIN_DEVICE_PRIORITY);
385         }
386
387         return plugin_intf->haptic_internal_play_buffer(device_handle, g_haptic_internal_pattern_list[pattern].ivt_pt, iteration, input_feedback_level, priority);
388 }
389
390         EXTAPI
391 int device_haptic_stop_play(int device_handle)
392 {
393         int status;
394
395         if (device_handle_count == 0) {
396                 ERR("Haptic device is not opened yet");
397                 return HAPTIC_NOT_OPENED;
398         }
399
400         if (has_haptic_module == 1) {
401                 status = plugin_intf->haptic_internal_stop_all_playing_effects(device_handle);
402                 if(HAPTIC_FAILED(status)) {
403                         ERR("plugin_intf->haptic_internal_stop_all_playing_effects(0) fail: %d", status);
404                         return HAPTIC_FAIL;
405                 }
406         } else {
407                 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_ENABLE, 0);
408                 if (status < 0) {
409                         ERR("Haptic device stop failed: %d", status);
410                         return HAPTIC_FAIL;
411                 }
412         }
413
414         return HAPTIC_SUCCESS;
415 }
416
417         EXTAPI
418 int device_haptic_play_monotone(int device_handle, int duration)
419 {
420         return device_haptic_play_monotone_with_feedback_level(device_handle, duration, HAPTIC_FEEDBACK_LEVEL_AUTO);
421 }
422
423         EXTAPI
424 int device_haptic_play_monotone_with_feedback_level(int device_handle, int duration, int feedback_level)
425 {
426         int status;
427         int input_strength;
428         int input_feedback_level;
429         int effect_handle;
430
431         if (device_handle_count == 0) {
432                 ERR("Haptic device is not opened yet");
433                 return HAPTIC_NOT_OPENED;
434         }
435
436         if (duration < 0) {
437                 ERR("Invalid parameter: duration < 0");
438                 return HAPTIC_FAIL;
439         }
440
441         if (feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
442                 input_feedback_level = __get_master_strength_value();
443         } else {
444                 input_feedback_level = __convert_strength_level(feedback_level);
445         }
446
447         if (has_haptic_module == 1) {
448                 status = plugin_intf->haptic_internal_play_monotone(device_handle, duration, input_feedback_level, 0x05);
449                 if(HAPTIC_FAILED(status)) {
450                         ERR("plugin_intf->haptic_internal_play_monotone(0) fail: %d", status);
451                         return HAPTIC_FAIL;
452                 }
453         } else {
454                 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_LEVEL, input_feedback_level);
455                 if (status < 0) {
456                         ERR(" haptic_set_level for strength:%d (error:%d) \n", input_strength, status);
457                         return HAPTIC_FAIL;
458                 }
459
460                 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_ONESHOT, duration);
461                 if (status < 0) {
462                         ERR(" haptic_oneshot for duration:%d (error:%d) \n", duration, status);
463                         return HAPTIC_FAIL;
464                 }
465         }
466
467         return HAPTIC_SUCCESS;
468 }
469
470         EXTAPI
471 int device_haptic_play_monotone_with_detail_feedback_level(int device_handle, int duration, int detail_feedback_level)
472 {
473         int status;
474         int input_strength;
475         int input_feedback_level;
476         int effect_handle;
477
478         if (device_handle_count == 0) {
479                 ERR("Haptic device is not opened yet");
480                 return HAPTIC_NOT_OPENED;
481         }
482
483         if (duration < 0) {
484                 ERR("Invalid parameter: duration < 0");
485                 return HAPTIC_FAIL;
486         }
487
488         if (detail_feedback_level < 0 && detail_feedback_level > 100) {
489                 ERR("detail_feedback_level is wrong: %d", detail_feedback_level);
490                 return HAPTIC_FAIL;
491         } else {
492                 if (detail_feedback_level == 0) {
493                         input_feedback_level = __get_master_strength_value();
494                 } else {
495                         input_feedback_level = detail_feedback_level * 100;
496                 }
497         }
498
499         if (has_haptic_module == 1) {
500                 status = plugin_intf->haptic_internal_play_monotone(device_handle, duration, input_feedback_level, 0x05);
501                 if(HAPTIC_FAILED(status)) {
502                         ERR("plugin_intf->haptic_internal_play_monotone(0) fail: %d", status);
503                         return HAPTIC_FAIL;
504                 }
505         } else {
506                 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_LEVEL, input_feedback_level);
507                 if (status < 0) {
508                         ERR(" haptic_set_level for strength:%d (error:%d) \n", input_strength, status);
509                         return HAPTIC_FAIL;
510                 }
511
512                 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_ONESHOT, duration);
513                 if (status < 0) {
514                         ERR(" haptic_oneshot for duration:%d (error:%d) \n", duration, status);
515                         return HAPTIC_FAIL;
516                 }
517         }
518
519         return HAPTIC_SUCCESS;
520 }
521
522         EXTAPI
523 int device_haptic_get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *duration)
524 {
525         if (device_handle_count == 0) {
526                 ERR("Haptic device is not opened yet");
527                 return HAPTIC_NOT_OPENED;
528         }
529
530         if (has_haptic_module == 0) {
531                 ERR("%s() is not supported without specific haptic module", __func__);
532                 return HAPTIC_NOT_SUPPORTED;
533         }
534
535         return plugin_intf->haptic_internal_get_buffer_duration(device_handle, vibe_buffer, duration);
536 }
537
538         EXTAPI
539 int device_haptic_get_file_duration(int device_handle, const char *file_name, int *duration)
540 {
541         if (device_handle_count == 0) {
542                 ERR("Haptic device is not opened yet");
543                 return HAPTIC_NOT_OPENED;
544         }
545
546         if (has_haptic_module == 0) {
547                 ERR("%s() is not supported without specific haptic module", __func__);
548                 return HAPTIC_NOT_SUPPORTED;
549         }
550
551         return plugin_intf->haptic_internal_get_file_duration(device_handle, file_name, duration);
552 }
553
554         EXTAPI
555 int device_haptic_get_pattern_duration(int device_handle, int pattern, int *duration)
556 {
557         if (device_handle_count == 0) {
558                 ERR("Haptic device is not opened yet");
559                 return HAPTIC_NOT_OPENED;
560         }
561
562         if (has_haptic_module == 0) {
563                 ERR("%s() is not supported without specific haptic module", __func__);
564                 return HAPTIC_NOT_SUPPORTED;
565         }
566         int status;
567         char file_name[NAME_MAX];
568
569         if (!g_haptic_internal_pattern_list[pattern].ivt_pt) {
570                 /* Pass filename insted of buffer pointer */
571                 if (0 > snprintf(file_name, NAME_MAX, "%s%s%s", HAPTIC_BUILT_IN_FILE_PATH, g_haptic_internal_pattern_list[pattern].file_name, HAPTIC_PLAY_FILE_EXT))
572                 {
573                         ERR("snprintf fail in EFFCTVIBE_SET_EFFECT_TYPE");
574                         return HAPTIC_FAIL;
575                 }
576
577                 return plugin_intf->haptic_internal_get_file_duration(device_handle, file_name, duration);
578         }
579
580         return plugin_intf->haptic_internal_get_buffer_duration(device_handle, g_haptic_internal_pattern_list[pattern].ivt_pt, duration);
581 }
582
583         EXTAPI
584 int device_haptic_get_device_count()
585 {
586         int status;
587         int device_count = -1;
588
589         if (has_haptic_module == 0) {
590                 return DEFAULT_MOTOR_COUNT;
591         }
592
593         if (device_handle_count == 0) {
594                 plugin_intf->haptic_internal_prepare_node();
595
596                 status = plugin_intf->haptic_internal_initialize();
597                 if (status < 0) {
598                         return HAPTIC_FAIL;
599                 }
600                 /* Get device count */
601                 device_count = plugin_intf->haptic_internal_get_device_count();
602                 if(HAPTIC_FAILED(device_count)) {
603                         ERR("plugin_intf->haptic_internal_get_device_count(0) fail: %d",status);
604                         return HAPTIC_FAIL;
605                 }
606
607                 status = plugin_intf->haptic_internal_terminate();
608                 if (status < 0) {
609                         return HAPTIC_FAIL;
610                 }
611         } else {
612                 device_count = plugin_intf->haptic_internal_get_device_count();
613                 if(HAPTIC_FAILED(device_count)) {
614                         ERR("plugin_intf->haptic_internal_get_device_count(0) fail: %d",status);
615                         return HAPTIC_FAIL;
616                 }
617         }
618
619         return device_count;
620 }
621 /* END: devman_haptic APIs */
622
623
624 /* START: devman_haptic_ext APIs */
625         EXTAPI
626 int device_haptic_get_device_state(int device_index, int *state)
627 {
628         int status;
629         int index = device_index >> 1;
630
631         if (device_handle_count == 0) {
632                 ERR("Haptic device is not opened yet");
633                 return HAPTIC_NOT_OPENED;
634         }
635
636         if (has_haptic_module == 0) {
637                 ERR("%s() is not supported without specific haptic module", __func__);
638                 return HAPTIC_NOT_SUPPORTED;
639         }
640
641         return plugin_intf->haptic_internal_get_device_state(index, state);
642 }
643
644         EXTAPI
645 int device_haptic_get_device_capability_bool(int device_index, int device_cap_type, unsigned char *device_cap_value)
646 {
647         int status;
648         int index = device_index >> 1;
649
650         if (device_handle_count == 0) {
651                 ERR("Haptic device is not opened yet");
652                 return HAPTIC_NOT_OPENED;
653         }
654
655         if (has_haptic_module == 0) {
656                 ERR("%s() is not supported without specific haptic module", __func__);
657                 return HAPTIC_NOT_SUPPORTED;
658         }
659
660         return plugin_intf->haptic_internal_get_device_capability_bool(index, device_cap_type, device_cap_value);
661 }
662
663         EXTAPI
664 int device_haptic_get_device_capability_int32(int device_index, int device_cap_type, int *device_cap_value)
665 {
666         int status;
667         int index = device_index >> 1;
668
669         if (device_handle_count == 0) {
670                 ERR("Haptic device is not opened yet");
671                 return HAPTIC_NOT_OPENED;
672         }
673
674         if (has_haptic_module == 0) {
675                 ERR("%s() is not supported without specific haptic module", __func__);
676                 return HAPTIC_NOT_SUPPORTED;
677         }
678
679         return plugin_intf->haptic_internal_get_device_capability_int32(index, device_cap_type, device_cap_value);
680 }
681
682         EXTAPI
683 int device_haptic_get_device_capability_string(int device_index, int device_cap_type, int size, char *device_cap_value)
684 {
685         int status;
686         int index = device_index >> 1;
687
688         if (device_handle_count == 0) {
689                 ERR("Haptic device is not opened yet");
690                 return HAPTIC_NOT_OPENED;
691         }
692
693         if (has_haptic_module == 0) {
694                 ERR("%s() is not supported without specific haptic module", __func__);
695                 return HAPTIC_NOT_SUPPORTED;
696         }
697
698         return plugin_intf->haptic_internal_get_device_capability_string(index, device_cap_type, size, device_cap_value);
699 }
700
701         EXTAPI
702 int device_haptic_get_device_property_bool(int device_handle, int device_prop_type, unsigned char *device_prop_value)
703 {
704         int status;
705
706         if (device_handle_count == 0) {
707                 ERR("Haptic device is not opened yet");
708                 return HAPTIC_NOT_OPENED;
709         }
710
711         if (has_haptic_module == 0) {
712                 ERR("%s() is not supported without specific haptic module", __func__);
713                 return HAPTIC_NOT_SUPPORTED;
714         }
715
716         return plugin_intf->haptic_internal_get_device_property_bool(device_handle, device_prop_type, device_prop_value);
717 }
718
719         EXTAPI
720 int device_haptic_set_device_property_bool(int device_handle, int device_prop_type, unsigned char device_prop_value)
721 {
722         int status;
723
724         if (device_handle_count == 0) {
725                 ERR("Haptic device is not opened yet");
726                 return HAPTIC_NOT_OPENED;
727         }
728
729         if (has_haptic_module == 0) {
730                 ERR("%s() is not supported without specific haptic module", __func__);
731                 return HAPTIC_NOT_SUPPORTED;
732         }
733
734         return plugin_intf->haptic_internal_set_device_property_bool(device_handle, device_prop_type, device_prop_value);
735 }
736
737         EXTAPI
738 int device_haptic_get_device_property_int32(int device_handle, int device_prop_type, int *device_prop_value)
739 {
740         int status;
741
742         if (device_handle_count == 0) {
743                 ERR("Haptic device is not opened yet");
744                 return HAPTIC_NOT_OPENED;
745         }
746
747         if (has_haptic_module == 0) {
748                 ERR("%s() is not supported without specific haptic module", __func__);
749                 return HAPTIC_NOT_SUPPORTED;
750         }
751
752         return plugin_intf->haptic_internal_get_device_property_int32(device_handle, device_prop_type, device_prop_value);
753 }
754
755         EXTAPI
756 int device_haptic_set_device_property_int32(int device_handle, int device_prop_type, int device_prop_value)
757 {
758         int status;
759
760         if (device_handle_count == 0) {
761                 ERR("Haptic device is not opened yet");
762                 return HAPTIC_NOT_OPENED;
763         }
764
765         if (has_haptic_module == 0) {
766                 ERR("%s() is not supported without specific haptic module", __func__);
767                 return HAPTIC_NOT_SUPPORTED;
768         }
769
770         return plugin_intf->haptic_internal_set_device_property_int32(device_handle, device_prop_type, device_prop_value);
771 }
772
773         EXTAPI
774 int device_haptic_get_device_property_string(int device_handle, int device_prop_type, int size, char *device_prop_value)
775 {
776         int status;
777
778         if (device_handle_count == 0) {
779                 ERR("Haptic device is not opened yet");
780                 return HAPTIC_NOT_OPENED;
781         }
782
783         if (has_haptic_module == 0) {
784                 ERR("%s() is not supported without specific haptic module", __func__);
785                 return HAPTIC_NOT_SUPPORTED;
786         }
787
788         return plugin_intf->haptic_internal_get_device_property_string(device_handle, device_prop_type, size, device_prop_value);
789 }
790
791         EXTAPI
792 int device_haptic_set_device_property_string(int device_handle, int device_prop_type, const char *device_prop_value)
793 {
794         int status;
795
796         if (device_handle_count == 0) {
797                 ERR("Haptic device is not opened yet");
798                 return HAPTIC_NOT_OPENED;
799         }
800
801         if (has_haptic_module == 0) {
802                 ERR("%s() is not supported without specific haptic module", __func__);
803                 return HAPTIC_NOT_SUPPORTED;
804         }
805
806         return plugin_intf->haptic_internal_set_device_property_string(device_handle, device_prop_type, device_prop_value);
807 }
808
809         EXTAPI
810 int device_haptic_get_effect_count(const unsigned char *haptic_buffer)
811 {
812         int status;
813
814         if (device_handle_count == 0) {
815                 ERR("Haptic device is not opened yet");
816                 return HAPTIC_NOT_OPENED;
817         }
818
819         if (has_haptic_module == 0) {
820                 ERR("%s() is not supported without specific haptic module", __func__);
821                 return HAPTIC_NOT_SUPPORTED;
822         }
823
824         return plugin_intf->haptic_internal_get_IVT_effect_count(haptic_buffer);
825 }
826
827         EXTAPI
828 int device_haptic_get_effect_name(const unsigned char *haptic_buffer, int effect_index, int size, char *effect_name)
829 {
830         int status;
831
832         if (device_handle_count == 0) {
833                 ERR("Haptic device is not opened yet");
834                 return HAPTIC_NOT_OPENED;
835         }
836
837         if (has_haptic_module == 0) {
838                 ERR("%s() is not supported without specific haptic module", __func__);
839                 return HAPTIC_NOT_SUPPORTED;
840         }
841
842         return plugin_intf->haptic_internal_get_IVT_effect_name(haptic_buffer, effect_index, size, effect_name);
843 }
844
845         EXTAPI
846 int device_haptic_get_effect_name_u(const unsigned char *haptic_buffer, int effect_index, int size, unsigned short *effect_name)
847 {
848         int status;
849
850         if (device_handle_count == 0) {
851                 ERR("Haptic device is not opened yet");
852                 return HAPTIC_NOT_OPENED;
853         }
854
855         if (has_haptic_module == 0) {
856                 ERR("%s() is not supported without specific haptic module", __func__);
857                 return HAPTIC_NOT_SUPPORTED;
858         }
859
860         return plugin_intf->haptic_internal_get_IVT_effect_name_u(haptic_buffer, effect_index, size, effect_name);
861 }
862
863         EXTAPI
864 int device_haptic_get_effect_index_from_name(const unsigned char *haptic_buffer, char const *effect_name, int *effect_index)
865 {
866         int status;
867
868         if (device_handle_count == 0) {
869                 ERR("Haptic device is not opened yet");
870                 return HAPTIC_NOT_OPENED;
871         }
872
873         if (has_haptic_module == 0) {
874                 ERR("%s() is not supported without specific haptic module", __func__);
875                 return HAPTIC_NOT_SUPPORTED;
876         }
877
878         return plugin_intf->haptic_internal_get_IVT_effect_index_from_name(haptic_buffer, effect_name, effect_index);
879 }
880
881         EXTAPI
882 int device_haptic_get_effect_index_from_name_u(const unsigned char *haptic_buffer, const unsigned short *effect_name, int *effect_index)
883 {
884         int status;
885
886         if (device_handle_count == 0) {
887                 ERR("Haptic device is not opened yet");
888                 return HAPTIC_NOT_OPENED;
889         }
890
891         if (has_haptic_module == 0) {
892                 ERR("%s() is not supported without specific haptic module", __func__);
893                 return HAPTIC_NOT_SUPPORTED;
894         }
895
896         return plugin_intf->haptic_internal_get_IVT_effect_index_from_name_u(haptic_buffer, effect_name, effect_index);
897 }
898
899         EXTAPI
900 int device_haptic_play_effect(int device_handle, const unsigned char *haptic_buffer, int effect_index, int *effect_handle)
901 {
902         int status;
903
904         if (device_handle_count == 0) {
905                 ERR("Haptic device is not opened yet");
906                 return HAPTIC_NOT_OPENED;
907         }
908
909         if (has_haptic_module == 0) {
910                 ERR("%s() is not supported without specific haptic module", __func__);
911                 return HAPTIC_NOT_SUPPORTED;
912         }
913
914         return plugin_intf->haptic_internal_play_IVT_effect(device_handle, haptic_buffer, effect_index, effect_handle);
915 }
916
917         EXTAPI
918 int device_haptic_play_effect_repeat(int device_handle, const unsigned char *haptic_buffer, int effect_index, unsigned char repeat, int *effect_handle)
919 {
920         int status;
921
922         if (device_handle_count == 0) {
923                 ERR("Haptic device is not opened yet");
924                 return HAPTIC_NOT_OPENED;
925         }
926
927         if (has_haptic_module == 0) {
928                 ERR("%s() is not supported without specific haptic module", __func__);
929                 return HAPTIC_NOT_SUPPORTED;
930         }
931
932         return plugin_intf->haptic_internal_play_IVT_effect_repeat(device_handle, haptic_buffer, effect_index, repeat, effect_handle);
933 }
934
935         EXTAPI
936 int device_haptic_stop_playing_effect(int device_handle, int effect_handle)
937 {
938         int status;
939
940         if (device_handle_count == 0) {
941                 ERR("Haptic device is not opened yet");
942                 return HAPTIC_NOT_OPENED;
943         }
944
945         if (has_haptic_module == 0) {
946                 ERR("%s() is not supported without specific haptic module", __func__);
947                 return HAPTIC_NOT_SUPPORTED;
948         }
949
950         return plugin_intf->haptic_internal_stop_playing_effect(device_handle, effect_handle);
951 }
952
953         EXTAPI
954 int device_haptic_get_effect_type(const unsigned char *haptic_buffer, int effect_index, int *effect_type)
955 {
956         int status;
957
958         if (device_handle_count == 0) {
959                 ERR("Haptic device is not opened yet");
960                 return HAPTIC_NOT_OPENED;
961         }
962
963         if (has_haptic_module == 0) {
964                 ERR("%s() is not supported without specific haptic module", __func__);
965                 return HAPTIC_NOT_SUPPORTED;
966         }
967
968         return plugin_intf->haptic_internal_get_IVT_effect_type(haptic_buffer, effect_index, effect_type);
969 }
970
971         EXTAPI
972 int device_haptic_get_magsweep_effect_definition(const unsigned char *haptic_buffer, int effect_index,
973                 int *duration, int *magnitude, int *style, int *attacktime, int *attacklevel,
974                 int *fadetime, int *fadelevel)
975 {
976         int status;
977
978         if (device_handle_count == 0) {
979                 ERR("Haptic device is not opened yet");
980                 return HAPTIC_NOT_OPENED;
981         }
982
983         if (has_haptic_module == 0) {
984                 ERR("%s() is not supported without specific haptic module", __func__);
985                 return HAPTIC_NOT_SUPPORTED;
986         }
987
988         return plugin_intf->haptic_internal_get_IVT_magsweep_effect_definition(haptic_buffer, effect_index, duration, magnitude, style, attacktime, attacklevel, fadetime, fadelevel);
989 }
990
991         EXTAPI
992 int device_haptic_get_periodic_effect_definition(const unsigned char *haptic_buffer, int effect_index,
993                 int *duration, int *magnitude, int *period, int *style_and_wave_type, int *attacktime, int *attacklevel,
994                 int *fadetime, int *fadelevel)
995 {
996         int status;
997
998         if (device_handle_count == 0) {
999                 ERR("Haptic device is not opened yet");
1000                 return HAPTIC_NOT_OPENED;
1001         }
1002
1003         if (has_haptic_module == 0) {
1004                 ERR("%s() is not supported without specific haptic module", __func__);
1005                 return HAPTIC_NOT_SUPPORTED;
1006         }
1007
1008         return plugin_intf->haptic_internal_get_IVT_periodic_effect_definition(haptic_buffer, effect_index, duration, magnitude, period, style_and_wave_type, attacktime, attacklevel, fadetime, fadelevel);
1009 }
1010
1011         EXTAPI
1012 int device_haptic_get_effect_duration(const unsigned char *haptic_buffer, int effect_index, int *effect_duration)
1013 {
1014         int status;
1015
1016         if (device_handle_count == 0) {
1017                 ERR("Haptic device is not opened yet");
1018                 return HAPTIC_NOT_OPENED;
1019         }
1020
1021         if (has_haptic_module == 0) {
1022                 ERR("%s() is not supported without specific haptic module", __func__);
1023                 return HAPTIC_NOT_SUPPORTED;
1024         }
1025
1026         return plugin_intf->haptic_internal_get_IVT_effect_duration(haptic_buffer, effect_index, effect_duration);
1027 }
1028
1029         EXTAPI
1030 int device_haptic_play_magsweep_effect(int device_handle,
1031                 int duration, int magnitude, int style, int attacktime, int attacklevel,
1032                 int fadetime, int fadelevel, int *effect_handle)
1033 {
1034         int status;
1035
1036         if (device_handle_count == 0) {
1037                 ERR("Haptic device is not opened yet");
1038                 return HAPTIC_NOT_OPENED;
1039         }
1040
1041         if (has_haptic_module == 0) {
1042                 ERR("%s() is not supported without specific haptic module", __func__);
1043                 return HAPTIC_NOT_SUPPORTED;
1044         }
1045
1046         return plugin_intf->haptic_internal_play_magsweep_effect(device_handle, duration, magnitude, style, attacktime, attacklevel, fadetime, fadelevel, effect_handle);
1047 }
1048
1049         EXTAPI
1050 int device_haptic_play_periodic_effect(int device_handle,
1051                 int duration, int magnitude, int period, int style_and_wave_type, int attacktime, int attacklevel,
1052                 int fadetime, int fadelevel, int *effect_handle)
1053 {
1054         int status;
1055
1056         if (device_handle_count == 0) {
1057                 ERR("Haptic device is not opened yet");
1058                 return HAPTIC_NOT_OPENED;
1059         }
1060
1061         if (has_haptic_module == 0) {
1062                 ERR("%s() is not supported without specific haptic module", __func__);
1063                 return HAPTIC_NOT_SUPPORTED;
1064         }
1065
1066         return plugin_intf->haptic_internal_play_periodic_effect(device_handle, duration, magnitude, period, style_and_wave_type, attacktime, attacklevel, fadetime, fadelevel, effect_handle);
1067 }
1068
1069         EXTAPI
1070 int device_haptic_modify_playing_magsweep_effect(int device_handle, int effect_handle,
1071                 int duration, int magnitude, int style, int attacktime, int attacklevel, int fadetime, int fadelevel)
1072 {
1073         int status;
1074
1075         if (device_handle_count == 0) {
1076                 ERR("Haptic device is not opened yet");
1077                 return HAPTIC_NOT_OPENED;
1078         }
1079
1080         if (has_haptic_module == 0) {
1081                 ERR("%s() is not supported without specific haptic module", __func__);
1082                 return HAPTIC_NOT_SUPPORTED;
1083         }
1084
1085         return plugin_intf->haptic_internal_modify_playing_magsweep_effect(device_handle, effect_handle, duration, magnitude, style, attacktime, attacklevel, fadetime, fadelevel);
1086 }
1087
1088         EXTAPI
1089 int device_haptic_modify_playing_periodic_effect(int device_handle, int effect_handle,
1090                 int duration, int magnitude, int period, int style_and_wave_type, int attacktime, int attacklevel, int fadetime, int fadelevel)
1091 {
1092         int status;
1093
1094         if (device_handle_count == 0) {
1095                 ERR("Haptic device is not opened yet");
1096                 return HAPTIC_NOT_OPENED;
1097         }
1098
1099         if (has_haptic_module == 0) {
1100                 ERR("%s() is not supported without specific haptic module", __func__);
1101                 return HAPTIC_NOT_SUPPORTED;
1102         }
1103
1104         return plugin_intf->haptic_internal_modify_playing_periodic_effect(device_handle, effect_handle, duration, magnitude, period, style_and_wave_type, attacktime, attacklevel, fadetime, fadelevel);
1105 }
1106
1107         EXTAPI
1108 int device_haptic_create_streaming_effect(int device_handle, int *effect_handle)
1109 {
1110         int status;
1111
1112         if (device_handle_count == 0) {
1113                 ERR("Haptic device is not opened yet");
1114                 return HAPTIC_NOT_OPENED;
1115         }
1116
1117         if (has_haptic_module == 0) {
1118                 ERR("%s() is not supported without specific haptic module", __func__);
1119         }
1120
1121         return plugin_intf->haptic_internal_create_streaming_effect(device_handle, effect_handle);
1122 }
1123
1124         EXTAPI
1125 int device_haptic_destroy_streaming_effect(int device_handle, int effect_handle)
1126 {
1127         int status;
1128
1129         if (device_handle_count == 0) {
1130                 ERR("Haptic device is not opened yet");
1131                 return HAPTIC_NOT_OPENED;
1132         }
1133
1134         if (has_haptic_module == 0) {
1135                 ERR("%s() is not supported without specific haptic module", __func__);
1136                 return HAPTIC_NOT_SUPPORTED;
1137         }
1138
1139         return plugin_intf->haptic_internal_destroy_streaming_effect(device_handle, effect_handle);
1140 }
1141
1142         EXTAPI
1143 int device_haptic_play_streaming_sample(int device_handle, int effect_handle, const unsigned char *streaming_sample, int size)
1144 {
1145         int status;
1146
1147         if (device_handle_count == 0) {
1148                 ERR("Haptic device is not opened yet");
1149                 return HAPTIC_NOT_OPENED;
1150         }
1151
1152         if (has_haptic_module == 0) {
1153                 ERR("%s() is not supported without specific haptic module", __func__);
1154                 return HAPTIC_NOT_SUPPORTED;
1155         }
1156
1157         return plugin_intf->haptic_internal_play_streaming_sample(device_handle, effect_handle, streaming_sample, size);
1158 }
1159
1160         EXTAPI
1161 int device_haptic_play_streaming_sample_with_offset(int device_handle, int effect_handle, const unsigned char *streaming_sample, int size, int offset_time)
1162 {
1163         int status;
1164
1165         if (device_handle_count == 0) {
1166                 ERR("Haptic device is not opened yet");
1167                 return HAPTIC_NOT_OPENED;
1168         }
1169
1170         if (has_haptic_module == 0) {
1171                 ERR("%s() is not supported without specific haptic module", __func__);
1172                 return HAPTIC_NOT_SUPPORTED;
1173         }
1174
1175         return plugin_intf->haptic_internal_play_streaming_sample_with_offset(device_handle, effect_handle, streaming_sample, size, offset_time);
1176 }
1177
1178         EXTAPI
1179 int device_haptic_stop_all_playing_effects(int device_handle)
1180 {
1181         int status;
1182
1183         if (device_handle_count == 0) {
1184                 ERR("Haptic device is not opened yet");
1185                 return HAPTIC_NOT_OPENED;
1186         }
1187
1188         if (has_haptic_module == 0) {
1189                 ERR("%s() is not supported without specific haptic module", __func__);
1190                 return HAPTIC_NOT_SUPPORTED;
1191         }
1192
1193         return plugin_intf->haptic_internal_stop_all_playing_effects(device_handle);
1194 }
1195
1196         EXTAPI
1197 int device_haptic_save_file(const unsigned char *haptic_buffer, const char *path_name)
1198 {
1199         ERR("%s() is not supported without specific haptic module", __func__);
1200         return -2;
1201
1202         int status;
1203
1204         if (device_handle_count == 0) {
1205                 ERR("Haptic device is not opened yet");
1206                 return -1;
1207         }
1208
1209         if (has_haptic_module == 0) {
1210                 ERR("%s() is not supported without specific haptic module", __func__);
1211                 return -2;
1212         }
1213
1214         return plugin_intf->haptic_internal_save_IVT_file(haptic_buffer, path_name);
1215 }
1216
1217         EXTAPI
1218 int device_haptic_delete_file(const char *path_name)
1219 {
1220         int status;
1221
1222         if (device_handle_count == 0) {
1223                 ERR("Haptic device is not opened yet");
1224                 return HAPTIC_NOT_OPENED;
1225         }
1226
1227         if (has_haptic_module == 0) {
1228                 ERR("%s() is not supported without specific haptic module", __func__);
1229                 return HAPTIC_NOT_SUPPORTED;
1230         }
1231
1232         return plugin_intf->haptic_internal_delete_IVT_file(path_name);
1233 }
1234
1235         EXTAPI
1236 int device_haptic_pause_playing_effect(int device_handle, int effect_handle)
1237 {
1238         int status;
1239
1240         if (device_handle_count == 0) {
1241                 ERR("Haptic device is not opened yet");
1242                 return HAPTIC_NOT_OPENED;
1243         }
1244
1245         if (has_haptic_module == 0) {
1246                 ERR("%s() is not supported without specific haptic module", __func__);
1247                 return HAPTIC_NOT_SUPPORTED;
1248         }
1249
1250         return plugin_intf->haptic_internal_pause_playing_effect(device_handle, effect_handle);
1251 }
1252
1253         EXTAPI
1254 int device_haptic_resume_paused_effect(int device_handle, int effect_handle)
1255 {
1256         int status;
1257
1258         if (device_handle_count == 0) {
1259                 ERR("Haptic device is not opened yet");
1260                 return HAPTIC_NOT_OPENED;
1261         }
1262
1263         if (has_haptic_module == 0) {
1264                 ERR("%s() is not supported without specific haptic module", __func__);
1265                 return HAPTIC_NOT_SUPPORTED;
1266         }
1267
1268         return plugin_intf->haptic_internal_resume_paused_effect(device_handle, effect_handle);
1269 }
1270
1271         EXTAPI
1272 int device_haptic_get_effect_state(int device_handle, int effect_handle, int *effect_state)
1273 {
1274         int status;
1275
1276         if (device_handle_count == 0) {
1277                 ERR("Haptic device is not opened yet");
1278                 return HAPTIC_NOT_OPENED;
1279         }
1280
1281         if (has_haptic_module == 0) {
1282                 ERR("%s() is not supported without specific haptic module", __func__);
1283                 return HAPTIC_NOT_SUPPORTED;
1284         }
1285
1286         return plugin_intf->haptic_internal_get_effect_state(device_handle, effect_handle, effect_state);
1287 }
1288
1289         EXTAPI
1290 int device_haptic_get_size(const unsigned char *haptic_buffer, int size)
1291 {
1292         int status;
1293
1294         if (device_handle_count == 0) {
1295                 ERR("Haptic device is not opened yet");
1296                 return HAPTIC_NOT_OPENED;
1297         }
1298
1299         if (has_haptic_module == 0) {
1300                 ERR("%s() is not supported without specific haptic module", __func__);
1301                 return HAPTIC_NOT_SUPPORTED;
1302         }
1303
1304         return plugin_intf->haptic_internal_get_IVT_size(haptic_buffer, size);
1305 }
1306
1307         EXTAPI
1308 int device_haptic_initialize_buffer(unsigned char *haptic_buffer, int size)
1309 {
1310         int status;
1311
1312         if (device_handle_count == 0) {
1313                 ERR("Haptic device is not opened yet");
1314                 return HAPTIC_NOT_OPENED;
1315         }
1316
1317         if (has_haptic_module == 0) {
1318                 ERR("%s() is not supported without specific haptic module", __func__);
1319                 return HAPTIC_NOT_SUPPORTED;
1320         }
1321
1322         return plugin_intf->haptic_internal_initialize_IVT_buffer(haptic_buffer, size);
1323 }
1324
1325         EXTAPI
1326 int device_haptic_insert_element(unsigned char *haptic_buffer, int size, int timeline_index, const HapticElement *element)
1327 {
1328         int status;
1329
1330         if (device_handle_count == 0) {
1331                 ERR("Haptic device is not opened yet");
1332                 return HAPTIC_NOT_OPENED;
1333         }
1334
1335         if (has_haptic_module == 0) {
1336                 ERR("%s() is not supported without specific haptic module", __func__);
1337                 return HAPTIC_NOT_SUPPORTED;
1338         }
1339
1340         return plugin_intf->haptic_internal_insert_IVT_element(haptic_buffer, size, timeline_index, element);
1341 }
1342
1343         EXTAPI
1344 int device_haptic_insert_element2(unsigned char *haptic_buffer, int size, int timeline_index, const HapticElement2 *element)
1345 {
1346         int status;
1347
1348         if (device_handle_count == 0) {
1349                 ERR("Haptic device is not opened yet");
1350                 return HAPTIC_NOT_OPENED;
1351         }
1352
1353         if (has_haptic_module == 0) {
1354                 ERR("%s() is not supported without specific haptic module", __func__);
1355                 return HAPTIC_NOT_SUPPORTED;
1356         }
1357
1358         return plugin_intf->haptic_internal_insert_IVT_element2(haptic_buffer, size, timeline_index, element);
1359 }
1360
1361         EXTAPI
1362 int device_haptic_insert_element3(unsigned char *haptic_buffer, int size, int timeline_index, const HapticElement3 *element)
1363 {
1364         int status;
1365
1366         if (device_handle_count == 0) {
1367                 ERR("Haptic device is not opened yet");
1368                 return HAPTIC_NOT_OPENED;
1369         }
1370
1371         if (has_haptic_module == 0) {
1372                 ERR("%s() is not supported without specific haptic module", __func__);
1373                 return HAPTIC_NOT_SUPPORTED;
1374         }
1375
1376         return plugin_intf->haptic_internal_insert_IVT_element3(haptic_buffer, size, timeline_index, element);
1377 }
1378
1379         EXTAPI
1380 int device_haptic_read_element(const unsigned char *haptic_buffer, int size, int timeline_index, int element_index, HapticElement *element)
1381 {
1382         int status;
1383
1384         if (device_handle_count == 0) {
1385                 ERR("Haptic device is not opened yet");
1386                 return HAPTIC_NOT_OPENED;
1387         }
1388
1389         if (has_haptic_module == 0) {
1390                 ERR("%s() is not supported without specific haptic module", __func__);
1391                 return HAPTIC_NOT_SUPPORTED;
1392         }
1393
1394         return plugin_intf->haptic_internal_read_IVT_element(haptic_buffer, size, timeline_index, element_index, element);
1395 }
1396
1397         EXTAPI
1398 int device_haptic_read_element2(const unsigned char *haptic_buffer, int size, int timeline_index, int element_index, HapticElement2 *element)
1399 {
1400         int status;
1401
1402         if (device_handle_count == 0) {
1403                 ERR("Haptic device is not opened yet");
1404                 return HAPTIC_NOT_OPENED;
1405         }
1406
1407         if (has_haptic_module == 0) {
1408                 ERR("%s() is not supported without specific haptic module", __func__);
1409                 return HAPTIC_NOT_SUPPORTED;
1410         }
1411
1412         return plugin_intf->haptic_internal_read_IVT_element2(haptic_buffer, size, timeline_index, element_index, element);
1413 }
1414
1415         EXTAPI
1416 int device_haptic_read_element3(const unsigned char *haptic_buffer, int size, int timeline_index, int element_index, HapticElement3 *element)
1417 {
1418         int status;
1419
1420         if (device_handle_count == 0) {
1421                 ERR("Haptic device is not opened yet");
1422                 return HAPTIC_NOT_OPENED;
1423         }
1424
1425         if (has_haptic_module == 0) {
1426                 ERR("%s() is not supported without specific haptic module", __func__);
1427                 return HAPTIC_NOT_SUPPORTED;
1428         }
1429
1430         return plugin_intf->haptic_internal_read_IVT_element3(haptic_buffer, size, timeline_index, element_index, element);
1431 }
1432
1433         EXTAPI
1434 int device_haptic_remove_element(unsigned char *haptic_buffer, int size, int timeline_index, int element_index)
1435 {
1436         int status;
1437
1438         if (device_handle_count == 0) {
1439                 ERR("Haptic device is not opened yet");
1440                 return HAPTIC_NOT_OPENED;
1441         }
1442
1443         if (has_haptic_module == 0) {
1444                 ERR("%s() is not supported without specific haptic module", __func__);
1445                 return HAPTIC_NOT_SUPPORTED;
1446         }
1447
1448         return plugin_intf->haptic_internal_remove_IVT_element(haptic_buffer, size, timeline_index, element_index);
1449 }
1450 /* END: devman_haptic_ext APIs */
1451
1452 static void __attribute__ ((constructor)) module_init()
1453 {
1454         char *error;
1455
1456         if (access(HAPTIC_DEVICE_NODE_PATH, F_OK) < 0) {
1457                 has_haptic_module = 0;
1458                 return;
1459         } else {
1460                 has_haptic_module = 1;
1461         }
1462
1463         dlopen_handle = dlopen(HAPTIC_MODULE_PATH, RTLD_NOW);
1464         if (!dlopen_handle) {
1465                 ERR("dlopen failed: %s", dlerror());
1466                 has_haptic_module = 0;
1467                 return;
1468         }
1469
1470         const devman_haptic_plugin_interface *(*get_devman_haptic_plugin_interface) ();
1471         get_devman_haptic_plugin_interface = dlsym(dlopen_handle, "get_devman_haptic_plugin_interface");
1472         if ((error = dlerror()) != NULL) {
1473                 ERR("dlsym failed : %s", error);
1474                 has_haptic_module = 0;
1475                 dlclose(dlopen_handle);
1476                 return;
1477         }
1478
1479         plugin_intf = get_devman_haptic_plugin_interface();
1480         if (!plugin_intf) {
1481                 ERR("get_devman_haptic_plugin_interface() failed");
1482                 has_haptic_module = 0;
1483                 dlclose(dlopen_handle);
1484                 return;
1485         }
1486 }
1487
1488 static void __attribute__ ((destructor)) module_fini()
1489 {
1490         if (dlopen_handle) {
1491                 dlclose(dlopen_handle);
1492         }
1493 }
1494