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
diff --git a/apps/appevents.h b/apps/appevents.h
new file mode 100644
index 0000000..36990f9
--- /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 <stdbool.h>
+#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 a821e7f..d963a98 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 @@
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 @@
/* 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 @@
/* 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 @@
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 @@
/* 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 @@
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 c5a58c2..c361318 100644
--- a/apps/buffering.h
+++ b/apps/buffering.h
@@ -24,7 +24,7 @@
#include <sys/types.h>
#include <stdbool.h>
-#include "events.h"
+#include "appevents.h"
enum data_type {
@@ -38,14 +38,6 @@
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 47cc05a..4d50740 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 @@
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 7e82214..f36d609 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 b71cbb0..016255b 100644
--- a/apps/menus/display_menu.c
+++ b/apps/menus/display_menu.c
@@ -23,7 +23,7 @@
#include <stddef.h>
#include <limits.h>
#include "config.h"
-#include "events.h"
+#include "appevents.h"
#include "lang.h"
#include "action.h"
#include "settings.h"
@@ -304,7 +304,7 @@
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 6056b68..713915d 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 82ab244..c7c0b5e 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 @@
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 @@
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 @@
#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 2c6bdf4..acf1e9e 100644
--- a/apps/scrobbler.c
+++ b/apps/scrobbler.c
@@ -34,6 +34,7 @@
#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 92bf18b..7b05391 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"
diff --git a/firmware/export/events.h b/firmware/export/events.h
index 40447d5..cad0fad 100644
--- a/firmware/export/events.h
+++ b/firmware/export/events.h
@@ -24,6 +24,10 @@
#include <stdbool.h>
+/** Only CLASS defines and firmware/ level events should be defined here.
+ * apps/ level events are defined in apps/appevents.h
+ */
+
/**
* High byte = Event class definition
* Low byte = Event ID
@@ -34,17 +38,6 @@
#define EVENT_CLASS_BUFFERING 0x0400
#define EVENT_CLASS_GUI 0x0800
-/**
- * Because same playback events are used in mpeg.c and playback.c, define
- * them here to prevent cluttering and ifdefs.
- */
-enum {
- PLAYBACK_EVENT_TRACK_BUFFER = (EVENT_CLASS_PLAYBACK|1),
- PLAYBACK_EVENT_TRACK_FINISH,
- PLAYBACK_EVENT_TRACK_CHANGE,
-};
-
-
bool add_event(unsigned short id, bool oneshot, void (*handler));
void remove_event(unsigned short id, void (*handler));
void send_event(unsigned short id, void *data);