Lines Matching refs:preset

568 typedef uint8_t (*preset_func_t)(const struct has_preset *preset, void *user_data);
573 struct has_preset *preset, *tmp; in preset_foreach() local
575 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&preset_list, preset, tmp, node) { in preset_foreach()
576 if (preset->index < start_index) { in preset_foreach()
580 if (preset->index > end_index) { in preset_foreach()
584 if (func(preset, user_data) == BT_HAS_PRESET_ITER_STOP) { in preset_foreach()
590 static uint8_t preset_found(const struct has_preset *preset, void *user_data) in preset_found() argument
594 *found = preset; in preset_found()
599 static void preset_insert(struct has_preset *preset) in preset_insert() argument
604 if (tmp->index > preset->index) { in preset_insert()
606 sys_slist_insert(&preset_list, &prev->node, &preset->node); in preset_insert()
608 sys_slist_prepend(&preset_list, &preset->node); in preset_insert()
616 sys_slist_append(&preset_list, &preset->node); in preset_insert()
622 struct has_preset *preset; in preset_alloc() local
630 preset = CONTAINER_OF(node, struct has_preset, node); in preset_alloc()
631 preset->index = index; in preset_alloc()
632 preset->properties = properties; in preset_alloc()
634 utf8_lcpy(preset->name, name, ARRAY_SIZE(preset->name)); in preset_alloc()
636 preset->name = name; in preset_alloc()
638 preset->ops = ops; in preset_alloc()
640 preset_insert(preset); in preset_alloc()
642 return preset; in preset_alloc()
645 static void preset_free(struct has_preset *preset) in preset_free() argument
649 removed = sys_slist_find_and_remove(&preset_list, &preset->node); in preset_free()
651 sys_slist_append(&preset_free_list, &preset->node); in preset_free()
669 static struct has_preset *preset_get_prev(const struct has_preset *preset) in preset_get_prev() argument
674 if (SYS_SLIST_PEEK_NEXT_CONTAINER(prev, node) == preset) { in preset_get_prev()
680 if (prev == preset) { in preset_get_prev()
689 struct has_preset *preset; in preset_lookup_index() local
691 SYS_SLIST_FOR_EACH_CONTAINER(&preset_list, preset, node) { in preset_lookup_index()
692 if (preset->index == index) { in preset_lookup_index()
693 return preset; in preset_lookup_index()
700 static struct has_preset *preset_get_next(struct has_preset *preset) in preset_get_next() argument
704 next = SYS_SLIST_PEEK_NEXT_CONTAINER(preset, node); in preset_get_next()
707 if (next == preset) { in preset_get_next()
715 static uint8_t preset_get_prev_index(const struct has_preset *preset) in preset_get_prev_index() argument
719 prev = preset_get_prev(preset); in preset_get_prev_index()
720 if (prev == NULL || prev->index >= preset->index) { in preset_get_prev_index()
826 static int bt_has_cp_read_preset_rsp(struct has_client *client, const struct has_preset *preset, in bt_has_cp_read_preset_rsp() argument
835 preset->index, preset->properties, preset->name, is_last); in bt_has_cp_read_preset_rsp()
841 rsp->index = preset->index; in bt_has_cp_read_preset_rsp()
842 rsp->properties = preset->properties; in bt_has_cp_read_preset_rsp()
843 net_buf_simple_add_mem(&buf, preset->name, strlen(preset->name)); in bt_has_cp_read_preset_rsp()
984 const struct has_preset *preset = NULL; in read_preset_response() local
991 preset_found, &preset); in read_preset_response()
993 if (unlikely(preset == NULL)) { in read_preset_response()
1000 preset_foreach(preset->index + 1, BT_HAS_PRESET_INDEX_LAST, preset_found, &next); in read_preset_response()
1005 err = bt_has_cp_read_preset_rsp(client, preset, is_last); in read_preset_response()
1010 if (preset->index > client->context->last_preset_index_known) { in read_preset_response()
1011 update_last_preset_index_known(client, preset->index); in read_preset_response()
1015 client->read_presets_req.start_index = preset->index + 1; in read_preset_response()
1093 const struct has_preset *preset = NULL; in preset_list_changed() local
1110 preset_found, &preset); in preset_list_changed()
1112 if (preset == NULL) { in preset_list_changed()
1116 preset_foreach(preset->index + 1, BT_HAS_PRESET_INDEX_LAST, preset_found, &next); in preset_list_changed()
1121 is_last = next == NULL && preset->index >= client->context->last_preset_index_known; in preset_list_changed()
1123 err = bt_has_cp_generic_update(client, preset_get_prev_index(preset), preset->index, in preset_list_changed()
1124 preset->properties, preset->name, is_last); in preset_list_changed()
1133 update_last_preset_index_known(client, preset->index); in preset_list_changed()
1151 client->preset_changed_index_next = preset->index + 1; in preset_list_changed()
1164 const struct has_preset *preset = NULL; in handle_read_preset_req() local
1189 preset_foreach(req->start_index, BT_HAS_PRESET_INDEX_LAST, preset_found, &preset); in handle_read_preset_req()
1191 if (preset == NULL) { in handle_read_preset_req()
1211 struct has_preset *preset = NULL; in set_preset_name() local
1220 preset_foreach(index, BT_HAS_PRESET_INDEX_LAST, preset_found, &preset); in set_preset_name()
1222 if (preset == NULL) { in set_preset_name()
1226 if (!(preset->properties & BT_HAS_PROP_WRITABLE)) { in set_preset_name()
1231 __ASSERT(len < ARRAY_SIZE(preset->name), "No space for name"); in set_preset_name()
1233 (void)memcpy(preset->name, name, len); in set_preset_name()
1236 preset->name[len] = '\0'; in set_preset_name()
1239 utf8_trunc(preset->name); in set_preset_name()
1242 if (preset->ops->name_changed) { in set_preset_name()
1243 preset->ops->name_changed(index, preset->name); in set_preset_name()
1246 return bt_has_cp_generic_update(NULL, preset_get_prev_index(preset), preset->index, in set_preset_name()
1247 preset->properties, preset->name, BT_HAS_IS_LAST); in set_preset_name()
1289 static void preset_set_active(struct has_preset *preset) in preset_set_active() argument
1291 if (active_preset != preset) { in preset_set_active()
1292 active_preset = preset; in preset_set_active()
1298 static uint8_t preset_select(struct has_preset *preset, bool sync) in preset_select() argument
1300 const int err = preset->ops->select(preset->index, sync); in preset_select()
1317 preset_set_active(preset); in preset_select()
1322 static bool is_preset_available(const struct has_preset *preset) in is_preset_available() argument
1324 return (preset->properties & BT_HAS_PROP_AVAILABLE) != 0; in is_preset_available()
1330 struct has_preset *preset; in handle_set_active_preset() local
1338 preset = preset_lookup_index(pdu->index); in handle_set_active_preset()
1339 if (preset == NULL) { in handle_set_active_preset()
1343 if (!is_preset_available(preset)) { in handle_set_active_preset()
1347 return preset_select(preset, sync); in handle_set_active_preset()
1480 struct has_preset *preset; in bt_has_preset_register() local
1519 preset = preset_lookup_index(param->index); in bt_has_preset_register()
1520 if (preset != NULL) { in bt_has_preset_register()
1530 preset = preset_alloc(param->index, param->properties, param->name, param->ops); in bt_has_preset_register()
1531 if (preset == NULL) { in bt_has_preset_register()
1535 if (preset == preset_get_tail()) { in bt_has_preset_register()
1536 update_last_preset_index_known(NULL, preset->index); in bt_has_preset_register()
1539 return bt_has_cp_generic_update(NULL, preset_get_prev_index(preset), preset->index, in bt_has_preset_register()
1540 preset->properties, preset->name, BT_HAS_IS_LAST); in bt_has_preset_register()
1545 struct has_preset *preset; in bt_has_preset_unregister() local
1553 preset = preset_lookup_index(index); in bt_has_preset_unregister()
1554 if (preset == NULL) { in bt_has_preset_unregister()
1558 if (preset == active_preset) { in bt_has_preset_unregister()
1562 err = bt_has_cp_preset_record_deleted(NULL, preset->index); in bt_has_preset_unregister()
1567 if (preset == preset_get_tail()) { in bt_has_preset_unregister()
1568 update_last_preset_index_known(NULL, preset_get_prev_index(preset)); in bt_has_preset_unregister()
1571 preset_free(preset); in bt_has_preset_unregister()
1580 struct has_preset *preset; in set_preset_availability() local
1588 preset = preset_lookup_index(index); in set_preset_availability()
1589 if (preset == NULL) { in set_preset_availability()
1593 if (is_preset_available(preset) == available) { in set_preset_availability()
1598 preset->properties ^= BT_HAS_PROP_AVAILABLE; in set_preset_availability()
1600 if (is_preset_available(preset)) { in set_preset_availability()
1607 net_buf_simple_add_u8(&buf, preset->index); in set_preset_availability()
1627 static uint8_t bt_has_preset_foreach_func(const struct has_preset *preset, void *user_data) in bt_has_preset_foreach_func() argument
1631 return data->func(preset->index, preset->properties, preset->name, data->user_data); in bt_has_preset_foreach_func()
1654 struct has_preset *preset; in bt_has_preset_active_set() local
1661 preset = preset_lookup_index(index); in bt_has_preset_active_set()
1662 if (preset == NULL) { in bt_has_preset_active_set()
1666 if (!is_preset_available(preset)) { in bt_has_preset_active_set()
1670 preset_set_active(preset); in bt_has_preset_active_set()
1808 struct has_preset *preset = &preset_pool[i]; in bt_has_register() local
1810 sys_slist_append(&preset_free_list, &preset->node); in bt_has_register()