Loading system/gd/hci/le_address_manager.cc +28 −8 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include "common/init_flags.h" #include "hci/octets.h" #include "include/macros.h" #include "os/log.h" #include "os/rand.h" Loading @@ -29,6 +30,22 @@ namespace hci { static constexpr uint8_t BLE_ADDR_MASK = 0xc0u; enum class LeAddressManager::ClientState { WAITING_FOR_PAUSE, PAUSED, WAITING_FOR_RESUME, RESUMED, }; std::string LeAddressManager::ClientStateText(const ClientState cs) { switch (cs) { CASE_RETURN_TEXT(ClientState::WAITING_FOR_PAUSE); CASE_RETURN_TEXT(ClientState::PAUSED); CASE_RETURN_TEXT(ClientState::WAITING_FOR_RESUME); CASE_RETURN_TEXT(ClientState::RESUMED); } } LeAddressManager::LeAddressManager( common::Callback<void(std::unique_ptr<CommandBuilder>)> enqueue_command, os::Handler* handler, Loading Loading @@ -266,8 +283,8 @@ void LeAddressManager::pause_registered_clients() { case ClientState::PAUSED: case ClientState::WAITING_FOR_PAUSE: break; case WAITING_FOR_RESUME: case RESUMED: case ClientState::WAITING_FOR_RESUME: case ClientState::RESUMED: client.second = ClientState::WAITING_FOR_PAUSE; client.first->OnPause(); break; Loading @@ -289,20 +306,18 @@ void LeAddressManager::ack_pause(LeAddressManagerCallback* callback) { for (auto client : registered_clients_) { switch (client.second) { case ClientState::PAUSED: log::info("Client already in paused state"); log::verbose("Client already in paused state"); break; case ClientState::WAITING_FOR_PAUSE: // make sure all client paused log::debug("Wait all clients paused, return"); return; case WAITING_FOR_RESUME: case RESUMED: log::debug("Trigger OnPause for client that not paused and not waiting for pause"); case ClientState::WAITING_FOR_RESUME: case ClientState::RESUMED: log::warn("Trigger OnPause for client {}", ClientStateText(client.second)); client.second = ClientState::WAITING_FOR_PAUSE; client.first->OnPause(); return; default: log::error("Found client in unexpected state:{}", client.second); } } Loading @@ -320,6 +335,9 @@ void LeAddressManager::resume_registered_clients() { log::info("Resuming registered clients"); for (auto& client : registered_clients_) { if (client.second != ClientState::PAUSED) { log::warn("client is not paused {}", ClientStateText(client.second)); } client.second = ClientState::WAITING_FOR_RESUME; client.first->OnResume(); } Loading @@ -328,6 +346,8 @@ void LeAddressManager::resume_registered_clients() { void LeAddressManager::ack_resume(LeAddressManagerCallback* callback) { if (registered_clients_.find(callback) != registered_clients_.end()) { registered_clients_.find(callback)->second = ClientState::RESUMED; } else { log::info("Client not registered"); } } Loading system/gd/hci/le_address_manager.h +2 −11 Original line number Diff line number Diff line Loading @@ -110,12 +110,8 @@ class LeAddressManager { std::chrono::milliseconds maximum_rotation_time_; private: enum ClientState { WAITING_FOR_PAUSE, PAUSED, WAITING_FOR_RESUME, RESUMED, }; enum class ClientState; std::string ClientStateText(const ClientState cs); enum CommandType { ROTATE_RANDOM_ADDRESS, Loading Loading @@ -180,8 +176,6 @@ class LeAddressManager { uint8_t resolving_list_size_; std::queue<Command> cached_commands_; bool supports_ble_privacy_{false}; friend struct ::fmt::formatter<ClientState>; }; } // namespace hci Loading @@ -189,9 +183,6 @@ class LeAddressManager { namespace fmt { template <> struct formatter<bluetooth::hci::LeAddressManager::ClientState> : enum_formatter<bluetooth::hci::LeAddressManager::ClientState> {}; template <> struct formatter<bluetooth::hci::LeAddressManager::AddressPolicy> : enum_formatter<bluetooth::hci::LeAddressManager::AddressPolicy> {}; } // namespace fmt Loading
system/gd/hci/le_address_manager.cc +28 −8 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include "common/init_flags.h" #include "hci/octets.h" #include "include/macros.h" #include "os/log.h" #include "os/rand.h" Loading @@ -29,6 +30,22 @@ namespace hci { static constexpr uint8_t BLE_ADDR_MASK = 0xc0u; enum class LeAddressManager::ClientState { WAITING_FOR_PAUSE, PAUSED, WAITING_FOR_RESUME, RESUMED, }; std::string LeAddressManager::ClientStateText(const ClientState cs) { switch (cs) { CASE_RETURN_TEXT(ClientState::WAITING_FOR_PAUSE); CASE_RETURN_TEXT(ClientState::PAUSED); CASE_RETURN_TEXT(ClientState::WAITING_FOR_RESUME); CASE_RETURN_TEXT(ClientState::RESUMED); } } LeAddressManager::LeAddressManager( common::Callback<void(std::unique_ptr<CommandBuilder>)> enqueue_command, os::Handler* handler, Loading Loading @@ -266,8 +283,8 @@ void LeAddressManager::pause_registered_clients() { case ClientState::PAUSED: case ClientState::WAITING_FOR_PAUSE: break; case WAITING_FOR_RESUME: case RESUMED: case ClientState::WAITING_FOR_RESUME: case ClientState::RESUMED: client.second = ClientState::WAITING_FOR_PAUSE; client.first->OnPause(); break; Loading @@ -289,20 +306,18 @@ void LeAddressManager::ack_pause(LeAddressManagerCallback* callback) { for (auto client : registered_clients_) { switch (client.second) { case ClientState::PAUSED: log::info("Client already in paused state"); log::verbose("Client already in paused state"); break; case ClientState::WAITING_FOR_PAUSE: // make sure all client paused log::debug("Wait all clients paused, return"); return; case WAITING_FOR_RESUME: case RESUMED: log::debug("Trigger OnPause for client that not paused and not waiting for pause"); case ClientState::WAITING_FOR_RESUME: case ClientState::RESUMED: log::warn("Trigger OnPause for client {}", ClientStateText(client.second)); client.second = ClientState::WAITING_FOR_PAUSE; client.first->OnPause(); return; default: log::error("Found client in unexpected state:{}", client.second); } } Loading @@ -320,6 +335,9 @@ void LeAddressManager::resume_registered_clients() { log::info("Resuming registered clients"); for (auto& client : registered_clients_) { if (client.second != ClientState::PAUSED) { log::warn("client is not paused {}", ClientStateText(client.second)); } client.second = ClientState::WAITING_FOR_RESUME; client.first->OnResume(); } Loading @@ -328,6 +346,8 @@ void LeAddressManager::resume_registered_clients() { void LeAddressManager::ack_resume(LeAddressManagerCallback* callback) { if (registered_clients_.find(callback) != registered_clients_.end()) { registered_clients_.find(callback)->second = ClientState::RESUMED; } else { log::info("Client not registered"); } } Loading
system/gd/hci/le_address_manager.h +2 −11 Original line number Diff line number Diff line Loading @@ -110,12 +110,8 @@ class LeAddressManager { std::chrono::milliseconds maximum_rotation_time_; private: enum ClientState { WAITING_FOR_PAUSE, PAUSED, WAITING_FOR_RESUME, RESUMED, }; enum class ClientState; std::string ClientStateText(const ClientState cs); enum CommandType { ROTATE_RANDOM_ADDRESS, Loading Loading @@ -180,8 +176,6 @@ class LeAddressManager { uint8_t resolving_list_size_; std::queue<Command> cached_commands_; bool supports_ble_privacy_{false}; friend struct ::fmt::formatter<ClientState>; }; } // namespace hci Loading @@ -189,9 +183,6 @@ class LeAddressManager { namespace fmt { template <> struct formatter<bluetooth::hci::LeAddressManager::ClientState> : enum_formatter<bluetooth::hci::LeAddressManager::ClientState> {}; template <> struct formatter<bluetooth::hci::LeAddressManager::AddressPolicy> : enum_formatter<bluetooth::hci::LeAddressManager::AddressPolicy> {}; } // namespace fmt