Apply tizen 3.0 based product patchsets
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-hid.c
index cde8fa2..2587a15 100644 (file)
@@ -1,11 +1,5 @@
 /*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
- *              Girishashok Joshi <girish.joshi@samsung.com>
- *              Chanyeol Park <chanyeol.park@samsung.com>
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  */
 
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus.h>
 #include <glib.h>
+#include <gio/gio.h>
 #include <dlog.h>
 #include <string.h>
-#if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
 #include <syspopup_caller.h>
-#endif
+#include <vconf.h>
 #include "bluetooth-api.h"
 
 #include "bt-service-common.h"
 #include "bt-service-event.h"
 #include "bt-service-util.h"
 
-static void __bt_hid_connect_cb(DBusGProxy *proxy, DBusGProxyCall *call,
-                                   gpointer user_data)
+#define BT_HID_BARCODE_SUPPORT "file/bluetooth/hid/barcode_support"
+
+static void __bt_hid_connect_cb(GDBusProxy *proxy, GAsyncResult *res,
+                                       gpointer user_data)
 {
        GError *g_error = NULL;
-       GArray *out_param1 = NULL;
-       GArray *out_param2 = NULL;
+       GVariant *out_param1 = NULL;
+       GVariant *reply = NULL;
        bluetooth_device_address_t device_addr = { {0} };
        int result = BLUETOOTH_ERROR_NONE;
        bt_function_data_t *func_data;
        request_info_t *req_info;
 
-       dbus_g_proxy_end_call(proxy, call, &g_error, G_TYPE_INVALID);
+       BT_DBG("+");
+       func_data = user_data;
 
+       reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
        g_object_unref(proxy);
+       if (reply == NULL) {
+               BT_ERR("Hid Connect Dbus Call Error");
+               if (g_error) {
+                       BT_ERR("Error: %s\n", g_error->message);
+                       g_clear_error(&g_error);
+               }
+               result = BLUETOOTH_ERROR_INTERNAL;
+       }
+       g_variant_unref(reply);
 
-       func_data = user_data;
 
        if (func_data == NULL) {
                /* Send reply */
@@ -66,58 +70,53 @@ static void __bt_hid_connect_cb(DBusGProxy *proxy, DBusGProxyCall *call,
                goto done;
        }
 
-       if (g_error != NULL) {
-               BT_ERR("Hidh Connect Dbus Call Error: %s\n", g_error->message);
-               result = BLUETOOTH_ERROR_INTERNAL;
-       }
-
        if (req_info->context == NULL)
                goto done;
-
-       out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
-       out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
-
+       BT_DBG("Address: %s", func_data->address);
        _bt_convert_addr_string_to_type(device_addr.addr,
                                        func_data->address);
 
-       g_array_append_vals(out_param1, &device_addr,
-                               sizeof(bluetooth_device_address_t));
-       g_array_append_vals(out_param2, &result, sizeof(int));
-
-       dbus_g_method_return(req_info->context, out_param1, out_param2);
+       out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
+                       &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
 
-       g_array_free(out_param1, TRUE);
-       g_array_free(out_param2, TRUE);
+       g_dbus_method_invocation_return_value(req_info->context,
+                       g_variant_new("iv", result, out_param1));
 
        _bt_delete_request_list(req_info->req_id);
        BT_DBG("HID Connected..");
-done:
-       if (g_error)
-               g_error_free(g_error);
 
+done:
        if (func_data) {
                g_free(func_data->address);
                g_free(func_data);
        }
 }
 
-static void __bt_hid_disconnect_cb(DBusGProxy *proxy, DBusGProxyCall *call,
-                                   gpointer user_data)
+static void __bt_hid_disconnect_cb(GDBusProxy *proxy, GAsyncResult *res,
+                                       gpointer user_data)
 {
        GError *g_error = NULL;
-       GArray *out_param1 = NULL;
-       GArray *out_param2 = NULL;
+       GVariant *out_param1 = NULL;
+       GVariant *reply;
        bluetooth_device_address_t device_addr = { {0} };
        int result = BLUETOOTH_ERROR_NONE;
        bt_function_data_t *func_data;
        request_info_t *req_info;
 
-       dbus_g_proxy_end_call(proxy, call, &g_error, G_TYPE_INVALID);
-
+       reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
        g_object_unref(proxy);
 
-       func_data = user_data;
+       if (reply == NULL) {
+               BT_ERR("Hid Disconnect Dbus Call Error");
+               if (g_error) {
+                       BT_ERR("Error: %s\n", g_error->message);
+                       g_clear_error(&g_error);
+               }
+               result = BLUETOOTH_ERROR_INTERNAL;
+       }
+       g_variant_unref(reply);
 
+       func_data = user_data;
        if (func_data == NULL) {
                /* Send reply */
                BT_ERR("func_data == NULL");
@@ -130,34 +129,22 @@ static void __bt_hid_disconnect_cb(DBusGProxy *proxy, DBusGProxyCall *call,
                goto done;
        }
 
-       if (g_error != NULL) {
-               BT_ERR("Hidh Connect Dbus Call Error: %s\n", g_error->message);
-               result = BLUETOOTH_ERROR_INTERNAL;
-       }
-
        if (req_info->context == NULL)
                goto done;
-
-       out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
-       out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
-
+       BT_DBG("Address: %s", func_data->address);
        _bt_convert_addr_string_to_type(device_addr.addr,
                                        func_data->address);
 
-       g_array_append_vals(out_param1, &device_addr,
-                               sizeof(bluetooth_device_address_t));
-       g_array_append_vals(out_param2, &result, sizeof(int));
+       out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
+                                                       &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
 
-       dbus_g_method_return(req_info->context, out_param1, out_param2);
-
-       g_array_free(out_param1, TRUE);
-       g_array_free(out_param2, TRUE);
+       g_dbus_method_invocation_return_value(req_info->context,
+                       g_variant_new("iv", result, out_param1));
 
        _bt_delete_request_list(req_info->req_id);
-done:
-       if (g_error)
-               g_error_free(g_error);
+       BT_DBG("HID Disconnected..");
 
+done:
        if (func_data) {
                g_free(func_data->address);
                g_free(func_data);
@@ -174,24 +161,24 @@ int _bt_hid_connect(int request_id,
 {
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
        bt_function_data_t *func_data;
-       DBusGProxy *adapter_proxy;
-       DBusGConnection *conn;
+       /* GDBusProxy *adapter_proxy; */
+       GDBusConnection *conn;
 
        int ret;
        char *uuid;
 
        BT_CHECK_PARAMETER(device_address, return);
 
+       /* Unused adapter proxy
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       conn = _bt_get_system_gconn();
+       */
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
        func_data = g_malloc0(sizeof(bt_function_data_t));
-
        func_data->address = g_strdup(address);
        func_data->req_id = request_id;
        uuid = HID_UUID;
@@ -201,6 +188,8 @@ int _bt_hid_connect(int request_id,
 
        if (ret != BLUETOOTH_ERROR_NONE) {
                BT_ERR("_bt_connect_profile Error");
+               g_free(func_data->address);
+               g_free(func_data);
                return ret;
        }
        return BLUETOOTH_ERROR_NONE;
@@ -211,23 +200,23 @@ int _bt_hid_disconnect(int request_id,
 {
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
        bt_function_data_t *func_data;
-       DBusGProxy *adapter_proxy;
-       DBusGConnection *conn;
+       /* GDBusProxy *adapter_proxy; */
+       GDBusConnection *conn;
 
        int ret;
 
        BT_CHECK_PARAMETER(device_address, return);
 
+       /* Unused adapter proxy
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       conn = _bt_get_system_gconn();
+       */
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
        func_data = g_malloc0(sizeof(bt_function_data_t));
-
        func_data->address = g_strdup(address);
        func_data->req_id = request_id;
 
@@ -236,8 +225,21 @@ int _bt_hid_disconnect(int request_id,
 
        if (ret != BLUETOOTH_ERROR_NONE) {
                BT_ERR("_bt_disconnect_profile Error");
+               g_free(func_data->address);
+               g_free(func_data);
                return ret;
        }
 
        return BLUETOOTH_ERROR_NONE;
 }
+
+int _bt_hid_enable_barcode_feature(void)
+{
+       if (vconf_set_bool(BT_HID_BARCODE_SUPPORT, true) != 0) {
+               BT_ERR("Set vconf failed\n");
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+