2.0 alpha
[platform/core/system/devman.git] / src / 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 #include <iniparser.h>
33
34 #include "devlog.h"
35 #include "device_haptic.h"
36 #include "devman.h"
37 #include "devman_haptic.h"
38 #include "devman_haptic_ext.h"
39 #include "devman_haptic_plugin_intf.h"
40 /* START: Will be excluded by removing pattern */
41 #include "device_haptic_tsp4000_pattern.h"
42 /* END: Will be excluded */
43
44 #ifndef EXTAPI
45 #define EXTAPI __attribute__ ((visibility("default")))
46 #endif /* EXTAPI */
47
48 #define HAPTIC_DEVICE_NODE_PATH         "/dev/tspdrv"
49 #define HAPTIC_MODULE_PATH              "/usr/lib/devman/libdevman_haptic.so"
50
51 #define __STR_EMUL                              "emul"
52 #define __LEN_STR_EMUL                          4
53 #define BIN_INFO_FILE_PATH                      "/etc/info.ini"
54
55 /* START: Will be supported by kernel */
56 //#define NEED_THE_SUPPORT_OF_KERNEL
57 /* END: Will be supported */
58
59 /* START: Will be removed by removing pattern */
60 struct g_pivt_list_t
61 {
62         unsigned char *ivt_pt;
63         int priority;
64 };
65
66 struct g_pivt_list_t g_haptic_internal_pattern_list[EFFCTVIBE_PATTERN_END] = {
67         /*for BeatUX*/
68         [EFFCTVIBE_TOUCH]                       = { touch_ivt, 15},
69         [EFFCTVIBE_HW_TOUCH]                    = { hw_touch_ivt, 15},
70
71         [EFFCTVIBE_NOTIFICATION]                = { noti_ivt, 7},
72         [EFFCTVIBE_INCOMING_CALL01]             = { incomming_01_ivt, 7},
73         [EFFCTVIBE_INCOMING_CALL02]             = { incomming_02_ivt, 7},
74         [EFFCTVIBE_INCOMING_CALL03]             = { incomming_03_ivt, 7},
75
76         [EFFCTVIBE_ALERTS_CALL]                 = { alerts_call_ivt, 15},
77         [EFFCTVIBE_OPERATION]                   = { operation_ivt, 7},
78         [EFFCTVIBE_SILENT_MODE]                 = { silent_ivt, 7},
79 };
80 /* END: Will be removed */
81
82 static enum {
83         MODULE_NONE = 0,
84         MODULE_BASIC,
85         MODULE_TSP,
86         MODULE_EMUL,
87 };
88
89 static int has_haptic_module = MODULE_NONE;
90 static int feedback_mode = 0;
91 static int device_handle_count = 0;
92
93 /* Device Manager Haptic Plugin Interface */
94 static void *dlopen_handle;
95 static const devman_haptic_plugin_interface *plugin_intf;
96
97 enum {
98         MODE_DEFAULT = 0x0000,
99         MODE_FEEDBACK_LEVEL_CHECK_DISABLE = 0x0001,
100 };
101
102 /* START of Static Function Section */
103 static int __get_master_strength_value()
104 {
105         int setting_fb_level = -1;
106
107         if (feedback_mode)
108                 return VIBE_FEEDBACK_LEVEL_3;
109
110         if (vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &setting_fb_level) < 0) {
111                 setting_fb_level = SETTING_VIB_FEEDBACK_LEVEL3;
112         }
113
114         switch (setting_fb_level) {
115         case SETTING_VIB_FEEDBACK_LEVEL0:
116                 return 0;
117         case SETTING_VIB_FEEDBACK_LEVEL1:
118                 return VIBE_FEEDBACK_LEVEL_1;
119         case SETTING_VIB_FEEDBACK_LEVEL2:
120                 return VIBE_FEEDBACK_LEVEL_2;
121         case SETTING_VIB_FEEDBACK_LEVEL3:
122                 return VIBE_FEEDBACK_LEVEL_3;
123         case SETTING_VIB_FEEDBACK_LEVEL4:
124                 return VIBE_FEEDBACK_LEVEL_4;
125         case SETTING_VIB_FEEDBACK_LEVEL5:
126                 return VIBE_FEEDBACK_LEVEL_5;
127         }
128         ERR("error get VCONF_SETAPPL_VIB_FEEDBACK_INT value (= %d) invalid", setting_fb_level);
129     return -1;
130 }
131
132 static int __convert_strength_level(int base_level)
133 {
134         switch (base_level) {
135         case HAPTIC_FEEDBACK_LEVEL_0:
136                 return VIBE_FEEDBACK_LEVEL_0;
137         case HAPTIC_FEEDBACK_LEVEL_1:
138                 return VIBE_FEEDBACK_LEVEL_1;
139         case HAPTIC_FEEDBACK_LEVEL_2:
140                 return VIBE_FEEDBACK_LEVEL_2;
141         case HAPTIC_FEEDBACK_LEVEL_3:
142                 return VIBE_FEEDBACK_LEVEL_3;
143         case HAPTIC_FEEDBACK_LEVEL_4:
144                 return VIBE_FEEDBACK_LEVEL_4;
145         case HAPTIC_FEEDBACK_LEVEL_5:
146                 return VIBE_FEEDBACK_LEVEL_5;
147         }
148         ERR("error invalid convertable value (%d)", base_level);
149         return -1;
150 }
151
152 static int __convert_priority_level(int base_level)
153 {
154         switch (base_level) {
155         case HAPTIC_PRIORITY_LEVEL_MIN:
156                 return HAPTIC_MIN_DEVICE_PRIORITY;
157         case HAPTIC_PRIORITY_LEVEL_MAX_DEV:
158                 return HAPTIC_MAX_DEV_DEVICE_PRIORITY;
159         case HAPTIC_PRIORITY_LEVEL_MAX_OEM:
160                 return HAPTIC_MAX_OEM_DEVICE_PRIORITY;
161         }
162         ERR("error invalid convertable value (%d)", base_level);
163         return -1;
164 }
165
166 static int __is_emulator_binary()
167 {
168         char szEmul[__LEN_STR_EMUL+1];
169         const char* szBinVer = NULL;
170
171         dictionary* dic = iniparser_load(BIN_INFO_FILE_PATH);
172         // when failed to get the info, let's regard the binary as an emulator one
173         if (!dic)
174                 return 1;
175
176         szBinVer = (const char*)iniparser_getstr(dic, "Version:Build");
177         if (szBinVer) {
178                 char* str = g_strdup(szBinVer);
179                 if (str) {
180                         char* pPos = str;
181                         while (*pPos++) {
182                                 if ('_' == *pPos)
183                                         *pPos = ' ';
184                         }
185                         sscanf(str, "%*s %4s", szEmul);
186                 }
187                 g_free(str);
188         }
189
190         if (dic) {
191                 iniparser_freedict(dic);
192                 dic = NULL;
193         }
194
195         if (!strncmp(szEmul, __STR_EMUL, __LEN_STR_EMUL))
196                 return 1;
197
198         return 0;
199 }
200 /* END of Static Function Section */
201
202 /* START: devman_haptic APIs */
203 EXTAPI
204 int device_haptic_open(haptic_dev_idx dev_idx, unsigned int mode)
205 {
206         int status;
207         int device_index = dev_idx >> 1;
208         int device_handle;
209
210         if (!(dev_idx == DEV_IDX_0 || dev_idx == DEV_IDX_1 || dev_idx == DEV_IDX_ALL)) {
211                 ERR("Invalid parameter - dev_idx(%d)", dev_idx);
212                 return HAPTIC_INVALID_ARGUMENT;
213         }
214
215         DBG("handle count : %d, haptic module : %d\n", device_handle_count, has_haptic_module);
216
217         if (has_haptic_module == MODULE_NONE) {
218                 ERR("%s() is not supported without specific haptic module", __func__);
219                 return HAPTIC_NOT_SUPPORTED;
220         }
221
222         if (device_handle_count == 0) {
223                 if (has_haptic_module == MODULE_TSP) {
224                         plugin_intf->haptic_internal_prepare_node();
225
226                         if (plugin_intf->haptic_internal_initialize() < 0) {
227                                 ERR("plugin_intf->haptic_internal_initialize() failed");
228                                 return HAPTIC_FAIL;
229                         }
230                 }
231
232                 if (mode & MODE_FEEDBACK_LEVEL_CHECK_DISABLE) {
233                         pid_t cpid;
234                         cpid = getpid();
235                         DBG("NOT USE MAIN VIB_FEEDBACK_CHECK ROUTINE !!, at pid : %d", cpid);
236                         feedback_mode = 1;
237                 }
238         }
239
240         if (has_haptic_module == MODULE_TSP) {
241                 if (dev_idx == DEV_IDX_ALL) {
242                         status = plugin_intf->haptic_internal_open_composite_device(NULL, device_index, &device_handle);
243                         if(HAPTIC_FAILED(status)) {
244                                 ERR("plugin_intf->haptic_internal_open_composite_device() Failed: %d", status);
245                                 return HAPTIC_FAIL;
246                         }
247                 } else {
248                         status = plugin_intf->haptic_internal_open_device(device_index, &device_handle);
249                         if(HAPTIC_FAILED(status)) {
250                                 ERR("plugin_intf->haptic_internal_open_device() Failed: %d", status);
251                                 return HAPTIC_FAIL;
252                         }
253                 }
254
255                 ++device_handle_count;
256                 return device_handle;
257         }
258
259         ++device_handle_count;
260         return DEFAULT_DEVICE_HANDLE;
261 }
262
263 EXTAPI
264 int device_haptic_close(int device_handle)
265 {
266         int status;
267
268         if (has_haptic_module == MODULE_EMUL)
269                 return HAPTIC_SUCCESS;
270
271         if (has_haptic_module == MODULE_NONE) {
272                 ERR("%s() is not supported without specific haptic module", __func__);
273                 return HAPTIC_NOT_SUPPORTED;
274         }
275
276         if (device_handle_count == 0) {
277                 ERR("Haptic device already closed");
278                 return HAPTIC_NOT_OPENED;
279         }
280
281         if (has_haptic_module == MODULE_TSP) {
282                 status = plugin_intf->haptic_internal_close_device(device_handle);
283                 if(HAPTIC_FAILED(status)) {
284                         ERR("plugin_intf->haptic_internal_close_device(0) fail: %d", status);
285                         return HAPTIC_FAIL;
286                 }
287         }
288
289         --device_handle_count;
290         if (device_handle_count == 0) {
291                 if (has_haptic_module == MODULE_TSP) {
292                         status = plugin_intf->haptic_internal_terminate();
293                         if(HAPTIC_FAILED(status)) {
294                                 ERR("plugin_intf->haptic_internal_terminate(0) fail: %d", status);
295                                 return HAPTIC_FAIL;
296                         }
297                 } else {
298                         status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_ENABLE, 0);
299                         if (status < 0) {
300                                 ERR("Haptic device close failed: %d", status);
301                                 return HAPTIC_FAIL;
302                         }
303                 }
304                 feedback_mode = 0;
305         }
306
307         return HAPTIC_SUCCESS;
308 }
309
310 EXTAPI
311 int device_haptic_play_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback_level)
312 {
313         int input_feedback_level;
314
315         if (vibe_buffer == NULL || iteration < 0) {
316                 ERR("Invalid parameter - vibe_buffer(NULL) or iteration(%d)", iteration);
317                 return HAPTIC_INVALID_ARGUMENT;
318         }
319
320         if (feedback_level < HAPTIC_FEEDBACK_LEVEL_AUTO || feedback_level > HAPTIC_FEEDBACK_LEVEL_END-1) {
321                 ERR("feedback_level is wrong : %d", feedback_level);
322                 return HAPTIC_INVALID_ARGUMENT;
323         }
324
325         if (has_haptic_module == MODULE_EMUL)
326                 return HAPTIC_SUCCESS;
327
328         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
329                 ERR("%s() is not supported without specific haptic module", __func__);
330                 return HAPTIC_NOT_SUPPORTED;
331         }
332
333         if (device_handle_count == 0) {
334                 ERR("Haptic device is not opened yet");
335                 return HAPTIC_NOT_OPENED;
336         }
337
338         if (feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
339                 input_feedback_level = __get_master_strength_value();
340         } else {
341                 input_feedback_level = __convert_strength_level(feedback_level);
342         }
343
344         if (input_feedback_level == VIBE_FEEDBACK_LEVEL_0) {
345                 DBG("feedback_level is 0, so can not vibe");
346                 return HAPTIC_SUCCESS;
347         }
348
349         DBG("iteration : %d, feedback_level : %d, priority : %d", iteration, input_feedback_level, HAPTIC_MIN_DEVICE_PRIORITY);
350         return plugin_intf->haptic_internal_play_buffer(device_handle, vibe_buffer, iteration, input_feedback_level, HAPTIC_MIN_DEVICE_PRIORITY);
351 }
352
353 EXTAPI
354 int device_haptic_play_file(int device_handle, const char *file_name, int iteration, int feedback_level)
355 {
356         int input_feedback_level;
357
358         if (file_name == NULL || iteration < 0) {
359                 ERR("Invalid parameter - file_name(NULL) or iteration(%d)", iteration);
360                 return HAPTIC_INVALID_ARGUMENT;
361         }
362
363         if (feedback_level < HAPTIC_FEEDBACK_LEVEL_AUTO || feedback_level > HAPTIC_FEEDBACK_LEVEL_END-1) {
364                 ERR("feedback_level is wrong : %d", feedback_level);
365                 return HAPTIC_INVALID_ARGUMENT;
366         }
367
368         if (has_haptic_module == MODULE_EMUL)
369                 return HAPTIC_SUCCESS;
370
371         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
372                 ERR("%s() is not supported without specific haptic module", __func__);
373                 return HAPTIC_NOT_SUPPORTED;
374         }
375
376         if (device_handle_count == 0) {
377                 ERR("Haptic device is not opened yet");
378                 return HAPTIC_NOT_OPENED;
379         }
380
381         if (feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
382                 input_feedback_level = __get_master_strength_value();
383         } else {
384                 input_feedback_level = __convert_strength_level(feedback_level);
385         }
386
387         if (input_feedback_level == VIBE_FEEDBACK_LEVEL_0) {
388                 DBG("feedback_level is 0, so can not vibe");
389                 return HAPTIC_SUCCESS;
390         }
391
392         DBG("iteration : %d, feedback_level : %d, priority : %d", iteration, input_feedback_level, HAPTIC_MIN_DEVICE_PRIORITY);
393         return plugin_intf->haptic_internal_play_file(device_handle, file_name, iteration, input_feedback_level, HAPTIC_MIN_DEVICE_PRIORITY);
394 }
395
396 EXTAPI
397 int device_haptic_play_file_with_priority(int device_handle, const char *file_name, int priority_level, int iteration, int feedback_level)
398 {
399         int input_feedback_level;
400         int input_priority_level;
401
402         if (file_name == NULL || iteration < 0) {
403                 ERR("Invalid parameter - file_name(NULL) or iteration(%d)", iteration);
404                 return HAPTIC_INVALID_ARGUMENT;
405         }
406
407         if (priority_level < HAPTIC_PRIORITY_LEVEL_MIN || priority_level > HAPTIC_PRIORITY_LEVEL_MAX_OEM) {
408                 ERR("priority_level is wrong : %d", priority_level);
409                 return HAPTIC_INVALID_ARGUMENT;
410         }
411
412         if (feedback_level < HAPTIC_FEEDBACK_LEVEL_AUTO || feedback_level > HAPTIC_FEEDBACK_LEVEL_END-1) {
413                 ERR("feedback_level is wrong : %d", feedback_level);
414                 return HAPTIC_INVALID_ARGUMENT;
415         }
416
417         if (has_haptic_module == MODULE_EMUL)
418                 return HAPTIC_SUCCESS;
419
420         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
421                 ERR("%s() is not supported without specific haptic module", __func__);
422                 return HAPTIC_NOT_SUPPORTED;
423         }
424
425         if (device_handle_count == 0) {
426                 ERR("Haptic device is not opened yet");
427                 return HAPTIC_NOT_OPENED;
428         }
429
430         input_priority_level = __convert_priority_level(priority_level);
431
432         if (feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
433                 input_feedback_level = __get_master_strength_value();
434         } else {
435                 input_feedback_level = __convert_strength_level(feedback_level);
436         }
437
438         if (input_feedback_level == VIBE_FEEDBACK_LEVEL_0) {
439                 DBG("feedback_level is 0, so can not vibe");
440                 return HAPTIC_SUCCESS;
441         }
442
443         DBG("iteration : %d, feedback_level : %d, priority : %d", iteration, input_feedback_level, input_priority_level);
444         return plugin_intf->haptic_internal_play_file(device_handle, file_name, iteration, input_feedback_level, input_priority_level);
445 }
446
447 EXTAPI
448 int device_haptic_play_pattern(int device_handle, int pattern, int iteration, int feedback_level)
449 {
450         int input_priority_level = -1;
451         int input_feedback_level;
452
453         if (pattern < EFFCTVIBE_TOUCH || pattern > EFFCTVIBE_PATTERN_END-1) {
454                 ERR("Pattern value(%d) is not valid", pattern);
455                 return HAPTIC_INVALID_ARGUMENT;
456         }
457
458         if (!g_haptic_internal_pattern_list[pattern].ivt_pt) {
459                 ERR("This pattern value(%d) doesn't have a pattern buffer", pattern);
460                 return HAPTIC_INVALID_ARGUMENT;
461         }
462
463         if (feedback_level < HAPTIC_FEEDBACK_LEVEL_AUTO || feedback_level > HAPTIC_FEEDBACK_LEVEL_END-1) {
464                 ERR("feedback_level is wrong : %d", feedback_level);
465                 return HAPTIC_INVALID_ARGUMENT;
466         }
467
468         if (has_haptic_module == MODULE_EMUL)
469                 return HAPTIC_SUCCESS;
470
471         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
472                 ERR("%s() is not supported without specific haptic module", __func__);
473                 return HAPTIC_NOT_SUPPORTED;
474         }
475
476         if (device_handle_count == 0) {
477                 ERR("Haptic device is not opened yet");
478                 return HAPTIC_NOT_OPENED;
479         }
480
481         if (feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
482                 input_feedback_level = __get_master_strength_value();
483         } else {
484                 input_feedback_level = __convert_strength_level(feedback_level);
485         }
486
487         if (input_feedback_level == VIBE_FEEDBACK_LEVEL_0) {
488                 DBG("feedback_level is 0, so can not vibe");
489                 return HAPTIC_SUCCESS;
490         }
491
492         /* Set Priority */
493         if (!g_haptic_internal_pattern_list[pattern].priority) {
494                 input_priority_level = HAPTIC_MIN_DEVICE_PRIORITY;
495         } else {
496                 input_priority_level = g_haptic_internal_pattern_list[pattern].priority;
497         }
498
499         DBG("iteration : %d, feedback_level : %d, priority : %d", iteration, input_feedback_level, input_priority_level);
500         return plugin_intf->haptic_internal_play_buffer(device_handle, g_haptic_internal_pattern_list[pattern].ivt_pt, iteration, input_feedback_level, input_priority_level);
501 }
502
503 EXTAPI
504 int device_haptic_stop_play(int device_handle)
505 {
506         int status;
507
508         if (has_haptic_module == MODULE_EMUL)
509                 return HAPTIC_SUCCESS;
510
511         if (has_haptic_module == MODULE_NONE) {
512                 ERR("%s() is not supported without specific haptic module", __func__);
513                 return HAPTIC_NOT_SUPPORTED;
514         }
515
516         if (device_handle_count == 0) {
517                 ERR("Haptic device is not opened yet");
518                 return HAPTIC_NOT_OPENED;
519         }
520
521         if (has_haptic_module == MODULE_TSP) {
522                 status = plugin_intf->haptic_internal_stop_all_playing_effects(device_handle);
523                 if(HAPTIC_FAILED(status)) {
524                         ERR("plugin_intf->haptic_internal_stop_all_playing_effects(0) fail: %d", status);
525                         return HAPTIC_FAIL;
526                 }
527         } else {
528                 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_ENABLE, 0);
529                 if (status < 0) {
530                         ERR("Haptic device stop failed: %d", status);
531                         return HAPTIC_FAIL;
532                 }
533         }
534
535         return HAPTIC_SUCCESS;
536 }
537
538 EXTAPI
539 int device_haptic_play_monotone(int device_handle, int duration)
540 {
541         return device_haptic_play_monotone_with_feedback_level(device_handle, duration, HAPTIC_FEEDBACK_LEVEL_AUTO);
542 }
543
544 EXTAPI
545 int device_haptic_play_monotone_with_feedback_level(int device_handle, int duration, int feedback_level)
546 {
547         int status;
548         int input_strength;
549         int input_feedback_level;
550
551         if (duration < 0) {
552                 ERR("Invalid parameter - duration(%d)", duration);
553                 return HAPTIC_INVALID_ARGUMENT;
554         }
555
556         if (feedback_level < HAPTIC_FEEDBACK_LEVEL_AUTO || feedback_level > HAPTIC_FEEDBACK_LEVEL_END-1) {
557                 ERR("feedback_level is wrong : %d", feedback_level);
558                 return HAPTIC_INVALID_ARGUMENT;
559         }
560
561         if (has_haptic_module == MODULE_EMUL)
562                 return HAPTIC_SUCCESS;
563
564         if (has_haptic_module == MODULE_NONE) {
565                 ERR("%s() is not supported without specific haptic module", __func__);
566                 return HAPTIC_NOT_SUPPORTED;
567         }
568
569         if (device_handle_count == 0) {
570                 ERR("Haptic device is not opened yet");
571                 return HAPTIC_NOT_OPENED;
572         }
573
574         if (feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
575                 input_feedback_level = __get_master_strength_value();
576         } else {
577                 input_feedback_level = __convert_strength_level(feedback_level);
578         }
579
580         if (input_feedback_level == VIBE_FEEDBACK_LEVEL_0) {
581                 DBG("feedback_level is 0, so can not vibe");
582                 return HAPTIC_SUCCESS;
583         }
584
585         DBG("duration : %d, feedback_level : %d, priority : %d", duration, input_feedback_level, 0x05);
586         if (has_haptic_module == MODULE_TSP) {
587                 status = plugin_intf->haptic_internal_play_monotone(device_handle, duration, input_feedback_level, 0x05);
588                 if(HAPTIC_FAILED(status)) {
589                         ERR("plugin_intf->haptic_internal_play_monotone(0) fail: %d", status);
590                         return HAPTIC_FAIL;
591                 }
592         } else {
593                 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_LEVEL, (input_feedback_level-1)/100);
594                 if (status < 0) {
595                         ERR(" haptic_set_level for strength:%d (error:%d) \n", input_strength, status);
596                         return HAPTIC_FAIL;
597                 }
598
599                 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_ONESHOT, duration);
600                 if (status < 0) {
601                         ERR(" haptic_oneshot for duration:%d (error:%d) \n", duration, status);
602                         return HAPTIC_FAIL;
603                 }
604         }
605
606         return HAPTIC_SUCCESS;
607 }
608
609 EXTAPI
610 int device_haptic_play_monotone_with_detail_feedback_level(int device_handle, int duration, int detail_feedback_level)
611 {
612         int status;
613         int input_strength;
614         int input_feedback_level;
615
616         if (duration < 0) {
617                 ERR("Invalid parameter - duration(%d)", duration);
618                 return HAPTIC_INVALID_ARGUMENT;
619         }
620
621         if (detail_feedback_level < HAPTIC_FEEDBACK_LEVEL_AUTO || detail_feedback_level > 100) {
622                 ERR("detail_feedback_level is wrong : %d", detail_feedback_level);
623                 return HAPTIC_INVALID_ARGUMENT;
624         }
625
626         if (has_haptic_module == MODULE_EMUL)
627                 return HAPTIC_SUCCESS;
628
629         if (has_haptic_module == MODULE_NONE) {
630                 ERR("%s() is not supported without specific haptic module", __func__);
631                 return HAPTIC_NOT_SUPPORTED;
632         }
633
634         if (device_handle_count == 0) {
635                 ERR("Haptic device is not opened yet");
636                 return HAPTIC_NOT_OPENED;
637         }
638
639         if (detail_feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
640                 input_feedback_level = __get_master_strength_value();
641         } else {
642                 input_feedback_level = detail_feedback_level * 100;
643         }
644
645         if (input_feedback_level == 0) {
646                 DBG("feedback_level is 0, so can not vibe");
647                 return HAPTIC_SUCCESS;
648         }
649
650         DBG("duration : %d, feedback_level : %d, priority : %d", duration, input_feedback_level, 0x05);
651         if (has_haptic_module == MODULE_TSP) {
652                 status = plugin_intf->haptic_internal_play_monotone(device_handle, duration, input_feedback_level, 0x05);
653                 if(HAPTIC_FAILED(status)) {
654                         ERR("plugin_intf->haptic_internal_play_monotone(0) fail: %d", status);
655                         return HAPTIC_FAIL;
656                 }
657         } else {
658                 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_LEVEL, (input_feedback_level-1)/100);
659                 if (status < 0) {
660                         ERR(" haptic_set_level for strength:%d (error:%d) \n", input_strength, status);
661                         return HAPTIC_FAIL;
662                 }
663
664                 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_ONESHOT, duration);
665                 if (status < 0) {
666                         ERR(" haptic_oneshot for duration:%d (error:%d) \n", duration, status);
667                         return HAPTIC_FAIL;
668                 }
669         }
670
671         return HAPTIC_SUCCESS;
672 }
673
674 EXTAPI
675 int device_haptic_get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *duration)
676 {
677         if (vibe_buffer == NULL || duration == NULL) {
678                 ERR("Invalid parameter - vibe_buffer(NULL) or duration(NULL)");
679                 return HAPTIC_INVALID_ARGUMENT;
680         }
681
682         if (has_haptic_module == MODULE_EMUL) {
683                 *duration = DEFAULT_DURATION_VALUE;
684                 return HAPTIC_SUCCESS;
685         }
686
687         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
688                 ERR("%s() is not supported without specific haptic module", __func__);
689                 return HAPTIC_NOT_SUPPORTED;
690         }
691
692         if (device_handle_count == 0) {
693                 ERR("Haptic device is not opened yet");
694                 return HAPTIC_NOT_OPENED;
695         }
696
697         return plugin_intf->haptic_internal_get_buffer_duration(device_handle, vibe_buffer, duration);
698 }
699
700 EXTAPI
701 int device_haptic_get_file_duration(int device_handle, const char *file_name, int *duration)
702 {
703         if (file_name == NULL || duration == NULL) {
704                 ERR("Invalid parameter - file_name(NULL) or duration(NULL)");
705                 return HAPTIC_INVALID_ARGUMENT;
706         }
707
708         if (has_haptic_module == MODULE_EMUL) {
709                 *duration = DEFAULT_DURATION_VALUE;
710                 return HAPTIC_SUCCESS;
711         }
712
713         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
714                 ERR("%s() is not supported without specific haptic module", __func__);
715                 return HAPTIC_NOT_SUPPORTED;
716         }
717
718         if (device_handle_count == 0) {
719                 ERR("Haptic device is not opened yet");
720                 return HAPTIC_NOT_OPENED;
721         }
722
723         return plugin_intf->haptic_internal_get_file_duration(device_handle, file_name, duration);
724 }
725
726 EXTAPI
727 int device_haptic_get_pattern_duration(int device_handle, int pattern, int *duration)
728 {
729         if (duration == NULL) {
730                 ERR("Invalid parameter - duration(NULL)");
731                 return HAPTIC_INVALID_ARGUMENT;
732         }
733
734         if (pattern < EFFCTVIBE_TOUCH || pattern > EFFCTVIBE_PATTERN_END-1) {
735                 ERR("Pattern value(%d) is not valid", pattern);
736                 return HAPTIC_INVALID_ARGUMENT;
737         }
738
739         if (!g_haptic_internal_pattern_list[pattern].ivt_pt) {
740                 ERR("This pattern value(%d) doesn't have a pattern buffer", pattern);
741                 return HAPTIC_INVALID_ARGUMENT;
742         }
743
744         if (has_haptic_module == MODULE_EMUL) {
745                 *duration = DEFAULT_DURATION_VALUE;
746                 return HAPTIC_SUCCESS;
747         }
748
749         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
750                 ERR("%s() is not supported without specific haptic module", __func__);
751                 return HAPTIC_NOT_SUPPORTED;
752         }
753
754         if (device_handle_count == 0) {
755                 ERR("Haptic device is not opened yet");
756                 return HAPTIC_NOT_OPENED;
757         }
758
759         return plugin_intf->haptic_internal_get_buffer_duration(device_handle, g_haptic_internal_pattern_list[pattern].ivt_pt, duration);
760 }
761
762 EXTAPI
763 int device_haptic_get_device_count()
764 {
765         int status;
766         int device_count = -1;
767
768         if (has_haptic_module == MODULE_NONE) {
769                 return HAPTIC_NOT_SUPPORTED;
770         }
771
772         if (has_haptic_module == MODULE_TSP) {
773                 if (device_handle_count == 0) {
774                         plugin_intf->haptic_internal_prepare_node();
775
776                         status = plugin_intf->haptic_internal_initialize();
777                         if (status < 0) {
778                                 return HAPTIC_FAIL;
779                         }
780                         /* Get device count */
781                         device_count = plugin_intf->haptic_internal_get_device_count();
782                         if(HAPTIC_FAILED(device_count)) {
783                                 ERR("plugin_intf->haptic_internal_get_device_count(0) fail: %d",status);
784                                 return HAPTIC_FAIL;
785                         }
786
787                         status = plugin_intf->haptic_internal_terminate();
788                         if (status < 0) {
789                                 return HAPTIC_FAIL;
790                         }
791                 } else {
792                         device_count = plugin_intf->haptic_internal_get_device_count();
793                         if(HAPTIC_FAILED(device_count)) {
794                                 ERR("plugin_intf->haptic_internal_get_device_count(0) fail: %d",status);
795                                 return HAPTIC_FAIL;
796                         }
797                 }
798
799                 return device_count;
800         }
801
802         return DEFAULT_MOTOR_COUNT;
803 }
804 /* END: devman_haptic APIs */
805
806
807 /* START: devman_haptic_ext APIs */
808 EXTAPI
809 int device_haptic_get_device_state(int device_index, int *state)
810 {
811         int index = device_index >> 1;
812
813         if (!(device_index == DEV_IDX_0 || device_index == DEV_IDX_1 || device_index == DEV_IDX_ALL)) {
814                 ERR("Invalid parameter - device_index(%d)", device_index);
815                 return HAPTIC_INVALID_ARGUMENT;
816         }
817
818         if (state == NULL) {
819                 ERR("Invalid parameter - state(NULL)");
820                 return HAPTIC_INVALID_ARGUMENT;
821         }
822
823         if (has_haptic_module == MODULE_EMUL)
824                 return HAPTIC_SUCCESS;
825
826         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
827                 ERR("%s() is not supported without specific haptic module", __func__);
828                 return HAPTIC_NOT_SUPPORTED;
829         }
830
831         if (device_handle_count == 0) {
832                 ERR("Haptic device is not opened yet");
833                 return HAPTIC_NOT_OPENED;
834         }
835
836         return plugin_intf->haptic_internal_get_device_state(index, state);
837 }
838
839 EXTAPI
840 int device_haptic_get_device_capability_bool(int device_index, int device_cap_type, unsigned char *device_cap_value)
841 {
842         int index = device_index >> 1;
843
844         if (!(device_index == DEV_IDX_0 || device_index == DEV_IDX_1 || device_index == DEV_IDX_ALL)) {
845                 ERR("Invalid parameter - device_index(%d)", device_index);
846                 return HAPTIC_INVALID_ARGUMENT;
847         }
848
849         if (device_cap_value == NULL) {
850                 ERR("Invalid parameter - device_cap_value(NULL)");
851                 return HAPTIC_INVALID_ARGUMENT;
852         }
853
854         if (device_cap_type < HAPTIC_DEVCAPTYPE_DEVICE_CATEGORY || device_cap_type > HAPTIC_DEVCAPTYPE_HANDSET_INDEX) {
855                 ERR("Invalid parameter - device_cap_type(%d)", device_cap_type);
856                 return HAPTIC_INVALID_ARGUMENT;
857         }
858
859         if (has_haptic_module == MODULE_EMUL)
860                 return HAPTIC_SUCCESS;
861
862         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
863                 ERR("%s() is not supported without specific haptic module", __func__);
864                 return HAPTIC_NOT_SUPPORTED;
865         }
866
867         if (device_handle_count == 0) {
868                 ERR("Haptic device is not opened yet");
869                 return HAPTIC_NOT_OPENED;
870         }
871
872         return plugin_intf->haptic_internal_get_device_capability_bool(index, device_cap_type, device_cap_value);
873 }
874
875 EXTAPI
876 int device_haptic_get_device_capability_int32(int device_index, int device_cap_type, int *device_cap_value)
877 {
878         int index = device_index >> 1;
879
880         if (!(device_index == DEV_IDX_0 || device_index == DEV_IDX_1 || device_index == DEV_IDX_ALL)) {
881                 ERR("Invalid parameter - device_index(%d)", device_index);
882                 return HAPTIC_INVALID_ARGUMENT;
883         }
884
885         if (device_cap_value == NULL) {
886                 ERR("Invalid parameter - device_cap_value(NULL)");
887                 return HAPTIC_INVALID_ARGUMENT;
888         }
889
890         if (device_cap_type < HAPTIC_DEVCAPTYPE_DEVICE_CATEGORY || device_cap_type > HAPTIC_DEVCAPTYPE_HANDSET_INDEX) {
891                 ERR("Invalid parameter - device_cap_type(%d)", device_cap_type);
892                 return HAPTIC_INVALID_ARGUMENT;
893         }
894
895         if (has_haptic_module == MODULE_EMUL)
896                 return HAPTIC_SUCCESS;
897
898         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
899                 ERR("%s() is not supported without specific haptic module", __func__);
900                 return HAPTIC_NOT_SUPPORTED;
901         }
902
903         if (device_handle_count == 0) {
904                 ERR("Haptic device is not opened yet");
905                 return HAPTIC_NOT_OPENED;
906         }
907
908         return plugin_intf->haptic_internal_get_device_capability_int32(index, device_cap_type, device_cap_value);
909 }
910
911 EXTAPI
912 int device_haptic_get_device_capability_string(int device_index, int device_cap_type, int size, char *device_cap_value)
913 {
914         int index = device_index >> 1;
915
916         if (!(device_index == DEV_IDX_0 || device_index == DEV_IDX_1 || device_index == DEV_IDX_ALL)) {
917                 ERR("Invalid parameter - device_index(%d)", device_index);
918                 return HAPTIC_INVALID_ARGUMENT;
919         }
920
921         if (device_cap_value == NULL) {
922                 ERR("Invalid parameter - device_cap_value(NULL)");
923                 return HAPTIC_INVALID_ARGUMENT;
924         }
925
926         if (device_cap_type < HAPTIC_DEVCAPTYPE_DEVICE_CATEGORY || device_cap_type > HAPTIC_DEVCAPTYPE_HANDSET_INDEX) {
927                 ERR("Invalid parameter - device_cap_type(%d)", device_cap_type);
928                 return HAPTIC_INVALID_ARGUMENT;
929         }
930
931         if (has_haptic_module == MODULE_EMUL)
932                 return HAPTIC_SUCCESS;
933
934         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
935                 ERR("%s() is not supported without specific haptic module", __func__);
936                 return HAPTIC_NOT_SUPPORTED;
937         }
938
939         if (device_handle_count == 0) {
940                 ERR("Haptic device is not opened yet");
941                 return HAPTIC_NOT_OPENED;
942         }
943
944         return plugin_intf->haptic_internal_get_device_capability_string(index, device_cap_type, size, device_cap_value);
945 }
946
947 EXTAPI
948 int device_haptic_get_device_property_bool(int device_handle, int device_prop_type, unsigned char *device_prop_value)
949 {
950         if (device_prop_value == NULL) {
951                 ERR("Invalid parameter - device_prop_value(NULL)");
952                 return HAPTIC_INVALID_ARGUMENT;
953         }
954
955         if (device_prop_type < HAPTIC_DEVPROPTYPE_PRIORITY || device_prop_type > HAPTIC_DEVPROPTYPE_MASTERSTRENGTH) {
956                 ERR("Invalid parameter - device_prop_type(%d)", device_prop_type);
957                 return HAPTIC_INVALID_ARGUMENT;
958         }
959
960         if (has_haptic_module == MODULE_EMUL)
961                 return HAPTIC_SUCCESS;
962
963         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
964                 ERR("%s() is not supported without specific haptic module", __func__);
965                 return HAPTIC_NOT_SUPPORTED;
966         }
967
968         if (device_handle_count == 0) {
969                 ERR("Haptic device is not opened yet");
970                 return HAPTIC_NOT_OPENED;
971         }
972
973         return plugin_intf->haptic_internal_get_device_property_bool(device_handle, device_prop_type, device_prop_value);
974 }
975
976 EXTAPI
977 int device_haptic_set_device_property_bool(int device_handle, int device_prop_type, unsigned char device_prop_value)
978 {
979         if (device_prop_type < HAPTIC_DEVPROPTYPE_PRIORITY || device_prop_type > HAPTIC_DEVPROPTYPE_MASTERSTRENGTH) {
980                 ERR("Invalid parameter - device_prop_type(%d)", device_prop_type);
981                 return HAPTIC_INVALID_ARGUMENT;
982         }
983
984         if (has_haptic_module == MODULE_EMUL)
985                 return HAPTIC_SUCCESS;
986
987         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
988                 ERR("%s() is not supported without specific haptic module", __func__);
989                 return HAPTIC_NOT_SUPPORTED;
990         }
991
992         if (device_handle_count == 0) {
993                 ERR("Haptic device is not opened yet");
994                 return HAPTIC_NOT_OPENED;
995         }
996
997         return plugin_intf->haptic_internal_set_device_property_bool(device_handle, device_prop_type, device_prop_value);
998 }
999
1000 EXTAPI
1001 int device_haptic_get_device_property_int32(int device_handle, int device_prop_type, int *device_prop_value)
1002 {
1003         if (device_prop_value == NULL) {
1004                 ERR("Invalid parameter - device_prop_value(NULL)");
1005                 return HAPTIC_INVALID_ARGUMENT;
1006         }
1007
1008         if (device_prop_type < HAPTIC_DEVPROPTYPE_PRIORITY || device_prop_type > HAPTIC_DEVPROPTYPE_MASTERSTRENGTH) {
1009                 ERR("Invalid parameter - device_prop_type(%d)", device_prop_type);
1010                 return HAPTIC_INVALID_ARGUMENT;
1011         }
1012
1013         if (has_haptic_module == MODULE_EMUL)
1014                 return HAPTIC_SUCCESS;
1015
1016         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1017                 ERR("%s() is not supported without specific haptic module", __func__);
1018                 return HAPTIC_NOT_SUPPORTED;
1019         }
1020
1021         if (device_handle_count == 0) {
1022                 ERR("Haptic device is not opened yet");
1023                 return HAPTIC_NOT_OPENED;
1024         }
1025
1026         return plugin_intf->haptic_internal_get_device_property_int32(device_handle, device_prop_type, device_prop_value);
1027 }
1028
1029 EXTAPI
1030 int device_haptic_set_device_property_int32(int device_handle, int device_prop_type, int device_prop_value)
1031 {
1032         if (device_prop_type < HAPTIC_DEVPROPTYPE_PRIORITY || device_prop_type > HAPTIC_DEVPROPTYPE_MASTERSTRENGTH) {
1033                 ERR("Invalid parameter - device_prop_type(%d)", device_prop_type);
1034                 return HAPTIC_INVALID_ARGUMENT;
1035         }
1036
1037         if (has_haptic_module == MODULE_EMUL)
1038                 return HAPTIC_SUCCESS;
1039
1040         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1041                 ERR("%s() is not supported without specific haptic module", __func__);
1042                 return HAPTIC_NOT_SUPPORTED;
1043         }
1044
1045         if (device_handle_count == 0) {
1046                 ERR("Haptic device is not opened yet");
1047                 return HAPTIC_NOT_OPENED;
1048         }
1049
1050         return plugin_intf->haptic_internal_set_device_property_int32(device_handle, device_prop_type, device_prop_value);
1051 }
1052
1053 EXTAPI
1054 int device_haptic_get_device_property_string(int device_handle, int device_prop_type, int size, char *device_prop_value)
1055 {
1056         if (size <= 0 || device_prop_value == NULL) {
1057                 ERR("Invalid parameter - size(%d) or device_prop_value(NULL)", size);
1058                 return HAPTIC_INVALID_ARGUMENT;
1059         }
1060
1061         if (device_prop_type < HAPTIC_DEVPROPTYPE_PRIORITY || device_prop_type > HAPTIC_DEVPROPTYPE_MASTERSTRENGTH) {
1062                 ERR("Invalid parameter - device_prop_type(%d)", device_prop_type);
1063                 return HAPTIC_INVALID_ARGUMENT;
1064         }
1065
1066         if (has_haptic_module == MODULE_EMUL)
1067                 return HAPTIC_SUCCESS;
1068
1069         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1070                 ERR("%s() is not supported without specific haptic module", __func__);
1071                 return HAPTIC_NOT_SUPPORTED;
1072         }
1073
1074         if (device_handle_count == 0) {
1075                 ERR("Haptic device is not opened yet");
1076                 return HAPTIC_NOT_OPENED;
1077         }
1078
1079         return plugin_intf->haptic_internal_get_device_property_string(device_handle, device_prop_type, size, device_prop_value);
1080 }
1081
1082 EXTAPI
1083 int device_haptic_set_device_property_string(int device_handle, int device_prop_type, const char *device_prop_value)
1084 {
1085         if (device_prop_value == NULL) {
1086                 ERR("Invalid parameter - device_prop_value(NULL)");
1087                 return HAPTIC_INVALID_ARGUMENT;
1088         }
1089
1090         if (device_prop_type < HAPTIC_DEVPROPTYPE_PRIORITY || device_prop_type > HAPTIC_DEVPROPTYPE_MASTERSTRENGTH) {
1091                 ERR("Invalid parameter - device_prop_type(%d)", device_prop_type);
1092                 return HAPTIC_INVALID_ARGUMENT;
1093         }
1094
1095         if (has_haptic_module == MODULE_EMUL)
1096                 return HAPTIC_SUCCESS;
1097
1098         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1099                 ERR("%s() is not supported without specific haptic module", __func__);
1100                 return HAPTIC_NOT_SUPPORTED;
1101         }
1102
1103         if (device_handle_count == 0) {
1104                 ERR("Haptic device is not opened yet");
1105                 return HAPTIC_NOT_OPENED;
1106         }
1107
1108         return plugin_intf->haptic_internal_set_device_property_string(device_handle, device_prop_type, device_prop_value);
1109 }
1110
1111 EXTAPI
1112 int device_haptic_get_effect_count(const unsigned char *haptic_buffer)
1113 {
1114         if (haptic_buffer == NULL) {
1115                 ERR("Invalid parameter - haptic_buffer(NULL)");
1116                 return HAPTIC_INVALID_ARGUMENT;
1117         }
1118
1119         if (has_haptic_module == MODULE_EMUL)
1120                 return HAPTIC_SUCCESS;
1121
1122         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1123                 ERR("%s() is not supported without specific haptic module", __func__);
1124                 return HAPTIC_NOT_SUPPORTED;
1125         }
1126
1127         if (device_handle_count == 0) {
1128                 ERR("Haptic device is not opened yet");
1129                 return HAPTIC_NOT_OPENED;
1130         }
1131
1132         return plugin_intf->haptic_internal_get_IVT_effect_count(haptic_buffer);
1133 }
1134
1135 EXTAPI
1136 int device_haptic_get_effect_name(const unsigned char *haptic_buffer, int effect_index, int size, char *effect_name)
1137 {
1138         if (haptic_buffer == NULL || effect_index < 0 || size <= 0 || effect_name == NULL) {
1139                 ERR("Invalid parameter - haptic_buffer(NULL) or effect_index(%d) or size(%d) or effect_name(NULL)", effect_index, size);
1140                 return HAPTIC_INVALID_ARGUMENT;
1141         }
1142
1143         if (has_haptic_module == MODULE_EMUL)
1144                 return HAPTIC_SUCCESS;
1145
1146         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1147                 ERR("%s() is not supported without specific haptic module", __func__);
1148                 return HAPTIC_NOT_SUPPORTED;
1149         }
1150
1151         if (device_handle_count == 0) {
1152                 ERR("Haptic device is not opened yet");
1153                 return HAPTIC_NOT_OPENED;
1154         }
1155
1156         return plugin_intf->haptic_internal_get_IVT_effect_name(haptic_buffer, effect_index, size, effect_name);
1157 }
1158
1159 EXTAPI
1160 int device_haptic_get_effect_name_u(const unsigned char *haptic_buffer, int effect_index, int size, unsigned short *effect_name)
1161 {
1162         if (haptic_buffer == NULL || effect_index < 0 || size <= 0 || effect_name == NULL) {
1163                 ERR("Invalid parameter - haptic_buffer(NULL) or effect_index(%d) or size(%d) or effect_name(NULL)", effect_index, size);
1164                 return HAPTIC_INVALID_ARGUMENT;
1165         }
1166
1167         if (has_haptic_module == MODULE_EMUL)
1168                 return HAPTIC_SUCCESS;
1169
1170         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1171                 ERR("%s() is not supported without specific haptic module", __func__);
1172                 return HAPTIC_NOT_SUPPORTED;
1173         }
1174
1175         if (device_handle_count == 0) {
1176                 ERR("Haptic device is not opened yet");
1177                 return HAPTIC_NOT_OPENED;
1178         }
1179
1180         return plugin_intf->haptic_internal_get_IVT_effect_name_u(haptic_buffer, effect_index, size, effect_name);
1181 }
1182
1183 EXTAPI
1184 int device_haptic_get_effect_index_from_name(const unsigned char *haptic_buffer, char const *effect_name, int *effect_index)
1185 {
1186         if (haptic_buffer == NULL || effect_name == NULL || effect_index == NULL) {
1187                 ERR("Invalid parameter - haptic_buffer(NULL) or effect_name(NULL) or effect_index(NULL)");
1188                 return HAPTIC_INVALID_ARGUMENT;
1189         }
1190
1191         if (has_haptic_module == MODULE_EMUL)
1192                 return HAPTIC_SUCCESS;
1193
1194         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1195                 ERR("%s() is not supported without specific haptic module", __func__);
1196                 return HAPTIC_NOT_SUPPORTED;
1197         }
1198
1199         if (device_handle_count == 0) {
1200                 ERR("Haptic device is not opened yet");
1201                 return HAPTIC_NOT_OPENED;
1202         }
1203
1204         return plugin_intf->haptic_internal_get_IVT_effect_index_from_name(haptic_buffer, effect_name, effect_index);
1205 }
1206
1207 EXTAPI
1208 int device_haptic_get_effect_index_from_name_u(const unsigned char *haptic_buffer, const unsigned short *effect_name, int *effect_index)
1209 {
1210         if (haptic_buffer == NULL || effect_name == NULL || effect_index == NULL) {
1211                 ERR("Invalid parameter - haptic_buffer(NULL) or effect_name(NULL) or effect_index(NULL)");
1212                 return HAPTIC_INVALID_ARGUMENT;
1213         }
1214
1215         if (has_haptic_module == MODULE_EMUL)
1216                 return HAPTIC_SUCCESS;
1217
1218         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1219                 ERR("%s() is not supported without specific haptic module", __func__);
1220                 return HAPTIC_NOT_SUPPORTED;
1221         }
1222
1223         if (device_handle_count == 0) {
1224                 ERR("Haptic device is not opened yet");
1225                 return HAPTIC_NOT_OPENED;
1226         }
1227
1228         return plugin_intf->haptic_internal_get_IVT_effect_index_from_name_u(haptic_buffer, effect_name, effect_index);
1229 }
1230
1231 EXTAPI
1232 int device_haptic_play_effect(int device_handle, const unsigned char *haptic_buffer, int effect_index, int *effect_handle)
1233 {
1234         if (haptic_buffer == NULL || effect_index < 0 || effect_handle == NULL) {
1235                 ERR("Invalid parameter - haptic_buffer(NULL) or effect_index(%d) or effect_handle(NULL)", effect_index);
1236                 return HAPTIC_INVALID_ARGUMENT;
1237         }
1238
1239         if (has_haptic_module == MODULE_EMUL)
1240                 return HAPTIC_SUCCESS;
1241
1242         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1243                 ERR("%s() is not supported without specific haptic module", __func__);
1244                 return HAPTIC_NOT_SUPPORTED;
1245         }
1246
1247         if (device_handle_count == 0) {
1248                 ERR("Haptic device is not opened yet");
1249                 return HAPTIC_NOT_OPENED;
1250         }
1251
1252         return plugin_intf->haptic_internal_play_IVT_effect(device_handle, haptic_buffer, effect_index, effect_handle);
1253 }
1254
1255 EXTAPI
1256 int device_haptic_play_effect_repeat(int device_handle, const unsigned char *haptic_buffer, int effect_index, unsigned char repeat, int *effect_handle)
1257 {
1258         if (haptic_buffer == NULL || effect_index < 0 || effect_handle == NULL) {
1259                 ERR("Invalid parameter - haptic_buffer(NULL) or effect_index(%d) or effect_handle(NULL)", effect_index);
1260                 return HAPTIC_INVALID_ARGUMENT;
1261         }
1262
1263         if (has_haptic_module == MODULE_EMUL)
1264                 return HAPTIC_SUCCESS;
1265
1266         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1267                 ERR("%s() is not supported without specific haptic module", __func__);
1268                 return HAPTIC_NOT_SUPPORTED;
1269         }
1270
1271         if (device_handle_count == 0) {
1272                 ERR("Haptic device is not opened yet");
1273                 return HAPTIC_NOT_OPENED;
1274         }
1275
1276         return plugin_intf->haptic_internal_play_IVT_effect_repeat(device_handle, haptic_buffer, effect_index, repeat, effect_handle);
1277 }
1278
1279 EXTAPI
1280 int device_haptic_stop_playing_effect(int device_handle, int effect_handle)
1281 {
1282         if (has_haptic_module == MODULE_EMUL)
1283                 return HAPTIC_SUCCESS;
1284
1285         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1286                 ERR("%s() is not supported without specific haptic module", __func__);
1287                 return HAPTIC_NOT_SUPPORTED;
1288         }
1289
1290         if (device_handle_count == 0) {
1291                 ERR("Haptic device is not opened yet");
1292                 return HAPTIC_NOT_OPENED;
1293         }
1294
1295         return plugin_intf->haptic_internal_stop_playing_effect(device_handle, effect_handle);
1296 }
1297
1298 EXTAPI
1299 int device_haptic_get_effect_type(const unsigned char *haptic_buffer, int effect_index, int *effect_type)
1300 {
1301         if (haptic_buffer == NULL || effect_index < 0 || effect_type == NULL) {
1302                 ERR("Invalid parameter - haptic_buffer(NULL) or effect_index(%d) or effect_type(NULL)", effect_index);
1303                 return HAPTIC_INVALID_ARGUMENT;
1304         }
1305         if (has_haptic_module == MODULE_EMUL)
1306                 return HAPTIC_SUCCESS;
1307
1308         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1309                 ERR("%s() is not supported without specific haptic module", __func__);
1310                 return HAPTIC_NOT_SUPPORTED;
1311         }
1312
1313         if (device_handle_count == 0) {
1314                 ERR("Haptic device is not opened yet");
1315                 return HAPTIC_NOT_OPENED;
1316         }
1317
1318         return plugin_intf->haptic_internal_get_IVT_effect_type(haptic_buffer, effect_index, effect_type);
1319 }
1320
1321 EXTAPI
1322 int device_haptic_get_magsweep_effect_definition(const unsigned char *haptic_buffer, int effect_index,
1323         int *duration, int *magnitude, int *style, int *attacktime, int *attacklevel,
1324         int *fadetime, int *fadelevel)
1325 {
1326         if (haptic_buffer == NULL || effect_index < 0 || duration == NULL || magnitude == NULL || style == NULL
1327                 || attacktime == NULL || attacklevel == NULL || fadetime == NULL || fadelevel == NULL) {
1328                 ERR("Invalid parameter");
1329                 return HAPTIC_INVALID_ARGUMENT;
1330         }
1331
1332         if (has_haptic_module == MODULE_EMUL)
1333                 return HAPTIC_SUCCESS;
1334
1335         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1336                 ERR("%s() is not supported without specific haptic module", __func__);
1337                 return HAPTIC_NOT_SUPPORTED;
1338         }
1339
1340         if (device_handle_count == 0) {
1341                 ERR("Haptic device is not opened yet");
1342                 return HAPTIC_NOT_OPENED;
1343         }
1344
1345         return plugin_intf->haptic_internal_get_IVT_magsweep_effect_definition(haptic_buffer, effect_index, duration, magnitude, style, attacktime, attacklevel, fadetime, fadelevel);
1346 }
1347
1348 EXTAPI
1349 int device_haptic_get_periodic_effect_definition(const unsigned char *haptic_buffer, int effect_index,
1350         int *duration, int *magnitude, int *period, int *style_and_wave_type, int *attacktime, int *attacklevel,
1351         int *fadetime, int *fadelevel)
1352 {
1353         if (haptic_buffer == NULL || effect_index < 0 || duration == NULL || magnitude == NULL
1354                 || period == NULL || style_and_wave_type == NULL || attacktime == NULL || attacklevel == NULL
1355                 || fadetime == NULL || fadelevel == NULL) {
1356                 ERR("Invalid parameter");
1357                 return HAPTIC_INVALID_ARGUMENT;
1358         }
1359
1360         if (has_haptic_module == MODULE_EMUL)
1361                 return HAPTIC_SUCCESS;
1362
1363         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1364                 ERR("%s() is not supported without specific haptic module", __func__);
1365                 return HAPTIC_NOT_SUPPORTED;
1366         }
1367
1368         if (device_handle_count == 0) {
1369                 ERR("Haptic device is not opened yet");
1370                 return HAPTIC_NOT_OPENED;
1371         }
1372
1373         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);
1374 }
1375
1376 EXTAPI
1377 int device_haptic_get_effect_duration(const unsigned char *haptic_buffer, int effect_index, int *effect_duration)
1378 {
1379         if (haptic_buffer == NULL || effect_index < 0 || effect_duration == NULL) {
1380                 ERR("Invalid parameter - haptic_buffer(NULL) or effect_index(%d) or effect_duration(NULL)", effect_index);
1381                 return HAPTIC_INVALID_ARGUMENT;
1382         }
1383
1384         if (has_haptic_module == MODULE_EMUL)
1385                 return HAPTIC_SUCCESS;
1386
1387         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1388                 ERR("%s() is not supported without specific haptic module", __func__);
1389                 return HAPTIC_NOT_SUPPORTED;
1390         }
1391
1392         if (device_handle_count == 0) {
1393                 ERR("Haptic device is not opened yet");
1394                 return HAPTIC_NOT_OPENED;
1395         }
1396
1397         return plugin_intf->haptic_internal_get_IVT_effect_duration(haptic_buffer, effect_index, effect_duration);
1398 }
1399
1400 EXTAPI
1401 int device_haptic_play_magsweep_effect(int device_handle,
1402         int duration, int magnitude, int style, int attacktime, int attacklevel,
1403         int fadetime, int fadelevel, int *effect_handle)
1404 {
1405         if (duration < 0 || magnitude < 0 || style < 0 || attacktime < 0 || attacklevel < 0
1406                 || fadetime < 0 || fadelevel < 0 || effect_handle == NULL) {
1407                 ERR("Invalid parameter - duration(%d) or magnitude(%d) or style(%d) or attacktime(%d) or attacklevel(%d) or fadetime(%d) or fadelevel(%d) or effect_handle(NULL)", duration, magnitude, style, attacktime, attacklevel, fadetime, fadelevel);
1408                 return HAPTIC_INVALID_ARGUMENT;
1409         }
1410
1411         if (has_haptic_module == MODULE_EMUL)
1412                 return HAPTIC_SUCCESS;
1413
1414         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1415                 ERR("%s() is not supported without specific haptic module", __func__);
1416                 return HAPTIC_NOT_SUPPORTED;
1417         }
1418
1419         if (device_handle_count == 0) {
1420                 ERR("Haptic device is not opened yet");
1421                 return HAPTIC_NOT_OPENED;
1422         }
1423
1424         return plugin_intf->haptic_internal_play_magsweep_effect(device_handle, duration, magnitude, style, attacktime, attacklevel, fadetime, fadelevel, effect_handle);
1425 }
1426
1427 EXTAPI
1428 int device_haptic_play_periodic_effect(int device_handle,
1429         int duration, int magnitude, int period, int style_and_wave_type, int attacktime, int attacklevel,
1430         int fadetime, int fadelevel, int *effect_handle)
1431 {
1432         if (duration < 0 || magnitude < 0 || period < 0 || style_and_wave_type < 0 || attacktime < 0
1433                 || attacklevel < 0 || fadetime < 0 || fadelevel < 0 || effect_handle == NULL) {
1434                 ERR("Invalid parameter - duration(%d) or magnitude(%d) or period(%d) or style_and_wave_type(%d) or attacktime(%d) or attacklevel(%d) or fadetime(%d) or fadelevel(%d) or effect_handle(NULL)", duration, magnitude, period, style_and_wave_type, attacktime, attacklevel, fadetime, fadelevel);
1435                 return HAPTIC_INVALID_ARGUMENT;
1436         }
1437
1438         if (has_haptic_module == MODULE_EMUL)
1439                 return HAPTIC_SUCCESS;
1440
1441         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1442                 ERR("%s() is not supported without specific haptic module", __func__);
1443                 return HAPTIC_NOT_SUPPORTED;
1444         }
1445
1446         if (device_handle_count == 0) {
1447                 ERR("Haptic device is not opened yet");
1448                 return HAPTIC_NOT_OPENED;
1449         }
1450
1451         return plugin_intf->haptic_internal_play_periodic_effect(device_handle, duration, magnitude, period, style_and_wave_type, attacktime, attacklevel, fadetime, fadelevel, effect_handle);
1452 }
1453
1454 EXTAPI
1455 int device_haptic_modify_playing_magsweep_effect(int device_handle, int effect_handle,
1456         int duration, int magnitude, int style, int attacktime, int attacklevel, int fadetime, int fadelevel)
1457 {
1458         if (effect_handle < 0 || duration < 0 || magnitude < 0 || style < 0
1459                 || attacktime < 0 || attacklevel < 0 || fadetime < 0 || fadelevel < 0) {
1460                 ERR("Invalid parameter - effect_handle(%d) or duration(%d) or magnitude(%d) or style(%d) or attacktime(%d) or attacklevel(%d) or fadetime(%d) or fadelevel(%d)", effect_handle, duration, magnitude, style, attacktime, attacklevel, fadetime, fadelevel);
1461                 return HAPTIC_INVALID_ARGUMENT;
1462         }
1463
1464         if (has_haptic_module == MODULE_EMUL)
1465                 return HAPTIC_SUCCESS;
1466
1467         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1468                 ERR("%s() is not supported without specific haptic module", __func__);
1469                 return HAPTIC_NOT_SUPPORTED;
1470         }
1471
1472         if (device_handle_count == 0) {
1473                 ERR("Haptic device is not opened yet");
1474                 return HAPTIC_NOT_OPENED;
1475         }
1476
1477         return plugin_intf->haptic_internal_modify_playing_magsweep_effect(device_handle, effect_handle, duration, magnitude, style, attacktime, attacklevel, fadetime, fadelevel);
1478 }
1479
1480 EXTAPI
1481 int device_haptic_modify_playing_periodic_effect(int device_handle, int effect_handle,
1482         int duration, int magnitude, int period, int style_and_wave_type, int attacktime, int attacklevel, int fadetime, int fadelevel)
1483 {
1484         if (effect_handle < 0 || duration < 0 || magnitude < 0 || period < 0 || style_and_wave_type < 0
1485                 || attacktime < 0 || attacklevel < 0 || fadetime < 0 || fadelevel < 0) {
1486                 ERR("Invalid parameter - effect_handle(%d) or duration(%d) or magnitude(%d) or period(%d) or style_and_wave_type(%d) or attacktime(%d) or attacklevel(%d) or fadetime(%d) or fadelevel(%d)", effect_handle, duration, magnitude, period, style_and_wave_type, attacktime, attacklevel, fadetime, fadelevel);
1487                 return HAPTIC_INVALID_ARGUMENT;
1488         }
1489
1490         if (has_haptic_module == MODULE_EMUL)
1491                 return HAPTIC_SUCCESS;
1492
1493         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1494                 ERR("%s() is not supported without specific haptic module", __func__);
1495                 return HAPTIC_NOT_SUPPORTED;
1496         }
1497
1498         if (device_handle_count == 0) {
1499                 ERR("Haptic device is not opened yet");
1500                 return HAPTIC_NOT_OPENED;
1501         }
1502
1503         return plugin_intf->haptic_internal_modify_playing_periodic_effect(device_handle, effect_handle, duration, magnitude, period, style_and_wave_type, attacktime, attacklevel, fadetime, fadelevel);
1504 }
1505
1506 EXTAPI
1507 int device_haptic_create_streaming_effect(int device_handle, int *effect_handle)
1508 {
1509         if (effect_handle == NULL) {
1510                 ERR("Invalid parameter - effect_handle(NULL)");
1511                 return HAPTIC_INVALID_ARGUMENT;
1512         }
1513
1514         if (has_haptic_module == MODULE_EMUL)
1515                 return HAPTIC_SUCCESS;
1516
1517         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1518                 ERR("%s() is not supported without specific haptic module", __func__);
1519         }
1520
1521         if (device_handle_count == 0) {
1522                 ERR("Haptic device is not opened yet");
1523                 return HAPTIC_NOT_OPENED;
1524         }
1525
1526         return plugin_intf->haptic_internal_create_streaming_effect(device_handle, effect_handle);
1527 }
1528
1529 EXTAPI
1530 int device_haptic_destroy_streaming_effect(int device_handle, int effect_handle)
1531 {
1532         if (effect_handle < 0) {
1533                 ERR("Invalid parameter - effect_handle(%d)", effect_handle);
1534                 return HAPTIC_INVALID_ARGUMENT;
1535         }
1536
1537         if (has_haptic_module == MODULE_EMUL)
1538                 return HAPTIC_SUCCESS;
1539
1540         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1541                 ERR("%s() is not supported without specific haptic module", __func__);
1542                 return HAPTIC_NOT_SUPPORTED;
1543         }
1544
1545         if (device_handle_count == 0) {
1546                 ERR("Haptic device is not opened yet");
1547                 return HAPTIC_NOT_OPENED;
1548         }
1549
1550         return plugin_intf->haptic_internal_destroy_streaming_effect(device_handle, effect_handle);
1551 }
1552
1553 EXTAPI
1554 int device_haptic_play_streaming_sample(int device_handle, int effect_handle, const unsigned char *streaming_sample, int size)
1555 {
1556         if (effect_handle < 0 || streaming_sample == NULL) {
1557                 ERR("Invalid parameter - effect_handle(%d) or streaming_sample(NULL)", effect_handle);
1558                 return HAPTIC_INVALID_ARGUMENT;
1559         }
1560
1561         if (has_haptic_module == MODULE_EMUL)
1562                 return HAPTIC_SUCCESS;
1563
1564         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1565                 ERR("%s() is not supported without specific haptic module", __func__);
1566                 return HAPTIC_NOT_SUPPORTED;
1567         }
1568
1569         if (device_handle_count == 0) {
1570                 ERR("Haptic device is not opened yet");
1571                 return HAPTIC_NOT_OPENED;
1572         }
1573
1574         return plugin_intf->haptic_internal_play_streaming_sample(device_handle, effect_handle, streaming_sample, size);
1575 }
1576
1577 EXTAPI
1578 int device_haptic_play_streaming_sample_with_offset(int device_handle, int effect_handle, const unsigned char *streaming_sample, int size, int offset_time)
1579 {
1580         if (effect_handle < 0 || streaming_sample == NULL || size <= 0 || offset_time < 0) {
1581                 ERR("Invalid parameter - effect_handle(%d) or streaming_sample(NULL) or size(%d) or offset_time(%d)", effect_handle, size, offset_time);
1582                 return HAPTIC_INVALID_ARGUMENT;
1583         }
1584
1585         if (has_haptic_module == MODULE_EMUL)
1586                 return HAPTIC_SUCCESS;
1587
1588         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1589                 ERR("%s() is not supported without specific haptic module", __func__);
1590                 return HAPTIC_NOT_SUPPORTED;
1591         }
1592
1593         if (device_handle_count == 0) {
1594                 ERR("Haptic device is not opened yet");
1595                 return HAPTIC_NOT_OPENED;
1596         }
1597
1598         return plugin_intf->haptic_internal_play_streaming_sample_with_offset(device_handle, effect_handle, streaming_sample, size, offset_time);
1599 }
1600
1601 EXTAPI
1602 int device_haptic_stop_all_playing_effects(int device_handle)
1603 {
1604         if (has_haptic_module == MODULE_EMUL)
1605                 return HAPTIC_SUCCESS;
1606
1607         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1608                 ERR("%s() is not supported without specific haptic module", __func__);
1609                 return HAPTIC_NOT_SUPPORTED;
1610         }
1611
1612         if (device_handle_count == 0) {
1613                 ERR("Haptic device is not opened yet");
1614                 return HAPTIC_NOT_OPENED;
1615         }
1616
1617         return plugin_intf->haptic_internal_stop_all_playing_effects(device_handle);
1618 }
1619
1620 EXTAPI
1621 int device_haptic_save_file(const unsigned char *ivt_buffer, int max_bufsize, const char *path_name)
1622 {
1623         if (ivt_buffer == NULL || max_bufsize <= 0 || path_name == NULL) {
1624                 ERR("Invalid parameter - ivt_buffer(NULL) or max_bufsize(%d) or path_name(NULL)", max_bufsize);
1625                 return HAPTIC_INVALID_ARGUMENT;
1626         }
1627
1628         if (has_haptic_module == MODULE_EMUL)
1629                 return HAPTIC_SUCCESS;
1630
1631         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1632                 ERR("%s() is not supported without specific haptic module", __func__);
1633                 return HAPTIC_NOT_SUPPORTED;
1634         }
1635
1636         if (device_handle_count == 0) {
1637                 ERR("Haptic device is not opened yet");
1638                 return HAPTIC_NOT_OPENED;
1639         }
1640
1641         return plugin_intf->haptic_internal_save_IVT_file(ivt_buffer, max_bufsize, path_name);
1642 }
1643
1644 EXTAPI
1645 int device_haptic_delete_file(const char *path_name)
1646 {
1647         if (path_name == NULL) {
1648                 ERR("Invalid parameter - path_name(NULL)", path_name);
1649                 return HAPTIC_INVALID_ARGUMENT;
1650         }
1651
1652         if (has_haptic_module == MODULE_EMUL)
1653                 return HAPTIC_SUCCESS;
1654
1655         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1656                 ERR("%s() is not supported without specific haptic module", __func__);
1657                 return HAPTIC_NOT_SUPPORTED;
1658         }
1659
1660         if (device_handle_count == 0) {
1661                 ERR("Haptic device is not opened yet");
1662                 return HAPTIC_NOT_OPENED;
1663         }
1664
1665         return plugin_intf->haptic_internal_delete_IVT_file(path_name);
1666 }
1667
1668 EXTAPI
1669 int device_haptic_pause_playing_effect(int device_handle, int effect_handle)
1670 {
1671         if (effect_handle < 0) {
1672                 ERR("Invalid parameter - effect_handle(%d)", effect_handle);
1673                 return HAPTIC_INVALID_ARGUMENT;
1674         }
1675
1676         if (has_haptic_module == MODULE_EMUL)
1677                 return HAPTIC_SUCCESS;
1678
1679         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1680                 ERR("%s() is not supported without specific haptic module", __func__);
1681                 return HAPTIC_NOT_SUPPORTED;
1682         }
1683
1684         if (device_handle_count == 0) {
1685                 ERR("Haptic device is not opened yet");
1686                 return HAPTIC_NOT_OPENED;
1687         }
1688
1689         return plugin_intf->haptic_internal_pause_playing_effect(device_handle, effect_handle);
1690 }
1691
1692 EXTAPI
1693 int device_haptic_resume_paused_effect(int device_handle, int effect_handle)
1694 {
1695         if (effect_handle < 0) {
1696                 ERR("Invalid parameter - effect_handle(%d)", effect_handle);
1697                 return HAPTIC_INVALID_ARGUMENT;
1698         }
1699
1700         if (has_haptic_module == MODULE_EMUL)
1701                 return HAPTIC_SUCCESS;
1702
1703         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1704                 ERR("%s() is not supported without specific haptic module", __func__);
1705                 return HAPTIC_NOT_SUPPORTED;
1706         }
1707
1708         if (device_handle_count == 0) {
1709                 ERR("Haptic device is not opened yet");
1710                 return HAPTIC_NOT_OPENED;
1711         }
1712
1713         return plugin_intf->haptic_internal_resume_paused_effect(device_handle, effect_handle);
1714 }
1715
1716 EXTAPI
1717 int device_haptic_get_effect_state(int device_handle, int effect_handle, int *effect_state)
1718 {
1719         if (effect_handle < 0 || effect_state == NULL) {
1720                 ERR("Invalid parameter - effect_handle(%d) or effect_state(NULL)", effect_handle);
1721                 return HAPTIC_INVALID_ARGUMENT;
1722         }
1723
1724         if (has_haptic_module == MODULE_EMUL)
1725                 return HAPTIC_SUCCESS;
1726
1727         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1728                 ERR("%s() is not supported without specific haptic module", __func__);
1729                 return HAPTIC_NOT_SUPPORTED;
1730         }
1731
1732         if (device_handle_count == 0) {
1733                 ERR("Haptic device is not opened yet");
1734                 return HAPTIC_NOT_OPENED;
1735         }
1736
1737         return plugin_intf->haptic_internal_get_effect_state(device_handle, effect_handle, effect_state);
1738 }
1739
1740 EXTAPI
1741 int device_haptic_get_size(const unsigned char *haptic_buffer, int size)
1742 {
1743         if (haptic_buffer == NULL || size <= 0) {
1744                 ERR("Invalid parameter - haptic_buffer(NULL) or size(%d)", size);
1745                 return HAPTIC_INVALID_ARGUMENT;
1746         }
1747
1748         if (has_haptic_module == MODULE_EMUL)
1749                 return HAPTIC_SUCCESS;
1750
1751         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1752                 ERR("%s() is not supported without specific haptic module", __func__);
1753                 return HAPTIC_NOT_SUPPORTED;
1754         }
1755
1756         if (device_handle_count == 0) {
1757                 ERR("Haptic device is not opened yet");
1758                 return HAPTIC_NOT_OPENED;
1759         }
1760
1761         return plugin_intf->haptic_internal_get_IVT_size(haptic_buffer, size);
1762 }
1763
1764 EXTAPI
1765 int device_haptic_initialize_buffer(unsigned char *haptic_buffer, int size)
1766 {
1767         if (haptic_buffer == NULL || size <= 0) {
1768                 ERR("Invalid parameter - haptic_buffer(NULL) or size(%d)", size);
1769                 return HAPTIC_INVALID_ARGUMENT;
1770         }
1771
1772         if (has_haptic_module == MODULE_EMUL)
1773                 return HAPTIC_SUCCESS;
1774
1775         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1776                 ERR("%s() is not supported without specific haptic module", __func__);
1777                 return HAPTIC_NOT_SUPPORTED;
1778         }
1779
1780         if (device_handle_count == 0) {
1781                 ERR("Haptic device is not opened yet");
1782                 return HAPTIC_NOT_OPENED;
1783         }
1784
1785         return plugin_intf->haptic_internal_initialize_IVT_buffer(haptic_buffer, size);
1786 }
1787
1788 EXTAPI
1789 int device_haptic_insert_element(unsigned char *haptic_buffer, int size, int timeline_index, const HapticElement *element)
1790 {
1791         if (haptic_buffer == NULL || size <= 0 || timeline_index < 0 || element == NULL) {
1792                 ERR("Invalid parameter - haptic_buffer(NULL) or size(%d) or timeline_index(%d) or element(NULL)", size, timeline_index);
1793                 return HAPTIC_INVALID_ARGUMENT;
1794         }
1795
1796         if (has_haptic_module == MODULE_EMUL)
1797                 return HAPTIC_SUCCESS;
1798
1799         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1800                 ERR("%s() is not supported without specific haptic module", __func__);
1801                 return HAPTIC_NOT_SUPPORTED;
1802         }
1803
1804         if (device_handle_count == 0) {
1805                 ERR("Haptic device is not opened yet");
1806                 return HAPTIC_NOT_OPENED;
1807         }
1808
1809         return plugin_intf->haptic_internal_insert_IVT_element(haptic_buffer, size, timeline_index, element);
1810 }
1811
1812 EXTAPI
1813 int device_haptic_insert_element2(unsigned char *haptic_buffer, int size, int timeline_index, const HapticElement2 *element)
1814 {
1815         if (haptic_buffer == NULL || size <= 0 || timeline_index < 0 || element == NULL) {
1816                 ERR("Invalid parameter - haptic_buffer(NULL) or size(%d) or timeline_index(%d) or element(NULL)", size, timeline_index);
1817                 return HAPTIC_INVALID_ARGUMENT;
1818         }
1819
1820         if (has_haptic_module == MODULE_EMUL)
1821                 return HAPTIC_SUCCESS;
1822
1823         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1824                 ERR("%s() is not supported without specific haptic module", __func__);
1825                 return HAPTIC_NOT_SUPPORTED;
1826         }
1827
1828         if (device_handle_count == 0) {
1829                 ERR("Haptic device is not opened yet");
1830                 return HAPTIC_NOT_OPENED;
1831         }
1832
1833         return plugin_intf->haptic_internal_insert_IVT_element2(haptic_buffer, size, timeline_index, element);
1834 }
1835
1836 EXTAPI
1837 int device_haptic_insert_element3(unsigned char *haptic_buffer, int size, int timeline_index, const HapticElement3 *element)
1838 {
1839         if (haptic_buffer == NULL || size <= 0 || timeline_index < 0 || element == NULL) {
1840                 ERR("Invalid parameter - haptic_buffer(NULL) or size(%d) or timeline_index(%d) or element(NULL)", size, timeline_index);
1841                 return HAPTIC_INVALID_ARGUMENT;
1842         }
1843
1844         if (has_haptic_module == MODULE_EMUL)
1845                 return HAPTIC_SUCCESS;
1846
1847         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1848                 ERR("%s() is not supported without specific haptic module", __func__);
1849                 return HAPTIC_NOT_SUPPORTED;
1850         }
1851
1852         if (device_handle_count == 0) {
1853                 ERR("Haptic device is not opened yet");
1854                 return HAPTIC_NOT_OPENED;
1855         }
1856
1857         return plugin_intf->haptic_internal_insert_IVT_element3(haptic_buffer, size, timeline_index, element);
1858 }
1859
1860 EXTAPI
1861 int device_haptic_read_element(const unsigned char *haptic_buffer, int size, int timeline_index, int element_index, HapticElement *element)
1862 {
1863         if (haptic_buffer == NULL || size <= 0 || timeline_index < 0 || element_index < 0 || element == NULL) {
1864                 ERR("Invalid parameter - haptic_buffer(NULL) or size(%d) or timeline_index(%d) or element_index(%d) or element(NULL)", size, timeline_index, element_index);
1865                 return HAPTIC_INVALID_ARGUMENT;
1866         }
1867
1868         if (has_haptic_module == MODULE_EMUL)
1869                 return HAPTIC_SUCCESS;
1870
1871         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1872                 ERR("%s() is not supported without specific haptic module", __func__);
1873                 return HAPTIC_NOT_SUPPORTED;
1874         }
1875
1876         if (device_handle_count == 0) {
1877                 ERR("Haptic device is not opened yet");
1878                 return HAPTIC_NOT_OPENED;
1879         }
1880
1881         return plugin_intf->haptic_internal_read_IVT_element(haptic_buffer, size, timeline_index, element_index, element);
1882 }
1883
1884 EXTAPI
1885 int device_haptic_read_element2(const unsigned char *haptic_buffer, int size, int timeline_index, int element_index, HapticElement2 *element)
1886 {
1887         if (haptic_buffer == NULL || size <= 0 || timeline_index < 0 || element_index < 0 || element == NULL) {
1888                 ERR("Invalid parameter - haptic_buffer(NULL) or size(%d) or timeline_index(%d) or element_index(%d) or element(NULL)", size, timeline_index, element_index);
1889                 return HAPTIC_INVALID_ARGUMENT;
1890         }
1891
1892         if (has_haptic_module == MODULE_EMUL)
1893                 return HAPTIC_SUCCESS;
1894
1895         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1896                 ERR("%s() is not supported without specific haptic module", __func__);
1897                 return HAPTIC_NOT_SUPPORTED;
1898         }
1899
1900         if (device_handle_count == 0) {
1901                 ERR("Haptic device is not opened yet");
1902                 return HAPTIC_NOT_OPENED;
1903         }
1904
1905         return plugin_intf->haptic_internal_read_IVT_element2(haptic_buffer, size, timeline_index, element_index, element);
1906 }
1907
1908 EXTAPI
1909 int device_haptic_read_element3(const unsigned char *haptic_buffer, int size, int timeline_index, int element_index, HapticElement3 *element)
1910 {
1911         if (haptic_buffer == NULL || size <= 0 || timeline_index < 0 || element_index < 0 || element == NULL) {
1912                 ERR("Invalid parameter - haptic_buffer(NULL) or size(%d) or timeline_index(%d) or element_index(%d) or element(NULL)", size, timeline_index, element_index);
1913                 return HAPTIC_INVALID_ARGUMENT;
1914         }
1915
1916         if (has_haptic_module == MODULE_EMUL)
1917                 return HAPTIC_SUCCESS;
1918
1919         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1920                 ERR("%s() is not supported without specific haptic module", __func__);
1921                 return HAPTIC_NOT_SUPPORTED;
1922         }
1923
1924         if (device_handle_count == 0) {
1925                 ERR("Haptic device is not opened yet");
1926                 return HAPTIC_NOT_OPENED;
1927         }
1928
1929         return plugin_intf->haptic_internal_read_IVT_element3(haptic_buffer, size, timeline_index, element_index, element);
1930 }
1931
1932 EXTAPI
1933 int device_haptic_remove_element(unsigned char *haptic_buffer, int size, int timeline_index, int element_index)
1934 {
1935         if (haptic_buffer == NULL || size <= 0 || timeline_index < 0 || element_index < 0) {
1936                 ERR("Invalid parameter - haptic_buffer(NULL) or size(%d) or timeline_index(%d) or element_index(%d)", size, timeline_index, element_index);
1937                 return HAPTIC_INVALID_ARGUMENT;
1938         }
1939
1940         if (has_haptic_module == MODULE_EMUL)
1941                 return HAPTIC_SUCCESS;
1942
1943         if (has_haptic_module == MODULE_NONE || has_haptic_module == MODULE_BASIC) {
1944                 ERR("%s() is not supported without specific haptic module", __func__);
1945                 return HAPTIC_NOT_SUPPORTED;
1946         }
1947
1948         if (device_handle_count == 0) {
1949                 ERR("Haptic device is not opened yet");
1950                 return HAPTIC_NOT_OPENED;
1951         }
1952
1953         return plugin_intf->haptic_internal_remove_IVT_element(haptic_buffer, size, timeline_index, element_index);
1954 }
1955 /* END: devman_haptic_ext APIs */
1956
1957 static void __attribute__ ((constructor)) module_init()
1958 {
1959         char *error;
1960
1961         if (__is_emulator_binary()) {
1962                 has_haptic_module = MODULE_EMUL;
1963 /* START: Will be supported by kernel */
1964 #ifdef NEED_THE_SUPPORT_OF_KERNEL
1965         } else if (__is_supported_other()) {
1966                 if (access(HAPTIC_DEVICE_NODE_PATH, F_OK) < 0) {
1967                         has_haptic_module = MODULE_NONE;
1968                         return;
1969                 }
1970
1971                 dlopen_handle = dlopen(HAPTIC_MODULE_PATH, RTLD_NOW);
1972                 if (!dlopen_handle) {
1973                         ERR("dlopen failed: %s", dlerror());
1974                         has_haptic_module = MODULE_NONE;
1975                         return;
1976                 }
1977
1978                 const devman_haptic_plugin_interface *(*get_devman_haptic_plugin_interface) ();
1979                 get_devman_haptic_plugin_interface = dlsym(dlopen_handle, "get_devman_haptic_plugin_interface");
1980                 if ((error = dlerror()) != NULL) {
1981                         ERR("dlsym failed : %s", error);
1982                         has_haptic_module = MODULE_NONE;
1983                         dlclose(dlopen_handle);
1984                         return;
1985                 }
1986
1987                 plugin_intf = get_devman_haptic_plugin_interface();
1988                 if (!plugin_intf) {
1989                         ERR("get_devman_haptic_plugin_interface() failed");
1990                         has_haptic_module = MODULE_NONE;
1991                         dlclose(dlopen_handle);
1992                         return;
1993                 }
1994
1995                 has_haptic_module = MODULE_TSP;
1996 #endif
1997 /* END: Will be supported */
1998         } else {
1999                 has_haptic_module = MODULE_BASIC;
2000         }
2001 }
2002
2003 static void __attribute__ ((destructor)) module_fini()
2004 {
2005         if (has_haptic_module != MODULE_TSP)
2006                 return;
2007
2008         if (dlopen_handle) {
2009                 dlclose(dlopen_handle);
2010         }
2011 }
2012