diff options
author | Anna Prosvetova <anna@prosvetova.me> | 2021-11-01 23:35:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-01 23:35:54 +0300 |
commit | e9e76e144c13424869bf8afabfd8e8882baa0c24 (patch) | |
tree | 36cd3122d291408c30aef00056409fff7b8f669d /applications/rpc | |
parent | b397442d895194aec75c9075e74ac820cb4e6817 (diff) |
RPC: Implement storage_stat_request (#800)
* RPC: Update protobuf sources
* RPC: Implement storage_stat_request
* RPC: Test storage_stat_request
* FuriRecord: fix use after free in destroy method.
* Furi: refactor PubSub and it's usage. Fix allocation in RPC.
* FuriCore: fix memory leak in pubsub
* FuriCore: update unsubscribe method signature in pubsub, make subscription structure lighter.
* FuriCore: remove dead code
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
Diffstat (limited to 'applications/rpc')
-rw-r--r-- | applications/rpc/rpc_gui.c | 8 | ||||
-rw-r--r-- | applications/rpc/rpc_i.h | 3 | ||||
-rw-r--r-- | applications/rpc/rpc_storage.c | 42 |
3 files changed, 47 insertions, 6 deletions
diff --git a/applications/rpc/rpc_gui.c b/applications/rpc/rpc_gui.c index e5a6aeb9..10a0afd9 100644 --- a/applications/rpc/rpc_gui.c +++ b/applications/rpc/rpc_gui.c @@ -113,9 +113,9 @@ void rpc_system_gui_send_input_event_request_process(const PB_Main* request, voi return; } - PubSub* input_events = furi_record_open("input_events"); + FuriPubSub* input_events = furi_record_open("input_events"); furi_check(input_events); - notify_pubsub(input_events, &event); + furi_pubsub_publish(input_events, &event); furi_record_close("input_events"); rpc_send_and_release_empty(rpc_gui->rpc, request->command_id, PB_CommandStatus_OK); } @@ -142,11 +142,13 @@ void* rpc_system_gui_alloc(Rpc* rpc) { rpc_handler.message_handler = rpc_system_gui_send_input_event_request_process; rpc_add_handler(rpc, PB_Main_gui_send_input_event_request_tag, &rpc_handler); - return NULL; + return rpc_gui; } void rpc_system_gui_free(void* ctx) { + furi_assert(ctx); RpcGuiSystem* rpc_gui = ctx; + furi_assert(rpc_gui->gui); gui_set_framebuffer_callback(rpc_gui->gui, NULL, NULL); furi_record_close("gui"); free(rpc_gui); diff --git a/applications/rpc/rpc_i.h b/applications/rpc/rpc_i.h index fdfcfde9..76df1e5a 100644 --- a/applications/rpc/rpc_i.h +++ b/applications/rpc/rpc_i.h @@ -1,5 +1,6 @@ #pragma once #include "rpc.h" +#include "storage/filesystem-api-defines.h" #include <pb.h> #include <pb_decode.h> #include <pb_encode.h> @@ -29,3 +30,5 @@ void rpc_system_gui_free(void* ctx); void rpc_print_message(const PB_Main* message); void rpc_cli_command_start_session(Cli* cli, string_t args, void* context); + +PB_CommandStatus rpc_system_storage_get_error(FS_Error fs_error);
\ No newline at end of file diff --git a/applications/rpc/rpc_storage.c b/applications/rpc/rpc_storage.c index f8e0a97e..99844e5d 100644 --- a/applications/rpc/rpc_storage.c +++ b/applications/rpc/rpc_storage.c @@ -51,7 +51,7 @@ static void rpc_system_storage_reset_state(RpcStorageSystem* rpc_storage, bool s } } -static PB_CommandStatus rpc_system_storage_get_error(FS_Error fs_error) { +PB_CommandStatus rpc_system_storage_get_error(FS_Error fs_error) { PB_CommandStatus pb_error; switch(fs_error) { case FSE_OK: @@ -96,6 +96,40 @@ static PB_CommandStatus rpc_system_storage_get_file_error(File* file) { return rpc_system_storage_get_error(storage_file_get_error(file)); } +static void rpc_system_storage_stat_process(const PB_Main* request, void* context) { + furi_assert(request); + furi_assert(context); + furi_assert(request->which_content == PB_Main_storage_stat_request_tag); + + RpcStorageSystem* rpc_storage = context; + rpc_system_storage_reset_state(rpc_storage, true); + + PB_Main* response = furi_alloc(sizeof(PB_Main)); + response->command_id = request->command_id; + + Storage* fs_api = furi_record_open("storage"); + + const char* path = request->content.storage_stat_request.path; + FileInfo fileinfo; + FS_Error error = storage_common_stat(fs_api, path, &fileinfo); + + response->command_status = rpc_system_storage_get_error(error); + response->which_content = PB_Main_empty_tag; + + if(error == FSE_OK) { + response->which_content = PB_Main_storage_stat_response_tag; + response->content.storage_stat_response.has_file = true; + response->content.storage_stat_response.file.type = (fileinfo.flags & FSF_DIRECTORY) ? + PB_Storage_File_FileType_DIR : + PB_Storage_File_FileType_FILE; + response->content.storage_stat_response.file.size = fileinfo.size; + } + + rpc_send_and_release(rpc_storage->rpc, response); + free(response); + furi_record_close("storage"); +} + static void rpc_system_storage_list_root(const PB_Main* request, void* context) { RpcStorageSystem* rpc_storage = context; const char* hard_coded_dirs[] = {"any", "int", "ext"}; @@ -140,11 +174,10 @@ static void rpc_system_storage_list_process(const PB_Main* request, void* contex PB_Main response = { .command_id = request->command_id, .has_next = false, - .which_content = PB_Main_storage_list_request_tag, + .which_content = PB_Main_storage_list_response_tag, .command_status = PB_CommandStatus_OK, }; PB_Storage_ListResponse* list = &response.content.storage_list_response; - response.which_content = PB_Main_storage_list_response_tag; bool finish = false; int i = 0; @@ -434,6 +467,9 @@ void* rpc_system_storage_alloc(Rpc* rpc) { .context = rpc_storage, }; + rpc_handler.message_handler = rpc_system_storage_stat_process; + rpc_add_handler(rpc, PB_Main_storage_stat_request_tag, &rpc_handler); + rpc_handler.message_handler = rpc_system_storage_list_process; rpc_add_handler(rpc, PB_Main_storage_list_request_tag, &rpc_handler); |