When setting a cache path also enable the cache implicitly.
[Rockbox.git] / firmware / events.c
blob12f5ab1c8d5e7a1e51723106332b819f0634ae3e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Miika Pekkarinen
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <stdio.h>
21 #include "events.h"
22 #include "panic.h"
24 struct sysevent {
25 unsigned short id;
26 bool oneshot;
27 void (*callback)(void *data);
30 struct sysevent events[MAX_SYS_EVENTS];
32 bool add_event(unsigned short id, bool oneshot, void (*handler))
34 int i;
36 /* Check if the event already exists. */
37 for (i = 0; i < MAX_SYS_EVENTS; i++)
39 if (events[i].callback == handler && events[i].id == id)
40 return false;
43 /* Try to find a free slot. */
44 for (i = 0; i < MAX_SYS_EVENTS; i++)
46 if (events[i].callback == NULL)
48 events[i].id = id;
49 events[i].oneshot = oneshot;
50 events[i].callback = handler;
51 return true;
55 panicf("event line full");
56 return false;
59 void remove_event(unsigned short id, void (*handler))
61 int i;
63 for (i = 0; i < MAX_SYS_EVENTS; i++)
65 if (events[i].id == id && events[i].callback == handler)
67 events[i].callback = NULL;
68 return;
72 panicf("event %d not found", (int)id);
75 void send_event(unsigned short id, void *data)
77 int i;
79 for (i = 0; i < MAX_SYS_EVENTS; i++)
81 if (events[i].id == id && events[i].callback != NULL)
83 events[i].callback(data);
85 if (events[i].oneshot)
86 events[i].callback = NULL;