diff options
author | Thomas Martitz <kugel@rockbox.org> | 2010-08-23 16:56:49 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2010-08-23 16:56:49 +0000 |
commit | abdc5935beb7dc3fa63bffeec584921ad2a4c8bd (patch) | |
tree | 3eb3ca86063d0fff58ca8ed2c49dbb0af0792570 /apps/plugins/metronome.c | |
parent | 8106c9dc646bbb26131896eb12d23edb26cba476 (diff) | |
download | rockbox-abdc5935beb7dc3fa63bffeec584921ad2a4c8bd.tar.gz rockbox-abdc5935beb7dc3fa63bffeec584921ad2a4c8bd.zip |
Introduce plugin_crt0.c that every plugin links.
It handles exit() properly, calling the handler also when the plugin returns
normally (also it makes exit() more standard compliant while at it).
It also holds PLUGIN_HEADER, so that it doesn't need to be in each plugin anymore.
To work better together with callbacks passed to rb->default_event_handler_ex introduce exit_on_usb() which will call the exit handler before showing the usb screen and exit() after it.
In most cases it was passed a callback which was manually called at all other return points. This can now be done via atexit().
In future plugin_crt0.c could also handle clearing bss, initializing iram and more.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27862 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/metronome.c')
-rw-r--r-- | apps/plugins/metronome.c | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/apps/plugins/metronome.c b/apps/plugins/metronome.c index 37a7329b22..b38f0bbf2c 100644 --- a/apps/plugins/metronome.c +++ b/apps/plugins/metronome.c | |||
@@ -20,8 +20,9 @@ | |||
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #include "plugin.h" | 21 | #include "plugin.h" |
22 | #include "lib/pluginlib_actions.h" | 22 | #include "lib/pluginlib_actions.h" |
23 | #include "lib/pluginlib_exit.h" | ||
24 | |||
23 | 25 | ||
24 | PLUGIN_HEADER | ||
25 | 26 | ||
26 | #if CONFIG_CODEC != SWCODEC | 27 | #if CONFIG_CODEC != SWCODEC |
27 | /* tick sound from a metronome */ | 28 | /* tick sound from a metronome */ |
@@ -846,13 +847,14 @@ void timer_callback(void) | |||
846 | } | 847 | } |
847 | } | 848 | } |
848 | 849 | ||
849 | void cleanup(void *parameter) | 850 | void cleanup(void) |
850 | { | 851 | { |
851 | (void)parameter; | ||
852 | |||
853 | rb->timer_unregister(); | 852 | rb->timer_unregister(); |
854 | MET_PLAY_STOP; /* stop audio ISR */ | 853 | MET_PLAY_STOP; /* stop audio ISR */ |
855 | rb->led(0); | 854 | rb->led(0); |
855 | #if CONFIG_CODEC == SWCODEC | ||
856 | rb->pcm_set_frequency(HW_SAMPR_DEFAULT); | ||
857 | #endif | ||
856 | } | 858 | } |
857 | 859 | ||
858 | void tap(void) | 860 | void tap(void) |
@@ -885,9 +887,9 @@ enum plugin_status plugin_start(const void* parameter) | |||
885 | { | 887 | { |
886 | int button; | 888 | int button; |
887 | static int last_button = BUTTON_NONE; | 889 | static int last_button = BUTTON_NONE; |
888 | enum plugin_status status; | ||
889 | 890 | ||
890 | (void)parameter; | 891 | (void)parameter; |
892 | atexit(cleanup); | ||
891 | 893 | ||
892 | if (MET_IS_PLAYING) | 894 | if (MET_IS_PLAYING) |
893 | MET_PLAY_STOP; /* stop audio IS */ | 895 | MET_PLAY_STOP; /* stop audio IS */ |
@@ -927,9 +929,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
927 | 929 | ||
928 | case METRONOME_QUIT: | 930 | case METRONOME_QUIT: |
929 | /* get out of here */ | 931 | /* get out of here */ |
930 | cleanup(NULL); | 932 | return PLUGIN_OK; |
931 | status = PLUGIN_OK; | ||
932 | goto metronome_exit; | ||
933 | 933 | ||
934 | case METRONOME_PAUSE: | 934 | case METRONOME_PAUSE: |
935 | if(!sound_paused) | 935 | if(!sound_paused) |
@@ -981,12 +981,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
981 | #endif | 981 | #endif |
982 | 982 | ||
983 | default: | 983 | default: |
984 | if (rb->default_event_handler_ex(button, cleanup, NULL) | 984 | exit_on_usb(button); |
985 | == SYS_USB_CONNECTED) | ||
986 | { | ||
987 | status = PLUGIN_USB_CONNECTED; | ||
988 | goto metronome_exit; | ||
989 | } | ||
990 | reset_tap = false; | 985 | reset_tap = false; |
991 | break; | 986 | break; |
992 | 987 | ||
@@ -998,11 +993,5 @@ enum plugin_status plugin_start(const void* parameter) | |||
998 | } | 993 | } |
999 | rb->yield(); | 994 | rb->yield(); |
1000 | } | 995 | } |
1001 | |||
1002 | metronome_exit: | ||
1003 | #if CONFIG_CODEC == SWCODEC | ||
1004 | rb->pcm_set_frequency(HW_SAMPR_DEFAULT); | ||
1005 | #endif | ||
1006 | return status; | ||
1007 | } | 996 | } |
1008 | 997 | ||