/*
- * 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 <string.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus.h>
#include <glib.h>
#include <dlog.h>
#include <vconf.h>
#include "bluetooth-api.h"
#include "bluetooth-audio-api.h"
+#include "bluetooth-hid-api.h"
#include "bt-internal-types.h"
+#include "bluetooth-media-control.h"
#include "bt-common.h"
#include "bt-event-handler.h"
+#include "bt-gatt-client.h"
#include "bt-request-sender.h"
+#define PROFILE_SUPPORTED 0x3 /* This corresponds to binary 0b11*/
+#define BT_RELIABLE_DISABLE_TIME 300 /* 300 ms */
+
typedef struct {
int server_fd;
} bt_server_info_t;
} bt_sending_info_t;
static int obex_server_id;
+static guint disable_timer_id;
static gboolean is_initialized;
static GSList *sending_list = NULL;
static GSList *server_list = NULL;
static GSList *event_list = NULL;
+static int owner_sig_id = -1;
void _bt_add_push_request_id(int request_id)
{
if (info == NULL)
continue;
- retv_if(info->request_id == request_id, TRUE);
+ BT_DBG("compare %d with %d", info->request_id, request_id);
+ if (info->request_id == request_id)
+ return TRUE;
}
return FALSE;
if (info == NULL)
continue;
+ BT_DBG("info->request_id = %d\n", info->request_id);
+ BT_DBG("request_id = %d\n", request_id);
if (info->request_id == request_id) {
sending_list = g_slist_remove(sending_list, (void *)info);
g_free(info);
dev_info->service_index = uuid_count;
- for (i = 0; uuids[i] != NULL && i < uuid_count; i++) {
+ for (i = 0; i < uuid_count && uuids[i] != NULL; i++) {
g_strlcpy(dev_info->uuids[i], uuids[i], BLUETOOTH_UUID_STRING_MAX);
parts = g_strsplit(uuids[i], "-", -1);
g_strfreev(parts);
}
}
+static int __bt_call_list_create(bt_hf_call_list_s **list)
+{
+ bt_hf_call_list_s *handle;
+
+ if (*list != NULL) {
+ BT_DBG("Already Initialized");
+ return BLUETOOTH_ERROR_NONE;
+ }
+ handle = g_malloc0(sizeof(bt_hf_call_list_s));
+ *list = handle;
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static int __bt_call_list_reset(bt_hf_call_list_s *list)
+{
+ bt_hf_call_list_s *handle;
+ bt_hf_call_status_info_t *call_status;
+
+ if (list == NULL) {
+ BT_ERR("invalid parameter");
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+ }
+ handle = (bt_hf_call_list_s *)list;
+ do {
+ call_status = (bt_hf_call_status_info_t *)g_list_nth_data(handle->list, 0);
+ if (call_status == NULL)
+ break;
+ handle->list = g_list_remove(handle->list, call_status);
+ g_free(call_status->number);
+ g_free(call_status);
+ } while (1);
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static int __bt_call_list_destroy(bt_hf_call_list_s *list)
+{
+ int result;
+ bt_hf_call_list_s *handle;
+
+ if (list == NULL) {
+ BT_ERR("invalid parameter");
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+ }
+ handle = (bt_hf_call_list_s *)list;
+ result = __bt_call_list_reset(list);
+ g_free(handle);
+ return result;
+}
+static int __bt_call_list_add(bt_hf_call_list_s *list, char * number,
+ int dir, int status, int mpart, int idx)
+{
+ bt_hf_call_list_s *handle;
+ bt_hf_call_status_info_t *call_status;
+
+ if (list == NULL) {
+ BT_ERR("invalid parameter");
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+ }
+ handle = (bt_hf_call_list_s *)list;
+ call_status = g_malloc0(sizeof(bt_hf_call_status_info_t));
+ call_status->number = g_strdup(number);
+ call_status->direction = dir;
+ call_status->status = status;
+ call_status->mpart = mpart;
+ call_status->idx = idx;
+ handle->list = g_list_append(handle->list, (gpointer)call_status);
+ return BLUETOOTH_ERROR_NONE;
+}
-static bluetooth_device_info_t *__bt_get_device_info_in_message(DBusMessage *msg, int *ret)
+static bluetooth_device_info_t *__bt_get_device_info_in_message(GVariant *parameters, int *ret)
{
bluetooth_device_info_t *dev_info;
- char *address = NULL;
- char *name = NULL;
- char **uuids = NULL;
- unsigned int class = 0;
- int rssi = 0;
+ const char *address = NULL;
+ const char *name = NULL;
+ gchar **uuids = NULL;
+ unsigned int dev_class = 0;
+ short rssi = 0;
gboolean paired = FALSE;
- gboolean connected = FALSE;
+ guint connected = 0;
gboolean trust = FALSE;
- int uuid_count = 0;
+ gsize uuid_count;
int result = BLUETOOTH_ERROR_NONE;
-
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_UINT32, &class,
- DBUS_TYPE_INT16, &rssi,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_BOOLEAN, &paired,
- DBUS_TYPE_BOOLEAN, &connected,
- DBUS_TYPE_BOOLEAN, &trust,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &uuids, &uuid_count,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
+ GVariant *string_var;
+ int i = 0, len = 0;
+ int manufacturer_data_len = 0;
+ GVariant *manufacturer_var = NULL;
+ const char *manufacturer_data = NULL;
+
+ g_variant_get(parameters, "(isunsbub@asn@ay)", &result, &address,
+ &dev_class, &rssi, &name, &paired,
+ &connected, &trust, &string_var, &manufacturer_data_len, &manufacturer_var);
+
+ if (string_var == NULL) {
+ BT_ERR("invalid parameters in signal");
return NULL;
}
- dev_info = g_malloc0(sizeof(bluetooth_device_info_t));
+ uuids = (gchar **)g_variant_get_strv(string_var, &uuid_count);
+ len = g_variant_get_size(manufacturer_var);
+ if (len > 0)
+ manufacturer_data = (char *)g_variant_get_data(manufacturer_var);
+
+ dev_info = g_malloc0(sizeof(bluetooth_device_info_t));
dev_info->rssi = rssi;
dev_info->paired = paired;
dev_info->connected = connected;
- dev_info->paired = paired;
dev_info->trust = trust;
- g_strlcpy(dev_info->device_name.name, name, BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
+ g_strlcpy(dev_info->device_name.name, name,
+ BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
- _bt_divide_device_class(&dev_info->device_class, class);
+ _bt_divide_device_class(&dev_info->device_class, dev_class);
_bt_convert_addr_string_to_type(dev_info->device_address.addr,
address);
if (uuid_count > 0)
__bt_get_uuid_info(dev_info, uuids, uuid_count);
+ if (manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
+ BT_ERR("manufacturer_data_len is too long(len = %d)", manufacturer_data_len);
+ manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
+ }
+ dev_info->manufacturer_data.data_len = manufacturer_data_len;
+ if (manufacturer_data)
+ for (i = 0; i < manufacturer_data_len; i++)
+ dev_info->manufacturer_data.data[i] = manufacturer_data[i];
*ret = result;
-
+ g_free(uuids);
+ g_variant_unref(string_var);
+ g_variant_unref(manufacturer_var);
return dev_info;
}
-static DBusHandlerResult __bt_adapter_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static bluetooth_le_device_info_t *__bt_get_le_device_info_in_message(GVariant *parameters, int *ret)
{
- bt_event_info_t *event_info;
+ bluetooth_le_device_info_t *le_dev_info;
+ const char *address = NULL;
+ int i;
+ short addr_type = 0;
+ short rssi = 0;
+ int len = 0;
+ int adv_data_len = 0;
+ GVariant *adv_var = NULL;
+ const char *adv_data = NULL;
+ int scan_data_len = 0;
+ GVariant *scan_var = NULL;
+ const char *scan_data = NULL;
int result = BLUETOOTH_ERROR_NONE;
- const char *member = dbus_message_get_member(msg);
- event_info = (bt_event_info_t *)data;
- retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ g_variant_get(parameters, "(i&snnn@ayn@ay)", &result, &address,
+ &addr_type, &rssi, &adv_data_len, &adv_var, &scan_data_len, &scan_var);
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ len = g_variant_get_size(adv_var);
+ if (len > 0)
+ adv_data = (char *)g_variant_get_data(adv_var);
- if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ len = g_variant_get_size(scan_var);
+ if (len > 0)
+ scan_data = (char *)g_variant_get_data(scan_var);
- if (!dbus_message_has_path(msg, BT_ADAPTER_PATH))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ le_dev_info = g_malloc0(sizeof(bluetooth_le_device_info_t));
+ _bt_convert_addr_string_to_type(le_dev_info->device_address.addr, address);
+ le_dev_info->addr_type = addr_type;
+ le_dev_info->rssi = rssi;
+ le_dev_info->adv_ind_data.data_len = adv_data_len;
+ for (i = 0; i < adv_data_len; i++)
+ if (adv_data)
+ le_dev_info->adv_ind_data.data.data[i] = adv_data[i];
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ le_dev_info->scan_resp_data.data_len = scan_data_len;
- if (strcasecmp(member, BT_ENABLED) == 0) {
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ for (i = 0; i < scan_data_len; i++)
+ if (scan_data)
+ le_dev_info->scan_resp_data.data.data[i] = scan_data[i];
- if (result == BLUETOOTH_ERROR_NONE) {
- if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
- BT_ERR("Set vconf failed\n");
- }
+ *ret = result;
+ g_variant_unref(adv_var);
+ g_variant_unref(scan_var);
+ return le_dev_info;
+}
- _bt_common_event_cb(BLUETOOTH_EVENT_ENABLED,
- result, NULL,
- event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_DISABLED) == 0) {
+gboolean __bt_reliable_disable_cb(gpointer user_data)
+{
+ BT_DBG("+");
+ bt_event_info_t *event_info = user_data;
+
+ _bt_set_le_scan_status(FALSE);
+
+ _bt_set_adapter_internal_status(FALSE);
+
+ if (is_initialized != FALSE) {
_bt_common_event_cb(BLUETOOTH_EVENT_DISABLED,
BLUETOOTH_ERROR_NONE, NULL,
event_info->cb, event_info->user_data);
+ }
- obex_server_id = BT_NO_SERVER;
- __bt_remove_all_server();
- __bt_remove_all_push_request_id();
- } else if (strcasecmp(member, BT_DISCOVERABLE_MODE_CHANGED) == 0) {
- int mode = 0;
+ obex_server_id = BT_NO_SERVER;
+ __bt_remove_all_server();
+ __bt_remove_all_push_request_id();
+#ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
+ _bt_rfcomm_server_free_all();
+#endif
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INT16, &mode,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ _bluetooth_hid_free_hid_info();
+
+ BT_DBG("-");
+ return FALSE;
+}
+
+void __bt_adapter_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ bt_event_info_t *event_info;
+ int result = BLUETOOTH_ERROR_NONE;
+
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
+
+ if (strcasecmp(object_path, BT_ADAPTER_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
+
+ if (strcasecmp(signal_name, BT_ENABLED) == 0) {
+ BT_INFO("BT_ENABLED");
+ g_variant_get(parameters, "(i)", &result);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_ENABLED,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_DISABLED) == 0) {
+ BT_INFO("BT_DISABLED");
+
+ /* Wait for the termining time of bt-service */
+ if (disable_timer_id > 0)
+ g_source_remove(disable_timer_id);
+
+ disable_timer_id = g_timeout_add(BT_RELIABLE_DISABLE_TIME,
+ (GSourceFunc)__bt_reliable_disable_cb,
+ event_info);
+ } else if (strcasecmp(signal_name, BT_DISCOVERABLE_MODE_CHANGED) == 0) {
+ int mode = 0;
+ g_variant_get(parameters, "(in)", &result, &mode);
_bt_common_event_cb(BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
result, &mode,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_DISCOVERABLE_TIMEOUT_CHANGED) == 0) {
+ } else if (strcasecmp(signal_name, BT_DISCOVERABLE_TIMEOUT_CHANGED) == 0) {
int timeout = 0;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INT16, &timeout,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
+ g_variant_get(parameters, "(in)", &result, &timeout);
_bt_common_event_cb(BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED,
result, &timeout,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_ADAPTER_NAME_CHANGED) == 0) {
- char *adapter_name = NULL;
+ } else if (strcasecmp(signal_name, BT_CONNECTABLE_CHANGED) == 0) {
+ gboolean connectable = FALSE;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &adapter_name,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(b)", &connectable);
+ BT_DBG("Connectable is changed : %d", connectable);
+ _bt_common_event_cb(BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
+ result, &connectable,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_ADAPTER_NAME_CHANGED) == 0) {
+ char *adapter_name = NULL;
+
+ g_variant_get(parameters, "(i&s)", &result, &adapter_name);
_bt_common_event_cb(BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
result, adapter_name,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_DISCOVERY_STARTED) == 0) {
+ } else if (strcasecmp(signal_name, BT_DISCOVERY_STARTED) == 0) {
_bt_common_event_cb(BLUETOOTH_EVENT_DISCOVERY_STARTED,
BLUETOOTH_ERROR_NONE, NULL,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_DISCOVERY_FINISHED) == 0) {
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
+ } else if (strcasecmp(signal_name, BT_DISCOVERY_FINISHED) == 0) {
+ g_variant_get(parameters, "(i)", &result);
_bt_common_event_cb(BLUETOOTH_EVENT_DISCOVERY_FINISHED,
result, NULL,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_DEVICE_FOUND) == 0) {
- int event;
- bluetooth_device_info_t *device_info;
+ } else if (strcasecmp(signal_name, BT_ADVERTISING_STARTED) == 0) {
+ int adv_handle;
- device_info = __bt_get_device_info_in_message(msg, &result);
- retv_if(device_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ g_variant_get(parameters, "(ii)", &result, &adv_handle);
+ _bt_common_event_cb(BLUETOOTH_EVENT_ADVERTISING_STARTED,
+ result, &adv_handle,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_ADVERTISING_STOPPED) == 0) {
+ int adv_handle;
- if (strlen(device_info->device_name.name) > 0) {
- event = BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED;
- } else {
- event = BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND;
- }
+ g_variant_get(parameters, "(ii)", &result, &adv_handle);
+ _bt_common_event_cb(BLUETOOTH_EVENT_ADVERTISING_STOPPED,
+ result, &adv_handle,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_ADVERTISING_MANUFACTURER_DATA_CHANGED) == 0) {
+ GVariant *var = NULL;
+ char *data;
+ int len;
- _bt_common_event_cb(event,
- result, device_info,
+ g_variant_get(parameters, "(@ay)", &var);
+ len = g_variant_get_size(var);
+ data = (char *)g_variant_get_data(var);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_ADVERTISING_MANUFACTURER_DATA_CHANGED,
+ len, data,
event_info->cb, event_info->user_data);
- g_free(device_info);
- } else if (strcasecmp(member, BT_DEVICE_DISAPPEARED) == 0) {
+ g_variant_unref(var);
+ } else if (strcasecmp(signal_name, BT_SCAN_RESPONSE_MANUFACTURER_DATA_CHANGED) == 0) {
+ GVariant *var = NULL;
+ char *data;
+ int len;
+
+ g_variant_get(parameters, "(@ay)", &var);
+ len = g_variant_get_size(var);
+ data = (char *)g_variant_get_data(var);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_SCAN_RESPONSE_MANUFACTURER_DATA_CHANGED,
+ len, data,
+ event_info->cb, event_info->user_data);
+
+ g_variant_unref(var);
+ } else if (strcasecmp(signal_name, BT_MANUFACTURER_DATA_CHANGED) == 0) {
+ GVariant *var = NULL;
+ char *data;
+ int len;
+
+ g_variant_get(parameters, "(@ay)", &var);
+ len = g_variant_get_size(var);
+ data = (char *)g_variant_get_data(var);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED,
+ len, data,
+ event_info->cb, event_info->user_data);
+
+ g_variant_unref(var);
+ } else if (strcasecmp(signal_name, BT_PASSKEY_NOTIFICATION) == 0) {
+ const char *address = NULL;
+ const char *passkey = NULL;
+ const char *passkey_info[2];
+
+ g_variant_get(parameters, "(&s&s)", &address, &passkey);
+ passkey_info[0] = address;
+ passkey_info[1] = passkey;
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_PASSKEY_NOTIFICATION,
+ BLUETOOTH_ERROR_NONE, (void*)passkey_info,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_DEVICE_FOUND) == 0) {
+ int event;
bluetooth_device_info_t *device_info;
- device_info = __bt_get_device_info_in_message(msg, &result);
- retv_if(device_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ device_info = __bt_get_device_info_in_message(parameters,
+ &result);
+ ret_if(device_info == NULL);
+ if (strlen(device_info->device_name.name) > 0)
+ event = BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED;
+ else
+ event = BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND;
- _bt_common_event_cb(BLUETOOTH_EVENT_REMOTE_DEVICE_DISAPPEARED,
+ _bt_common_event_cb(event,
result, device_info,
event_info->cb, event_info->user_data);
+
g_free(device_info);
- } else if (strcasecmp(member, BT_BOND_CREATED) == 0) {
+ } else if (strcasecmp(signal_name, BT_BOND_CREATED) == 0) {
bluetooth_device_info_t *device_info;
- device_info = __bt_get_device_info_in_message(msg, &result);
+ device_info = __bt_get_device_info_in_message(parameters,
+ &result);
+ ret_if(device_info == NULL);
_bt_common_event_cb(BLUETOOTH_EVENT_BONDING_FINISHED,
result, device_info,
event_info->cb, event_info->user_data);
g_free(device_info);
- } else if (strcasecmp(member, BT_BOND_DESTROYED) == 0) {
- char *address = NULL;
+ } else if (strcasecmp(signal_name, BT_BOND_DESTROYED) == 0) {
+ const char *address = NULL;
bluetooth_device_address_t dev_address = { {0} };
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s)", &result, &address);
_bt_convert_addr_string_to_type(dev_address.addr,
address);
_bt_common_event_cb(BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
result, &dev_address,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_SERVICE_SEARCHED) == 0) {
+ } else if (strcasecmp(signal_name, BT_SERVICE_SEARCHED) == 0) {
bluetooth_device_info_t *device_info;
bt_sdp_info_t sdp_info;
- device_info = __bt_get_device_info_in_message(msg, &result);
+ device_info = __bt_get_device_info_in_message(parameters,
+ &result);
+ ret_if(device_info == NULL);
memset(&sdp_info, 0x00, sizeof(bt_sdp_info_t));
event_info->cb, event_info->user_data);
g_free(device_info);
+ } else if (strcasecmp(signal_name, BT_IPSP_INITIALIZED) == 0) {
+ gboolean ipsp_intialized = FALSE;
+ g_variant_get(parameters, "(b)", &ipsp_intialized);
+
+ BT_DBG("IPSP init state changed to : %d", ipsp_intialized);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
+ BLUETOOTH_ERROR_NONE, &ipsp_intialized,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_KBD_PASSKEY_DISPLAY_REQ_RECEIVED) == 0) {
+ const char *address = NULL;
+ const char *name = NULL;
+ const char *str_passkey = NULL;
+
+ bluetooth_authentication_request_info_t auth_info;
+ memset(&auth_info, 0x00, sizeof(bluetooth_authentication_request_info_t));
+
+ g_variant_get(parameters, "(i&s&s&s)", &result, &address, &name, &str_passkey);
+
+ g_strlcpy(auth_info.device_name.name, name,
+ BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
+ _bt_convert_addr_string_to_type(auth_info.device_address.addr,
+ address);
+ g_strlcpy(auth_info.str_passkey, str_passkey, strlen(str_passkey)+1);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY,
+ result, &auth_info,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_PIN_REQ_RECEIVED) == 0) {
+ const char *address = NULL;
+ const char *name = NULL;
+
+ bluetooth_authentication_request_info_t auth_info;
+ memset(&auth_info, 0x00, sizeof(bluetooth_authentication_request_info_t));
+
+ g_variant_get(parameters, "(i&s&s)", &result, &address, &name);
+
+ g_strlcpy(auth_info.device_name.name, name,
+ BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
+ _bt_convert_addr_string_to_type(auth_info.device_address.addr,
+ address);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_PIN_REQUEST,
+ result, &auth_info,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_PASSKEY_REQ_RECEIVED) == 0) {
+ const char *address = NULL;
+ const char *name = NULL;
+
+ bluetooth_authentication_request_info_t auth_info;
+ memset(&auth_info, 0x00, sizeof(bluetooth_authentication_request_info_t));
+
+ g_variant_get(parameters, "(i&s&s)", &result, &address, &name);
+
+ g_strlcpy(auth_info.device_name.name, name,
+ BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
+ _bt_convert_addr_string_to_type(auth_info.device_address.addr,
+ address);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_PASSKEY_REQUEST,
+ result, &auth_info,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_PASSKEY_CFM_REQ_RECEIVED) == 0) {
+ const char *address = NULL;
+ const char *name = NULL;
+ const char *str_passkey = NULL;
+
+ bluetooth_authentication_request_info_t auth_info;
+ memset(&auth_info, 0x00, sizeof(bluetooth_authentication_request_info_t));
+
+ g_variant_get(parameters, "(i&s&s&s)", &result, &address, &name, &str_passkey);
+
+ g_strlcpy(auth_info.device_name.name, name,
+ BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
+ _bt_convert_addr_string_to_type(auth_info.device_address.addr,
+ address);
+ g_strlcpy(auth_info.str_passkey, str_passkey, strlen(str_passkey)+1);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST,
+ result, &auth_info,
+ event_info->cb, event_info->user_data);
}
+}
+
+void __bt_adapter_le_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ bt_event_info_t *event_info;
+ int result = BLUETOOTH_ERROR_NONE;
+
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (strcasecmp(object_path, BT_LE_ADAPTER_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
+
+ if (strcasecmp(signal_name, BT_LE_ENABLED) == 0) {
+ BT_INFO("BT_LE_ENABLED");
+ g_variant_get(parameters, "(i)", &result);
+ _bt_common_event_cb(BLUETOOTH_EVENT_LE_ENABLED,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_LE_DISABLED) == 0) {
+ BT_INFO("BT_LE_DISABLED");
+ _bt_common_event_cb(BLUETOOTH_EVENT_LE_DISABLED,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_LE_DISCOVERY_STARTED) == 0) {
+ _bt_common_event_cb(BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
+ BLUETOOTH_ERROR_NONE, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_LE_DISCOVERY_FINISHED) == 0) {
+ g_variant_get(parameters, "(i)", &result);
+ _bt_common_event_cb(BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_LE_DEVICE_FOUND) == 0) {
+ bluetooth_le_device_info_t *le_device_info;
+
+ le_device_info = __bt_get_le_device_info_in_message(parameters,
+ &result);
+ ret_if(le_device_info == NULL);
+
+ if (bluetooth_is_le_scanning() == TRUE) {
+ _bt_common_event_cb(BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND,
+ result, le_device_info,
+ event_info->cb, event_info->user_data);
+ }
+
+ g_free(le_device_info);
+ }
}
-static DBusHandlerResult __bt_device_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+void __bt_device_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
bt_event_info_t *event_info;
int result = BLUETOOTH_ERROR_NONE;
- const char *member = dbus_message_get_member(msg);
- event_info = (bt_event_info_t *)data;
- retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
+
+ gboolean gatt_interface = FALSE;
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (strcasecmp(interface_name, BT_GATT_CHARACTERISTIC_INTERFACE) == 0)
+ gatt_interface = TRUE;
- if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (strcasecmp(object_path, BT_DEVICE_PATH) != 0 &&
+ gatt_interface == FALSE)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0 &&
+ gatt_interface == FALSE)
+ return;
- if (!dbus_message_has_path(msg, BT_DEVICE_PATH))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ ret_if(signal_name == NULL);
+ if (strcasecmp(signal_name, BT_GATT_CONNECTED) == 0) {
+ const char *address = NULL;
+ bluetooth_device_address_t dev_address = { {0} };
+ BT_DBG("BT_GATT_CONNECTED");
+ g_variant_get(parameters, "(i&s)", &result, &address);
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ _bt_convert_addr_string_to_type(dev_address.addr, address);
+ _bt_common_event_cb(BLUETOOTH_EVENT_GATT_CONNECTED,
+ result, &dev_address,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_GATT_DISCONNECTED) == 0) {
+ const char *address = NULL;
+ bluetooth_device_address_t dev_address = { {0} };
+ BT_DBG("BT_GATT_DISCONNECTED");
+ g_variant_get(parameters, "(i&s)", &result, &address);
- if (strcasecmp(member, BT_DEVICE_CONNECTED) == 0) {
- char *address = NULL;
+ _bt_convert_addr_string_to_type(dev_address.addr, address);
+ _bt_common_event_cb(BLUETOOTH_EVENT_GATT_DISCONNECTED,
+ result, &dev_address,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_GATT_REQ_ATT_MTU_CHANGED) == 0) {
+ const char *address = NULL;
bluetooth_device_address_t dev_address = { {0} };
+ bluetooth_le_att_mtu_info_t att_mtu_info;
+ guint16 mtu;
+ guint8 status;
+ BT_DBG("BT_GATT_REQ_ATT_MTU_CHANGED");
+ g_variant_get(parameters, "(i&sqy)", &result, &address, &mtu, &status);
+
+ _bt_convert_addr_string_to_type(dev_address.addr, address);
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_DBG("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ memset(&att_mtu_info, 0x00, sizeof(bluetooth_le_att_mtu_info_t));
+ memcpy(att_mtu_info.device_address.addr,
+ dev_address.addr,
+ BLUETOOTH_ADDRESS_LENGTH);
+
+ att_mtu_info.mtu = mtu;
+ att_mtu_info.status = status;
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
+ result, &att_mtu_info,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_GATT_BLUEZ_CHAR_VAL_CHANGED) == 0) {
+ const char *char_handle = NULL;
+ int len = 0;
+ const char * value = NULL;
+ GVariant *char_value_var = NULL;
+ bt_gatt_char_value_t char_val = { 0, };
+
+ g_variant_get(parameters, "(i&s@ay)", &result, &char_handle, &char_value_var);
+
+ len = g_variant_get_size(char_value_var);
+ ret_if(char_value_var == NULL);
+
+ if (len > 0)
+ value = (char *)g_variant_get_data(char_value_var);
+
+ char_val.char_handle = g_strdup(char_handle);
+ char_val.val_len = len;
+ /* Fix : FORWARD_NULL : g_variant_get_data can return NULL */
+ if (char_val.val_len > 0 && value != NULL) {
+ char_val.char_value = (unsigned char*) g_malloc0(char_val.val_len);
+ memcpy(char_val.char_value, value, len);
+ _bt_common_event_cb(BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
+ result, &char_val,
+ event_info->cb, event_info->user_data);
+ g_free(char_val.char_value);
+ g_variant_unref(char_value_var);
}
+ g_free(char_val.char_handle);
+ } else if (strcasecmp(signal_name, BT_DEVICE_CONNECTED) == 0) {
+ const char *address = NULL;
+ unsigned char addr_type;
+ bt_connection_info_t conn_info;
+ bluetooth_device_address_t dev_address = { {0} };
+ BT_DBG("BT_DEVICE_CONNECTED");
+ g_variant_get(parameters, "(i&sy)", &result, &address, &addr_type);
_bt_convert_addr_string_to_type(dev_address.addr,
address);
+ memset(&conn_info, 0x00, sizeof(bt_connection_info_t));
+
+ memcpy(conn_info.device_addr.addr,
+ dev_address.addr,
+ BLUETOOTH_ADDRESS_LENGTH);
+
+ conn_info.addr_type = addr_type;
+ conn_info.disc_reason = 0;
_bt_common_event_cb(BLUETOOTH_EVENT_DEVICE_CONNECTED,
+ result, &conn_info,
+ event_info->cb, event_info->user_data);
+
+ } else if (strcasecmp(signal_name, BT_DEVICE_DISCONNECTED) == 0) {
+ const char *address = NULL;
+ unsigned char addr_type;
+ bt_connection_info_t conn_info;
+ bluetooth_device_address_t dev_address = { {0} };
+ BT_DBG("BT_DEVICE_DISCONNECTED");
+ g_variant_get(parameters, "(i&sy)", &result, &address, &addr_type);
+
+ _bt_convert_addr_string_to_type(dev_address.addr,
+ address);
+
+ memset(&conn_info, 0x00, sizeof(bt_connection_info_t));
+
+ memcpy(conn_info.device_addr.addr,
+ dev_address.addr,
+ BLUETOOTH_ADDRESS_LENGTH);
+
+ conn_info.addr_type = addr_type;
+ conn_info.disc_reason = result;
+ _bt_common_event_cb(BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
+ result, &conn_info,
+ event_info->cb, event_info->user_data);
+
+ } else if (strcasecmp(signal_name, BT_RSSI_MONITORING_ENABLED) == 0) {
+ bt_rssi_enabled_t enabled = { 0, };
+ char *address;
+ int link_type;
+ gboolean rssi_enabled = FALSE;
+
+ g_variant_get(parameters, "(isib)", &result, &address,
+ &link_type, &rssi_enabled);
+
+ BT_DBG("RSSI Enabled[Address:%s LinkType:%d RSSI_dbm:%d]",
+ address, link_type, rssi_enabled);
+ enabled.address = address;
+ enabled.link_type = link_type;
+ enabled.rssi_enabled = rssi_enabled;
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_RSSI_ENABLED,
+ result, &enabled,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_RSSI_ALERT) == 0) {
+ int alert_type;
+ int rssi_dbm;
+ char *address;
+ int link_type;
+ bt_rssi_alert_t alert = { 0, };
+
+ g_variant_get(parameters, "(isiii)", &result, &address,
+ &link_type, &alert_type, &rssi_dbm);
+
+ alert.alert_type = alert_type;
+ alert.rssi_dbm = rssi_dbm;
+ alert.address = address;
+ alert.link_type = link_type;
+ BT_DBG("Address [%s] LinkType[%d] AlertType[%d] RSSI dBm[%d]",
+ address, link_type, alert_type, rssi_dbm);
+ _bt_common_event_cb(BLUETOOTH_EVENT_RSSI_ALERT,
+ result, &alert,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_RAW_RSSI_EVENT) == 0) {
+ int rssi_dbm;
+ int link_type;
+ char *address;
+ bt_raw_rssi_t raw_rssi = { 0, };
+
+ g_variant_get(parameters, "(isii)", &result,
+ &address, &link_type, &rssi_dbm);
+
+ BT_DBG("Address [%s] Link Type[%d] dBm[%d]",
+ address, link_type, rssi_dbm);
+
+ raw_rssi.rssi_dbm = rssi_dbm;
+ raw_rssi.address = address;
+ raw_rssi.link_type = link_type;
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_RAW_RSSI,
+ result, &raw_rssi,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_DEVICE_AUTHORIZED) == 0) {
+ const char *address = NULL;
+ bluetooth_device_address_t dev_address = { {0} };
+
+ g_variant_get(parameters, "(i&s)", &result, &address);
+
+ _bt_convert_addr_string_to_type(dev_address.addr,
+ address);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_DEVICE_AUTHORIZED,
result, &dev_address,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_DEVICE_DISCONNECTED) == 0) {
- char *address = NULL;
+ } else if (strcasecmp(signal_name, BT_DEVICE_UNAUTHORIZED) == 0) {
+ const char *address = NULL;
bluetooth_device_address_t dev_address = { {0} };
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_DBG("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s)", &result, &address);
_bt_convert_addr_string_to_type(dev_address.addr,
address);
- _bt_common_event_cb(BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
+ _bt_common_event_cb(BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED,
result, &dev_address,
event_info->cb, event_info->user_data);
- }
+ } else if (strcasecmp(signal_name, BT_SUPPORTED_PROFILE_TRUSTED) == 0) {
+ char *address;
+ bt_supported_profile_trusted_t profile_info = { 0, };
+ int trust;
+
+ g_variant_get(parameters, "(i&si)", &result,
+ &address, &trust);
+
+ BT_DBG("Address [%s] trust[%d]", address, trust);
+ profile_info.address = address;
+ if (trust & (PROFILE_SUPPORTED << 0)) { /* Bit 0 & 1 - for PBAP Supported */
+ profile_info.profile = TRUSTED_PROFILE_PBAP;
+ profile_info.supported = TRUE;
+ if (trust & (1 << 1)) /* Bit 1 - for PBAP Trusted */
+ profile_info.trusted = TRUE;
+ else
+ profile_info.trusted = FALSE;
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
+ result, &profile_info,
+ event_info->cb, event_info->user_data);
+ }
+ if (trust & (PROFILE_SUPPORTED << 2)) { /* Bit 2 & 3 - for MAP Supported */
+ profile_info.profile = TRUSTED_PROFILE_MAP;
+ profile_info.supported = TRUE;
+ if (trust & (1 << 3)) /* Bit 3 - for PBAP Trusted */
+ profile_info.trusted = TRUE;
+ else
+ profile_info.trusted = FALSE;
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
+ result, &profile_info,
+ event_info->cb, event_info->user_data);
+ }
+ if (trust & (PROFILE_SUPPORTED << 4)) { /* Bit 4 & 5- for SAP Supported */
+ profile_info.profile = TRUSTED_PROFILE_SAP;
+ profile_info.supported = TRUE;
+ if (trust & (1 << 5)) /* Bit 5 - for SAP Trusted */
+ profile_info.trusted = TRUE;
+ else
+ profile_info.trusted = FALSE;
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
+ result, &profile_info,
+ event_info->cb, event_info->user_data);
+ }
+ } else if (strcasecmp(signal_name, BT_IPSP_CONNECTED) == 0) {
+ const char *address = NULL;
+ const char *if_name = NULL;
+ bt_ipsp_connection_info_t bt_ipsp_iface_info;
+ memset(&bt_ipsp_iface_info, 0, sizeof(bt_ipsp_iface_info));
+
+ BT_DBG("BT_IPSP_CONNECTED");
+ g_variant_get(parameters, "(i&s&s)", &result, &address, &if_name);
+
+ _bt_convert_addr_string_to_type(bt_ipsp_iface_info.btaddr.addr, address);
+ memcpy(bt_ipsp_iface_info.if_name, if_name, 16);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_IPSP_CONNECTED,
+ result, &bt_ipsp_iface_info,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_IPSP_DISCONNECTED) == 0) {
+ const char *address = NULL;
+ const char *if_name = NULL;
+ bt_ipsp_connection_info_t bt_ipsp_iface_info;
+ memset(&bt_ipsp_iface_info, 0, sizeof(bt_ipsp_iface_info));
+
+ BT_DBG("BT_IPSP_DISCONNECTED");
+ g_variant_get(parameters, "(i&s&s)", &result, &address, &if_name);
+
+ _bt_convert_addr_string_to_type(bt_ipsp_iface_info.btaddr.addr, address);
+ memcpy(bt_ipsp_iface_info.if_name, if_name, 16);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_IPSP_DISCONNECTED,
+ result, &bt_ipsp_iface_info,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_LE_DATA_LENGTH_CHANGED) == 0) {
+ const char *address = NULL;
+ bluetooth_device_address_t dev_address = { {0} };
+ uint tx_octets = 0;
+ uint tx_time = 0;
+ uint rx_octets = 0;
+ uint rx_time = 0;
+ bt_le_data_length_params_t params;
+
+ BT_DBG("BT_LE_DATA_LENGTH_CHANGED");
+
+ g_variant_get(parameters, "(i&sqqqq)", &result, &address,
+ &tx_octets, &tx_time, &rx_octets, &rx_time);
+
+ params.max_tx_octets = tx_octets;
+ params.max_tx_time = tx_time;
+ params.max_rx_octets = rx_octets;
+ params.max_rx_time = rx_time;
+
+ _bt_convert_addr_string_to_type(dev_address.addr, address);
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ memcpy(¶ms.device_address,
+ &dev_address, BLUETOOTH_ADDRESS_LENGTH);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED,
+ result, ¶ms, event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_PXP_PROPERTY_CHANGED) == 0) {
+ const char *address = NULL;
+ bluetooth_device_address_t dev_address = { {0} };
+ int role, type, level;
+ bt_pxp_property_changed_params_t params;
+
+ BT_DBG("BT_PXP_PROPERTY_CHANGED");
+
+ g_variant_get(parameters, "(isiii)", &result, &address, &role, &type, &level);
+
+ _bt_convert_addr_string_to_type(dev_address.addr, address);
+ memcpy(¶ms.device_address, &dev_address, BLUETOOTH_ADDRESS_LENGTH);
+ params.role = role;
+ params.service_type = type;
+ params.alert_lvl = level;
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
+ result, ¶ms, event_info->cb, event_info->user_data);
+ }
}
-static DBusHandlerResult __bt_hid_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+void __bt_hid_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
bt_event_info_t *event_info;
int result = BLUETOOTH_ERROR_NONE;
- const char *member = dbus_message_get_member(msg);
-
- event_info = (bt_event_info_t *)data;
- retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
- if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (strcasecmp(object_path, BT_HID_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
- if (!dbus_message_has_path(msg, BT_HID_PATH))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ ret_if(signal_name == NULL);
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- if (strcasecmp(member, BT_INPUT_CONNECTED) == 0) {
- char *address = NULL;
+ if (strcasecmp(signal_name, BT_INPUT_CONNECTED) == 0) {
+ const char *address = NULL;
bluetooth_device_address_t dev_address = { {0} };
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_DBG("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s)", &result, &address);
_bt_convert_addr_string_to_type(dev_address.addr,
address);
_bt_input_event_cb(BLUETOOTH_HID_CONNECTED,
result, &dev_address,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_INPUT_DISCONNECTED) == 0) {
- char *address = NULL;
+ } else if (strcasecmp(signal_name, BT_INPUT_DISCONNECTED) == 0) {
+ const char *address = NULL;
bluetooth_device_address_t dev_address = { {0} };
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_DBG("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s)", &result, &address);
BT_DBG("address: %s", address);
result, &dev_address,
event_info->cb, event_info->user_data);
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static DBusHandlerResult __bt_headset_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+void __bt_headset_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
bt_event_info_t *event_info;
int result = BLUETOOTH_ERROR_NONE;
- const char *member = dbus_message_get_member(msg);
-
- event_info = (bt_event_info_t *)data;
- retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
- if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (strcasecmp(object_path, BT_HEADSET_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
- if (!dbus_message_has_path(msg, BT_HEADSET_PATH))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ ret_if(signal_name == NULL);
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- if (strcasecmp(member, BT_HEADSET_CONNECTED) == 0) {
+ if (strcasecmp(signal_name, BT_HEADSET_CONNECTED) == 0) {
char *address = NULL;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s)", &result, &address);
_bt_headset_event_cb(BLUETOOTH_EVENT_AG_CONNECTED,
result, address,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_HEADSET_DISCONNECTED) == 0) {
+ } else if (strcasecmp(signal_name, BT_HEADSET_DISCONNECTED) == 0) {
char *address = NULL;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s)", &result, &address);
_bt_headset_event_cb(BLUETOOTH_EVENT_AG_DISCONNECTED,
result, address,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_STEREO_HEADSET_CONNECTED) == 0) {
+ } else if (strcasecmp(signal_name, BT_STEREO_HEADSET_CONNECTED) == 0) {
char *address = NULL;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s)", &result, &address);
_bt_headset_event_cb(BLUETOOTH_EVENT_AV_CONNECTED,
result, address,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_STEREO_HEADSET_DISCONNECTED) == 0) {
+ } else if (strcasecmp(signal_name, BT_STEREO_HEADSET_DISCONNECTED) == 0) {
char *address = NULL;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s)", &result, &address);
_bt_headset_event_cb(BLUETOOTH_EVENT_AV_DISCONNECTED,
result, address,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_SCO_CONNECTED) == 0) {
+ } else if (strcasecmp(signal_name, BT_A2DP_SOURCE_CONNECTED) == 0) {
char *address = NULL;
- bluetooth_device_address_t dev_address = { {0} };
-
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
- _bt_convert_addr_string_to_type(dev_address.addr,
- address);
-
- _bt_headset_event_cb(BLUETOOTH_EVENT_AG_AUDIO_CONNECTED,
- result, &dev_address,
- event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_SCO_DISCONNECTED) == 0) {
+ g_variant_get(parameters, "(i&s)", &result, &address);
+ _bt_a2dp_source_event_cb(BLUETOOTH_EVENT_AV_SOURCE_CONNECTED,
+ result, address,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_A2DP_SOURCE_DISCONNECTED) == 0) {
char *address = NULL;
- bluetooth_device_address_t dev_address = { {0} };
-
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
- _bt_convert_addr_string_to_type(dev_address.addr,
- address);
+ g_variant_get(parameters, "(i&s)", &result, &address);
- _bt_headset_event_cb(BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED,
- result, &dev_address,
- event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_SPEAKER_GAIN) == 0) {
+ _bt_a2dp_source_event_cb(BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED,
+ result, address,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_SPEAKER_GAIN) == 0) {
unsigned int gain;
guint16 spkr_gain;
char *address = NULL;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_UINT16, &spkr_gain,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&sq)", &result, &address,
+ &spkr_gain);
gain = (unsigned int)spkr_gain;
_bt_headset_event_cb(BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
result, &gain,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_MICROPHONE_GAIN) == 0) {
+ } else if (strcasecmp(signal_name, BT_MICROPHONE_GAIN) == 0) {
unsigned int gain;
guint16 mic_gain;
char *address = NULL;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_UINT16, &mic_gain,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&sq)", &result,
+ &address, &mic_gain);
gain = (unsigned int)mic_gain;
_bt_headset_event_cb(BLUETOOTH_EVENT_AG_MIC_GAIN,
result, &gain,
event_info->cb, event_info->user_data);
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static DBusHandlerResult __bt_network_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+void __bt_hid_device_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
bt_event_info_t *event_info;
int result = BLUETOOTH_ERROR_NONE;
- const char *member = dbus_message_get_member(msg);
-
- event_info = (bt_event_info_t *)data;
- retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
+ if (strcasecmp(object_path, BT_HID_DEVICE_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
- if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ ret_if(signal_name == NULL);
- if (!dbus_message_has_path(msg, BT_NETWORK_PATH))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- if (strcasecmp(member, BT_NETWORK_CONNECTED) == 0) {
- char *address = NULL;
+ if (strcasecmp(signal_name, BT_HID_DEVICE_CONNECTED) == 0) {
+ const char *address = NULL;
bluetooth_device_address_t dev_address = { {0} };
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s)", &result, &address);
_bt_convert_addr_string_to_type(dev_address.addr,
address);
- _bt_common_event_cb(BLUETOOTH_EVENT_NETWORK_CONNECTED,
+ _bt_input_event_cb(BLUETOOTH_HID_DEVICE_CONNECTED,
result, &dev_address,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_NETWORK_DISCONNECTED) == 0) {
- char *address = NULL;
+ } else if (strcasecmp(signal_name, BT_HID_DEVICE_DISCONNECTED) == 0) {
+ const char *address = NULL;
bluetooth_device_address_t dev_address = { {0} };
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s)", &result, &address);
+
+ BT_DBG("address: %s", address);
_bt_convert_addr_string_to_type(dev_address.addr,
address);
- _bt_common_event_cb(BLUETOOTH_EVENT_NETWORK_DISCONNECTED,
+ _bt_input_event_cb(BLUETOOTH_HID_DEVICE_DISCONNECTED,
result, &dev_address,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_NETWORK_SERVER_CONNECTED) == 0) {
- char *device = NULL;
- char *address = NULL;
- bluetooth_network_device_info_t network_info;
-
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &device,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ } else if (strcasecmp(signal_name, BT_INPUT_HID_DEVICE_CONNECTED) == 0) {
+ BT_INFO_C("Type %s", g_variant_get_type_string(parameters));
+ const char *address = NULL;
+ bluetooth_device_address_t dev_address = { {0} };
- memset(&network_info, 0x00, sizeof(bluetooth_network_device_info_t));
+ g_variant_get(parameters, "(i&s)", &result, &address);
- _bt_convert_addr_string_to_type(network_info.device_address.addr,
+ BT_DBG("address: %s", address);
+ _bt_convert_addr_string_to_type(dev_address.addr,
address);
+ int ctrl = -1, intr = -1;
+ _bt_hid_device_get_fd(address, &ctrl, &intr);
+ if (ctrl != -1 && intr != -1) {
+ new_hid_connection(NULL, ctrl, &dev_address);
+ new_hid_connection(NULL, intr, &dev_address);
+ }
+ } else if (strcasecmp(signal_name, BT_INPUT_HID_DEVICE_DISCONNECTED) == 0) {
+ const char *address = NULL;
+ g_variant_get(parameters, "(i&s)", &result, &address);
- _bt_print_device_address_t(&network_info.device_address);
- g_strlcpy(network_info.interface_name, device, BLUETOOTH_INTERFACE_NAME_LENGTH);
-
- BT_DBG("name: %s", network_info.interface_name);
-
- _bt_common_event_cb(BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
+ BT_DBG("address: %s", address);
+ }
+}
+void __bt_a2dp_source_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ bt_event_info_t *event_info;
+ int result = BLUETOOTH_ERROR_NONE;
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
+
+ if (strcasecmp(object_path, BT_A2DP_SOURCE_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
+
+ ret_if(signal_name == NULL);
+
+ if (strcasecmp(signal_name, BT_A2DP_SOURCE_CONNECTED) == 0) {
+ char *address = NULL;
+
+ g_variant_get(parameters, "(i&s)", &result, &address);
+ _bt_a2dp_source_event_cb(BLUETOOTH_EVENT_AV_SOURCE_CONNECTED,
+ result, address,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_A2DP_SOURCE_DISCONNECTED) == 0) {
+ char *address = NULL;
+
+ g_variant_get(parameters, "(i&s)", &result, &address);
+
+ _bt_a2dp_source_event_cb(BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED,
+ result, address,
+ event_info->cb, event_info->user_data);
+ }
+}
+
+void __bt_network_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ bt_event_info_t *event_info;
+ int result = BLUETOOTH_ERROR_NONE;
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
+
+ if (strcasecmp(object_path, BT_NETWORK_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
+
+ ret_if(signal_name == NULL);
+
+ if (strcasecmp(signal_name, BT_NETWORK_CONNECTED) == 0) {
+ const char *address = NULL;
+ bluetooth_device_address_t dev_address = { {0} };
+
+ g_variant_get(parameters, "(i&s)", &result, &address);
+
+ _bt_convert_addr_string_to_type(dev_address.addr,
+ address);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_NETWORK_CONNECTED,
+ result, &dev_address,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_NETWORK_DISCONNECTED) == 0) {
+ const char *address = NULL;
+ bluetooth_device_address_t dev_address = { {0} };
+
+ g_variant_get(parameters, "(i&s)", &result, &address);
+
+ _bt_convert_addr_string_to_type(dev_address.addr,
+ address);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_NETWORK_DISCONNECTED,
+ result, &dev_address,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_NETWORK_SERVER_CONNECTED) == 0) {
+ const char *device = NULL;
+ const char *address = NULL;
+ bluetooth_network_device_info_t network_info;
+
+ g_variant_get(parameters, "(i&s&s)", &result,
+ &device, &address);
+
+ memset(&network_info, 0x00, sizeof(bluetooth_network_device_info_t));
+
+ _bt_convert_addr_string_to_type(network_info.device_address.addr,
+ address);
+
+ _bt_print_device_address_t(&network_info.device_address);
+ g_strlcpy(network_info.interface_name, device,
+ sizeof(network_info.interface_name));
+
+ DBG_SECURE("Interface: %s", network_info.interface_name);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
result, &network_info,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_NETWORK_SERVER_DISCONNECTED) == 0) {
- char *device = NULL;
- char *address = NULL;
+ } else if (strcasecmp(signal_name, BT_NETWORK_SERVER_DISCONNECTED) == 0) {
+ const char *device = NULL;
+ const char *address = NULL;
bluetooth_network_device_info_t network_info;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &device,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s&s)", &result, &device, &address);
memset(&network_info, 0x00, sizeof(bluetooth_network_device_info_t));
result, &network_info,
event_info->cb, event_info->user_data);
}
-
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static DBusHandlerResult __bt_avrcp_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+void __bt_avrcp_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
bt_event_info_t *event_info;
int result = BLUETOOTH_ERROR_NONE;
- const char *member = dbus_message_get_member(msg);
-
- event_info = (bt_event_info_t *)data;
- retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
- if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (strcasecmp(object_path, BT_AVRCP_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
- if (!dbus_message_has_path(msg, BT_AVRCP_PATH))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ ret_if(signal_name == NULL);
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- if (strcasecmp(member, BT_STEREO_HEADSET_CONNECTED) == 0) {
+ if (strcasecmp(signal_name, BT_AVRCP_CONNECTED) == 0) {
char *address = NULL;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s)", &result, &address);
_bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_CONNECTED,
result, address,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_STEREO_HEADSET_DISCONNECTED) == 0) {
+ } else if (strcasecmp(signal_name, BT_AVRCP_DISCONNECTED) == 0) {
char *address = NULL;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s)", &result, &address);
_bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_DISCONNECTED,
result, address,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_MEDIA_SHUFFLE_STATUS) == 0) {
+ } else if (strcasecmp(signal_name, BT_MEDIA_SHUFFLE_STATUS) == 0) {
unsigned int status;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_UINT32, &status,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+
+ g_variant_get(parameters, "(u)", &status);
_bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_SETTING_SHUFFLE_STATUS,
result, &status,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_MEDIA_EQUALIZER_STATUS) == 0) {
+ } else if (strcasecmp(signal_name, BT_MEDIA_EQUALIZER_STATUS) == 0) {
unsigned int status;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_UINT32, &status,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+
+ g_variant_get(parameters, "(u)", &status);
_bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_SETTING_EQUALIZER_STATUS,
result, &status,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_MEDIA_REPEAT_STATUS) == 0) {
+ } else if (strcasecmp(signal_name, BT_MEDIA_REPEAT_STATUS) == 0) {
unsigned int status;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_UINT32, &status,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+
+ g_variant_get(parameters, "(u)", &status);
_bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_SETTING_REPEAT_STATUS,
result, &status,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_MEDIA_SCAN_STATUS) == 0) {
+ } else if (strcasecmp(signal_name, BT_MEDIA_SCAN_STATUS) == 0) {
unsigned int status;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_UINT32, &status,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+
+ g_variant_get(parameters, "(u)", &status);
_bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_SETTING_SCAN_STATUS,
result, &status,
event_info->cb, event_info->user_data);
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static DBusHandlerResult __bt_opp_client_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+void __bt_avrcp_control_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
bt_event_info_t *event_info;
int result = BLUETOOTH_ERROR_NONE;
- const char *member = dbus_message_get_member(msg);
-
- event_info = (bt_event_info_t *)data;
- retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (strcasecmp(object_path, BT_AVRCP_CONTROL_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
- if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ ret_if(signal_name == NULL);
- if (!dbus_message_has_path(msg, BT_OPP_CLIENT_PATH))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (strcasecmp(signal_name, BT_AVRCP_CONNECTED) == 0) {
+ char *address = NULL;
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ g_variant_get(parameters, "(i&s)", &result, &address);
- if (strcasecmp(member, BT_OPP_CONNECTED) == 0) {
+ _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED,
+ result, address,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_AVRCP_DISCONNECTED) == 0) {
char *address = NULL;
+
+ g_variant_get(parameters, "(i&s)", &result, &address);
+
+ _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED,
+ result, address,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_MEDIA_SHUFFLE_STATUS) == 0) {
+ unsigned int status;
+
+ g_variant_get(parameters, "(u)", &status);
+ _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS,
+ result, &status,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_MEDIA_EQUALIZER_STATUS) == 0) {
+ unsigned int status;
+
+ g_variant_get(parameters, "(u)", &status);
+ _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS,
+ result, &status,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_MEDIA_REPEAT_STATUS) == 0) {
+ unsigned int status;
+
+ g_variant_get(parameters, "(u)", &status);
+ _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS,
+ result, &status,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_MEDIA_SCAN_STATUS) == 0) {
+ unsigned int status;
+
+ g_variant_get(parameters, "(u)", &status);
+ _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS,
+ result, &status,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_MEDIA_PLAY_STATUS) == 0) {
+ unsigned int status;
+
+ g_variant_get(parameters, "(u)", &status);
+ _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED,
+ result, &status,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_MEDIA_POSITION_STATUS) == 0) {
+ unsigned int status;
+
+ g_variant_get(parameters, "(u)", &status);
+ _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS,
+ result, &status,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_MEDIA_TRACK_CHANGE) == 0) {
+ media_metadata_attributes_t metadata;
+ const char *title;
+ const char *artist;
+ const char *album;
+ const char *genre;
+ unsigned int total_tracks;
+ unsigned int number;
+ unsigned int duration;
+
+ g_variant_get(parameters, "(&s&s&s&suuu)", &title,
+ &artist, &album, &genre,
+ &total_tracks, &number,
+ &duration);
+ memset(&metadata, 0x00, sizeof(media_metadata_attributes_t));
+
+ metadata.title = title;
+ metadata.artist = artist;
+ metadata.album = album;
+ metadata.genre = genre;
+ metadata.total_tracks = total_tracks;
+ metadata.number = number;
+ metadata.duration = duration;
+
+ _bt_avrcp_event_cb(BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED,
+ result, &metadata,
+ event_info->cb, event_info->user_data);
+ }
+}
+
+void __bt_opp_client_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ bt_event_info_t *event_info;
+ int result = BLUETOOTH_ERROR_NONE;
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
+
+ if (strcasecmp(object_path, BT_OPP_CLIENT_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
+
+ ret_if(signal_name == NULL);
+
+ if (strcasecmp(signal_name, BT_OPP_CONNECTED) == 0) {
+ const char *address = NULL;
int request_id = 0;
bluetooth_device_address_t dev_address = { {0} };
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INT32, &request_id,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&si)", &result,
+ &address, &request_id);
if (__bt_is_request_id_exist(request_id) == FALSE) {
BT_ERR("Different request id!");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ return;
}
_bt_convert_addr_string_to_type(dev_address.addr,
result, &dev_address,
event_info->cb, event_info->user_data);
- if (result != BLUETOOTH_ERROR_NONE) {
+ if (result != BLUETOOTH_ERROR_NONE)
__bt_remove_push_request_id(request_id);
- }
- } else if (strcasecmp(member, BT_OPP_DISCONNECTED) == 0) {
- char *address = NULL;
+
+ } else if (strcasecmp(signal_name, BT_OPP_DISCONNECTED) == 0) {
+ const char *address = NULL;
int request_id = 0;
bluetooth_device_address_t dev_address = { {0} };
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INT32, &request_id,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&si)", &result, &address,
+ &request_id);
if (__bt_is_request_id_exist(request_id) == FALSE) {
BT_ERR("Different request id!");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ return;
}
_bt_convert_addr_string_to_type(dev_address.addr,
event_info->cb, event_info->user_data);
__bt_remove_push_request_id(request_id);
- } else if (strcasecmp(member, BT_TRANSFER_STARTED) == 0) {
- char *file_name = NULL;
+ } else if (strcasecmp(signal_name, BT_TRANSFER_STARTED) == 0) {
+ const char *file_name = NULL;
+ const char *device_addr = NULL;
int request_id = 0;
guint64 size = 0;
bt_opc_transfer_info_t transfer_info;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &file_name,
- DBUS_TYPE_UINT64, &size,
- DBUS_TYPE_INT32, &request_id,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s&sti)", &result, &device_addr, &file_name,
+ &size, &request_id);
if (__bt_is_request_id_exist(request_id) == FALSE) {
BT_ERR("Different request id!");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ return;
}
memset(&transfer_info, 0x00, sizeof(bt_opc_transfer_info_t));
transfer_info.filename = g_strdup(file_name);
+ transfer_info.device_addr = g_strdup(device_addr);
transfer_info.size = size;
_bt_common_event_cb(BLUETOOTH_EVENT_OPC_TRANSFER_STARTED,
result, &transfer_info,
event_info->cb, event_info->user_data);
+ g_free(transfer_info.device_addr);
g_free(transfer_info.filename);
- } else if (strcasecmp(member, BT_TRANSFER_PROGRESS) == 0) {
- char *file_name = NULL;
+ } else if (strcasecmp(signal_name, BT_TRANSFER_PROGRESS) == 0) {
+ const char *file_name = NULL;
int request_id = 0;
guint64 size = 0;
int progress = 0;
bt_opc_transfer_info_t transfer_info;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &file_name,
- DBUS_TYPE_UINT64, &size,
- DBUS_TYPE_INT32, &progress,
- DBUS_TYPE_INT32, &request_id,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&stii)", &result,
+ &file_name, &size, &progress, &request_id);
if (__bt_is_request_id_exist(request_id) == FALSE) {
BT_ERR("Different request id!");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ return;
}
memset(&transfer_info, 0x00, sizeof(bt_opc_transfer_info_t));
event_info->cb, event_info->user_data);
g_free(transfer_info.filename);
- } else if (strcasecmp(member, BT_TRANSFER_COMPLETED) == 0) {
- char *file_name = NULL;
+ } else if (strcasecmp(signal_name, BT_TRANSFER_COMPLETED) == 0) {
+ const char *file_name = NULL;
+ const char *device_addr = NULL;
int request_id = 0;
guint64 size = 0;
bt_opc_transfer_info_t transfer_info;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &file_name,
- DBUS_TYPE_UINT64, &size,
- DBUS_TYPE_INT32, &request_id,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s&sti)", &result, &device_addr,
+ &file_name, &size, &request_id);
if (__bt_is_request_id_exist(request_id) == FALSE) {
BT_ERR("Different request id!");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ return;
}
memset(&transfer_info, 0x00, sizeof(bt_opc_transfer_info_t));
+ transfer_info.device_addr = g_strdup(device_addr);
transfer_info.filename = g_strdup(file_name);
transfer_info.size = size;
result, &transfer_info,
event_info->cb, event_info->user_data);
+ g_free(transfer_info.device_addr);
g_free(transfer_info.filename);
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static DBusHandlerResult __bt_opp_server_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+void __bt_opp_server_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
bt_event_info_t *event_info;
int result = BLUETOOTH_ERROR_NONE;
- const char *member = dbus_message_get_member(msg);
-
- event_info = (bt_event_info_t *)data;
- retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
- if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (strcasecmp(object_path, BT_OPP_SERVER_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
- if (!dbus_message_has_path(msg, BT_OPP_SERVER_PATH))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ ret_if(signal_name == NULL);
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- if (strcasecmp(member, BT_TRANSFER_AUTHORIZED) == 0) {
+ if (strcasecmp(signal_name, BT_TRANSFER_AUTHORIZED) == 0) {
/* Native only event */
- char *file_name = NULL;
+ const char *file_name = NULL;
+ const char *address = NULL;
+ const char *device_name = NULL;
guint64 size = 0;
bt_obex_server_authorize_into_t auth_info;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &file_name,
- DBUS_TYPE_UINT64, &size,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&st&s&s)", &result, &file_name, &size,
+ &address, &device_name);
/* OSP server: Don't get this event */
- retv_if(obex_server_id == BT_CUSTOM_SERVER,
- DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ ret_if(obex_server_id == BT_CUSTOM_SERVER);
memset(&auth_info, 0x00, sizeof(bt_obex_server_authorize_into_t));
auth_info.filename = g_strdup(file_name);
auth_info.length = size;
-
+ auth_info.address = g_strdup(address);
+ auth_info.name = g_strdup(device_name);
_bt_common_event_cb(BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE,
result, &auth_info,
event_info->cb, event_info->user_data);
g_free(auth_info.filename);
- } else if (strcasecmp(member, BT_CONNECTION_AUTHORIZED) == 0) {
+ g_free(auth_info.address);
+ g_free(auth_info.name);
+ } else if (strcasecmp(signal_name, BT_CONNECTION_AUTHORIZED) == 0) {
/* OSP only event */
- char *address = NULL;
- char *name = NULL;
+ const char *address = NULL;
+ const char *name = NULL;
bluetooth_device_address_t dev_address = { {0} };
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s&s)", &result, &address, &name);
/* Native server: Don't get this event */
- retv_if(obex_server_id == BT_NATIVE_SERVER,
- DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ ret_if(obex_server_id == BT_NATIVE_SERVER);
_bt_convert_addr_string_to_type(dev_address.addr,
address);
_bt_common_event_cb(BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
result, &dev_address,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_TRANSFER_STARTED) == 0) {
- char *file_name = NULL;
- char *type = NULL;
+ } else if (strcasecmp(signal_name, BT_TRANSFER_CONNECTED) == 0) {
+ bt_obex_server_connection_info_t conn_info = {0, };
+ char *address = NULL;
+ char *name = NULL;
+ int transfer_id = -1;
+ g_variant_get(parameters, "(i&s&si)", &result,
+ &address, &name, &transfer_id);
+
+ conn_info.address = g_strdup(address);
+ conn_info.device_name = g_strdup(name);
+ conn_info.transfer_id = transfer_id;
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_CONNECTED,
+ result, &conn_info, event_info->cb,
+ event_info->user_data);
+
+ g_free(conn_info.address);
+ g_free(conn_info.device_name);
+ } else if (strcasecmp(signal_name, BT_TRANSFER_DISCONNECTED) == 0) {
+ bt_obex_server_transfer_info_t transfer_info = {0, };
+ char *address = NULL;
+ int transfer_id = -1;
+ g_variant_get(parameters, "(i&si)", &result, &address, &transfer_id);
+ DBG_SECURE("address: %s, transfer_id: %d", address, transfer_id);
+
+ transfer_info.address = g_strdup(address);
+ transfer_info.transfer_id = transfer_id;
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_DISCONNECTED,
+ result, &transfer_info, event_info->cb,
+ event_info->user_data);
+ g_free(transfer_info.address);
+ } else if (strcasecmp(signal_name, BT_TRANSFER_STARTED) == 0) {
+ const char *device_name = NULL;
+ const char *file_name = NULL;
+ const char *type = NULL;
+ const char *address = NULL;
+ GVariantIter *iter = NULL;
+ int i = 0;
+ guchar byte;
int transfer_id = 0;
int server_type = 0; /* bt_server_type_t */
guint64 size = 0;
bt_obex_server_transfer_info_t transfer_info;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &file_name,
- DBUS_TYPE_STRING, &type,
- DBUS_TYPE_UINT64, &size,
- DBUS_TYPE_INT32, &transfer_id,
- DBUS_TYPE_INT32, &server_type,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s&s&s&stii(ay))", &result, &device_name,
+ &file_name, &type, &address, &size, &transfer_id, &server_type, &iter);
/* Other server's event */
- retv_if(obex_server_id != server_type &&
- server_type != BT_FTP_SERVER,
- DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ ret_if(obex_server_id != server_type &&
+ server_type != BT_FTP_SERVER);
memset(&transfer_info, 0x00, sizeof(bt_obex_server_transfer_info_t));
+ transfer_info.contact_auth_info = g_malloc0(sizeof(unsigned char) * 5);
+
+ for (i = 0; i < 5 && g_variant_iter_loop(iter, "y", &byte); ++i)
+ transfer_info.contact_auth_info[i] = byte;
+
+ transfer_info.device_name = g_strdup(device_name);
transfer_info.filename = g_strdup(file_name);
transfer_info.type = g_strdup(type);
+ transfer_info.address = g_strdup(address);
transfer_info.file_size = size;
transfer_info.transfer_id = transfer_id;
+ transfer_info.server_type = (server_type == BT_FTP_SERVER) ?
+ FTP_SERVER : OPP_SERVER;
_bt_common_event_cb(BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
result, &transfer_info,
g_free(transfer_info.filename);
g_free(transfer_info.type);
- } else if (strcasecmp(member, BT_TRANSFER_PROGRESS) == 0) {
- char *file_name = NULL;
- char *type = NULL;
+ g_free(transfer_info.device_name);
+ g_free(transfer_info.address);
+ g_free(transfer_info.contact_auth_info);
+ g_variant_iter_free(iter);
+ } else if (strcasecmp(signal_name, BT_TRANSFER_PROGRESS) == 0) {
+ const char *file_name = NULL;
+ const char *type = NULL;
+ const char *device_name = NULL;
+ const char *address = NULL;
int transfer_id = 0;
int progress = 0;
int server_type = 0; /* bt_server_type_t */
guint64 size = 0;
bt_obex_server_transfer_info_t transfer_info;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &file_name,
- DBUS_TYPE_STRING, &type,
- DBUS_TYPE_UINT64, &size,
- DBUS_TYPE_INT32, &transfer_id,
- DBUS_TYPE_INT32, &progress,
- DBUS_TYPE_INT32, &server_type,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s&s&s&stiii)", &result, &file_name,
+ &type, &device_name, &address, &size, &transfer_id,
+ &progress, &server_type);
/* Other server's event */
- retv_if(obex_server_id != server_type &&
- server_type != BT_FTP_SERVER,
- DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ ret_if(obex_server_id != server_type &&
+ server_type != BT_FTP_SERVER);
memset(&transfer_info, 0x00, sizeof(bt_obex_server_transfer_info_t));
transfer_info.filename = g_strdup(file_name);
transfer_info.type = g_strdup(type);
+ transfer_info.device_name = g_strdup(device_name);
+ transfer_info.address = g_strdup(address);
transfer_info.file_size = size;
transfer_info.transfer_id = transfer_id;
transfer_info.percentage = progress;
+ transfer_info.server_type = (server_type == BT_FTP_SERVER) ?
+ FTP_SERVER : OPP_SERVER;
_bt_common_event_cb(BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS,
result, &transfer_info,
event_info->cb, event_info->user_data);
g_free(transfer_info.filename);
+ g_free(transfer_info.device_name);
+ g_free(transfer_info.address);
g_free(transfer_info.type);
- } else if (strcasecmp(member, BT_TRANSFER_COMPLETED) == 0) {
- char *file_name = NULL;
- char *device_name = NULL;
- char *type = NULL;
+ } else if (strcasecmp(signal_name, BT_TRANSFER_COMPLETED) == 0) {
+ const char *file_name = NULL;
+ const char *device_name = NULL;
+ const char *address = NULL;
+ const char *type = NULL;
+ const char *file_path;
int transfer_id = 0;
int server_type = 0; /* bt_server_type_t */
guint64 size = 0;
bt_obex_server_transfer_info_t transfer_info;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &file_name,
- DBUS_TYPE_STRING, &type,
- DBUS_TYPE_STRING, &device_name,
- DBUS_TYPE_UINT64, &size,
- DBUS_TYPE_INT32, &transfer_id,
- DBUS_TYPE_INT32, &server_type,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s&s&s&s&stii)", &result, &file_name,
+ &type, &device_name, &file_path, &address, &size,
+ &transfer_id, &server_type);
/* Other server's event */
- retv_if(obex_server_id != server_type &&
- server_type != BT_FTP_SERVER,
- DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ ret_if(obex_server_id != server_type &&
+ server_type != BT_FTP_SERVER);
memset(&transfer_info, 0x00, sizeof(bt_obex_server_transfer_info_t));
transfer_info.filename = g_strdup(file_name);
transfer_info.type = g_strdup(type);
transfer_info.device_name = g_strdup(device_name);
+ transfer_info.file_path = g_strdup(file_path);
+ transfer_info.address = g_strdup(address);
transfer_info.file_size = size;
transfer_info.transfer_id = transfer_id;
+ transfer_info.server_type = (server_type == BT_FTP_SERVER) ?
+ FTP_SERVER : OPP_SERVER;
_bt_common_event_cb(BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED,
result, &transfer_info,
g_free(transfer_info.filename);
g_free(transfer_info.type);
g_free(transfer_info.device_name);
+ g_free(transfer_info.address);
+ g_free(transfer_info.file_path);
+ }
+}
+
+void __bt_map_client_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ BT_DBG("Entered __bt_map_client_event_filter");
+ bt_event_info_t *event_info;
+ int result = BLUETOOTH_ERROR_NONE;
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
+
+ if (strcasecmp(object_path, BT_MAP_CLIENT_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
+
+ ret_if(signal_name == NULL);
+
+ if (strcasecmp(signal_name, BT_MAP_CONNECTED) == 0) {
+ const char *address = NULL;
+ int request_id = 0;
+ bluetooth_device_address_t dev_address = { {0} };
+
+ g_variant_get(parameters, "(i&si)", &result,
+ &address, &request_id);
+
+ if (__bt_is_request_id_exist(request_id) == FALSE) {
+ BT_ERR("Different request id!");
+ return;
+ }
+
+ _bt_convert_addr_string_to_type(dev_address.addr,
+ address);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_MAP_CONNECTED,
+ result, &dev_address,
+ event_info->cb, event_info->user_data);
+
+ if (result != BLUETOOTH_ERROR_NONE)
+ __bt_remove_push_request_id(request_id);
+ } else if (strcasecmp(signal_name, BT_MAP_DISCONNECTED) == 0) {
+ const char *address = NULL;
+ int request_id = 0;
+ bluetooth_device_address_t dev_address = { {0} };
+
+ g_variant_get(parameters, "(i&si)", &result, &address,
+ &request_id);
+
+ if (__bt_is_request_id_exist(request_id) == FALSE) {
+ BT_ERR("Different request id!");
+ return;
+ }
+
+ _bt_convert_addr_string_to_type(dev_address.addr,
+ address);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_MAP_DISCONNECTED,
+ result, &dev_address,
+ event_info->cb, event_info->user_data);
+
+ __bt_remove_push_request_id(request_id);
+ } else if (strcasecmp(signal_name, BT_MAP_LIST_FOLDERS_COMPLETE) == 0) {
+ int request_id = 0;
+ GVariant* folder_list_var = NULL;
+
+ g_variant_get(parameters, "(iiv)", &result, &request_id, &folder_list_var);
+ if (__bt_is_request_id_exist(request_id) == FALSE) {
+ BT_ERR("Different request id!");
+ return;
+ }
+
+ GVariantIter* iter;
+
+ bt_map_client_folders_s folders_struct = {0,};
+ g_variant_get(folder_list_var, "(aa{sv})", &iter);
+
+ folders_struct.size = g_variant_iter_n_children(iter);
+ folders_struct.names = (char**) malloc(folders_struct.size * sizeof(*(folders_struct.names)));
+ BT_DBG("g_variant_iter_n_children: %d", folders_struct.size);
+ GVariantIter* res = NULL;
+ int i = 0;
+ while (g_variant_iter_loop(iter, "a{sv}", &res)) {
+ char* key = NULL;
+ GVariant* value = NULL;
+ while (g_variant_iter_loop(res, "{sv}", &key, &value)) {
+ char* string_value = NULL;
+ g_variant_get(value, "s", &string_value);
+ BT_DBG("got folder name: %s", string_value);
+ folders_struct.names[i] = strdup(string_value);
+ }
+ ++i;
+ }
+ _bt_common_event_cb(BLUETOOTH_EVENT_MAP_LIST_FOLDERS_COMPLETE,
+ result, &folders_struct,
+ event_info->cb, event_info->user_data);
+
+ __bt_remove_push_request_id(request_id);
+
+ // freeing resources
+ while (--i >= 0) {
+ free(folders_struct.names[i]);
+ folders_struct.names[i] = NULL;
+ }
+ free(folders_struct.names);
+
+ g_variant_unref(folder_list_var);
+
+ } else if (strcasecmp(signal_name, BT_MAP_FILTER_FIELDS_COMPLETE) == 0) {
+ BT_DBG("BT_MAP_LIST_FOLDERS_COMPLETE");
+
+ GVariant *value;
+ int request_id = 0;
+ int i = 0;
+ bt_map_list_filter_fields_info_t fields_info = {0,};
+
+ g_variant_get(parameters, "(ivi)", &result, &value, &request_id);
+
+ if (__bt_is_request_id_exist(request_id) == FALSE) {
+ BT_ERR("Different request id!");
+ return;
+ }
+
+ if (value) {
+ GVariantIter *iter = NULL;
+ g_variant_get(value, "(as)", &iter);
+ fields_info.size = g_variant_iter_n_children(iter);
+ char* field = NULL;
+
+ fields_info.fields = malloc(fields_info.size * sizeof(char*));
+ while (g_variant_iter_loop(iter, "s", &field)) {
+ fields_info.fields[i] = strdup(field);
+ i++;
+ }
+ }
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_MAP_LIST_FILTER_FIELD_COMPLETE,
+ request_id, &fields_info,
+ event_info->cb, event_info->user_data);
+
+ while (--i >= 0) {
+ free(fields_info.fields[i]);
+ fields_info.fields[i] = NULL;
+ }
+ free(fields_info.fields);
+
+ __bt_remove_push_request_id(request_id);
+ g_variant_unref(value);
+ } else if (strcasecmp(signal_name, BT_MAP_LIST_MESSAGES_COMPLETE) == 0) {
+ int request_id = 0;
+ GVariant* messages_list_var = NULL;
+ g_variant_get(parameters, "(iiv)", &result, &request_id, &messages_list_var);
+ if (__bt_is_request_id_exist(request_id) == FALSE) {
+ BT_ERR("Different request id!");
+ return;
+ }
+
+ bt_map_client_message_items_s messages_struct = {0,};
+
+ GVariantIter* iter;
+ g_variant_get(messages_list_var, "(a{oa{sv}})", &iter);
+ messages_struct.size = g_variant_iter_n_children(iter);
+ messages_struct.message_items = (bt_map_client_message_item_t*)
+ malloc(messages_struct.size * sizeof(*(messages_struct.message_items)));
+ BT_DBG("g_variant_iter_n_children: %d", messages_struct.size);
+
+ char *object = NULL;
+ GVariantIter *properites = NULL;
+ int i = 0;
+ while (g_variant_iter_loop(iter, "{oa{sv}}", &object, &properites)) {
+ messages_struct.message_items[i].message_object = strdup(object);
+ BT_DBG("Message found: %s", messages_struct.message_items[i].message_object);
+ messages_struct.message_items[i].folder = NULL;
+ messages_struct.message_items[i].subject = NULL;
+ messages_struct.message_items[i].timestamp = NULL;
+ messages_struct.message_items[i].sender = NULL;
+ messages_struct.message_items[i].sender_address = NULL;
+ messages_struct.message_items[i].reply_to = NULL;
+ messages_struct.message_items[i].recipient = NULL;
+ messages_struct.message_items[i].recipient_address = NULL;
+ messages_struct.message_items[i].type = NULL;
+ messages_struct.message_items[i].size = -1;
+ messages_struct.message_items[i].is_text = -1;
+ messages_struct.message_items[i].status = NULL;
+ messages_struct.message_items[i].attachment_size = -1;
+ messages_struct.message_items[i].is_priority = -1;
+ messages_struct.message_items[i].is_read = -1;
+ messages_struct.message_items[i].is_sent = -1;
+ messages_struct.message_items[i].is_protected = -1;
+ char *key = NULL;
+ GVariant *value = NULL;
+ while (g_variant_iter_loop(properites, "{sv}", &key, &value)) {
+ char *value_string = NULL;
+ uint64_t value_int = -1;
+ bool value_bool = false;
+ if (strcmp(key, "Folder") == 0) {
+ g_variant_get(value, "s", &value_string);
+ messages_struct.message_items[i].folder = strdup(value_string);
+ BT_DBG(" Folder: %s", value_string);
+ } else if (strcmp(key, "Subject") == 0) {
+ g_variant_get(value, "s", &value_string);
+ messages_struct.message_items[i].subject = strdup(value_string);
+ BT_DBG(" Subject: %s", value_string);
+ } else if (strcmp(key, "Timestamp") == 0) {
+ g_variant_get(value, "s", &value_string);
+ messages_struct.message_items[i].timestamp = strdup(value_string);
+ BT_DBG(" Timestamp: %s", value_string);
+ } else if (strcmp(key, "Sender") == 0) {
+ g_variant_get(value, "s", &value_string);
+ messages_struct.message_items[i].sender = strdup(value_string);
+ BT_DBG(" Sender: %s", value_string);
+ } else if (strcmp(key, "SenderAddress") == 0) {
+ g_variant_get(value, "s", &value_string);
+ messages_struct.message_items[i].sender_address = strdup(value_string);
+ BT_DBG(" SenderAddress: %s", value_string);
+ } else if (strcmp(key, "ReplyTo") == 0) {
+ g_variant_get(value, "s", &value_string);
+ messages_struct.message_items[i].reply_to = strdup(value_string);
+ BT_DBG(" ReplyTo: %s", value_string);
+ } else if (strcmp(key, "Recipient") == 0) {
+ g_variant_get(value, "s", &value_string);
+ messages_struct.message_items[i].recipient = strdup(value_string);
+ BT_DBG(" Recipient: %s", value_string);
+ } else if (strcmp(key, "RecipientAddress") == 0) {
+ g_variant_get(value, "s", &value_string);
+ messages_struct.message_items[i].recipient_address = strdup(value_string);
+ BT_DBG(" RecipientAddress: %s", value_string);
+ } else if (strcmp(key, "Type") == 0) {
+ g_variant_get(value, "s", &value_string);
+ messages_struct.message_items[i].type = strdup(value_string);
+ BT_DBG(" Type: %s", value_string);
+ } else if (strcmp(key, "Size") == 0) {
+ g_variant_get(value, "t", &value_int);
+ messages_struct.message_items[i].size = value_int;
+ BT_DBG(" Size: %d", value_int);
+ } else if (strcmp(key, "Text") == 0) {
+ g_variant_get(value, "b", &value_bool);
+ messages_struct.message_items[i].is_text = value_bool ? 1 : 0;
+ BT_DBG(" Text: %s", value_bool ? "true" : "false");
+ } else if (strcmp(key, "Status") == 0) {
+ g_variant_get(value, "s", &value_string);
+ messages_struct.message_items[i].status = strdup(value_string);
+ BT_DBG(" Status: %s", value_string);
+ } else if (strcmp(key, "AttachmentSize") == 0) {
+ g_variant_get(value, "t", &value_int);
+ messages_struct.message_items[i].attachment_size = value_int;
+ BT_DBG(" AttachmentSize: %d", value_int);
+ } else if (strcmp(key, "Priority") == 0) {
+ g_variant_get(value, "b", &value_bool);
+ messages_struct.message_items[i].is_priority = value_bool ? 1 : 0;
+ BT_DBG(" Priority: %s", value_bool ? "true" : "false");
+ } else if (strcmp(key, "Read") == 0) {
+ g_variant_get(value, "b", &value_bool);
+ messages_struct.message_items[i].is_read = value_bool ? 1 : 0;
+ BT_DBG(" Read: %s", value_bool ? "true" : "false");
+ } else if (strcmp(key, "Sent") == 0) {
+ g_variant_get(value, "b", &value_bool);
+ messages_struct.message_items[i].is_sent = value_bool ? 1 : 0;
+ BT_DBG(" Sent: %s", value_bool ? "true" : "false");
+ } else if (strcmp(key, "Protected") == 0) {
+ g_variant_get(value, "b", &value_bool);
+ messages_struct.message_items[i].is_protected = value_bool ? 1 : 0;
+ BT_DBG(" Protected: %s", value_bool ? "true" : "false");
+ }
+ }
+ ++i;
+ }
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_MAP_LIST_MESSAGES_COMPLETE,
+ result, &messages_struct,
+ event_info->cb, event_info->user_data);
+
+ __bt_remove_push_request_id(request_id);
+
+ while (--i >= 0) {
+ free(messages_struct.message_items[i].folder);
+ free(messages_struct.message_items[i].subject);
+ free(messages_struct.message_items[i].timestamp);
+ free(messages_struct.message_items[i].sender);
+ free(messages_struct.message_items[i].sender_address);
+ free(messages_struct.message_items[i].reply_to);
+ free(messages_struct.message_items[i].recipient);
+ free(messages_struct.message_items[i].recipient_address);
+ free(messages_struct.message_items[i].type);
+ free(messages_struct.message_items[i].status);
+ }
+ free(messages_struct.message_items);
+
+ g_variant_unref(messages_list_var);
+ } else if (strcasecmp(signal_name, BT_MAP_GET_MESSAGE_COMPLETE) == 0) {
+ BT_DBG("BT_MAP_GET_MESSAGE_COMPLETE");
+ int request_id = 0;
+
+ g_variant_get(parameters, "(ii)", &result, &request_id);
+ if (__bt_is_request_id_exist(request_id) == FALSE) {
+ BT_ERR("Different request id!");
+ return;
+ }
+
+ // currently there is no result value passed from here, just passing NULL
+ void* some_result_value = NULL;
+ _bt_common_event_cb(BLUETOOTH_EVENT_MAP_GET_MESSAGE_COMPLETE,
+ result, some_result_value, event_info->cb, event_info->user_data);
+
+ __bt_remove_push_request_id(request_id);
+ } else if (strcasecmp(signal_name, BT_MAP_PUSH_MESSAGE_COMPLETE) == 0) {
+ BT_DBG("BT_MAP_PUSH_MESSAGE_COMPLETE");
+ int request_id = 0;
+
+ g_variant_get(parameters, "(ii)", &result, &request_id);
+ if (__bt_is_request_id_exist(request_id) == FALSE) {
+ BT_ERR("Different request id!");
+ return;
+ }
+
+ // currently there is no result value passed from here, just passing NULL
+ void* some_result_value = NULL;
+ _bt_common_event_cb(BLUETOOTH_EVENT_MAP_PUSH_MESSAGE_COMPLETE,
+ result, some_result_value, event_info->cb, event_info->user_data);
+
+ __bt_remove_push_request_id(request_id);
}
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static DBusHandlerResult __bt_rfcomm_client_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+void __bt_pbap_client_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
bt_event_info_t *event_info;
int result = BLUETOOTH_ERROR_NONE;
- const char *member = dbus_message_get_member(msg);
+ event_info = (bt_event_info_t *)user_data;
- event_info = (bt_event_info_t *)data;
- retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ ret_if(event_info == NULL);
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (strcasecmp(object_path, BT_PBAP_CLIENT_PATH) != 0)
+ return;
- if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
- if (!dbus_message_has_path(msg, BT_RFCOMM_CLIENT_PATH))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ ret_if(signal_name == NULL);
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ BT_DBG("Type: %s", g_variant_get_type_string(parameters));
- if (strcasecmp(member, BT_RFCOMM_CONNECTED) == 0) {
+ if (strcasecmp(signal_name, BT_PBAP_CONNECTED) == 0) {
+ bt_pbap_connected_t connected = { { { 0 }, }, };
char *address = NULL;
- char *uuid = NULL;
+
+ g_variant_get(parameters, "(i&s)", &result, &address);
+ BT_DBG("address: %s", address);
+
+ _bt_convert_addr_string_to_type(connected.btaddr.addr,
+ address);
+ if (result == 0)
+ connected.connected = 1;
+ else
+ connected.connected = 0;
+
+ _bt_common_event_cb(BLUETOOTH_PBAP_CONNECTED,
+ result, &connected,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_PBAP_DISCONNECTED) == 0) {
+ bt_pbap_connected_t disconnected = { { { 0 }, }, };
+ char *address = NULL;
+
+ g_variant_get(parameters, "(i&s)", &result, &address);
+ BT_DBG("address: %s", address);
+
+ _bt_convert_addr_string_to_type(disconnected.btaddr.addr,
+ address);
+ disconnected.connected = 0;
+
+ _bt_common_event_cb(BLUETOOTH_PBAP_DISCONNECTED,
+ result, &disconnected,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_PBAP_PHONEBOOK_SIZE) == 0) {
+ bt_pbap_phonebook_size_t pb_size = { { { 0 }, }, };
+ char *address = NULL;
+ int size = 0;
+
+ g_variant_get(parameters, "(i&si)", &result, &address, &size);
+
+ BT_DBG("address: %s, size: %d", address, size);
+
+ _bt_convert_addr_string_to_type(pb_size.btaddr.addr,
+ address);
+ pb_size.size = size;
+
+ _bt_common_event_cb(BLUETOOTH_PBAP_PHONEBOOK_SIZE,
+ result, &pb_size,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_PBAP_PHONEBOOK_PULL) == 0) {
+ bt_pbap_phonebook_pull_t pb_pull = { { { 0 } }, };
+ char *address = NULL;
+ char *vcf_file = NULL;
+ int success = -1;
+
+ g_variant_get(parameters, "(i&s&si)", &result, &address, &vcf_file, &success);
+
+ BT_DBG("address: %s, vcf_file: %s, success: %d",
+ address, vcf_file, success);
+
+ _bt_convert_addr_string_to_type(pb_pull.btaddr.addr,
+ address);
+ pb_pull.vcf_file = vcf_file;
+ pb_pull.success = success;
+ _bt_common_event_cb(BLUETOOTH_PBAP_PHONEBOOK_PULL,
+ result, &pb_pull,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_PBAP_VCARD_LIST) == 0) {
+ bt_pbap_vcard_list_t vc_list = { { { 0 } }, };
+ char *address = NULL;
+ gsize count = 0;
+ gchar **list = NULL;
+ GVariant *string_var;
+ int success = -1;
+ int i = 0;
+
+ g_variant_get(parameters, "(i&sv)", &result, &address, &string_var);
+
+ list = (gchar **)g_variant_get_strv(string_var, &count);
+
+ success = !result;
+
+ for (i = 0; i < count; i++)
+ BT_DBG("%s", list[i]);
+
+ BT_DBG("address: %s, result: %d, count: %d, success: %d",
+ address, result, count, success);
+
+ _bt_convert_addr_string_to_type(vc_list.btaddr.addr,
+ address);
+ vc_list.vcards = list;
+ vc_list.length = count;
+ vc_list.success = success;
+ _bt_common_event_cb(BLUETOOTH_PBAP_VCARD_LIST,
+ result, &vc_list,
+ event_info->cb, event_info->user_data);
+
+ g_variant_unref(string_var);
+ //free lists
+ } else if (strcasecmp(signal_name, BT_PBAP_VCARD_PULL) == 0) {
+ bt_pbap_vcard_pull_t vc_pull = { { { 0 } }, };
+ char *address = NULL;
+ char *vcf_file = NULL;
+ int success = -1;
+
+ g_variant_get(parameters, "(i&s&si)",
+ &result, &address, &vcf_file, &success);
+
+ BT_DBG("address: %s, vcf_file: %s, success: %d",
+ address, vcf_file, success);
+
+ _bt_convert_addr_string_to_type(vc_pull.btaddr.addr, address);
+ vc_pull.vcf_file = vcf_file;
+ vc_pull.success = success;
+ _bt_common_event_cb(BLUETOOTH_PBAP_VCARD_PULL,
+ result, &vc_pull,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_PBAP_SEARCH_PHONEBOOK) == 0) {
+ bt_pbap_phonebook_search_list_t vc_list = { { { 0 } }, };
+ char *address = NULL;
+ gsize count = 0;
+ gchar **list = NULL;
+ GVariant *string_var;
+ int success = -1;
+ int i = 0;
+
+ g_variant_get(parameters, "(i&s@as)", &result, &address, &string_var);
+
+ list = (gchar **)g_variant_get_strv(string_var, &count);
+ success = !result;
+ for (i = 0; i < count; i++)
+ BT_DBG("%s", list[i]);
+
+ BT_DBG("address: %s success: %d", address, success);
+
+ _bt_convert_addr_string_to_type(vc_list.btaddr.addr, address);
+ vc_list.vcards = list;
+ vc_list.length = count;
+ vc_list.success = success;
+ _bt_common_event_cb(BLUETOOTH_PBAP_PHONEBOOK_SEARCH,
+ result, &vc_list,
+ event_info->cb, event_info->user_data);
+
+ g_variant_unref(string_var);
+ //free lists
+ }
+}
+
+void __bt_rfcomm_client_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ bt_event_info_t *event_info;
+ int result = BLUETOOTH_ERROR_NONE;
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
+
+ if (strcasecmp(object_path, BT_RFCOMM_CLIENT_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
+
+ ret_if(signal_name == NULL);
+
+ if (strcasecmp(signal_name, BT_RFCOMM_CONNECTED) == 0) {
+ const char *address = NULL;
+ const char *uuid = NULL;
int socket_fd = 0;
bluetooth_rfcomm_connection_t conn_info;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_STRING, &uuid,
- DBUS_TYPE_INT16, &socket_fd,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s&sn)", &result, &address,
+ &uuid, &socket_fd);
memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
conn_info.device_role = RFCOMM_ROLE_CLIENT;
_bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
result, &conn_info,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_RFCOMM_DISCONNECTED) == 0) {
- char *address = NULL;
- char *uuid = NULL;
+ } else if (strcasecmp(signal_name, BT_RFCOMM_DISCONNECTED) == 0) {
+ const char *address = NULL;
+ const char *uuid = NULL;
int socket_fd = 0;
bluetooth_rfcomm_disconnection_t disconn_info;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_STRING, &uuid,
- DBUS_TYPE_INT16, &socket_fd,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s&sn)", &result, &address,
+ &uuid, &socket_fd);
memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
disconn_info.device_role = RFCOMM_ROLE_CLIENT;
_bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
result, &disconn_info,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_RFCOMM_DATA_RECEIVED) == 0) {
- char *buffer = NULL;
+ } else if (strcasecmp(signal_name, BT_RFCOMM_DATA_RECEIVED) == 0) {
+ char *buffer;
int buffer_len = 0;
int socket_fd = 0;
bluetooth_rfcomm_received_data_t data_r;
+ GVariant *byte_var;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INT16, &socket_fd,
- DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
- &buffer, &buffer_len,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(in@ay)", &result, &socket_fd,
+ &byte_var);
+
+ buffer_len = g_variant_get_size(byte_var);
+ buffer = (char *) g_variant_get_data(byte_var);
data_r.socket_fd = socket_fd;
data_r.buffer_size = buffer_len;
- data_r.buffer = g_memdup(buffer, buffer_len);
+ data_r.buffer = buffer;
_bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
result, &data_r,
event_info->cb, event_info->user_data);
-
- g_free(data_r.buffer);
+ g_variant_unref(byte_var);
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static DBusHandlerResult __bt_rfcomm_server_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+void __bt_rfcomm_server_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
bt_event_info_t *event_info;
int result = BLUETOOTH_ERROR_NONE;
- const char *member = dbus_message_get_member(msg);
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
- event_info = (bt_event_info_t *)data;
- retv_if(event_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ if (strcasecmp(object_path, BT_RFCOMM_SERVER_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ ret_if(signal_name == NULL);
- if (!dbus_message_has_interface(msg, BT_EVENT_SERVICE))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- if (!dbus_message_has_path(msg, BT_RFCOMM_SERVER_PATH))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- if (strcasecmp(member, BT_RFCOMM_CONNECTED) == 0) {
- char *address = NULL;
- char *uuid = NULL;
+ if (strcasecmp(signal_name, BT_RFCOMM_CONNECTED) == 0) {
+ const char *address = NULL;
+ const char *uuid = NULL;
int socket_fd = 0;
bluetooth_rfcomm_connection_t conn_info;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_STRING, &uuid,
- DBUS_TYPE_INT16, &socket_fd,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s&sn)", &result, &address,
+ &uuid, &socket_fd);
memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
conn_info.device_role = RFCOMM_ROLE_SERVER;
_bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
result, &conn_info,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_RFCOMM_DISCONNECTED) == 0) {
- char *address = NULL;
- char *uuid = NULL;
+ } else if (strcasecmp(signal_name, BT_RFCOMM_DISCONNECTED) == 0) {
+ const char *address = NULL;
+ const char *uuid = NULL;
int socket_fd = 0;
bluetooth_rfcomm_disconnection_t disconn_info;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_STRING, &uuid,
- DBUS_TYPE_INT16, &socket_fd,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s&sn)", &result, &address,
+ &uuid, &socket_fd);
memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
disconn_info.device_role = RFCOMM_ROLE_SERVER;
_bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
result, &disconn_info,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_CONNECTION_AUTHORIZED) == 0) {
+ } else if (strcasecmp(signal_name, BT_CONNECTION_AUTHORIZED) == 0) {
/* OSP only event */
bluetooth_rfcomm_connection_request_t req_ind;
char *address = NULL;
char *uuid = NULL;
char *name = NULL;
+ char *path = NULL;
int socket_fd = 0;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_STRING, &uuid,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INT16, &socket_fd,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(i&s&s&s&sn)", &result, &address,
+ &uuid, &name, &path, &socket_fd);
- /* Don't send the authorized event to other server */
- retv_if(__bt_is_server_exist(socket_fd) == FALSE,
- DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ if (_check_uuid_path(path, uuid) == FALSE)
+ return;
memset(&req_ind, 0x00, sizeof(bluetooth_rfcomm_connection_request_t));
_bt_convert_addr_string_to_type(req_ind.device_addr.addr,
_bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
result, &req_ind,
event_info->cb, event_info->user_data);
- } else if (strcasecmp(member, BT_RFCOMM_SERVER_REMOVED) == 0) {
+ } else if (strcasecmp(signal_name, BT_RFCOMM_SERVER_REMOVED) == 0) {
/* OSP only event */
int socket_fd = 0;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INT16, &socket_fd,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(in)", &result, &socket_fd);
- retv_if(__bt_is_server_exist(socket_fd) == FALSE,
- DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ ret_if(__bt_is_server_exist(socket_fd) == FALSE);
_bt_remove_server(socket_fd);
- } else if (strcasecmp(member, BT_RFCOMM_DATA_RECEIVED) == 0) {
+ } else if (strcasecmp(signal_name, BT_RFCOMM_DATA_RECEIVED) == 0) {
char *buffer = NULL;
int buffer_len = 0;
int socket_fd = 0;
bluetooth_rfcomm_received_data_t data_r;
+ GVariant *byte_var;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INT16, &socket_fd,
- DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
- &buffer, &buffer_len,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ g_variant_get(parameters, "(in@ay)", &result,
+ &socket_fd, &byte_var);
+
+ buffer_len = g_variant_get_size(byte_var);
+ buffer = (char *) g_variant_get_data(byte_var);
data_r.socket_fd = socket_fd;
data_r.buffer_size = buffer_len;
- data_r.buffer = g_memdup(buffer, buffer_len);
+ data_r.buffer = buffer;
_bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
result, &data_r,
event_info->cb, event_info->user_data);
+ g_variant_unref(byte_var);
+ }
+}
+
+void __bt_hf_agent_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ BT_DBG("+\n");
+
+ bt_event_info_t *event_info;
+ int result = BLUETOOTH_ERROR_NONE;
+ event_info = (bt_event_info_t *)user_data;
+ ret_if(event_info == NULL);
+
+ BT_DBG("+\n");
+ if (strcasecmp(object_path, BT_HF_AGENT_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_HF_SERVICE_INTERFACE) != 0)
+ return;
+
+ ret_if(signal_name == NULL);
+
+ BT_DBG("%s", signal_name);
+ if (strcasecmp(signal_name, "Connected") == 0) {
+ char *address = NULL;
+
+ g_variant_get(parameters, "(s)", &address);
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CONNECTED,
+ result, address,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "Disconnected") == 0) {
+ char *address = NULL;
+
+ g_variant_get(parameters, "(s)", &address);
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_DISCONNECTED,
+ result, address,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "AudioConnected") == 0) {
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_AUDIO_CONNECTED,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "AudioDisconnected") == 0) {
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_AUDIO_DISCONNECTED,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "Ring") == 0) {
+ char *phoneno = NULL;
+
+ g_variant_get(parameters, "(&s)", &phoneno);
+
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_RING_INDICATOR,
+ result, phoneno,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "CallWaiting") == 0) {
+ char *phoneno = NULL;
+
+ g_variant_get(parameters, "(&s)", &phoneno);
+
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CALL_WAITING,
+ result, phoneno,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "CallTerminated") == 0) {
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CALL_TERMINATED,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "FailedToDial") == 0) {
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CALL_FAILED_TO_DIAL,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "CallIdle") == 0) {
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CALL_IDLE,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "CallSetupIncoming") == 0) {
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CALLSETUP_INCOMING,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "CallSetupDialing") == 0) {
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CALLSETUP_DIALING,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "CallSetupAlerting") == 0) {
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CALLSETUP_ALERTING,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "CallStarted") == 0) {
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CALL_STARTED,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "CallEnded") == 0) {
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CALL_ENDED,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "NoCallsHeld") == 0) {
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CALL_UNHOLD,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "CallsSwapped") == 0) {
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CALL_SWAPPED,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "CallOnHold") == 0) {
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CALL_ON_HOLD,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "CallStatusUpdate") == 0) {
+ int call_count;
+ GVariant *var_data = NULL;
+ char *number = NULL;
+ int idx, dir, status, mpart;
+ bt_hf_call_list_s *handle = NULL;
+
+ g_variant_get(parameters, "(i@a(siiii))", &call_count,
+ &var_data);
+ BT_DBG("call count : %d", call_count);
+
+ if (var_data) {
+ GVariantIter *iter = NULL;
+ __bt_call_list_create(&handle);
+
+ g_variant_get(var_data, "a(siiii)", &iter);
+ while (g_variant_iter_loop(iter, "(siiii)", &number,
+ &dir, &status, &mpart, &idx)) {
+ BT_DBG("call number:%s, dir:%d, status : %d",
+ number, dir, status);
+ BT_DBG("call mpart : %d, idx : %d", mpart, idx);
+ __bt_call_list_add(handle, number, dir,
+ status, mpart, idx);
+ }
+ g_variant_iter_free(iter);
+ g_variant_unref(var_data);
+ }
+
+ if (handle && (call_count == g_list_length(handle->list))) {
+ handle->count = call_count;
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CALL_STATUS,
+ result, handle,
+ event_info->cb, event_info->user_data);
+ } else {
+ BT_ERR(" Mismatch in call count : %d", call_count);
+ }
+
+ __bt_call_list_destroy(handle);
+ } else if (strcasecmp(signal_name, "VoiceRecognition") == 0) {
+ int status;
+ g_variant_get(parameters, "(i)", &status);
+ BT_DBG("status = [%d]\n", status);
+ if (status)
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_ENABLED,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ else
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_DISABLED,
+ result, NULL,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "VolumeSpeaker") == 0) {
+ int value;
+ g_variant_get(parameters, "(i)", &value);
+ BT_DBG("Value = [%d]\n", value);
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_VOLUME_SPEAKER,
+ result, &value,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "SamsungXSAT") == 0) {
+ int value = 0;
+ char *msg = NULL;
+ bluetooth_vendor_dep_at_cmd_t cmd;
+ g_variant_get(parameters, "(i&s)", &value, &msg);
+ BT_DBG("Value = [%d], message = %s\n", value, msg);
+ cmd.app_id = value;
+ cmd.message = msg;
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_VENDOR_DEP_CMD,
+ result, &cmd,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, "PropertyChanged") == 0) {
+ GVariant *value;
+ gchar *property;
+ bluetooth_hf_ciev_device_event_t dev_event;
+
+ g_variant_get(parameters, "(&sv)", &property, &value);
+ dev_event.value = g_variant_get_uint16(value);
+
+ BT_DBG("Property: %s , value: %d", property, dev_event.value);
+ g_variant_unref(value);
+
+ if (strcasecmp(property, "BatteryCharge") == 0) {
+ dev_event.event = BLUETOOTH_HF_CIEV_BATTCHG;
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CIEV_DEVICE_STATUS_CHANGED,
+ result, &dev_event,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(property, "SignalStrength") == 0) {
+ dev_event.event = BLUETOOTH_HF_CIEV_SIGNAL;
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CIEV_DEVICE_STATUS_CHANGED,
+ result, &dev_event,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(property, "RegistrationStatus") == 0) {
+ dev_event.event = BLUETOOTH_HF_CIEV_SERVICE;
+ _bt_hf_event_cb(BLUETOOTH_EVENT_HF_CIEV_DEVICE_STATUS_CHANGED,
+ result, &dev_event,
+ event_info->cb, event_info->user_data);
+ }
+ }
+ BT_DBG("-\n");
+}
+
+static void __bt_tds_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ bt_event_info_t *event_info;
+ event_info = (bt_event_info_t *)user_data;
+ int result = BLUETOOTH_ERROR_NONE;
+
+ ret_if(event_info == NULL);
+
+ if (strcasecmp(object_path, BT_TDS_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
+
+ ret_if(signal_name == NULL);
+
+ BT_DBG("+");
+
+ if (strcasecmp(signal_name, BT_TDS_ACTIVATION_REQUESTED) == 0) {
+ bluetooth_tds_activation_req_t act_req;
+ const char *address = NULL;
+ char *buffer = NULL;
+ int transport = 0;
+ GVariant *byte_var;
+
+ g_variant_get(parameters, "(&si@ay)", &address,
+ &transport, &byte_var);
+
+ memset(&act_req, 0x00, sizeof(bluetooth_tds_activation_req_t));
+
+ act_req.transport = transport;
+
+ act_req.tds_data.length = g_variant_get_size(byte_var);
+ if (act_req.tds_data.length > BLUETOOTH_TDS_DATA_LENGTH_MAX) {
+ BT_INFO("tds data length > BLUETOOTH_TDS_DATA_LENGTH_MAX");
+ act_req.tds_data.length = BLUETOOTH_TDS_DATA_LENGTH_MAX;
+ }
+ buffer = (char *) g_variant_get_data(byte_var);
+ memcpy(act_req.tds_data.data, buffer, act_req.tds_data.length);
+
+ _bt_convert_addr_string_to_type(act_req.rem_addr.addr, address);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_TDS_ACTIVATION_REQUESTED,
+ BLUETOOTH_ERROR_NONE, &act_req,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_TDS_TRANSPORT_DATA_RECEIVED) == 0) {
+ BT_DBG("TDS Complete Block Data received");
+ const char *address = NULL;
+ char *data;
+ int data_len = 0;
+ int k;
+ GVariant *var = NULL;
+ bluetooth_tds_transport_data_info_t *info = NULL;
+
+ /* Extract data from DBUS params */
+ g_variant_get(parameters, "(i&sn@ay)", &result, &address, &data_len, &var);
+ data = (char *)g_variant_get_data(var);
+
+ BT_DBG("Address [%s]", address);
+ BT_DBG("Data len [%d]", data_len);
+
+ /* DEBUG */
+ for (k = 0; k < data_len ; k++)
+ BT_DBG("Data[%d] [0x%x]", k, data[k]);
+
+ if (data_len == 0) {
+ BT_ERR("No data");
+ g_variant_unref(var);
+ return;
+ }
+
+ info = g_malloc0(sizeof(bluetooth_tds_transport_data_info_t));
+ info->data_length = data_len;
+ info->data = g_memdup(data, data_len);
+
+ _bt_convert_addr_string_to_type(info->device_address.addr,
+ address);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_TDS_TRANSPORT_DATA_RECEIVED,
+ result, info,
+ event_info->cb, event_info->user_data);
+
+ if (info->data) {
+ g_free(info->data);
+ g_free(info);
+ }
+
+ g_variant_unref(var);
+ } else if (strcasecmp(signal_name, BT_TDS_ACTIVATION_RESULT) == 0) {
+ BT_DBG("TDS Control point Activation result");
+ const char *address = NULL;
+ bluetooth_device_address_t dev_address = { {0} };
+
+ /* Extract data from DBUS params */
+ g_variant_get(parameters, "(i&s)", &result, &address);
+ BT_DBG("Address [%s]", address);
+ BT_DBG("Result [%d]", result);
+
+ _bt_convert_addr_string_to_type(dev_address.addr,
+ address);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_TDS_ACTIVATION_RESULT,
+ result, &dev_address,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_TDS_ACTIVATION_INDICATION) == 0) {
+ BT_DBG("TDS Control point Indication Response");
+ bluetooth_tds_indication_res_t ind_res;
+ const char *address = NULL;
+ char *buffer = NULL;
+ GVariant *byte_var = NULL;
+
+ g_variant_get(parameters, "(&s@ay)", &address, &byte_var);
+
+ memset(&ind_res, 0x00, sizeof(bluetooth_tds_indication_res_t));
+
+ ind_res.tds_data.length = g_variant_get_size(byte_var);
+
+ buffer = (char *) g_variant_get_data(byte_var);
+ memcpy(ind_res.tds_data.data, buffer, ind_res.tds_data.length);
+
+ _bt_convert_addr_string_to_type(ind_res.rem_addr.addr, address);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_TDS_ACTIVATION_INDICATION,
+ BLUETOOTH_ERROR_NONE, &ind_res,
+ event_info->cb, event_info->user_data);
+
+ g_variant_unref(byte_var);
+ } else if (strcasecmp(signal_name, BT_TDS_CONTROL_POINT_ENABLED) == 0) {
+ BT_DBG("TDS Control point Enabled event");
+ const char *address = NULL;
+ bluetooth_device_address_t dev_address = { {0} };
+
+ /* Extract data from DBUS params */
+ g_variant_get(parameters, "(i&s)", &result, &address);
+ BT_DBG("Address [%s]", address);
+ BT_DBG("Result [%d]", result);
+
+ _bt_convert_addr_string_to_type(dev_address.addr,
+ address);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_TDS_CONTROL_POINT_ENABLED,
+ result, &dev_address,
+ event_info->cb, event_info->user_data);
+ }
+
+ BT_DBG("-");
+}
+
+static void __bt_otp_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ bt_event_info_t *event_info;
+ event_info = (bt_event_info_t *)user_data;
+ int result = BLUETOOTH_ERROR_NONE;
+
+ ret_if(event_info == NULL);
+
+ if (strcasecmp(object_path, BT_OTP_PATH) != 0)
+ return;
+ if (strcasecmp(interface_name, BT_EVENT_SERVICE) != 0)
+ return;
+
+ ret_if(signal_name == NULL);
+
+ BT_DBG("+");
+
+ if (strcasecmp(signal_name, BT_OTP_SERVER_STATE_CHANGED) == 0) {
+ BT_DBG("OTP Server State Changed Event");
+ bool status = FALSE;
+
+ /* Extract data from DBUS params */
+ g_variant_get(parameters, "(ib)", &result, &status);
+ BT_DBG("Result [%d]", result);
+ BT_DBG("Status [%s]", status ? "enabled" : "disabled");
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_OTP_SERVER_STATE_CHANGED,
+ result, &status, event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_OTP_READ_CHAR_VAL) == 0) {
+ BT_DBG("OTP Read Data received");
+ const char *handle = NULL;
+ char *data;
+ int data_len = 0;
+ GVariant *var = NULL;
+ bluetooth_otp_resp_info_t *info = NULL;
+
+ /* Extract data from DBUS params */
+ g_variant_get(parameters, "(i&sn@ay)", &result, &handle, &data_len, &var);
+ data = (char *)g_variant_get_data(var);
+
+ BT_DBG("Handle [%s]", handle);
+ BT_DBG("Data len [%d]", data_len);
+
+ if (data_len == 0) {
+ BT_ERR("No data");
+ if (var)
+ g_variant_unref(var);
+ return;
+ }
+
+ info = g_malloc0(sizeof(bluetooth_otp_resp_info_t));
+ info->data_length = data_len;
+ info->data = g_memdup(data, data_len);
+ info->handle = g_strdup(handle);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_OTP_READ_CHAR_VAL,
+ result, info,
+ event_info->cb, event_info->user_data);
+
+ if (info->handle) {
+ g_free(info->handle);
+ }
+
+ if (info->data) {
+ g_free(info->data);
+ g_free(info);
+ }
+ if (var)
+ g_variant_unref(var);
+ } else if (strcasecmp(signal_name, BT_OTP_NOTIFICATION_ENABLED) == 0) {
+ BT_DBG("OTP Notification Enabled event");
+ char *handle = NULL;
+
+ /* Extract data from DBUS params */
+ g_variant_get(parameters, "(i&s)", &result, &handle);
+ BT_DBG("Handle [%s]", handle);
+ BT_DBG("Result [%d]", result);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_OTP_NOTIFICATION_ENABLED,
+ result, handle,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_OTP_WRITE_CHAR_VAL) == 0) {
+ BT_DBG("OTP Control point Activation result");
+ char *handle = NULL;
+
+ /* Extract data from DBUS params */
+ g_variant_get(parameters, "(i&s)", &result, &handle);
+ BT_DBG("Handle [%s]", handle);
+ BT_DBG("Result [%d]", result);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_OTP_WRITE_CHAR_VAL,
+ result, handle,
+ event_info->cb, event_info->user_data);
+ } else if (strcasecmp(signal_name, BT_OTP_INDICATION) == 0) {
+ BT_DBG("OTP Control point Indication Response");
+ bluetooth_otp_resp_info_t *ind_res = NULL;
+ char *buffer = NULL;
+ GVariant *byte_var = NULL;
+ char *handle = NULL;
+
+ g_variant_get(parameters, "(i&s@ay)", &result, &handle, &byte_var);
+
+ ind_res = g_malloc0(sizeof(bluetooth_otp_resp_info_t));
+ ind_res->data_length = g_variant_get_size(byte_var);
+ buffer = (char *)g_variant_get_data(byte_var);
+ ind_res->data = g_memdup(buffer, ind_res->data_length);
+ ind_res->handle = g_strdup(handle);
+
+ _bt_common_event_cb(BLUETOOTH_EVENT_OTP_INDICATION,
+ result, ind_res,
+ event_info->cb, event_info->user_data);
+
+ if (ind_res->handle) {
+ g_free(ind_res->handle);
+ }
- g_free(data_r.buffer);
+ if (ind_res->data) {
+ g_free(ind_res->data);
+ g_free(ind_res);
+ }
+ if (byte_var)
+ g_variant_unref(byte_var);
}
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ BT_DBG("-");
}
static void __bt_remove_all_events(void)
{
- GSList *l;
bt_event_info_t *info;
- for (l = event_list; l != NULL; l = g_slist_next(l)) {
- info = l->data;
+ while ((info = g_slist_nth_data(event_list, 0)) != NULL)
+ _bt_unregister_event(info->event_type);
- if (info)
- _bt_unregister_event(info->event_type);
+ if (event_list) {
+ g_slist_free(event_list);
+ event_list = NULL;
}
-
- g_slist_free(event_list);
- event_list = NULL;
}
static gboolean __bt_event_is_registered(int event_type)
if (info == NULL)
continue;
- retv_if(info->event_type == event_type, TRUE);
+ if (info->event_type == event_type)
+ return TRUE;
}
return FALSE;
}
-bt_event_info_t* __bt_event_get_cb_data(int event_type)
+bt_event_info_t *_bt_event_get_cb_data(int event_type)
{
GSList *l;
bt_event_info_t *info;
if (info == NULL)
continue;
- if (info->server_fd == server_fd) {
+ if (info->server_fd == server_fd)
server_list = g_slist_remove(server_list, (void *)info);
- }
g_free(info);
}
__bt_remove_all_events();
+ if (disable_timer_id > 0) {
+ g_source_remove(disable_timer_id);
+ disable_timer_id = 0;
+ }
+
is_initialized = FALSE;
return BLUETOOTH_ERROR_NONE;
ret_if(cb_data == NULL);
- if (cb_data->conn)
- dbus_connection_unref(cb_data->conn);
-
g_free(cb_data);
}
int _bt_register_event(int event_type, void *event_cb, void *user_data)
{
- DBusError dbus_error;
- char *match;
- DBusConnection *connection_type;
- DBusHandleMessageFunction event_func;
+ GDBusConnection *connection_type;
+ GDBusSignalCallback event_func;
bt_event_info_t *cb_data;
+ const char *path;
+ const char *interface = BT_EVENT_SERVICE;
if (is_initialized == FALSE)
_bt_init_event_handler();
switch (event_type) {
case BT_ADAPTER_EVENT:
- connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
-
event_func = __bt_adapter_event_filter;
- match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
- BT_ADAPTER_PATH);
+ path = BT_ADAPTER_PATH;
+ break;
+ case BT_LE_ADAPTER_EVENT:
+ event_func = __bt_adapter_le_event_filter;
+ path = BT_LE_ADAPTER_PATH;
break;
case BT_DEVICE_EVENT:
- connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
-
event_func = __bt_device_event_filter;
- match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
- BT_DEVICE_PATH);
+ path = BT_DEVICE_PATH;
break;
case BT_HID_EVENT:
- connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
-
event_func = __bt_hid_event_filter;
- match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
- BT_HID_PATH);
+ path = BT_HID_PATH;
break;
case BT_HEADSET_EVENT:
- connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
-
event_func = __bt_headset_event_filter;
- match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
- BT_HEADSET_PATH);
+ path = BT_HEADSET_PATH;
break;
case BT_NETWORK_EVENT:
- connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
-
event_func = __bt_network_event_filter;
- match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
- BT_NETWORK_PATH);
+ path = BT_NETWORK_PATH;
break;
case BT_AVRCP_EVENT:
- connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
-
event_func = __bt_avrcp_event_filter;
- match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
- BT_AVRCP_PATH);
+ path = BT_AVRCP_PATH;
+ break;
+ case BT_AVRCP_CONTROL_EVENT:
+ event_func = __bt_avrcp_control_event_filter;
+ path = BT_AVRCP_CONTROL_PATH;
break;
case BT_OPP_CLIENT_EVENT:
- connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
-
event_func = __bt_opp_client_event_filter;
- match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
- BT_OPP_CLIENT_PATH);
+ path = BT_OPP_CLIENT_PATH;
break;
case BT_OPP_SERVER_EVENT:
- connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
-
event_func = __bt_opp_server_event_filter;
- match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
- BT_OPP_SERVER_PATH);
+ path = BT_OPP_SERVER_PATH;
+ break;
+ case BT_MAP_CLIENT_EVENT:
+ event_func = __bt_map_client_event_filter;
+ path = BT_MAP_CLIENT_PATH;
+ break;
+ case BT_PBAP_CLIENT_EVENT:
+ event_func = __bt_pbap_client_event_filter;
+ path = BT_PBAP_CLIENT_PATH;
break;
case BT_RFCOMM_CLIENT_EVENT:
- connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
-
event_func = __bt_rfcomm_client_event_filter;
- match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
- BT_RFCOMM_CLIENT_PATH);
+ path = BT_RFCOMM_CLIENT_PATH;
break;
case BT_RFCOMM_SERVER_EVENT:
- connection_type = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
-
event_func = __bt_rfcomm_server_event_filter;
- match = g_strdup_printf(EVENT_MATCH_RULE, BT_EVENT_SERVICE,
- BT_RFCOMM_SERVER_PATH);
+ path = BT_RFCOMM_SERVER_PATH;
+ break;
+ case BT_HF_AGENT_EVENT:
+ BT_DBG("BT_HF_AGENT_EVENT\n");
+ event_func = __bt_hf_agent_event_filter;
+ path = BT_HF_AGENT_PATH;
+ interface = BT_HF_SERVICE_INTERFACE;
+ break;
+ case BT_A2DP_SOURCE_EVENT:
+ BT_DBG("BT_A2DP_SOURCE_EVENT");
+ event_func = __bt_a2dp_source_event_filter;
+ path = BT_A2DP_SOURCE_PATH;
+ break;
+ case BT_HID_DEVICE_EVENT:
+ BT_DBG("BT_HID_DEVICE_EVENT");
+ event_func = __bt_hid_device_event_filter;
+ path = BT_HID_DEVICE_PATH;
+ break;
+ case BT_GATT_BLUEZ_EVENT:
+ BT_DBG("BT_GATT_BLUEZ_EVENT");
+ event_func = __bt_device_event_filter;
+ interface = BT_GATT_CHARACTERISTIC_INTERFACE;
+ path = NULL;
+ break;
+ case BT_TDS_EVENT:
+ BT_DBG("BT_TDS_EVENT");
+ event_func = __bt_tds_event_filter;
+ path = BT_TDS_PATH;
+ break;
+ case BT_OTP_EVENT:
+ BT_DBG("BT_OTP_EVENT");
+ event_func = __bt_otp_event_filter;
+ path = BT_OTP_PATH;
break;
default:
BT_ERR("Unknown event");
return BLUETOOTH_ERROR_INTERNAL;
}
+ connection_type = _bt_gdbus_get_system_gconn();
+ if (connection_type == NULL)
+ return BLUETOOTH_ERROR_INTERNAL;
+
cb_data = g_new0(bt_event_info_t, 1);
cb_data->event_type = event_type;
- cb_data->conn = connection_type;
- cb_data->func = event_func;
cb_data->cb = event_cb;
cb_data->user_data = user_data;
- if (!dbus_connection_add_filter(connection_type, event_func,
- (void *)cb_data, __bt_event_data_free)) {
- BT_ERR("Fail to add filter");
- goto fail;
- }
-
- dbus_error_init(&dbus_error);
-
- if (match)
- dbus_bus_add_match(connection_type, match, &dbus_error);
-
- if (dbus_error_is_set(&dbus_error)) {
- BT_ERR("Fail to add match: %s\n", dbus_error.message);
- dbus_error_free(&dbus_error);
- goto fail;
- }
-
- g_free(match);
+ cb_data->id = g_dbus_connection_signal_subscribe(connection_type,
+ NULL, interface, NULL, path, NULL, 0,
+ event_func, cb_data, NULL);
event_list = g_slist_append(event_list, cb_data);
return BLUETOOTH_ERROR_NONE;
-fail:
- if (connection_type)
- dbus_connection_unref(connection_type);
-
- g_free(cb_data);
- g_free(match);
- return BLUETOOTH_ERROR_INTERNAL;
}
int _bt_unregister_event(int event_type)
{
- DBusConnection *connection_type;
- DBusHandleMessageFunction event_func;
+ GDBusConnection *connection_type;
bt_event_info_t *cb_data;
if (is_initialized == FALSE) {
BT_ERR("Event is not registered");
- return BLUETOOTH_ERROR_INTERNAL;
+ return BLUETOOTH_ERROR_NOT_INITIALIZED;
}
if (__bt_event_is_registered(event_type) == FALSE) {
return BLUETOOTH_ERROR_INTERNAL;
}
- cb_data = __bt_event_get_cb_data(event_type);
+ cb_data = _bt_event_get_cb_data(event_type);
if (cb_data == NULL) {
BT_ERR("No matched event data");
return BLUETOOTH_ERROR_INTERNAL;
}
- connection_type = cb_data->conn;
- event_func = cb_data->func;
+ connection_type = _bt_gdbus_get_system_gconn();
event_list = g_slist_remove(event_list, (void *)cb_data);
retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL);
- retv_if(event_func == NULL, BLUETOOTH_ERROR_INTERNAL);
- dbus_connection_remove_filter(connection_type, event_func,
- (void *)cb_data);
+ g_dbus_connection_signal_unsubscribe(connection_type, cb_data->id);
+
+ __bt_event_data_free((void *)cb_data);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static void __bt_name_owner_changed(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ const char *name = NULL;
+ const char *old_owner = NULL;
+ const char *new_owner = NULL;
+ bt_event_info_t *event_info;
+
+ g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);
+
+ if (g_strcmp0(name, BT_DBUS_NAME) == 0 &&
+ (new_owner != NULL && *new_owner == '\0')) {
+ BT_DBG("bt-service is terminated");
+ event_info = _bt_event_get_cb_data(BT_ADAPTER_EVENT);
+ if (event_info == NULL)
+ return;
+
+ if (disable_timer_id > 0)
+ g_source_remove(disable_timer_id);
+
+ disable_timer_id = g_timeout_add(BT_RELIABLE_DISABLE_TIME,
+ (GSourceFunc)__bt_reliable_disable_cb,
+ event_info);
+ }
+}
+
+void _bt_register_name_owner_changed(void)
+{
+ GDBusConnection *connection_type;
+
+ connection_type = _bt_gdbus_get_system_gconn();
+ if (connection_type == NULL) {
+ BT_ERR("Unable to get the bus");
+ return;
+ }
+ owner_sig_id = g_dbus_connection_signal_subscribe(connection_type,
+ NULL, BT_EVENT_FREEDESKTOP,
+ BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
+ __bt_name_owner_changed, NULL, NULL);
+}
+
+void _bt_unregister_name_owner_changed(void)
+{
+ GDBusConnection *connection_type;
+
+ connection_type = _bt_gdbus_get_system_gconn();
+ if (connection_type != NULL && owner_sig_id != -1) {
+ g_dbus_connection_signal_unsubscribe(connection_type,
+ owner_sig_id);
+ owner_sig_id = -1;
+ }
+}
+
+static void __bt_manager_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ char *path = NULL;
+ GVariantIter *interface_iter = NULL;
+ char *interface_str = NULL;
+ bt_gatt_service_change_t change;
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ bt_user_info_t *user_info = NULL;
+
+ if (strcasecmp(signal_name, "GattServiceAdded") == 0) {
+ g_variant_get(parameters, "(&s)", &path);
+
+ _bt_convert_device_path_to_address(path, address);
+ _bt_convert_addr_string_to_type(change.device_addr.addr, address);
+ _bt_convert_addr_string_to_secure_string(secure_address, address);
+
+ if (_bluetooth_gatt_check_service_change_watcher_address(&change.device_addr)
+ == FALSE) {
+ BT_INFO("GATT Service [%s] added, but no watcher for %s",
+ path, secure_address);
+ return;
+ } else
+ BT_INFO(" ### GATT Service added [%s] [%s]",
+ path, secure_address);
+
+ change.svc_path = g_strdup(path);
+ change.change_type = BLUETOOTH_GATT_SERVICE_CHANGE_TYPE_ADD;
+
+ user_info = _bt_get_user_data(BT_COMMON);
+ if (user_info != NULL) {
+ _bt_common_event_cb(
+ BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED,
+ BLUETOOTH_ERROR_NONE, &change,
+ user_info->cb, user_info->user_data);
+ }
+
+ g_free(change.svc_path);
+ } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
+ g_variant_get(parameters, "(&oas)",
+ &path, &interface_iter);
+
+ if (!path) {
+ BT_ERR("Invalid adapter path");
+ return;
+ }
+
+ _bt_convert_device_path_to_address(path, address);
+ _bt_convert_addr_string_to_type(change.device_addr.addr, address);
+ _bt_convert_addr_string_to_secure_string(secure_address, address);
+
+ if (_bluetooth_gatt_check_service_change_watcher_address(&change.device_addr)
+ == FALSE) {
+ BT_INFO("GATT Service [%s] removed, but no watcher for %s",
+ path, secure_address);
+ return;
+ }
+
+ while (g_variant_iter_loop(interface_iter, "s", &interface_str)) {
+ if (g_strcmp0(interface_str, GATT_SERV_INTERFACE) == 0) {
+ change.svc_path = g_strdup(path);
+ change.change_type = BLUETOOTH_GATT_SERVICE_CHANGE_TYPE_REMOVE;
+
+ BT_INFO(" ### GATT Service removed [%s] [%s]",
+ path, secure_address);
+
+ user_info = _bt_get_user_data(BT_COMMON);
+ if (user_info != NULL) {
+ _bt_common_event_cb(
+ BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED,
+ BLUETOOTH_ERROR_NONE, &change,
+ user_info->cb, user_info->user_data);
+ }
+
+ g_free(change.svc_path);
+ break;
+ }
+ }
+ g_variant_iter_free(interface_iter);
+ }
+}
+
+int _bt_register_manager_subscribe_signal(gboolean subscribe)
+{
+ GDBusConnection *g_conn;
+ static int service_added_id = -1;
+ static int interface_removed_id = -1;
+
+ g_conn = _bt_gdbus_get_system_gconn();
+ if (g_conn == NULL)
+ return BLUETOOTH_ERROR_INTERNAL;
+
+ if (subscribe == TRUE) {
+ if (service_added_id == -1) {
+ service_added_id = g_dbus_connection_signal_subscribe(g_conn,
+ NULL, GATT_SERV_INTERFACE,
+ "GattServiceAdded", NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (interface_removed_id == -1) {
+ interface_removed_id = g_dbus_connection_signal_subscribe(g_conn,
+ NULL, BT_MANAGER_INTERFACE,
+ "InterfacesRemoved", NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ } else {
+ if (service_added_id != -1) {
+ g_dbus_connection_signal_unsubscribe(g_conn,
+ service_added_id);
+ service_added_id = -1;
+ }
+ if (interface_removed_id != -1) {
+ g_dbus_connection_signal_unsubscribe(g_conn,
+ interface_removed_id);
+ interface_removed_id = -1;
+ }
+ }
return BLUETOOTH_ERROR_NONE;
}
+