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

Commit 64ecda51 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

LeAudio: Minor NumOfConnected() method cleanup

Split the NumOfConnected() method in two for better readability.

Bug: 308428860
Bug: 295972694
Test: atest --host bluetooth_le_audio_test bluetooth_le_audio_client_test  bluetooth_test_broadcaster bluetooth_test_broadcaster_state_machine bluetooth_le_audio_codec_manager_test --disable-upload-result --minimal-build --no-metrics --no-bazel-mode
Flag: EXEMPT; mechanical refactor; no functional change - confirmed with unit tests
Change-Id: Ie12c0331f4624e7de9d4aa3ce03b743937e01dc9
parent dd53fcba
Loading
Loading
Loading
Loading
+18 −13
Original line number Diff line number Diff line
@@ -83,23 +83,28 @@ bool LeAudioDeviceGroup::IsAnyDeviceConnected(void) const {

int LeAudioDeviceGroup::Size(void) const { return leAudioDevices_.size(); }

int LeAudioDeviceGroup::NumOfConnected(LeAudioContextType context_type) const {
  if (leAudioDevices_.empty()) return 0;

  bool check_context_type = (context_type != LeAudioContextType::RFU);
  AudioContexts type_set(context_type);

int LeAudioDeviceGroup::NumOfConnected() const {
  /* return number of connected devices from the set*/
  return std::count_if(
      leAudioDevices_.begin(), leAudioDevices_.end(),
      [type_set, check_context_type](auto& iter) {
      leAudioDevices_.begin(), leAudioDevices_.end(), [](auto& iter) {
        auto dev = iter.lock();
        if (dev) {
          if (dev->conn_id_ == GATT_INVALID_CONN_ID) return false;
          if (dev->GetConnectionState() != DeviceConnectState::CONNECTED)
          return (dev->conn_id_ != GATT_INVALID_CONN_ID) &&
                 (dev->GetConnectionState() == DeviceConnectState::CONNECTED);
        }
        return false;
          if (!check_context_type) return true;
          return dev->GetSupportedContexts().test_any(type_set);
      });
}

int LeAudioDeviceGroup::NumOfConnected(LeAudioContextType context_type) const {
  /* return number of connected devices from the set with supported context */
  return std::count_if(
      leAudioDevices_.begin(), leAudioDevices_.end(), [&](auto& iter) {
        auto dev = iter.lock();
        if (dev) {
          return (dev->conn_id_ != GATT_INVALID_CONN_ID) &&
                 (dev->GetConnectionState() == DeviceConnectState::CONNECTED) &&
                 dev->GetSupportedContexts().test(context_type);
        }
        return false;
      });
+2 −2
Original line number Diff line number Diff line
@@ -151,8 +151,8 @@ class LeAudioDeviceGroup {
  bool IsEmpty(void) const;
  bool IsAnyDeviceConnected(void) const;
  int Size(void) const;
  int NumOfConnected(types::LeAudioContextType context_type =
                         types::LeAudioContextType::RFU) const;
  int NumOfConnected() const;
  int NumOfConnected(types::LeAudioContextType context_type) const;
  bool Activate(types::LeAudioContextType context_type,
                const types::BidirectionalPair<types::AudioContexts>&
                    metadata_context_types,