/*
- * bluetooth-frwk
- *
- * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
*
*/
-#include <dbus/dbus-glib.h>
#include <glib.h>
#include <dlog.h>
#include <string.h>
#include "bluetooth-hid-api.h"
#include "bluetooth-audio-api.h"
#include "bt-internal-types.h"
+#include "bluetooth-ipsp-api.h"
#include "bt-common.h"
#include "bt-request-sender.h"
#include "bt-event-handler.h"
-
-/* auto generated header by bt-request-service.xml*/
-#include "bt-request-service.h"
+#include "bluetooth-media-control.h"
+#include "bluetooth-gatt-client-api.h"
+#include "bluetooth-mesh-api.h"
static GSList *sending_requests;
-DBusGConnection *service_conn;
-DBusGConnection *system_conn;
-DBusGProxy *service_proxy;
-
-static void __bt_remove_all_sending_requests(void)
-{
- GSList *l;
- bt_req_info_t *info;
-
- for (l = sending_requests; l != NULL; l = g_slist_next(l)) {
- info = l->data;
-
- if (info && info->proxy && info->proxy_call)
- dbus_g_proxy_cancel_call(info->proxy, info->proxy_call);
- }
-
- g_slist_free(sending_requests);
- sending_requests = NULL;
-}
+static GDBusProxy *service_gproxy;
-DBusGProxy *_bt_init_service_proxy(void)
+static GDBusProxy *__bt_gdbus_init_service_proxy(void)
{
- DBusGProxy *proxy;
+ GDBusConnection *service_gconn;
+ GDBusProxy *proxy;
+ GError *err = NULL;
- g_type_init();
+ service_gconn = _bt_get_system_private_conn();
- if (service_conn == NULL) {
- service_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(service_conn == NULL, NULL);
- }
+ if (!service_gconn)
+ return NULL;
- proxy = dbus_g_proxy_new_for_name(service_conn, BT_DBUS_NAME, BT_SERVICE_PATH,
- BT_DBUS_NAME);
+ proxy = g_dbus_proxy_new_sync(service_gconn,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
+ BT_DBUS_NAME,
+ BT_SERVICE_PATH,
+ BT_DBUS_NAME,
+ NULL, &err);
+ if (!proxy) {
+ if (err) {
+ BT_ERR("Unable to create proxy: %s", err->message);
+ g_clear_error(&err);
+ }
- if (proxy == NULL) {
- dbus_g_connection_unref(service_conn);
- service_conn = NULL;
return NULL;
}
- service_proxy = proxy;
+ service_gproxy = proxy;
return proxy;
}
-void _bt_deinit_proxys(void)
+static GDBusProxy *__bt_gdbus_get_service_proxy(void)
{
- __bt_remove_all_sending_requests();
-
- if (service_proxy) {
- g_object_unref(service_proxy);
- service_proxy = NULL;
- }
-
- if (service_conn) {
- dbus_g_connection_unref(service_conn);
- service_conn = NULL;
- }
-
- if (system_conn) {
- dbus_g_connection_unref(system_conn);
- system_conn = NULL;
- }
+ return (service_gproxy) ? service_gproxy : __bt_gdbus_init_service_proxy();
}
-static DBusGProxy *__bt_get_service_proxy(void)
+void _bt_gdbus_deinit_proxys(void)
{
- return (service_proxy) ? service_proxy : _bt_init_service_proxy();
+ if (service_gproxy) {
+ g_object_unref(service_gproxy);
+ service_gproxy = NULL;
+ }
}
static void __bt_get_event_info(int service_function, GArray *output,
{
ret_if(event == NULL);
+ BT_DBG("service_function : %s (0x%x)",
+ _bt_convert_service_function_to_string(service_function),
+ service_function);
switch (service_function) {
case BT_BOND_DEVICE:
+ case BT_BOND_DEVICE_BY_TYPE:
*event_type = BT_ADAPTER_EVENT;
*event = BLUETOOTH_EVENT_BONDING_FINISHED;
ret_if(output == NULL);
*event = BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED;
ret_if(output == NULL);
*param_data = &g_array_index(output,
- bluetooth_device_info_t, 0);
+ bluetooth_device_address_t, 0);
break;
case BT_SEARCH_SERVICE:
*event_type = BT_ADAPTER_EVENT;
*event = BLUETOOTH_EVENT_SERVICE_SEARCHED;
ret_if(output == NULL);
*param_data = &g_array_index(output,
- bluetooth_device_info_t, 0);
+ bt_sdp_info_t, 0);
break;
case BT_HID_CONNECT:
*event_type = BT_HID_EVENT;
ret_if(output == NULL);
*param_data = &g_array_index(output, char, 0);
break;
+ case BT_AV_SOURCE_CONNECT:
+ *event_type = BT_A2DP_SOURCE_EVENT;
+ *event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output, char, 0);
+ break;
+ case BT_AV_SOURCE_DISCONNECT:
+ *event_type = BT_A2DP_SOURCE_EVENT;
+ *event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output, char, 0);
+ break;
+ case BT_HF_CONNECT:
+ *event_type = BT_HF_AGENT_EVENT;
+ *event = BLUETOOTH_EVENT_HF_CONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output, char, 0);
+ break;
+ case BT_HF_DISCONNECT:
+ *event_type = BT_HF_AGENT_EVENT;
+ *event = BLUETOOTH_EVENT_HF_DISCONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output, char, 0);
+ break;
case BT_NETWORK_CONNECT:
*event_type = BT_ADAPTER_EVENT;
*event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
ret_if(output == NULL);
*param_data = &g_array_index(output,
bluetooth_rfcomm_connection_t, 0);
-
+ break;
+ case BT_AVRCP_TARGET_CONNECT:
+ *event_type = BT_AVRCP_EVENT;
+ *event = BLUETOOTH_EVENT_AVRCP_CONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output, char, 0);
+ break;
+ case BT_AVRCP_TARGET_DISCONNECT:
+ *event_type = BT_AVRCP_EVENT;
+ *event = BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output, char, 0);
+ break;
+ case BT_AVRCP_CONTROL_CONNECT:
+ *event_type = BT_AVRCP_CONTROL_EVENT;
+ *event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output, char, 0);
+ break;
+ case BT_AVRCP_CONTROL_DISCONNECT:
+ *event_type = BT_AVRCP_CONTROL_EVENT;
+ *event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output, char, 0);
+ break;
+ case BT_REQ_ATT_MTU:
+ *event_type = BT_DEVICE_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_device_address_t, 0);
+ break;
+ case BT_CONNECT_LE:
+ *event_type = BT_DEVICE_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_CLIENT_CONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_device_address_t, 0);
+ break;
+ case BT_DISCONNECT_LE:
+ *event_type = BT_DEVICE_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_device_address_t, 0);
+ break;
+ case BT_GATT_READ_CHARACTERISTIC:
+ BT_INFO("BT_GATT_READ_CHARACTERISTIC");
+ *event_type = BT_GATT_CLIENT_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_READ_CHAR;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_gatt_client_char_prop_info_t, 0);
+ break;
+ case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE:
+ BT_INFO("BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE");
+ *event_type = BT_GATT_CLIENT_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_WRITE_CHAR;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_gatt_client_char_prop_info_t, 0);
+ break;
+ case BT_GATT_READ_DESCRIPTOR_VALUE:
+ BT_INFO("BT_GATT_READ_DESCRIPTOR_VALUE");
+ *event_type = BT_GATT_CLIENT_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_READ_DESC;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_gatt_client_desc_prop_info_t, 0);
+ break;
+ case BT_GATT_WRITE_DESCRIPTOR_VALUE:
+ BT_INFO("BT_GATT_WRITE_DESCRIPTOR_VALUE");
+ *event_type = BT_GATT_CLIENT_EVENT;
+ *event = BLUETOOTH_EVENT_GATT_WRITE_DESC;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_gatt_client_desc_prop_info_t, 0);
+ break;
+ case BT_TDS_READ_TRANSPORT_DATA:
+ *event_type = BT_TDS_EVENT;
+ *event = BLUETOOTH_EVENT_TDS_TRANSPORT_DATA_RECEIVED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_device_address_t, 0);
+ break;
+ case BT_TDS_ENABLE_CONTROL_POINT:
+ *event_type = BT_TDS_EVENT;
+ *event = BLUETOOTH_EVENT_TDS_CONTROL_POINT_ENABLED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_device_address_t, 0);
+ break;
+ case BT_TDS_ACTIVATE_CONTROL_POINT:
+ *event_type = BT_TDS_EVENT;
+ *event = BLUETOOTH_EVENT_TDS_ACTIVATION_RESULT;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_device_address_t, 0);
+ break;
+ case BT_HDP_CONNECT:
+ *event_type = BT_HDP_EVENT;
+ *event = BLUETOOTH_EVENT_HDP_CONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bt_hdp_connected_t, 0);
+ break;
+ case BT_HDP_DISCONNECT:
+ *event_type = BT_HDP_EVENT;
+ *event = BLUETOOTH_EVENT_HDP_DISCONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bt_hdp_disconnected_t, 0);
+ break;
+ case BT_MESH_NETWORK_PROVISION_DEVICE:
+ *event_type = BT_MESH_EVENT;
+ *event = BLUETOOTH_EVENT_MESH_PROVISIONING_FINISHED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_mesh_provisioning_request_t, 0);
+ break;
+ case BT_MESH_NODE_BROWSE:
+ *event_type = BT_MESH_EVENT;
+ *event = BLUETOOTH_EVENT_MESH_NODE_BROWSED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_mesh_node_discover_t, 0);
+ break;
+ case BT_MESH_NODE_GET_VENDOR_FEATURES:
+ *event_type = BT_MESH_EVENT;
+ *event = BLUETOOTH_EVENT_MESH_NODE_VENDOR_FEATURES;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_mesh_node_features_t, 0);
+ break;
+ case BT_MESH_NODE_CONFIGURE_KEY:
+ *event_type = BT_MESH_EVENT;
+ *event = BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_mesh_key_configure_t, 0);
+ break;
+ case BT_MESH_NODE_TTL_EXECUTE:
+ *event_type = BT_MESH_EVENT;
+ *event = BLUETOOTH_EVENT_MESH_NODE_TTL_CONFIGURED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_mesh_node_ttl_info_t, 0);
+ break;
+ case BT_MESH_MODEL_CONFIGURE_APPKEY:
+ *event_type = BT_MESH_EVENT;
+ *event = BLUETOOTH_EVENT_MESH_MODEL_APPKEY_BIND;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_mesh_model_configure_t, 0);
+ break;
+ case BT_MESH_MODEL_EXECUTE_MSG:
+ *event_type = BT_MESH_EVENT;
+ *event = BLUETOOTH_EVENT_MESH_MODEL_MSG_EXECUTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_mesh_model_msg_t, 0);
+ break;
+ case BT_MESH_MODEL_CONFIG_GROUP_SUB:
+ *event_type = BT_MESH_EVENT;
+ *event = BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_CONFGURED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_mesh_model_configure_t, 0);
+ break;
+ case BT_MESH_MODEL_GET_APPKEY_LIST:
+ *event_type = BT_MESH_EVENT;
+ *event = BLUETOOTH_EVENT_MESH_MODEL_APPKEY_LIST;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_mesh_model_configure_t, 0);
+ break;
+ case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST:
+ *event_type = BT_MESH_EVENT;
+ *event = BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_LIST;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_mesh_model_configure_t, 0);
+ break;
+ case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB:
+ *event_type = BT_MESH_EVENT;
+ *event = BLUETOOTH_EVENT_MESH_MODEL_VIRTUAL_SUBSCRIPTION_CONFGURED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_mesh_model_configure_t, 0);
+ break;
+ case BT_MESH_MODEL_SET_PUBLICATION:
+ *event_type = BT_MESH_EVENT;
+ *event = BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_mesh_model_configure_t, 0);
+ break;
+ case BT_MESH_MODEL_GET_PUBLICATION:
+ *event_type = BT_MESH_EVENT;
+ *event = BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_mesh_model_configure_t, 0);
break;
default:
BT_ERR("Unknown function");
out param2: return paramter
out param3:
*/
-void __send_request_cb(DBusGProxy *proxy, GArray *out_param1,
- GArray *out_param2, GError *error,
- gpointer userdata)
+static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
+{
+ char *data;
+ int size;
+
+ size = g_variant_get_size(var);
+ if (size > 0) {
+ data = (char *)g_variant_get_data(var);
+ if (data)
+ param = g_array_append_vals(param, data, size);
+
+ }
+}
+
+static void __send_request_cb(GDBusProxy *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
bluetooth_event_param_t bt_event;
- bt_req_info_t *cb_data = userdata;
+ bt_req_info_t *cb_data = user_data;
int result = BLUETOOTH_ERROR_NONE;
int event_type = BT_ADAPTER_EVENT;
int request_id;
+ GError *error = NULL;
+ GVariant *value;
+ GVariant *param1;
+// GVariant *param2;
+ GArray *out_param1 = NULL;
+// GArray *out_param2 = NULL;
+ BT_DBG("+");
memset(&bt_event, 0x00, sizeof(bluetooth_event_param_t));
- if (error != NULL) {
- /* dBUS gives error cause */
- BT_ERR("D-Bus API failure: message[%s]", error->message);
- g_error_free(error);
+ value = g_dbus_proxy_call_finish(proxy, res, &error);
+ if (value == NULL) {
+ if (error) {
+ /* dBUS gives error cause */
+ BT_ERR("D-Bus API failure: message[%s]",
+ error->message);
+ g_clear_error(&error);
+ }
result = BLUETOOTH_ERROR_TIMEOUT;
ret_if(cb_data == NULL);
&bt_event.event, &event_type,
&bt_event.param_data);
} else {
- ret_if(out_param2 == NULL);
+ g_variant_get(value, "(iv)", &result, ¶m1);
+ g_variant_unref(value);
+
+ if (param1) {
+ out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
+ __bt_fill_garray_from_variant(param1, out_param1);
+ g_variant_unref(param1);
+ }
- result = g_array_index(out_param2, int, 0);
+// if (param2) {
+// out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
+// __bt_fill_garray_from_variant(param2, out_param2);
+// result = g_array_index(out_param2, int, 0);
+// g_variant_unref(param2);
+// g_array_free(out_param2, TRUE);
+// } else {
+// result = BLUETOOTH_ERROR_INTERNAL;
+// }
ret_if(cb_data == NULL);
&bt_event.event, &event_type,
&bt_event.param_data);
- if (result == BLUETOOTH_ERROR_NONE) {
+ BT_DBG("service_function [%d]", cb_data->service_function);
+ if (result == BLUETOOTH_ERROR_NONE && out_param1) {
if (cb_data->service_function == BT_OPP_PUSH_FILES) {
request_id = g_array_index(out_param1, int, 0);
+ BT_DBG("request_id : %d", request_id);
+ _bt_add_push_request_id(request_id);
+ } else if (cb_data->service_function == BT_MAP_LIST_FOLDERS) {
+ request_id = g_array_index(out_param1, int, 0);
+ BT_DBG("request_id : %d", request_id);
+ _bt_add_push_request_id(request_id);
+ } else if (cb_data->service_function == BT_MAP_LIST_FILTER_FIELDS) {
+ request_id = g_array_index(out_param1, int, 0);
+ BT_DBG("request_id : %d", request_id);
+ _bt_add_push_request_id(request_id);
+ } else if (cb_data->service_function == BT_MAP_LIST_MESSAGES) {
+ request_id = g_array_index(out_param1, int, 0);
+ BT_DBG("request_id : %d", request_id);
+ _bt_add_push_request_id(request_id);
+ } else if (cb_data->service_function == BT_MAP_GET_MESSAGE) {
+ request_id = g_array_index(out_param1, int, 0);
+ BT_DBG("request_id : %d", request_id);
+ _bt_add_push_request_id(request_id);
+ } else if (cb_data->service_function == BT_MAP_PUSH_MESSAGE) {
+ request_id = g_array_index(out_param1, int, 0);
+ BT_DBG("request_id : %d", request_id);
_bt_add_push_request_id(request_id);
}
- if (out_param1)
- g_array_free(out_param1, FALSE);
-
- if (out_param2)
- g_array_free(out_param2, FALSE);
-
goto done;
}
-
- if (out_param1)
- g_array_free(out_param1, FALSE);
-
- if (out_param2)
- g_array_free(out_param2, FALSE);
}
if (cb_data->cb == NULL)
/* Only if fail case, call the callback function*/
bt_event.result = result;
+ BT_INFO("event_type[%d], result= %s [0x%x]", event_type,
+ _bt_convert_error_to_string(result), result);
if (event_type == BT_ADAPTER_EVENT || event_type == BT_RFCOMM_CLIENT_EVENT) {
((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
(bt_audio_event_param_t *)&bt_event,
cb_data->user_data);
+ } else if (event_type == BT_HF_AGENT_EVENT) {
+ ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
+ (bt_audio_event_param_t *)&bt_event,
+ cb_data->user_data);
+ } else if (event_type == BT_AVRCP_CONTROL_EVENT) {
+ ((media_cb_func_ptr)cb_data->cb)(bt_event.event,
+ (media_event_param_t *)&bt_event,
+ cb_data->user_data);
+ } else if (event_type == BT_A2DP_SOURCE_EVENT) {
+ ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
+ (bt_audio_event_param_t *)&bt_event,
+ cb_data->user_data);
+ } else if (event_type == BT_DEVICE_EVENT) {
+ ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
+ &bt_event,
+ cb_data->user_data);
+ } else if (event_type == BT_TDS_EVENT) {
+ ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
+ &bt_event,
+ cb_data->user_data);
+ } else if (event_type == BT_HDP_EVENT) {
+ ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
+ &bt_event, cb_data->user_data);
+ } else if (event_type == BT_AVRCP_EVENT) {
+ ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
+ &bt_event, cb_data->user_data);
+ } else if (event_type == BT_GATT_CLIENT_EVENT) {
+ ((gatt_client_cb_func_ptr)cb_data->cb)(bt_event.event,
+ (gatt_client_event_param_t*)&bt_event, cb_data->user_data);
+ } else if (event_type == BT_MESH_EVENT) {
+ ((mesh_cb_func_ptr)cb_data->cb)(bt_event.event,
+ (mesh_event_param_t*)&bt_event, cb_data->user_data);
+ } else {
+ BT_INFO("Not handled event type : %d", event_type);
}
done:
+ if (out_param1)
+ g_array_free(out_param1, TRUE);
+
sending_requests = g_slist_remove(sending_requests, (void *)cb_data);
g_free(cb_data);
+ BT_DBG("-");
}
-int _bt_send_request(int service_type, int service_function,
+int _bt_sync_send_request(int service_type, int service_function,
GArray *in_param1, GArray *in_param2,
GArray *in_param3, GArray *in_param4,
GArray **out_param1)
{
int result = BLUETOOTH_ERROR_NONE;
- char *cookie;
- gboolean ret;
GError *error = NULL;
GArray *in_param5 = NULL;
- GArray *out_param2 = NULL;
- DBusGProxy *proxy;
+// GArray *out_param2 = NULL;
+
+ GDBusProxy *proxy;
+ GVariant *ret;
+ GVariant *param1;
+ GVariant *param2;
+ GVariant *param3;
+ GVariant *param4;
+ GVariant *param5;
switch (service_type) {
case BT_BLUEZ_SERVICE:
case BT_OBEX_SERVICE:
- proxy = __bt_get_service_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+ case BT_AGENT_SERVICE:
+ case BT_CHECK_PRIVILEGE:
+ proxy = __bt_gdbus_get_service_proxy();
+ if (!proxy)
+ return BLUETOOTH_ERROR_INTERNAL;
- in_param5 = g_array_new(FALSE, FALSE, sizeof(gchar));
+ in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
+
+
+
+ param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param1->data, in_param1->len,
+ TRUE, NULL, NULL);
+ param2 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param2->data, in_param2->len,
+ TRUE, NULL, NULL);
+ param3 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param3->data, in_param3->len,
+ TRUE, NULL, NULL);
+ param4 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param4->data, in_param4->len,
+ TRUE, NULL, NULL);
+ param5 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param5->data, in_param5->len,
+ TRUE, NULL, NULL);
+
+ ret = g_dbus_proxy_call_sync(proxy, "service_request",
+ g_variant_new("(iii@ay@ay@ay@ay@ay)",
+ service_type, service_function,
+ BT_SYNC_REQ, param1,
+ param2, param3,
+ param4, param5),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &error);
- cookie = _bt_get_cookie();
+ g_array_free(in_param5, TRUE);
- if (cookie) {
- g_array_append_vals(in_param5, cookie,
- _bt_get_cookie_size());
- }
+ if (ret == NULL) {
+ /* dBUS-RPC is failed */
+ BT_ERR("dBUS-RPC is failed");
- ret = org_projectx_bt_service_request(proxy,
- service_type, service_function,
- BT_SYNC_REQ, in_param1, in_param2,
- in_param3, in_param4, in_param5,
- out_param1, &out_param2, &error);
+ if (error != NULL) {
+ /* dBUS gives error cause */
+ BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
+ error->code, error->message);
- g_array_free(in_param5, TRUE);
- break;
- default:
- BT_ERR("Unknown service type");
- return BLUETOOTH_ERROR_INTERNAL;
- }
+ g_clear_error(&error);
+ } else {
+ /* dBUS does not give error cause dBUS-RPC is failed */
+ BT_ERR("error returned was NULL");
+ }
- if (out_param2) {
- result = g_array_index(out_param2, int, 0);
- g_array_free(out_param2, TRUE);
- } else {
- result = BLUETOOTH_ERROR_INTERNAL;
- }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
- if (ret != TRUE) {
- /* dBUS-RPC is failed */
- BT_ERR("dBUS-RPC is failed");
+ param1 = NULL;
+// param2 = NULL;
- if (error != NULL) {
- /* dBUS gives error cause */
- BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
- error->code, error->message);
+ g_variant_get(ret, "(iv)", &result, ¶m1);
- g_error_free(error);
- }
- else {
- /* dBUS does not give error cause dBUS-RPC is failed */
- BT_ERR("error returned was NULL");
+ if (param1) {
+ *out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
+ __bt_fill_garray_from_variant(param1, *out_param1);
+ g_variant_unref(param1);
}
- return result;
+// if (param2) {
+// out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
+// __bt_fill_garray_from_variant(param2, out_param2);
+// result = g_array_index(out_param2, int, 0);
+// g_variant_unref(param2);
+// g_array_free(out_param2, TRUE);
+// } else {
+// result = BLUETOOTH_ERROR_INTERNAL;
+// }
+
+ g_variant_unref(ret);
+ break;
+ default:
+ BT_ERR("Unknown service type");
+ return BLUETOOTH_ERROR_INTERNAL;
}
- BT_DBG("dBUS RPC is successfully done. type=%d, function=0x%x",
- service_type, service_function);
-
return result;
}
-int _bt_send_request_async(int service_type, int service_function,
+int _bt_async_send_request(int service_type, int service_function,
GArray *in_param1, GArray *in_param2,
GArray *in_param3, GArray *in_param4,
void *callback, void *user_data)
{
GArray* in_param5 = NULL;
bt_req_info_t *cb_data;
- DBusGProxy *proxy;
- DBusGProxyCall *proxy_call;
+
+ GDBusProxy *proxy;
+ int timeout;
+ GVariant *param1;
+ GVariant *param2;
+ GVariant *param3;
+ GVariant *param4;
+ GVariant *param5;
+
+ BT_DBG("service_function : %s (0x%x)",
+ _bt_convert_service_function_to_string(service_function),
+ service_function);
cb_data = g_new0(bt_req_info_t, 1);
switch (service_type) {
case BT_BLUEZ_SERVICE:
case BT_OBEX_SERVICE:
- proxy = __bt_get_service_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+ proxy = __bt_gdbus_get_service_proxy();
+ if (!proxy) {
+ g_free(cb_data);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ /* Do not timeout the request in certain cases. Sometime the
+ * request may take undeterministic time to reponse.
+ * (for ex: pairing retry) */
+ if (service_function == BT_BOND_DEVICE ||
+ service_function == BT_BOND_DEVICE_BY_TYPE)
+ timeout = INT_MAX;
+ else
+ timeout = BT_DBUS_TIMEOUT_MAX;
+
+ in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
+
+ param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param1->data, in_param1->len,
+ TRUE, NULL, NULL);
+ param2 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param2->data, in_param2->len,
+ TRUE, NULL, NULL);
+ param3 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param3->data, in_param3->len,
+ TRUE, NULL, NULL);
+ param4 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param4->data, in_param4->len,
+ TRUE, NULL, NULL);
+ param5 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param5->data, in_param5->len,
+ TRUE, NULL, NULL);
+
+ g_dbus_proxy_call(proxy, "service_request",
+ g_variant_new("(iii@ay@ay@ay@ay@ay)",
+ service_type, service_function,
+ BT_ASYNC_REQ, param1, param2,
+ param3, param4, param5),
+ G_DBUS_CALL_FLAGS_NONE,
+ timeout, NULL,
+ (GAsyncReadyCallback)__send_request_cb,
+ (gpointer)cb_data);
+ sending_requests = g_slist_append(sending_requests, cb_data);
+
+ g_array_free(in_param5, TRUE);
+ break;
+ default:
+ g_free(cb_data);
+ break;
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
- dbus_g_proxy_set_default_timeout(proxy, BT_DBUS_TIMEOUT_MAX);
+int _bt_async_send_request_with_unix_fd_list(int service_type, int service_function,
+ GArray *in_param1, GArray *in_param2,
+ GArray *in_param3, GArray *in_param4,
+ void *callback, void *user_data,
+ GUnixFDList *fd_list, GAsyncReadyCallback __async_req_cb)
+{
+ GArray* in_param5 = NULL;
+ bt_req_info_t *cb_data;
- in_param5 = g_array_new(FALSE, FALSE, sizeof(gchar));
+ GDBusProxy *proxy;
+ int timeout;
+ GVariant *param1;
+ GVariant *param2;
+ GVariant *param3;
+ GVariant *param4;
+ GVariant *param5;
- proxy_call = org_projectx_bt_service_request_async(proxy, service_type,
- service_function, BT_ASYNC_REQ, in_param1, in_param2,
- in_param3, in_param4, in_param5,
- (org_projectx_bt_service_request_reply)__send_request_cb,
- (gpointer)cb_data);
+ BT_DBG("service_function : %d", service_function);
- if (proxy_call == NULL) {
+ cb_data = g_new0(bt_req_info_t, 1);
+ cb_data->service_function = service_function;
+ cb_data->cb = callback;
+ cb_data->user_data = user_data;
- BT_ERR("dBUS-RPC is failed");
- g_array_free(in_param5, TRUE);
+ switch (service_type) {
+ case BT_BLUEZ_SERVICE:
+ case BT_OBEX_SERVICE:
+ proxy = __bt_gdbus_get_service_proxy();
+ if (!proxy) {
g_free(cb_data);
return BLUETOOTH_ERROR_INTERNAL;
}
+ /* Do not timeout the request in certain cases. Sometime the
+ * request may take undeterministic time to reponse.
+ * (for ex: pairing retry) */
+ if (service_function == BT_BOND_DEVICE ||
+ service_function == BT_BOND_DEVICE_BY_TYPE)
+ timeout = INT_MAX;
+ else
+ timeout = BT_DBUS_TIMEOUT_MAX;
+
+ in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
+
+ param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param1->data, in_param1->len,
+ TRUE, NULL, NULL);
+ param2 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param2->data, in_param2->len,
+ TRUE, NULL, NULL);
+ param3 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param3->data, in_param3->len,
+ TRUE, NULL, NULL);
+ param4 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param4->data, in_param4->len,
+ TRUE, NULL, NULL);
+ param5 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param5->data, in_param5->len,
+ TRUE, NULL, NULL);
+
+ g_dbus_proxy_call_with_unix_fd_list(proxy, "service_request",
+ g_variant_new("(iii@ay@ay@ay@ay@ay)",
+ service_type, service_function,
+ BT_ASYNC_REQ, param1, param2,
+ param3, param4, param5),
+ G_DBUS_CALL_FLAGS_NONE,
+ timeout, fd_list, NULL,
+ __async_req_cb, (gpointer)cb_data);
sending_requests = g_slist_append(sending_requests, cb_data);
g_array_free(in_param5, TRUE);
break;
+ default:
+ g_free(cb_data);
+ break;
}
- BT_DBG("dBUS RPC is successfully done. type=%d, function=0x%x",
- service_type, service_function);
-
return BLUETOOTH_ERROR_NONE;
}
+int _bt_sync_send_request_with_unix_fd_list(
+ int service_type, int service_function,
+ GArray *in_param1, GArray *in_param2,
+ GArray *in_param3, GArray *in_param4,
+ GUnixFDList *fd_list, GArray **out_param1,
+ GUnixFDList **out_fd_list)
+{
+ int result = BLUETOOTH_ERROR_NONE;
+ GError *error = NULL;
+ GArray *in_param5 = NULL;
+
+ GDBusProxy *proxy;
+ GVariant *ret;
+ GVariant *param1;
+ GVariant *param2;
+ GVariant *param3;
+ GVariant *param4;
+ GVariant *param5;
+
+ switch (service_type) {
+ case BT_BLUEZ_SERVICE:
+ case BT_OBEX_SERVICE:
+ case BT_AGENT_SERVICE:
+ case BT_CHECK_PRIVILEGE:
+ proxy = __bt_gdbus_get_service_proxy();
+ if (!proxy)
+ return BLUETOOTH_ERROR_INTERNAL;
+
+ in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
+
+ param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param1->data, in_param1->len,
+ TRUE, NULL, NULL);
+ param2 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param2->data, in_param2->len,
+ TRUE, NULL, NULL);
+ param3 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param3->data, in_param3->len,
+ TRUE, NULL, NULL);
+ param4 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param4->data, in_param4->len,
+ TRUE, NULL, NULL);
+ param5 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param5->data, in_param5->len,
+ TRUE, NULL, NULL);
+
+ ret = g_dbus_proxy_call_with_unix_fd_list_sync(proxy, "service_request",
+ g_variant_new("(iii@ay@ay@ay@ay@ay)",
+ service_type, service_function,
+ BT_SYNC_REQ, param1, param2,
+ param3, param4, param5),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ fd_list, out_fd_list, NULL, &error);
+ g_array_free(in_param5, TRUE);
+
+ if (ret == NULL) {
+ /* dBUS-RPC is failed */
+ BT_ERR("dBUS-RPC is failed");
+
+ if (error != NULL) {
+ /* dBUS gives error cause */
+ BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
+ error->code, error->message);
+
+ g_clear_error(&error);
+ } else {
+ /* dBUS does not give error cause dBUS-RPC is failed */
+ BT_ERR("error returned was NULL");
+ }
+
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ param1 = NULL;
+ g_variant_get(ret, "(iv)", &result, ¶m1);
+
+ if (param1) {
+ *out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
+ __bt_fill_garray_from_variant(param1, *out_param1);
+ g_variant_unref(param1);
+ }
+
+ g_variant_unref(ret);
+ break;
+ default:
+ BT_ERR("Unknown service type");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ return result;
+}