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/fractals | |
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/fractals')
-rw-r--r-- | apps/plugins/fractals/fractal.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/apps/plugins/fractals/fractal.c b/apps/plugins/fractals/fractal.c index 971ae506ca..179bc3e562 100644 --- a/apps/plugins/fractals/fractal.c +++ b/apps/plugins/fractals/fractal.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "fractal_rect.h" | 29 | #include "fractal_rect.h" |
30 | #include "fractal_sets.h" | 30 | #include "fractal_sets.h" |
31 | #include "mandelbrot_set.h" | 31 | #include "mandelbrot_set.h" |
32 | #include "lib/pluginlib_exit.h" | ||
32 | 33 | ||
33 | #ifdef USEGSLIB | 34 | #ifdef USEGSLIB |
34 | GREY_INFO_STRUCT | 35 | GREY_INFO_STRUCT |
@@ -41,7 +42,7 @@ static size_t gbuf_size = 0; | |||
41 | #define REDRAW_FULL 2 | 42 | #define REDRAW_FULL 2 |
42 | #define REDRAW_FULL_OVERLAY 3 | 43 | #define REDRAW_FULL_OVERLAY 3 |
43 | 44 | ||
44 | PLUGIN_HEADER | 45 | |
45 | 46 | ||
46 | /* returns 1 if a button has been pressed, 0 otherwise */ | 47 | /* returns 1 if a button has been pressed, 0 otherwise */ |
47 | static int button_yield(void *ctx) | 48 | static int button_yield(void *ctx) |
@@ -85,9 +86,8 @@ static int button_yield(void *ctx) | |||
85 | } | 86 | } |
86 | } | 87 | } |
87 | 88 | ||
88 | static void cleanup(void *parameter) | 89 | static void cleanup(void) |
89 | { | 90 | { |
90 | (void)parameter; | ||
91 | #ifdef USEGSLIB | 91 | #ifdef USEGSLIB |
92 | grey_release(); | 92 | grey_release(); |
93 | #endif | 93 | #endif |
@@ -109,11 +109,13 @@ enum plugin_status plugin_start(const void* parameter) | |||
109 | if (!grey_init(gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL)) | 109 | if (!grey_init(gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL)) |
110 | { | 110 | { |
111 | rb->splash(HZ, "Couldn't init greyscale display"); | 111 | rb->splash(HZ, "Couldn't init greyscale display"); |
112 | return 0; | 112 | return PLUGIN_ERROR; |
113 | } | 113 | } |
114 | grey_show(true); /* switch on greyscale overlay */ | 114 | grey_show(true); /* switch on greyscale overlay */ |
115 | #endif | 115 | #endif |
116 | 116 | ||
117 | /* release greylib on exit */ | ||
118 | atexit(cleanup); | ||
117 | #if LCD_DEPTH > 1 | 119 | #if LCD_DEPTH > 1 |
118 | rb->lcd_set_backdrop(NULL); | 120 | rb->lcd_set_backdrop(NULL); |
119 | #endif | 121 | #endif |
@@ -161,9 +163,6 @@ enum plugin_status plugin_start(const void* parameter) | |||
161 | case FRACTAL_RC_QUIT: | 163 | case FRACTAL_RC_QUIT: |
162 | #endif | 164 | #endif |
163 | case FRACTAL_QUIT: | 165 | case FRACTAL_QUIT: |
164 | #ifdef USEGSLIB | ||
165 | grey_release(); | ||
166 | #endif | ||
167 | return PLUGIN_OK; | 166 | return PLUGIN_OK; |
168 | 167 | ||
169 | case FRACTAL_ZOOM_OUT: | 168 | case FRACTAL_ZOOM_OUT: |
@@ -246,18 +245,13 @@ enum plugin_status plugin_start(const void* parameter) | |||
246 | break; | 245 | break; |
247 | 246 | ||
248 | default: | 247 | default: |
249 | if (rb->default_event_handler_ex(button, cleanup, NULL) | 248 | exit_on_usb(button); |
250 | == SYS_USB_CONNECTED) | ||
251 | return PLUGIN_USB_CONNECTED; | ||
252 | break; | 249 | break; |
253 | } | 250 | } |
254 | 251 | ||
255 | if (button != BUTTON_NONE) | 252 | if (button != BUTTON_NONE) |
256 | lastbutton = button; | 253 | lastbutton = button; |
257 | } | 254 | } |
258 | #ifdef USEGSLIB | ||
259 | grey_release(); | ||
260 | #endif | ||
261 | return PLUGIN_OK; | 255 | return PLUGIN_OK; |
262 | } | 256 | } |
263 | 257 | ||