[IOMultiplexerV2] added CIOTimer class to c++ interface && added some features to...
[NextIRCd.git] / src / IOHandler / IOTimer.h
1 /* IOTimer.h - IOMultiplexer v2
2  * Copyright (C) 2014  Philipp Kreil (pk910)
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 3 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, see <http://www.gnu.org/licenses/>. 
16  */
17 #ifndef _IOTimer_h
18 #define _IOTimer_h
19 #ifndef _IOHandler_internals
20 #include "IOHandler.h"
21 #else
22 #include <sys/time.h>
23
24
25 #define IOTIMERFLAG_PERIODIC       0x01
26 #define IOTIMERFLAG_ACTIVE         0x02
27 #define IOTIMERFLAG_IN_LIST        0x04
28 #define IOTIMERFLAG_PARENT_PUBLIC  0x08
29 #define IOTIMERFLAG_PARENT_SOCKET  0x10
30 #define IOTIMERFLAG_PERSISTENT     0x20
31
32 struct _IOTimerDescriptor;
33
34 extern struct _IOTimerDescriptor *iotimer_sorted_descriptors;
35
36 struct _IOTimerDescriptor {
37         unsigned int flags : 8;
38         void *parent; 
39         
40         struct timeval timeout;
41         struct timeval autoreload;
42         
43         struct _IOTimerDescriptor *prev, *next;
44 };
45
46 void _init_timers();
47 struct _IOTimerDescriptor *_create_timer(struct timeval *timeout);
48 void _destroy_timer(struct _IOTimerDescriptor *timer);
49 void _trigger_timer();
50
51 #endif
52
53 struct IOTimerDescriptor;
54
55 #define IOTIMER_CALLBACK(NAME) void NAME(struct IOTimerDescriptor *iotimer)
56 typedef IOTIMER_CALLBACK(iotimer_callback);
57
58 struct IOTimerDescriptor {
59         void *iotimer; /* struct _IOTimerDescriptor */
60         
61         iotimer_callback *callback;
62         void *data;
63 };
64
65 struct IOTimerDescriptor *iotimer_create(struct timeval *timeout);
66 void iotimer_start(struct IOTimerDescriptor *iotimer);
67 void iotimer_stop(struct IOTimerDescriptor *iotimer);
68 int iotimer_state(struct IOTimerDescriptor *iotimer);
69 void iotimer_set_autoreload(struct IOTimerDescriptor *iotimer, struct timeval *autoreload);
70 struct timeval iotimer_get_autoreload(struct IOTimerDescriptor *iotimer);
71 void iotimer_set_timeout(struct IOTimerDescriptor *iotimer, struct timeval *timeout);
72 struct timeval iotimer_get_timeout(struct IOTimerDescriptor *iotimer);
73 void iotimer_set_callback(struct IOTimerDescriptor *iotimer, iotimer_callback *callback);
74 void iotimer_set_persistent(struct IOTimerDescriptor *iotimer, int persistent);
75 void iotimer_destroy(struct IOTimerDescriptor *iotimer);
76
77 #endif