[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:
SG
2022-02-19 05:53:46 +10:00
committed by GitHub
parent 242241987e
commit 274c12fc56
257 changed files with 4480 additions and 2657 deletions

View File

@@ -349,13 +349,13 @@ void rpc_print_message(const PB_Main* message) {
}
static Rpc* rpc_alloc(void) {
Rpc* rpc = furi_alloc(sizeof(Rpc));
Rpc* rpc = malloc(sizeof(Rpc));
rpc->busy_mutex = osMutexNew(NULL);
rpc->busy = false;
rpc->events = osEventFlagsNew(NULL);
rpc->stream = xStreamBufferCreate(RPC_BUFFER_SIZE, 1);
rpc->decoded_message = furi_alloc(sizeof(PB_Main));
rpc->decoded_message = malloc(sizeof(PB_Main));
rpc->decoded_message->cb_content.funcs.decode = content_callback;
rpc->decoded_message->cb_content.arg = rpc;
@@ -384,7 +384,7 @@ RpcSession* rpc_session_open(Rpc* rpc) {
session->decode_error = false;
xStreamBufferReset(rpc->stream);
session->system_contexts = furi_alloc(COUNT_OF(rpc_systems) * sizeof(void*));
session->system_contexts = malloc(COUNT_OF(rpc_systems) * sizeof(void*));
for(int i = 0; i < COUNT_OF(rpc_systems); ++i) {
session->system_contexts[i] = rpc_systems[i].alloc(rpc);
}
@@ -554,7 +554,7 @@ void rpc_send_and_release(Rpc* rpc, PB_Main* message) {
bool result = pb_encode_ex(&ostream, &PB_Main_msg, message, PB_ENCODE_DELIMITED);
furi_check(result && ostream.bytes_written);
uint8_t* buffer = furi_alloc(ostream.bytes_written);
uint8_t* buffer = malloc(ostream.bytes_written);
ostream = pb_ostream_from_buffer(buffer, ostream.bytes_written);
pb_encode_ex(&ostream, &PB_Main_msg, message, PB_ENCODE_DELIMITED);

View File

@@ -40,7 +40,7 @@ void rpc_cli_command_start_session(Cli* cli, string_t args, void* context) {
rpc_session_set_send_bytes_callback(rpc_session, rpc_send_bytes_callback);
rpc_session_set_close_callback(rpc_session, rpc_session_close_callback);
uint8_t* buffer = furi_alloc(CLI_READ_BUFFER_SIZE);
uint8_t* buffer = malloc(CLI_READ_BUFFER_SIZE);
size_t size_received = 0;
while(1) {

View File

@@ -21,11 +21,11 @@ static void
RpcGuiSystem* rpc_gui = context;
PB_Main* frame = furi_alloc(sizeof(PB_Main));
PB_Main* frame = malloc(sizeof(PB_Main));
frame->which_content = PB_Main_gui_screen_frame_tag;
frame->command_status = PB_CommandStatus_OK;
frame->content.gui_screen_frame.data = furi_alloc(PB_BYTES_ARRAY_T_ALLOCSIZE(size));
frame->content.gui_screen_frame.data = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(size));
uint8_t* buffer = frame->content.gui_screen_frame.data->bytes;
uint16_t* frame_size_msg = &frame->content.gui_screen_frame.data->size;
*frame_size_msg = size;
@@ -160,7 +160,7 @@ static void rpc_system_gui_start_virtual_display_process(const PB_Main* request,
// Using display framebuffer size as an XBM buffer size is like comparing apples and oranges
// Glad they both are 1024 for now
size_t buffer_size = canvas_get_buffer_size(rpc_gui->gui->canvas);
rpc_gui->virtual_display_buffer = furi_alloc(buffer_size);
rpc_gui->virtual_display_buffer = malloc(buffer_size);
if(request->content.gui_start_virtual_display_request.has_first_frame) {
size_t buffer_size = canvas_get_buffer_size(rpc_gui->gui->canvas);
@@ -223,7 +223,7 @@ static void rpc_system_gui_virtual_display_frame_process(const PB_Main* request,
void* rpc_system_gui_alloc(Rpc* rpc) {
furi_assert(rpc);
RpcGuiSystem* rpc_gui = furi_alloc(sizeof(RpcGuiSystem));
RpcGuiSystem* rpc_gui = malloc(sizeof(RpcGuiSystem));
rpc_gui->gui = furi_record_open("gui");
rpc_gui->rpc = rpc;

View File

@@ -104,7 +104,7 @@ static void rpc_system_storage_info_process(const PB_Main* request, void* contex
RpcStorageSystem* rpc_storage = context;
rpc_system_storage_reset_state(rpc_storage, true);
PB_Main* response = furi_alloc(sizeof(PB_Main));
PB_Main* response = malloc(sizeof(PB_Main));
response->command_id = request->command_id;
Storage* fs_api = furi_record_open("storage");
@@ -135,7 +135,7 @@ static void rpc_system_storage_stat_process(const PB_Main* request, void* contex
RpcStorageSystem* rpc_storage = context;
rpc_system_storage_reset_state(rpc_storage, true);
PB_Main* response = furi_alloc(sizeof(PB_Main));
PB_Main* response = malloc(sizeof(PB_Main));
response->command_id = request->command_id;
Storage* fs_api = furi_record_open("storage");
@@ -178,7 +178,7 @@ static void rpc_system_storage_list_root(const PB_Main* request, void* context)
response.content.storage_list_response.file[i].data = NULL;
response.content.storage_list_response.file[i].size = 0;
response.content.storage_list_response.file[i].type = PB_Storage_File_FileType_DIR;
char* str = furi_alloc(strlen(hard_coded_dirs[i]) + 1);
char* str = malloc(strlen(hard_coded_dirs[i]) + 1);
strcpy(str, hard_coded_dirs[i]);
response.content.storage_list_response.file[i].name = str;
}
@@ -221,7 +221,7 @@ static void rpc_system_storage_list_process(const PB_Main* request, void* contex
while(!finish) {
FileInfo fileinfo;
char* name = furi_alloc(MAX_NAME_LENGTH + 1);
char* name = malloc(MAX_NAME_LENGTH + 1);
if(storage_dir_read(dir, &fileinfo, name, MAX_NAME_LENGTH)) {
if(i == COUNT_OF(list->file)) {
list->file_count = i;
@@ -259,7 +259,7 @@ static void rpc_system_storage_read_process(const PB_Main* request, void* contex
rpc_system_storage_reset_state(rpc_storage, true);
/* use same message memory to send reponse */
PB_Main* response = furi_alloc(sizeof(PB_Main));
PB_Main* response = malloc(sizeof(PB_Main));
const char* path = request->content.storage_read_request.path;
Storage* fs_api = furi_record_open("storage");
File* file = storage_file_alloc(fs_api);
@@ -273,7 +273,7 @@ static void rpc_system_storage_read_process(const PB_Main* request, void* contex
response->command_status = PB_CommandStatus_OK;
response->content.storage_read_response.has_file = true;
response->content.storage_read_response.file.data =
furi_alloc(PB_BYTES_ARRAY_T_ALLOCSIZE(MIN(size_left, MAX_DATA_SIZE)));
malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(MIN(size_left, MAX_DATA_SIZE)));
uint8_t* buffer = response->content.storage_read_response.file.data->bytes;
uint16_t* read_size_msg = &response->content.storage_read_response.file.data->size;
@@ -357,7 +357,7 @@ static bool rpc_system_storage_is_dir_is_empty(Storage* fs_api, const char* path
if((error == FSE_OK) && (fileinfo.flags & FSF_DIRECTORY)) {
File* dir = storage_file_alloc(fs_api);
if(storage_dir_open(dir, path)) {
char* name = furi_alloc(MAX_NAME_LENGTH);
char* name = malloc(MAX_NAME_LENGTH);
is_dir_is_empty = !storage_dir_read(dir, &fileinfo, name, MAX_NAME_LENGTH);
free(name);
}
@@ -508,7 +508,7 @@ static void rpc_system_storage_rename_process(const PB_Main* request, void* cont
void* rpc_system_storage_alloc(Rpc* rpc) {
furi_assert(rpc);
RpcStorageSystem* rpc_storage = furi_alloc(sizeof(RpcStorageSystem));
RpcStorageSystem* rpc_storage = malloc(sizeof(RpcStorageSystem));
rpc_storage->api = furi_record_open("storage");
rpc_storage->rpc = rpc;
rpc_storage->state = RpcStorageStateIdle;

View File

@@ -27,7 +27,7 @@ static void rpc_system_system_ping_process(const PB_Main* msg_request, void* con
const PB_System_PingRequest* request = &msg_request->content.system_ping_request;
PB_System_PingResponse* response = &msg_response.content.system_ping_response;
if(request->data && (request->data->size > 0)) {
response->data = furi_alloc(PB_BYTES_ARRAY_T_ALLOCSIZE(request->data->size));
response->data = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(request->data->size));
memcpy(response->data->bytes, request->data->bytes, request->data->size);
response->data->size = request->data->size;
}
@@ -84,7 +84,7 @@ static void rpc_system_system_device_info_process(const PB_Main* request, void*
furi_assert(context);
Rpc* rpc = context;
PB_Main* response = furi_alloc(sizeof(PB_Main));
PB_Main* response = malloc(sizeof(PB_Main));
response->command_id = request->command_id;
response->which_content = PB_Main_system_device_info_response_tag;
response->command_status = PB_CommandStatus_OK;
@@ -108,7 +108,7 @@ static void rpc_system_system_get_datetime_process(const PB_Main* request, void*
FuriHalRtcDateTime datetime;
furi_hal_rtc_get_datetime(&datetime);
PB_Main* response = furi_alloc(sizeof(PB_Main));
PB_Main* response = malloc(sizeof(PB_Main));
response->command_id = request->command_id;
response->which_content = PB_Main_system_get_datetime_response_tag;
response->command_status = PB_CommandStatus_OK;
@@ -180,7 +180,7 @@ static void rpc_system_system_protobuf_version_process(const PB_Main* request, v
Rpc* rpc = context;
PB_Main* response = furi_alloc(sizeof(PB_Main));
PB_Main* response = malloc(sizeof(PB_Main));
response->command_id = request->command_id;
response->has_next = false;
response->command_status = PB_CommandStatus_OK;