mynewt-nimble icon indicating copy to clipboard operation
mynewt-nimble copied to clipboard

nimble/host : Feature GATT Caching

Open IshaESP opened this issue 3 years ago • 4 comments

Added GATT Caching feature support.

IshaESP avatar Oct 27 '22 06:10 IshaESP

Hi @sjanc , Can you please review this PR? It attempts on adding GATT Caching feature support.

IshaESP avatar Oct 27 '22 06:10 IshaESP

Hi,

for starter please fix CI issues, eg it looks like "bool aware_state;" is declared outside of conn object and code doesn't even compile... was this tested at all? or it is just "rebase issue" ?

sjanc avatar Oct 28 '22 08:10 sjanc

Hi, Yes the code is locally tested and it works. I missed adding some files that's why the CI is failing. The variable aware_state in inside conn object locally, maybe rebase issue. I will check all changes again.

IshaESP avatar Oct 28 '22 10:10 IshaESP

Style check summary

Our coding style is here!

nimble/host/src/ble_gattc_cache.c

@@ -95,7 +95,7 @@
 }
 
 static int
-cacheWrite(cache_handle_t handle, const char * key, const void* value, size_t length)
+cacheWrite(cache_handle_t handle, const char * key, const void * value, size_t length)
 {
     if (cache_fn.write) {
         return cache_fn.write(handle, key, value, length);
@@ -104,7 +104,7 @@
 }
 
 static int
-cacheRead(cache_handle_t handle, const char * key, void* out_value, size_t* length)
+cacheRead(cache_handle_t handle, const char * key, void * out_value, size_t * length)
 {
     if (cache_fn.read) {
         return cache_fn.read(handle, key, out_value, length);
@@ -234,7 +234,7 @@
             if (cache_env->is_open) {
                 cacheErase(cache_env->addr_fp);
                 if (cache_fn.close) {
- 		    cache_fn.close(cache_env->addr_fp);
+                    cache_fn.close(cache_env->addr_fp);
                 }
                 cache_env->is_open = false;
                 BLE_HS_LOG(DEBUG, "%s erased entire cache from NVS");
@@ -562,7 +562,7 @@
         case BLE_GATT_ATTR_TYPE_CHAR_DESCR:
             rc = ble_gattc_add_dsc_from_cache(peer_addr, nv_attr[i]);
             break;
-    
+
         default:
             break;
         }
@@ -628,13 +628,13 @@
     memset(cache_env, 0x0, sizeof(cache_env_t));
 
     if (cache_fn.open) {
-    	if ((rc = cache_fn.open(cache_addr, READWRITE, &fp)) == 0) {
+        if ((rc = cache_fn.open(cache_addr, READWRITE, &fp)) == 0) {
             cache_env->addr_fp = fp;
             cache_env->is_open = true;
 
             /* Read previously saved blob if available */
             if ((rc = cacheRead(fp, cache_key, p_buf, &length)) != 0) {
-                if(rc != 0) {
+                if (rc != 0) {
                     BLE_HS_LOG(ERROR, "%s, Line = %d, storage flash get blob data fail, err_code = 0x%x",
                              __func__, __LINE__, rc);
                 }

porting/nimble/include/nimble/storage_port.h

@@ -31,8 +31,8 @@
 typedef int (*open_cache)(const char *namespace_name, open_mode_t open_mode, cache_handle_t *out_handle);
 typedef void (*close_cache)(cache_handle_t handle);
 typedef int (*erase_all_cache)(cache_handle_t handle);
-typedef int (*write_cache)(cache_handle_t handle, const char *key, const void* value, size_t length);
-typedef int (*read_cache)(cache_handle_t handle, const char *key, void* out_value, size_t *length);
+typedef int (*write_cache)(cache_handle_t handle, const char *key, const void * value, size_t length);
+typedef int (*read_cache)(cache_handle_t handle, const char *key, void * out_value, size_t *length);
 
 struct cache_fn_mapping {
     open_cache open;

nimble/host/services/gatt/src/ble_svc_gatt.c

@@ -43,28 +43,31 @@
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
         .uuid = BLE_UUID16_DECLARE(BLE_GATT_SVC_UUID16),
         .characteristics = (struct ble_gatt_chr_def[]) { {
-            .uuid = BLE_UUID16_DECLARE(BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16),
-            .access_cb = ble_svc_gatt_access,
-            .val_handle = &ble_svc_gatt_changed_val_handle,
-            .flags = BLE_GATT_CHR_F_INDICATE,
-        },
+                                                             .uuid = BLE_UUID16_DECLARE(
+                    BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16),
+                                                             .access_cb = ble_svc_gatt_access,
+                                                             .val_handle = &ble_svc_gatt_changed_val_handle,
+                                                             .flags = BLE_GATT_CHR_F_INDICATE,
+                                                         },
 #if MYNEWT_VAL(BLE_GATT_CACHING)
-        {
-            .uuid = BLE_UUID16_DECLARE(BLE_SVC_GATT_CHR_CLIENT_SUPPORTED_FEATURES_UUID16),
-            .access_cb = ble_svc_gatt_access,
-            .val_handle = &ble_svc_gatt_client_supp_feature_handle,
-            .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
-        },
-        {
-            .uuid = BLE_UUID16_DECLARE(BLE_SVC_GATT_CHR_DATABASE_HASH_UUID16),
-            .access_cb = ble_svc_gatt_access,
-            .val_handle = &ble_svc_gatt_db_hash_handle,
-            .flags = BLE_GATT_CHR_F_READ,
-        },
+                                                         {
+                                                             .uuid = BLE_UUID16_DECLARE(
+                    BLE_SVC_GATT_CHR_CLIENT_SUPPORTED_FEATURES_UUID16),
+                                                             .access_cb = ble_svc_gatt_access,
+                                                             .val_handle = &ble_svc_gatt_client_supp_feature_handle,
+                                                             .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
+                                                         },
+                                                         {
+                                                             .uuid = BLE_UUID16_DECLARE(
+                    BLE_SVC_GATT_CHR_DATABASE_HASH_UUID16),
+                                                             .access_cb = ble_svc_gatt_access,
+                                                             .val_handle = &ble_svc_gatt_db_hash_handle,
+                                                             .flags = BLE_GATT_CHR_F_READ,
+                                                         },
 #endif
-        {
-            0, /* No more characteristics in this service. */
-        } },
+                                                         {
+                                                             0, /* No more characteristics in this service. */
+                                                         } },
     },
 
     {

apache-mynewt-bot avatar Nov 02 '22 12:11 apache-mynewt-bot