OSDN Git Service

acl: Remove DisconnectorForLe
authorMyles Watson <mylesgw@google.com>
Tue, 17 Nov 2020 15:30:54 +0000 (07:30 -0800)
committerMyles Watson <mylesgw@google.com>
Tue, 17 Nov 2020 17:36:08 +0000 (09:36 -0800)
Bug: 172725986
Test: atest bluetooth_test_gd
Tag: #gd-refactor
Change-Id: Id9a5dcbba3f4be0490baa13d3ff538f0f2158c5c

gd/hci/acl_manager.cc
gd/hci/acl_manager/classic_impl.h
gd/hci/acl_manager/disconnector_for_le.h [deleted file]
gd/hci/acl_manager/le_acl_connection.cc
gd/hci/acl_manager/le_acl_connection.h
gd/hci/acl_manager/le_impl.h

index e0f66db..d1b586b 100644 (file)
@@ -61,7 +61,7 @@ struct AclManager::impl {
     hci_queue_end_->RegisterDequeue(
         handler_, common::Bind(&impl::dequeue_and_route_acl_packet_to_connection, common::Unretained(this)));
     classic_impl_ = new classic_impl(hci_layer_, controller_, handler_, round_robin_scheduler_);
-    le_impl_ = new le_impl(hci_layer_, controller_, handler_, round_robin_scheduler_, classic_impl_);
+    le_impl_ = new le_impl(hci_layer_, controller_, handler_, round_robin_scheduler_);
   }
 
   void Stop() {
index c292d50..24451d8 100644 (file)
@@ -18,7 +18,6 @@
 
 #include "common/bind.h"
 #include "hci/acl_manager/assembler.h"
-#include "hci/acl_manager/disconnector_for_le.h"
 #include "hci/acl_manager/event_checkers.h"
 #include "hci/acl_manager/round_robin_scheduler.h"
 #include "hci/controller.h"
@@ -38,7 +37,7 @@ struct acl_connection {
   ConnectionManagementCallbacks* connection_management_callbacks_ = nullptr;
 };
 
-struct classic_impl : public DisconnectorForLe, public security::ISecurityManagerListener {
+struct classic_impl : public security::ISecurityManagerListener {
   classic_impl(HciLayer* hci_layer, Controller* controller, os::Handler* handler,
                RoundRobinScheduler* round_robin_scheduler)
       : hci_layer_(hci_layer), controller_(controller), round_robin_scheduler_(round_robin_scheduler) {
diff --git a/gd/hci/acl_manager/disconnector_for_le.h b/gd/hci/acl_manager/disconnector_for_le.h
deleted file mode 100644 (file)
index cdb21c2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2020 The Android Open Source Project
- *
- * 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
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include "hci/hci_packets.h"
-
-namespace bluetooth {
-namespace hci {
-namespace acl_manager {
-
-class DisconnectorForLe {
- public:
-  DisconnectorForLe() = default;
-  virtual ~DisconnectorForLe() = default;
-  virtual void handle_disconnect(uint16_t handle, DisconnectReason reason) = 0;
-};
-
-}  // namespace acl_manager
-}  // namespace hci
-}  // namespace bluetooth
index 737c600..021864a 100644 (file)
@@ -23,9 +23,8 @@ namespace acl_manager {
 
 class LeAclConnectionTracker : public LeConnectionManagementCallbacks {
  public:
-  LeAclConnectionTracker(LeAclConnectionInterface* le_acl_connection_interface,
-                         common::OnceCallback<void(DisconnectReason reason)> disconnect)
-      : le_acl_connection_interface_(le_acl_connection_interface), do_disconnect_(std::move(disconnect)) {}
+  LeAclConnectionTracker(LeAclConnectionInterface* le_acl_connection_interface)
+      : le_acl_connection_interface_(le_acl_connection_interface) {}
   ~LeAclConnectionTracker() override {
     ASSERT(queued_callbacks_.empty());
   }
@@ -66,16 +65,14 @@ class LeAclConnectionTracker : public LeConnectionManagementCallbacks {
 #undef SAVE_OR_CALL
 
   LeAclConnectionInterface* le_acl_connection_interface_;
-  common::OnceCallback<void(DisconnectReason)> do_disconnect_;
   os::Handler* client_handler_ = nullptr;
   LeConnectionManagementCallbacks* client_callbacks_ = nullptr;
   std::list<common::OnceClosure> queued_callbacks_;
 };
 
 struct LeAclConnection::impl {
-  impl(LeAclConnectionInterface* le_acl_connection_interface, std::shared_ptr<Queue> queue,
-       common::OnceCallback<void(DisconnectReason)> disconnect)
-      : queue_(std::move(queue)), tracker(le_acl_connection_interface, std::move(disconnect)) {}
+  impl(LeAclConnectionInterface* le_acl_connection_interface, std::shared_ptr<Queue> queue)
+      : queue_(std::move(queue)), tracker(le_acl_connection_interface) {}
   LeConnectionManagementCallbacks* GetEventCallbacks() {
     ASSERT(!callbacks_given_);
     callbacks_given_ = true;
@@ -91,12 +88,18 @@ LeAclConnection::LeAclConnection()
     : AclConnection(), local_address_(Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS),
       remote_address_(Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS) {}
 
-LeAclConnection::LeAclConnection(std::shared_ptr<Queue> queue, LeAclConnectionInterface* le_acl_connection_interface,
-                                 common::OnceCallback<void(DisconnectReason)> disconnect, uint16_t handle,
-                                 AddressWithType local_address, AddressWithType remote_address, Role role)
-    : AclConnection(queue->GetUpEnd(), handle), local_address_(local_address), remote_address_(remote_address),
+LeAclConnection::LeAclConnection(
+    std::shared_ptr<Queue> queue,
+    LeAclConnectionInterface* le_acl_connection_interface,
+    uint16_t handle,
+    AddressWithType local_address,
+    AddressWithType remote_address,
+    Role role)
+    : AclConnection(queue->GetUpEnd(), handle),
+      local_address_(local_address),
+      remote_address_(remote_address),
       role_(role) {
-  pimpl_ = new LeAclConnection::impl(le_acl_connection_interface, std::move(queue), std::move(disconnect));
+  pimpl_ = new LeAclConnection::impl(le_acl_connection_interface, std::move(queue));
 }
 
 LeAclConnection::~LeAclConnection() {
@@ -109,7 +112,18 @@ void LeAclConnection::RegisterCallbacks(LeConnectionManagementCallbacks* callbac
 }
 
 void LeAclConnection::Disconnect(DisconnectReason reason) {
-  common::BindOnce(std::move(pimpl_->tracker.do_disconnect_), reason).Run();
+  pimpl_->tracker.le_acl_connection_interface_->EnqueueCommand(
+      DisconnectBuilder::Create(handle_, reason),
+      pimpl_->tracker.client_handler_->BindOnce([](CommandStatusView status) {
+        ASSERT(status.IsValid());
+        ASSERT(status.GetCommandOpCode() == OpCode::DISCONNECT);
+        auto disconnect_status = DisconnectStatusView::Create(status);
+        ASSERT(disconnect_status.IsValid());
+        auto error_code = disconnect_status.GetStatus();
+        if (error_code != ErrorCode::SUCCESS) {
+          LOG_INFO("Disconnect status %s", ErrorCodeText(error_code).c_str());
+        }
+      }));
 }
 
 LeConnectionManagementCallbacks* LeAclConnection::GetEventCallbacks() {
index c764060..05a7983 100644 (file)
@@ -29,9 +29,13 @@ namespace acl_manager {
 class LeAclConnection : public AclConnection {
  public:
   LeAclConnection();
-  LeAclConnection(std::shared_ptr<Queue> queue, LeAclConnectionInterface* le_acl_connection_interface,
-                  common::OnceCallback<void(DisconnectReason)> disconnect, uint16_t handle,
-                  AddressWithType local_address, AddressWithType remote_address, Role role);
+  LeAclConnection(
+      std::shared_ptr<Queue> queue,
+      LeAclConnectionInterface* le_acl_connection_interface,
+      uint16_t handle,
+      AddressWithType local_address,
+      AddressWithType remote_address,
+      Role role);
   ~LeAclConnection() override;
 
   virtual AddressWithType GetLocalAddress() const {
index c0569ed..ec921cb 100644 (file)
@@ -19,7 +19,6 @@
 #include "common/bind.h"
 #include "crypto_toolbox/crypto_toolbox.h"
 #include "hci/acl_manager/assembler.h"
-#include "hci/acl_manager/disconnector_for_le.h"
 #include "hci/acl_manager/round_robin_scheduler.h"
 #include "hci/le_address_manager.h"
 #include "os/alarm.h"
@@ -44,10 +43,8 @@ struct le_acl_connection {
 };
 
 struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
-  le_impl(HciLayer* hci_layer, Controller* controller, os::Handler* handler, RoundRobinScheduler* round_robin_scheduler,
-          DisconnectorForLe* disconnector)
-      : hci_layer_(hci_layer), controller_(controller), round_robin_scheduler_(round_robin_scheduler),
-        disconnector_(disconnector) {
+  le_impl(HciLayer* hci_layer, Controller* controller, os::Handler* handler, RoundRobinScheduler* round_robin_scheduler)
+      : hci_layer_(hci_layer), controller_(controller), round_robin_scheduler_(round_robin_scheduler) {
     hci_layer_ = hci_layer;
     controller_ = controller;
     handler_ = handler;
@@ -159,12 +156,9 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
     le_acl_connections_.emplace(std::piecewise_construct, std::forward_as_tuple(handle),
                                 std::forward_as_tuple(remote_address, queue->GetDownEnd(), handler_));
     auto& connection_proxy = check_and_get_le_connection(handle);
-    auto do_disconnect =
-        common::BindOnce(&DisconnectorForLe::handle_disconnect, common::Unretained(disconnector_), handle);
     round_robin_scheduler_->Register(RoundRobinScheduler::ConnectionType::LE, handle, queue);
-    std::unique_ptr<LeAclConnection> connection(new LeAclConnection(std::move(queue), le_acl_connection_interface_,
-                                                                    std::move(do_disconnect), handle, local_address,
-                                                                    remote_address, role));
+    std::unique_ptr<LeAclConnection> connection(new LeAclConnection(
+        std::move(queue), le_acl_connection_interface_, handle, local_address, remote_address, role));
     connection_proxy.le_connection_management_callbacks_ = connection->GetEventCallbacks();
     le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectSuccess,
                                               common::Unretained(le_client_callbacks_), remote_address,
@@ -223,11 +217,8 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
                                 std::forward_as_tuple(remote_address, queue->GetDownEnd(), handler_));
     auto& connection_proxy = check_and_get_le_connection(handle);
     round_robin_scheduler_->Register(RoundRobinScheduler::ConnectionType::LE, handle, queue);
-    auto do_disconnect =
-        common::BindOnce(&DisconnectorForLe::handle_disconnect, common::Unretained(disconnector_), handle);
-    std::unique_ptr<LeAclConnection> connection(new LeAclConnection(std::move(queue), le_acl_connection_interface_,
-                                                                    std::move(do_disconnect), handle, local_address,
-                                                                    remote_address, role));
+    std::unique_ptr<LeAclConnection> connection(new LeAclConnection(
+        std::move(queue), le_acl_connection_interface_, handle, local_address, remote_address, role));
     connection_proxy.le_connection_management_callbacks_ = connection->GetEventCallbacks();
     le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectSuccess,
                                               common::Unretained(le_client_callbacks_), remote_address,
@@ -600,7 +591,6 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
   std::map<uint16_t, le_acl_connection> le_acl_connections_;
   std::set<AddressWithType> connecting_le_;
   std::set<AddressWithType> canceled_connections_;
-  DisconnectorForLe* disconnector_;
   bool address_manager_registered = false;
   bool ready_to_unregister = false;
   bool pause_connection = false;