From 71898e5c547e1f92bb128aede558938873f56d3c Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Thu, 16 Oct 2008 10:38:03 +0000 Subject: Accept FS#9480 - centralise and organise the events in the apps/ layer. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18819 a1c6a512-1295-4272-9138-f99709370657 --- apps/appevents.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++ apps/buffering.c | 14 ++++++------ apps/buffering.h | 10 +-------- apps/gui/gwps.c | 3 ++- apps/gui/statusbar.h | 4 ---- apps/menus/display_menu.c | 4 ++-- apps/mpeg.c | 2 +- apps/playback.c | 10 ++++----- apps/scrobbler.c | 1 + apps/tagtree.c | 2 +- 10 files changed, 76 insertions(+), 30 deletions(-) create mode 100644 apps/appevents.h (limited to 'apps') diff --git a/apps/appevents.h b/apps/appevents.h new file mode 100644 index 0000000000..36990f9768 --- /dev/null +++ b/apps/appevents.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: events.h 17847 2008-06-28 18:10:04Z bagder $ + * + * Copyright (C) 2008 by Jonathan Gordon + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef _APPEVENTS_H +#define _APPEVENTS_H + +#include +#include "events.h" + +/** Only app/ level events should be defined here. + * firmware/ level events and CLASS's are defined in firmware/export/events.h + */ + +/** Playback events **/ +enum { + PLAYBACK_EVENT_TRACK_BUFFER = (EVENT_CLASS_PLAYBACK|1), + PLAYBACK_EVENT_TRACK_FINISH, + PLAYBACK_EVENT_TRACK_CHANGE, +}; + +/** Buffering events **/ +enum { + BUFFER_EVENT_BUFFER_LOW = (EVENT_CLASS_BUFFERING|1), + BUFFER_EVENT_REBUFFER, + BUFFER_EVENT_CLOSED, + BUFFER_EVENT_MOVED, + BUFFER_EVENT_FINISHED, +}; + +/** Generic GUI class events **/ +enum { + GUI_EVENT_THEME_CHANGED = (EVENT_CLASS_GUI|1), + GUI_EVENT_STATUSBAR_TOGGLE, +}; + +#endif + + diff --git a/apps/buffering.c b/apps/buffering.c index a821e7f8c7..d963a983a6 100644 --- a/apps/buffering.c +++ b/apps/buffering.c @@ -50,7 +50,7 @@ #include "pcmbuf.h" #include "buffer.h" #include "bmp.h" -#include "events.h" +#include "appevents.h" #include "metadata.h" #if MEM > 1 @@ -600,7 +600,7 @@ static bool buffer_handle(int handle_id) h->filerem = 0; h->available = sizeof(struct mp3entry); h->widx += sizeof(struct mp3entry); - send_event(EVENT_HANDLE_FINISHED, &h->id); + send_event(BUFFER_EVENT_FINISHED, &h->id); return true; } @@ -673,7 +673,7 @@ static bool buffer_handle(int handle_id) /* finished buffering the file */ close(h->fd); h->fd = -1; - send_event(EVENT_HANDLE_FINISHED, &h->id); + send_event(BUFFER_EVENT_FINISHED, &h->id); } return true; @@ -729,7 +729,7 @@ static void rebuffer_handle(int handle_id, size_t newpos) /* There isn't enough space to rebuffer all of the track from its new offset, so we ask the user to free some */ DEBUGF("rebuffer_handle: space is needed\n"); - send_event(EVENT_HANDLE_REBUFFER, &handle_id); + send_event(BUFFER_EVENT_REBUFFER, &handle_id); } /* Now we ask for a rebuffer */ @@ -1339,7 +1339,7 @@ void buffering_thread(void) LOGFQUEUE("buffering < Q_START_FILL %d", (int)ev.data); /* Call buffer callbacks here because this is one of two ways * to begin a full buffer fill */ - send_event(EVENT_BUFFER_LOW, 0); + send_event(BUFFER_EVENT_BUFFER_LOW, 0); shrink_buffer(); queue_reply(&buffering_queue, 1); filling |= buffer_handle((int)ev.data); @@ -1401,7 +1401,7 @@ void buffering_thread(void) /* If the buffer is low, call the callbacks to get new data */ if (num_handles > 0 && data_counters.useful <= conf_watermark) - send_event(EVENT_BUFFER_LOW, 0); + send_event(BUFFER_EVENT_BUFFER_LOW, 0); #if 0 /* TODO: This needs to be fixed to use the idle callback, disable it @@ -1411,7 +1411,7 @@ void buffering_thread(void) else if (ata_disk_is_active() && queue_empty(&buffering_queue)) { if (num_handles > 0 && data_counters.useful <= high_watermark) - send_event(EVENT_BUFFER_LOW, 0); + send_event(BUFFER_EVENT_BUFFER_LOW, 0); if (data_counters.remaining > 0 && BUF_USED <= high_watermark) { diff --git a/apps/buffering.h b/apps/buffering.h index c5a58c2e42..c36131898b 100644 --- a/apps/buffering.h +++ b/apps/buffering.h @@ -24,7 +24,7 @@ #include #include -#include "events.h" +#include "appevents.h" enum data_type { @@ -38,14 +38,6 @@ enum data_type { TYPE_UNKNOWN, }; -enum callback_event { - EVENT_BUFFER_LOW = (EVENT_CLASS_BUFFERING|1), - EVENT_HANDLE_REBUFFER, - EVENT_HANDLE_CLOSED, - EVENT_HANDLE_MOVED, - EVENT_HANDLE_FINISHED, -}; - /* Error return values */ #define ERR_HANDLE_NOT_FOUND -1 #define ERR_BUFFER_FULL -2 diff --git a/apps/gui/gwps.c b/apps/gui/gwps.c index 47cc05aad2..4d50740182 100644 --- a/apps/gui/gwps.c +++ b/apps/gui/gwps.c @@ -61,6 +61,7 @@ #include "backdrop.h" #include "quickscreen.h" #include "pitchscreen.h" +#include "appevents.h" /* currently only on wps_state is needed */ struct wps_state wps_state; @@ -820,7 +821,7 @@ void gui_sync_wps_init(void) gui_wps_set_statusbar(&gui_wps[i], &statusbars.statusbars[i]); } #ifdef HAVE_LCD_BITMAP - add_event(STATUSBAR_TOGGLE_EVENT, false, statusbar_toggle_handler); + add_event(GUI_EVENT_STATUSBAR_TOGGLE, false, statusbar_toggle_handler); #endif #if LCD_DEPTH > 1 unload_wps_backdrop(); diff --git a/apps/gui/statusbar.h b/apps/gui/statusbar.h index 7e8221461d..f36d609bad 100644 --- a/apps/gui/statusbar.h +++ b/apps/gui/statusbar.h @@ -30,10 +30,6 @@ #define STATUSBAR_Y_POS 0 /* MUST be a multiple of 8 */ #define STATUSBAR_HEIGHT 8 -/* possibly a horrible misuse of the event system. - This is triggered when the statusbar setting changes */ -#define STATUSBAR_TOGGLE_EVENT (EVENT_CLASS_GUI|1) - struct status_info { int battlevel; int batt_charge_step; diff --git a/apps/menus/display_menu.c b/apps/menus/display_menu.c index b71cbb0e08..016255bad1 100644 --- a/apps/menus/display_menu.c +++ b/apps/menus/display_menu.c @@ -23,7 +23,7 @@ #include #include #include "config.h" -#include "events.h" +#include "appevents.h" #include "lang.h" #include "action.h" #include "settings.h" @@ -304,7 +304,7 @@ static int statusbar_callback(int action,const struct menu_item_ex *this_item) switch (action) { case ACTION_EXIT_MENUITEM: - send_event(STATUSBAR_TOGGLE_EVENT, NULL); + send_event(GUI_EVENT_STATUSBAR_TOGGLE, NULL); /* this should be changed so only the viewports are reloaded */ settings_apply(false); break; diff --git a/apps/mpeg.c b/apps/mpeg.c index 6056b68053..713915d5a6 100644 --- a/apps/mpeg.c +++ b/apps/mpeg.c @@ -39,7 +39,7 @@ #include "mp3_playback.h" #include "sound.h" #include "bitswap.h" -#include "events.h" +#include "appevents.h" #ifndef SIMULATOR #include "i2c.h" #include "mas.h" diff --git a/apps/playback.c b/apps/playback.c index 82ab24405f..c7c0b5e9c4 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -44,7 +44,7 @@ #include "codecs.h" #include "audio.h" #include "buffering.h" -#include "events.h" +#include "appevents.h" #include "voice_thread.h" #include "mp3_playback.h" #include "usb.h" @@ -2134,7 +2134,7 @@ static void audio_stop_playback(void) prev_track_elapsed = curtrack_id3.elapsed; - remove_event(EVENT_BUFFER_LOW, buffering_low_buffer_callback); + remove_event(BUFFER_EVENT_BUFFER_LOW, buffering_low_buffer_callback); } paused = false; @@ -2194,7 +2194,7 @@ static void audio_play_start(size_t offset) audio_fill_file_buffer(true, offset); - add_event(EVENT_BUFFER_LOW, false, buffering_low_buffer_callback); + add_event(BUFFER_EVENT_BUFFER_LOW, false, buffering_low_buffer_callback); LOGFQUEUE("audio > audio Q_AUDIO_TRACK_CHANGED"); queue_post(&audio_queue, Q_AUDIO_TRACK_CHANGED, 0); @@ -2578,8 +2578,8 @@ void audio_init(void) #endif } - add_event(EVENT_HANDLE_REBUFFER, false, buffering_handle_rebuffer_callback); - add_event(EVENT_HANDLE_FINISHED, false, buffering_handle_finished_callback); + add_event(BUFFER_EVENT_REBUFFER, false, buffering_handle_rebuffer_callback); + add_event(BUFFER_EVENT_FINISHED, false, buffering_handle_finished_callback); /* Probably safe to say */ audio_is_initialized = true; diff --git a/apps/scrobbler.c b/apps/scrobbler.c index 2c6bdf4a1f..acf1e9e4b0 100644 --- a/apps/scrobbler.c +++ b/apps/scrobbler.c @@ -34,6 +34,7 @@ http://www.audioscrobbler.net/wiki/Portable_Player_Logging #include "settings.h" #include "ata_idle_notify.h" #include "misc.h" +#include "appevents.h" #if CONFIG_RTC #include "time.h" diff --git a/apps/tagtree.c b/apps/tagtree.c index 92bf18bc26..7b05391640 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -47,7 +47,7 @@ #include "misc.h" #include "filetypes.h" #include "audio.h" -#include "events.h" +#include "appevents.h" #define FILE_SEARCH_INSTRUCTIONS ROCKBOX_DIR "/tagnavi.config" -- cgit v1.2.3