forked from len0rd/rockbox
[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
This commit is contained in:
parent
2e99e2175b
commit
a2e5d9563f
6 changed files with 176 additions and 123 deletions
|
|
@ -97,6 +97,7 @@ enum plugin_status plugin_start(const void* parameter); /* entry */
|
|||
static struct
|
||||
{
|
||||
bool exiting; /* signal to the thread that we want to exit */
|
||||
bool resume;
|
||||
unsigned int id; /* worker thread id */
|
||||
struct event_queue queue; /* thread event queue */
|
||||
long stack[THREAD_STACK_SIZE / sizeof(long)];
|
||||
|
|
@ -393,7 +394,7 @@ static int settings_menu(void)
|
|||
break;
|
||||
case 4: /*sep*/
|
||||
continue;
|
||||
case 5:
|
||||
case 5: /* quit the plugin */
|
||||
return -1;
|
||||
break;
|
||||
case 6:
|
||||
|
|
@ -433,7 +434,8 @@ void thread(void)
|
|||
in_usb = false;
|
||||
/*fall through*/
|
||||
case EV_STARTUP:
|
||||
rb->beep_play(1500, 100, 1000);
|
||||
if (!gThread.resume)
|
||||
rb->beep_play(1500, 100, 1000);
|
||||
break;
|
||||
case EV_EXIT:
|
||||
return;
|
||||
|
|
@ -479,17 +481,45 @@ void thread_quit(void)
|
|||
}
|
||||
}
|
||||
|
||||
static bool check_user_input(void)
|
||||
{
|
||||
int i = 0;
|
||||
rb->button_clear_queue();
|
||||
if (rb->button_get_w_tmo(HZ) > BUTTON_NONE)
|
||||
{
|
||||
while ((rb->button_get(false) & BUTTON_REL) != BUTTON_REL)
|
||||
{
|
||||
if (i & 1)
|
||||
rb->beep_play(800, 100, 1000 - i * (1000 / 15));
|
||||
|
||||
if (++i > 15)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
rb->sleep(HZ / 5);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* callback to end the TSR plugin, called before a new one gets loaded */
|
||||
static bool exit_tsr(bool reenter)
|
||||
static int exit_tsr(bool reenter)
|
||||
{
|
||||
if (reenter)
|
||||
{
|
||||
rb->queue_post(&gThread.queue, EV_OTHINSTANCE, 0);
|
||||
return false; /* dont let it start again */
|
||||
|
||||
/* quit the plugin if user holds a button */
|
||||
if (check_user_input() == true)
|
||||
{
|
||||
if (settings_menu() < 0)
|
||||
return PLUGIN_TSR_TERMINATE; /*kill TSR dont let it start again */
|
||||
}
|
||||
return PLUGIN_TSR_CONTINUE; /* dont let new plugin start*/
|
||||
}
|
||||
thread_quit();
|
||||
|
||||
return true;
|
||||
return PLUGIN_TSR_SUSPEND;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -497,58 +527,35 @@ static bool exit_tsr(bool reenter)
|
|||
|
||||
int plugin_main(const void* parameter)
|
||||
{
|
||||
(void)parameter;
|
||||
bool settings = false;
|
||||
int i = 0;
|
||||
|
||||
rb->memset(&gThread, 0, sizeof(gThread));
|
||||
|
||||
gAnnounce.index = 0;
|
||||
gAnnounce.timeout = 0;
|
||||
|
||||
rb->splash(HZ / 2, "Announce Status");
|
||||
|
||||
if (configfile_load(CFG_FILE, config, gCfg_sz, CFG_VER) < 0)
|
||||
/* Resume plugin ? */
|
||||
if (parameter == rb->plugin_tsr)
|
||||
{
|
||||
/* If the loading failed, save a new config file */
|
||||
config_set_defaults();
|
||||
configfile_save(CFG_FILE, config, gCfg_sz, CFG_VER);
|
||||
|
||||
rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS));
|
||||
gThread.resume = true;
|
||||
}
|
||||
|
||||
if (gAnnounce.show_prompt)
|
||||
else
|
||||
{
|
||||
if (rb->mixer_channel_status(PCM_MIXER_CHAN_PLAYBACK) != CHANNEL_PLAYING)
|
||||
rb->splash(HZ / 2, "Announce Status");
|
||||
if (gAnnounce.show_prompt)
|
||||
{
|
||||
rb->talk_id(LANG_HOLD_FOR_SETTINGS, false);
|
||||
}
|
||||
rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS));
|
||||
}
|
||||
|
||||
rb->button_clear_queue();
|
||||
if (rb->button_get_w_tmo(HZ) > BUTTON_NONE)
|
||||
{
|
||||
while ((rb->button_get(false) & BUTTON_REL) != BUTTON_REL)
|
||||
{
|
||||
if (i & 1)
|
||||
rb->beep_play(800, 100, 1000);
|
||||
|
||||
if (++i > 15)
|
||||
if (rb->mixer_channel_status(PCM_MIXER_CHAN_PLAYBACK) != CHANNEL_PLAYING)
|
||||
{
|
||||
settings = true;
|
||||
break;
|
||||
rb->talk_id(LANG_HOLD_FOR_SETTINGS, false);
|
||||
}
|
||||
rb->sleep(HZ / 5);
|
||||
rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS));
|
||||
}
|
||||
}
|
||||
|
||||
if (settings)
|
||||
{
|
||||
rb->splash(100, ID2P(LANG_SETTINGS));
|
||||
int ret = settings_menu();
|
||||
if (ret < 0)
|
||||
return 0;
|
||||
|
||||
if (check_user_input() == true)
|
||||
{
|
||||
rb->splash(100, ID2P(LANG_SETTINGS));
|
||||
int ret = settings_menu();
|
||||
if (ret < 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
gAnnounce.timeout = *rb->current_tick;
|
||||
|
|
@ -571,6 +578,16 @@ enum plugin_status plugin_start(const void* parameter)
|
|||
/* now go ahead and have fun! */
|
||||
if (rb->usb_inserted() == true)
|
||||
return PLUGIN_USB_CONNECTED;
|
||||
|
||||
config_set_defaults();
|
||||
if (configfile_load(CFG_FILE, config, gCfg_sz, CFG_VER) < 0)
|
||||
{
|
||||
/* If the loading failed, save a new config file */
|
||||
config_set_defaults();
|
||||
configfile_save(CFG_FILE, config, gCfg_sz, CFG_VER);
|
||||
rb->splash(HZ, ID2P(LANG_HOLD_FOR_SETTINGS));
|
||||
}
|
||||
|
||||
int ret = plugin_main(parameter);
|
||||
return (ret==0) ? PLUGIN_OK : PLUGIN_ERROR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -289,11 +289,11 @@ static struct event_queue thread_q SHAREDBSS_ATTR;
|
|||
static bool in_usb_mode;
|
||||
static unsigned int buf_idx;
|
||||
|
||||
static bool exit_tsr(bool reenter)
|
||||
static int exit_tsr(bool reenter)
|
||||
{
|
||||
bool is_exit;
|
||||
int exit_status;
|
||||
long button;
|
||||
(void)reenter;
|
||||
|
||||
rb->lcd_clear_display();
|
||||
rb->lcd_puts_scroll(0, 0, "Batt.Bench is currently running.");
|
||||
rb->lcd_puts_scroll(0, 1, "Press " BATTERY_OFF_TXT " to cancel the test");
|
||||
|
|
@ -313,16 +313,17 @@ static bool exit_tsr(bool reenter)
|
|||
rb->thread_wait(gThread.id);
|
||||
/* remove the thread's queue from the broadcast list */
|
||||
rb->queue_delete(&thread_q);
|
||||
is_exit = true;
|
||||
exit_status = (reenter ? PLUGIN_TSR_TERMINATE : PLUGIN_TSR_SUSPEND);
|
||||
|
||||
}
|
||||
else is_exit = false;
|
||||
else exit_status = PLUGIN_TSR_CONTINUE;
|
||||
|
||||
break;
|
||||
}
|
||||
FOR_NB_SCREENS(idx)
|
||||
rb->screens[idx]->scroll_stop();
|
||||
|
||||
return is_exit;
|
||||
return exit_status;
|
||||
}
|
||||
|
||||
#define BIT_CHARGER 0x1
|
||||
|
|
@ -502,14 +503,19 @@ static void put_centered_str(const char* str, plcdfunc putsxy, int lcd_width, in
|
|||
|
||||
enum plugin_status plugin_start(const void* parameter)
|
||||
{
|
||||
(void)parameter;
|
||||
int button, fd;
|
||||
bool resume = false;
|
||||
bool on = false;
|
||||
start_tick = *rb->current_tick;
|
||||
int i;
|
||||
const char *msgs[] = { "Battery Benchmark","Check file", BATTERY_LOG,
|
||||
"for more info", BATTERY_ON_TXT, BATTERY_OFF_TXT " - quit" };
|
||||
rb->lcd_clear_display();
|
||||
|
||||
if (parameter == rb->plugin_tsr)
|
||||
{
|
||||
resume = true;
|
||||
on = true;
|
||||
}
|
||||
|
||||
rb->lcd_clear_display();
|
||||
rb->lcd_setfont(FONT_SYSFIXED);
|
||||
|
|
@ -529,36 +535,38 @@ enum plugin_status plugin_start(const void* parameter)
|
|||
rb->lcd_remote_putsxy,LCD_REMOTE_WIDTH,2);
|
||||
rb->lcd_remote_update();
|
||||
#endif
|
||||
|
||||
do
|
||||
if (!resume)
|
||||
{
|
||||
button = rb->button_get(true);
|
||||
switch (button)
|
||||
do
|
||||
{
|
||||
case BATTERY_ON:
|
||||
#ifdef BATTERY_RC_ON
|
||||
case BATTERY_RC_ON:
|
||||
#endif
|
||||
on = true;
|
||||
break;
|
||||
case BATTERY_OFF:
|
||||
#ifdef BATTERY_RC_OFF
|
||||
case BATTERY_RC_OFF:
|
||||
#endif
|
||||
return PLUGIN_OK;
|
||||
|
||||
default:
|
||||
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
||||
return PLUGIN_USB_CONNECTED;
|
||||
}
|
||||
}while(!on);
|
||||
button = rb->button_get(true);
|
||||
switch (button)
|
||||
{
|
||||
case BATTERY_ON:
|
||||
#ifdef BATTERY_RC_ON
|
||||
case BATTERY_RC_ON:
|
||||
#endif
|
||||
on = true;
|
||||
break;
|
||||
case BATTERY_OFF:
|
||||
#ifdef BATTERY_RC_OFF
|
||||
case BATTERY_RC_OFF:
|
||||
#endif
|
||||
return PLUGIN_OK;
|
||||
|
||||
default:
|
||||
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
||||
return PLUGIN_USB_CONNECTED;
|
||||
}
|
||||
}while(!on);
|
||||
}
|
||||
fd = rb->open(BATTERY_LOG, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT, 0666);
|
||||
if (fd >= 0)
|
||||
{
|
||||
|
||||
rb->fdprintf(fd,
|
||||
"# This plugin will log your battery performance in a\n"
|
||||
"# file (%s) every minute.\n"
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ static struct
|
|||
bool force_flush;
|
||||
} gCache;
|
||||
|
||||
static struct
|
||||
static struct lastfm_config
|
||||
{
|
||||
int savepct;
|
||||
int beeplvl;
|
||||
|
|
@ -528,7 +528,7 @@ void thread_quit(void)
|
|||
}
|
||||
|
||||
/* callback to end the TSR plugin, called before a new one gets loaded */
|
||||
static bool exit_tsr(bool reenter)
|
||||
static int exit_tsr(bool reenter)
|
||||
{
|
||||
MENUITEM_STRINGLIST(menu, ID2P(LANG_AUDIOSCROBBLER), NULL, ID2P(LANG_SETTINGS),
|
||||
"Flush Cache", "Exit Plugin", ID2P(LANG_BACK));
|
||||
|
|
@ -556,19 +556,13 @@ static bool exit_tsr(bool reenter)
|
|||
case 2: /* exit plugin - quit */
|
||||
if(rb->gui_syncyesno_run(&quit_prompt, NULL, NULL) == YESNO_YES)
|
||||
{
|
||||
scrobbler_flush_cache();
|
||||
thread_quit();
|
||||
if (reenter)
|
||||
rb->plugin_tsr(NULL); /* remove TSR cb */
|
||||
return !reenter;
|
||||
return (reenter ? PLUGIN_TSR_TERMINATE : PLUGIN_TSR_SUSPEND);
|
||||
}
|
||||
|
||||
if(!reenter)
|
||||
return false;
|
||||
|
||||
break;
|
||||
|
||||
/* Fall Through */
|
||||
case 3: /* back to menu */
|
||||
return false;
|
||||
return PLUGIN_TSR_CONTINUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -576,7 +570,17 @@ static bool exit_tsr(bool reenter)
|
|||
/****************** main ******************/
|
||||
static int plugin_main(const void* parameter)
|
||||
{
|
||||
(void)parameter;
|
||||
struct lastfm_config cfg;
|
||||
rb->memcpy(&cfg, & gConfig, sizeof(struct lastfm_config));
|
||||
|
||||
/* Resume plugin ? */
|
||||
if (parameter == rb->plugin_tsr)
|
||||
{
|
||||
|
||||
gConfig.beeplvl = 0;
|
||||
gConfig.playback = false;
|
||||
gConfig.verbose = false;
|
||||
}
|
||||
|
||||
rb->memset(&gThread, 0, sizeof(gThread));
|
||||
if (gConfig.verbose)
|
||||
|
|
@ -586,9 +590,11 @@ static int plugin_main(const void* parameter)
|
|||
rb->plugin_tsr(exit_tsr); /* stay resident */
|
||||
|
||||
thread_create();
|
||||
rb->memcpy(&gConfig, &cfg, sizeof(struct lastfm_config));
|
||||
|
||||
if (gConfig.playback)
|
||||
return PLUGIN_GOTO_WPS;
|
||||
|
||||
return PLUGIN_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ static void kill_tsr(void)
|
|||
rb->queue_delete(&queue);
|
||||
}
|
||||
|
||||
static bool exit_tsr(bool reenter)
|
||||
static int exit_tsr(bool reenter)
|
||||
{
|
||||
MENUITEM_STRINGLIST(menu, "USB test menu", NULL,
|
||||
"Status", "Stop plugin", "Back");
|
||||
|
|
@ -100,9 +100,9 @@ static bool exit_tsr(bool reenter)
|
|||
case 1:
|
||||
rb->splashf(HZ, "Stopping USB test thread");
|
||||
kill_tsr();
|
||||
return true;
|
||||
return (reenter ? PLUGIN_TSR_TERMINATE : PLUGIN_TSR_SUSPEND);
|
||||
case 2:
|
||||
return false;
|
||||
return PLUGIN_TSR_CONTINUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -119,14 +119,15 @@ static void run_tsr(void)
|
|||
|
||||
enum plugin_status plugin_start(const void* parameter)
|
||||
{
|
||||
(void)parameter;
|
||||
bool resume = (parameter == rb->plugin_tsr);
|
||||
|
||||
MENUITEM_STRINGLIST(menu, "USB test menu", NULL,
|
||||
"Start", "Quit");
|
||||
|
||||
switch(rb->do_menu(&menu, NULL, NULL, false)) {
|
||||
switch(!resume ? rb->do_menu(&menu, NULL, NULL, false) : 0) {
|
||||
case 0:
|
||||
run_tsr();
|
||||
rb->splashf(HZ, "Thread started");
|
||||
rb->splashf(HZ, "USB test thread started");
|
||||
return PLUGIN_OK;
|
||||
case 1:
|
||||
return PLUGIN_OK;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue