change the structure of haptic to use dbus 56/15156/1
authorjy910.yun <jy910.yun@samsung.com>
Wed, 29 May 2013 09:39:18 +0000 (18:39 +0900)
committerKrzysztof Sasiak <k.sasiak@samsung.com>
Thu, 16 Jan 2014 13:37:25 +0000 (14:37 +0100)
add new interface (.haptic)

Change-Id: Ib650fbadfd25d9b03368a5c05524dc1f03026325
Signed-off-by: jy910.yun <jy910.yun@samsung.com>
CMakeLists.txt
src/core/devices.c
src/core/devices.h
src/core/edbus-handler.c
src/core/edbus-handler.h
src/deviced/haptic-plugin-intf.h
src/haptic/haptic.c [new file with mode: 0644]
src/shared/dbus.c
src/shared/dbus.h
src/shared/haptic.c

index 989485b..233ff51 100755 (executable)
@@ -59,6 +59,9 @@ SET(SRCS ${SRCS}
 SET(SRCS ${SRCS}
        src/control/control.c)
 
+SET(SRCS ${SRCS}
+       src/haptic/haptic.c)
+
 # libdeviced
 SET(DEVICED_SRCS
        src/shared/battery.c
index 1893c83..47f11dc 100644 (file)
@@ -46,6 +46,7 @@ static const struct device_ops *devices[] = {
        &ta_device_ops,
        &pmon_device_ops,
        &mmc_device_ops,
+       &haptic_device_ops,
        &led_device_ops,
        &vibrator_device_ops,
        &notifier_device_ops,
index fca9f5b..72f428c 100644 (file)
@@ -84,6 +84,7 @@ extern const struct device_ops usb_device_ops;
 extern const struct device_ops ta_device_ops;
 extern const struct device_ops pmon_device_ops;
 extern const struct device_ops mmc_device_ops;
+extern const struct device_ops haptic_device_ops;
 extern const struct device_ops led_device_ops;
 extern const struct device_ops vibrator_device_ops;
 extern const struct device_ops notifier_device_ops;
index 87c70d2..aa8056c 100644 (file)
@@ -46,6 +46,7 @@ static struct edbus_object {
        { DEVICED_PATH_CORE   , DEVICED_INTERFACE_CORE   , NULL, NULL },
        { DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, NULL, NULL },
        { DEVICED_PATH_STORAGE, DEVICED_INTERFACE_STORAGE, NULL, NULL },
+       { DEVICED_PATH_HAPTIC , DEVICED_INTERFACE_HAPTIC , NULL, NULL },
        /* Add new object & interface here*/
 };
 
index b2f1d91..79bb523 100644 (file)
 #define DEVICED_PATH_STORAGE           OBJECT_PATH"/Storage"
 #define DEVICED_INTERFACE_STORAGE      INTERFACE_NAME".storage"
 
+/*
+ * Haptic service
+ *   operatioins about haptic
+ */
+#define DEVICED_PATH_HAPTIC            OBJECT_PATH"/Haptic"
+#define DEVICED_INTERFACE_HAPTIC       INTERFACE_NAME".haptic"
+
 int register_edbus_signal_handler(const char *path, const char *interface,
                const char *name, E_DBus_Signal_Cb cb);
 E_DBus_Interface *get_edbus_interface(const char *path);
index f914f1b..63b5a55 100644 (file)
@@ -27,16 +27,10 @@ struct haptic_ops {
        int (*open_device) (int, int*);
        int (*close_device) (int);
        int (*vibrate_monotone) (int, int, int, int, int*);
-       int (*vibrate_file) (int, const char*, int, int, int, int*);
        int (*vibrate_buffer) (int, const unsigned char*, int, int, int, int*);
-       int (*stop_effect) (int, int);
-       int (*stop_all_effects) (int);
-       int (*pause_effect) (int, int);
-       int (*resume_effect) (int, int);
-       int (*get_effect_state) (int, int, int*);
+       int (*stop_device) (int);
+       int (*get_device_state) (int, int*);
        int (*create_effect) (unsigned char*, int, haptic_module_effect_element*, int);
-       int (*save_effect) (const unsigned char*, int, const char*);
-       int (*get_file_duration) (int, const char*, int*);
        int (*get_buffer_duration) (int, const unsigned char*, int*);
        int (*convert_binary) (const unsigned char*, int, const char*);
 };
diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c
new file mode 100644 (file)
index 0000000..128f243
--- /dev/null
@@ -0,0 +1,508 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <dlfcn.h>
+
+#include "core/log.h"
+#include "core/common.h"
+#include "core/devices.h"
+#include "core/edbus-handler.h"
+#include "haptic-module.h"
+#include "haptic-plugin-intf.h"
+
+#define HAPTIC_MODULE_PATH                     "/usr/lib/libhaptic-module.so"
+
+/* Haptic Plugin Interface */
+static void *dlopen_handle;
+static const struct haptic_ops *plugin_intf;
+
+static DBusMessage *edbus_get_count(E_DBus_Object *obj, DBusMessage *msg)
+{
+       DBusMessageIter iter;
+       DBusMessage *reply;
+       int val, ret;
+
+       if (!plugin_intf || !plugin_intf->get_device_count) {
+               ret = -EFAULT;
+               goto exit;
+       }
+
+       ret = plugin_intf->get_device_count(&val);
+       if (ret < 0)
+               _E("fail to get device count : %d", ret);
+       else
+               ret = val;
+
+       _D("get haptic count %d", ret);
+
+exit:
+       reply = dbus_message_new_method_return(msg);
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+       return reply;
+}
+
+static DBusMessage *edbus_open_device(E_DBus_Object *obj, DBusMessage *msg)
+{
+       DBusMessageIter iter;
+       DBusMessage *reply;
+       DBusError err;
+       int index, handle, ret;
+
+       if (!plugin_intf || !plugin_intf->open_device) {
+               ret = -EFAULT;
+               goto exit;
+       }
+
+       dbus_error_init(&err);
+       if (!dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID)) {
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       ret = plugin_intf->open_device(index, &handle);
+       if (ret < 0)
+               _E("fail to open device : %d", ret);
+       else
+               ret = handle;
+
+       _D("haptic open %d", ret);
+
+exit:
+       reply = dbus_message_new_method_return(msg);
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+       return reply;
+}
+
+static DBusMessage *edbus_close_device(E_DBus_Object *obj, DBusMessage *msg)
+{
+       DBusMessageIter iter;
+       DBusMessage *reply;
+       DBusError err;
+       unsigned int handle;
+       int ret;
+
+       if (!plugin_intf || !plugin_intf->close_device) {
+               ret = -EFAULT;
+               goto exit;
+       }
+
+       dbus_error_init(&err);
+       if (!dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID)) {
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       ret = plugin_intf->close_device(handle);
+       if (ret < 0)
+               _E("fail to close device : %d", ret);
+
+       _D("haptic close %d", ret);
+
+exit:
+       reply = dbus_message_new_method_return(msg);
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+       return reply;
+}
+
+static DBusMessage *edbus_stop_device(E_DBus_Object *obj, DBusMessage *msg)
+{
+       DBusMessageIter iter;
+       DBusMessage *reply;
+       DBusError err;
+       unsigned int handle;
+       int ret;
+
+       if (!plugin_intf || !plugin_intf->stop_device) {
+               ret = -EFAULT;
+               goto exit;
+       }
+
+       dbus_error_init(&err);
+       if (!dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID)) {
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       ret = plugin_intf->stop_device(handle);
+       if (ret < 0)
+               _E("fail to stop device : %d", ret);
+
+       _D("haptic close %d", ret);
+
+exit:
+       reply = dbus_message_new_method_return(msg);
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+       return reply;
+}
+
+static DBusMessage *edbus_vibrate_monotone(E_DBus_Object *obj, DBusMessage *msg)
+{
+       DBusMessageIter iter;
+       DBusMessage *reply;
+       DBusError err;
+       unsigned int handle;
+       int duration, feedback, priority, e_handle, ret;
+
+       if (!plugin_intf || !plugin_intf->vibrate_monotone) {
+               ret = -EFAULT;
+               goto exit;
+       }
+
+       dbus_error_init(&err);
+       if (!dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &handle,
+                               DBUS_TYPE_INT32, &duration,
+                               DBUS_TYPE_INT32, &feedback,
+                               DBUS_TYPE_INT32, &priority, DBUS_TYPE_INVALID)) {
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       ret = plugin_intf->vibrate_monotone(handle, duration, feedback, priority, &e_handle);
+       if (ret < 0)
+               _E("fail to vibrate monotone : %d", ret);
+       else
+               ret = e_handle;
+
+       _D("haptic vibrate monotone %d(h:%d, d:%d, f:%d, p:%d)", ret, handle, duration, feedback, priority);
+
+exit:
+       reply = dbus_message_new_method_return(msg);
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+       return reply;
+
+}
+
+static DBusMessage *edbus_vibrate_buffer(E_DBus_Object *obj, DBusMessage *msg)
+{
+       DBusMessageIter iter;
+       DBusMessage *reply;
+       DBusError err;
+       unsigned int handle;
+       unsigned char *data;
+       int size, iteration, feedback, priority, e_handle, ret;
+
+       if (!plugin_intf || !plugin_intf->vibrate_buffer) {
+               ret = -EFAULT;
+               goto exit;
+       }
+
+       dbus_error_init(&err);
+       if (!dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &handle,
+                               DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &data, &size,
+                               DBUS_TYPE_INT32, &iteration,
+                               DBUS_TYPE_INT32, &feedback,
+                               DBUS_TYPE_INT32, &priority, DBUS_TYPE_INVALID)) {
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       ret = plugin_intf->vibrate_buffer(handle, data, iteration, feedback, priority, &e_handle);
+       if (ret < 0)
+               _E("fail to vibrate buffer : %d", ret);
+       else
+               ret = e_handle;
+
+       _D("haptic vibrate buffer %d(h:%d, s:%d, i:%d, f:%d, p:%d)",
+                       ret, handle, size, iteration, feedback, priority);
+
+exit:
+       reply = dbus_message_new_method_return(msg);
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+       return reply;
+}
+
+static DBusMessage *edbus_get_state(E_DBus_Object *obj, DBusMessage *msg)
+{
+       DBusMessageIter iter;
+       DBusMessage *reply;
+       DBusError err;
+       unsigned int handle;
+       int state, ret;
+
+       if (!plugin_intf || !plugin_intf->get_device_state) {
+               ret = -EFAULT;
+               goto exit;
+       }
+
+       dbus_error_init(&err);
+       if (!dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID)) {
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       ret = plugin_intf->get_device_state(handle, &state);
+       if (ret < 0)
+               _E("fail to get device state : %d", ret);
+       else
+               ret = state;
+
+       _D("get haptic state %d", ret);
+
+exit:
+       reply = dbus_message_new_method_return(msg);
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+       return reply;
+}
+
+static DBusMessage *edbus_create_effect(E_DBus_Object *obj, DBusMessage *msg)
+{
+       DBusMessageIter iter;
+       DBusMessage *reply;
+       DBusError err;
+       haptic_module_effect_element *elem_arr;
+       unsigned char *data;
+       unsigned char *elem;
+       unsigned char *p;
+       int i, size, cnt, ret;
+
+       if (!plugin_intf || !plugin_intf->create_effect) {
+               ret = -EFAULT;
+               goto exit;
+       }
+
+       dbus_error_init(&err);
+       if (!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &data,
+                               DBUS_TYPE_INT32, &size,
+                               DBUS_TYPE_STRING, &elem,
+                               DBUS_TYPE_INT32, &cnt, DBUS_TYPE_INVALID)) {
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       elem_arr = (haptic_module_effect_element*)malloc(sizeof(haptic_module_effect_element)*cnt);
+       for (p = elem_arr, i = 0; i < cnt; i++, p+=9) {
+               sscanf(p, "%6d%3d", &elem_arr[i].haptic_duration, &elem_arr[i].haptic_level);
+               _D("[%2d] duration : %d, level : %d", i, elem_arr[i].haptic_duration, elem_arr[i].haptic_level);
+       }
+
+       ret = plugin_intf->create_effect(data, size, elem_arr, cnt);
+       if (ret < 0)
+               _E("fail to create haptic effect : %d", ret);
+
+       _D("create haptic effect %d", ret);
+
+exit:
+       reply = dbus_message_new_method_return(msg);
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+       return reply;
+}
+
+static DBusMessage *edbus_get_duration(E_DBus_Object *obj, DBusMessage *msg)
+{
+       DBusMessageIter iter;
+       DBusMessage *reply;
+       DBusError err;
+       unsigned int handle;
+       unsigned char *data;
+       int duration, ret;
+
+       if (!plugin_intf || !plugin_intf->get_buffer_duration) {
+               ret = -EFAULT;
+               goto exit;
+       }
+
+       dbus_error_init(&err);
+       if (!dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &handle,
+                               DBUS_TYPE_STRING, &data, DBUS_TYPE_INVALID)) {
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       ret = plugin_intf->get_buffer_duration(handle, data, &duration);
+       if (ret < 0)
+               _E("fail to get buffer duration : %d", ret);
+       else
+               ret = duration;
+
+       _D("haptic get buffer duration %d", ret);
+
+exit:
+       reply = dbus_message_new_method_return(msg);
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+       return reply;
+}
+
+static DBusMessage *edbus_save_binary(E_DBus_Object *obj, DBusMessage *msg)
+{
+       DBusMessageIter iter;
+       DBusMessage *reply;
+       DBusError err;
+       unsigned char *data;
+       unsigned char *path;
+       int size, ret;
+
+       if (!plugin_intf || !plugin_intf->convert_binary) {
+               ret = -EFAULT;
+               goto exit;
+       }
+
+       dbus_error_init(&err);
+       if (!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &data,
+                               DBUS_TYPE_INT32, &size,
+                               DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID)) {
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       _D("file path : %s", path);
+       ret = plugin_intf->convert_binary(data, size, path);
+       if (ret < 0)
+               _E("fail to save binary data : %d", ret);
+
+       _D("haptic save binary data %d", ret);
+
+exit:
+       reply = dbus_message_new_method_return(msg);
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+       return reply;
+}
+
+static int load_module(void)
+{
+       struct stat buf;
+       const struct haptic_ops *(*get_haptic_plugin_interface) () = NULL;
+
+       if (stat(HAPTIC_MODULE_PATH, &buf)) {
+               _E("file(%s) is not presents", HAPTIC_MODULE_PATH);
+               goto error;
+       }
+
+       dlopen_handle = dlopen(HAPTIC_MODULE_PATH, RTLD_NOW);
+       if (!dlopen_handle) {
+               _E("dlopen failed: %s", dlerror());
+               goto error;
+       }
+
+       get_haptic_plugin_interface = dlsym(dlopen_handle, "get_haptic_plugin_interface");
+       if (!get_haptic_plugin_interface) {
+               _E("dlsym failed : %s", dlerror());
+               goto error;
+       }
+
+       plugin_intf = get_haptic_plugin_interface();
+       if (!plugin_intf) {
+               _E("get_haptic_plugin_interface() failed");
+               goto error;
+       }
+
+       _D("This device can vibe");
+       return 0;
+
+error:
+       if (dlopen_handle) {
+               dlclose(dlopen_handle);
+               dlopen_handle = NULL;
+       }
+
+       _D("This device can not vibe");
+       return -EPERM;
+}
+
+static void release_module(void)
+{
+       if (dlopen_handle) {
+               dlclose(dlopen_handle);
+               dlopen_handle = NULL;
+       }
+
+       _D("haptic module is released");
+}
+
+static struct edbus_method {
+       const char *member;
+       const char *signature;
+       const char *reply_signature;
+       E_DBus_Method_Cb func;
+} edbus_methods[] = {
+       { "GetCount",          NULL,   "i", edbus_get_count },
+       { "OpenDevice",         "i",   "i", edbus_open_device },
+       { "CloseDevice",        "u",   "i", edbus_close_device },
+       { "StopDevice",         "u",   "i", edbus_stop_device },
+       { "VibrateMonotone", "uiii",   "i", edbus_vibrate_monotone },
+       { "VibrateBuffer", "uayiii",   "i", edbus_vibrate_buffer },
+       { "GetState",           "u",   "i", edbus_get_state },
+       { "GetDuration",       "us",   "i", edbus_get_duration },
+       { "CreateEffect",    "sisi",   "i", edbus_create_effect },
+       { "SaveBinary",       "sis",   "i", edbus_save_binary },
+       /* Add methods here */
+};
+
+static int haptic_dbus_init(void)
+{
+       E_DBus_Interface *iface;
+       int ret, i;
+
+       iface = get_edbus_interface(DEVICED_PATH_HAPTIC);
+
+       _D("%s, %x", DEVICED_PATH_HAPTIC, iface);
+
+       if (!iface) {
+               _E("fail to get edbus interface!");
+               return -EPERM;
+       }
+
+       for (i = 0; i < ARRAY_SIZE(edbus_methods); i++) {
+               ret = e_dbus_interface_method_add(iface,
+                                   edbus_methods[i].member,
+                                   edbus_methods[i].signature,
+                                   edbus_methods[i].reply_signature,
+                                   edbus_methods[i].func);
+               if (!ret) {
+                       _E("fail to add method %s!", edbus_methods[i].member);
+                       return -EPERM;
+               }
+       }
+
+       return 0;
+}
+
+static void haptic_init(void *data)
+{
+       int r;
+
+       /* init dbus interface */
+       haptic_dbus_init();
+
+       /* load haptic plugin module */
+       r = load_module();
+       if (r < 0)
+               _E("fail to load haptic plugin module");
+}
+
+static void haptic_exit(void *data)
+{
+       /* release haptic plugin module */
+       release_module();
+}
+
+const struct device_ops haptic_device_ops = {
+       .init = haptic_init,
+       .exit = haptic_exit,
+};
index 3940d1d..eed6b94 100644 (file)
@@ -30,6 +30,8 @@ static int append_variant(DBusMessageIter *iter, const char *sig, char *param[])
        char *ch;
        int i;
        int int_type;
+       DBusMessageIter arr;
+       struct dbus_byte *byte;
 
        if (!sig || !param)
                return 0;
@@ -41,8 +43,22 @@ static int append_variant(DBusMessageIter *iter, const char *sig, char *param[])
                        dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &int_type);
                        break;
                case 's':
+                       _D("data : %s", param[i]);
                        dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &param[i]);
                        break;
+               case 'a':
+                       ++i, ++ch;
+                       switch (*ch) {
+                       case 'y':
+                               dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &arr);
+                               byte = (struct dbus_byte*)param[i];
+                               dbus_message_iter_append_fixed_array(&arr, DBUS_TYPE_BYTE, &(byte->data), byte->size);
+                               dbus_message_iter_close_container(iter, &arr);
+                               break;
+                       default:
+                               break;
+                       }
+                       break;
                default:
                        return -EINVAL;
                }
index 3e4c4e3..df560e5 100644 (file)
 #define DEVICED_PATH_DISPLAY           OBJECT_PATH"/Display"
 #define DEVICED_INTERFACE_DISPLAY      INTERFACE_NAME".display"
 
+#define DEVICED_PATH_HAPTIC            OBJECT_PATH"/Haptic"
+#define DEVICED_INTERFACE_HAPTIC       INTERFACE_NAME".haptic"
+
+struct dbus_byte {
+       char *data;
+       int size;
+};
+
 DBusMessage *deviced_dbus_method_sync(const char *dest, const char *path,
                const char *interface, const char *method,
                const char *sig, char *param[]);
index 8fc99e6..a09d090 100644 (file)
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -28,6 +29,7 @@
 #include <vconf.h>
 
 #include "log.h"
+#include "dbus.h"
 #include "haptic-plugin-intf.h"
 #include "dd-haptic.h"
 
 #define API __attribute__ ((visibility("default")))
 #endif
 
-#define HAPTIC_MODULE_PATH                     "/usr/lib/libhaptic-module.so"
+#define METHOD_OPEN_DEVICE                     "OpenDevice"
+#define METHOD_CLOSE_DEVICE                    "CloseDevice"
+#define METHOD_STOP_DEVICE                     "StopDevice"
+#define METHOD_VIBRATE_MONOTONE                "VibrateMonotone"
+#define METHOD_VIBRATE_BUFFER          "VibrateBuffer"
+#define METHOD_GET_COUNT                       "GetCount"
+#define METHOD_GET_STATE                       "GetState"
+#define METHOD_GET_DURATION                    "GetDuration"
+#define METHOD_CREATE_EFFECT           "CreateEffect"
+#define METHOD_SAVE_BINARY                     "SaveBinary"
 
-/* Haptic Handle Control */
-static unsigned int __handle_cnt;
-
-/* Haptic Plugin Interface */
-static void *dlopen_handle;
-static const struct haptic_ops *plugin_intf;
+#define DURATION_CHAR  6
+#define LEVEL_CHAR             3
 
 /* START of Static Function Section */
-static int __module_init(void)
+static unsigned char* convert_file_to_buffer(const char *file_name, int *size)
 {
-       struct stat buf;
-       const struct haptic_ops *(*get_haptic_plugin_interface) () = NULL;
+       FILE *pf;
+       long file_size;
+       unsigned char *pdata;
 
-       if (stat(HAPTIC_MODULE_PATH, &buf)) {
-               _E("file(%s) is not presents", HAPTIC_MODULE_PATH);
-               goto EXIT;
-       }
+       if (!file_name)
+               return NULL;
 
-       dlopen_handle = dlopen(HAPTIC_MODULE_PATH, RTLD_NOW);
-       if (!dlopen_handle) {
-               _E("dlopen failed: %s", dlerror());
-               goto EXIT;
+       /* Get File Stream Pointer */
+       pf = fopen(file_name, "rb");
+       if (!pf) {
+               _E("fopen failed : %s", strerror(errno));
+               return NULL;
        }
 
-
-       get_haptic_plugin_interface = dlsym(dlopen_handle, "get_haptic_plugin_interface");
-       if (!get_haptic_plugin_interface) {
-               _E("dlsym failed : %s", dlerror());
-               goto EXIT;
+       if (fseek(pf, 0, SEEK_END)) {
+               _E("fseek failed : %s", strerror(errno));
+               fclose(pf);
+               return NULL;
        }
 
-       plugin_intf = get_haptic_plugin_interface();
-       if (!plugin_intf) {
-               _E("get_haptic_plugin_interface() failed");
-               goto EXIT;
+       file_size = ftell(pf);
+       if (fseek(pf, 0, SEEK_SET)) {
+               _E("fseek failed : %s", strerror(errno));
+               fclose(pf);
+               return NULL;
        }
 
-       _D("This device can vibe");
-       return 0;
+       pdata = (unsigned char*)malloc(file_size);
+       if (!pdata) {
+               fclose(pf);
+               return NULL;
+       }
 
-EXIT:
-       if (dlopen_handle) {
-               dlclose(dlopen_handle);
-               dlopen_handle = NULL;
+       if (fread(pdata, 1, file_size, pf) != file_size) {
+               _E("fread failed : %s", strerror(errno));
+               free(pdata);
+               fclose(pf);
+               return NULL;
        }
 
-       _D("This device can not vibe");
-       return -1;
+       fclose(pf);
+       *size = file_size;
+       return pdata;
 }
 
-static int __module_fini(void)
+static int save_data(const unsigned char *data, int size, const char *file_path)
 {
-       if (dlopen_handle) {
-               dlclose(dlopen_handle);
-               dlopen_handle = NULL;
+       FILE *file;
+       int fd;
+
+       file = fopen(file_path, "wb+");
+       if (file == NULL) {
+               _E("To open file is failed : %s", strerror(errno));
+               return -1;
+       }
+
+       if (fwrite(data, 1, size, file) != size) {
+               _E("To write file is failed : %s", strerror(errno));
+               fclose(file);
+               return -1;
        }
 
-       _D("haptic module is released");
+       fd = fileno(file);
+       if (fd < 0) {
+               _E("To get file descriptor is failed : %s", strerror(errno));
+               fclose(file);
+               return -1;
+       }
+
+       if (fsync(fd) < 0) {
+               _E("To be synchronized with the disk is failed : %s", strerror(errno));
+               fclose(file);
+               return -1;
+       }
+
+       fclose(file);
        return 0;
 }
 
-static haptic_feedback_e __get_setting_feedback_level(void)
+static haptic_feedback_e convert_setting_to_module_level(void)
 {
        int setting_fb_level;
 
@@ -125,103 +160,123 @@ static haptic_feedback_e __get_setting_feedback_level(void)
 
 API int haptic_get_count(int *device_number)
 {
-       int ret;
-
-       if (__handle_cnt == 0) {
-               _E("Not initialized");
-               return HAPTIC_ERROR_NOT_INITIALIZED;
-       }
+       DBusError err;
+       DBusMessage *msg;
+       int ret, ret_val;
 
+       /* check if pointer is valid */
        if (device_number == NULL) {
                _E("Invalid parameter : device_number(NULL)");
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (!plugin_intf || !plugin_intf->get_device_count) {
-               _E("plugin_intf == NULL || plugin_intf->get_device_count == NULL");
+       /* request to deviced to get haptic count */
+       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+                       METHOD_GET_COUNT, NULL, NULL);
+       if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
-       }
 
-       ret = plugin_intf->get_device_count(device_number);
-       if (ret != HAPTIC_MODULE_ERROR_NONE) {
-               _E("haptic_internal_get_device_count is failed : %d", ret);
-               return HAPTIC_ERROR_OPERATION_FAILED;
+       dbus_error_init(&err);
+
+       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
+       if (!ret) {
+               _E("no message : [%s:%s]", err.name, err.message);
+               ret = HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       return HAPTIC_ERROR_NONE;
+       dbus_message_unref(msg);
+       dbus_error_free(&err);
+
+       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_GET_COUNT, ret_val);
+
+       *device_number = ret_val;
+       return ret;
 }
 
 API int haptic_open(haptic_device_e device_index, haptic_device_h *device_handle)
 {
-       int ret;
-       int handle;
-
-       if (!(device_index == HAPTIC_DEVICE_0 || device_index == HAPTIC_DEVICE_1 || device_index == HAPTIC_DEVICE_ALL)) {
+       DBusError err;
+       DBusMessage *msg;
+       char str_index[32];
+       char *arr[1];
+       int ret, ret_val;
+
+       /* check if index is valid */
+       if (!(device_index == HAPTIC_DEVICE_0 || device_index == HAPTIC_DEVICE_1 ||
+                               device_index == HAPTIC_DEVICE_ALL)) {
                _E("Invalid parameter : device_index(%d)", device_index);
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
+       /* check if pointer is valid */
        if (device_handle == NULL) {
                _E("Invalid parameter : device_handle(NULL)");
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (__handle_cnt == 0) {
-               ret = __module_init();
-               if (ret < 0) {
-                       _E("__module_init failed");
-                       return HAPTIC_ERROR_OPERATION_FAILED;
-               }
-       }
+       snprintf(str_index, sizeof(str_index), "%d", device_index);
+       arr[0] = str_index;
 
-       if (!plugin_intf || !plugin_intf->open_device) {
-               _E("plugin_intf == NULL || plugin_intf->open_device == NULL");
+       /* request to deviced to open haptic device */
+       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+                       METHOD_OPEN_DEVICE, "i", arr);
+       if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
-       }
 
-       ret = plugin_intf->open_device((int)device_index, &handle);
-       if (ret != HAPTIC_MODULE_ERROR_NONE) {
-               _E("haptic_internal_open_device is failed : %d", ret);
-               __module_fini();
-               return HAPTIC_ERROR_OPERATION_FAILED;
+       dbus_error_init(&err);
+
+       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
+       if (!ret) {
+               _E("no message : [%s:%s]", err.name, err.message);
+               ret = HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       __handle_cnt++;
-       *device_handle = (haptic_device_h)handle;
-       return HAPTIC_ERROR_NONE;
+       dbus_message_unref(msg);
+       dbus_error_free(&err);
+
+       _D("%s-%s : %d(%d)", DEVICED_INTERFACE_HAPTIC, METHOD_OPEN_DEVICE, ret_val, (unsigned int)ret_val);
+
+       *device_handle = (haptic_device_h)ret_val;
+       return ret;
 }
 
 API int haptic_close(haptic_device_h device_handle)
 {
-       int ret;
-
-       if (__handle_cnt == 0) {
-               _E("Not initialized");
-               return HAPTIC_ERROR_NOT_INITIALIZED;
-       }
+       DBusError err;
+       DBusMessage *msg;
+       char str_handle[32];
+       char *arr[1];
+       int ret, ret_val;
 
+       /* check if handle is valid */
        if (device_handle < 0) {
                _E("Invalid parameter : device_handle(%d)", device_handle);
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (!plugin_intf || !plugin_intf->close_device) {
-               _E("plugin_intf == NULL || plugin_intf->close_device == NULL");
-               return HAPTIC_ERROR_OPERATION_FAILED;
-       }
+       snprintf(str_handle, sizeof(str_handle), "%u", device_handle);
+       arr[0] = str_handle;
 
-       ret = plugin_intf->close_device((int)device_handle);
-       if (ret != HAPTIC_MODULE_ERROR_NONE) {
-               _E("haptic_internal_close_device is failed : %d", ret);
+       /* request to deviced to open haptic device */
+       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+                       METHOD_CLOSE_DEVICE, "u", arr);
+       if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
-       }
 
-       __handle_cnt--;
-       if (__handle_cnt == 0) {
-               __module_fini();
+       dbus_error_init(&err);
+
+       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
+       if (!ret) {
+               _E("no message : [%s:%s]", err.name, err.message);
+               ret = HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       return HAPTIC_ERROR_NONE;
+       dbus_message_unref(msg);
+       dbus_error_free(&err);
+
+       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_CLOSE_DEVICE, ret_val);
+
+       return ret;
 }
 
 API int haptic_vibrate_monotone(haptic_device_h device_handle, int duration, haptic_effect_h *effect_handle)
@@ -239,19 +294,22 @@ API int haptic_vibrate_monotone_with_detail(haptic_device_h device_handle,
                                         haptic_priority_e priority,
                                         haptic_effect_h *effect_handle)
 {
-       int ret;
-       int handle;
-
-       if (__handle_cnt == 0) {
-               _E("Not initialized");
-               return HAPTIC_ERROR_NOT_INITIALIZED;
-       }
-
+       DBusError err;
+       DBusMessage *msg;
+       char str_handle[32];
+       char str_duration[32];
+       char str_feedback[32];
+       char str_priority[32];
+       char *arr[4];
+       int ret, ret_val;
+
+       /* check if handle is valid */
        if (device_handle < 0) {
                _E("Invalid parameter : device_handle(%d)", device_handle);
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
+       /* check if passed arguments are valid */
        if (duration < 0) {
                _E("Invalid parameter : duration(%d)", duration);
                return HAPTIC_ERROR_INVALID_PARAMETER;
@@ -267,68 +325,71 @@ API int haptic_vibrate_monotone_with_detail(haptic_device_h device_handle,
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (!plugin_intf || !plugin_intf->vibrate_monotone) {
-               _E("plugin_intf == NULL || plugin_intf->vibrate_monotone == NULL");
-               return HAPTIC_ERROR_OPERATION_FAILED;
-       }
+       /* in case of FEEDBACK_AUTO, should be converted */
+       if (feedback == HAPTIC_FEEDBACK_AUTO)
+               feedback = convert_setting_to_module_level();
 
-       if (feedback == HAPTIC_FEEDBACK_AUTO) {
-               _D("Auto feedback level, feedback value will be changed");
-               feedback = __get_setting_feedback_level();
-       }
+       snprintf(str_handle, sizeof(str_handle), "%u", device_handle);
+       arr[0] = str_handle;
+       snprintf(str_duration, sizeof(str_duration), "%d", duration);
+       arr[1] = str_duration;
+       snprintf(str_feedback, sizeof(str_feedback), "%d", feedback);
+       arr[2] = str_feedback;
+       snprintf(str_priority, sizeof(str_priority), "%d", priority);
+       arr[3] = str_priority;
 
-       _D("duration : %d, feedback : %d, priority : %d", duration, feedback, priority);
-       ret = plugin_intf->vibrate_monotone((int)device_handle, duration, feedback, priority, &handle);
-       if (ret != HAPTIC_MODULE_ERROR_NONE) {
-               _E("haptic_internal_vibrate_monotone is failed : %d", ret);
+       /* request to deviced to open haptic device */
+       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+                       METHOD_VIBRATE_MONOTONE, "uiii", arr);
+       if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
-       }
 
-       if (effect_handle != NULL) {
-               *effect_handle = (haptic_effect_h)handle;
+       dbus_error_init(&err);
+
+       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
+       if (!ret) {
+               _E("no message : [%s:%s]", err.name, err.message);
+               ret = HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       return HAPTIC_ERROR_NONE;
-}
+       dbus_message_unref(msg);
+       dbus_error_free(&err);
 
-API int haptic_vibrate_file(haptic_device_h device_handle, const char *file_path, haptic_effect_h *effect_handle)
-{
-       return haptic_vibrate_file_with_detail(device_handle,
-                                                                                  file_path,
-                                                                                  HAPTIC_ITERATION_ONCE,
-                                                                                  HAPTIC_FEEDBACK_AUTO,
-                                                                                  HAPTIC_PRIORITY_MIN,
-                                                                                  effect_handle);
-}
+       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_VIBRATE_MONOTONE, ret_val);
 
-API int haptic_vibrate_file_with_detail(haptic_device_h device_handle,
-                                    const char *file_path,
-                                    haptic_iteration_e iteration,
-                                    haptic_feedback_e feedback,
-                                    haptic_priority_e priority,
-                                    haptic_effect_h *effect_handle)
-{
-       int ret;
-       int handle;
-       struct stat buf;
+       if (effect_handle != NULL)
+               *effect_handle = (haptic_effect_h)ret_val;
 
-       if (__handle_cnt == 0) {
-               _E("Not initialized");
-               return HAPTIC_ERROR_NOT_INITIALIZED;
-       }
+       return ret;
+}
 
+static int haptic_vibrate_buffer_with_detail_size(haptic_device_h device_handle,
+                                      const unsigned char *vibe_buffer,
+                                                                         int size,
+                                      haptic_iteration_e iteration,
+                                      haptic_feedback_e feedback,
+                                      haptic_priority_e priority,
+                                      haptic_effect_h *effect_handle)
+{
+       DBusError err;
+       DBusMessage *msg;
+       char str_handle[32];
+       char str_iteration[32];
+       char str_feedback[32];
+       char str_priority[32];
+       char *arr[6];
+       int ret, ret_val;
+       struct dbus_byte byte;
+
+       /* check if handle is valid */
        if (device_handle < 0) {
                _E("Invalid parameter : device_handle(%d)", device_handle);
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (file_path == NULL) {
-               _E("Invalid parameter : file_path(NULL)");
-               return HAPTIC_ERROR_INVALID_PARAMETER;
-       }
-
-       if (stat(file_path, &buf)) {
-               _E("Invalid parameter : (%s) is not presents", file_path);
+       /* check if passed arguments are valid */
+       if (vibe_buffer == NULL) {
+               _E("Invalid parameter : vibe_buffer(NULL)");
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
@@ -347,28 +408,94 @@ API int haptic_vibrate_file_with_detail(haptic_device_h device_handle,
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (!plugin_intf || !plugin_intf->vibrate_file) {
-               _E("plugin_intf == NULL || plugin_intf->vibrate_file == NULL");
+       /* in case of FEEDBACK_AUTO, should be converted */
+       if (feedback == HAPTIC_FEEDBACK_AUTO)
+               feedback = convert_setting_to_module_level();
+
+       snprintf(str_handle, sizeof(str_handle), "%u", device_handle);
+       arr[0] = str_handle;
+       byte.size = size;
+       byte.data = vibe_buffer;
+       arr[2] = &byte;
+       snprintf(str_iteration, sizeof(str_iteration), "%d", iteration);
+       arr[3] = str_iteration;
+       snprintf(str_feedback, sizeof(str_feedback), "%d", feedback);
+       arr[4] = str_feedback;
+       snprintf(str_priority, sizeof(str_priority), "%d", priority);
+       arr[5] = str_priority;
+
+       /* request to deviced to open haptic device */
+       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+                       METHOD_VIBRATE_BUFFER, "uayiii", arr);
+       if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
-       }
 
-       if (feedback == HAPTIC_FEEDBACK_AUTO) {
-               _D("Auto feedback level, feedback value will be changed");
-               feedback = __get_setting_feedback_level();
+       dbus_error_init(&err);
+
+       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
+       if (!ret) {
+               _E("no message : [%s:%s]", err.name, err.message);
+               ret = HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       _D("file_path : %s, iteration : %d, feedback : %d, priority : %d", file_path, iteration, feedback, priority);
-       ret = plugin_intf->vibrate_file((int)device_handle, file_path, iteration, feedback, priority, &handle);
-       if (ret != HAPTIC_MODULE_ERROR_NONE) {
-               _E("haptic_internal_vibrate_file is failed : %d", ret);
+       dbus_message_unref(msg);
+       dbus_error_free(&err);
+
+       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_VIBRATE_BUFFER, ret_val);
+
+       if (effect_handle != NULL)
+               *effect_handle = (haptic_effect_h)ret_val;
+
+       return ret;
+}
+
+API int haptic_vibrate_file(haptic_device_h device_handle, const char *file_path, haptic_effect_h *effect_handle)
+{
+       char *vibe_buffer;
+       int size, ret;
+
+       vibe_buffer = convert_file_to_buffer(file_path, &size);
+       if (!vibe_buffer) {
+               _E("Convert file to buffer error");
                return HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       if (effect_handle != NULL) {
-               *effect_handle = (haptic_effect_h)handle;
+       ret = haptic_vibrate_buffer_with_detail_size(device_handle,
+                                                                                       vibe_buffer,
+                                                                                       size,
+                                                                                       HAPTIC_ITERATION_ONCE,
+                                                                                       HAPTIC_FEEDBACK_AUTO,
+                                                                                       HAPTIC_PRIORITY_MIN,
+                                                                                       effect_handle);
+       free(vibe_buffer);
+       return ret;
+}
+
+API int haptic_vibrate_file_with_detail(haptic_device_h device_handle,
+                                    const char *file_path,
+                                    haptic_iteration_e iteration,
+                                    haptic_feedback_e feedback,
+                                    haptic_priority_e priority,
+                                    haptic_effect_h *effect_handle)
+{
+       char *vibe_buffer;
+       int size, ret;
+
+       vibe_buffer = convert_file_to_buffer(file_path, &size);
+       if (!vibe_buffer) {
+               _E("Convert file to buffer error");
+               return HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       return HAPTIC_ERROR_NONE;
+       ret = haptic_vibrate_buffer_with_detail_size(device_handle,
+                                                                                       vibe_buffer,
+                                                                                       size,
+                                                                                       iteration,
+                                                                                       feedback,
+                                                                                       priority,
+                                                                                       effect_handle);
+       free(vibe_buffer);
+       return ret;
 }
 
 API int haptic_vibrate_buffer(haptic_device_h device_handle, const unsigned char *vibe_buffer, haptic_effect_h *effect_handle)
@@ -420,19 +547,23 @@ API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle,
                                       haptic_priority_e priority,
                                       haptic_effect_h *effect_handle)
 {
-       int ret;
-       int handle;
-
-       if (__handle_cnt == 0) {
-               _E("Not initialized");
-               return HAPTIC_ERROR_NOT_INITIALIZED;
-       }
-
+       DBusError err;
+       DBusMessage *msg;
+       char str_handle[32];
+       char str_iteration[32];
+       char str_feedback[32];
+       char str_priority[32];
+       char *arr[6];
+       int ret, ret_val;
+       struct dbus_byte byte;
+
+       /* check if handle is valid */
        if (device_handle < 0) {
                _E("Invalid parameter : device_handle(%d)", device_handle);
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
+       /* check if passed arguments are valid */
        if (vibe_buffer == NULL) {
                _E("Invalid parameter : vibe_buffer(NULL)");
                return HAPTIC_ERROR_INVALID_PARAMETER;
@@ -453,28 +584,45 @@ API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle,
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (!plugin_intf || !plugin_intf->vibrate_buffer) {
-               _E("plugin_intf == NULL || plugin_intf->vibrate_buffer == NULL");
-               return HAPTIC_ERROR_OPERATION_FAILED;
-       }
+       /* in case of FEEDBACK_AUTO, should be converted */
+       if (feedback == HAPTIC_FEEDBACK_AUTO)
+               feedback = convert_setting_to_module_level();
 
-       if (feedback == HAPTIC_FEEDBACK_AUTO) {
-               _D("Auto feedback level, feedback value will be changed");
-               feedback = __get_setting_feedback_level();
-       }
+       _D("data : %s(%d)", vibe_buffer, strlen(vibe_buffer));
+
+       snprintf(str_handle, sizeof(str_handle), "%u", device_handle);
+       arr[0] = str_handle;
+       arr[1] = vibe_buffer;
+       snprintf(str_iteration, sizeof(str_iteration), "%d", iteration);
+       arr[2] = str_iteration;
+       snprintf(str_feedback, sizeof(str_feedback), "%d", feedback);
+       arr[3] = str_feedback;
+       snprintf(str_priority, sizeof(str_priority), "%d", priority);
+       arr[4] = str_priority;
 
-       _D("iteration : %d, feedback : %d, priority : %d", iteration, feedback, priority);
-       ret = plugin_intf->vibrate_buffer((int)device_handle, vibe_buffer, iteration, feedback, priority, &handle);
-       if (ret != HAPTIC_MODULE_ERROR_NONE) {
-               _E("haptic_internal_vibrate_buffer is failed : %d", ret);
+       /* request to deviced to open haptic device */
+       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+                       METHOD_VIBRATE_BUFFER, "usiii", arr);
+       if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
-       }
 
-       if (effect_handle != NULL) {
-               *effect_handle = (haptic_effect_h)handle;
+       dbus_error_init(&err);
+
+       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
+       if (!ret) {
+               _E("no message : [%s:%s]", err.name, err.message);
+               ret = HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       return HAPTIC_ERROR_NONE;
+       dbus_message_unref(msg);
+       dbus_error_free(&err);
+
+       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_VIBRATE_BUFFER, ret_val);
+
+       if (effect_handle != NULL)
+               *effect_handle = (haptic_effect_h)ret_val;
+
+       return ret;
 }
 
 API int haptic_stop_effect(haptic_device_h device_handle, haptic_effect_h effect_handle)
@@ -484,42 +632,50 @@ API int haptic_stop_effect(haptic_device_h device_handle, haptic_effect_h effect
 
 API int haptic_stop_all_effects(haptic_device_h device_handle)
 {
-       int ret;
-
-       if (__handle_cnt == 0) {
-               _E("Not initialized");
-               return HAPTIC_ERROR_NOT_INITIALIZED;
-       }
-
+       DBusError err;
+       DBusMessage *msg;
+       char str_handle[32];
+       char *arr[1];
+       int ret, ret_val;
+       /* check if handle is valid */
        if (device_handle < 0) {
-               _E("Invalid parameter : device_handle(%d)", device_handle);
+               _E("Invalid parameter : device_handle(NULL)");
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (!plugin_intf || !plugin_intf->stop_all_effects) {
-               _E("plugin_intf == NULL || plugin_intf->stop_all_effects == NULL");
-               return HAPTIC_ERROR_OPERATION_FAILED;
-       }
+       snprintf(str_handle, sizeof(str_handle), "%u", device_handle);
+       arr[0] = str_handle;
 
-       ret = plugin_intf->stop_all_effects((int)device_handle);
-       if (ret != HAPTIC_MODULE_ERROR_NONE) {
-               _E("haptic_internal_stop_all_effects is failed : %d", ret);
+       /* request to deviced to open haptic device */
+       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+                       METHOD_STOP_DEVICE, "u", arr);
+       if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
+       dbus_error_init(&err);
+
+       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
+       if (!ret) {
+               _E("no message : [%s:%s]", err.name, err.message);
+               ret = HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       return HAPTIC_ERROR_NONE;
+       dbus_message_unref(msg);
+       dbus_error_free(&err);
+
+       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_STOP_DEVICE, ret_val);
+
+       return ret;
 }
 
 API int haptic_get_effect_state(haptic_device_h device_handle, haptic_effect_h effect_handle, haptic_state_e *effect_state)
 {
-       int ret;
-       int state;
-
-       if (__handle_cnt == 0) {
-               _E("Not initialized");
-               return HAPTIC_ERROR_NOT_INITIALIZED;
-       }
+       DBusError err;
+       DBusMessage *msg;
+       char str_handle[32];
+       char *arr[1];
+       int ret, ret_val;
 
+       /* check if handle is valid */
        if (device_handle < 0) {
                _E("Invalid parameter : device_handle(%d)", device_handle);
                return HAPTIC_ERROR_INVALID_PARAMETER;
@@ -535,19 +691,30 @@ API int haptic_get_effect_state(haptic_device_h device_handle, haptic_effect_h e
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (!plugin_intf || !plugin_intf->get_effect_state) {
-               _E("plugin_intf == NULL || plugin_intf->get_effect_state == NULL");
-               return HAPTIC_ERROR_OPERATION_FAILED;
-       }
+       snprintf(str_handle, sizeof(str_handle), "%u", device_handle);
+       arr[0] = str_handle;
 
-       ret = plugin_intf->get_effect_state((int)device_handle, (int)effect_handle, &state);
-       if (ret != HAPTIC_MODULE_ERROR_NONE) {
-               _E("haptic_internal_get_effect_state is failed : %d", ret);
+       /* request to deviced to open haptic device */
+       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+                       METHOD_GET_STATE, "u", arr);
+       if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
+
+       dbus_error_init(&err);
+
+       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
+       if (!ret) {
+               _E("no message : [%s:%s]", err.name, err.message);
+               ret = HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       *effect_state = (haptic_state_e)state;
-       return HAPTIC_ERROR_NONE;
+       dbus_message_unref(msg);
+       dbus_error_free(&err);
+
+       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_GET_STATE, ret_val);
+
+       *effect_state = (haptic_state_e)ret_val;
+       return ret;
 }
 
 API int haptic_create_effect(unsigned char *vibe_buffer,
@@ -555,14 +722,15 @@ API int haptic_create_effect(unsigned char *vibe_buffer,
                          haptic_effect_element_s *elem_arr,
                          int max_elemcnt)
 {
-       int ret;
-       int i;
-
-       if (__handle_cnt == 0) {
-               _E("Not initialized");
-               return HAPTIC_ERROR_NOT_INITIALIZED;
-       }
-
+       DBusError err;
+       DBusMessage *msg;
+       char str_bufsize[32];
+       char *str_elem;
+       char str_elemcnt[32];
+       char *arr[4];
+       int i, temp, size, ret, ret_val;
+
+       /* check if passed arguments are valid */
        if (vibe_buffer == NULL) {
                _E("Invalid parameter : vibe_buffer(NULL)");
                return HAPTIC_ERROR_INVALID_PARAMETER;
@@ -583,39 +751,56 @@ API int haptic_create_effect(unsigned char *vibe_buffer,
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (!plugin_intf || !plugin_intf->create_effect) {
-               _E("plugin_intf == NULL || plugin_intf->create_effect == NULL");
-               return HAPTIC_ERROR_OPERATION_FAILED;
-       }
-
+       arr[0] = vibe_buffer;
+       snprintf(str_bufsize, sizeof(str_bufsize), "%d", max_bufsize);
+       arr[1] = str_bufsize;
+       size = (DURATION_CHAR+LEVEL_CHAR)*max_elemcnt;
+       str_elem = (unsigned char *)malloc(size+1);
+       memset(str_elem, 0, size);
        for (i = 0; i < max_elemcnt; i++) {
                if (elem_arr[i].haptic_level == HAPTIC_FEEDBACK_AUTO) {
-                       vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &elem_arr[i].haptic_level);
-            elem_arr[i].haptic_level = elem_arr[i].haptic_level*20;
+                       vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &temp);
+                       elem_arr[i].haptic_level = temp*20;
                }
-       }
-
-       ret = plugin_intf->create_effect(vibe_buffer, max_bufsize, (haptic_module_effect_element*)elem_arr, max_elemcnt);
-       if (ret != HAPTIC_MODULE_ERROR_NONE) {
-               _E("haptic_internal_create_effect is failed : %d", ret);
+               snprintf(str_elem, size, "%s%6d%3d", str_elem,
+                               elem_arr[i].haptic_duration, elem_arr[i].haptic_level);
+       }
+       str_elem[size] = '\0';
+       arr[2] = str_elem;
+       snprintf(str_elemcnt, sizeof(str_elemcnt), "%d", max_elemcnt);
+       arr[3] = str_elemcnt;
+
+       /* request to deviced to open haptic device */
+       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+                       METHOD_CREATE_EFFECT, "sisi", arr);
+       free(str_elem);
+       if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
+
+       dbus_error_init(&err);
+
+       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
+       if (!ret) {
+               _E("no message : [%s:%s]", err.name, err.message);
+               ret = HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       return HAPTIC_ERROR_NONE;
+       dbus_message_unref(msg);
+       dbus_error_free(&err);
+
+       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_CREATE_EFFECT, ret_val);
+
+       return ret;
 }
 
 API int haptic_save_effect(const unsigned char *vibe_buffer,
                        int max_bufsize,
                        const char *file_path)
 {
-       int ret;
        struct stat buf;
+       int size, ret;
 
-       if (__handle_cnt == 0) {
-               _E("Not initialized");
-               return HAPTIC_ERROR_NOT_INITIALIZED;
-       }
-
+       /* check if passed arguments are valid */
        if (vibe_buffer == NULL) {
                _E("Invalid parameter : vibe_buffer(NULL)");
                return HAPTIC_ERROR_INVALID_PARAMETER;
@@ -631,70 +816,97 @@ API int haptic_save_effect(const unsigned char *vibe_buffer,
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
+       /* check if the file already exists */
        if (!stat(file_path, &buf)) {
                _E("Already exist : file_path(%s)", file_path);
                return HAPTIC_ERROR_FILE_EXISTS;
        }
 
-       if (!plugin_intf || !plugin_intf->save_effect) {
-               _E("plugin_intf == NULL || plugin_intf->save_effect == NULL");
-               return HAPTIC_ERROR_OPERATION_FAILED;
+       size = strlen(vibe_buffer);
+       if (size <= 0) {
+               _E("fail to get buffer size");
+               return HAPTIC_MODULE_OPERATION_FAILED;
        }
 
        _D("file path : %s", file_path);
-       ret = plugin_intf->save_effect(vibe_buffer, max_bufsize, file_path);
-       if (ret != HAPTIC_MODULE_ERROR_NONE) {
-               _E("haptic_internal_save_effect is failed : %d", ret);
-               return HAPTIC_ERROR_OPERATION_FAILED;
+       ret = save_data(vibe_buffer, size, file_path);
+       if (ret < 0) {
+               _E("fail to save data");
+               return HAPTIC_MODULE_OPERATION_FAILED;
        }
 
        return HAPTIC_ERROR_NONE;
 }
 
-API int haptic_get_file_duration(haptic_device_h device_handle, const char *file_path, int *file_duration)
+static int haptic_get_buffer_duration_size(haptic_device_h device_handle, const unsigned char *vibe_buffer, int size, int *buffer_duration)
 {
-       int ret;
-       struct stat buf;
-       int duration;
-
-       if (__handle_cnt == 0) {
-               _E("Not initialized");
-               return HAPTIC_ERROR_NOT_INITIALIZED;
-       }
+       DBusError err;
+       DBusMessage *msg;
+       char str_handle[32];
+       char *arr[2];
+       int ret, ret_val;
 
+       /* check if handle is valid */
        if (device_handle < 0) {
                _E("Invalid parameter : device_handle(%d)", device_handle);
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (file_path == NULL) {
-               _E("Invalid parameter : file_path(NULL)");
+       if (vibe_buffer == NULL) {
+               _E("Invalid parameter : vibe_buffer(NULL)");
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (stat(file_path, &buf)) {
-               _E("Invalid parameter : (%s) is not presents", file_path);
+       /* check if pointer is valid */
+       if (buffer_duration == NULL) {
+               _E("Invalid parameter : buffer_duration(NULL)");
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (file_duration == NULL) {
-               _E("Invalid parameter : file_duration(NULL)");
-               return HAPTIC_ERROR_INVALID_PARAMETER;
-       }
+       snprintf(str_handle, sizeof(str_handle), "%u", device_handle);
+       arr[0] = str_handle;
+       arr[1] = vibe_buffer;
 
-       if (!plugin_intf || !plugin_intf->get_file_duration) {
-               _E("plugin_intf == NULL || plugin_intf->get_file_duration == NULL");
+       /* request to deviced to open haptic device */
+       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+                       METHOD_GET_DURATION, "us", arr);
+       if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
+
+       dbus_error_init(&err);
+
+       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
+       if (!ret) {
+               _E("no message : [%s:%s]", err.name, err.message);
+               ret = HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       ret = plugin_intf->get_file_duration((int)device_handle, file_path, &duration);
-       if (ret != HAPTIC_MODULE_ERROR_NONE) {
-               _E("haptic_internal_stop_get_file_duration is failed : %d", ret);
+       dbus_message_unref(msg);
+       dbus_error_free(&err);
+
+       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_GET_DURATION, ret_val);
+
+       *buffer_duration = ret_val;
+       return ret;
+}
+
+API int haptic_get_file_duration_size(haptic_device_h device_handle, const char *file_path, int *file_duration)
+{
+       char *vibe_buffer;
+       int size, ret;
+
+       vibe_buffer = convert_file_to_buffer(file_path, &size);
+       if (!vibe_buffer) {
+               _E("Convert file to buffer error");
                return HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       *file_duration = duration;
-       return HAPTIC_ERROR_NONE;
+       ret = haptic_get_buffer_duration_size(device_handle,
+                                                                        vibe_buffer,
+                                                                        size,
+                                                                        file_duration);
+       free(vibe_buffer);
+       return ret;
 }
 
 API int haptic_get_buffer_duration(haptic_device_h device_handle, const unsigned char *vibe_buffer, int *buffer_duration)
@@ -707,14 +919,13 @@ API int haptic_get_buffer_duration(haptic_device_h device_handle, const unsigned
 
 API int haptic_get_buffers_duration(haptic_device_h device_handle, const unsigned char *vibe_buffer, int size, int *buffer_duration)
 {
-       int ret;
-       int duration;
-
-       if (__handle_cnt == 0) {
-               _E("Not initialized");
-               return HAPTIC_ERROR_NOT_INITIALIZED;
-       }
+       DBusError err;
+       DBusMessage *msg;
+       char str_handle[32];
+       char *arr[2];
+       int ret, ret_val;
 
+       /* check if handle is valid */
        if (device_handle < 0) {
                _E("Invalid parameter : device_handle(%d)", device_handle);
                return HAPTIC_ERROR_INVALID_PARAMETER;
@@ -725,36 +936,49 @@ API int haptic_get_buffers_duration(haptic_device_h device_handle, const unsigne
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
+       /* check if pointer is valid */
        if (buffer_duration == NULL) {
                _E("Invalid parameter : buffer_duration(NULL)");
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
-       if (!plugin_intf || !plugin_intf->get_buffer_duration) {
-               _E("plugin_intf == NULL || plugin_intf->get_buffer_duration == NULL");
-               return HAPTIC_ERROR_OPERATION_FAILED;
-       }
+       snprintf(str_handle, sizeof(str_handle), "%u", device_handle);
+       arr[0] = str_handle;
+       arr[1] = vibe_buffer;
 
-       ret = plugin_intf->get_buffer_duration((int)device_handle, vibe_buffer, &duration);
-       if (ret != HAPTIC_MODULE_ERROR_NONE) {
-               _E("haptic_internal_stop_get_buffer_duration is failed : %d", ret);
+       /* request to deviced to open haptic device */
+       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+                       METHOD_GET_DURATION, "us", arr);
+       if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
+
+       dbus_error_init(&err);
+
+       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
+       if (!ret) {
+               _E("no message : [%s:%s]", err.name, err.message);
+               ret = HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       *buffer_duration = duration;
-       return HAPTIC_ERROR_NONE;
+       dbus_message_unref(msg);
+       dbus_error_free(&err);
+
+       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_GET_DURATION, ret_val);
+
+       *buffer_duration = ret_val;
+       return ret;
 }
 
 API int haptic_save_led(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path)
 {
-       int ret;
+       DBusError err;
+       DBusMessage *msg;
        struct stat buf;
+       char str_bufsize[32];
+       char *arr[3];
+       int size, ret, ret_val;
 
-       if (__handle_cnt == 0) {
-               _E("Not initialized");
-               return HAPTIC_ERROR_NOT_INITIALIZED;
-       }
-
+       /* check if passed arguments are valid */
        if (vibe_buffer == NULL) {
                _E("Invalid parameter : vibe_buffer(NULL)");
                return HAPTIC_ERROR_INVALID_PARAMETER;
@@ -770,22 +994,35 @@ API int haptic_save_led(const unsigned char *vibe_buffer, int max_bufsize, const
                return HAPTIC_ERROR_INVALID_PARAMETER;
        }
 
+       /* check if the file already exists */
        if (!stat(file_path, &buf)) {
                _E("Already exist : file_path(%s)", file_path);
                return HAPTIC_ERROR_FILE_EXISTS;
        }
 
-       if (!plugin_intf || !plugin_intf->convert_binary) {
-               _E("plugin_intf == NULL || plugin_intf->convert_binary == NULL");
-               return HAPTIC_ERROR_OPERATION_FAILED;
-       }
+       arr[0] = vibe_buffer;
+       snprintf(str_bufsize, sizeof(str_bufsize), "%d", max_bufsize);
+       arr[1] = str_bufsize;
+       arr[2] = file_path;
 
-       _D("file path : %s", file_path);
-       ret = plugin_intf->convert_binary(vibe_buffer, max_bufsize, file_path);
-       if (ret != HAPTIC_MODULE_ERROR_NONE) {
-               _E("haptic_internal_save_effect is failed : %d", ret);
+       /* request to deviced to open haptic device */
+       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+                       METHOD_SAVE_BINARY, "sis", arr);
+       if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
+
+       dbus_error_init(&err);
+
+       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
+       if (!ret) {
+               _E("no message : [%s:%s]", err.name, err.message);
+               ret = HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       return HAPTIC_ERROR_NONE;
+       dbus_message_unref(msg);
+       dbus_error_free(&err);
+
+       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_SAVE_BINARY, ret_val);
+
+       return ret;
 }