4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
28 #include <syspopup_caller.h>
29 #include "bluetooth-api.h"
31 #include "bt-service-common.h"
32 #include "bt-service-device.h"
33 #include "bt-service-hid.h"
34 #include "bt-service-event.h"
35 #include "bt-service-util.h"
37 static void __bt_hid_connect_cb(GDBusProxy *proxy, GAsyncResult *res,
40 GError *g_error = NULL;
41 GVariant *out_param1 = NULL;
42 GVariant *reply = NULL;
43 bluetooth_device_address_t device_addr = { {0} };
44 int result = BLUETOOTH_ERROR_NONE;
45 bt_function_data_t *func_data;
46 request_info_t *req_info;
49 func_data = user_data;
51 reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
52 g_object_unref(proxy);
54 BT_ERR("Hid Connect Dbus Call Error");
56 BT_ERR("Error: %s\n", g_error->message);
57 g_clear_error(&g_error);
59 result = BLUETOOTH_ERROR_INTERNAL;
61 g_variant_unref(reply);
64 if (func_data == NULL) {
66 BT_ERR("func_data == NULL");
70 req_info = _bt_get_request_info(func_data->req_id);
71 if (req_info == NULL) {
72 BT_ERR("req_info == NULL");
76 if (req_info->context == NULL)
78 BT_DBG("Address: %s", func_data->address);
79 _bt_convert_addr_string_to_type(device_addr.addr,
82 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
83 &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
85 g_dbus_method_invocation_return_value(req_info->context,
86 g_variant_new("iv", result, out_param1));
88 _bt_delete_request_list(req_info->req_id);
89 BT_DBG("HID Connected..");
93 g_free(func_data->address);
98 static void __bt_hid_disconnect_cb(GDBusProxy *proxy,GAsyncResult *res,
101 GError *g_error = NULL;
102 GVariant *out_param1 = NULL;
104 bluetooth_device_address_t device_addr = { {0} };
105 int result = BLUETOOTH_ERROR_NONE;
106 bt_function_data_t *func_data;
107 request_info_t *req_info;
109 reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
110 g_object_unref(proxy);
113 BT_ERR("Hid Disconnect Dbus Call Error");
115 BT_ERR("Error: %s\n", g_error->message);
116 g_clear_error(&g_error);
118 result = BLUETOOTH_ERROR_INTERNAL;
120 g_variant_unref(reply);
122 func_data = user_data;
123 if (func_data == NULL) {
125 BT_ERR("func_data == NULL");
129 req_info = _bt_get_request_info(func_data->req_id);
130 if (req_info == NULL) {
131 BT_ERR("req_info == NULL");
135 if (req_info->context == NULL)
137 BT_DBG("Address: %s", func_data->address);
138 _bt_convert_addr_string_to_type(device_addr.addr,
141 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
142 &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
144 g_dbus_method_invocation_return_value(req_info->context,
145 g_variant_new("iv", result, out_param1));
147 _bt_delete_request_list(req_info->req_id);
148 BT_DBG("HID Disconnected..");
152 g_free(func_data->address);
158 /**********************************************************************
160 ***********************************************************************/
162 int _bt_hid_connect(int request_id,
163 bluetooth_device_address_t *device_address)
165 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
166 bt_function_data_t *func_data;
167 /* GDBusProxy *adapter_proxy; */
168 GDBusConnection *conn;
173 BT_CHECK_PARAMETER(device_address, return);
175 /* Unused adapter proxy
176 adapter_proxy = _bt_get_adapter_proxy();
177 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
179 conn = _bt_get_system_gconn();
180 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
182 _bt_convert_addr_type_to_string(address, device_address->addr);
184 func_data = g_malloc0(sizeof(bt_function_data_t));
185 /* Fix : NULL_RETURNS */
186 retv_if(func_data == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION);
188 func_data->address = g_strdup(address);
189 func_data->req_id = request_id;
192 ret = _bt_connect_profile(address, uuid,
193 __bt_hid_connect_cb, func_data);
195 if (ret != BLUETOOTH_ERROR_NONE) {
196 BT_ERR("_bt_connect_profile Error");
199 return BLUETOOTH_ERROR_NONE;
202 int _bt_hid_disconnect(int request_id,
203 bluetooth_device_address_t *device_address)
205 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
206 bt_function_data_t *func_data;
207 /* GDBusProxy *adapter_proxy; */
208 GDBusConnection *conn;
212 BT_CHECK_PARAMETER(device_address, return);
214 /* Unused adapter proxy
215 adapter_proxy = _bt_get_adapter_proxy();
216 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
218 conn = _bt_get_system_gconn();
219 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
221 _bt_convert_addr_type_to_string(address, device_address->addr);
223 func_data = g_malloc0(sizeof(bt_function_data_t));
224 /* Fix : NULL_RETURNS */
225 retv_if(func_data == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION);
227 func_data->address = g_strdup(address);
228 func_data->req_id = request_id;
230 ret = _bt_disconnect_profile(address, HID_UUID,
231 __bt_hid_disconnect_cb, func_data);
233 if (ret != BLUETOOTH_ERROR_NONE) {
234 BT_ERR("_bt_disconnect_profile Error");
238 return BLUETOOTH_ERROR_NONE;