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

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

Use fmt to build enum cases

Bug: 305066880
Test: mma -j32
Flag: EXEMPT, logging-only change
Change-Id: Ie6728e643c895b2d15cb198cdb0ec3e9281b6df8
parent 7b8db98c
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
#include "common/init_flags.h"
#include "hci/octets.h"
#include "include/macros.h"
#include "os/log.h"
#include "os/rand.h"

namespace bluetooth {
@@ -39,11 +38,12 @@ enum class LeAddressManager::ClientState {

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);
    CASE_RETURN_STRING(ClientState::WAITING_FOR_PAUSE);
    CASE_RETURN_STRING(ClientState::PAUSED);
    CASE_RETURN_STRING(ClientState::WAITING_FOR_RESUME);
    CASE_RETURN_STRING(ClientState::RESUMED);
  }
  RETURN_UNKNOWN_TYPE_STRING(ClientState, cs);
}

LeAddressManager::LeAddressManager(
+14 −0
Original line number Diff line number Diff line
@@ -16,6 +16,20 @@

#pragma once

#include <bluetooth/log.h>

#include <cstdint>
#include <string>

#define CASE_RETURN_TEXT(code) \
  case code:                   \
    return #code

#define CASE_RETURN_STRING(enumerator)         \
  case enumerator:                             \
    return fmt::format(#enumerator "(0x{:x})", \
                       static_cast<uint64_t>(enumerator))

#define RETURN_UNKNOWN_TYPE_STRING(type, variable) \
  return fmt::format("Unknown {}(0x{:x})", #type,  \
                     static_cast<uint64_t>(variable))
+1 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ cc_test {
    name: "net_test_types",
    static_libs: [
        "libbluetooth-types",
        "libbluetooth_log",
        "libchrome",
        "libosi", // strlcpy
    ],
+4 −2
Original line number Diff line number Diff line
@@ -20,13 +20,14 @@

#include <string>

#include "macros.h"

#define BT_TRANSPORT_AUTO 0
#define BT_TRANSPORT_BR_EDR 1
#define BT_TRANSPORT_LE 2
typedef uint8_t tBT_TRANSPORT;

#if __has_include(<bluetooth/log.h>)
#include "macros.h"

inline std::string bt_transport_text(const tBT_TRANSPORT& transport) {
  switch (transport) {
    CASE_RETURN_TEXT(BT_TRANSPORT_AUTO);
@@ -36,3 +37,4 @@ inline std::string bt_transport_text(const tBT_TRANSPORT& transport) {
      return base::StringPrintf("UNKNOWN[%hhu]", transport);
  }
}
#endif