Skip to content
Snippets Groups Projects
Commit bcd042c2 authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Gerrit Code Review
Browse files

Merge "le_impl: add direct_connect_add and direct_connect_remove" into main

parents 4588d3ad 37257d13
No related branches found
No related tags found
No related merge requests found
......@@ -328,10 +328,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
}
connecting_le_.clear();
if (create_connection_timeout_alarms_.find(address_with_type) != create_connection_timeout_alarms_.end()) {
create_connection_timeout_alarms_.at(address_with_type).Cancel();
create_connection_timeout_alarms_.erase(address_with_type);
}
direct_connect_remove(address_with_type);
}
void on_le_connection_complete(LeMetaEventView packet) {
......@@ -442,11 +439,8 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
LOG_INFO(
"Received incoming connection of device in filter accept_list, %s",
ADDRESS_TO_LOGGABLE_CSTR(remote_address));
direct_connect_remove(remote_address);
remove_device_from_accept_list(remote_address);
if (create_connection_timeout_alarms_.find(remote_address) != create_connection_timeout_alarms_.end()) {
create_connection_timeout_alarms_.at(remote_address).Cancel();
create_connection_timeout_alarms_.erase(remote_address);
}
}
}
......@@ -669,6 +663,32 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
}
}
void direct_connect_add(AddressWithType address_with_type) {
direct_connections_.insert(address_with_type);
if (create_connection_timeout_alarms_.find(address_with_type) != create_connection_timeout_alarms_.end()) {
return;
}
auto emplace_result = create_connection_timeout_alarms_.emplace(
std::piecewise_construct,
std::forward_as_tuple(address_with_type.GetAddress(), address_with_type.GetAddressType()),
std::forward_as_tuple(handler_));
uint32_t connection_timeout =
os::GetSystemPropertyUint32(kPropertyDirectConnTimeout, kCreateConnectionTimeoutMs);
emplace_result.first->second.Schedule(
common::BindOnce(&le_impl::on_create_connection_timeout, common::Unretained(this), address_with_type),
std::chrono::milliseconds(connection_timeout));
}
void direct_connect_remove(AddressWithType address_with_type) {
auto it = create_connection_timeout_alarms_.find(address_with_type);
if (it != create_connection_timeout_alarms_.end()) {
it->second.Cancel();
create_connection_timeout_alarms_.erase(it);
}
direct_connections_.erase(address_with_type);
}
void add_device_to_accept_list(AddressWithType address_with_type) {
if (connections.alreadyConnected(address_with_type)) {
LOG_INFO("Device already connected, return");
......@@ -701,7 +721,6 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
}
accept_list.erase(address_with_type);
connecting_le_.erase(address_with_type);
direct_connections_.erase(address_with_type);
register_with_address_manager();
le_address_manager_->RemoveDeviceFromFilterAcceptList(
address_with_type.ToFilterAcceptListAddressType(), address_with_type.GetAddress());
......@@ -934,19 +953,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
}
if (is_direct) {
direct_connections_.insert(address_with_type);
if (create_connection_timeout_alarms_.find(address_with_type) == create_connection_timeout_alarms_.end()) {
create_connection_timeout_alarms_.emplace(
std::piecewise_construct,
std::forward_as_tuple(address_with_type.GetAddress(), address_with_type.GetAddressType()),
std::forward_as_tuple(handler_));
uint32_t connection_timeout =
os::GetSystemPropertyUint32(kPropertyDirectConnTimeout, kCreateConnectionTimeoutMs);
create_connection_timeout_alarms_.at(address_with_type)
.Schedule(
common::BindOnce(&le_impl::on_create_connection_timeout, common::Unretained(this), address_with_type),
std::chrono::milliseconds(connection_timeout));
}
direct_connect_add(address_with_type);
}
}
......@@ -996,30 +1003,22 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
void on_create_connection_timeout(AddressWithType address_with_type) {
LOG_INFO("on_create_connection_timeout, address: %s",
ADDRESS_TO_LOGGABLE_CSTR(address_with_type));
if (create_connection_timeout_alarms_.find(address_with_type) != create_connection_timeout_alarms_.end()) {
create_connection_timeout_alarms_.at(address_with_type).Cancel();
create_connection_timeout_alarms_.erase(address_with_type);
direct_connect_remove(address_with_type);
if (background_connections_.find(address_with_type) != background_connections_.end()) {
direct_connections_.erase(address_with_type);
disarm_connectability();
} else {
cancel_connect(address_with_type);
}
le_client_handler_->Post(common::BindOnce(
&LeConnectionCallbacks::OnLeConnectFail,
common::Unretained(le_client_callbacks_),
address_with_type,
ErrorCode::CONNECTION_ACCEPT_TIMEOUT));
if (background_connections_.find(address_with_type) != background_connections_.end()) {
disarm_connectability();
} else {
remove_device_from_accept_list(address_with_type);
}
le_client_handler_->Post(common::BindOnce(
&LeConnectionCallbacks::OnLeConnectFail,
common::Unretained(le_client_callbacks_),
address_with_type,
ErrorCode::CONNECTION_ACCEPT_TIMEOUT));
}
void cancel_connect(AddressWithType address_with_type) {
// Remove any alarms for this peer, if any
if (create_connection_timeout_alarms_.find(address_with_type) != create_connection_timeout_alarms_.end()) {
create_connection_timeout_alarms_.at(address_with_type).Cancel();
create_connection_timeout_alarms_.erase(address_with_type);
}
direct_connect_remove(address_with_type);
// the connection will be canceled by LeAddressManager.OnPause()
remove_device_from_accept_list(address_with_type);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment