summaryrefslogtreecommitdiff
path: root/apps/plugins/clock
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-08-24 14:30:46 +0000
committerThomas Martitz <kugel@rockbox.org>2010-08-24 14:30:46 +0000
commitcae4ae2c71ae10ff67d39a78a705136e740dc07e (patch)
treeb5bb5e1879493f67d7c7ad977fba90eb49b743d7 /apps/plugins/clock
parent3478bc5d6dc0a081c3aeb4f501c8b4cb4f53a78d (diff)
downloadrockbox-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/clock')
-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}