Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9158ccfd authored by Rahul Arya's avatar Rahul Arya
Browse files

GD-ify ACLScheduler

Make it a separate module, and post all requests to it via a handler. No
logical changes, since it already used contextual callbacks for
everything.

Bug: 246640776
Test: all existing
Tag: #refactor
BYPASS_LONG_LINES_REASON: Bluetooth

Change-Id: I4ce8ef6b48ebef50e323cb5fad4374ba5720ba50
parent 6d3a7b3a
Loading
Loading
Loading
Loading
+3 −6
Original line number Original line Diff line number Diff line
@@ -63,7 +63,7 @@ struct AclManager::impl {
    handler_ = acl_manager_.GetHandler();
    handler_ = acl_manager_.GetHandler();
    controller_ = acl_manager_.GetDependency<Controller>();
    controller_ = acl_manager_.GetDependency<Controller>();
    round_robin_scheduler_ = new RoundRobinScheduler(handler_, controller_, hci_layer_->GetAclQueueEnd());
    round_robin_scheduler_ = new RoundRobinScheduler(handler_, controller_, hci_layer_->GetAclQueueEnd());
    acl_scheduler_ = new AclScheduler();
    acl_scheduler_ = acl_manager_.GetDependency<AclScheduler>();


    hci_queue_end_ = hci_layer_->GetAclQueueEnd();
    hci_queue_end_ = hci_layer_->GetAclQueueEnd();
    hci_queue_end_->RegisterDequeue(
    hci_queue_end_->RegisterDequeue(
@@ -78,8 +78,6 @@ struct AclManager::impl {
  }
  }


  void Stop() {
  void Stop() {
    acl_scheduler_->Stop();

    {
    {
      const std::lock_guard<std::mutex> lock(dumpsys_mutex_);
      const std::lock_guard<std::mutex> lock(dumpsys_mutex_);
      delete le_impl_;
      delete le_impl_;
@@ -88,9 +86,6 @@ struct AclManager::impl {
      classic_impl_ = nullptr;
      classic_impl_ = nullptr;
    }
    }


    delete acl_scheduler_;
    acl_scheduler_ = nullptr;

    hci_queue_end_->UnregisterDequeue();
    hci_queue_end_->UnregisterDequeue();
    delete round_robin_scheduler_;
    delete round_robin_scheduler_;
    if (enqueue_registered_.exchange(false)) {
    if (enqueue_registered_.exchange(false)) {
@@ -99,6 +94,7 @@ struct AclManager::impl {
    hci_queue_end_ = nullptr;
    hci_queue_end_ = nullptr;
    handler_ = nullptr;
    handler_ = nullptr;
    hci_layer_ = nullptr;
    hci_layer_ = nullptr;
    acl_scheduler_ = nullptr;
  }
  }


  // Invoked from some external Queue Reactable context 2
  // Invoked from some external Queue Reactable context 2
@@ -325,6 +321,7 @@ void AclManager::ListDependencies(ModuleList* list) const {
  list->add<HciLayer>();
  list->add<HciLayer>();
  list->add<Controller>();
  list->add<Controller>();
  list->add<storage::StorageModule>();
  list->add<storage::StorageModule>();
  list->add<AclScheduler>();
}
}


void AclManager::Start() {
void AclManager::Start() {
+19 −5
Original line number Original line Diff line number Diff line
@@ -103,16 +103,19 @@ struct AclScheduler::impl {
  bool stopped_ = false;
  bool stopped_ = false;
};
};


const ModuleFactory AclScheduler::Factory = ModuleFactory([]() { return new AclScheduler(); });

AclScheduler::AclScheduler() : pimpl_(std::make_unique<impl>()){};
AclScheduler::AclScheduler() : pimpl_(std::make_unique<impl>()){};
AclScheduler::~AclScheduler() = default;
AclScheduler::~AclScheduler() = default;


void AclScheduler::EnqueueOutgoingAclConnection(
void AclScheduler::EnqueueOutgoingAclConnection(
    Address address, common::ContextualOnceCallback<void()> start_connection) {
    Address address, common::ContextualOnceCallback<void()> start_connection) {
  pimpl_->EnqueueOutgoingAclConnection(address, std::move(start_connection));
  GetHandler()->Call(
      &impl::EnqueueOutgoingAclConnection, common::Unretained(pimpl_.get()), address, std::move(start_connection));
}
}


void AclScheduler::RegisterPendingIncomingConnection(Address address) {
void AclScheduler::RegisterPendingIncomingConnection(Address address) {
  pimpl_->RegisterPendingIncomingConnection(address);
  GetHandler()->Call(&impl::RegisterPendingIncomingConnection, common::Unretained(pimpl_.get()), address);
}
}


void AclScheduler::ReportAclConnectionCompletion(
void AclScheduler::ReportAclConnectionCompletion(
@@ -120,7 +123,9 @@ void AclScheduler::ReportAclConnectionCompletion(
    common::ContextualOnceCallback<void()> handle_outgoing_connection,
    common::ContextualOnceCallback<void()> handle_outgoing_connection,
    common::ContextualOnceCallback<void()> handle_incoming_connection,
    common::ContextualOnceCallback<void()> handle_incoming_connection,
    common::ContextualOnceCallback<void(std::string)> handle_unknown_connection) {
    common::ContextualOnceCallback<void(std::string)> handle_unknown_connection) {
  pimpl_->ReportAclConnectionCompletion(
  GetHandler()->Call(
      &impl::ReportAclConnectionCompletion,
      common::Unretained(pimpl_.get()),
      address,
      address,
      std::move(handle_outgoing_connection),
      std::move(handle_outgoing_connection),
      std::move(handle_incoming_connection),
      std::move(handle_incoming_connection),
@@ -128,16 +133,25 @@ void AclScheduler::ReportAclConnectionCompletion(
}
}


void AclScheduler::ReportOutgoingAclConnectionFailure() {
void AclScheduler::ReportOutgoingAclConnectionFailure() {
  pimpl_->ReportOutgoingAclConnectionFailure();
  GetHandler()->Call(&impl::ReportOutgoingAclConnectionFailure, common::Unretained(pimpl_.get()));
}
}


void AclScheduler::CancelAclConnection(
void AclScheduler::CancelAclConnection(
    Address address,
    Address address,
    common::ContextualOnceCallback<void()> cancel_connection,
    common::ContextualOnceCallback<void()> cancel_connection,
    common::ContextualOnceCallback<void()> cancel_connection_completed) {
    common::ContextualOnceCallback<void()> cancel_connection_completed) {
  pimpl_->CancelAclConnection(address, std::move(cancel_connection), std::move(cancel_connection_completed));
  GetHandler()->Call(
      &impl::CancelAclConnection,
      common::Unretained(pimpl_.get()),
      address,
      std::move(cancel_connection),
      std::move(cancel_connection_completed));
}
}


void AclScheduler::ListDependencies(ModuleList* list) const {}

void AclScheduler::Start() {}

void AclScheduler::Stop() {
void AclScheduler::Stop() {
  pimpl_->Stop();
  pimpl_->Stop();
}
}
+11 −4
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@


#include "common/contextual_callback.h"
#include "common/contextual_callback.h"
#include "hci/hci_packets.h"
#include "hci/hci_packets.h"
#include "module.h"


namespace bluetooth {
namespace bluetooth {
namespace hci {
namespace hci {
@@ -34,7 +35,7 @@ namespace acl_manager {
//
//
// However, it does not perform any actual HCI operations itself - it simply takes in callbacks, and executes them
// However, it does not perform any actual HCI operations itself - it simply takes in callbacks, and executes them
// at the appropriate time.
// at the appropriate time.
class AclScheduler {
class AclScheduler : public bluetooth::Module {
 public:
 public:
  // Schedule an ACL Create Connection request
  // Schedule an ACL Create Connection request
  void EnqueueOutgoingAclConnection(Address address, common::ContextualOnceCallback<void()> start_connection);
  void EnqueueOutgoingAclConnection(Address address, common::ContextualOnceCallback<void()> start_connection);
@@ -62,14 +63,20 @@ class AclScheduler {
      common::ContextualOnceCallback<void()> cancel_connection,
      common::ContextualOnceCallback<void()> cancel_connection,
      common::ContextualOnceCallback<void()> cancel_connection_completed);
      common::ContextualOnceCallback<void()> cancel_connection_completed);


  // Stop all queue execution. Used only prior to destruction.
  void Stop();

 private:
 private:
  struct impl;
  struct impl;
  std::unique_ptr<impl> pimpl_;
  std::unique_ptr<impl> pimpl_;


 protected:
  void ListDependencies(ModuleList* list) const override;
  void Start() override;
  void Stop() override;
  std::string ToString() const override {
    return std::string("AclSchedulerModule");
  }

 public:
 public:
  static const ModuleFactory Factory;
  AclScheduler();
  AclScheduler();
  ~AclScheduler();
  ~AclScheduler();
};
};
+2 −0
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@
#include "gd/common/strings.h"
#include "gd/common/strings.h"
#include "gd/hal/hci_hal.h"
#include "gd/hal/hci_hal.h"
#include "gd/hci/acl_manager.h"
#include "gd/hci/acl_manager.h"
#include "gd/hci/acl_manager/acl_scheduler.h"
#include "gd/hci/controller.h"
#include "gd/hci/controller.h"
#include "gd/hci/hci_layer.h"
#include "gd/hci/hci_layer.h"
#include "gd/hci/le_advertising_manager.h"
#include "gd/hci/le_advertising_manager.h"
@@ -146,6 +147,7 @@ void Stack::StartEverything() {
  modules.add<sysprops::SyspropsModule>();
  modules.add<sysprops::SyspropsModule>();


  modules.add<hci::Controller>();
  modules.add<hci::Controller>();
  modules.add<hci::acl_manager::AclScheduler>();
  modules.add<hci::AclManager>();
  modules.add<hci::AclManager>();
  if (common::init_flags::gd_l2cap_is_enabled()) {
  if (common::init_flags::gd_l2cap_is_enabled()) {
    modules.add<l2cap::classic::L2capClassicModule>();
    modules.add<l2cap::classic::L2capClassicModule>();