OSDN Git Service

Add gatt_disconnection_reason_text
authorChris Manton <cmanton@google.com>
Fri, 8 Jan 2021 06:52:53 +0000 (22:52 -0800)
committerChris Manton <cmanton@google.com>
Wed, 13 Jan 2021 07:15:11 +0000 (23:15 -0800)
Towards loggable code

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

Change-Id: I7e053cff0cb1ca3c2a418e2d1ae362bbc02c22e4

stack/include/gatt_api.h

index c238993..ee25653 100644 (file)
@@ -18,6 +18,9 @@
 #ifndef GATT_API_H
 #define GATT_API_H
 
+#include <base/strings/stringprintf.h>
+#include <string>
+
 #include "bt_target.h"
 #include "btm_ble_api.h"
 #include "gattdefs.h"
@@ -206,6 +209,26 @@ typedef enum : uint16_t {
   GATT_CONN_LMP_TIMEOUT = HCI_ERR_LMP_RESPONSE_TIMEOUT,
 } tGATT_DISCONN_REASON;
 
+inline std::string gatt_disconnection_reason_text(
+    const tGATT_DISCONN_REASON& reason) {
+  switch (reason) {
+    case GATT_CONN_OK:
+      return std::string("ok/unknown");
+    case GATT_CONN_L2C_FAILURE:
+      return std::string("l2cap_failure");
+    case GATT_CONN_TIMEOUT:
+      return std::string("timeout");
+    case GATT_CONN_TERMINATE_PEER_USER:
+      return std::string("remote_terminated");
+    case GATT_CONN_TERMINATE_LOCAL_HOST:
+      return std::string("local_terminated");
+    case GATT_CONN_LMP_TIMEOUT:
+      return std::string("lmp_response_timeout");
+    default:
+      return base::StringPrintf("UNKNOWN:[0x%04hx]", reason);
+  }
+}
+
 /* MAX GATT MTU size
 */
 #ifndef GATT_MAX_MTU_SIZE