Fix for 64 bit compatibility.
[platform/core/system/haptic-module-tizen.git] / test / test.c
1 /*
2         * haptic-module-tizen
3         *
4         * Copyright (c) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5         *
6         * Contact: Jae-young Hwang <j-zero.hwang@samsung.com>
7         *
8         * PROPRIETARY/CONFIDENTIAL
9         *
10         * This software is the confidential and proprietary information of
11         * SAMSUNG ELECTRONICS ("Confidential Information"). You agree and acknowledge
12         * that this software is owned by Samsung and you shall not disclose
13         * such Confidential Information and shall use it only in accordance with the
14         * terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
15         * SAMSUNG make no representations or warranties about the suitability
16         * of the software, either express or implied, including but not limited
17         * to the implied warranties of merchantability, fitness for a particular
18         * purpose,
19         * by licensee arising out of or releated to this software.
20 */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <string.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <fcntl.h>
29 #include <vconf.h>
30 #include <dlfcn.h>
31
32 #include <haptic_plugin_intf.h>
33
34 #define HAPTIC_MODULE_PATH          "/usr/lib/libhaptic-module.so"
35
36 static void *dlopen_handle;
37 static const haptic_plugin_interface *plugin_intf;
38
39 int main ()
40 {
41         char *error = NULL;
42
43         printf("start!\n");
44         dlopen_handle = dlopen(HAPTIC_MODULE_PATH, RTLD_NOW);
45         if (!dlopen_handle) {
46                 printf("fail dlopen\n");
47                 printf("%s\n", dlerror());
48                 return -1;
49         }
50
51         const haptic_plugin_interface *(*get_haptic_plugin_interface) ();
52         get_haptic_plugin_interface = dlsym(dlopen_handle, "get_haptic_plugin_interface");
53
54         if ((error = dlerror()) != NULL) {
55                 printf("dlsym error\n");
56                 printf("%s\n", error);
57                 dlclose(dlopen_handle);
58                 return -1;
59         }
60
61         plugin_intf = get_haptic_plugin_interface();
62         if (!plugin_intf) {
63                 printf("plugin_intf error\n");
64                 dlclose(dlopen_handle);
65                 return -1;
66         }
67
68         while (1)
69         {
70                 char input = -1;
71                 int duration = -1;
72                 int handle = -1;
73                 int status = -1;
74
75                 printf ("============================================\n");
76                 printf ("haptic_internal_vibrate_monotone : a\n");
77                 printf ("hatpic_internal_stop_all_effects : b\n");
78                 printf ("Quit : z\n");
79                 printf ("============================================\n");
80
81                 status = scanf ("%c", &input);
82
83                 switch (input)
84                 {
85                         case 'a' :
86                                 printf ("Handle : ");
87                                 status = scanf ("%d", &handle);
88                                 if (status < 0)
89                                         return status;
90
91                                 printf ("Duration : ");
92                                 status = scanf ("%d", &duration);
93                                 if (status < 0)
94                                         return status;
95
96                                 plugin_intf->haptic_internal_vibrate_monotone(handle, duration, HAPTIC_MODULE_FEEDBACK_MAX, HAPTIC_MODULE_PRIORITY_HIGH, &handle);
97                                 break;
98
99                         case 'b':
100                                 printf ("Handle : ");
101                                 status = scanf ("%d", &handle);
102                                 if (status < 0)
103                                         return status;
104                                 plugin_intf->haptic_internal_stop_all_effects(handle);
105                                 break;
106
107                         case 'c':
108                                 break;
109
110                         case 'z':
111                                 return 0;
112                 }
113         }
114
115         if (dlopen_handle) {
116                 dlclose(dlopen_handle);
117         }
118
119         return 0;
120 }