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
|
@ -43,8 +43,8 @@ extern "C" {
|
|||
/** @brief Opaque Volume Offset Control Service instance. */
|
||||
struct bt_vocs;
|
||||
|
||||
/** @brief Structure for initializing a Volume Offset Control Service instance. */
|
||||
struct bt_vocs_init_param {
|
||||
/** @brief Structure for registering a Volume Offset Control Service instance. */
|
||||
struct bt_vocs_register_param {
|
||||
/** Audio Location bitmask */
|
||||
uint32_t location;
|
||||
|
||||
|
@ -59,6 +59,9 @@ struct bt_vocs_init_param {
|
|||
|
||||
/** Boolean to set whether the description is writable by clients */
|
||||
bool desc_writable;
|
||||
|
||||
/** Pointer to the callback structure. */
|
||||
struct bt_vocs_cb *cb;
|
||||
};
|
||||
|
||||
/** @brief Structure for discovering a Volume Offset Control Service instance. */
|
||||
|
@ -96,15 +99,15 @@ struct bt_vocs *bt_vocs_free_instance_get(void);
|
|||
void *bt_vocs_svc_decl_get(struct bt_vocs *vocs);
|
||||
|
||||
/**
|
||||
* @brief Initialize the Volume Offset Control Service instance.
|
||||
* @brief Register the Volume Offset Control Service instance.
|
||||
*
|
||||
* @param vocs Volume Offset Control Service instance.
|
||||
* @param init Volume Offset Control Service initialization structure.
|
||||
* May be NULL to use default values.
|
||||
* @param param Volume Offset Control Service register parameters.
|
||||
*
|
||||
* @return 0 if success, errno on failure.
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* @brief Callback function for the offset state.
|
||||
|
@ -257,16 +260,6 @@ int bt_vocs_description_get(struct bt_conn *conn, struct bt_vocs *inst);
|
|||
int bt_vocs_description_set(struct bt_conn *conn, struct bt_vocs *inst,
|
||||
const char *description);
|
||||
|
||||
/**
|
||||
* @brief Register callbacks for the Volume Offset Control Service.
|
||||
*
|
||||
* @param inst Pointer to the Volume Offset Control Service instance.
|
||||
* @param cb Pointer to the callback structure.
|
||||
*
|
||||
* @return 0 on success, GATT error value on fail.
|
||||
*/
|
||||
int bt_vocs_cb_register(struct bt_vocs *inst, struct bt_vocs_cb *cb);
|
||||
|
||||
/**
|
||||
* @brief Registers the callbacks for the Volume Offset Control Service client.
|
||||
*
|
||||
|
|
|
@ -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