-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibiphb.h
More file actions
172 lines (132 loc) · 5.94 KB
/
Copy pathlibiphb.h
File metadata and controls
172 lines (132 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
@brief Interface to the IP heartbeat service (libiphb).
@file libiphb.h
@author Raimo Vuonnala <raimo.vuonnala@nokia.com>
@author Semi Malinen <semi.malinen@nokia.com>
Copyright (C) 2008-2011 Nokia Corporation.
Copyright (C) AsteroidOS contributors (libiphb-timerfd).
This file is part of libiphb-timerfd.
libiphb-timerfd is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 2.1
as published by the Free Software Foundation.
It is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details.
You should have received a copy of the GNU Lesser General Public License
along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef IPHB_H
#define IPHB_H
#include <time.h>
/** Handle to the iphb service (NULL is an invalid handle). */
typedef void *iphb_t;
/**
Open the iphb service.
@param dummy For compatibility, can be NULL.
@return Handle for iphb, or NULL on error (check errno). On error the
caller should behave as if there were no heartbeat service.
*/
iphb_t iphb_open(int *dummy);
/**
"Global sync" predefined values (slots), see iphb_wait().
The timeline is divided into fixed global slots; all waiters for a given slot
are woken at the same time (lower-value waiters wake too), which lets
independent clients coalesce their wakeups.
*/
#define IPHB_GS_WAIT_30_SEC 30 //!< 30 second wakeup slot
#define IPHB_GS_WAIT_2_5_MINS (2*60+30) //!< 2.5 minute wakeup slot
#define IPHB_GS_WAIT_5_MINS (5*60) //!< 5 minute wakeup slot
#define IPHB_GS_WAIT_10_MINS (10*60) //!< 10 minute wakeup slot
#define IPHB_GS_WAIT_30_MINS (30*60) //!< 30 minute wakeup slot
#define IPHB_GS_WAIT_1_HOUR (60*60) //!< 1 hour wakeup slot
#define IPHB_GS_WAIT_2_HOURS (2*60*60) //!< 2 hour wakeup slot
#define IPHB_GS_WAIT_10_HOURS (10*60*60) //!< 10 hour wakeup slot
/**
Wait for the next heartbeat.
@param iphbh Handle from iphb_open().
@param mintime Seconds that MUST elapse before the heartbeat is reacted to.
Value 0 means "wake me when somebody else is woken".
@param maxtime Seconds by which the wait MUST end. Keeping maxtime - mintime
large lets clients sync. Setting mintime == maxtime to an
IPHB_GS_WAIT_* value selects a global synchronisation slot.
@param must_wait 1 to block until the heartbeat, 0 to drive the descriptor
yourself via select()/poll() (see iphb_get_fd()).
@return Seconds waited, or (time_t)-1 on error (check errno).
*/
time_t
iphb_wait(iphb_t iphbh, unsigned short mintime, unsigned short maxtime,
int must_wait);
/**
Wait for the next heartbeat (extended form).
There can be only one wakeup per iphb handle. Calling this cancels any
previously programmed wakeup. Passing zero for both mintime and maxtime
cancels the pending wakeup without programming a new one.
If mintime == maxtime, a global wakeup slot is used rather than a ranged
wakeup; use the predefined IPHB_GS_WAIT_* values to maximise synchronous
wakeups.
@param iphbh Handle from iphb_open().
@param mintime Seconds that MUST elapse before the heartbeat is reacted to.
@param maxtime Seconds by which the wait SHOULD end. Keeping maxtime -
mintime large maximises the chance of coalescing with other
iphb clients.
@param must_wait If non-zero, block until the wakeup before returning. Zero
means you will use select()/poll() on the descriptor from
iphb_get_fd(); once it becomes readable the pending data
must be flushed (see iphb_discard_wakeups()).
@param resume If non-zero, the device is woken from suspend to end the
wait. Use zero if the client can wait until the device
leaves suspend for some other reason.
@return Seconds waited, or (time_t)-1 on error (check errno).
*/
time_t
iphb_wait2(iphb_t iphbh, unsigned mintime, unsigned maxtime, int must_wait,
int resume);
/**
Acknowledge that the application woke up by some means other than iphb.
@param iphbh Handle from iphb_open().
@return >= 0 on success (number of wakeup bytes discarded),
-1 on error (check errno).
*/
int
iphb_I_woke_up(iphb_t iphbh);
/**
Discard any pending wakeups on the handle's descriptor.
Intended primarily for the Qt wrapper.
@param iphbh Handle from iphb_open().
@return >= 0 on success (number of bytes discarded),
-1 on error (check errno).
*/
int
iphb_discard_wakeups(iphb_t iphbh);
/**
Get the descriptor to use with select()/poll().
@param iphbh Handle from iphb_open().
@return A descriptor usable with select()/poll(), or -1 on error
(check errno). Note: this is a timerfd, so drain it with
read() (an 8-byte expiration count), not recv().
*/
int
iphb_get_fd(iphb_t iphbh);
/** iphb statistics. */
struct iphb_stats {
unsigned int clients; //!< number of active iphb clients
unsigned int waiting; //!< number of clients waiting for a heartbeat
unsigned int next_hb; //!< seconds until the next heartbeat, 0 if none pending
};
/**
Get statistics.
@param iphbh Handle from iphb_open().
@param stats Placeholder filled in on success.
@return 0 on success, -1 on error (check errno).
*/
int
iphb_get_stats(iphb_t iphbh, struct iphb_stats *stats);
/**
Close the iphb service.
@param iphbh Handle from iphb_open().
@return Always NULL (convenient for clearing the caller's handle).
*/
iphb_t
iphb_close(iphb_t iphbh);
#endif /* IPHB_H */