Bluetooth: GATT: Add support for static services

This reintroduces support for static service in the form of a new API,
BT_GATT_SERVICE_DEFINE, and changes the internal services (GAP/GATT)
to be defined as const as they are never register/unregistered.

Internal service needed to be renamed in order to keep the same order
as before since the section elements are sorted by name.

The result is the following (make ram_report):

before:
      gatt.c                                    572     0.66%
        cf_cfg                                   32     0.04%
        db                                        8     0.01%
        db_hash                                  16     0.02%
        db_hash_work                             32     0.04%
        gap_attrs				180     0.21%
        gap_svc                                  12     0.01%
        gatt_attrs                              160     0.18%
        gatt_sc                                  80     0.09%
        gatt_svc                                 12     0.01%
        sc_ccc_cfg                               32     0.04%
        subscriptions                             8     0.01%

after:
      gatt.c                                    210     0.24%
        cf_cfg                                   32     0.04%
        db                                        8     0.01%
        db_hash                                  16     0.02%
        db_hash_work                             32     0.04%
        gatt_sc                                  80     0.09%
        last_static_handle                        2     0.00%
        sc_ccc_cfg                               32     0.04%
        subscriptions                             8     0.01%

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2019-04-15 15:42:50 +03:00 committed by Johan Hedberg
commit e0f3ab6bf2
4 changed files with 139 additions and 45 deletions

View file

@ -152,6 +152,14 @@ struct bt_gatt_attr {
u8_t perm;
};
/** @brief GATT Service structure */
struct bt_gatt_service_static {
/** Service Attributes */
const struct bt_gatt_attr *attrs;
/** Service Attribute count */
size_t attr_count;
};
/** @brief GATT Service structure */
struct bt_gatt_service {
/** Service Attributes */
@ -391,6 +399,19 @@ ssize_t bt_gatt_attr_read_service(struct bt_conn *conn,
const struct bt_gatt_attr *attr,
void *buf, u16_t len, u16_t offset);
/** @def BT_GATT_SERVICE_DEFINE
* @brief Statically define and register a service.
*
* Helper macro to statically define and register a service.
*
* @param _name Service name.
*/
#define BT_GATT_SERVICE_DEFINE(_name, ...) \
const struct bt_gatt_attr attr_##_name[] = { __VA_ARGS__ }; \
const struct bt_gatt_service_static _name __aligned(4) \
__in_section(_bt_services, static, _name) = \
BT_GATT_SERVICE(attr_##_name)
/** @def BT_GATT_SERVICE
* @brief Service Structure Declaration Macro.
*