diff options
author | William Wilgus <wilgus.william@gmail.com> | 2023-03-20 22:15:33 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2023-03-25 10:02:43 -0400 |
commit | a2e5d9563f9dec84907f4f2060af6dfad895c4ba (patch) | |
tree | e2c27f4fca350e1f1ce8ba2ef8fe30fbb341c3c0 /apps/plugins | |
parent | 2e99e2175b48cc00274b03bb4aecf5d01403110d (diff) | |
download | rockbox-a2e5d9563f9dec84907f4f2060af6dfad895c4ba.tar.gz rockbox-a2e5d9563f9dec84907f4f2060af6dfad895c4ba.zip |
[Feature] resume TSR plugins after interruption WIP
save tsr plugin path for later
resume tsr plugin when user stops the interrupting plugin
expand return of tsr_exit function to allow
continue, suspend, terminate
tsr plugins check parameter at start to determine if
the plugin is being resumed
Change-Id: I6fc70de664c7771e7dbc9a1af7a831e7b50b1d15
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/announce_status.c | 107 | ||||
-rw-r--r-- | apps/plugins/battery_bench.c | 68 | ||||
-rw-r--r-- | apps/plugins/lastfm_scrobbler.c | 32 | ||||
-rw-r--r-- | apps/plugins/test_usb.c | 13 |
4 files changed, 126 insertions, 94 deletions
diff --git a/apps/plugins/announce_status.c b/apps/plugins/announce_status.c index 77e9015000..1ccfc1e70a 100644 --- a/apps/plugins/announce_status.c +++ b/apps/plugins/announce_status.c | |||
@@ -97,6 +97,7 @@ enum plugin_status plugin_start(const void* parameter); /* entry */ | |||
97 | static struct | 97 | static struct |
98 | { | 98 | { |
99 | bool exiting; /* signal to the thread that we want to exit */ | 99 | bool exiting; /* signal to the thread that we want to exit */ |
100 | bool resume; | ||
100 | unsigned int id; /* worker thread id */ | 101 | unsigned int id; /* worker thread id */ |
101 | struct event_queue queue; /* thread event queue */ | 102 | struct event_queue queue; /* thread event queue */ |
102 | long stack[THREAD_STACK_SIZE / sizeof(long)]; | 103 | long stack[THREAD_STACK_SIZE / sizeof(long)]; |
@@ -393,7 +394,7 @@ static int settings_menu(void) | |||
393 | break; | 394 | break; |
394 | case 4: /*sep*/ | 395 | case 4: /*sep*/ |
395 | continue; | 396 | continue; |
396 | case 5: | 397 | case 5: /* quit the plugin */ |
397 | return -1; | 398 | return -1; |
398 | break; | 399 | break; |
399 | case 6: | 400 | case 6: |
@@ -433,7 +434,8 @@ void thread(void) | |||
433 | in_usb = false; | 434 | in_usb = false; |
434 | /*fall through*/ | 435 | /*fall through*/ |
435 | case EV_STARTUP: | 436 | case EV_STARTUP: |
436 | rb->beep_play(1500, 100, 1000); | 437 | if (!gThread.resume) |
438 | rb->beep_play(1500, 100, 1000); | ||
437 | break; | 439 | break; |
438 | case EV_EXIT: | 440 | case EV_EXIT: |
439 | return; | 441 | return; |
@@ -479,17 +481,45 @@ void thread_quit(void) | |||
479 | } | 481 | } |
480 | } | 482 | } |
481 | 483 | ||
484 | static bool check_user_input(void) | ||
485 | { | ||
486 | int i = 0; | ||
487 | rb->button_clear_queue(); | ||
488 | if (rb->button_get_w_tmo(HZ) > BUTTON_NONE) | ||
489 | { | ||
490 | while ((rb->button_get(false) & BUTTON_REL) != BUTTON_REL) | ||
491 | { | ||
492 | if (i & 1) | ||
493 | rb->beep_play(800, 100, 1000 - i * (1000 / 15)); | ||
494 | |||
495 | if (++i > 15) | ||
496 | { | ||
497 | return true; | ||
498 | } | ||
499 | rb->sleep(HZ / 5); | ||
500 | } | ||
501 | } | ||
502 | return false; | ||
503 | } | ||
504 | |||
482 | /* callback to end the TSR plugin, called before a new one gets loaded */ | 505 | /* callback to end the TSR plugin, called before a new one gets loaded */ |
483 | static bool exit_tsr(bool reenter) | 506 | static int exit_tsr(bool reenter) |
484 | { | 507 | { |
485 | if (reenter) | 508 | if (reenter) |
486 | { | 509 | { |
487 | rb->queue_post(&gThread.queue, EV_OTHINSTANCE, 0); | 510 | rb->queue_post(&gThread.queue, EV_OTHINSTANCE, 0); |
488 | return false; /* dont let it start again */ | 511 | |
512 | /* quit the plugin if user holds a button */ | ||
513 | if (check_user_input() == true) | ||
514 | { | ||
515 | if (settings_menu() < 0) | ||
516 | return PLUGIN_TSR_TERMINATE; /*kill TSR dont let it start again */ | ||
517 | } | ||
518 | return PLUGIN_TSR_CONTINUE; /* dont let new plugin start*/ | ||
489 | } | 519 | } |
490 | thread_quit(); | 520 | thread_quit(); |
491 | 521 | ||
492 | return true; | 522 | return PLUGIN_TSR_SUSPEND; |
493 | } | 523 | } |
494 | 524 | ||
495 | 525 | ||
@@ -497,58 +527,35 @@ static bool exit_tsr(bool reenter) | |||
497 | 527 | ||
498 | int plugin_main(const void* parameter) | 528 | int plugin_main(const void* parameter) |
499 | { | 529 | { |
500 | (void)parameter; | ||
501 | bool settings = false; | ||
502 | int i = 0; | ||
503 | |||
504 | rb->memset(&gThread, 0, sizeof(gThread)); | 530 | rb->memset(&gThread, 0, sizeof(gThread)); |
505 | 531 | ||
506 | gAnnounce.index = 0; | 532 | gAnnounce.index = 0; |
507 | gAnnounce.timeout = 0; | 533 | gAnnounce.timeout = 0; |
508 | 534 | /* Resume plugin ? */ | |
509 | rb->splash(HZ / 2, "Announce Status"); | 535 | if (parameter == rb->plugin_tsr) |
510 | |||
511 | if (configfile_load(CFG_FILE, config, gCfg_sz, CFG_VER) < 0) | ||
512 | { | ||
513 | /* If the loading failed, save a new config file */ | ||
514 | config_set_defaults(); | ||
515 | configfile_save(CFG_FILE, config, gCfg_sz, CFG_VER); | ||
516 | |||
517 | rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS)); | ||
518 | } | ||
519 | |||
520 | if (gAnnounce.show_prompt) | ||
521 | { | 536 | { |
522 | if (rb->mixer_channel_status(PCM_MIXER_CHAN_PLAYBACK) != CHANNEL_PLAYING) | 537 | gThread.resume = true; |
523 | { | ||
524 | rb->talk_id(LANG_HOLD_FOR_SETTINGS, false); | ||
525 | } | ||
526 | rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS)); | ||
527 | } | 538 | } |
528 | 539 | else | |
529 | rb->button_clear_queue(); | ||
530 | if (rb->button_get_w_tmo(HZ) > BUTTON_NONE) | ||
531 | { | 540 | { |
532 | while ((rb->button_get(false) & BUTTON_REL) != BUTTON_REL) | 541 | rb->splash(HZ / 2, "Announce Status"); |
542 | if (gAnnounce.show_prompt) | ||
533 | { | 543 | { |
534 | if (i & 1) | 544 | if (rb->mixer_channel_status(PCM_MIXER_CHAN_PLAYBACK) != CHANNEL_PLAYING) |
535 | rb->beep_play(800, 100, 1000); | ||
536 | |||
537 | if (++i > 15) | ||
538 | { | 545 | { |
539 | settings = true; | 546 | rb->talk_id(LANG_HOLD_FOR_SETTINGS, false); |
540 | break; | ||
541 | } | 547 | } |
542 | rb->sleep(HZ / 5); | 548 | rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS)); |
543 | } | 549 | } |
544 | } | ||
545 | 550 | ||
546 | if (settings) | 551 | |
547 | { | 552 | if (check_user_input() == true) |
548 | rb->splash(100, ID2P(LANG_SETTINGS)); | 553 | { |
549 | int ret = settings_menu(); | 554 | rb->splash(100, ID2P(LANG_SETTINGS)); |
550 | if (ret < 0) | 555 | int ret = settings_menu(); |
551 | return 0; | 556 | if (ret < 0) |
557 | return 0; | ||
558 | } | ||
552 | } | 559 | } |
553 | 560 | ||
554 | gAnnounce.timeout = *rb->current_tick; | 561 | gAnnounce.timeout = *rb->current_tick; |
@@ -571,6 +578,16 @@ enum plugin_status plugin_start(const void* parameter) | |||
571 | /* now go ahead and have fun! */ | 578 | /* now go ahead and have fun! */ |
572 | if (rb->usb_inserted() == true) | 579 | if (rb->usb_inserted() == true) |
573 | return PLUGIN_USB_CONNECTED; | 580 | return PLUGIN_USB_CONNECTED; |
581 | |||
582 | config_set_defaults(); | ||
583 | if (configfile_load(CFG_FILE, config, gCfg_sz, CFG_VER) < 0) | ||
584 | { | ||
585 | /* If the loading failed, save a new config file */ | ||
586 | config_set_defaults(); | ||
587 | configfile_save(CFG_FILE, config, gCfg_sz, CFG_VER); | ||
588 | rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS)); | ||
589 | } | ||
590 | |||
574 | int ret = plugin_main(parameter); | 591 | int ret = plugin_main(parameter); |
575 | return (ret==0) ? PLUGIN_OK : PLUGIN_ERROR; | 592 | return (ret==0) ? PLUGIN_OK : PLUGIN_ERROR; |
576 | } | 593 | } |
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c index 17d3b918cf..f258492363 100644 --- a/apps/plugins/battery_bench.c +++ b/apps/plugins/battery_bench.c | |||
@@ -289,11 +289,11 @@ static struct event_queue thread_q SHAREDBSS_ATTR; | |||
289 | static bool in_usb_mode; | 289 | static bool in_usb_mode; |
290 | static unsigned int buf_idx; | 290 | static unsigned int buf_idx; |
291 | 291 | ||
292 | static bool exit_tsr(bool reenter) | 292 | static int exit_tsr(bool reenter) |
293 | { | 293 | { |
294 | bool is_exit; | 294 | int exit_status; |
295 | long button; | 295 | long button; |
296 | (void)reenter; | 296 | |
297 | rb->lcd_clear_display(); | 297 | rb->lcd_clear_display(); |
298 | rb->lcd_puts_scroll(0, 0, "Batt.Bench is currently running."); | 298 | rb->lcd_puts_scroll(0, 0, "Batt.Bench is currently running."); |
299 | rb->lcd_puts_scroll(0, 1, "Press " BATTERY_OFF_TXT " to cancel the test"); | 299 | rb->lcd_puts_scroll(0, 1, "Press " BATTERY_OFF_TXT " to cancel the test"); |
@@ -313,16 +313,17 @@ static bool exit_tsr(bool reenter) | |||
313 | rb->thread_wait(gThread.id); | 313 | rb->thread_wait(gThread.id); |
314 | /* remove the thread's queue from the broadcast list */ | 314 | /* remove the thread's queue from the broadcast list */ |
315 | rb->queue_delete(&thread_q); | 315 | rb->queue_delete(&thread_q); |
316 | is_exit = true; | 316 | exit_status = (reenter ? PLUGIN_TSR_TERMINATE : PLUGIN_TSR_SUSPEND); |
317 | |||
317 | } | 318 | } |
318 | else is_exit = false; | 319 | else exit_status = PLUGIN_TSR_CONTINUE; |
319 | 320 | ||
320 | break; | 321 | break; |
321 | } | 322 | } |
322 | FOR_NB_SCREENS(idx) | 323 | FOR_NB_SCREENS(idx) |
323 | rb->screens[idx]->scroll_stop(); | 324 | rb->screens[idx]->scroll_stop(); |
324 | 325 | ||
325 | return is_exit; | 326 | return exit_status; |
326 | } | 327 | } |
327 | 328 | ||
328 | #define BIT_CHARGER 0x1 | 329 | #define BIT_CHARGER 0x1 |
@@ -502,14 +503,19 @@ static void put_centered_str(const char* str, plcdfunc putsxy, int lcd_width, in | |||
502 | 503 | ||
503 | enum plugin_status plugin_start(const void* parameter) | 504 | enum plugin_status plugin_start(const void* parameter) |
504 | { | 505 | { |
505 | (void)parameter; | ||
506 | int button, fd; | 506 | int button, fd; |
507 | bool resume = false; | ||
507 | bool on = false; | 508 | bool on = false; |
508 | start_tick = *rb->current_tick; | 509 | start_tick = *rb->current_tick; |
509 | int i; | 510 | int i; |
510 | const char *msgs[] = { "Battery Benchmark","Check file", BATTERY_LOG, | 511 | const char *msgs[] = { "Battery Benchmark","Check file", BATTERY_LOG, |
511 | "for more info", BATTERY_ON_TXT, BATTERY_OFF_TXT " - quit" }; | 512 | "for more info", BATTERY_ON_TXT, BATTERY_OFF_TXT " - quit" }; |
512 | rb->lcd_clear_display(); | 513 | |
514 | if (parameter == rb->plugin_tsr) | ||
515 | { | ||
516 | resume = true; | ||
517 | on = true; | ||
518 | } | ||
513 | 519 | ||
514 | rb->lcd_clear_display(); | 520 | rb->lcd_clear_display(); |
515 | rb->lcd_setfont(FONT_SYSFIXED); | 521 | rb->lcd_setfont(FONT_SYSFIXED); |
@@ -529,36 +535,38 @@ enum plugin_status plugin_start(const void* parameter) | |||
529 | rb->lcd_remote_putsxy,LCD_REMOTE_WIDTH,2); | 535 | rb->lcd_remote_putsxy,LCD_REMOTE_WIDTH,2); |
530 | rb->lcd_remote_update(); | 536 | rb->lcd_remote_update(); |
531 | #endif | 537 | #endif |
532 | 538 | if (!resume) | |
533 | do | ||
534 | { | 539 | { |
535 | button = rb->button_get(true); | 540 | do |
536 | switch (button) | ||
537 | { | 541 | { |
538 | case BATTERY_ON: | 542 | button = rb->button_get(true); |
539 | #ifdef BATTERY_RC_ON | 543 | switch (button) |
540 | case BATTERY_RC_ON: | 544 | { |
541 | #endif | 545 | case BATTERY_ON: |
542 | on = true; | 546 | #ifdef BATTERY_RC_ON |
543 | break; | 547 | case BATTERY_RC_ON: |
544 | case BATTERY_OFF: | 548 | #endif |
545 | #ifdef BATTERY_RC_OFF | 549 | on = true; |
546 | case BATTERY_RC_OFF: | 550 | break; |
547 | #endif | 551 | case BATTERY_OFF: |
548 | return PLUGIN_OK; | 552 | #ifdef BATTERY_RC_OFF |
549 | 553 | case BATTERY_RC_OFF: | |
550 | default: | 554 | #endif |
551 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) | 555 | return PLUGIN_OK; |
552 | return PLUGIN_USB_CONNECTED; | 556 | |
553 | } | 557 | default: |
554 | }while(!on); | 558 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) |
555 | 559 | return PLUGIN_USB_CONNECTED; | |
560 | } | ||
561 | }while(!on); | ||
562 | } | ||
556 | fd = rb->open(BATTERY_LOG, O_RDONLY); | 563 | fd = rb->open(BATTERY_LOG, O_RDONLY); |
557 | if (fd < 0) | 564 | if (fd < 0) |
558 | { | 565 | { |
559 | fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT, 0666); | 566 | fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT, 0666); |
560 | if (fd >= 0) | 567 | if (fd >= 0) |
561 | { | 568 | { |
569 | |||
562 | rb->fdprintf(fd, | 570 | rb->fdprintf(fd, |
563 | "# This plugin will log your battery performance in a\n" | 571 | "# This plugin will log your battery performance in a\n" |
564 | "# file (%s) every minute.\n" | 572 | "# file (%s) every minute.\n" |
diff --git a/apps/plugins/lastfm_scrobbler.c b/apps/plugins/lastfm_scrobbler.c index 5565eed4c5..dce6be0d1e 100644 --- a/apps/plugins/lastfm_scrobbler.c +++ b/apps/plugins/lastfm_scrobbler.c | |||
@@ -98,7 +98,7 @@ static struct | |||
98 | bool force_flush; | 98 | bool force_flush; |
99 | } gCache; | 99 | } gCache; |
100 | 100 | ||
101 | static struct | 101 | static struct lastfm_config |
102 | { | 102 | { |
103 | int savepct; | 103 | int savepct; |
104 | int beeplvl; | 104 | int beeplvl; |
@@ -528,7 +528,7 @@ void thread_quit(void) | |||
528 | } | 528 | } |
529 | 529 | ||
530 | /* callback to end the TSR plugin, called before a new one gets loaded */ | 530 | /* callback to end the TSR plugin, called before a new one gets loaded */ |
531 | static bool exit_tsr(bool reenter) | 531 | static int exit_tsr(bool reenter) |
532 | { | 532 | { |
533 | MENUITEM_STRINGLIST(menu, ID2P(LANG_AUDIOSCROBBLER), NULL, ID2P(LANG_SETTINGS), | 533 | MENUITEM_STRINGLIST(menu, ID2P(LANG_AUDIOSCROBBLER), NULL, ID2P(LANG_SETTINGS), |
534 | "Flush Cache", "Exit Plugin", ID2P(LANG_BACK)); | 534 | "Flush Cache", "Exit Plugin", ID2P(LANG_BACK)); |
@@ -556,19 +556,13 @@ static bool exit_tsr(bool reenter) | |||
556 | case 2: /* exit plugin - quit */ | 556 | case 2: /* exit plugin - quit */ |
557 | if(rb->gui_syncyesno_run(&quit_prompt, NULL, NULL) == YESNO_YES) | 557 | if(rb->gui_syncyesno_run(&quit_prompt, NULL, NULL) == YESNO_YES) |
558 | { | 558 | { |
559 | scrobbler_flush_cache(); | ||
559 | thread_quit(); | 560 | thread_quit(); |
560 | if (reenter) | 561 | return (reenter ? PLUGIN_TSR_TERMINATE : PLUGIN_TSR_SUSPEND); |
561 | rb->plugin_tsr(NULL); /* remove TSR cb */ | ||
562 | return !reenter; | ||
563 | } | 562 | } |
564 | 563 | /* Fall Through */ | |
565 | if(!reenter) | ||
566 | return false; | ||
567 | |||
568 | break; | ||
569 | |||
570 | case 3: /* back to menu */ | 564 | case 3: /* back to menu */ |
571 | return false; | 565 | return PLUGIN_TSR_CONTINUE; |
572 | } | 566 | } |
573 | } | 567 | } |
574 | } | 568 | } |
@@ -576,7 +570,17 @@ static bool exit_tsr(bool reenter) | |||
576 | /****************** main ******************/ | 570 | /****************** main ******************/ |
577 | static int plugin_main(const void* parameter) | 571 | static int plugin_main(const void* parameter) |
578 | { | 572 | { |
579 | (void)parameter; | 573 | struct lastfm_config cfg; |
574 | rb->memcpy(&cfg, & gConfig, sizeof(struct lastfm_config)); | ||
575 | |||
576 | /* Resume plugin ? */ | ||
577 | if (parameter == rb->plugin_tsr) | ||
578 | { | ||
579 | |||
580 | gConfig.beeplvl = 0; | ||
581 | gConfig.playback = false; | ||
582 | gConfig.verbose = false; | ||
583 | } | ||
580 | 584 | ||
581 | rb->memset(&gThread, 0, sizeof(gThread)); | 585 | rb->memset(&gThread, 0, sizeof(gThread)); |
582 | if (gConfig.verbose) | 586 | if (gConfig.verbose) |
@@ -586,9 +590,11 @@ static int plugin_main(const void* parameter) | |||
586 | rb->plugin_tsr(exit_tsr); /* stay resident */ | 590 | rb->plugin_tsr(exit_tsr); /* stay resident */ |
587 | 591 | ||
588 | thread_create(); | 592 | thread_create(); |
593 | rb->memcpy(&gConfig, &cfg, sizeof(struct lastfm_config)); | ||
589 | 594 | ||
590 | if (gConfig.playback) | 595 | if (gConfig.playback) |
591 | return PLUGIN_GOTO_WPS; | 596 | return PLUGIN_GOTO_WPS; |
597 | |||
592 | return PLUGIN_OK; | 598 | return PLUGIN_OK; |
593 | } | 599 | } |
594 | 600 | ||
diff --git a/apps/plugins/test_usb.c b/apps/plugins/test_usb.c index 6bb77c40be..28ef8f7e5f 100644 --- a/apps/plugins/test_usb.c +++ b/apps/plugins/test_usb.c | |||
@@ -85,7 +85,7 @@ static void kill_tsr(void) | |||
85 | rb->queue_delete(&queue); | 85 | rb->queue_delete(&queue); |
86 | } | 86 | } |
87 | 87 | ||
88 | static bool exit_tsr(bool reenter) | 88 | static int exit_tsr(bool reenter) |
89 | { | 89 | { |
90 | MENUITEM_STRINGLIST(menu, "USB test menu", NULL, | 90 | MENUITEM_STRINGLIST(menu, "USB test menu", NULL, |
91 | "Status", "Stop plugin", "Back"); | 91 | "Status", "Stop plugin", "Back"); |
@@ -100,9 +100,9 @@ static bool exit_tsr(bool reenter) | |||
100 | case 1: | 100 | case 1: |
101 | rb->splashf(HZ, "Stopping USB test thread"); | 101 | rb->splashf(HZ, "Stopping USB test thread"); |
102 | kill_tsr(); | 102 | kill_tsr(); |
103 | return true; | 103 | return (reenter ? PLUGIN_TSR_TERMINATE : PLUGIN_TSR_SUSPEND); |
104 | case 2: | 104 | case 2: |
105 | return false; | 105 | return PLUGIN_TSR_CONTINUE; |
106 | } | 106 | } |
107 | } | 107 | } |
108 | } | 108 | } |
@@ -119,14 +119,15 @@ static void run_tsr(void) | |||
119 | 119 | ||
120 | enum plugin_status plugin_start(const void* parameter) | 120 | enum plugin_status plugin_start(const void* parameter) |
121 | { | 121 | { |
122 | (void)parameter; | 122 | bool resume = (parameter == rb->plugin_tsr); |
123 | |||
123 | MENUITEM_STRINGLIST(menu, "USB test menu", NULL, | 124 | MENUITEM_STRINGLIST(menu, "USB test menu", NULL, |
124 | "Start", "Quit"); | 125 | "Start", "Quit"); |
125 | 126 | ||
126 | switch(rb->do_menu(&menu, NULL, NULL, false)) { | 127 | switch(!resume ? rb->do_menu(&menu, NULL, NULL, false) : 0) { |
127 | case 0: | 128 | case 0: |
128 | run_tsr(); | 129 | run_tsr(); |
129 | rb->splashf(HZ, "Thread started"); | 130 | rb->splashf(HZ, "USB test thread started"); |
130 | return PLUGIN_OK; | 131 | return PLUGIN_OK; |
131 | case 1: | 132 | case 1: |
132 | return PLUGIN_OK; | 133 | return PLUGIN_OK; |