Remove all $Id$ from top of file
[jlayton/wireshark.git] / wsutil / nstime.h
1 /* nstime.h
2  * Definition of data structure to hold time values with nanosecond resolution
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #ifndef __NSTIME_H__
24 #define __NSTIME_H__
25
26 #include <time.h>
27
28 #include "ws_symbol_export.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33
34 /** @file
35  * Definition of data structure to hold time values with nanosecond resolution
36  */
37
38 /** data structure to hold time values with nanosecond resolution*/
39 typedef struct {
40         time_t  secs;
41         int     nsecs;
42 } nstime_t;
43
44 /* functions */
45
46 /** set the given nstime_t to zero */
47 WS_DLL_PUBLIC void nstime_set_zero(nstime_t *nstime);
48
49 /** is the given nstime_t currently zero? */
50 WS_DLL_PUBLIC gboolean nstime_is_zero(nstime_t *nstime);
51
52 /** set the given nstime_t to (0,maxint) to mark it as "unset"
53  * That way we can find the first frame even when a timestamp
54  * is zero (fix for bug 1056)
55  */
56 WS_DLL_PUBLIC void nstime_set_unset(nstime_t *nstime);
57
58 /* is the given nstime_t currently (0,maxint)? */
59 WS_DLL_PUBLIC gboolean nstime_is_unset(nstime_t *nstime);
60
61 /** duplicate the current time
62  *
63  * a = b
64  */
65 WS_DLL_PUBLIC void nstime_copy(nstime_t *a, const nstime_t *b);
66
67 /** calculate the delta between two times (can be negative!)
68  *
69  * delta = b-a
70  *
71  * Note that it is acceptable for two or more of the arguments to point at the
72  * same structure.
73  */
74 WS_DLL_PUBLIC void nstime_delta(nstime_t *delta, const nstime_t *b, const nstime_t *a );
75
76 /** calculate the sum of two times
77  *
78  * sum = a+b
79  *
80  * Note that it is acceptable for two or more of the arguments to point at the
81  * same structure.
82  */
83 WS_DLL_PUBLIC void nstime_sum(nstime_t *sum, const nstime_t *b, const nstime_t *a );
84
85 /** sum += a */
86 #define nstime_add(sum, a) nstime_sum(sum, sum, a)
87
88 /** sum -= a */
89 #define nstime_subtract(sum, a) nstime_delta(sum, sum, a)
90
91 /** compare two times are return a value similar to memcmp() or strcmp().
92  *
93  * a > b : > 0
94  * a = b : 0
95  * a < b : < 0
96  */
97 WS_DLL_PUBLIC int nstime_cmp (const nstime_t *a, const nstime_t *b );
98
99 /** converts nstime to double, time base is milli seconds */
100 WS_DLL_PUBLIC double nstime_to_msec(const nstime_t *nstime);
101
102 /** converts nstime to double, time base is seconds */
103 WS_DLL_PUBLIC double nstime_to_sec(const nstime_t *nstime);
104
105 #ifdef __cplusplus
106 }
107 #endif /* __cplusplus */
108
109 #endif /* __NSTIME_H__  */