2001-09-14 07:33:04 +00:00
|
|
|
/* nstime.h
|
|
|
|
* Definition of data structure to hold time values with nanosecond resolution
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2001-09-14 07:33:04 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2001-09-14 07:33:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2001-09-14 07:33:04 +00:00
|
|
|
* This program 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 General Public License for more details.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2001-09-14 07:33:04 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2001-09-14 07:33:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __NSTIME_H__
|
|
|
|
#define __NSTIME_H__
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
2013-03-01 23:53:11 +00:00
|
|
|
#include "ws_symbol_export.h"
|
2007-04-03 21:17:13 +00:00
|
|
|
|
2012-07-27 21:43:02 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** @file
|
|
|
|
* Definition of data structure to hold time values with nanosecond resolution
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** data structure to hold time values with nanosecond resolution*/
|
2014-04-12 04:32:20 +00:00
|
|
|
typedef struct nstime_t {
|
2001-09-14 07:33:04 +00:00
|
|
|
time_t secs;
|
|
|
|
int nsecs;
|
|
|
|
} nstime_t;
|
|
|
|
|
2005-08-03 20:37:28 +00:00
|
|
|
/* functions */
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** set the given nstime_t to zero */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC void nstime_set_zero(nstime_t *nstime);
|
2005-08-24 21:31:56 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** is the given nstime_t currently zero? */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC gboolean nstime_is_zero(nstime_t *nstime);
|
2005-08-24 21:31:56 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** set the given nstime_t to (0,maxint) to mark it as "unset"
|
2007-05-21 20:41:05 +00:00
|
|
|
* That way we can find the first frame even when a timestamp
|
|
|
|
* is zero (fix for bug 1056)
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC void nstime_set_unset(nstime_t *nstime);
|
2007-05-21 20:41:05 +00:00
|
|
|
|
|
|
|
/* is the given nstime_t currently (0,maxint)? */
|
2014-05-23 23:40:56 +00:00
|
|
|
WS_DLL_PUBLIC gboolean nstime_is_unset(const nstime_t *nstime);
|
2007-05-21 20:41:05 +00:00
|
|
|
|
2011-08-13 17:39:25 +00:00
|
|
|
/** duplicate the current time
|
|
|
|
*
|
|
|
|
* a = b
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC void nstime_copy(nstime_t *a, const nstime_t *b);
|
2011-08-13 17:39:25 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** calculate the delta between two times (can be negative!)
|
2005-08-03 20:37:28 +00:00
|
|
|
*
|
|
|
|
* delta = b-a
|
|
|
|
*
|
|
|
|
* Note that it is acceptable for two or more of the arguments to point at the
|
|
|
|
* same structure.
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC void nstime_delta(nstime_t *delta, const nstime_t *b, const nstime_t *a );
|
2005-08-03 20:37:28 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** calculate the sum of two times
|
2005-08-03 20:37:28 +00:00
|
|
|
*
|
|
|
|
* sum = a+b
|
|
|
|
*
|
|
|
|
* Note that it is acceptable for two or more of the arguments to point at the
|
|
|
|
* same structure.
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC void nstime_sum(nstime_t *sum, const nstime_t *b, const nstime_t *a );
|
2005-08-03 20:37:28 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** sum += a */
|
2005-08-24 21:31:56 +00:00
|
|
|
#define nstime_add(sum, a) nstime_sum(sum, sum, a)
|
2005-08-22 07:12:20 +00:00
|
|
|
|
2010-10-27 07:44:26 +00:00
|
|
|
/** sum -= a */
|
2011-08-21 18:06:42 +00:00
|
|
|
#define nstime_subtract(sum, a) nstime_delta(sum, sum, a)
|
2010-10-27 07:44:26 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** compare two times are return a value similar to memcmp() or strcmp().
|
2007-11-20 18:35:41 +00:00
|
|
|
*
|
|
|
|
* a > b : > 0
|
|
|
|
* a = b : 0
|
|
|
|
* a < b : < 0
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC int nstime_cmp (const nstime_t *a, const nstime_t *b );
|
2007-11-20 18:35:41 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** converts nstime to double, time base is milli seconds */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC double nstime_to_msec(const nstime_t *nstime);
|
2005-08-03 20:37:28 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** converts nstime to double, time base is seconds */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC double nstime_to_sec(const nstime_t *nstime);
|
2005-08-24 21:31:56 +00:00
|
|
|
|
2015-04-20 20:41:07 +00:00
|
|
|
/** converts Windows FILETIME to nstime, returns TRUE on success,
|
|
|
|
FALSE on failure */
|
|
|
|
WS_DLL_PUBLIC gboolean filetime_to_nstime(nstime_t *nstime, guint64 filetime);
|
|
|
|
|
2015-04-21 01:27:41 +00:00
|
|
|
/** converts time like Windows FILETIME, but expressed in nanoseconds
|
|
|
|
rather than tenths of microseconds, to nstime, returns TRUE on success,
|
|
|
|
FALSE on failure */
|
|
|
|
WS_DLL_PUBLIC gboolean nsfiletime_to_nstime(nstime_t *nstime, guint64 nsfiletime);
|
|
|
|
|
2012-07-27 21:43:02 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2001-09-14 07:33:04 +00:00
|
|
|
#endif /* __NSTIME_H__ */
|