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 #if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
23 #include <syspopup_caller.h>
25 #include "bluetooth-api.h"
27 #include "bt-service-common.h"
28 #include "bt-service-device.h"
29 #include "bt-service-hid.h"
30 #include "bt-service-event.h"
31 #include "bt-service-util.h"
33 static void __bt_hid_connect_cb(GDBusProxy *proxy, GAsyncResult *res,
36 GError *g_error = NULL;
37 GVariant *out_param1 = NULL;
38 GVariant *reply = NULL;
39 bluetooth_device_address_t device_addr = { {0} };
40 int result = BLUETOOTH_ERROR_NONE;
41 bt_function_data_t *func_data;
42 request_info_t *req_info;
45 func_data = user_data;
47 reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
48 g_object_unref(proxy);
50 BT_ERR("Hid Connect Dbus Call Error");
52 BT_ERR("Error: %s\n", g_error->message);
53 g_clear_error(&g_error);
55 result = BLUETOOTH_ERROR_INTERNAL;
57 g_variant_unref(reply);
60 if (func_data == NULL) {
62 BT_ERR("func_data == NULL");
66 req_info = _bt_get_request_info(func_data->req_id);
67 if (req_info == NULL) {
68 BT_ERR("req_info == NULL");
72 if (req_info->context == NULL)
74 BT_DBG("Address: %s", func_data->address);
75 _bt_convert_addr_string_to_type(device_addr.addr,
78 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
79 &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
81 g_dbus_method_invocation_return_value(req_info->context,
82 g_variant_new("iv", result, out_param1));
84 _bt_delete_request_list(req_info->req_id);
85 BT_DBG("HID Connected..");
89 g_free(func_data->address);
94 static void __bt_hid_disconnect_cb(GDBusProxy *proxy, GAsyncResult *res,
97 GError *g_error = NULL;
98 GVariant *out_param1 = NULL;
100 bluetooth_device_address_t device_addr = { {0} };
101 int result = BLUETOOTH_ERROR_NONE;
102 bt_function_data_t *func_data;
103 request_info_t *req_info;
105 reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
106 g_object_unref(proxy);
109 BT_ERR("Hid Disconnect Dbus Call Error");
111 BT_ERR("Error: %s\n", g_error->message);
112 g_clear_error(&g_error);
114 result = BLUETOOTH_ERROR_INTERNAL;
116 g_variant_unref(reply);
118 func_data = user_data;
119 if (func_data == NULL) {
121 BT_ERR("func_data == NULL");
125 req_info = _bt_get_request_info(func_data->req_id);
126 if (req_info == NULL) {
127 BT_ERR("req_info == NULL");
131 if (req_info->context == NULL)
133 BT_DBG("Address: %s", func_data->address);
134 _bt_convert_addr_string_to_type(device_addr.addr,
137 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
138 &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
140 g_dbus_method_invocation_return_value(req_info->context,
141 g_variant_new("iv", result, out_param1));
143 _bt_delete_request_list(req_info->req_id);
144 BT_DBG("HID Disconnected..");
148 g_free(func_data->address);
154 /**********************************************************************
156 ***********************************************************************/
158 int _bt_hid_connect(int request_id,
159 bluetooth_device_address_t *device_address)
161 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
162 bt_function_data_t *func_data;
163 /* GDBusProxy *adapter_proxy; */
164 GDBusConnection *conn;
169 BT_CHECK_PARAMETER(device_address, return);
171 /* Unused adapter proxy
172 adapter_proxy = _bt_get_adapter_proxy();
173 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
175 conn = _bt_get_system_gconn();
176 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
178 _bt_convert_addr_type_to_string(address, device_address->addr);
180 func_data = g_malloc0(sizeof(bt_function_data_t));
181 /* Fix : NULL_RETURNS */
182 retv_if(func_data == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION);
184 func_data->address = g_strdup(address);
185 func_data->req_id = request_id;
188 ret = _bt_connect_profile(address, uuid,
189 __bt_hid_connect_cb, func_data);
191 if (ret != BLUETOOTH_ERROR_NONE) {
192 BT_ERR("_bt_connect_profile Error");
195 return BLUETOOTH_ERROR_NONE;
198 int _bt_hid_disconnect(int request_id,
199 bluetooth_device_address_t *device_address)
201 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
202 bt_function_data_t *func_data;
203 /* GDBusProxy *adapter_proxy; */
204 GDBusConnection *conn;
208 BT_CHECK_PARAMETER(device_address, return);
210 /* Unused adapter proxy
211 adapter_proxy = _bt_get_adapter_proxy();
212 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
214 conn = _bt_get_system_gconn();
215 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
217 _bt_convert_addr_type_to_string(address, device_address->addr);
219 func_data = g_malloc0(sizeof(bt_function_data_t));
220 /* Fix : NULL_RETURNS */
221 retv_if(func_data == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION);
223 func_data->address = g_strdup(address);
224 func_data->req_id = request_id;
226 ret = _bt_disconnect_profile(address, HID_UUID,
227 __bt_hid_disconnect_cb, func_data);
229 if (ret != BLUETOOTH_ERROR_NONE) {
230 BT_ERR("_bt_disconnect_profile Error");
234 return BLUETOOTH_ERROR_NONE;