summaryrefslogtreecommitdiff
path: root/apps/plugins/pictureflow
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-08-23 16:56:49 +0000
committerThomas Martitz <kugel@rockbox.org>2010-08-23 16:56:49 +0000
commitabdc5935beb7dc3fa63bffeec584921ad2a4c8bd (patch)
tree3eb3ca86063d0fff58ca8ed2c49dbb0af0792570 /apps/plugins/pictureflow
parent8106c9dc646bbb26131896eb12d23edb26cba476 (diff)
downloadrockbox-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/pictureflow')
-rw-r--r--apps/plugins/pictureflow/pictureflow.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c
index 546afad217..8ad62b0238 100644
--- a/apps/plugins/pictureflow/pictureflow.c
+++ b/apps/plugins/pictureflow/pictureflow.c
@@ -27,6 +27,7 @@
27#include <albumart.h> 27#include <albumart.h>
28#include "lib/read_image.h" 28#include "lib/read_image.h"
29#include "lib/pluginlib_actions.h" 29#include "lib/pluginlib_actions.h"
30#include "lib/pluginlib_exit.h"
30#include "lib/helper.h" 31#include "lib/helper.h"
31#include "lib/configfile.h" 32#include "lib/configfile.h"
32#include "lib/grey.h" 33#include "lib/grey.h"
@@ -34,7 +35,7 @@
34#include "lib/feature_wrappers.h" 35#include "lib/feature_wrappers.h"
35#include "lib/buflib.h" 36#include "lib/buflib.h"
36 37
37PLUGIN_HEADER 38
38 39
39/******************************* Globals ***********************************/ 40/******************************* Globals ***********************************/
40 41
@@ -2068,9 +2069,8 @@ void update_scroll_animation(void)
2068/** 2069/**
2069 Cleanup the plugin 2070 Cleanup the plugin
2070*/ 2071*/
2071void cleanup(void *parameter) 2072void cleanup(void)
2072{ 2073{
2073 (void) parameter;
2074 int i; 2074 int i;
2075#ifdef HAVE_ADJUSTABLE_CPU_FREQ 2075#ifdef HAVE_ADJUSTABLE_CPU_FREQ
2076 rb->cpu_boost(false); 2076 rb->cpu_boost(false);
@@ -2610,19 +2610,6 @@ int main(void)
2610 cache_version = CACHE_VERSION; 2610 cache_version = CACHE_VERSION;
2611 configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS, CONFIG_VERSION); 2611 configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS, CONFIG_VERSION);
2612 2612
2613
2614#ifdef USEGSLIB
2615 long grey_buf_used;
2616 if (!grey_init(buf, buf_size, GREY_BUFFERED|GREY_ON_COP,
2617 LCD_WIDTH, LCD_HEIGHT, &grey_buf_used))
2618 {
2619 error_wait("Greylib init failed!");
2620 return PLUGIN_ERROR;
2621 }
2622 grey_setfont(FONT_UI);
2623 buf_size -= grey_buf_used;
2624 buf = (void*)(grey_buf_used + (char*)buf);
2625#endif
2626 buflib_init(&buf_ctx, (void *)buf, buf_size); 2613 buflib_init(&buf_ctx, (void *)buf, buf_size);
2627 2614
2628 if (!(empty_slide_hid = read_pfraw(EMPTY_SLIDE, 0))) 2615 if (!(empty_slide_hid = read_pfraw(EMPTY_SLIDE, 0)))
@@ -2841,9 +2828,7 @@ int main(void)
2841 } 2828 }
2842 break; 2829 break;
2843 default: 2830 default:
2844 if (rb->default_event_handler_ex(button, cleanup, NULL) 2831 exit_on_usb(button);
2845 == SYS_USB_CONNECTED)
2846 return PLUGIN_USB_CONNECTED;
2847 break; 2832 break;
2848 } 2833 }
2849 } 2834 }
@@ -2855,6 +2840,7 @@ enum plugin_status plugin_start(const void *parameter)
2855{ 2840{
2856 int ret, i; 2841 int ret, i;
2857 (void) parameter; 2842 (void) parameter;
2843 atexit(cleanup);
2858 2844
2859 FOR_NB_SCREENS(i) 2845 FOR_NB_SCREENS(i)
2860 rb->viewportmanager_theme_enable(i, false, NULL); 2846 rb->viewportmanager_theme_enable(i, false, NULL);
@@ -2873,6 +2859,21 @@ enum plugin_status plugin_start(const void *parameter)
2873 } 2859 }
2874#endif 2860#endif
2875#endif 2861#endif
2862
2863#ifdef USEGSLIB
2864 long grey_buf_used;
2865 if (!grey_init(buf, buf_size, GREY_BUFFERED|GREY_ON_COP,
2866 LCD_WIDTH, LCD_HEIGHT, &grey_buf_used))
2867 {
2868 error_wait("Greylib init failed!");
2869 return PLUGIN_ERROR;
2870 }
2871 grey_setfont(FONT_UI);
2872 buf_size -= grey_buf_used;
2873 buf = (void*)(grey_buf_used + (char*)buf);
2874#endif
2875
2876 atexit(cleanup);
2876 ret = main(); 2877 ret = main();
2877 if ( ret == PLUGIN_OK || ret == PLUGIN_GOTO_WPS) { 2878 if ( ret == PLUGIN_OK || ret == PLUGIN_GOTO_WPS) {
2878 if (configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS, 2879 if (configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS,
@@ -2882,7 +2883,5 @@ enum plugin_status plugin_start(const void *parameter)
2882 ret = PLUGIN_ERROR; 2883 ret = PLUGIN_ERROR;
2883 } 2884 }
2884 } 2885 }
2885
2886 cleanup(NULL);
2887 return ret; 2886 return ret;
2888} 2887}