1 /*
2  *  Copyright 2006  Serge van den Boom <svdb@stack.nl>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18 
19 #ifndef LIBS_CALLBACK_ALARM_H_
20 #define LIBS_CALLBACK_ALARM_H_
21 
22 #include "port.h"
23 #include "types.h"
24 
25 typedef uint32 AlarmTime;
26 static inline uint32
alarmTimeToMsUint32(AlarmTime time)27 alarmTimeToMsUint32(AlarmTime time) {
28 	return (uint32) time;
29 }
30 
31 typedef struct Alarm Alarm;
32 typedef void *AlarmCallbackArg;
33 typedef void (*AlarmCallback)(AlarmCallbackArg arg);
34 
35 struct Alarm {
36 	size_t index;
37 			// For the HeapValue 'base struct'.
38 
39 	AlarmTime time;
40 	AlarmCallback callback;
41 	AlarmCallbackArg arg;
42 };
43 
44 void Alarm_init(void);
45 void Alarm_uninit(void);
46 Alarm *Alarm_addAbsoluteMs(uint32 ms, AlarmCallback callback,
47 		AlarmCallbackArg arg);
48 Alarm *Alarm_addRelativeMs(uint32 ms, AlarmCallback callback,
49 		AlarmCallbackArg arg);
50 void Alarm_remove(Alarm *alarm);
51 bool Alarm_processOne(void);
52 void Alarm_processAll(void);
53 uint32 Alarm_timeBeforeNextMs(void);
54 
55 #endif  /* LIBS_CALLBACK_ALARM_H_ */
56 
57