diff options
author | Miika Pekkarinen <miipekk@ihme.org> | 2008-03-16 13:55:16 +0000 |
---|---|---|
committer | Miika Pekkarinen <miipekk@ihme.org> | 2008-03-16 13:55:16 +0000 |
commit | 19c6e66c1353993659ee007a6c1792a6b0b7ba13 (patch) | |
tree | 1dd7f88282b2e543fb5b22458fcb2f3bf1c7eb80 /firmware/events.c | |
parent | 478ba0afa11061a620e44cd9cc60debd955b1b33 (diff) | |
download | rockbox-19c6e66c1353993659ee007a6c1792a6b0b7ba13.tar.gz 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.c | 88 |
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2008 by Miika Pekkarinen | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include <stdio.h> | ||
21 | #include "events.h" | ||
22 | #include "panic.h" | ||
23 | |||
24 | struct sysevent { | ||
25 | unsigned short id; | ||
26 | void (*callback)(void *data); | ||
27 | }; | ||
28 | |||
29 | struct sysevent events[MAX_SYS_EVENTS]; | ||
30 | |||
31 | bool add_event(unsigned short id, void (*handler)) | ||
32 | { | ||
33 | int i; | ||
34 | |||
35 | /* Chcek if the event already exists. */ | ||
36 | for (i = 0; i < MAX_SYS_EVENTS; i++) | ||
37 | { | ||
38 | if (events[i].callback == handler && events[i].id == id) | ||
39 | return false; | ||
40 | } | ||
41 | |||
42 | /* Try to find a free slot. */ | ||
43 | for (i = 0; i < MAX_SYS_EVENTS; i++) | ||
44 | { | ||
45 | if (events[i].callback == NULL) | ||
46 | { | ||
47 | events[i].id = id; | ||
48 | events[i].callback = handler; | ||
49 | return true; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | panicf("event line full"); | ||
54 | return false; | ||
55 | } | ||
56 | |||
57 | void remove_event(unsigned short id, void (*handler)) | ||
58 | { | ||
59 | int i; | ||
60 | |||
61 | for (i = 0; i < MAX_SYS_EVENTS; i++) | ||
62 | { | ||
63 | if (events[i].id == id && events[i].callback == handler) | ||
64 | { | ||
65 | events[i].callback = NULL; | ||
66 | return; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | panicf("event not found"); | ||
71 | } | ||
72 | |||
73 | void send_event(unsigned short id, bool oneshot, void *data) | ||
74 | { | ||
75 | int i; | ||
76 | |||
77 | for (i = 0; i < MAX_SYS_EVENTS; i++) | ||
78 | { | ||
79 | if (events[i].id == id && events[i].callback != NULL) | ||
80 | { | ||
81 | events[i].callback(data); | ||
82 | |||
83 | if (oneshot) | ||
84 | events[i].callback = NULL; | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | |||