2001-09-14 07:33:04 +00:00
|
|
|
/* nstime.h
|
|
|
|
* Definition of data structure to hold time values with nanosecond resolution
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2001-09-14 07:33:04 +00:00
|
|
|
*
|
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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __NSTIME_H__
|
|
|
|
#define __NSTIME_H__
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
2007-04-03 21:17:13 +00:00
|
|
|
#include <wiretap/wtap.h>
|
|
|
|
|
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*/
|
2001-09-14 07:33:04 +00:00
|
|
|
typedef struct {
|
|
|
|
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 */
|
2005-08-24 21:31:56 +00:00
|
|
|
extern void nstime_set_zero(nstime_t *nstime);
|
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** is the given nstime_t currently zero? */
|
2005-08-24 21:31:56 +00:00
|
|
|
extern gboolean nstime_is_zero(nstime_t *nstime);
|
|
|
|
|
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)
|
|
|
|
*/
|
|
|
|
extern void nstime_set_unset(nstime_t *nstime);
|
|
|
|
|
|
|
|
/* is the given nstime_t currently (0,maxint)? */
|
|
|
|
extern gboolean nstime_is_unset(nstime_t *nstime);
|
|
|
|
|
2011-08-13 17:39:25 +00:00
|
|
|
/** duplicate the current time
|
|
|
|
*
|
|
|
|
* a = b
|
|
|
|
*/
|
|
|
|
extern void nstime_copy(nstime_t *a, const nstime_t *b);
|
|
|
|
|
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.
|
|
|
|
*/
|
2005-08-24 21:31:56 +00:00
|
|
|
extern 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.
|
|
|
|
*/
|
2005-08-24 21:31:56 +00:00
|
|
|
extern 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
|
|
|
|
*/
|
2009-09-07 18:53:17 +00:00
|
|
|
extern 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 */
|
2008-06-23 20:04:31 +00:00
|
|
|
extern 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 */
|
2008-06-23 20:04:31 +00:00
|
|
|
extern double nstime_to_sec(const nstime_t *nstime);
|
2005-08-24 21:31:56 +00:00
|
|
|
|
2010-08-29 10:47:38 +00:00
|
|
|
/** converts wtap_nstime to double, time base is seconds */
|
2008-06-23 20:04:31 +00:00
|
|
|
extern double wtap_nstime_to_sec(const struct wtap_nstime *nstime);
|
2007-04-03 21:17:13 +00:00
|
|
|
|
2001-09-14 07:33:04 +00:00
|
|
|
#endif /* __NSTIME_H__ */
|