@@ -31,10 +31,18 @@ CliShellKeyComboSet* component_key_combo_sets[] = {
3131static_assert (CliShellComponentMAX == COUNT_OF (component_key_combo_sets ));
3232
3333typedef enum {
34- CliShellStorageEventMount ,
35- CliShellStorageEventUnmount ,
34+ CliShellStorageEventMount = ( 1 << 0 ) ,
35+ CliShellStorageEventUnmount = ( 1 << 1 ) ,
3636} CliShellStorageEvent ;
3737
38+ #define CliShellStorageEventAll (CliShellStorageEventMount | CliShellStorageEventUnmount)
39+
40+ typedef struct {
41+ Storage * storage ;
42+ FuriPubSubSubscription * subscription ;
43+ FuriEventFlag * event_flag ;
44+ } CliShellStorage ;
45+
3846struct CliShell {
3947 // Set and freed by external thread
4048 CliShellMotd motd ;
@@ -49,11 +57,7 @@ struct CliShell {
4957 FuriEventLoop * event_loop ;
5058 CliAnsiParser * ansi_parser ;
5159 FuriEventLoopTimer * ansi_parsing_timer ;
52-
53- Storage * storage ;
54- FuriPubSubSubscription * storage_subscription ;
55- FuriMessageQueue * storage_event_queue ;
56-
60+ CliShellStorage storage ;
5761 void * components [CliShellComponentMAX ];
5862};
5963
@@ -256,31 +260,32 @@ const char* cli_shell_get_prompt(CliShell* cli_shell) {
256260// Event handlers
257261// ==============
258262
263+ static void cli_shell_signal_storage_event (CliShell * cli_shell , CliShellStorageEvent event ) {
264+ furi_check (!(furi_event_flag_set (cli_shell -> storage .event_flag , event ) & FuriFlagError ));
265+ }
266+
259267static void cli_shell_storage_event (const void * message , void * context ) {
260268 CliShell * cli_shell = context ;
261269 const StorageEvent * event = message ;
262270
263271 if (event -> type == StorageEventTypeCardMount ) {
264- CliShellStorageEvent cli_event = CliShellStorageEventMount ;
265- furi_check (
266- furi_message_queue_put (cli_shell -> storage_event_queue , & cli_event , 0 ) == FuriStatusOk );
272+ cli_shell_signal_storage_event (cli_shell , CliShellStorageEventMount );
267273 } else if (event -> type == StorageEventTypeCardUnmount ) {
268- CliShellStorageEvent cli_event = CliShellStorageEventUnmount ;
269- furi_check (
270- furi_message_queue_put (cli_shell -> storage_event_queue , & cli_event , 0 ) == FuriStatusOk );
274+ cli_shell_signal_storage_event (cli_shell , CliShellStorageEventUnmount );
271275 }
272276}
273277
274278static void cli_shell_storage_internal_event (FuriEventLoopObject * object , void * context ) {
275279 CliShell * cli_shell = context ;
276- FuriMessageQueue * queue = object ;
277- CliShellStorageEvent event ;
278- furi_check (furi_message_queue_get (queue , & event , 0 ) == FuriStatusOk );
280+ FuriEventFlag * event_flag = object ;
281+ CliShellStorageEvent event =
282+ furi_event_flag_wait (event_flag , FuriFlagWaitAll , FuriFlagWaitAny , 0 );
283+ furi_check (!(event & FuriFlagError ));
279284
280- if (event == CliShellStorageEventMount ) {
281- cli_registry_reload_external_commands (cli_shell -> registry , cli_shell -> ext_config );
282- } else if (event == CliShellStorageEventUnmount ) {
285+ if (event & CliShellStorageEventUnmount ) {
283286 cli_registry_remove_external_commands (cli_shell -> registry );
287+ } else if (event & CliShellStorageEventMount ) {
288+ cli_registry_reload_external_commands (cli_shell -> registry , cli_shell -> ext_config );
284289 } else {
285290 furi_crash ();
286291 }
@@ -377,25 +382,26 @@ static void cli_shell_init(CliShell* shell) {
377382 shell -> ansi_parsing_timer = furi_event_loop_timer_alloc (
378383 shell -> event_loop , cli_shell_timer_expired , FuriEventLoopTimerTypeOnce , shell );
379384
380- shell -> storage_event_queue = furi_message_queue_alloc ( 1 , sizeof ( CliShellStorageEvent ) );
381- furi_event_loop_subscribe_message_queue (
385+ shell -> storage . event_flag = furi_event_flag_alloc ( );
386+ furi_event_loop_subscribe_event_flag (
382387 shell -> event_loop ,
383- shell -> storage_event_queue ,
388+ shell -> storage . event_flag ,
384389 FuriEventLoopEventIn ,
385390 cli_shell_storage_internal_event ,
386391 shell );
387- shell -> storage = furi_record_open (RECORD_STORAGE );
388- shell -> storage_subscription =
389- furi_pubsub_subscribe ( storage_get_pubsub (shell -> storage ), cli_shell_storage_event , shell );
392+ shell -> storage . storage = furi_record_open (RECORD_STORAGE );
393+ shell -> storage . subscription = furi_pubsub_subscribe (
394+ storage_get_pubsub (shell -> storage . storage ), cli_shell_storage_event , shell );
390395
391396 cli_shell_install_pipe (shell );
392397}
393398
394399static void cli_shell_deinit (CliShell * shell ) {
395- furi_pubsub_unsubscribe (storage_get_pubsub (shell -> storage ), shell -> storage_subscription );
400+ furi_pubsub_unsubscribe (
401+ storage_get_pubsub (shell -> storage .storage ), shell -> storage .subscription );
396402 furi_record_close (RECORD_STORAGE );
397- furi_event_loop_unsubscribe (shell -> event_loop , shell -> storage_event_queue );
398- furi_message_queue_free (shell -> storage_event_queue );
403+ furi_event_loop_unsubscribe (shell -> event_loop , shell -> storage . event_flag );
404+ furi_event_flag_free (shell -> storage . event_flag );
399405
400406 cli_shell_completions_free (shell -> components [CliShellComponentCompletions ]);
401407 cli_shell_line_free (shell -> components [CliShellComponentLine ]);
0 commit comments