aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_time_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_time_lib.h')
-rw-r--r--src/include/gnunet_time_lib.h151
1 files changed, 66 insertions, 85 deletions
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h
index ffae1ce51..1f157631f 100644
--- a/src/include/gnunet_time_lib.h
+++ b/src/include/gnunet_time_lib.h
@@ -151,34 +151,40 @@ struct GNUNET_TIME_AbsoluteNBO
151/** 151/**
152 * Return relative time of 0ms. 152 * Return relative time of 0ms.
153 */ 153 */
154struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero (void); 154struct GNUNET_TIME_Relative
155GNUNET_TIME_relative_get_zero (void);
155 156
156/** 157/**
157 * Return absolute time of 0ms. 158 * Return absolute time of 0ms.
158 */ 159 */
159struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero (void); 160struct GNUNET_TIME_Absolute
161GNUNET_TIME_absolute_get_zero (void);
160 162
161/** 163/**
162 * Return relative time of 1ms. 164 * Return relative time of 1ms.
163 */ 165 */
164struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_unit (void); 166struct GNUNET_TIME_Relative
167GNUNET_TIME_relative_get_unit (void);
165 168
166/** 169/**
167 * Return "forever". 170 * Return "forever".
168 */ 171 */
169struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever (void); 172struct GNUNET_TIME_Relative
173GNUNET_TIME_relative_get_forever (void);
170 174
171/** 175/**
172 * Return "forever". 176 * Return "forever".
173 */ 177 */
174struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever (void); 178struct GNUNET_TIME_Absolute
179GNUNET_TIME_absolute_get_forever (void);
175 180
176/** 181/**
177 * Get the current time. 182 * Get the current time.
178 * 183 *
179 * @return the current time 184 * @return the current time
180 */ 185 */
181struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get (void); 186struct GNUNET_TIME_Absolute
187GNUNET_TIME_absolute_get (void);
182 188
183/** 189/**
184 * Convert relative time to an absolute time in the 190 * Convert relative time to an absolute time in the
@@ -187,9 +193,8 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get (void);
187 * @param rel relative time to convert 193 * @param rel relative time to convert
188 * @return timestamp that is "rel" in the future, or FOREVER if rel==FOREVER (or if we would overflow) 194 * @return timestamp that is "rel" in the future, or FOREVER if rel==FOREVER (or if we would overflow)
189 */ 195 */
190struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute (struct 196struct GNUNET_TIME_Absolute
191 GNUNET_TIME_Relative 197GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel);
192 rel);
193 198
194/** 199/**
195 * Return the minimum of two relative time values. 200 * Return the minimum of two relative time values.
@@ -198,10 +203,9 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute (struct
198 * @param t2 other timestamp 203 * @param t2 other timestamp
199 * @return timestamp that is smaller 204 * @return timestamp that is smaller
200 */ 205 */
201struct GNUNET_TIME_Relative GNUNET_TIME_relative_min (struct 206struct GNUNET_TIME_Relative
202 GNUNET_TIME_Relative t1, 207GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1,
203 struct 208 struct GNUNET_TIME_Relative t2);
204 GNUNET_TIME_Relative t2);
205 209
206 210
207/** 211/**
@@ -211,10 +215,9 @@ struct GNUNET_TIME_Relative GNUNET_TIME_relative_min (struct
211 * @param t2 other timestamp 215 * @param t2 other timestamp
212 * @return timestamp that is larger 216 * @return timestamp that is larger
213 */ 217 */
214struct GNUNET_TIME_Relative GNUNET_TIME_relative_max (struct 218struct GNUNET_TIME_Relative
215 GNUNET_TIME_Relative t1, 219GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1,
216 struct 220 struct GNUNET_TIME_Relative t2);
217 GNUNET_TIME_Relative t2);
218 221
219/** 222/**
220 * Return the minimum of two absolute time values. 223 * Return the minimum of two absolute time values.
@@ -223,10 +226,9 @@ struct GNUNET_TIME_Relative GNUNET_TIME_relative_max (struct
223 * @param t2 other timestamp 226 * @param t2 other timestamp
224 * @return timestamp that is smaller 227 * @return timestamp that is smaller
225 */ 228 */
226struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min (struct 229struct GNUNET_TIME_Absolute
227 GNUNET_TIME_Absolute t1, 230GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1,
228 struct 231 struct GNUNET_TIME_Absolute t2);
229 GNUNET_TIME_Absolute t2);
230 232
231/** 233/**
232 * Return the maximum of two absolute time values. 234 * Return the maximum of two absolute time values.
@@ -235,10 +237,9 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min (struct
235 * @param t2 other timestamp 237 * @param t2 other timestamp
236 * @return timestamp that is smaller 238 * @return timestamp that is smaller
237 */ 239 */
238struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max (struct 240struct GNUNET_TIME_Absolute
239 GNUNET_TIME_Absolute t1, 241GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1,
240 struct 242 struct GNUNET_TIME_Absolute t2);
241 GNUNET_TIME_Absolute t2);
242 243
243/** 244/**
244 * Given a timestamp in the future, how much time 245 * Given a timestamp in the future, how much time
@@ -247,9 +248,8 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max (struct
247 * @param future some absolute time, typically in the future 248 * @param future some absolute time, typically in the future
248 * @return future - now, or 0 if now >= future, or FOREVER if future==FOREVER. 249 * @return future - now, or 0 if now >= future, or FOREVER if future==FOREVER.
249 */ 250 */
250struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining (struct 251struct GNUNET_TIME_Relative
251 GNUNET_TIME_Absolute 252GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future);
252 future);
253 253
254 254
255/** 255/**
@@ -262,10 +262,9 @@ struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining (struct
262 * @return remaining duration for the operation, 262 * @return remaining duration for the operation,
263 * assuming it continues at the same speed 263 * assuming it continues at the same speed
264 */ 264 */
265struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct 265struct GNUNET_TIME_Relative
266 GNUNET_TIME_Absolute 266GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, uint64_t finished,
267 start, uint64_t finished, 267 uint64_t total);
268 uint64_t total);
269 268
270 269
271/** 270/**
@@ -277,12 +276,9 @@ struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct
277 * @param end some absolute time (typically larger or equal to start) 276 * @param end some absolute time (typically larger or equal to start)
278 * @return 0 if start >= end; FOREVER if end==FOREVER; otherwise end - start 277 * @return 0 if start >= end; FOREVER if end==FOREVER; otherwise end - start
279 */ 278 */
280struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference (struct 279struct GNUNET_TIME_Relative
281 GNUNET_TIME_Absolute 280GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start,
282 start, 281 struct GNUNET_TIME_Absolute end);
283 struct
284 GNUNET_TIME_Absolute
285 end);
286 282
287/** 283/**
288 * Get the duration of an operation as the 284 * Get the duration of an operation as the
@@ -291,9 +287,8 @@ struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference (struct
291 * @param whence some absolute time, typically in the past 287 * @param whence some absolute time, typically in the past
292 * @return aborts if hence==FOREVER, 0 if hence > now, otherwise now-hence. 288 * @return aborts if hence==FOREVER, 0 if hence > now, otherwise now-hence.
293 */ 289 */
294struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration (struct 290struct GNUNET_TIME_Relative
295 GNUNET_TIME_Absolute 291GNUNET_TIME_absolute_get_duration (struct GNUNET_TIME_Absolute whence);
296 whence);
297 292
298 293
299/** 294/**
@@ -304,12 +299,9 @@ struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration (struct
304 * @param duration some relative time to add 299 * @param duration some relative time to add
305 * @return FOREVER if either argument is FOREVER or on overflow; start+duration otherwise 300 * @return FOREVER if either argument is FOREVER or on overflow; start+duration otherwise
306 */ 301 */
307struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add (struct 302struct GNUNET_TIME_Absolute
308 GNUNET_TIME_Absolute 303GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start,
309 start, 304 struct GNUNET_TIME_Relative duration);
310 struct
311 GNUNET_TIME_Relative
312 duration);
313 305
314 306
315/** 307/**
@@ -320,12 +312,9 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add (struct
320 * @param duration some relative time to subtract 312 * @param duration some relative time to subtract
321 * @return ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise 313 * @return ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise
322 */ 314 */
323struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract (struct 315struct GNUNET_TIME_Absolute
324 GNUNET_TIME_Absolute 316GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start,
325 start, 317 struct GNUNET_TIME_Relative duration);
326 struct
327 GNUNET_TIME_Relative
328 duration);
329 318
330/** 319/**
331 * Multiply relative time by a given factor. 320 * Multiply relative time by a given factor.
@@ -334,10 +323,9 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract (struct
334 * @param factor integer to multiply with 323 * @param factor integer to multiply with
335 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor 324 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
336 */ 325 */
337struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply (struct 326struct GNUNET_TIME_Relative
338 GNUNET_TIME_Relative 327GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
339 rel, 328 unsigned int factor);
340 unsigned int factor);
341 329
342/** 330/**
343 * Divide relative time by a given factor. 331 * Divide relative time by a given factor.
@@ -346,10 +334,9 @@ struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply (struct
346 * @param factor integer to divide by 334 * @param factor integer to divide by
347 * @return FOREVER if rel=FOREVER or factor==0; otherwise rel/factor 335 * @return FOREVER if rel=FOREVER or factor==0; otherwise rel/factor
348 */ 336 */
349struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide (struct 337struct GNUNET_TIME_Relative
350 GNUNET_TIME_Relative 338GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel,
351 rel, 339 unsigned int factor);
352 unsigned int factor);
353 340
354/** 341/**
355 * Add relative times together. 342 * Add relative times together.
@@ -358,10 +345,9 @@ struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide (struct
358 * @param a2 some other relative time 345 * @param a2 some other relative time
359 * @return FOREVER if either argument is FOREVER or on overflow; a1+a2 otherwise 346 * @return FOREVER if either argument is FOREVER or on overflow; a1+a2 otherwise
360 */ 347 */
361struct GNUNET_TIME_Relative GNUNET_TIME_relative_add (struct 348struct GNUNET_TIME_Relative
362 GNUNET_TIME_Relative a1, 349GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1,
363 struct 350 struct GNUNET_TIME_Relative a2);
364 GNUNET_TIME_Relative a2);
365 351
366/** 352/**
367 * Subtract relative timestamp from the other. 353 * Subtract relative timestamp from the other.
@@ -370,12 +356,9 @@ struct GNUNET_TIME_Relative GNUNET_TIME_relative_add (struct
370 * @param a2 second timestamp 356 * @param a2 second timestamp
371 * @return ZERO if a2>=a1 (including both FOREVER), FOREVER if a1 is FOREVER, a1-a2 otherwise 357 * @return ZERO if a2>=a1 (including both FOREVER), FOREVER if a1 is FOREVER, a1-a2 otherwise
372 */ 358 */
373struct GNUNET_TIME_Relative GNUNET_TIME_relative_subtract (struct 359struct GNUNET_TIME_Relative
374 GNUNET_TIME_Relative 360GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1,
375 a1, 361 struct GNUNET_TIME_Relative a2);
376 struct
377 GNUNET_TIME_Relative
378 a2);
379 362
380 363
381/** 364/**
@@ -384,9 +367,8 @@ struct GNUNET_TIME_Relative GNUNET_TIME_relative_subtract (struct
384 * @param a time to convert 367 * @param a time to convert
385 * @return converted time value 368 * @return converted time value
386 */ 369 */
387struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton (struct 370struct GNUNET_TIME_RelativeNBO
388 GNUNET_TIME_Relative 371GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a);
389 a);
390 372
391/** 373/**
392 * Convert relative time from network byte order. 374 * Convert relative time from network byte order.
@@ -394,9 +376,8 @@ struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton (struct
394 * @param a time to convert 376 * @param a time to convert
395 * @return converted time value 377 * @return converted time value
396 */ 378 */
397struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh (struct 379struct GNUNET_TIME_Relative
398 GNUNET_TIME_RelativeNBO 380GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a);
399 a);
400 381
401/** 382/**
402 * Convert relative time to network byte order. 383 * Convert relative time to network byte order.
@@ -404,9 +385,8 @@ struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh (struct
404 * @param a time to convert 385 * @param a time to convert
405 * @return converted time value 386 * @return converted time value
406 */ 387 */
407struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton (struct 388struct GNUNET_TIME_AbsoluteNBO
408 GNUNET_TIME_Absolute 389GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a);
409 a);
410 390
411/** 391/**
412 * Convert relative time from network byte order. 392 * Convert relative time from network byte order.
@@ -414,9 +394,8 @@ struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton (struct
414 * @param a time to convert 394 * @param a time to convert
415 * @return converted time value 395 * @return converted time value
416 */ 396 */
417struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh (struct 397struct GNUNET_TIME_Absolute
418 GNUNET_TIME_AbsoluteNBO 398GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a);
419 a);
420 399
421/** 400/**
422 * Convert a relative time to a string. 401 * Convert a relative time to a string.
@@ -426,14 +405,16 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh (struct
426 * 405 *
427 * @return string form of the time (as milliseconds) 406 * @return string form of the time (as milliseconds)
428 */ 407 */
429const char *GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time); 408const char *
409GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time);
430 410
431/** 411/**
432 * Set the timestamp offset for this instance. 412 * Set the timestamp offset for this instance.
433 * 413 *
434 * @param offset the offset to skew the locale time by 414 * @param offset the offset to skew the locale time by
435 */ 415 */
436void GNUNET_TIME_set_offset (long long offset); 416void
417GNUNET_TIME_set_offset (long long offset);
437 418
438#if 0 /* keep Emacsens' auto-indent happy */ 419#if 0 /* keep Emacsens' auto-indent happy */
439{ 420{