From 738aa4df92309bc958ba5e849b5c167f3bc0d7c5 Mon Sep 17 00:00:00 2001 From: Chris Manton Date: Fri, 7 May 2021 08:54:45 -0700 Subject: [PATCH] Enum-ify stack/gatt::tGATTC_OPTYPE Towards readable code Bug: 163134718 Test: gd/cert/run Tag: #refactor Change-Id: Ib44fdf887a41bdf7bbc3e8a7496b8c59800f7e19 --- stack/gatt/gatt_attr.cc | 3 ++- stack/gatt/gatt_cl.cc | 6 +++--- stack/gatt/gatt_int.h | 2 +- stack/gatt/gatt_utils.cc | 2 +- stack/include/gatt_api.h | 19 ++++++++++--------- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/stack/gatt/gatt_attr.cc b/stack/gatt/gatt_attr.cc index 06af5870a..64541a21d 100644 --- a/stack/gatt/gatt_attr.cc +++ b/stack/gatt/gatt_attr.cc @@ -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(op)) + << " status: " << status << " conn id: " << loghex(static_cast(conn_id)); if (op != GATTC_OPTYPE_READ) return; diff --git a/stack/gatt/gatt_cl.cc b/stack/gatt/gatt_cl.cc index 1c7f4dbb9..aef2d2e96 100644 --- a/stack/gatt/gatt_cl.cc +++ b/stack/gatt/gatt_cl.cc @@ -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__; diff --git a/stack/gatt/gatt_int.h b/stack/gatt/gatt_int.h index 532ddaddc..1a5980e24 100644 --- a/stack/gatt/gatt_int.h +++ b/stack/gatt/gatt_int.h @@ -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; diff --git a/stack/gatt/gatt_utils.cc b/stack/gatt/gatt_utils.cc index 6de437f33..1de25c078 100644 --- a/stack/gatt/gatt_utils.cc +++ b/stack/gatt/gatt_utils.cc @@ -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; diff --git a/stack/include/gatt_api.h b/stack/include/gatt_api.h index 841341ef4..15948ab91 100644 --- a/stack/include/gatt_api.h +++ b/stack/include/gatt_api.h @@ -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 */ -- 2.11.0