Bluetooth: GATT: Replace handle with attribute object in bt_gatt_notify

This make more sense since the handles are normally self allocated by
the stack.

Change-Id: I198dd9c3ef6259cff8a0e528514918ec18990dea
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2016-01-19 13:18:21 +02:00 committed by Anas Nashif
commit d65dcc5e4b
6 changed files with 25 additions and 19 deletions

View file

@ -96,8 +96,8 @@ int bt_gatt_attr_read_cpf(struct bt_conn *conn,
return -ENOSYS; return -ENOSYS;
} }
int bt_gatt_notify(struct bt_conn *conn, uint16_t handle, const void *data, int bt_gatt_notify(struct bt_conn *conn, const struct bt_gatt_attr *attr,
uint16_t len) const void *data, uint16_t len)
{ {
return -ENOSYS; return -ENOSYS;
} }

View file

@ -670,12 +670,12 @@ int bt_gatt_attr_read_cpf(struct bt_conn *conn,
* notification only the given connection. * notification only the given connection.
* *
* @param conn Connection object. * @param conn Connection object.
* @param handle Attribute handle. * @param attr Attribute object.
* @param value Attribute value. * @param value Attribute value.
* @param len Attribute value length. * @param len Attribute value length.
*/ */
int bt_gatt_notify(struct bt_conn *conn, uint16_t handle, const void *data, int bt_gatt_notify(struct bt_conn *conn, const struct bt_gatt_attr *attr,
uint16_t len); const void *data, uint16_t len);
#if defined(CONFIG_BLUETOOTH_GATT_CLIENT) #if defined(CONFIG_BLUETOOTH_GATT_CLIENT)
/* Client API */ /* Client API */

View file

@ -471,20 +471,24 @@ static uint8_t notify_cb(const struct bt_gatt_attr *attr, void *user_data)
return BT_GATT_ITER_CONTINUE; return BT_GATT_ITER_CONTINUE;
} }
int bt_gatt_notify(struct bt_conn *conn, uint16_t handle, const void *data, int bt_gatt_notify(struct bt_conn *conn, const struct bt_gatt_attr *attr,
uint16_t len) const void *data, uint16_t len)
{ {
struct notify_data nfy; struct notify_data nfy;
if (conn) { if (!attr || !attr->handle) {
return att_notify(conn, handle, data, len); return -EINVAL;
} }
nfy.handle = handle; if (conn) {
return att_notify(conn, attr->handle, data, len);
}
nfy.handle = attr->handle;
nfy.data = data; nfy.data = data;
nfy.len = len; nfy.len = len;
bt_gatt_foreach_attr(handle, 0xffff, notify_cb, &nfy); bt_gatt_foreach_attr(attr->handle, 0xffff, notify_cb, &nfy);
return 0; return 0;
} }

View file

@ -495,7 +495,7 @@ void main(void)
/* Current Time Service updates only when time is changed */ /* Current Time Service updates only when time is changed */
if (ct_update) { if (ct_update) {
ct_update = 0; ct_update = 0;
bt_gatt_notify(NULL, 0x0014, &ct, sizeof(ct)); bt_gatt_notify(NULL, &attrs[20], &ct, sizeof(ct));
} }
/* Heartrate measurements simulation */ /* Heartrate measurements simulation */
@ -505,7 +505,7 @@ void main(void)
hrm[1] = 90; hrm[1] = 90;
} }
bt_gatt_notify(NULL, 0x0008, &hrm, sizeof(hrm)); bt_gatt_notify(NULL, &attrs[8], &hrm, sizeof(hrm));
} }
/* Battery level simulation */ /* Battery level simulation */
@ -517,7 +517,8 @@ void main(void)
battery = 100; battery = 100;
} }
bt_gatt_notify(NULL, 0x0010, &battery, sizeof(battery)); bt_gatt_notify(NULL, &attrs[16], &battery,
sizeof(battery));
} }
} }
} }

View file

@ -510,7 +510,7 @@ void main(void)
/* Current Time Service updates only when time is changed */ /* Current Time Service updates only when time is changed */
if (ct_update) { if (ct_update) {
ct_update = 0; ct_update = 0;
bt_gatt_notify(NULL, 0x0014, &ct, sizeof(ct)); bt_gatt_notify(NULL, &cts_attrs[3], &ct, sizeof(ct));
} }
/* Heartrate measurements simulation */ /* Heartrate measurements simulation */
@ -518,7 +518,7 @@ void main(void)
hrm[0] = 0x06; /* uint8, sensor contact */ hrm[0] = 0x06; /* uint8, sensor contact */
hrm[1] = 90 + (sys_rand32_get() % 20); hrm[1] = 90 + (sys_rand32_get() % 20);
bt_gatt_notify(NULL, 0x0008, &hrm, sizeof(hrm)); bt_gatt_notify(NULL, &hrs_attrs[3], &hrm, sizeof(hrm));
} }
/* Battery level simulation */ /* Battery level simulation */
@ -530,7 +530,8 @@ void main(void)
battery = 100; battery = 100;
} }
bt_gatt_notify(NULL, 0x0010, &battery, sizeof(battery)); bt_gatt_notify(NULL, &bas_attrs[3], &battery,
sizeof(battery));
} }
} }
} }

View file

@ -653,8 +653,8 @@ static uint8_t set_value_cb(struct bt_gatt_attr *attr, void *user_data)
memcpy(gatt_value->data, cmd->value, gatt_value->len); memcpy(gatt_value->data, cmd->value, gatt_value->len);
if (gatt_value->has_ccc) { if (gatt_value->has_ccc) {
bt_gatt_notify(NULL, attr->handle, bt_gatt_notify(NULL, attr, gatt_value->data,
gatt_value->data, gatt_value->len); gatt_value->len);
} }
status = BTP_STATUS_SUCCESS; status = BTP_STATUS_SUCCESS;