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

Commit c4c7fef3 authored by Myles Watson's avatar Myles Watson
Browse files

Separate LE connection state from callbacks

Bug: 145832107
Test: ./cert/run --host && bluetooth_test_gd
Change-Id: I1937574fe807956a1dbeb961b0dc88bc5273d739
parent 5fd14304
Loading
Loading
Loading
Loading
+238 −126

File changed.

Preview size limit exceeded, changes collapsed.

+16 −19
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ class LeConnectionManagementCallbacks {
  virtual ~LeConnectionManagementCallbacks() = default;
  virtual void OnConnectionUpdate(uint16_t connection_interval, uint16_t connection_latency,
                                  uint16_t supervision_timeout) = 0;
  virtual void OnDisconnection(ErrorCode reason) = 0;
};

class AclConnection {
@@ -121,7 +122,6 @@ class AclConnection {
  // TODO: API to change link settings ... ?

 protected:
  friend AclManager;
  AclConnection(const AclManager* acl_manager, QueueUpEnd* queue_up_end, uint16_t handle, Role role)
      : manager_(acl_manager), queue_up_end_(queue_up_end), handle_(handle), role_(role) {}
  const AclManager* manager_;
@@ -133,7 +133,7 @@ class AclConnection {

class ClassicAclConnection : public AclConnection {
 public:
  ClassicAclConnection() : AclConnection(), address_(Address::kEmpty) {}
  ClassicAclConnection() : AclConnection(), acl_connection_interface_(nullptr), address_(Address::kEmpty) {}

  virtual Address GetAddress() const {
    return address_;
@@ -189,10 +189,12 @@ class ClassicAclConnection : public AclConnection {

class LeAclConnection : public AclConnection {
 public:
  LeAclConnection()
      : AclConnection(), le_acl_connection_interface_(nullptr),
        local_address_(Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS),
        remote_address_(Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS){};
  LeAclConnection();
  LeAclConnection(const AclManager* acl_manager, QueueUpEnd* queue_up_end,
                  LeAclConnectionInterface* le_acl_connection_interface,
                  common::OnceCallback<void(DisconnectReason)> disconnect, uint16_t handle,
                  AddressWithType local_address, AddressWithType remote_address, Role role);
  ~LeAclConnection() override;

  virtual AddressWithType GetLocalAddress() const {
    return local_address_;
@@ -203,24 +205,19 @@ class LeAclConnection : public AclConnection {
  }

  virtual void RegisterCallbacks(LeConnectionManagementCallbacks* callbacks, os::Handler* handler);
  virtual void RegisterDisconnectCallback(common::OnceCallback<void(ErrorCode)> on_disconnect, os::Handler* handler);
  virtual bool Disconnect(DisconnectReason reason);
  virtual void Disconnect(DisconnectReason reason);

  virtual bool LeConnectionUpdate(uint16_t conn_interval_min, uint16_t conn_interval_max, uint16_t conn_latency,
                                  uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length,
                                  common::OnceCallback<void(ErrorCode)> done_callback, os::Handler* handler);
                                  uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length);

  // Called once before passing the connection to the client
  virtual LeConnectionManagementCallbacks* GetEventCallbacks();

  // TODO: API to change link settings ... ?

 private:
  friend AclManager;
  LeAclConnection(const AclManager* acl_manager, QueueUpEnd* queue_up_end,
                  LeAclConnectionInterface* le_acl_connection_interface, uint16_t handle, AddressWithType local_address,
                  AddressWithType remote_address, Role role)
      : AclConnection(acl_manager, queue_up_end, handle, role),
        le_acl_connection_interface_(le_acl_connection_interface), local_address_(local_address),
        remote_address_(remote_address) {}
  LeAclConnectionInterface* le_acl_connection_interface_;
  struct impl;
  struct impl* pimpl_{};
  AddressWithType local_address_;
  AddressWithType remote_address_;
  DISALLOW_COPY_AND_ASSIGN(LeAclConnection);
@@ -295,11 +292,11 @@ class AclManager : public Module {
 private:
  friend AclConnection;
  friend ClassicAclConnection;
  friend LeAclConnection;
  struct impl;
  std::unique_ptr<impl> pimpl_;

  struct acl_connection;
  struct le_acl_connection;
  DISALLOW_COPY_AND_ASSIGN(AclManager);
};

+1 −3
Original line number Diff line number Diff line
@@ -44,9 +44,7 @@ class MockLeAclConnection : public LeAclConnection {
 public:
  MOCK_METHOD(AddressWithType, GetLocalAddress, (), (const, override));
  MOCK_METHOD(AddressWithType, GetRemoteAddress, (), (const, override));
  MOCK_METHOD(void, RegisterDisconnectCallback,
              (common::OnceCallback<void(ErrorCode)> on_disconnect, os::Handler* handler), (override));
  MOCK_METHOD(bool, Disconnect, (DisconnectReason reason), (override));
  MOCK_METHOD(void, Disconnect, (DisconnectReason reason), (override));
  MOCK_METHOD(void, Finish, (), (override));
  MOCK_METHOD(void, RegisterCallbacks, (LeConnectionManagementCallbacks * callbacks, os::Handler* handler), (override));

+235 −46

File changed.

Preview size limit exceeded, changes collapsed.

+4 −0
Original line number Diff line number Diff line
@@ -206,6 +206,10 @@ class LeAclManagerFacadeService : public LeAclManagerFacade::Service, public ::b
                supervision_timeout);
    }

    void OnDisconnection(ErrorCode reason) override {
      LOG_DEBUG("reason: %s", ErrorCodeText(reason).c_str());
    }

    LeConnectionManagementCallbacks* GetCallbacks() {
      return this;
    }
Loading