You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2022/11/01 09:03:47 UTC

[GitHub] [mynewt-nimble] apache-mynewt-bot commented on pull request #1402: nimble/host : Feature GATT Caching

apache-mynewt-bot commented on PR #1402:
URL: https://github.com/apache/mynewt-nimble/pull/1402#issuecomment-1298238277

   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/host/src/ble_gattc_cache.c
   <details>
   
   ```diff
   @@ -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);
   @@ -162,7 +162,7 @@
        if ((index = ble_gattc_cache_find_addr(*addr)) != INVALID_ADDR_NUM) {
            if (cache_env->cache_addr[index].is_open) {
                cacheErase(cache_env->cache_addr[index].cache_fp);
   -            
   +
                if (cache_fn.close) {
                    cache_fn.close(cache_env->cache_addr[index].cache_fp);
                }
   @@ -223,7 +223,7 @@
                           cache_env->cache_addr[i].hash_key, sizeof(ble_hash_key));
                }
    
   -          if (cache_env->is_open) {
   +            if (cache_env->is_open) {
                    if (cacheWrite(cache_env->addr_fp, cache_key, p_buf, length) != 0) {
                        BLE_HS_LOG(INFO, "%s, storage set blob failed", __func__);
                    }
   @@ -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");
   @@ -376,7 +376,7 @@
    
        cache_handle_t *fp = &cache_env->addr_fp;
        uint16_t length = num*(sizeof(ble_addr_t) + sizeof(hash_key_t));
   - 
   +
        for (i = 0; i < num; i++) {
    
            memcpy(p_buf + i*(sizeof(ble_addr_t) + sizeof(ble_hash_key)),
   @@ -395,7 +395,7 @@
                    BLE_HS_LOG(ERROR, "storage set blob fail, err %d", rc);
                }
            } else {
   -            rc = cache_fn.open(cache_addr, READWRITE , fp);
   +            rc = cache_fn.open(cache_addr, READWRITE, fp);
    
                if (rc == 0) {
                    cache_env->is_open = true;
   @@ -442,7 +442,7 @@
            if (cacheOpen(peer->ble_gattc_p_addr, true, &index)) {
                BLE_HS_LOG(DEBUG, "Cache Opened already \n\tWriting cache_fp and cache_key on index = %d",
                               index);
   -            rc = cacheWrite(cache_env->cache_addr[index].cache_fp, cache_key, nv_attr, 
   +            rc = cacheWrite(cache_env->cache_addr[index].cache_fp, cache_key, nv_attr,
                                num_attr * sizeof(struct ble_gatt_nv_attr));
            } else {
                rc = -1;
   @@ -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,19 +628,19 @@
        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);
                    }
                    free(p_buf);
                    return rc;
   -        }
   +            }
    
                num_addr = length / (sizeof(ble_addr_t) + sizeof(ble_hash_key));
                cache_env->num_addr = num_addr;
   ```
   
   </details>
   
   #### nimble/host/src/ble_gattc_peer.c
   <details>
   
   ```diff
   @@ -159,7 +159,7 @@
            assert(0);
            return BLE_HS_EUNKNOWN;
        }
   - 
   +
        if (chr_val_handle == 0) {
            chr = ble_gattc_p_chr_find_handle(svc, gatt_dsc->handle);
        } else {
   @@ -313,7 +313,7 @@
        if (svc == NULL) {
            /* Can't find service for discovered characteristic; this shouldn't
             * happen.
   -         */ 
   +         */
            assert(0);
            return BLE_HS_EUNKNOWN;
        }
   @@ -338,7 +338,7 @@
        } else {
            SLIST_NEXT(prev, next) = chr;
        }
   - 
   +
    #if MYNEWT_VAL(BLE_GATT_CACHING)
        ble_gattc_db_hash_chr_present(chr->chr.uuid.u16);
    #endif
   ```
   
   </details>
   
   #### porting/nimble/include/nimble/storage_port.h
   <details>
   
   ```diff
   @@ -28,11 +28,11 @@
    } open_mode_t;
    
    typedef uint32_t cache_handle_t;
   -typedef int (*open_cache)(const char* namespace_name, open_mode_t open_mode, cache_handle_t *out_handle);
   +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;
   ```
   
   </details>
   
   #### nimble/host/include/host/ble_gatt.h
   <details>
   
   ```diff
   @@ -124,14 +124,14 @@
    };
    typedef uint8_t ble_gatt_attr_type;
    
   -typedef struct ble_gatt_nv_attr{
   +typedef struct ble_gatt_nv_attr {
        uint16_t s_handle;
        uint16_t e_handle;              /* used for service only */
        ble_gatt_attr_type attr_type;
        ble_uuid16_t uuid;
        uint8_t properties;             /* used for characteristic only */
        bool is_primary;                /* used for service only */
   -}ble_gatt_nv_attr;
   +} ble_gatt_nv_attr;
    typedef unsigned char hash_key_t[4];
    #endif
    
   ```
   
   </details>
   
   #### nimble/host/services/gatt/src/ble_svc_gatt.c
   <details>
   
   ```diff
   @@ -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. */
   +                                                         } },
        },
    
        {
   ```
   
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org