From: Chris Manton Date: Thu, 15 Oct 2020 17:15:23 +0000 (-0700) Subject: Enum-ify bta/av/bta_av_int::BTA_AV_RS_ X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=280b55e8263977fac5920717331ef80e62bd032e;p=android-x86%2Fsystem-bt.git Enum-ify bta/av/bta_av_int::BTA_AV_RS_ Also add BtaAvRoleSwitchText Towards readable and loggable code Bug: 163134718 Tag: #refactor Test: gd/cert/run --host Change-Id: I334e82ed2d5bb7860b4089b2f2c00158bfb7c2f3 --- diff --git a/bta/av/bta_av_int.h b/bta/av/bta_av_int.h index d57c182c6..04e51cd5a 100644 --- a/bta/av/bta_av_int.h +++ b/bta/av/bta_av_int.h @@ -32,6 +32,10 @@ #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;