summaryrefslogtreecommitdiffstats
path: root/firmware/events.c
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2008-03-16 13:55:16 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2008-03-16 13:55:16 +0000
commit19c6e66c1353993659ee007a6c1792a6b0b7ba13 (patch)
tree1dd7f88282b2e543fb5b22458fcb2f3bf1c7eb80 /firmware/events.c
parent478ba0afa11061a620e44cd9cc60debd955b1b33 (diff)
downloadrockbox-19c6e66c1353993659ee007a6c1792a6b0b7ba13.tar.gz
rockbox-19c6e66c1353993659ee007a6c1792a6b0b7ba13.tar.bz2
rockbox-19c6e66c1353993659ee007a6c1792a6b0b7ba13.zip
Implement the playback event handling as a system-wide multi-purpose event system. Unified mpeg.c and playback.c audio event handling. Converted ata_idle_notify to use the new event handling system also.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16682 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/events.c')
-rw-r--r--firmware/events.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/firmware/events.c b/firmware/events.c
new file mode 100644
index 0000000000..eaf2e5c352
--- /dev/null
+++ b/firmware/events.c
@@ -0,0 +1,88 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2008 by Miika Pekkarinen
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <stdio.h>
+#include "events.h"
+#include "panic.h"
+
+struct sysevent {
+ unsigned short id;
+ void (*callback)(void *data);
+};
+
+struct sysevent events[MAX_SYS_EVENTS];
+
+bool add_event(unsigned short id, void (*handler))
+{
+ int i;
+
+ /* Chcek if the event already exists. */
+ for (i = 0; i < MAX_SYS_EVENTS; i++)
+ {
+ if (events[i].callback == handler && events[i].id == id)
+ return false;
+ }
+
+ /* Try to find a free slot. */
+ for (i = 0; i < MAX_SYS_EVENTS; i++)
+ {
+ if (events[i].callback == NULL)
+ {
+ events[i].id = id;
+ events[i].callback = handler;
+ return true;
+ }
+ }
+
+ panicf("event line full");
+ return false;
+}
+
+void remove_event(unsigned short id, void (*handler))
+{
+ int i;
+
+ for (i = 0; i < MAX_SYS_EVENTS; i++)
+ {
+ if (events[i].id == id && events[i].callback == handler)
+ {
+ events[i].callback = NULL;
+ return;
+ }
+ }
+
+ panicf("event not found");
+}
+
+void send_event(unsigned short id, bool oneshot, void *data)
+{
+ int i;
+
+ for (i = 0; i < MAX_SYS_EVENTS; i++)
+ {
+ if (events[i].id == id && events[i].callback != NULL)
+ {
+ events[i].callback(data);
+
+ if (oneshot)
+ events[i].callback = NULL;
+ }
+ }
+}
+