/*
- * bluetooth-frwk
- *
- * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ * 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.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
*
*/
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus.h>
#include <glib.h>
+#include <gio/gio.h>
#include <dlog.h>
#include <string.h>
#include <syspopup_caller.h>
+#include <vconf.h>
#include "bluetooth-api.h"
+
#include "bt-service-common.h"
+#include "bt-service-device.h"
#include "bt-service-hid.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 */
goto done;
}
- if (g_error != NULL) {
- BT_ERR("Hidh Connect Dbus Call Error: %s\n", g_error->message);
- result = BLUETOOTH_ERROR_INTERNAL;
- goto dbus_return;
- }
-
-dbus_return:
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);
-done:
- if (g_error)
- g_error_free(g_error);
+ BT_DBG("HID Connected..");
+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");
goto done;
}
- if (g_error != NULL) {
- BT_ERR("Hidh Connect Dbus Call Error: %s\n", g_error->message);
- result = BLUETOOTH_ERROR_INTERNAL;
- goto dbus_return;
- }
-
-dbus_return:
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);
int _bt_hid_connect(int request_id,
bluetooth_device_address_t *device_address)
{
- gchar *device_path = NULL;
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
bt_function_data_t *func_data;
- DBusGProxy *adapter_proxy;
- DBusGProxy *hid_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);
- dbus_g_proxy_call(adapter_proxy, "FindDevice", NULL,
- G_TYPE_STRING, address, G_TYPE_INVALID,
- DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID);
-
- if (device_path == NULL) {
- BT_ERR("No paired device");
- return BLUETOOTH_ERROR_NOT_PAIRED;
- }
-
- hid_proxy = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
- device_path, BT_INPUT_INTERFACE);
- g_free(device_path);
- retv_if(hid_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
func_data = g_malloc0(sizeof(bt_function_data_t));
-
func_data->address = g_strdup(address);
func_data->req_id = request_id;
+ uuid = HID_UUID;
- if (!dbus_g_proxy_begin_call(hid_proxy, "Connect",
- (DBusGProxyCallNotify)__bt_hid_connect_cb,
- func_data, NULL, G_TYPE_INVALID)) {
- BT_ERR("Hidh connect Dbus Call Error");
- g_object_unref(hid_proxy);
- return BLUETOOTH_ERROR_INTERNAL;
- }
+ ret = _bt_connect_profile(address, uuid,
+ __bt_hid_connect_cb, func_data);
+ if (ret != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("_bt_connect_profile Error");
+ return ret;
+ }
return BLUETOOTH_ERROR_NONE;
}
int _bt_hid_disconnect(int request_id,
bluetooth_device_address_t *device_address)
{
- gchar *device_path = NULL;
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
bt_function_data_t *func_data;
- DBusGProxy *adapter_proxy;
- DBusGProxy *hid_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);
- dbus_g_proxy_call(adapter_proxy, "FindDevice", NULL,
- G_TYPE_STRING, address, G_TYPE_INVALID,
- DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID);
-
- if (device_path == NULL) {
- BT_ERR("No paired device");
- return BLUETOOTH_ERROR_NOT_PAIRED;
- }
-
- hid_proxy = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
- device_path, BT_INPUT_INTERFACE);
- g_free(device_path);
- retv_if(hid_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
func_data = g_malloc0(sizeof(bt_function_data_t));
-
func_data->address = g_strdup(address);
func_data->req_id = request_id;
- if (!dbus_g_proxy_begin_call(hid_proxy, "Disconnect",
- (DBusGProxyCallNotify)__bt_hid_disconnect_cb,
- func_data, NULL, G_TYPE_INVALID)) {
- BT_ERR("Hidh disconnect Dbus Call Error");
- g_object_unref(hid_proxy);
+ ret = _bt_disconnect_profile(address, HID_UUID,
+ __bt_hid_disconnect_cb, func_data);
+
+ if (ret != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("_bt_disconnect_profile Error");
+ return ret;
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_hid_enable_barcode_feature(void)
+{
+ if (vconf_set_int(BT_HID_BARCODE_SUPPORT, 1) != 0) {
+ BT_ERR("Set vconf failed\n");
return BLUETOOTH_ERROR_INTERNAL;
}