[FL-2274] Inventing streams and moving FFF to them (#981)
* Streams: string stream * String stream: updated insert/delete api * Streams: generic stream interface and string stream implementation * Streams: helpers for insert and delete_and_insert * FFF: now compatible with streams * MinUnit: introduced tests with arguments * FFF: stream access violation * Streams: copy data between streams * Streams: file stream * FFF: documentation * FFStream: documentation * FFF: alloc as file * MinUnit: support for nested tests * Streams: changed delete_and_insert, now it returns success flag. Added ability dump stream inner parameters and data to cout. * FFF: simplified file open function * Streams: unit tests * FFF: tests * Streams: declare cache_size constant as define, to allow variable modified arrays * FFF: lib moved to a separate folder * iButton: new FFF * RFID: new FFF * Animations: new FFF * IR: new FFF * NFC: new FFF * Flipper file format: delete lib * U2F: new FFF * Subghz: new FFF and streams * Streams: read line * Streams: split * FuriCore: implement memset with extra asserts * FuriCore: implement extra heap asserts without inventing memset * Scene manager: protected access to the scene id stack with a size check * NFC worker: dirty fix for issue where hal_nfc was busy on app start * Furi: update allocator to erase memory on allocation. Replace furi_alloc with malloc. * FuriCore: cleanup memmgr code. * Furi HAL: furi_hal_init is split into critical and non-critical parts. The critical part is currently clock and console. * Memmgr: added ability to track allocations and deallocations through console. * FFStream: some speedup * Streams, FF: minor fixes * Tests: restore * File stream: a slightly more thread-safe version of file_stream_delete_and_insert Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -15,7 +15,7 @@ const CanvasFontParameters canvas_font_params[FontTotalNumber] = {
|
||||
};
|
||||
|
||||
Canvas* canvas_init() {
|
||||
Canvas* canvas = furi_alloc(sizeof(Canvas));
|
||||
Canvas* canvas = malloc(sizeof(Canvas));
|
||||
|
||||
furi_hal_power_insomnia_enter();
|
||||
|
||||
|
||||
@@ -417,7 +417,7 @@ void gui_set_lockdown(Gui* gui, bool lockdown) {
|
||||
}
|
||||
|
||||
Gui* gui_alloc() {
|
||||
Gui* gui = furi_alloc(sizeof(Gui));
|
||||
Gui* gui = malloc(sizeof(Gui));
|
||||
// Thread ID
|
||||
gui->thread = osThreadGetId();
|
||||
// Allocate mutex
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
IconAnimation* icon_animation_alloc(const Icon* icon) {
|
||||
furi_assert(icon);
|
||||
IconAnimation* instance = furi_alloc(sizeof(IconAnimation));
|
||||
IconAnimation* instance = malloc(sizeof(IconAnimation));
|
||||
instance->icon = icon;
|
||||
instance->timer = osTimerNew(icon_animation_timer_callback, osTimerPeriodic, instance, NULL);
|
||||
return instance;
|
||||
|
||||
@@ -290,7 +290,7 @@ ButtonMenuItem* button_menu_add_item(
|
||||
}
|
||||
|
||||
ButtonMenu* button_menu_alloc(void) {
|
||||
ButtonMenu* button_menu = furi_alloc(sizeof(ButtonMenu));
|
||||
ButtonMenu* button_menu = malloc(sizeof(ButtonMenu));
|
||||
button_menu->view = view_alloc();
|
||||
view_set_orientation(button_menu->view, ViewOrientationVertical);
|
||||
view_set_context(button_menu->view, button_menu);
|
||||
|
||||
@@ -65,7 +65,7 @@ static void button_panel_view_draw_callback(Canvas* canvas, void* _model);
|
||||
static bool button_panel_view_input_callback(InputEvent* event, void* context);
|
||||
|
||||
ButtonPanel* button_panel_alloc() {
|
||||
ButtonPanel* button_panel = furi_alloc(sizeof(ButtonPanel));
|
||||
ButtonPanel* button_panel = malloc(sizeof(ButtonPanel));
|
||||
button_panel->view = view_alloc();
|
||||
view_set_orientation(button_panel->view, ViewOrientationVertical);
|
||||
view_set_context(button_panel->view, button_panel);
|
||||
@@ -173,7 +173,7 @@ void button_panel_add_item(
|
||||
ButtonItem** button_item_ptr =
|
||||
button_panel_get_item(model, matrix_place_x, matrix_place_y);
|
||||
furi_check(*button_item_ptr == NULL);
|
||||
*button_item_ptr = furi_alloc(sizeof(ButtonItem));
|
||||
*button_item_ptr = malloc(sizeof(ButtonItem));
|
||||
ButtonItem* button_item = *button_item_ptr;
|
||||
button_item->callback = callback;
|
||||
button_item->callback_context = callback_context;
|
||||
|
||||
@@ -695,7 +695,7 @@ static void byte_input_reset_model_input_data(ByteInputModel* model) {
|
||||
* @return ByteInput instance pointer
|
||||
*/
|
||||
ByteInput* byte_input_alloc() {
|
||||
ByteInput* byte_input = furi_alloc(sizeof(ByteInput));
|
||||
ByteInput* byte_input = malloc(sizeof(ByteInput));
|
||||
byte_input->view = view_alloc();
|
||||
view_set_context(byte_input->view, byte_input);
|
||||
view_allocate_model(byte_input->view, ViewModelTypeLocking, sizeof(ByteInputModel));
|
||||
|
||||
@@ -60,7 +60,7 @@ static bool dialog_view_input_callback(InputEvent* event, void* context) {
|
||||
}
|
||||
|
||||
Dialog* dialog_alloc() {
|
||||
Dialog* dialog = furi_alloc(sizeof(Dialog));
|
||||
Dialog* dialog = malloc(sizeof(Dialog));
|
||||
dialog->view = view_alloc();
|
||||
view_set_context(dialog->view, dialog);
|
||||
view_allocate_model(dialog->view, ViewModelTypeLockFree, sizeof(DialogModel));
|
||||
|
||||
@@ -114,7 +114,7 @@ static bool dialog_ex_view_input_callback(InputEvent* event, void* context) {
|
||||
}
|
||||
|
||||
DialogEx* dialog_ex_alloc() {
|
||||
DialogEx* dialog_ex = furi_alloc(sizeof(DialogEx));
|
||||
DialogEx* dialog_ex = malloc(sizeof(DialogEx));
|
||||
dialog_ex->view = view_alloc();
|
||||
view_set_context(dialog_ex->view, dialog_ex);
|
||||
view_allocate_model(dialog_ex->view, ViewModelTypeLockFree, sizeof(DialogExModel));
|
||||
|
||||
@@ -14,7 +14,7 @@ static bool empty_screen_view_input_callback(InputEvent* event, void* context) {
|
||||
}
|
||||
|
||||
EmptyScreen* empty_screen_alloc() {
|
||||
EmptyScreen* empty_screen = furi_alloc(sizeof(EmptyScreen));
|
||||
EmptyScreen* empty_screen = malloc(sizeof(EmptyScreen));
|
||||
empty_screen->view = view_alloc();
|
||||
view_set_context(empty_screen->view, empty_screen);
|
||||
view_set_draw_callback(empty_screen->view, empty_screen_view_draw_callback);
|
||||
@@ -31,4 +31,4 @@ void empty_screen_free(EmptyScreen* empty_screen) {
|
||||
View* empty_screen_get_view(EmptyScreen* empty_screen) {
|
||||
furi_assert(empty_screen);
|
||||
return empty_screen->view;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ static bool file_select_init_inner(FileSelect* file_select) {
|
||||
}
|
||||
|
||||
FileSelect* file_select_alloc() {
|
||||
FileSelect* file_select = furi_alloc(sizeof(FileSelect));
|
||||
FileSelect* file_select = malloc(sizeof(FileSelect));
|
||||
file_select->view = view_alloc();
|
||||
file_select->fs_api = furi_record_open("storage");
|
||||
|
||||
@@ -278,7 +278,7 @@ bool file_select_fill_strings(FileSelect* file_select) {
|
||||
uint8_t string_counter = 0;
|
||||
uint16_t file_counter = 0;
|
||||
const uint8_t name_length = 100;
|
||||
char* name = furi_alloc(name_length);
|
||||
char* name = malloc(name_length);
|
||||
uint16_t first_file_index = 0;
|
||||
|
||||
with_view_model(
|
||||
@@ -346,7 +346,7 @@ bool file_select_fill_count(FileSelect* file_select) {
|
||||
|
||||
uint16_t file_counter = 0;
|
||||
const uint8_t name_length = 100;
|
||||
char* name = furi_alloc(name_length);
|
||||
char* name = malloc(name_length);
|
||||
|
||||
if(!storage_dir_open(directory, file_select->path)) {
|
||||
storage_dir_close(directory);
|
||||
@@ -397,7 +397,7 @@ void file_select_set_selected_file_internal(FileSelect* file_select, const char*
|
||||
File* directory = storage_file_alloc(file_select->fs_api);
|
||||
|
||||
const uint8_t name_length = 100;
|
||||
char* name = furi_alloc(name_length);
|
||||
char* name = malloc(name_length);
|
||||
uint16_t file_position = 0;
|
||||
bool file_found = false;
|
||||
|
||||
@@ -472,4 +472,4 @@ void file_select_set_selected_file(FileSelect* file_select, const char* filename
|
||||
if(!file_select_fill_strings(file_select)) {
|
||||
file_select->callback(false, file_select->context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ static void menu_exit(void* context) {
|
||||
}
|
||||
|
||||
Menu* menu_alloc() {
|
||||
Menu* menu = furi_alloc(sizeof(Menu));
|
||||
Menu* menu = malloc(sizeof(Menu));
|
||||
menu->view = view_alloc(menu->view);
|
||||
view_set_context(menu->view, menu);
|
||||
view_allocate_model(menu->view, ViewModelTypeLocking, sizeof(MenuModel));
|
||||
|
||||
@@ -108,7 +108,7 @@ void popup_stop_timer(void* context) {
|
||||
}
|
||||
|
||||
Popup* popup_alloc() {
|
||||
Popup* popup = furi_alloc(sizeof(Popup));
|
||||
Popup* popup = malloc(sizeof(Popup));
|
||||
popup->view = view_alloc();
|
||||
popup->timer = osTimerNew(popup_timer_callback, osTimerOnce, popup, NULL);
|
||||
furi_assert(popup->timer);
|
||||
|
||||
@@ -120,7 +120,7 @@ static bool submenu_view_input_callback(InputEvent* event, void* context) {
|
||||
}
|
||||
|
||||
Submenu* submenu_alloc() {
|
||||
Submenu* submenu = furi_alloc(sizeof(Submenu));
|
||||
Submenu* submenu = malloc(sizeof(Submenu));
|
||||
submenu->view = view_alloc();
|
||||
view_set_context(submenu->view, submenu);
|
||||
view_allocate_model(submenu->view, ViewModelTypeLocking, sizeof(SubmenuModel));
|
||||
|
||||
@@ -128,7 +128,7 @@ static bool text_box_view_input_callback(InputEvent* event, void* context) {
|
||||
}
|
||||
|
||||
TextBox* text_box_alloc() {
|
||||
TextBox* text_box = furi_alloc(sizeof(TextBox));
|
||||
TextBox* text_box = malloc(sizeof(TextBox));
|
||||
text_box->view = view_alloc();
|
||||
view_set_context(text_box->view, text_box);
|
||||
view_allocate_model(text_box->view, ViewModelTypeLocking, sizeof(TextBoxModel));
|
||||
|
||||
@@ -410,7 +410,7 @@ void text_input_timer_callback(void* context) {
|
||||
}
|
||||
|
||||
TextInput* text_input_alloc() {
|
||||
TextInput* text_input = furi_alloc(sizeof(TextInput));
|
||||
TextInput* text_input = malloc(sizeof(TextInput));
|
||||
text_input->view = view_alloc();
|
||||
view_set_context(text_input->view, text_input);
|
||||
view_allocate_model(text_input->view, ViewModelTypeLocking, sizeof(TextInputModel));
|
||||
|
||||
@@ -28,7 +28,7 @@ bool validator_is_file_callback(const char* text, string_t error, void* context)
|
||||
|
||||
ValidatorIsFile*
|
||||
validator_is_file_alloc_init(const char* app_path_folder, const char* app_extension) {
|
||||
ValidatorIsFile* instance = furi_alloc(sizeof(ValidatorIsFile));
|
||||
ValidatorIsFile* instance = malloc(sizeof(ValidatorIsFile));
|
||||
|
||||
instance->app_path_folder = app_path_folder;
|
||||
instance->app_extension = app_extension;
|
||||
|
||||
@@ -276,7 +276,7 @@ void variable_item_list_process_ok(VariableItemList* variable_item_list) {
|
||||
}
|
||||
|
||||
VariableItemList* variable_item_list_alloc() {
|
||||
VariableItemList* variable_item_list = furi_alloc(sizeof(VariableItemList));
|
||||
VariableItemList* variable_item_list = malloc(sizeof(VariableItemList));
|
||||
variable_item_list->view = view_alloc();
|
||||
view_set_context(variable_item_list->view, variable_item_list);
|
||||
view_allocate_model(
|
||||
|
||||
@@ -52,7 +52,7 @@ static bool gui_widget_view_input_callback(InputEvent* event, void* context) {
|
||||
}
|
||||
|
||||
Widget* widget_alloc() {
|
||||
Widget* widget = furi_alloc(sizeof(Widget));
|
||||
Widget* widget = malloc(sizeof(Widget));
|
||||
widget->view = view_alloc();
|
||||
view_set_context(widget->view, widget);
|
||||
view_allocate_model(widget->view, ViewModelTypeLocking, sizeof(GuiWidgetModel));
|
||||
|
||||
@@ -61,14 +61,14 @@ WidgetElement* widget_element_button_create(
|
||||
ButtonCallback callback,
|
||||
void* context) {
|
||||
// Allocate and init model
|
||||
GuiButtonModel* model = furi_alloc(sizeof(GuiButtonModel));
|
||||
GuiButtonModel* model = malloc(sizeof(GuiButtonModel));
|
||||
model->button_type = button_type;
|
||||
model->callback = callback;
|
||||
model->context = context;
|
||||
string_init_set_str(model->text, text);
|
||||
|
||||
// Allocate and init Element
|
||||
WidgetElement* gui_button = furi_alloc(sizeof(WidgetElement));
|
||||
WidgetElement* gui_button = malloc(sizeof(WidgetElement));
|
||||
gui_button->parent = NULL;
|
||||
gui_button->input = gui_button_input;
|
||||
gui_button->draw = gui_button_draw;
|
||||
|
||||
@@ -29,7 +29,7 @@ WidgetElement* widget_element_frame_create(
|
||||
uint8_t height,
|
||||
uint8_t radius) {
|
||||
// Allocate and init model
|
||||
GuiFrameModel* model = furi_alloc(sizeof(GuiFrameModel));
|
||||
GuiFrameModel* model = malloc(sizeof(GuiFrameModel));
|
||||
model->x = x;
|
||||
model->y = y;
|
||||
model->width = width;
|
||||
@@ -37,7 +37,7 @@ WidgetElement* widget_element_frame_create(
|
||||
model->radius = radius;
|
||||
|
||||
// Allocate and init Element
|
||||
WidgetElement* gui_frame = furi_alloc(sizeof(WidgetElement));
|
||||
WidgetElement* gui_frame = malloc(sizeof(WidgetElement));
|
||||
gui_frame->parent = NULL;
|
||||
gui_frame->input = NULL;
|
||||
gui_frame->draw = gui_frame_draw;
|
||||
|
||||
@@ -27,13 +27,13 @@ WidgetElement* widget_element_icon_create(uint8_t x, uint8_t y, const Icon* icon
|
||||
furi_assert(icon);
|
||||
|
||||
// Allocate and init model
|
||||
GuiIconModel* model = furi_alloc(sizeof(GuiIconModel));
|
||||
GuiIconModel* model = malloc(sizeof(GuiIconModel));
|
||||
model->x = x;
|
||||
model->y = y;
|
||||
model->icon = icon;
|
||||
|
||||
// Allocate and init Element
|
||||
WidgetElement* gui_icon = furi_alloc(sizeof(WidgetElement));
|
||||
WidgetElement* gui_icon = malloc(sizeof(WidgetElement));
|
||||
gui_icon->parent = NULL;
|
||||
gui_icon->input = NULL;
|
||||
gui_icon->draw = gui_icon_draw;
|
||||
|
||||
@@ -46,7 +46,7 @@ WidgetElement* widget_element_string_create(
|
||||
furi_assert(text);
|
||||
|
||||
// Allocate and init model
|
||||
GuiStringModel* model = furi_alloc(sizeof(GuiStringModel));
|
||||
GuiStringModel* model = malloc(sizeof(GuiStringModel));
|
||||
model->x = x;
|
||||
model->y = y;
|
||||
model->horizontal = horizontal;
|
||||
@@ -55,7 +55,7 @@ WidgetElement* widget_element_string_create(
|
||||
string_init_set_str(model->text, text);
|
||||
|
||||
// Allocate and init Element
|
||||
WidgetElement* gui_string = furi_alloc(sizeof(WidgetElement));
|
||||
WidgetElement* gui_string = malloc(sizeof(WidgetElement));
|
||||
gui_string->parent = NULL;
|
||||
gui_string->input = NULL;
|
||||
gui_string->draw = gui_string_draw;
|
||||
|
||||
@@ -47,7 +47,7 @@ WidgetElement* widget_element_string_multiline_create(
|
||||
furi_assert(text);
|
||||
|
||||
// Allocate and init model
|
||||
GuiStringMultiLineModel* model = furi_alloc(sizeof(GuiStringMultiLineModel));
|
||||
GuiStringMultiLineModel* model = malloc(sizeof(GuiStringMultiLineModel));
|
||||
model->x = x;
|
||||
model->y = y;
|
||||
model->horizontal = horizontal;
|
||||
@@ -56,7 +56,7 @@ WidgetElement* widget_element_string_multiline_create(
|
||||
string_init_set_str(model->text, text);
|
||||
|
||||
// Allocate and init Element
|
||||
WidgetElement* gui_string = furi_alloc(sizeof(WidgetElement));
|
||||
WidgetElement* gui_string = malloc(sizeof(WidgetElement));
|
||||
gui_string->parent = NULL;
|
||||
gui_string->input = NULL;
|
||||
gui_string->draw = gui_string_multiline_draw;
|
||||
|
||||
@@ -50,7 +50,7 @@ WidgetElement* widget_element_text_box_create(
|
||||
furi_assert(text);
|
||||
|
||||
// Allocate and init model
|
||||
GuiTextBoxModel* model = furi_alloc(sizeof(GuiTextBoxModel));
|
||||
GuiTextBoxModel* model = malloc(sizeof(GuiTextBoxModel));
|
||||
model->x = x;
|
||||
model->y = y;
|
||||
model->width = width;
|
||||
@@ -60,7 +60,7 @@ WidgetElement* widget_element_text_box_create(
|
||||
string_init_set_str(model->text, text);
|
||||
|
||||
// Allocate and init Element
|
||||
WidgetElement* gui_string = furi_alloc(sizeof(WidgetElement));
|
||||
WidgetElement* gui_string = malloc(sizeof(WidgetElement));
|
||||
gui_string->parent = NULL;
|
||||
gui_string->input = NULL;
|
||||
gui_string->draw = gui_text_box_draw;
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
SceneManager* scene_manager_alloc(const SceneManagerHandlers* app_scene_handlers, void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
SceneManager* scene_manager = furi_alloc(sizeof(SceneManager));
|
||||
SceneManager* scene_manager = malloc(sizeof(SceneManager));
|
||||
// Set SceneManager context and scene handlers
|
||||
scene_manager->context = context;
|
||||
scene_manager->scene_handlers = app_scene_handlers;
|
||||
// Allocate all scenes
|
||||
scene_manager->scene = furi_alloc(sizeof(AppScene) * app_scene_handlers->scene_num);
|
||||
scene_manager->scene = malloc(sizeof(AppScene) * app_scene_handlers->scene_num);
|
||||
// Initialize ScaneManager array for navigation
|
||||
SceneManagerIdStack_init(scene_manager->scene_id_stack);
|
||||
|
||||
@@ -48,9 +48,16 @@ bool scene_manager_handle_custom_event(SceneManager* scene_manager, uint32_t cus
|
||||
.type = SceneManagerEventTypeCustom,
|
||||
.event = custom_event,
|
||||
};
|
||||
uint32_t scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
return scene_manager->scene_handlers->on_event_handlers[scene_id](
|
||||
scene_manager->context, event);
|
||||
|
||||
bool result = false;
|
||||
if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
|
||||
uint32_t* scene_id_p = SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
uint32_t scene_id = *scene_id_p;
|
||||
result = scene_manager->scene_handlers->on_event_handlers[scene_id](
|
||||
scene_manager->context, event);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool scene_manager_handle_back_event(SceneManager* scene_manager) {
|
||||
@@ -59,9 +66,15 @@ bool scene_manager_handle_back_event(SceneManager* scene_manager) {
|
||||
SceneManagerEvent event = {
|
||||
.type = SceneManagerEventTypeBack,
|
||||
};
|
||||
uint32_t scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
bool consumed =
|
||||
scene_manager->scene_handlers->on_event_handlers[scene_id](scene_manager->context, event);
|
||||
|
||||
bool consumed = false;
|
||||
if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
|
||||
uint32_t* scene_id_p = SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
uint32_t scene_id = *scene_id_p;
|
||||
consumed = scene_manager->scene_handlers->on_event_handlers[scene_id](
|
||||
scene_manager->context, event);
|
||||
}
|
||||
|
||||
if(!consumed) {
|
||||
consumed = scene_manager_previous_scene(scene_manager);
|
||||
}
|
||||
@@ -74,8 +87,12 @@ void scene_manager_handle_tick_event(SceneManager* scene_manager) {
|
||||
SceneManagerEvent event = {
|
||||
.type = SceneManagerEventTypeTick,
|
||||
};
|
||||
uint32_t scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
scene_manager->scene_handlers->on_event_handlers[scene_id](scene_manager->context, event);
|
||||
|
||||
if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
|
||||
uint32_t* scene_id_p = SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
uint32_t scene_id = *scene_id_p;
|
||||
scene_manager->scene_handlers->on_event_handlers[scene_id](scene_manager->context, event);
|
||||
}
|
||||
}
|
||||
|
||||
void scene_manager_next_scene(SceneManager* scene_manager, uint32_t next_scene_id) {
|
||||
@@ -83,7 +100,7 @@ void scene_manager_next_scene(SceneManager* scene_manager, uint32_t next_scene_i
|
||||
furi_assert(next_scene_id < scene_manager->scene_handlers->scene_num);
|
||||
|
||||
// Check if it is not the first scene
|
||||
if(SceneManagerIdStack_size(scene_manager->scene_id_stack)) {
|
||||
if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
|
||||
uint32_t cur_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
|
||||
}
|
||||
@@ -95,18 +112,22 @@ void scene_manager_next_scene(SceneManager* scene_manager, uint32_t next_scene_i
|
||||
bool scene_manager_previous_scene(SceneManager* scene_manager) {
|
||||
furi_assert(scene_manager);
|
||||
|
||||
uint32_t cur_scene_id = 0;
|
||||
SceneManagerIdStack_pop_back(&cur_scene_id, scene_manager->scene_id_stack);
|
||||
if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
|
||||
uint32_t cur_scene_id = 0;
|
||||
SceneManagerIdStack_pop_back(&cur_scene_id, scene_manager->scene_id_stack);
|
||||
|
||||
// Handle exit from start scene separately
|
||||
if(SceneManagerIdStack_size(scene_manager->scene_id_stack) == 0) {
|
||||
// Handle exit from start scene separately
|
||||
if(SceneManagerIdStack_size(scene_manager->scene_id_stack) == 0) {
|
||||
scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
|
||||
return false;
|
||||
}
|
||||
uint32_t prev_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
|
||||
scene_manager->scene_handlers->on_enter_handlers[prev_scene_id](scene_manager->context);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
uint32_t prev_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
|
||||
scene_manager->scene_handlers->on_enter_handlers[prev_scene_id](scene_manager->context);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool scene_manager_search_and_switch_to_previous_scene(
|
||||
@@ -114,48 +135,55 @@ bool scene_manager_search_and_switch_to_previous_scene(
|
||||
uint32_t scene_id) {
|
||||
furi_assert(scene_manager);
|
||||
|
||||
uint32_t prev_scene_id = 0;
|
||||
uint32_t cur_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
SceneManagerIdStack_it_t scene_it;
|
||||
SceneManagerIdStack_it_last(scene_it, scene_manager->scene_id_stack);
|
||||
// Search scene with given id in navigation stack
|
||||
bool scene_found = false;
|
||||
while(!scene_found) {
|
||||
SceneManagerIdStack_previous(scene_it);
|
||||
if(SceneManagerIdStack_end_p(scene_it)) {
|
||||
return false;
|
||||
}
|
||||
prev_scene_id = *SceneManagerIdStack_ref(scene_it);
|
||||
if(prev_scene_id == scene_id) {
|
||||
scene_found = true;
|
||||
if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
|
||||
uint32_t prev_scene_id = 0;
|
||||
uint32_t cur_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
SceneManagerIdStack_it_t scene_it;
|
||||
SceneManagerIdStack_it_last(scene_it, scene_manager->scene_id_stack);
|
||||
// Search scene with given id in navigation stack
|
||||
bool scene_found = false;
|
||||
while(!scene_found) {
|
||||
SceneManagerIdStack_previous(scene_it);
|
||||
if(SceneManagerIdStack_end_p(scene_it)) {
|
||||
return false;
|
||||
}
|
||||
prev_scene_id = *SceneManagerIdStack_ref(scene_it);
|
||||
if(prev_scene_id == scene_id) {
|
||||
scene_found = true;
|
||||
}
|
||||
}
|
||||
// Remove all scene id from navigation stack
|
||||
SceneManagerIdStack_next(scene_it);
|
||||
SceneManagerIdStack_pop_until(scene_manager->scene_id_stack, scene_it);
|
||||
|
||||
scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
|
||||
scene_manager->scene_handlers->on_enter_handlers[prev_scene_id](scene_manager->context);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// Remove all scene id from navigation stack
|
||||
SceneManagerIdStack_next(scene_it);
|
||||
SceneManagerIdStack_pop_until(scene_manager->scene_id_stack, scene_it);
|
||||
|
||||
scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
|
||||
scene_manager->scene_handlers->on_enter_handlers[prev_scene_id](scene_manager->context);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool scene_manager_has_previous_scene(SceneManager* scene_manager, uint32_t scene_id) {
|
||||
furi_assert(scene_manager);
|
||||
bool scene_found = false;
|
||||
uint32_t prev_scene_id;
|
||||
SceneManagerIdStack_it_t scene_it;
|
||||
SceneManagerIdStack_it_last(scene_it, scene_manager->scene_id_stack);
|
||||
|
||||
// Perform search in scene stack
|
||||
while(!scene_found) {
|
||||
SceneManagerIdStack_previous(scene_it);
|
||||
if(SceneManagerIdStack_end_p(scene_it)) {
|
||||
break;
|
||||
}
|
||||
prev_scene_id = *SceneManagerIdStack_ref(scene_it);
|
||||
if(prev_scene_id == scene_id) {
|
||||
scene_found = true;
|
||||
if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
|
||||
uint32_t prev_scene_id;
|
||||
SceneManagerIdStack_it_t scene_it;
|
||||
SceneManagerIdStack_it_last(scene_it, scene_manager->scene_id_stack);
|
||||
|
||||
// Perform search in scene stack
|
||||
while(!scene_found) {
|
||||
SceneManagerIdStack_previous(scene_it);
|
||||
if(SceneManagerIdStack_end_p(scene_it)) {
|
||||
break;
|
||||
}
|
||||
prev_scene_id = *SceneManagerIdStack_ref(scene_it);
|
||||
if(prev_scene_id == scene_id) {
|
||||
scene_found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return scene_found;
|
||||
@@ -167,25 +195,29 @@ bool scene_manager_search_and_switch_to_another_scene(
|
||||
furi_assert(scene_manager);
|
||||
furi_assert(scene_id < scene_manager->scene_handlers->scene_num);
|
||||
|
||||
uint32_t cur_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
SceneManagerIdStack_it_t scene_it;
|
||||
SceneManagerIdStack_it(scene_it, scene_manager->scene_id_stack);
|
||||
SceneManagerIdStack_next(scene_it);
|
||||
// Remove all scene id from navigation stack until first scene
|
||||
SceneManagerIdStack_pop_until(scene_manager->scene_id_stack, scene_it);
|
||||
// Add next scene
|
||||
SceneManagerIdStack_push_back(scene_manager->scene_id_stack, scene_id);
|
||||
if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
|
||||
uint32_t cur_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
SceneManagerIdStack_it_t scene_it;
|
||||
SceneManagerIdStack_it(scene_it, scene_manager->scene_id_stack);
|
||||
SceneManagerIdStack_next(scene_it);
|
||||
// Remove all scene id from navigation stack until first scene
|
||||
SceneManagerIdStack_pop_until(scene_manager->scene_id_stack, scene_it);
|
||||
// Add next scene
|
||||
SceneManagerIdStack_push_back(scene_manager->scene_id_stack, scene_id);
|
||||
|
||||
scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
|
||||
scene_manager->scene_handlers->on_enter_handlers[scene_id](scene_manager->context);
|
||||
scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
|
||||
scene_manager->scene_handlers->on_enter_handlers[scene_id](scene_manager->context);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void scene_manager_stop(SceneManager* scene_manager) {
|
||||
furi_assert(scene_manager);
|
||||
|
||||
if(SceneManagerIdStack_size(scene_manager->scene_id_stack)) {
|
||||
if(SceneManagerIdStack_size(scene_manager->scene_id_stack) > 0) {
|
||||
uint32_t cur_scene_id = *SceneManagerIdStack_back(scene_manager->scene_id_stack);
|
||||
scene_manager->scene_handlers->on_exit_handlers[cur_scene_id](scene_manager->context);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "view_i.h"
|
||||
|
||||
View* view_alloc() {
|
||||
View* view = furi_alloc(sizeof(View));
|
||||
View* view = malloc(sizeof(View));
|
||||
view->orientation = ViewOrientationHorizontal;
|
||||
return view;
|
||||
}
|
||||
@@ -78,12 +78,12 @@ void view_allocate_model(View* view, ViewModelType type, size_t size) {
|
||||
furi_assert(view->model == NULL);
|
||||
view->model_type = type;
|
||||
if(view->model_type == ViewModelTypeLockFree) {
|
||||
view->model = furi_alloc(size);
|
||||
view->model = malloc(size);
|
||||
} else if(view->model_type == ViewModelTypeLocking) {
|
||||
ViewModelLocking* model = furi_alloc(sizeof(ViewModelLocking));
|
||||
ViewModelLocking* model = malloc(sizeof(ViewModelLocking));
|
||||
model->mutex = osMutexNew(NULL);
|
||||
furi_check(model->mutex);
|
||||
model->data = furi_alloc(size);
|
||||
model->data = malloc(size);
|
||||
view->model = model;
|
||||
} else {
|
||||
furi_assert(false);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#define TAG "ViewDispatcher"
|
||||
|
||||
ViewDispatcher* view_dispatcher_alloc() {
|
||||
ViewDispatcher* view_dispatcher = furi_alloc(sizeof(ViewDispatcher));
|
||||
ViewDispatcher* view_dispatcher = malloc(sizeof(ViewDispatcher));
|
||||
|
||||
view_dispatcher->view_port = view_port_alloc();
|
||||
view_port_draw_callback_set(
|
||||
|
||||
@@ -35,7 +35,7 @@ static void view_port_setup_canvas_orientation(const ViewPort* view_port, Canvas
|
||||
}
|
||||
|
||||
ViewPort* view_port_alloc() {
|
||||
ViewPort* view_port = furi_alloc(sizeof(ViewPort));
|
||||
ViewPort* view_port = malloc(sizeof(ViewPort));
|
||||
view_port->orientation = ViewPortOrientationHorizontal;
|
||||
view_port->is_enabled = true;
|
||||
return view_port;
|
||||
|
||||
@@ -62,7 +62,7 @@ static void view_stack_exit(void* context) {
|
||||
}
|
||||
|
||||
ViewStack* view_stack_alloc(void) {
|
||||
ViewStack* view_stack = furi_alloc(sizeof(ViewStack));
|
||||
ViewStack* view_stack = malloc(sizeof(ViewStack));
|
||||
view_stack->view = view_alloc();
|
||||
|
||||
view_allocate_model(view_stack->view, ViewModelTypeLocking, sizeof(ViewStackModel));
|
||||
|
||||
Reference in New Issue
Block a user