3 * Copyright 2007,2008 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #ifndef INCLUDED_OMNI_TIME_H
22 #define INCLUDED_OMNI_TIME_H
25 long int d_secs; // seconds.
26 long int d_nsecs; // nanoseconds. Always in [0, 1e9-1]
28 omni_time() : d_secs(0), d_nsecs(0) {}
29 omni_time(long secs, long nanosecs=0) : d_secs(secs), d_nsecs(nanosecs) {}
31 // N.B., this only makes sense for differences between times.
32 // Double doesn't have enough bits to precisely represent an absolute time.
33 omni_time(double secs);
35 // N.B. This only makes sense for differences between times.
36 // Double doesn't have enough bits to precisely represent an absolute time.
37 double double_time() const { return (double)d_secs + d_nsecs * 1e-9; }
40 * \brief Return an absolute time suitable for use with
41 * schedule_one_shot_timeout & schedule_periodic_timeout
43 * The return value is the current time plus the given relative offset.
45 static omni_time time(const omni_time &relative_offset = omni_time());
50 operator<(const omni_time &x, const omni_time &y)
52 return ((x.d_secs < y.d_secs)
53 || (x.d_secs == y.d_secs && x.d_nsecs < y.d_nsecs));
57 operator>(const omni_time &x, const omni_time &y)
59 return ((x.d_secs > y.d_secs)
60 || (x.d_secs == y.d_secs && x.d_nsecs > y.d_nsecs));
64 operator>=(const omni_time &x, const omni_time &y)
66 return ((x.d_secs > y.d_secs)
67 || (x.d_secs == y.d_secs && x.d_nsecs >= y.d_nsecs));
71 operator<=(const omni_time &x, const omni_time &y)
73 return ((x.d_secs < y.d_secs)
74 || (x.d_secs == y.d_secs && x.d_nsecs <= y.d_nsecs));
78 operator==(const omni_time &x, const omni_time &y)
80 return (x.d_secs == y.d_secs && x.d_nsecs == y.d_nsecs);
84 omni_time operator+(const omni_time &x, const omni_time &y);
85 omni_time operator+(const omni_time &x, double y);
86 omni_time operator-(const omni_time &x, const omni_time &y);
87 omni_time operator-(const omni_time &x, double y);
89 #endif /* INCLUDED_OMNI_TIME_H */