1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 by Miika Pekkarinen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
26 #define MAX_SYS_EVENTS 28
31 void (*callback
)(void *data
);
34 static struct sysevent events
[MAX_SYS_EVENTS
];
36 bool add_event(unsigned short id
, bool oneshot
, void (*handler
)(void *data
))
40 /* Check if the event already exists. */
41 for (i
= 0; i
< MAX_SYS_EVENTS
; i
++)
43 if (events
[i
].callback
== handler
&& events
[i
].id
== id
)
47 /* Try to find a free slot. */
48 for (i
= 0; i
< MAX_SYS_EVENTS
; i
++)
50 if (events
[i
].callback
== NULL
)
53 events
[i
].oneshot
= oneshot
;
54 events
[i
].callback
= handler
;
59 panicf("event line full");
63 void remove_event(unsigned short id
, void (*handler
)(void *data
))
67 for (i
= 0; i
< MAX_SYS_EVENTS
; i
++)
69 if (events
[i
].id
== id
&& events
[i
].callback
== handler
)
71 events
[i
].callback
= NULL
;
77 void send_event(unsigned short id
, void *data
)
81 for (i
= 0; i
< MAX_SYS_EVENTS
; i
++)
83 if (events
[i
].id
== id
&& events
[i
].callback
!= NULL
)
85 events
[i
].callback(data
);
87 if (events
[i
].oneshot
)
88 events
[i
].callback
= NULL
;