X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-service%2Fbt-service-event-receiver.c;h=c8a073176c77d172f063b82a321ce6a6c4015d51;hb=1fa07edcd0e77a445700975773db3300f556caf5;hp=a980dad19690df599a172806cabc71aa6a8c869c;hpb=6b1b7c6441ff19fdf870866c431410387b552c38;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-service/bt-service-event-receiver.c b/bt-service/bt-service-event-receiver.c index a980dad..c8a0731 100644 --- a/bt-service/bt-service-event-receiver.c +++ b/bt-service/bt-service-event-receiver.c @@ -42,11 +42,8 @@ #include "bt-service-proximity.h" #include "bt-service-opp-client.h" -#include "bt-service-map-client.h" -#include "bt-service-tds.h" -#include "bt-service-otp.h" -#ifdef TIZEN_FEATURE_BT_DPM +#ifdef TIZEN_DPM_ENABLE #include "bt-service-dpm.h" #endif @@ -54,12 +51,10 @@ static GDBusConnection *manager_conn; static GDBusConnection *obexd_conn; static GDBusConnection *opc_obexd_conn; -static GDBusConnection *map_obexd_conn; static GList *p_cache_list = NULL; static guint event_id; -static guint le_scan_event_id = 0; static guint session_reinit_timer; guint nap_connected_device_count = 0; static guint hid_connected_device_count = 0; @@ -81,21 +76,17 @@ typedef enum { OBEX_PCSUITE = (1 << 6), OBEX_SYNCEVOLUTION = (1 << 7), OBEX_MAS = (1 << 8), - OBEX_MAP = (1 << 9), } bluetooth_obex_connection_type_t; void _bt_handle_property_changed_event(GVariant *msg, const char *object_path); void _bt_opc_property_changed_event(GVariant *msg, char *path); -void _bt_map_property_changed_event(GVariant *msg, const char *path); int _bt_register_service_event(GDBusConnection *g_conn, int event_type); void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type); void _bt_opp_client_event_deinit(void); -void _bt_map_client_event_deinit(void); void _bt_handle_network_client_event(GVariant *msg_iter, const char *path); void __bt_gatt_char_property_changed_event(GVariant *msg_iter, const char *path); -void _bt_map_on_transfer_finished(const char *transfer_object_path, const int error); static void __bt_free_bt_le_adv_info_t(gpointer data) { @@ -226,7 +217,7 @@ static gboolean __bt_parse_device_properties(GVariant *item, } g_free(uuid_value); } - } else if (strcasecmp(key, "ManufacturerDataLen") == 0) { + } else if (strcasecmp(key, "LegacyManufacturerDataLen") == 0) { g_variant_get(val, "q", &dev_info->manufacturer_data_len); if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) { BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len); @@ -235,7 +226,7 @@ static gboolean __bt_parse_device_properties(GVariant *item, if (dev_info->manufacturer_data_len == 0) dev_info->manufacturer_data = g_strdup(""); - } else if (strcasecmp(key, "ManufacturerData") == 0) { + } else if (strcasecmp(key, "LegacyManufacturerData") == 0) { int i = 0; int len = 0; GVariantIter *value_iter; @@ -303,7 +294,7 @@ static gboolean __bt_parse_interface(GVariant *msg, static int __bt_get_owner_info(GVariant *msg, char **name, char **previous, char **current) { - g_variant_get(msg, "(sss)", name, previous, current); + g_variant_get(msg, "(&s&s&s)", name, previous, current); return BLUETOOTH_ERROR_NONE; } @@ -353,7 +344,7 @@ gboolean _bt_discovery_finished_cb(gpointer user_data) static gboolean __bt_le_discovery_finished_cb(gpointer user_data) { int result = BLUETOOTH_ERROR_NONE; - le_scan_event_id = 0; + event_id = 0; GVariant *param = NULL; if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) { if (_bt_get_cancel_by_user() == TRUE) @@ -409,20 +400,34 @@ void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_statu BT_DBG("-"); } -gboolean __bt_handle_is_flight_mode_enabled(void) +static void __bt_device_remote_connected_properties( + bt_remote_dev_info_t *remote_dev_info, + char *address, gboolean connected) { - int is_flight_mode = 0; - int ret = -1; + int result = BLUETOOTH_ERROR_NONE; + int i; + GVariant *param = NULL; + BT_DBG("+"); - if (TIZEN_FEATURE_FLIGHTMODE_ENABLED) { - ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &is_flight_mode); - if (ret != 0) - BT_ERR("vconf_get_bool failed"); + if (remote_dev_info->uuid_count > 0) { + for (i = 0; i < remote_dev_info->uuid_count; i++) { + char *uuid = remote_dev_info->uuids[i]; + if (strcasecmp(uuid, HID_UUID) == 0) { + int event = BLUETOOTH_EVENT_NONE; - return (is_flight_mode == 0) ? FALSE : TRUE; - } else { - return FALSE; + event = (connected == TRUE) ? + BLUETOOTH_HID_CONNECTED : + BLUETOOTH_HID_DISCONNECTED; + param = g_variant_new("(is)", result, + address); + _bt_send_event(BT_HID_EVENT, event, + param); + break; + } + } } + + BT_DBG("-"); } void _bt_handle_adapter_event(GVariant *msg, const char *member) @@ -512,21 +517,18 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member) param = g_variant_new("(ii)", result, adv_handle); +#if 0 const char *sender; sender = _bt_get_adv_slot_owner(slot_id); _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT, event, param); +#else + _bt_send_event(BT_ADAPTER_EVENT, event, param); +#endif - if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED) { - char *name = g_strdup(sender); - + if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED) _bt_unregister_adv_slot_owner(slot_id); - - /* Advertising disabled, notify TDS */ - _bt_tds_handle_adv_disabled(name, adv_handle); - g_free(name); - } } else if (strcasecmp(member, "RssiEnabled") == 0) { BT_DBG("RSSI Enabled"); gboolean status = FALSE; @@ -659,10 +661,10 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) _bt_set_le_scan_status(TRUE); param = g_variant_new("(i)", result); _bt_send_event(BT_LE_ADAPTER_EVENT, - BLUETOOTH_EVENT_LE_DISCOVERY_STARTED, - param); + BLUETOOTH_EVENT_LE_DISCOVERY_STARTED, + param); } else { - if (le_scan_event_id > 0) + if (event_id > 0) continue; adapter_proxy = _bt_get_adapter_proxy(); @@ -671,10 +673,10 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) /* Need to stop searching */ ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery", - NULL, - G_DBUS_CALL_FLAGS_NONE, - DBUS_TIMEOUT, NULL, - &err); + NULL, + G_DBUS_CALL_FLAGS_NONE, + DBUS_TIMEOUT, NULL, + &err); if (err) { BT_ERR("Dbus Error %s", err->message); g_clear_error(&err); @@ -682,9 +684,9 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) if (ret) g_variant_unref(ret); - le_scan_event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY, + event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY, (GSourceFunc)__bt_le_discovery_finished_cb, NULL); - } + } } else if (strcasecmp(property, "Name") == 0) { char *name = NULL; g_variant_get(val, "&s", &name); @@ -722,6 +724,7 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, NULL, &err); + if (err != NULL) { BT_ERR("Set DiscoverableTimeout Failed: %s", err->message); g_clear_error(&err); @@ -730,8 +733,6 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) g_variant_unref(ret); } - _bt_stop_visibility_timer(); - mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE; /* Send event to application */ @@ -744,8 +745,11 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) _bt_get_discoverable_mode(&mode); /* Event will be sent by "DiscoverableTimeout" signal */ - if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) - continue; + if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) { + g_free(property); + g_variant_unref(val); + return; + } /* Send event to application */ BT_INFO("[General Discoverable]"); @@ -764,38 +768,42 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) /* Send event to application */ BT_INFO("[Limited Discoverable (Timeout %u secs)]", - _bt_get_discoverable_timeout_property()); + _bt_get_discoverable_timeout_property()); param = g_variant_new("(in)", result, mode); _bt_send_event(BT_ADAPTER_EVENT, - BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED, - param); + BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED, + param); } else if (strcasecmp(property, "Powered") == 0) { - /* TODO: Need to check this operation!! */ gboolean powered = FALSE; - int bt_state; + int bt_state = VCONFKEY_BT_STATUS_OFF; + int le_state = VCONFKEY_BT_LE_STATUS_OFF; g_variant_get(val, "b", &powered); BT_DBG("Powered = %d", powered); - if (powered == FALSE) { - if (TIZEN_FEATURE_BT_USB_DONGLE) { - _bt_handle_adapter_removed(); - } else { - if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 && - bt_state != VCONFKEY_BT_STATUS_OFF) { - if (__bt_handle_is_flight_mode_enabled() == FALSE) - _bt_disable_adapter(); - else - _bt_handle_adapter_removed(); - } - } - if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 && - bt_state != VCONFKEY_BT_LE_STATUS_OFF) { - _bt_set_le_disabled(BLUETOOTH_ERROR_NONE); - } - } else { - if (TIZEN_FEATURE_BT_USB_DONGLE) - _bt_handle_adapter_added(); + +#ifdef USB_BLUETOOTH + if (powered) { + _bt_handle_adapter_added(); + continue; } + + _bt_handle_adapter_removed(); + + vconf_get_int(VCONFKEY_BT_LE_STATUS, &le_state); + if (le_state != VCONFKEY_BT_LE_STATUS_OFF) + _bt_set_le_disabled(BLUETOOTH_ERROR_NONE); +#else + if (powered) + continue; + + vconf_get_int(VCONFKEY_BT_STATUS, &bt_state); + if (bt_state != VCONFKEY_BT_STATUS_OFF) + _bt_disable_adapter(); + + vconf_get_int(VCONFKEY_BT_LE_STATUS, &le_state); + if (le_state != VCONFKEY_BT_LE_STATUS_OFF) + _bt_set_le_disabled(BLUETOOTH_ERROR_NONE); +#endif } else if (strcasecmp(property, "Connectable") == 0) { gboolean connectable = FALSE; @@ -884,7 +892,6 @@ static void __bt_obex_property_changed_event(GVariant *msg, const char *path) _bt_obex_transfer_progress(path, transferred); } - /* TODO: MAP, "Complete"? see above */ g_free(property); g_variant_unref(val); g_variant_unref(child); @@ -903,10 +910,8 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) char *property = NULL; char *address; GVariant *param = NULL; + bt_remote_dev_info_t *remote_dev_info; g_variant_iter_init(&value_iter, msg); -#ifdef TIZEN_FEATURE_BT_DPM - int desktop_state = DPM_BT_ERROR; -#endif while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) { BT_DBG("Property %s", property); if (strcasecmp(property, "Connected") == 0) { @@ -925,6 +930,15 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) BT_DBG("connected: %d", connected); BT_DBG("address: %s", address); + remote_dev_info = _bt_get_remote_device_info_by_object_path(path); + + if (remote_dev_info != NULL) { + __bt_device_remote_connected_properties( + remote_dev_info, address, + connected != BLUETOOTH_CONNECTED_LINK_NONE ? + TRUE : FALSE); + _bt_free_device_info(remote_dev_info); + } param = g_variant_new("(is)", result, address); /* Send event to application */ _bt_send_event(BT_DEVICE_EVENT, @@ -939,12 +953,11 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) _bt_convert_device_path_to_address(path, address); BT_DBG("address: %s", address); - g_free(address); - remote_dev_info = _bt_get_remote_device_info_by_object_path(path); if (remote_dev_info == NULL) { g_free(property); g_variant_unref(val); + g_free(address); return; } BT_DBG("Address type %d", remote_dev_info->addr_type); @@ -952,9 +965,9 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) if (remote_dev_info->addr_type == 0) { BT_DBG("Name %s", remote_dev_info->name); -#ifdef TIZEN_FEATURE_BT_DPM - _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state); - if (desktop_state == DPM_RESTRICTED) { +#ifdef TIZEN_DPM_ENABLE + if (_bt_dpm_get_bluetooth_desktop_connectivity_state() == + DPM_RESTRICTED) { bluetooth_device_class_t device_class; _bt_divide_device_class(&device_class, remote_dev_info->class); @@ -963,6 +976,7 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) _bt_free_device_info(remote_dev_info); g_free(property); g_variant_unref(val); + g_free(address); return; } } @@ -999,6 +1013,7 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND, param); + g_free(address); } _bt_free_device_info(remote_dev_info); } else if (strcasecmp(property, "GattConnected") == 0) { @@ -1069,17 +1084,9 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 }; _bt_convert_addr_string_to_secure_string(secure_addr, address); - BT_INFO("### Paired: %s", secure_addr); + BT_INFO(" ### Paired: %s", secure_addr); __bt_update_remote_cache_devinfo(address, TRUE); - if (_bt_is_device_creating() == TRUE) { - BT_DBG("Try to Pair by me"); - _bt_free_device_info(remote_dev_info); - g_free(address); - g_free(property); - g_variant_unref(val); - return; - } GVariant *uuids = NULL; GVariantBuilder *builder = NULL; int i = 0; @@ -1152,8 +1159,7 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) } BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name); - if (headed_plugin_info->plugin_headed_enabled) - headed_plugin_info->headed_plugin->bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE, + _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE, remote_dev_info->name, auth_info, NULL, NULL, NULL); _bt_free_device_info(remote_dev_info); @@ -1245,6 +1251,7 @@ static void __bt_media_control_changed_event(GVariant *msg, const char *path) char *address; GVariant *val = NULL; GVariant *child = NULL; + bt_remote_dev_info_t *remote_dev_info; GVariant *param = NULL; g_variant_iter_init(&value_iter, msg); while ((child = g_variant_iter_next_value(&value_iter))) { @@ -1265,6 +1272,13 @@ static void __bt_media_control_changed_event(GVariant *msg, const char *path) BT_DBG("connected: %d", connected); BT_DBG("address: %s", address); + remote_dev_info = _bt_get_remote_device_info(address); + + if (remote_dev_info != NULL) { + __bt_device_remote_connected_properties( + remote_dev_info, address, connected); + _bt_free_device_info(remote_dev_info); + } param = g_variant_new("(is)", result, address); /* Send event to application */ _bt_send_event(BT_AVRCP_EVENT, @@ -1297,7 +1311,7 @@ static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *pat { int result = BLUETOOTH_ERROR_NONE; int service_type; - int alert_lvl = -1; + int alert_lvl; GVariantIter value_iter; char *property = NULL; char *address; @@ -1324,8 +1338,7 @@ static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *pat service_type = BT_PXP_PROPERTY_IAS; g_variant_get(val, "s", &alert_str); - if (alert_str) - alert_lvl = get_alert_level_enum(alert_str); + alert_lvl = get_alert_level_enum(alert_str); param = g_variant_new("(isiii)", result, address, role, service_type, alert_lvl); @@ -1377,6 +1390,10 @@ void _bt_handle_property_changed_event(GVariant *msg, const char *object_path) BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE"); _bt_handle_pxp_property_changed_event(val, object_path, BT_PXP_REPORTER_ROLE); + } else if (strcasecmp(interface_name, BT_PROXIMITY_MONITOR_INTERFACE) == 0) { + BT_DBG("BT_PROXIMITY_MONITOR_INTERFACE"); + _bt_handle_pxp_property_changed_event(val, + object_path, BT_PXP_MONITOR_ROLE); } g_variant_unref(val); } @@ -1390,7 +1407,7 @@ void __bt_opc_property_changed_event(GVariant *msg, GVariant *child = NULL; g_variant_iter_init(&value_iter, msg); - if ((child = g_variant_iter_next_value(&value_iter))) { + while ((child = g_variant_iter_next_value(&value_iter))) { g_variant_get(child, "{sv}", &property, &val); ret_if(property == NULL); @@ -1437,68 +1454,6 @@ void _bt_opc_property_changed_event(GVariant *msg, char *path) } -void __bt_map_property_changed_event(GVariant *msg, - const char *path) -{ - BT_DBG("Entered"); - GVariantIter value_iter; - char *property = NULL; - GVariant *val = NULL; - GVariant *child = NULL; - - g_variant_iter_init(&value_iter, msg); - while ((child = g_variant_iter_next_value(&value_iter))) { - g_variant_get(child, "{sv}", &property, &val); - ret_if(property == NULL); - - if (strcasecmp(property, "Status") == 0) { - char *status = NULL; - g_variant_get(val, "s", &status); - BT_DBG("Status is %s", status); - - if (strcasecmp(status, "active") == 0) { - BT_DBG("EVENT : STARTED"); - // currently doing nothing - } else if (strcasecmp(status, "complete") == 0) { - BT_DBG("EVENT : COMPLETED"); - _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_NONE); - } else if (strcasecmp(status, "error") == 0) { - BT_DBG("EVENT : FAILED"); - _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_INTERNAL); - } - g_free(status); - } else if (strcasecmp(property, "Transferred") == 0) { - guint64 transferred = 0; - g_variant_get(val, "t", &transferred); - - BT_DBG("EVENT : PROGRESS CALLBACK"); - // currently doing nothing - progress callback type is not used - } else { - BT_DBG("OTHER EVENT : property : [%s]", property); - } - g_free(property); - g_variant_unref(child); - g_variant_unref(val); - } -} - -void _bt_map_property_changed_event(GVariant *msg, const char *path) -{ - BT_DBG("Entered _bt_map_property_changed_event"); - char *interface_name = NULL; - GVariant *value = NULL; - g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL); - BT_INFO("interface_name = %s", interface_name); - if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) { - __bt_map_property_changed_event(value, - path); - } else { - BT_DBG("interface_name : [%s]", interface_name); - } - g_variant_unref(value); -} - - void _bt_handle_input_event(GVariant *msg, const char *path) { int result = BLUETOOTH_ERROR_NONE; @@ -1649,8 +1604,12 @@ void __bt_gatt_char_property_changed_event(GVariant *msg, { GVariantIter value_iter; char *property = NULL; + char * char_handle = NULL; GVariant *val = NULL; + int result = BLUETOOTH_ERROR_NONE; + GVariant *param = NULL; g_variant_iter_init(&value_iter, msg); + char_handle = g_strdup(path); while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) { BT_DBG("Property %s", property); @@ -1660,24 +1619,73 @@ void __bt_gatt_char_property_changed_event(GVariant *msg, gboolean property_flag = FALSE; g_variant_get(val, "b", &property_flag); BT_INFO("Notifying is %s", property_flag ? "enabled" : "disabled"); + } else if (strcasecmp(property, "ChangedValue") == 0) { + int len = 0; + GByteArray *gp_byte_array = NULL; + BT_INFO("Type '%s'\n", g_variant_get_type_string(val)); + + if (val) { + gp_byte_array = g_byte_array_new(); + len = g_variant_get_size(val); + BT_DBG("Len = %d", len); + g_byte_array_append(gp_byte_array, + (const guint8 *) g_variant_get_data(val), len); + if (gp_byte_array->len != 0) { + GVariant *byte_array = NULL; + byte_array = g_variant_new_from_data( + G_VARIANT_TYPE_BYTESTRING, + gp_byte_array->data, + gp_byte_array->len, + TRUE, NULL, NULL); + param = g_variant_new("(is@ay)", result, char_handle, + byte_array); + + /* Send event only registered client */ + _bt_send_char_value_changed_event(param); + } + g_byte_array_free(gp_byte_array, TRUE); + } } } + g_free(char_handle); } void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path) { ret_if(path == NULL); + if (strcasecmp(member, "GattValueChanged") == 0) { - /* Check TDS seekers waiting for Indication */ - _bt_tds_check_indication(path, msg); -#ifdef TIZEN_FEATURE_BT_OTP - _bt_otp_check_indication(path, msg); + +#if 0 // Debug Only + /*** Debug only ***/ + GVariant *value = NULL; + int value_len = 0; + char *buffer = NULL; + + g_variant_get(msg, "(is@ay)", NULL, NULL, &value); + value_len = g_variant_get_size(value); + if (value_len > 0) { + char buf[8 * 5 + 1] = { 0 }; + int i; + int to; + buffer = (char *)g_variant_get_data(value); + to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len; + + for (i = 0; i < to; i++) + snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]); + buf[i * 5] = '\0'; + BT_DBG("GATT Val[%d] %s", value_len, buf); + } + g_variant_unref(value); + /******/ #endif - } else { - BT_INFO("Unhandled event"); + + /* Send event only registered client */ + _bt_send_char_value_changed_event(msg); } } + void _bt_handle_device_event(GVariant *msg, const char *member, const char *path) { int event = 0; @@ -1913,7 +1921,6 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path _bt_opp_client_is_sending(&sending); if (sending == TRUE) _bt_opp_client_check_pending_transfer(address); - /* TODO: MAP? see above */ } param = g_variant_new("(isy)", result, address, addr_type); _bt_send_event(BT_DEVICE_EVENT, @@ -1934,105 +1941,99 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path _bt_convert_addr_string_to_type(bd_addr.addr, address); _bt_convert_addr_string_to_secure_string(secure_address, address); - BT_DBG("Address: %s", secure_address); - BT_DBG("Profile UUID: %s", profile_uuid); - BT_DBG("State: %d", state); + BT_INFO_C("[%s] state: %s, addr: %s", + _bt_convert_uuid_to_string(profile_uuid), + _bt_convert_profile_state_to_string(state), secure_address); - if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) && - (state == BT_PROFILE_STATE_CONNECTED)) { + if (strcmp(profile_uuid, A2DP_SINK_UUID) == 0) { + if (state == BT_PROFILE_STATE_CONNECTED) { - int event = BLUETOOTH_EVENT_AV_CONNECTED; -#ifndef TIZEN_BT_DUAL_HEADSET_CONNECT - bluetooth_device_address_t device_address; - char connected_address[BT_ADDRESS_STRING_SIZE + 1]; - gboolean connected; -#endif - bt_headset_wait_t *wait_list; - guint trusted = TRUE; + int event = BLUETOOTH_EVENT_AV_CONNECTED; + char connected_address[BT_ADDRESS_STRING_SIZE + 1]; + bluetooth_device_address_t device_address; + gboolean connected; + bt_headset_wait_t *wait_list; + guint restricted = 0x0; - __bt_set_device_values(TRUE, - VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED); + __bt_set_device_values(TRUE, + VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED); - __bt_connection_manager_set_state(address, event); + __bt_connection_manager_set_state(address, event); - _bt_get_trust_profile(&bd_addr, TRUSTED_PROFILE_HFP_HF, &trusted); + _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted); - if (_bt_headset_get_local_connection() == FALSE) { - if (trusted == TRUE) /* not restricted*/ - _bt_start_timer_for_connection(address, BT_AUDIO_HSP); - } else { - /* Connection Started from local device therefore no need to - * intiate connection for pending profile */ - _bt_headset_set_local_connection(FALSE); - } - param = g_variant_new("(is)", result, address); - _bt_send_event(BT_HEADSET_EVENT, event, - param); -#ifdef TIZEN_BT_DUAL_HEADSET_CONNECT - _bt_check_already_connected_headset(BT_AUDIO_A2DP, - address); -#else - connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP, - connected_address); - if (connected) { - if (g_strcmp0(connected_address, address) != 0) { - _bt_convert_addr_string_to_type( - device_address.addr, - connected_address); - _bt_audio_disconnect(0, BT_AUDIO_A2DP, - &device_address, NULL); + if (_bt_headset_get_local_connection() == FALSE) { + if (restricted == 0x0) /* not restricted*/ + _bt_start_timer_for_connection(address, BT_AUDIO_HSP); + } else { + /* Connection Started from local device therefore no need to + * intiate connection for pending profile */ + _bt_headset_set_local_connection(FALSE); + } + param = g_variant_new("(is)", result, address); + _bt_send_event(BT_HEADSET_EVENT, event, + param); + connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP, + connected_address); + if (connected) { + if (g_strcmp0(connected_address, address) != 0) { + _bt_convert_addr_string_to_type( + device_address.addr, + connected_address); + _bt_audio_disconnect(0, BT_AUDIO_A2DP, + &device_address, NULL); + } } - } -#endif - _bt_add_headset_to_list(BT_AUDIO_A2DP, - BT_STATE_CONNECTED, address); - wait_list = _bt_get_audio_wait_data(); - if (wait_list != NULL && - (g_strcmp0(wait_list->address, address) == 0)) - _bt_rel_wait_data(); + _bt_add_headset_to_list(BT_AUDIO_A2DP, + BT_STATE_CONNECTED, address); - } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) && - (state == BT_PROFILE_STATE_DISCONNECTED)) { + wait_list = _bt_get_audio_wait_data(); + if (wait_list != NULL && + (g_strcmp0(wait_list->address, address) == 0)) + _bt_rel_wait_data(); - int event = BLUETOOTH_EVENT_AV_DISCONNECTED; + } else if (state == BT_PROFILE_STATE_DISCONNECTED) { - if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) { - g_free(address); - g_free(profile_uuid); - return; - } + int event = BLUETOOTH_EVENT_AV_DISCONNECTED; - __bt_set_device_values(FALSE, - VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED); + if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) { + g_free(address); + g_free(profile_uuid); + return; + } - __bt_connection_manager_set_state(address, event); - param = g_variant_new("(is)", result, address); - _bt_send_event(BT_HEADSET_EVENT, event, - param); - /* Remove data from the connected list */ - _bt_remove_headset_from_list(BT_AUDIO_A2DP, address); - wait_list = _bt_get_audio_wait_data(); + __bt_set_device_values(FALSE, + VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED); - if (wait_list == NULL) { - g_free(address); - g_free(profile_uuid); - return; - } + __bt_connection_manager_set_state(address, event); + param = g_variant_new("(is)", result, address); + _bt_send_event(BT_HEADSET_EVENT, event, + param); + /* Remove data from the connected list */ + _bt_remove_headset_from_list(BT_AUDIO_A2DP, address); + wait_list = _bt_get_audio_wait_data(); - if (((wait_list->type == BT_AUDIO_ALL) && - (wait_list->ag_flag == TRUE)) || - (wait_list->type == BT_AUDIO_A2DP) || - (wait_list->disconnection_type == BT_AUDIO_A2DP)) { - bluetooth_device_address_t device_address; - _bt_convert_addr_string_to_type( - device_address.addr, - wait_list->address); + if (wait_list == NULL) { + g_free(address); + g_free(profile_uuid); + return; + } - _bt_audio_connect(wait_list->req_id, - wait_list->type, - &device_address, - NULL); + if (((wait_list->type == BT_AUDIO_ALL) && + (wait_list->ag_flag == TRUE)) || + (wait_list->type == BT_AUDIO_A2DP) || + (wait_list->disconnection_type == BT_AUDIO_A2DP)) { + bluetooth_device_address_t device_address; + _bt_convert_addr_string_to_type( + device_address.addr, + wait_list->address); + + _bt_audio_connect(wait_list->req_id, + wait_list->type, + &device_address, + NULL); + } } } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) { @@ -2123,18 +2124,6 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path param = g_variant_new("(is)", result, address); _bt_send_event(BT_HID_EVENT, event, param); - - /* Set the vconf value for device */ - if (state == BT_PROFILE_STATE_CONNECTED) { - hid_connected_device_count++; - __bt_set_device_values(TRUE, - VCONFKEY_BT_DEVICE_HID_CONNECTED); - } else { - hid_connected_device_count--; - if (hid_connected_device_count == 0) - __bt_set_device_values(FALSE, - VCONFKEY_BT_DEVICE_HID_CONNECTED); - } } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) { if (state == BT_PROFILE_STATE_CONNECTED) { int event; @@ -2163,12 +2152,11 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t)); g_variant_get(msg, "(&syyii@ay)", &le_dev_info->address, - &le_dev_info->addr_type, - &le_dev_info->adv_type, - &le_dev_info->rssi, - &le_dev_info->adv_data_len, - &value); - + &le_dev_info->addr_type, + &le_dev_info->adv_type, + &le_dev_info->rssi, + &le_dev_info->adv_data_len, + &value); if (value == NULL) { _bt_free_le_device_info(le_dev_info); return; @@ -2239,7 +2227,6 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path } else if (strcasecmp(member, "IpspStateChanged") == 0) { gboolean connected = FALSE; char *ifname = NULL; - GVariant *ipsp_param = NULL; g_variant_get(msg, "(bs)", &connected, &ifname); @@ -2249,88 +2236,32 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path address = g_malloc0(BT_ADDRESS_STRING_SIZE); _bt_convert_device_path_to_address(path, address); - BT_DBG("Ipsp BT Interface Name: %s, address: %s", ifname, address); - + BT_DBG("Ipsp BT Interface Name: %s", ifname); + BT_DBG("address: %s", address); param = g_variant_new("(iss)", result, address, ifname); - ipsp_param = g_variant_new("(ss)", ifname, address); - - g_free(ifname); - - /* Set Ipv6 Addr */ - GDBusProxy *ipsp_proxy; - if (connected) { - BT_DBG("IPSP connected, Set Ipv6 Addr"); - ipsp_proxy = _bt_get_ipsp_proxy(); - if (ipsp_proxy == NULL) { - BT_ERR("can not get ipsp proxy"); - g_free(address); - g_variant_unref(param); - g_variant_unref(ipsp_param); - return; - } - - g_dbus_proxy_call(ipsp_proxy, "SetIpv6Addr", - ipsp_param, G_DBUS_CALL_FLAGS_NONE, - -1, NULL, NULL, NULL); - } else { - g_variant_unref(ipsp_param); - BT_DBG("IPSP disconnected"); - ipsp_proxy = _bt_get_ipsp_proxy(); - if (ipsp_proxy == NULL) { - BT_ERR("can not get ipsp proxy"); - g_free(address); - g_variant_unref(param); - return; - } - - g_dbus_proxy_call(ipsp_proxy, "DisableIpsp", - NULL, G_DBUS_CALL_FLAGS_NONE, - -1, NULL, NULL, NULL); - } /* Send event to application */ - _bt_send_event(BT_DEVICE_EVENT, event, param); - g_free(address); - } else if (strcasecmp(member, "AttMtuChanged") == 0) { - int result = BLUETOOTH_ERROR_NONE; - guint16 mtu = 0; - guint8 status = 0; - - g_variant_get(msg, "(q)", &mtu); - - address = g_malloc0(BT_ADDRESS_STRING_SIZE); - - _bt_convert_device_path_to_address(path, address); - _bt_convert_addr_string_to_secure_string(secure_address, address); - BT_DBG("Address : %s MTU changed : %d", secure_address, mtu); - - param = g_variant_new("(isqy)", - result, - address, - mtu, - status); - - /* Send the event to application */ _bt_send_event(BT_DEVICE_EVENT, - BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED, - param); - + event, + param); g_free(address); - } else if (strcasecmp(member, "OtcDisconnected") == 0) { - gboolean connected = FALSE; - GVariant *otc_param = NULL; + } else if (strcasecmp(member, "iBeaconReport") == 0) { + bt_remote_ibeacon_dev_info_t *ibeacon_dev_info = NULL; - address = g_malloc0(BT_ADDRESS_STRING_SIZE); - _bt_convert_device_path_to_address(path, address); + ret_if(_bt_is_le_scanning() == FALSE); - BT_DBG("OTC Disconnected, address: %s", address); - otc_param = g_variant_new("(ibsn)", result, connected, address); + ibeacon_dev_info = g_malloc0(sizeof(bt_remote_ibeacon_dev_info_t)); - /* Send event to application */ - _bt_send_event(BT_OTP_EVENT, - BLUETOOTH_EVENT_OTC_STATE_CHANGED, - otc_param); - g_free(address); + g_variant_get(msg, "(syuusuuy)", &ibeacon_dev_info->address, + &ibeacon_dev_info->addr_type, + &ibeacon_dev_info->company_id, + &ibeacon_dev_info->ibeacon_type, + &ibeacon_dev_info->uuid, + &ibeacon_dev_info->major_id, + &ibeacon_dev_info->minor_id, + &ibeacon_dev_info->measured_power); + _bt_send_ibeacon_scan_result_event(ibeacon_dev_info); + g_free(ibeacon_dev_info); } } @@ -2393,7 +2324,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path) int event = BLUETOOTH_EVENT_NONE; bt_headset_wait_t *wait_list; char *address; - guint trusted = TRUE; + guint restricted = 0x0; g_variant_get(value, "b", &property_flag); address = g_malloc0(BT_ADDRESS_STRING_SIZE); @@ -2403,10 +2334,10 @@ void _bt_handle_headset_event(GVariant *msg, const char *path) if (property_flag == TRUE) { event = BLUETOOTH_EVENT_AG_CONNECTED; - _bt_get_trust_profile(&bd_addr, TRUSTED_PROFILE_A2DP, &trusted); + _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted); if (_bt_headset_get_local_connection() == FALSE) { - if (trusted == TRUE) /* not restricted*/ + if (restricted == 0x0) /* not restricted*/ _bt_start_timer_for_connection(address, BT_AUDIO_A2DP); } else _bt_headset_set_local_connection(FALSE); @@ -2444,6 +2375,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path) wait_list->address); _bt_audio_connect(wait_list->req_id, wait_list->type, &device_address, NULL); + _bt_rel_wait_data(); } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) { /* Add data to the connected list */ _bt_add_headset_to_list(BT_AUDIO_HSP, @@ -2604,7 +2536,7 @@ void _bt_handle_sink_event(GVariant *msg, const char *path) if (connected) { /* Match connected device address */ if (g_strcmp0(connected_address, address) != 0) { - /* Convert BD adress from string type */ + /* Convert BD address from string type */ _bt_convert_addr_string_to_type( device_address.addr, connected_address); @@ -2638,13 +2570,10 @@ void _bt_handle_agent_event(GVariant *msg, const char *member) if (strcasecmp(member, "ObexAuthorize") == 0) { __bt_get_agent_signal_info(msg, &address, &name, &uuid); - param = g_variant_new("(iss)", result, address, name); + param = g_variant_new("(i&s&s)", result, address, name); _bt_send_event(BT_OPP_SERVER_EVENT, BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE, param); - /* TODO: MAP? see above */ - g_free(address); - g_free(name); } else if (strcasecmp(member, "RfcommAuthorize") == 0) { bt_rfcomm_server_info_t *server_info; @@ -2653,42 +2582,11 @@ void _bt_handle_agent_event(GVariant *msg, const char *member) server_info = _bt_rfcomm_get_server_info_using_uuid(uuid); ret_if(server_info == NULL); ret_if(server_info->server_type != BT_CUSTOM_SERVER); - param = g_variant_new("(isssn)", result, address, uuid, name, + param = g_variant_new("(i&s&s&sn)", result, address, uuid, name, server_info->control_fd); _bt_send_event(BT_RFCOMM_SERVER_EVENT, BLUETOOTH_EVENT_RFCOMM_AUTHORIZE, param); - g_free(address); - g_free(uuid); - g_free(name); - } -} - -void _bt_handle_tds_provider_event(GVariant *msg, const char *member, const char *path) -{ - BT_INFO("member: %s, path: %s", member, path); - - ret_if(path == NULL); - - if (strcasecmp(member, "TdsActivationRequested") == 0) { - GVariant *value = NULL; - int len = 0; - unsigned char *buffer = NULL; - unsigned char org_id; - - g_variant_get(msg, "(y@ay)", &org_id, &value); - BT_DBG("org_id: %.2x", org_id); - len = g_variant_get_size(value); - if (len > 0) { - int i; - buffer = (unsigned char *)g_variant_get_data(value); - for (i = 0; i < len; i++) - BT_DBG("%.2x", buffer[i]); - } - - /* Send event only registered client */ - _bt_tds_handle_activation_request(path, org_id, buffer, len); - g_variant_unref(value); } } @@ -2770,20 +2668,18 @@ static void __bt_manager_event_filter(GDBusConnection *connection, g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value); if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) { - if (TIZEN_FEATURE_BT_USB_DONGLE) { - BT_DBG("Enable Adapter"); - _bt_enable_adapter(); - } else { - _bt_handle_adapter_added(); - } +#ifdef USB_BLUETOOTH + BT_DBG("Enable Adapter"); + _bt_enable_adapter(); +#else + _bt_handle_adapter_added(); +#endif } else { bt_event = __bt_parse_event(value); if (bt_event == BT_DEVICE_EVENT) { bt_cache_info_t *cache_info; bt_remote_dev_info_t *dev_info; -#ifdef TIZEN_FEATURE_BT_DPM - int desktop_state = DPM_BT_ERROR; -#endif + if (_bt_is_discovering() == FALSE && _bt_is_le_scanning() == FALSE) { g_variant_unref(value); @@ -2818,9 +2714,9 @@ static void __bt_manager_event_filter(GDBusConnection *connection, */ dev_info->name = g_strdup(dev_info->address); -#ifdef TIZEN_FEATURE_BT_DPM - _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state); - if (desktop_state == DPM_RESTRICTED) { +#ifdef TIZEN_DPM_ENABLE + if (_bt_dpm_get_bluetooth_desktop_connectivity_state() == + DPM_RESTRICTED) { bluetooth_device_class_t device_class; _bt_divide_device_class(&device_class, dev_info->class); BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class); @@ -2872,10 +2768,10 @@ static void __bt_manager_event_filter(GDBusConnection *connection, } g_variant_unref(value); } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) { - if (TIZEN_FEATURE_BT_USB_DONGLE) { - BT_DBG("InterfacesRemoved"); - _bt_handle_adapter_removed(); - } +#ifdef USB_BLUETOOTH + BT_DBG("InterfacesRemoved"); + _bt_handle_adapter_removed(); +#endif if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0) bt_event = BT_MEDIA_TRANSFER_EVENT; else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) @@ -2896,28 +2792,27 @@ static void __bt_manager_event_filter(GDBusConnection *connection, char *previous = NULL; char *current = NULL; + if (g_strcmp0(g_variant_get_type_string(parameters), "(sss)") != 0) { + BT_ERR("Invalid variant format"); + return; + } + if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) { BT_ERR("Fail to get the owner info"); return; } - if (*current != '\0') { - g_free(current); - if (name) - g_free(name); - if (previous) - g_free(previous); + if (*current != '\0') + return; + + if (name == NULL) return; - } if (strcasecmp(name, BT_BLUEZ_NAME) == 0) { BT_INFO_C("### Bluetoothd is terminated"); - if (_bt_adapter_get_status() != BT_DEACTIVATING && - _bt_adapter_get_status() != BT_DEACTIVATED) { - BT_INFO_C("Turn Off Bluetooth"); - _bt_set_le_disabled(BLUETOOTH_ERROR_NONE); - _bt_disable_cb(); - } + if (_bt_adapter_get_status() == BT_ACTIVATED) + _bt_disable_cb(); + _bt_handle_adapter_removed(); __bt_devices_list_free(); _bt_service_adapter_le_deinit(); @@ -2942,18 +2837,9 @@ static void __bt_manager_event_filter(GDBusConnection *connection, /* Stop advertising started by terminated process */ _bt_stop_advertising_by_terminated_process(name); + /* Stop LE Scan */ _bt_stop_le_scan(name); - - /* Stop the Proximity reporter service */ - _bt_proximity_reporter_stop_by_terminated_process(name); - - /* Stop the Transport Discovery service */ - _bt_tds_stop_by_terminated_process(name); - - g_free(name); - g_free(previous); - g_free(current); } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) { const char *path = object_path; @@ -2969,15 +2855,15 @@ static void __bt_manager_event_filter(GDBusConnection *connection, } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) { _bt_handle_network_server_event(parameters, signal_name); } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) { - _bt_handle_headset_event(parameters, object_path); + if (g_strcmp0(signal_name, "PropertyChanged") == 0) { + _bt_handle_headset_event(parameters, object_path); + } } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) { _bt_handle_sink_event(parameters, object_path); } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) { _bt_handle_agent_event(parameters, signal_name); } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) { _bt_handle_device_event(parameters, signal_name, object_path); - } else if (g_strcmp0(interface_name, BT_TDS_PROVIDER_INTERFACE) == 0) { - _bt_handle_tds_provider_event(parameters, signal_name, object_path); } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) { _bt_handle_gatt_event(parameters, signal_name, object_path); } @@ -3023,7 +2909,6 @@ static void __bt_obexd_event_filter(GDBusConnection *connection, BT_INFO("object_path = [%s]", obj_path); /*Handle OPP_SERVER_CONNECTED_EVENT here */ - /* TODO: MAP? see above */ if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER, strlen(BT_SESSION_BASEPATH_SERVER)) != 0) { g_free(obj_path); @@ -3037,7 +2922,6 @@ static void __bt_obexd_event_filter(GDBusConnection *connection, g_free(obj_path); } else if (strcasecmp(member, "InterfacesRemoved") == 0) { /*Handle OPP_SERVER_DISCONNECTED_EVENT here */ - /* TODO: MAP? see above */ if (__bt_get_object_path(parameters, &obj_path)) { BT_ERR("Fail to get the path"); return; @@ -3157,7 +3041,7 @@ int _bt_opp_client_event_init(void) GError *error = NULL; if (opc_obexd_conn == NULL) { - opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); if (!opc_obexd_conn) { if (error) { @@ -3188,118 +3072,56 @@ void _bt_opp_client_event_deinit(void) } } -static void __bt_map_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_event_filter"); - const char *member = signal_name; - - if (strcasecmp(member, "InterfacesAdded") == 0) { - BT_DBG("------------------------------------ADDED------------------------------------"); - // currently doing nothing - } else if (strcasecmp(member, "InterfacesRemoved") == 0) { - BT_DBG("------------------------------------REMOVED------------------------------------"); - // TODO check if something should be called here? - //_bt_map_on_transfer_finished(object_path, error); - } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) { - BT_DBG("------------------------------------CLIENT EVENT------------------------------------"); - _bt_map_property_changed_event(parameters, object_path); - } - - return; -} - -int _bt_map_client_event_init(void) -{ - GError *error = NULL; - - if (map_obexd_conn == NULL) { - map_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - - if (!map_obexd_conn) { - if (error) { - BT_ERR("Unable to connect to dbus: %s", error->message); - g_clear_error(&error); - } - return BLUETOOTH_ERROR_INTERNAL; - } - } - - if (_bt_register_service_event(map_obexd_conn, - BT_MAP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) { - g_object_unref(map_obexd_conn); - map_obexd_conn = NULL; - return BLUETOOTH_ERROR_INTERNAL; - } - - return BLUETOOTH_ERROR_NONE; -} - -void _bt_map_client_event_deinit(void) -{ - if (map_obexd_conn) { - _bt_unregister_service_event(map_obexd_conn, - BT_MAP_CLIENT_EVENT); - g_object_unref(map_obexd_conn); - map_obexd_conn = NULL; - } -} - int _bt_register_manager_subscribe_signal(GDBusConnection *conn, int subscribe) { if (conn == NULL) return -1; - static guint subs_interface_added_id; - static guint subs_interface_removed_id; - static guint subs_name_owner_id; - static guint subs_property_id; - static guint subs_adapter_id; - static guint subs_gatt_id; + static int subs_interface_added_id = -1; + static int subs_interface_removed_id = -1; + static int subs_name_owner_id = -1; + static int subs_property_id = -1; + static int subs_adapter_id = -1; + static int subs_gatt_id = -1; if (subscribe) { - if (subs_interface_added_id == 0) { + if (subs_interface_added_id == -1) { subs_interface_added_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_ADDED, NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_interface_removed_id == 0) { + if (subs_interface_removed_id == -1) { subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_REMOVED, NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_name_owner_id == 0) { + if (subs_name_owner_id == -1) { subs_name_owner_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_FREEDESKTOP_INTERFACE, BT_NAME_OWNER_CHANGED, NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_property_id == 0) { + if (subs_property_id == -1) { subs_property_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_PROPERTIES_INTERFACE, BT_PROPERTIES_CHANGED, NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_adapter_id == 0) { + if (subs_adapter_id == -1) { subs_adapter_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_ADAPTER_INTERFACE, NULL, NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_gatt_id == 0) { + if (subs_gatt_id == -1) { subs_gatt_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_GATT_CHAR_INTERFACE, NULL, NULL, NULL, 0, @@ -3307,33 +3129,33 @@ int _bt_register_manager_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_interface_added_id > 0) { + if (subs_interface_added_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_interface_added_id); - subs_interface_added_id = 0; + subs_interface_added_id = -1; } - if (subs_interface_removed_id > 0) { + if (subs_interface_removed_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_interface_removed_id); - subs_interface_removed_id = 0; + subs_interface_removed_id = -1; } - if (subs_name_owner_id > 0) { + if (subs_name_owner_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_name_owner_id); - subs_name_owner_id = 0; + subs_name_owner_id = -1; } - if (subs_property_id > 0) { + if (subs_property_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_property_id); - subs_property_id = 0; + subs_property_id = -1; } - if (subs_adapter_id > 0) { + if (subs_adapter_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id); - subs_adapter_id = 0; + subs_adapter_id = -1; } - if (subs_gatt_id > 0) { + if (subs_gatt_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id); - subs_gatt_id = 0; + subs_gatt_id = -1; } } return 0; @@ -3345,10 +3167,10 @@ int _bt_register_device_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static guint subs_device_id = 0; + static int subs_device_id = -1; if (subscribe) { - if (subs_device_id == 0) { + if (subs_device_id == -1) { subs_device_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_DEVICE_INTERFACE, NULL, NULL, NULL, 0, @@ -3356,10 +3178,10 @@ int _bt_register_device_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_device_id > 0) { + if (subs_device_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_device_id); - subs_device_id = 0; + subs_device_id = -1; } } return 0; @@ -3371,10 +3193,10 @@ int _bt_register_input_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static int subs_input_id = 0; + static int subs_input_id = -1; if (subscribe) { - if (subs_input_id == 0) { + if (subs_input_id == -1) { subs_input_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_INPUT_INTERFACE, NULL, NULL, NULL, 0, @@ -3382,10 +3204,10 @@ int _bt_register_input_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_input_id > 0) { + if (subs_input_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_input_id); - subs_input_id = 0; + subs_input_id = -1; } } return 0; @@ -3397,18 +3219,18 @@ int _bt_register_network_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static guint subs_serv_id = 0; - static guint subs_client_id = 0; + static int subs_serv_id = -1; + static int subs_client_id = -1; if (subscribe) { - if (subs_serv_id == 0) { + if (subs_serv_id == -1) { subs_serv_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_NETWORK_SERVER_INTERFACE, NULL, NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_client_id == 0) { + if (subs_client_id == -1) { subs_client_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_NETWORK_CLIENT_INTERFACE, NULL, NULL, NULL, 0, @@ -3416,15 +3238,15 @@ int _bt_register_network_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_serv_id > 0) { + if (subs_serv_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_serv_id); - subs_serv_id = 0; + subs_serv_id = -1; } - if (subs_client_id > 0) { + if (subs_client_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_client_id); - subs_client_id = 0; + subs_client_id = -1; } } return 0; @@ -3436,18 +3258,18 @@ int _bt_register_audio_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static guint subs_headset_id = 0; - static guint subs_sink_id = 0; + static int subs_headset_id = -1; + static int subs_sink_id = -1; if (subscribe) { - if (subs_headset_id == 0) { + if (subs_headset_id == -1) { subs_headset_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_HEADSET_INTERFACE, - NULL, NULL, NULL, 0, + "PropertyChanged", NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_sink_id == 0) { + if (subs_sink_id == -1) { subs_sink_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_SINK_INTERFACE, NULL, NULL, NULL, 0, @@ -3455,15 +3277,15 @@ int _bt_register_audio_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_headset_id > 0) { + if (subs_headset_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_headset_id); - subs_headset_id = 0; + subs_headset_id = -1; } - if (subs_sink_id > 0) { + if (subs_sink_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_sink_id); - subs_sink_id = 0; + subs_sink_id = -1; } } return 0; @@ -3475,27 +3297,27 @@ int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static guint subs_opp_server_interface_added_id = 0; - static guint subs_opp_server_interface_removed_id = 0; - static guint subs_opp_server_property_id = 0; + static int subs_opp_server_interface_added_id = -1; + static int subs_opp_server_interface_removed_id = -1; + static int subs_opp_server_property_id = -1; if (subscribe) { - if (subs_opp_server_interface_added_id == 0) { + if (subs_opp_server_interface_added_id == -1) { subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_ADDED, NULL, NULL, 0, __bt_obexd_event_filter, NULL, NULL); } - if (subs_opp_server_interface_removed_id == 0) { + if (subs_opp_server_interface_removed_id == -1) { subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_REMOVED, NULL, NULL, 0, __bt_obexd_event_filter, NULL, NULL); } - if (subs_opp_server_property_id == 0) { + if (subs_opp_server_property_id == -1) { subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_PROPERTIES_INTERFACE, BT_PROPERTIES_CHANGED, NULL, NULL, 0, @@ -3503,20 +3325,20 @@ int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_opp_server_interface_added_id > 0) { + if (subs_opp_server_interface_added_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_opp_server_interface_added_id); - subs_opp_server_interface_added_id = 0; + subs_opp_server_interface_added_id = -1; } - if (subs_opp_server_interface_removed_id > 0) { + if (subs_opp_server_interface_removed_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_opp_server_interface_removed_id); - subs_opp_server_interface_removed_id = 0; + subs_opp_server_interface_removed_id = -1; } - if (subs_opp_server_property_id > 0) { + if (subs_opp_server_property_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_opp_server_property_id); - subs_opp_server_property_id = 0; + subs_opp_server_property_id = -1; } } return 0; @@ -3528,27 +3350,27 @@ int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static guint subs_opp_client_interface_added_id = 0; - static guint subs_opp_client_interface_removed_id = 0; - static guint subs_opp_client_property_id = 0; + static int subs_opp_client_interface_added_id = -1; + static int subs_opp_client_interface_removed_id = -1; + static int subs_opp_client_property_id = -1; if (subscribe) { - if (subs_opp_client_interface_added_id == 0) { + if (subs_opp_client_interface_added_id == -1) { subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_ADDED, NULL, NULL, 0, __bt_opc_event_filter, NULL, NULL); } - if (subs_opp_client_interface_removed_id == 0) { + if (subs_opp_client_interface_removed_id == -1) { subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_REMOVED, NULL, NULL, 0, __bt_opc_event_filter, NULL, NULL); } - if (subs_opp_client_property_id == 0) { + if (subs_opp_client_property_id == -1) { subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_PROPERTIES_INTERFACE, BT_PROPERTIES_CHANGED, NULL, NULL, 0, @@ -3556,73 +3378,20 @@ int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_opp_client_interface_added_id > 0) { + if (subs_opp_client_interface_added_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_opp_client_interface_added_id); - subs_opp_client_interface_added_id = 0; + subs_opp_client_interface_added_id = -1; } - if (subs_opp_client_interface_removed_id > 0) { + if (subs_opp_client_interface_removed_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_opp_client_interface_removed_id); - subs_opp_client_interface_removed_id = 0; + subs_opp_client_interface_removed_id = -1; } - if (subs_opp_client_property_id > 0) { + if (subs_opp_client_property_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_opp_client_property_id); - subs_opp_client_property_id = 0; - } - } - return 0; -} - -int _bt_register_map_client_subscribe_signal(GDBusConnection *conn, - int subscribe) -{ - if (conn == NULL) - return -1; - - static guint subs_map_client_interface_added_id = 0; - static guint subs_map_client_interface_removed_id = 0; - static guint subs_map_client_property_id = 0; - - - if (subscribe) { - if (subs_map_client_interface_added_id == 0) { - subs_map_client_interface_added_id = g_dbus_connection_signal_subscribe(conn, - NULL, BT_MANAGER_INTERFACE, - BT_INTERFACES_ADDED, NULL, NULL, 0, - __bt_map_event_filter, - NULL, NULL); - } - if (subs_map_client_interface_removed_id == 0) { - subs_map_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn, - NULL, BT_MANAGER_INTERFACE, - BT_INTERFACES_REMOVED, NULL, NULL, 0, - __bt_map_event_filter, - NULL, NULL); - } - if (subs_map_client_property_id == 0) { - subs_map_client_property_id = g_dbus_connection_signal_subscribe(conn, - NULL, BT_PROPERTIES_INTERFACE, - BT_PROPERTIES_CHANGED, NULL, NULL, 0, - __bt_map_event_filter, - NULL, NULL); - } - } else { - if (subs_map_client_interface_added_id > 0) { - g_dbus_connection_signal_unsubscribe(conn, - subs_map_client_interface_added_id); - subs_map_client_interface_added_id = 0; - } - if (subs_map_client_interface_removed_id > 0) { - g_dbus_connection_signal_unsubscribe(conn, - subs_map_client_interface_removed_id); - subs_map_client_interface_removed_id = 0; - } - if (subs_map_client_property_id > 0) { - g_dbus_connection_signal_unsubscribe(conn, - subs_map_client_property_id); - subs_map_client_property_id = 0; + subs_opp_client_property_id = -1; } } return 0; @@ -3634,18 +3403,18 @@ int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static guint subs_a2dp_source_id = 0; - static guint subs_a2dp_sink_id = 0; + static int subs_a2dp_source_id = -1; + static int subs_a2dp_sink_id = -1; if (subscribe) { - if (subs_a2dp_source_id == 0) { + if (subs_a2dp_source_id == -1) { subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_A2DP_SOURCE_INTERFACE, NULL, NULL, NULL, 0, __bt_opc_event_filter, NULL, NULL); } - if (subs_a2dp_sink_id == 0) { + if (subs_a2dp_sink_id == -1) { subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_SINK_INTERFACE, NULL, NULL, NULL, 0, @@ -3653,46 +3422,20 @@ int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_a2dp_source_id > 0) { + if (subs_a2dp_source_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_a2dp_source_id); - subs_a2dp_source_id = 0; + subs_a2dp_source_id = -1; } - if (subs_a2dp_sink_id > 0) { + if (subs_a2dp_sink_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_a2dp_sink_id); - subs_a2dp_sink_id = 0; + subs_a2dp_sink_id = -1; } } return 0; } -int _bt_register_tds_provider_subscribe_signal(GDBusConnection *conn, int subscribe) -{ - if (conn == NULL) - return -1; - - static guint subs_custom_id = 0; - - if (subscribe) { - if (subs_custom_id == 0) { - subs_custom_id = g_dbus_connection_signal_subscribe(conn, - NULL, BT_TDS_PROVIDER_INTERFACE, - NULL, NULL, NULL, 0, - __bt_manager_event_filter, - NULL, NULL); - } - } else { - if (subs_custom_id > 0) { - g_dbus_connection_signal_unsubscribe(conn, - subs_custom_id); - subs_custom_id = 0; - } - } - - return 0; -} - static void __bt_dump_event_filter(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, @@ -3710,10 +3453,10 @@ int __bt_register_dump_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static guint subs_source_id = 0; + static int subs_source_id = -1; if (subscribe) { - if (subs_source_id == 0) { + if (subs_source_id == -1) { subs_source_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_DUMP_SERVICE_INTERFACE, BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0, @@ -3721,10 +3464,10 @@ int __bt_register_dump_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_source_id > 0) { + if (subs_source_id != -1) { g_dbus_connection_signal_unsubscribe(conn, subs_source_id); - subs_source_id = 0; + subs_source_id = -1; } } return 0; @@ -3752,27 +3495,19 @@ int _bt_register_service_event(GDBusConnection *g_conn, int event_type) case BT_HEADSET_EVENT: _bt_register_audio_subscribe_signal(g_conn, TRUE); break; + case BT_OPP_SERVER_EVENT: BT_ERR("BT_OPP_SERVER_EVENT: register service event"); _bt_register_opp_server_subscribe_signal(g_conn, TRUE); break; - case BT_OPP_CLIENT_EVENT: BT_ERR("BT_OPP_CLIENT_EVENT: register service event"); _bt_register_opp_client_subscribe_signal(g_conn, TRUE); break; - case BT_MAP_CLIENT_EVENT: - BT_ERR("BT_MAP_CLIENT_EVENT: register service event"); - _bt_register_map_client_subscribe_signal(g_conn, TRUE); - break; case BT_A2DP_SOURCE_EVENT: BT_INFO("A2dp Source event"); _bt_register_a2dp_subscribe_signal(g_conn, TRUE); break; - case BT_TDS_EVENT: - BT_INFO("TDS provider event"); - _bt_register_tds_provider_subscribe_signal(g_conn, TRUE); - break; default: BT_ERR("Unknown event"); return BLUETOOTH_ERROR_INTERNAL; @@ -3801,9 +3536,6 @@ void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type) case BT_OPP_CLIENT_EVENT: _bt_register_opp_client_subscribe_signal(g_conn, FALSE); break; - case BT_MAP_CLIENT_EVENT: - _bt_register_map_client_subscribe_signal(g_conn, FALSE); - break; default: BT_ERR("Unknown event"); return; @@ -3846,10 +3578,6 @@ static int __bt_init_manager_receiver(void) BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE) goto fail; - if (_bt_register_service_event(manager_conn, - BT_TDS_EVENT) != BLUETOOTH_ERROR_NONE) - goto fail; - __bt_register_dump_subscribe_signal(manager_conn, TRUE); return BLUETOOTH_ERROR_NONE; fail: @@ -3866,26 +3594,26 @@ fail: static int __bt_init_obexd_receiver(void) { BT_DBG("+"); - if (!TIZEN_PROFILE_TV) { /* TODO: obexd doesn't work in TV profile. It should be resolved later. */ - GError *error = NULL; +#ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */ + GError *error = NULL; - if (obexd_conn == NULL) { - obexd_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (error != NULL) { - BT_ERR("ERROR: Can't get on session bus [%s]", error->message); - g_clear_error(&error); - } - retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL); + if (obexd_conn == NULL) { + obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); + if (error != NULL) { + BT_ERR("ERROR: Can't get on session bus [%s]", error->message); + g_clear_error(&error); } + retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL); + } - if (_bt_register_service_event(obexd_conn, - BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) { - BT_ERR("Error while registering service event"); - g_object_unref(obexd_conn); - obexd_conn = NULL; - return BLUETOOTH_ERROR_INTERNAL; - } + if (_bt_register_service_event(obexd_conn, + BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) { + BT_ERR("Error while registering service event"); + g_object_unref(obexd_conn); + obexd_conn = NULL; + return BLUETOOTH_ERROR_INTERNAL; } +#endif BT_DBG("-"); return BLUETOOTH_ERROR_NONE; @@ -3972,10 +3700,5 @@ void _bt_deinit_service_event_receiver(void) g_source_remove(event_id); event_id = 0; - if (le_scan_event_id > 0) - g_source_remove(le_scan_event_id); - le_scan_event_id = 0; - BT_DBG("-"); } -