diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugin.c | 31 | ||||
-rw-r--r-- | apps/plugin.h | 25 | ||||
-rw-r--r-- | apps/plugins/alpine_cdc.c | 5 | ||||
-rw-r--r-- | apps/plugins/battery_bench.c | 28 |
4 files changed, 61 insertions, 28 deletions
diff --git a/apps/plugin.c b/apps/plugin.c index bc8419d313..518fdeff44 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -88,7 +88,8 @@ extern unsigned char pluginbuf[]; | |||
88 | /* for actual plugins only, not for codecs */ | 88 | /* for actual plugins only, not for codecs */ |
89 | static bool plugin_loaded = false; | 89 | static bool plugin_loaded = false; |
90 | static int plugin_size = 0; | 90 | static int plugin_size = 0; |
91 | static void (*pfn_tsr_exit)(void) = NULL; /* TSR exit callback */ | 91 | static bool (*pfn_tsr_exit)(bool) = NULL; /* TSR exit callback */ |
92 | static char current_plugin[MAX_PATH]; | ||
92 | 93 | ||
93 | static const struct plugin_api rockbox_api = { | 94 | static const struct plugin_api rockbox_api = { |
94 | 95 | ||
@@ -248,6 +249,7 @@ static const struct plugin_api rockbox_api = { | |||
248 | ata_sleep, | 249 | ata_sleep, |
249 | ata_disk_is_active, | 250 | ata_disk_is_active, |
250 | #endif | 251 | #endif |
252 | ata_spindown, | ||
251 | reload_directory, | 253 | reload_directory, |
252 | 254 | ||
253 | /* dir */ | 255 | /* dir */ |
@@ -317,6 +319,7 @@ static const struct plugin_api rockbox_api = { | |||
317 | memchr, | 319 | memchr, |
318 | memcmp, | 320 | memcmp, |
319 | strcasestr, | 321 | strcasestr, |
322 | strtok_r, | ||
320 | /* unicode stuff */ | 323 | /* unicode stuff */ |
321 | utf8decode, | 324 | utf8decode, |
322 | iso_decode, | 325 | iso_decode, |
@@ -464,21 +467,21 @@ static const struct plugin_api rockbox_api = { | |||
464 | show_logo, | 467 | show_logo, |
465 | tree_get_context, | 468 | tree_get_context, |
466 | 469 | ||
467 | /* new stuff at the end, sort into place next time | ||
468 | the API gets incompatible */ | ||
469 | |||
470 | strtok_r, | ||
471 | #ifdef HAVE_WHEEL_POSITION | 470 | #ifdef HAVE_WHEEL_POSITION |
472 | wheel_status, | 471 | wheel_status, |
473 | wheel_send_events, | 472 | wheel_send_events, |
474 | #endif | 473 | #endif |
475 | ata_spindown, | 474 | |
475 | /* new stuff at the end, sort into place next time | ||
476 | the API gets incompatible */ | ||
477 | |||
476 | }; | 478 | }; |
477 | 479 | ||
478 | int plugin_load(const char* plugin, void* parameter) | 480 | int plugin_load(const char* plugin, void* parameter) |
479 | { | 481 | { |
480 | int rc; | 482 | int rc; |
481 | struct plugin_header *hdr; | 483 | struct plugin_header *hdr; |
484 | const char *p = strrchr(plugin,'/'); | ||
482 | #ifdef SIMULATOR | 485 | #ifdef SIMULATOR |
483 | void *pd; | 486 | void *pd; |
484 | #else | 487 | #else |
@@ -495,14 +498,23 @@ int plugin_load(const char* plugin, void* parameter) | |||
495 | fb_data* old_backdrop; | 498 | fb_data* old_backdrop; |
496 | #endif | 499 | #endif |
497 | 500 | ||
501 | if (!p) | ||
502 | p = plugin; | ||
503 | action_signalscreenchange(); | ||
504 | |||
498 | if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */ | 505 | if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */ |
499 | { | 506 | { |
500 | pfn_tsr_exit(); /* force it to exit now */ | 507 | if (pfn_tsr_exit(!strcmp(current_plugin,p)) == false ) |
508 | { | ||
509 | /* not allowing another plugin to load */ | ||
510 | return PLUGIN_OK; | ||
511 | } | ||
501 | pfn_tsr_exit = NULL; | 512 | pfn_tsr_exit = NULL; |
502 | plugin_loaded = false; | 513 | plugin_loaded = false; |
503 | } | 514 | } |
504 | 515 | ||
505 | gui_syncsplash(0, true, str(LANG_WAIT)); | 516 | gui_syncsplash(0, true, str(LANG_WAIT)); |
517 | strcpy(current_plugin,p); | ||
506 | 518 | ||
507 | #ifdef SIMULATOR | 519 | #ifdef SIMULATOR |
508 | hdr = sim_plugin_load((char *)plugin, &pd); | 520 | hdr = sim_plugin_load((char *)plugin, &pd); |
@@ -635,7 +647,6 @@ int plugin_load(const char* plugin, void* parameter) | |||
635 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_ERROR)); | 647 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_ERROR)); |
636 | break; | 648 | break; |
637 | } | 649 | } |
638 | action_signalscreenchange(); | ||
639 | return PLUGIN_OK; | 650 | return PLUGIN_OK; |
640 | } | 651 | } |
641 | 652 | ||
@@ -675,7 +686,7 @@ void* plugin_get_audio_buffer(int* buffer_size) | |||
675 | /* The plugin wants to stay resident after leaving its main function, e.g. | 686 | /* The plugin wants to stay resident after leaving its main function, e.g. |
676 | runs from timer or own thread. The callback is registered to later | 687 | runs from timer or own thread. The callback is registered to later |
677 | instruct it to free its resources before a new plugin gets loaded. */ | 688 | instruct it to free its resources before a new plugin gets loaded. */ |
678 | void plugin_tsr(void (*exit_callback)(void)) | 689 | void plugin_tsr(bool (*exit_callback)(bool)) |
679 | { | 690 | { |
680 | pfn_tsr_exit = exit_callback; /* remember the callback for later */ | 691 | pfn_tsr_exit = exit_callback; /* remember the callback for later */ |
681 | } | 692 | } |
diff --git a/apps/plugin.h b/apps/plugin.h index 609f4cc65b..a7ed88985d 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -105,12 +105,12 @@ | |||
105 | #define PLUGIN_MAGIC 0x526F634B /* RocK */ | 105 | #define PLUGIN_MAGIC 0x526F634B /* RocK */ |
106 | 106 | ||
107 | /* increase this every time the api struct changes */ | 107 | /* increase this every time the api struct changes */ |
108 | #define PLUGIN_API_VERSION 33 | 108 | #define PLUGIN_API_VERSION 34 |
109 | 109 | ||
110 | /* update this to latest version if a change to the api struct breaks | 110 | /* update this to latest version if a change to the api struct breaks |
111 | backwards compatibility (and please take the opportunity to sort in any | 111 | backwards compatibility (and please take the opportunity to sort in any |
112 | new function which are "waiting" at the end of the function table) */ | 112 | new function which are "waiting" at the end of the function table) */ |
113 | #define PLUGIN_MIN_API_VERSION 30 | 113 | #define PLUGIN_MIN_API_VERSION 34 |
114 | 114 | ||
115 | /* plugin return codes */ | 115 | /* plugin return codes */ |
116 | enum plugin_status { | 116 | enum plugin_status { |
@@ -304,6 +304,7 @@ struct plugin_api { | |||
304 | void (*ata_sleep)(void); | 304 | void (*ata_sleep)(void); |
305 | bool (*ata_disk_is_active)(void); | 305 | bool (*ata_disk_is_active)(void); |
306 | #endif | 306 | #endif |
307 | void (*ata_spindown)(int seconds); | ||
307 | void (*reload_directory)(void); | 308 | void (*reload_directory)(void); |
308 | 309 | ||
309 | /* dir */ | 310 | /* dir */ |
@@ -378,6 +379,7 @@ struct plugin_api { | |||
378 | void *(*memchr)(const void *s1, int c, size_t n); | 379 | void *(*memchr)(const void *s1, int c, size_t n); |
379 | int (*memcmp)(const void *s1, const void *s2, size_t n); | 380 | int (*memcmp)(const void *s1, const void *s2, size_t n); |
380 | char *(*strcasestr) (const char* phaystack, const char* pneedle); | 381 | char *(*strcasestr) (const char* phaystack, const char* pneedle); |
382 | char* (*strtok_r)(char *ptr, const char *sep, char **end); | ||
381 | /* unicode stuff */ | 383 | /* unicode stuff */ |
382 | const unsigned char* (*utf8decode)(const unsigned char *utf8, unsigned short *ucs); | 384 | const unsigned char* (*utf8decode)(const unsigned char *utf8, unsigned short *ucs); |
383 | unsigned char* (*iso_decode)(const unsigned char *iso, unsigned char *utf8, int cp, int count); | 385 | unsigned char* (*iso_decode)(const unsigned char *iso, unsigned char *utf8, int cp, int count); |
@@ -511,7 +513,7 @@ struct plugin_api { | |||
511 | int (*set_time)(const struct tm *tm); | 513 | int (*set_time)(const struct tm *tm); |
512 | void* (*plugin_get_buffer)(int* buffer_size); | 514 | void* (*plugin_get_buffer)(int* buffer_size); |
513 | void* (*plugin_get_audio_buffer)(int* buffer_size); | 515 | void* (*plugin_get_audio_buffer)(int* buffer_size); |
514 | void (*plugin_tsr)(void (*exit_callback)(void)); | 516 | void (*plugin_tsr)(bool (*exit_callback)(bool reenter)); |
515 | #if defined(DEBUG) || defined(SIMULATOR) | 517 | #if defined(DEBUG) || defined(SIMULATOR) |
516 | void (*debugf)(const char *fmt, ...); | 518 | void (*debugf)(const char *fmt, ...); |
517 | #endif | 519 | #endif |
@@ -543,16 +545,15 @@ struct plugin_api { | |||
543 | int (*show_logo)(void); | 545 | int (*show_logo)(void); |
544 | struct tree_context* (*tree_get_context)(void); | 546 | struct tree_context* (*tree_get_context)(void); |
545 | 547 | ||
546 | /* new stuff at the end, sort into place next time | ||
547 | the API gets incompatible */ | ||
548 | |||
549 | char* (*strtok_r)(char *ptr, const char *sep, char **end); | ||
550 | |||
551 | #ifdef HAVE_WHEEL_POSITION | 548 | #ifdef HAVE_WHEEL_POSITION |
552 | int (*wheel_status)(void); | 549 | int (*wheel_status)(void); |
553 | void (*wheel_send_events)(bool send); | 550 | void (*wheel_send_events)(bool send); |
554 | #endif | 551 | #endif |
555 | void (*ata_spindown)(int seconds); | 552 | |
553 | /* new stuff at the end, sort into place next time | ||
554 | the API gets incompatible */ | ||
555 | |||
556 | |||
556 | }; | 557 | }; |
557 | 558 | ||
558 | /* plugin header */ | 559 | /* plugin header */ |
@@ -584,7 +585,11 @@ extern unsigned char plugin_end_addr[]; | |||
584 | int plugin_load(const char* plugin, void* parameter); | 585 | int plugin_load(const char* plugin, void* parameter); |
585 | void* plugin_get_buffer(int *buffer_size); | 586 | void* plugin_get_buffer(int *buffer_size); |
586 | void* plugin_get_audio_buffer(int *buffer_size); | 587 | void* plugin_get_audio_buffer(int *buffer_size); |
587 | void plugin_tsr(void (*exit_callback)(void)); | 588 | |
589 | /* plugin_tsr, | ||
590 | callback returns true to allow the new plugin to load, | ||
591 | reenter means the currently running plugin is being reloaded */ | ||
592 | void plugin_tsr(bool (*exit_callback)(bool reenter)); | ||
588 | 593 | ||
589 | /* defined by the plugin */ | 594 | /* defined by the plugin */ |
590 | enum plugin_status plugin_start(struct plugin_api* rockbox, void* parameter) | 595 | enum plugin_status plugin_start(struct plugin_api* rockbox, void* parameter) |
diff --git a/apps/plugins/alpine_cdc.c b/apps/plugins/alpine_cdc.c index 134bb3dee6..65108680c6 100644 --- a/apps/plugins/alpine_cdc.c +++ b/apps/plugins/alpine_cdc.c | |||
@@ -1122,8 +1122,10 @@ void thread(void) | |||
1122 | } | 1122 | } |
1123 | 1123 | ||
1124 | /* callback to end the TSR plugin, called before a new one gets loaded */ | 1124 | /* callback to end the TSR plugin, called before a new one gets loaded */ |
1125 | void exit_tsr(void) | 1125 | bool exit_tsr(bool reenter) |
1126 | { | 1126 | { |
1127 | if (reenter) | ||
1128 | return false; /* dont let it start again */ | ||
1127 | gTread.exiting = true; /* tell the thread to end */ | 1129 | gTread.exiting = true; /* tell the thread to end */ |
1128 | while (!gTread.ended) /* wait until it did */ | 1130 | while (!gTread.ended) /* wait until it did */ |
1129 | rb->yield(); | 1131 | rb->yield(); |
@@ -1133,6 +1135,7 @@ void exit_tsr(void) | |||
1133 | timer_set_mode(TM_OFF); /* timer interrupt off */ | 1135 | timer_set_mode(TM_OFF); /* timer interrupt off */ |
1134 | 1136 | ||
1135 | sound_normal(); /* restore sound settings */ | 1137 | sound_normal(); /* restore sound settings */ |
1138 | return true; | ||
1136 | } | 1139 | } |
1137 | 1140 | ||
1138 | /****************** main ******************/ | 1141 | /****************** main ******************/ |
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c index 75d5cbcabd..85d35b003e 100644 --- a/apps/plugins/battery_bench.c +++ b/apps/plugins/battery_bench.c | |||
@@ -92,7 +92,7 @@ PLUGIN_HEADER | |||
92 | /****************************** Plugin Entry Point ****************************/ | 92 | /****************************** Plugin Entry Point ****************************/ |
93 | static struct plugin_api* rb; | 93 | static struct plugin_api* rb; |
94 | int main(void); | 94 | int main(void); |
95 | void exit_tsr(void); | 95 | bool exit_tsr(bool); |
96 | void thread(void); | 96 | void thread(void); |
97 | 97 | ||
98 | 98 | ||
@@ -119,13 +119,27 @@ struct batt_info | |||
119 | 119 | ||
120 | struct event_queue thread_q; | 120 | struct event_queue thread_q; |
121 | 121 | ||
122 | void exit_tsr(void) | 122 | bool exit_tsr(bool reenter) |
123 | { | 123 | { |
124 | rb->queue_post(&thread_q, EV_EXIT, NULL); | 124 | bool exit = true; |
125 | while (!s_thread.ended) | 125 | (void)reenter; |
126 | rb->yield(); | 126 | rb->lcd_clear_display(); |
127 | /* remove the thread's queue from the broadcast list */ | 127 | rb->lcd_puts_scroll(0, 0, "Batt.Bench is currently running."); |
128 | rb->queue_delete(&thread_q); | 128 | rb->lcd_puts_scroll(0, 1, "Press OFF to cancel the test"); |
129 | rb->lcd_puts_scroll(0, 2, "Anything else will resume"); | ||
130 | rb->lcd_update(); | ||
131 | if (rb->button_get(true) != BATTERY_OFF) | ||
132 | exit = false; | ||
133 | if (exit) | ||
134 | { | ||
135 | rb->queue_post(&thread_q, EV_EXIT, NULL); | ||
136 | while (!s_thread.ended) | ||
137 | rb->yield(); | ||
138 | /* remove the thread's queue from the broadcast list */ | ||
139 | rb->queue_delete(&thread_q); | ||
140 | return true; | ||
141 | } | ||
142 | else return false; | ||
129 | } | 143 | } |
130 | 144 | ||
131 | #define BIT_CHARGER 0x1000 | 145 | #define BIT_CHARGER 0x1000 |