diff options
author | Thomas Martitz <kugel@rockbox.org> | 2010-08-24 14:30:46 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2010-08-24 14:30:46 +0000 |
commit | cae4ae2c71ae10ff67d39a78a705136e740dc07e (patch) | |
tree | b5bb5e1879493f67d7c7ad977fba90eb49b743d7 /apps/plugins/fractals | |
parent | 3478bc5d6dc0a081c3aeb4f501c8b4cb4f53a78d (diff) | |
download | rockbox-cae4ae2c71ae10ff67d39a78a705136e740dc07e.tar.gz rockbox-cae4ae2c71ae10ff67d39a78a705136e740dc07e.zip |
Second try: Introduce plugin_crt0.c that every plugin links.
It handles exit() properly, calling the handler also when the plugin returns
normally (also make 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 rb->default_event_handler_ex() 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@27873 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 | ||