summaryrefslogtreecommitdiff
path: root/apps/plugins/clock/clock.c
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/clock/clock.c
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/clock/clock.c')
-rw-r--r--apps/plugins/clock/clock.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/apps/plugins/clock/clock.c b/apps/plugins/clock/clock.c
index f06f3e15e4..8a1a55e17f 100644
--- a/apps/plugins/clock/clock.c
+++ b/apps/plugins/clock/clock.c
@@ -22,6 +22,7 @@
22#include "plugin.h" 22#include "plugin.h"
23#include "time.h" 23#include "time.h"
24#include "lib/pluginlib_actions.h" 24#include "lib/pluginlib_actions.h"
25#include "lib/pluginlib_exit.h"
25#include "lib/xlcd.h" 26#include "lib/xlcd.h"
26 27
27#include "clock.h" 28#include "clock.h"
@@ -30,7 +31,7 @@
30#include "clock_menu.h" 31#include "clock_menu.h"
31#include "clock_settings.h" 32#include "clock_settings.h"
32 33
33PLUGIN_HEADER 34
34 35
35/* Keymaps */ 36/* Keymaps */
36const struct button_mapping* plugin_contexts[]={ 37const struct button_mapping* plugin_contexts[]={
@@ -56,9 +57,8 @@ const struct button_mapping* plugin_contexts[]={
56/************************** 57/**************************
57 * Cleanup on plugin return 58 * Cleanup on plugin return
58 *************************/ 59 *************************/
59void cleanup(void *parameter) 60void cleanup(void)
60{ 61{
61 (void)parameter;
62 clock_draw_restore_colors(); 62 clock_draw_restore_colors();
63 if(clock_settings.general.save_settings == 1) 63 if(clock_settings.general.save_settings == 1)
64 save_settings(); 64 save_settings();
@@ -115,6 +115,7 @@ enum plugin_status plugin_start(const void* parameter){
115 struct counter counter; 115 struct counter counter;
116 bool exit_clock = false; 116 bool exit_clock = false;
117 (void)parameter; 117 (void)parameter;
118 atexit(cleanup);
118 119
119#if LCD_DEPTH > 1 120#if LCD_DEPTH > 1
120 rb->lcd_set_backdrop(NULL); 121 rb->lcd_set_backdrop(NULL);
@@ -174,9 +175,7 @@ enum plugin_status plugin_start(const void* parameter){
174 exit_clock=main_menu(); 175 exit_clock=main_menu();
175 break; 176 break;
176 default: 177 default:
177 if(rb->default_event_handler_ex(button, cleanup, NULL) 178 exit_on_usb(button);
178 == SYS_USB_CONNECTED)
179 return PLUGIN_USB_CONNECTED;
180 if(time.second != last_second){ 179 if(time.second != last_second){
181 last_second=time.second; 180 last_second=time.second;
182 redraw=true; 181 redraw=true;
@@ -193,6 +192,5 @@ enum plugin_status plugin_start(const void* parameter){
193 } 192 }
194 } 193 }
195 194
196 cleanup(NULL);
197 return PLUGIN_OK; 195 return PLUGIN_OK;
198} 196}