OSDN Git Service

Enum-ify stack/gatt::tGATTC_OPTYPE
authorChris Manton <cmanton@google.com>
Fri, 7 May 2021 15:54:45 +0000 (08:54 -0700)
committerChris Manton <cmanton@google.com>
Sun, 9 May 2021 20:28:28 +0000 (13:28 -0700)
Towards readable code

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

Change-Id: Ib44fdf887a41bdf7bbc3e8a7496b8c59800f7e19

stack/gatt/gatt_attr.cc
stack/gatt/gatt_cl.cc
stack/gatt/gatt_int.h
stack/gatt/gatt_utils.cc
stack/include/gatt_api.h

index 06af587..64541a2 100644 (file)
@@ -572,7 +572,8 @@ static void gatt_cl_op_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op,
                                   tGATT_CL_COMPLETE* p_data) {
   auto iter = OngoingOps.find(conn_id);
 
-  VLOG(1) << __func__ << " opcode: " << loghex(op) << " status: " << status
+  VLOG(1) << __func__ << " opcode: " << loghex(static_cast<uint8_t>(op))
+          << " status: " << status
           << " conn id: " << loghex(static_cast<uint8_t>(conn_id));
 
   if (op != GATTC_OPTYPE_READ) return;
index 1c7f4db..aef2d2e 100644 (file)
@@ -626,9 +626,9 @@ void gatt_process_notification(tGATT_TCB& tcb, uint16_t cid, uint8_t op_code,
   tGATT_STATUS encrypt_status;
   uint8_t* p = p_data;
   uint8_t i;
-  uint8_t event = (op_code == GATT_HANDLE_VALUE_IND)
-                      ? GATTC_OPTYPE_INDICATION
-                      : GATTC_OPTYPE_NOTIFICATION;
+  tGATTC_OPTYPE event = (op_code == GATT_HANDLE_VALUE_IND)
+                            ? GATTC_OPTYPE_INDICATION
+                            : GATTC_OPTYPE_NOTIFICATION;
 
   VLOG(1) << __func__;
 
index 532ddad..1a5980e 100644 (file)
@@ -342,7 +342,7 @@ struct tGATT_CLCB {
   uint16_t counter; /* used as offset, attribute length, num of prepare write */
   uint16_t start_offset;
   tGATT_AUTH_REQ auth_req; /* authentication requirement */
-  uint8_t operation;       /* one logic channel can have one operation active */
+  tGATTC_OPTYPE operation; /* one logic channel can have one operation active */
   uint8_t op_subtype;      /* operation subtype */
   tGATT_STATUS status;     /* operation status */
   bool first_read_blob_after_read;
index 6de437f..1de25c0 100644 (file)
@@ -1480,7 +1480,7 @@ void gatt_end_operation(tGATT_CLCB* p_clcb, tGATT_STATUS status, void* p_data) {
   tGATT_CL_COMPLETE cb_data;
   tGATT_CMPL_CBACK* p_cmpl_cb =
       (p_clcb->p_reg) ? p_clcb->p_reg->app_cb.p_cmpl_cb : NULL;
-  uint8_t op = p_clcb->operation;
+  tGATTC_OPTYPE op = p_clcb->operation;
   tGATT_DISC_TYPE disc_type = GATT_DISC_MAX;
   tGATT_DISC_CMPL_CB* p_disc_cmpl_cb =
       (p_clcb->p_reg) ? p_clcb->p_reg->app_cb.p_disc_cmpl_cb : NULL;
index 841341e..15948ab 100644 (file)
@@ -576,15 +576,16 @@ typedef union {
 
 /* GATT client operation type, used in client callback function
 */
-#define GATTC_OPTYPE_NONE 0
-#define GATTC_OPTYPE_DISCOVERY 1
-#define GATTC_OPTYPE_READ 2
-#define GATTC_OPTYPE_WRITE 3
-#define GATTC_OPTYPE_EXE_WRITE 4
-#define GATTC_OPTYPE_CONFIG 5
-#define GATTC_OPTYPE_NOTIFICATION 6
-#define GATTC_OPTYPE_INDICATION 7
-typedef uint8_t tGATTC_OPTYPE;
+typedef enum : uint8_t {
+  GATTC_OPTYPE_NONE = 0,
+  GATTC_OPTYPE_DISCOVERY = 1,
+  GATTC_OPTYPE_READ = 2,
+  GATTC_OPTYPE_WRITE = 3,
+  GATTC_OPTYPE_EXE_WRITE = 4,
+  GATTC_OPTYPE_CONFIG = 5,
+  GATTC_OPTYPE_NOTIFICATION = 6,
+  GATTC_OPTYPE_INDICATION = 7,
+} tGATTC_OPTYPE;
 
 /* characteristic declaration
 */