2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <syspopup_caller.h>
24 #include "bluetooth-api.h"
26 #include "bt-service-common.h"
27 #include "bt-service-device.h"
28 #include "bt-service-hid.h"
29 #include "bt-service-event.h"
30 #include "bt-service-util.h"
32 #define BT_HID_BARCODE_SUPPORT "file/bluetooth/hid/barcode_support"
34 static void __bt_hid_connect_cb(GDBusProxy *proxy, GAsyncResult *res,
37 GError *g_error = NULL;
38 GVariant *out_param1 = NULL;
39 GVariant *reply = NULL;
40 bluetooth_device_address_t device_addr = { {0} };
41 int result = BLUETOOTH_ERROR_NONE;
42 bt_function_data_t *func_data;
43 request_info_t *req_info;
46 func_data = user_data;
48 reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
49 g_object_unref(proxy);
51 BT_ERR("Hid Connect Dbus Call Error");
53 BT_ERR("Error: %s\n", g_error->message);
54 g_clear_error(&g_error);
56 result = BLUETOOTH_ERROR_INTERNAL;
58 g_variant_unref(reply);
61 if (func_data == NULL) {
63 BT_ERR("func_data == NULL");
67 req_info = _bt_get_request_info(func_data->req_id);
68 if (req_info == NULL) {
69 BT_ERR("req_info == NULL");
73 if (req_info->context == NULL)
75 BT_DBG("Address: %s", func_data->address);
76 _bt_convert_addr_string_to_type(device_addr.addr,
79 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
80 &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
82 g_dbus_method_invocation_return_value(req_info->context,
83 g_variant_new("iv", result, out_param1));
85 _bt_delete_request_list(req_info->req_id);
86 BT_DBG("HID Connected..");
90 g_free(func_data->address);
95 static void __bt_hid_disconnect_cb(GDBusProxy *proxy, GAsyncResult *res,
98 GError *g_error = NULL;
99 GVariant *out_param1 = NULL;
101 bluetooth_device_address_t device_addr = { {0} };
102 int result = BLUETOOTH_ERROR_NONE;
103 bt_function_data_t *func_data;
104 request_info_t *req_info;
106 reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
107 g_object_unref(proxy);
110 BT_ERR("Hid Disconnect Dbus Call Error");
112 BT_ERR("Error: %s\n", g_error->message);
113 g_clear_error(&g_error);
115 result = BLUETOOTH_ERROR_INTERNAL;
117 g_variant_unref(reply);
119 func_data = user_data;
120 if (func_data == NULL) {
122 BT_ERR("func_data == NULL");
126 req_info = _bt_get_request_info(func_data->req_id);
127 if (req_info == NULL) {
128 BT_ERR("req_info == NULL");
132 if (req_info->context == NULL)
134 BT_DBG("Address: %s", func_data->address);
135 _bt_convert_addr_string_to_type(device_addr.addr,
138 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
139 &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
141 g_dbus_method_invocation_return_value(req_info->context,
142 g_variant_new("iv", result, out_param1));
144 _bt_delete_request_list(req_info->req_id);
145 BT_DBG("HID Disconnected..");
149 g_free(func_data->address);
155 /**********************************************************************
157 ***********************************************************************/
159 int _bt_hid_connect(int request_id,
160 bluetooth_device_address_t *device_address)
162 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
163 bt_function_data_t *func_data;
164 /* GDBusProxy *adapter_proxy; */
165 GDBusConnection *conn;
170 BT_CHECK_PARAMETER(device_address, return);
172 /* Unused adapter proxy
173 adapter_proxy = _bt_get_adapter_proxy();
174 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
176 conn = _bt_gdbus_get_system_gconn();
177 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
179 _bt_convert_addr_type_to_string(address, device_address->addr);
181 func_data = g_malloc0(sizeof(bt_function_data_t));
182 func_data->address = g_strdup(address);
183 func_data->req_id = request_id;
186 ret = _bt_connect_profile(address, uuid,
187 __bt_hid_connect_cb, func_data);
189 if (ret != BLUETOOTH_ERROR_NONE) {
190 BT_ERR("_bt_connect_profile Error");
193 return BLUETOOTH_ERROR_NONE;
196 int _bt_hid_disconnect(int request_id,
197 bluetooth_device_address_t *device_address)
199 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
200 bt_function_data_t *func_data;
201 /* GDBusProxy *adapter_proxy; */
202 GDBusConnection *conn;
206 BT_CHECK_PARAMETER(device_address, return);
208 /* Unused adapter proxy
209 adapter_proxy = _bt_get_adapter_proxy();
210 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
212 conn = _bt_gdbus_get_system_gconn();
213 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
215 _bt_convert_addr_type_to_string(address, device_address->addr);
217 func_data = g_malloc0(sizeof(bt_function_data_t));
218 func_data->address = g_strdup(address);
219 func_data->req_id = request_id;
221 ret = _bt_disconnect_profile(address, HID_UUID,
222 __bt_hid_disconnect_cb, func_data);
224 if (ret != BLUETOOTH_ERROR_NONE) {
225 BT_ERR("_bt_disconnect_profile Error");
229 return BLUETOOTH_ERROR_NONE;
232 int _bt_hid_enable_barcode_feature(void)
234 if (vconf_set_int(BT_HID_BARCODE_SUPPORT, 1) != 0) {
235 BT_ERR("Set vconf failed\n");
236 return BLUETOOTH_ERROR_INTERNAL;
239 return BLUETOOTH_ERROR_NONE;