OSDN Git Service

Enum-ify bta/av/bta_av_int::BTA_AV_RS_
authorChris Manton <cmanton@google.com>
Thu, 15 Oct 2020 17:15:23 +0000 (10:15 -0700)
committerChris Manton <cmanton@google.com>
Tue, 5 Jan 2021 17:51:39 +0000 (09:51 -0800)
Also add BtaAvRoleSwitchText

Towards readable and loggable code

Bug: 163134718
Tag: #refactor
Test: gd/cert/run --host

Change-Id: I334e82ed2d5bb7860b4089b2f2c00158bfb7c2f3

bta/av/bta_av_int.h

index d57c182..04e51cd 100644 (file)
 #include "osi/include/list.h"
 #include "stack/include/a2dp_api.h"
 
+#define CASE_RETURN_TEXT(code) \
+  case code:                   \
+    return #code
+
 /*****************************************************************************
  *  Constants
  ****************************************************************************/
@@ -226,13 +230,25 @@ typedef struct {
   uint16_t service_uuid;
 } tBTA_AV_API_REG;
 
-enum {
+typedef enum : uint8_t {
   BTA_AV_RS_NONE, /* straight API call */
   BTA_AV_RS_OK,   /* the role switch result - successful */
   BTA_AV_RS_FAIL, /* the role switch result - failed */
   BTA_AV_RS_DONE  /* the role switch is done - continue */
-};
-typedef uint8_t tBTA_AV_RS_RES;
+} tBTA_AV_RS_RES;
+
+inline std::string bta_av_role_switch_result_text(
+    const tBTA_AV_RS_RES& result) {
+  switch (result) {
+    CASE_RETURN_TEXT(BTA_AV_RS_NONE);
+    CASE_RETURN_TEXT(BTA_AV_RS_OK);
+    CASE_RETURN_TEXT(BTA_AV_RS_FAIL);
+    CASE_RETURN_TEXT(BTA_AV_RS_DONE);
+    default:
+      return std::string("UNKNOWN");
+  }
+}
+
 /* data type for BTA_AV_API_OPEN_EVT */
 typedef struct {
   BT_HDR hdr;