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 #if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
30 #include <syspopup_caller.h>
32 #include "bluetooth-api.h"
34 #include "bt-service-common.h"
35 #include "bt-service-device.h"
36 #include "bt-service-hid.h"
37 #include "bt-service-event.h"
38 #include "bt-service-util.h"
40 static void __bt_hid_connect_cb(DBusGProxy *proxy, DBusGProxyCall *call,
43 GError *g_error = NULL;
44 GArray *out_param1 = NULL;
45 GArray *out_param2 = NULL;
46 bluetooth_device_address_t device_addr = { {0} };
47 int result = BLUETOOTH_ERROR_NONE;
48 bt_function_data_t *func_data;
49 request_info_t *req_info;
51 dbus_g_proxy_end_call(proxy, call, &g_error, G_TYPE_INVALID);
53 g_object_unref(proxy);
55 func_data = user_data;
57 if (func_data == NULL) {
59 BT_ERR("func_data == NULL");
63 req_info = _bt_get_request_info(func_data->req_id);
64 if (req_info == NULL) {
65 BT_ERR("req_info == NULL");
69 if (g_error != NULL) {
70 BT_ERR("Hidh Connect Dbus Call Error: %s\n", g_error->message);
71 result = BLUETOOTH_ERROR_INTERNAL;
74 if (req_info->context == NULL)
77 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
78 out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
80 _bt_convert_addr_string_to_type(device_addr.addr,
83 g_array_append_vals(out_param1, &device_addr,
84 sizeof(bluetooth_device_address_t));
85 g_array_append_vals(out_param2, &result, sizeof(int));
87 dbus_g_method_return(req_info->context, out_param1, out_param2);
89 g_array_free(out_param1, TRUE);
90 g_array_free(out_param2, TRUE);
92 _bt_delete_request_list(req_info->req_id);
93 BT_DBG("HID Connected..");
96 g_error_free(g_error);
99 g_free(func_data->address);
104 static void __bt_hid_disconnect_cb(DBusGProxy *proxy, DBusGProxyCall *call,
107 GError *g_error = NULL;
108 GArray *out_param1 = NULL;
109 GArray *out_param2 = NULL;
110 bluetooth_device_address_t device_addr = { {0} };
111 int result = BLUETOOTH_ERROR_NONE;
112 bt_function_data_t *func_data;
113 request_info_t *req_info;
115 dbus_g_proxy_end_call(proxy, call, &g_error, G_TYPE_INVALID);
117 g_object_unref(proxy);
119 func_data = user_data;
121 if (func_data == NULL) {
123 BT_ERR("func_data == NULL");
127 req_info = _bt_get_request_info(func_data->req_id);
128 if (req_info == NULL) {
129 BT_ERR("req_info == NULL");
133 if (g_error != NULL) {
134 BT_ERR("Hidh Connect Dbus Call Error: %s\n", g_error->message);
135 result = BLUETOOTH_ERROR_INTERNAL;
138 if (req_info->context == NULL)
141 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
142 out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
144 _bt_convert_addr_string_to_type(device_addr.addr,
147 g_array_append_vals(out_param1, &device_addr,
148 sizeof(bluetooth_device_address_t));
149 g_array_append_vals(out_param2, &result, sizeof(int));
151 dbus_g_method_return(req_info->context, out_param1, out_param2);
153 g_array_free(out_param1, TRUE);
154 g_array_free(out_param2, TRUE);
156 _bt_delete_request_list(req_info->req_id);
159 g_error_free(g_error);
162 g_free(func_data->address);
168 /**********************************************************************
170 ***********************************************************************/
172 int _bt_hid_connect(int request_id,
173 bluetooth_device_address_t *device_address)
175 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
176 bt_function_data_t *func_data;
177 DBusGProxy *adapter_proxy;
178 DBusGConnection *conn;
183 BT_CHECK_PARAMETER(device_address, return);
185 adapter_proxy = _bt_get_adapter_proxy();
186 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
188 conn = _bt_get_system_gconn();
189 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
191 _bt_convert_addr_type_to_string(address, device_address->addr);
193 func_data = g_malloc0(sizeof(bt_function_data_t));
195 func_data->address = g_strdup(address);
196 func_data->req_id = request_id;
199 ret = _bt_connect_profile(address, uuid,
200 __bt_hid_connect_cb, func_data);
202 if (ret != BLUETOOTH_ERROR_NONE) {
203 BT_ERR("_bt_connect_profile Error");
206 return BLUETOOTH_ERROR_NONE;
209 int _bt_hid_disconnect(int request_id,
210 bluetooth_device_address_t *device_address)
212 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
213 bt_function_data_t *func_data;
214 DBusGProxy *adapter_proxy;
215 DBusGConnection *conn;
219 BT_CHECK_PARAMETER(device_address, return);
221 adapter_proxy = _bt_get_adapter_proxy();
222 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
224 conn = _bt_get_system_gconn();
225 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
227 _bt_convert_addr_type_to_string(address, device_address->addr);
229 func_data = g_malloc0(sizeof(bt_function_data_t));
231 func_data->address = g_strdup(address);
232 func_data->req_id = request_id;
234 ret = _bt_disconnect_profile(address, HID_UUID,
235 __bt_hid_disconnect_cb, func_data);
237 if (ret != BLUETOOTH_ERROR_NONE) {
238 BT_ERR("_bt_disconnect_profile Error");
242 return BLUETOOTH_ERROR_NONE;