1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
24 #define MAX_SYS_EVENTS 16
29 void (*callback
)(void *data
);
32 static struct sysevent events
[MAX_SYS_EVENTS
];
34 bool add_event(unsigned short id
, bool oneshot
, void (*handler
))
38 /* Check if the event already exists. */
39 for (i
= 0; i
< MAX_SYS_EVENTS
; i
++)
41 if (events
[i
].callback
== handler
&& events
[i
].id
== id
)
45 /* Try to find a free slot. */
46 for (i
= 0; i
< MAX_SYS_EVENTS
; i
++)
48 if (events
[i
].callback
== NULL
)
51 events
[i
].oneshot
= oneshot
;
52 events
[i
].callback
= handler
;
57 panicf("event line full");
61 void remove_event(unsigned short id
, void (*handler
))
65 for (i
= 0; i
< MAX_SYS_EVENTS
; i
++)
67 if (events
[i
].id
== id
&& events
[i
].callback
== handler
)
69 events
[i
].callback
= NULL
;
74 panicf("event %d not found", (int)id
);
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
;