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.
24 #include <dbus/dbus-glib.h>
25 #include <dbus/dbus.h>
29 #include <syspopup_caller.h>
30 #include "bluetooth-api.h"
32 #include "bt-service-common.h"
33 #include "bt-service-device.h"
34 #include "bt-service-hid.h"
35 #include "bt-service-event.h"
36 #include "bt-service-util.h"
38 static void __bt_hid_connect_cb(DBusGProxy *proxy, DBusGProxyCall *call,
41 GError *g_error = NULL;
42 GArray *out_param1 = NULL;
43 GArray *out_param2 = NULL;
44 bluetooth_device_address_t device_addr = { {0} };
45 int result = BLUETOOTH_ERROR_NONE;
46 bt_function_data_t *func_data;
47 request_info_t *req_info;
49 dbus_g_proxy_end_call(proxy, call, &g_error, G_TYPE_INVALID);
51 g_object_unref(proxy);
53 func_data = user_data;
55 if (func_data == NULL) {
57 BT_ERR("func_data == NULL");
61 req_info = _bt_get_request_info(func_data->req_id);
62 if (req_info == NULL) {
63 BT_ERR("req_info == NULL");
67 if (g_error != NULL) {
68 BT_ERR("Hidh Connect Dbus Call Error: %s\n", g_error->message);
69 result = BLUETOOTH_ERROR_INTERNAL;
72 if (req_info->context == NULL)
75 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
76 out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
78 _bt_convert_addr_string_to_type(device_addr.addr,
81 g_array_append_vals(out_param1, &device_addr,
82 sizeof(bluetooth_device_address_t));
83 g_array_append_vals(out_param2, &result, sizeof(int));
85 dbus_g_method_return(req_info->context, out_param1, out_param2);
87 g_array_free(out_param1, TRUE);
88 g_array_free(out_param2, TRUE);
90 _bt_delete_request_list(req_info->req_id);
91 BT_DBG("HID Connected..");
94 g_error_free(g_error);
97 g_free(func_data->address);
102 static void __bt_hid_disconnect_cb(DBusGProxy *proxy, DBusGProxyCall *call,
105 GError *g_error = NULL;
106 GArray *out_param1 = NULL;
107 GArray *out_param2 = NULL;
108 bluetooth_device_address_t device_addr = { {0} };
109 int result = BLUETOOTH_ERROR_NONE;
110 bt_function_data_t *func_data;
111 request_info_t *req_info;
113 dbus_g_proxy_end_call(proxy, call, &g_error, G_TYPE_INVALID);
115 g_object_unref(proxy);
117 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 (g_error != NULL) {
132 BT_ERR("Hidh Connect Dbus Call Error: %s\n", g_error->message);
133 result = BLUETOOTH_ERROR_INTERNAL;
136 if (req_info->context == NULL)
139 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
140 out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
142 _bt_convert_addr_string_to_type(device_addr.addr,
145 g_array_append_vals(out_param1, &device_addr,
146 sizeof(bluetooth_device_address_t));
147 g_array_append_vals(out_param2, &result, sizeof(int));
149 dbus_g_method_return(req_info->context, out_param1, out_param2);
151 g_array_free(out_param1, TRUE);
152 g_array_free(out_param2, TRUE);
154 _bt_delete_request_list(req_info->req_id);
157 g_error_free(g_error);
160 g_free(func_data->address);
166 /**********************************************************************
168 ***********************************************************************/
170 int _bt_hid_connect(int request_id,
171 bluetooth_device_address_t *device_address)
173 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
174 bt_function_data_t *func_data;
175 DBusGProxy *adapter_proxy;
176 DBusGConnection *conn;
181 BT_CHECK_PARAMETER(device_address, return);
183 adapter_proxy = _bt_get_adapter_proxy();
184 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
186 conn = _bt_get_system_gconn();
187 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
189 _bt_convert_addr_type_to_string(address, device_address->addr);
191 func_data = g_malloc0(sizeof(bt_function_data_t));
193 func_data->address = g_strdup(address);
194 func_data->req_id = request_id;
197 ret = _bt_connect_profile(address, uuid,
198 __bt_hid_connect_cb, func_data);
200 if (ret != BLUETOOTH_ERROR_NONE) {
201 BT_ERR("_bt_connect_profile Error");
204 return BLUETOOTH_ERROR_NONE;
207 int _bt_hid_disconnect(int request_id,
208 bluetooth_device_address_t *device_address)
210 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
211 bt_function_data_t *func_data;
212 DBusGProxy *adapter_proxy;
213 DBusGConnection *conn;
217 BT_CHECK_PARAMETER(device_address, return);
219 adapter_proxy = _bt_get_adapter_proxy();
220 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
222 conn = _bt_get_system_gconn();
223 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
225 _bt_convert_addr_type_to_string(address, device_address->addr);
227 func_data = g_malloc0(sizeof(bt_function_data_t));
229 func_data->address = g_strdup(address);
230 func_data->req_id = request_id;
232 ret = _bt_disconnect_profile(address, HID_UUID,
233 __bt_hid_disconnect_cb, func_data);
235 if (ret != BLUETOOTH_ERROR_NONE) {
236 BT_ERR("_bt_disconnect_profile Error");
240 return BLUETOOTH_ERROR_NONE;