ROHC compression/decompression library
rohc_time_internal.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2013,2014 Didier Barvaux
00003  * Copyright 2010,2013 Viveris Technologies
00004  * Copyright 2009,2010 Thales Communications
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 /**
00022  * @file    rohc_time_internal.h
00023  * @brief   ROHC internal functions related to time
00024  * @author  Didier Barvaux <didier.barvaux@toulouse.viveris.com>
00025  * @author  Thales Communications
00026  * @author  Didier Barvaux <didier@barvaux.org>
00027  */
00028 
00029 #ifndef ROHC_TIME_INTERNAL_H
00030 #define ROHC_TIME_INTERNAL_H
00031 
00032 #include "rohc_time.h" /* for public definition of struct rohc_ts */
00033 
00034 #ifndef __KERNEL__
00035 #       include <sys/time.h>
00036 #endif
00037 
00038 
00039 static inline uint64_t rohc_time_interval(const struct rohc_ts begin,
00040                                           const struct rohc_ts end)
00041         __attribute__((warn_unused_result, const));
00042 
00043 
00044 #if !defined(ROHC_ENABLE_DEPRECATED_API) || ROHC_ENABLE_DEPRECATED_API == 1
00045 
00046 #ifndef __KERNEL__
00047 
00048 /**
00049  * @brief Get the current time in seconds
00050  *
00051  * @return The current time in seconds
00052  */
00053 static inline uint64_t rohc_get_seconds(void)
00054 {
00055         struct timeval tv;
00056 
00057         gettimeofday(&tv, NULL);
00058 
00059         return tv.tv_sec;
00060 }
00061 
00062 #else /* __KERNEL__ */
00063 
00064 /**
00065  * @brief Get the current time in seconds
00066  *
00067  * @return The current time in seconds
00068  */
00069 static inline uint64_t rohc_get_seconds(void)
00070 {
00071         struct timespec ts;
00072 
00073         ktime_get_ts(&ts);
00074 
00075         return ts.tv_sec;
00076 }
00077 
00078 #endif /* __KERNEL__ */
00079 
00080 #endif /* !ROHC_ENABLE_DEPRECATED_API */
00081 
00082 
00083 /**
00084  * @brief Compute the interval of time between 2 timestamps
00085  *
00086  * @param begin  The begin timestamp (in seconds and nanoseconds)
00087  * @param end    The end timestamp (in seconds and nanoseconds)
00088  * @return       The interval of time in microseconds
00089  */
00090 static inline uint64_t rohc_time_interval(const struct rohc_ts begin,
00091                                           const struct rohc_ts end)
00092 {
00093         uint64_t interval;
00094 
00095         interval = end.sec - begin.sec; /* difference btw seconds */
00096         interval *= 1e9;                /* convert in nanoseconds */
00097         interval += end.nsec;           /* additional end nanoseconds */
00098         interval -= begin.nsec;         /* superfluous begin nanoseconds */
00099         interval /= 1e3;
00100 
00101         return interval;
00102 }
00103 
00104 #endif /* ROHC_TIME_INTERNAL_H */
00105