Bluetooth: Audio: VOCS: Move callback structure to register function
Moves the callback structure for VOCS to the register function which is renamed from init, as there's no reason to register the callbacks separately. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
77da035141
commit
910e0c63f4
2 changed files with 26 additions and 38 deletions
|
@ -266,7 +266,8 @@ static void prepare_vocs_instances(void)
|
|||
}
|
||||
}
|
||||
|
||||
int bt_vocs_init(struct bt_vocs *vocs, const struct bt_vocs_init_param *init)
|
||||
int bt_vocs_register(struct bt_vocs *vocs,
|
||||
const struct bt_vocs_register_param *param)
|
||||
{
|
||||
int err;
|
||||
struct bt_gatt_attr *attr;
|
||||
|
@ -278,6 +279,11 @@ int bt_vocs_init(struct bt_vocs *vocs, const struct bt_vocs_init_param *init)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
CHECKIF(!param) {
|
||||
BT_DBG("NULL params pointer");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!instances_prepared) {
|
||||
prepare_vocs_instances();
|
||||
instances_prepared = true;
|
||||
|
@ -288,21 +294,22 @@ int bt_vocs_init(struct bt_vocs *vocs, const struct bt_vocs_init_param *init)
|
|||
return -EALREADY;
|
||||
}
|
||||
|
||||
CHECKIF(init->offset > BT_VOCS_MAX_OFFSET || init->offset < BT_VOCS_MIN_OFFSET) {
|
||||
BT_DBG("Invalid offset %d", init->offset);
|
||||
CHECKIF(param->offset > BT_VOCS_MAX_OFFSET || param->offset < BT_VOCS_MIN_OFFSET) {
|
||||
BT_DBG("Invalid offset %d", param->offset);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
vocs->srv.location = init->location;
|
||||
vocs->srv.state.offset = init->offset;
|
||||
vocs->srv.location = param->location;
|
||||
vocs->srv.state.offset = param->offset;
|
||||
vocs->srv.cb = param->cb;
|
||||
|
||||
if (init->output_desc) {
|
||||
strncpy(vocs->srv.output_desc, init->output_desc,
|
||||
if (param->output_desc) {
|
||||
strncpy(vocs->srv.output_desc, param->output_desc,
|
||||
sizeof(vocs->srv.output_desc) - 1);
|
||||
/* strncpy may not always null-terminate */
|
||||
vocs->srv.output_desc[sizeof(vocs->srv.output_desc) - 1] = '\0';
|
||||
if (IS_ENABLED(CONFIG_BT_DEBUG_VOCS) &&
|
||||
strcmp(vocs->srv.output_desc, init->output_desc)) {
|
||||
strcmp(vocs->srv.output_desc, param->output_desc)) {
|
||||
BT_DBG("Output desc clipped to %s", log_strdup(vocs->srv.output_desc));
|
||||
}
|
||||
}
|
||||
|
@ -316,13 +323,13 @@ int bt_vocs_init(struct bt_vocs *vocs, const struct bt_vocs_init_param *init)
|
|||
for (int i = 1; i < vocs->srv.service_p->attr_count; i++) {
|
||||
attr = &vocs->srv.service_p->attrs[i];
|
||||
|
||||
if (init->location_writable && !bt_uuid_cmp(attr->uuid, BT_UUID_VOCS_LOCATION)) {
|
||||
if (param->location_writable && !bt_uuid_cmp(attr->uuid, BT_UUID_VOCS_LOCATION)) {
|
||||
/* Update attr and chrc to be writable */
|
||||
chrc = vocs->srv.service_p->attrs[i - 1].user_data;
|
||||
attr->write = write_location;
|
||||
attr->perm |= BT_GATT_PERM_WRITE_ENCRYPT;
|
||||
chrc->properties |= BT_GATT_CHRC_WRITE_WITHOUT_RESP;
|
||||
} else if (init->desc_writable &&
|
||||
} else if (param->desc_writable &&
|
||||
!bt_uuid_cmp(attr->uuid, BT_UUID_VOCS_DESCRIPTION)) {
|
||||
/* Update attr and chrc to be writable */
|
||||
chrc = vocs->srv.service_p->attrs[i - 1].user_data;
|
||||
|
@ -480,16 +487,4 @@ int bt_vocs_description_set(struct bt_conn *conn, struct bt_vocs *inst, const ch
|
|||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
int bt_vocs_cb_register(struct bt_vocs *inst, struct bt_vocs_cb *cb)
|
||||
{
|
||||
CHECKIF(!inst) {
|
||||
BT_DBG("Null VOCS pointer");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
inst->srv.cb = cb;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BT_VOCS || CONFIG_BT_VOCS_CLIENT */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue