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 ****************************************************************************/
27 void (*callback
)(void *data
);
30 struct sysevent events
[MAX_SYS_EVENTS
];
32 bool add_event(unsigned short id
, bool oneshot
, void (*handler
))
36 /* Chcek if the event already exists. */
37 for (i
= 0; i
< MAX_SYS_EVENTS
; i
++)
39 if (events
[i
].callback
== handler
&& events
[i
].id
== id
)
43 /* Try to find a free slot. */
44 for (i
= 0; i
< MAX_SYS_EVENTS
; i
++)
46 if (events
[i
].callback
== NULL
)
49 events
[i
].oneshot
= oneshot
;
50 events
[i
].callback
= handler
;
55 panicf("event line full");
59 void remove_event(unsigned short id
, void (*handler
))
63 for (i
= 0; i
< MAX_SYS_EVENTS
; i
++)
65 if (events
[i
].id
== id
&& events
[i
].callback
== handler
)
67 events
[i
].callback
= NULL
;
72 panicf("event not found");
75 void send_event(unsigned short id
, void *data
)
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
;