Bluetooth: Add check given services is register API

Add API for chech given services is register.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
This commit is contained in:
Lingao Meng 2021-08-18 19:19:03 +08:00 committed by Carles Cufí
commit fd5c30c68b
2 changed files with 27 additions and 1 deletions

View file

@ -362,13 +362,21 @@ void bt_gatt_cb_register(struct bt_gatt_cb *cb);
int bt_gatt_service_register(struct bt_gatt_service *svc); int bt_gatt_service_register(struct bt_gatt_service *svc);
/** @brief Unregister GATT service. /** @brief Unregister GATT service.
* * *
* @param svc Service to be unregistered. * @param svc Service to be unregistered.
* *
* @return 0 in case of success or negative value in case of error. * @return 0 in case of success or negative value in case of error.
*/ */
int bt_gatt_service_unregister(struct bt_gatt_service *svc); int bt_gatt_service_unregister(struct bt_gatt_service *svc);
/** @brief Check if GATT service is registered.
*
* @param svc Service to be checked.
*
* @return true if registered or false if not register.
*/
bool bt_gatt_service_is_registered(const struct bt_gatt_service *svc);
enum { enum {
BT_GATT_ITER_STOP = 0, BT_GATT_ITER_STOP = 0,
BT_GATT_ITER_CONTINUE, BT_GATT_ITER_CONTINUE,

View file

@ -1323,6 +1323,24 @@ int bt_gatt_service_unregister(struct bt_gatt_service *svc)
return 0; return 0;
} }
bool bt_gatt_service_is_registered(const struct bt_gatt_service *svc)
{
bool registered = false;
sys_snode_t *node;
k_sched_lock();
SYS_SLIST_FOR_EACH_NODE(&db, node) {
if (&svc->node == node) {
registered = true;
break;
}
}
k_sched_unlock();
return registered;
}
#endif /* CONFIG_BT_GATT_DYNAMIC_DB */ #endif /* CONFIG_BT_GATT_DYNAMIC_DB */
ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr, ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,