]> code.delx.au - pulseaudio/commitdiff
Move timeval calculation functions into their own file.
authorPierre Ossman <ossman@cendio.se>
Thu, 18 May 2006 06:45:43 +0000 (06:45 +0000)
committerPierre Ossman <ossman@cendio.se>
Thu, 18 May 2006 06:45:43 +0000 (06:45 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@926 fefdeb5f-60dc-0310-8127-8f9354f1896f

23 files changed:
doxygen/doxygen.conf.in
src/Makefile.am
src/modules/module-combine.c
src/modules/module-null-sink.c
src/modules/module-tunnel.c
src/modules/rtp/module-rtp-recv.c
src/modules/rtp/module-rtp-send.c
src/polyp/glib12-mainloop.c
src/polyp/mainloop.c
src/polyp/polypaudio.h
src/polyp/timeval.c [new file with mode: 0644]
src/polyp/timeval.h [new file with mode: 0644]
src/polyp/util.c
src/polyp/util.h
src/polypcore/core-scache.c
src/polypcore/core.c
src/polypcore/module.c
src/polypcore/pdispatch.c
src/polypcore/protocol-esound.c
src/polypcore/protocol-native.c
src/polypcore/socket-client.c
src/tests/mainloop-test.c
src/tests/thread-mainloop-test.c

index 3d7ad3222d1196e5df211828f7abe49187fc9808..f466c9d47e9a30930f37ce5eb74a99e0b8f125d2 100644 (file)
@@ -417,7 +417,7 @@ WARN_LOGFILE           =
 # directories like "/usr/src/myproject". Separate the files or directories 
 # with spaces.
 
-INPUT                  = ../src/polyp/context.h ../src/polyp/stream.h ../src/polyp/polypaudio.h ../src/polyp/sample.h ../src/polyp/def.h ../src/polyp/subscribe.h ../src/polyp/introspect.h ../src/polyp/scache.h ../src/polyp/mainloop-api.h ../src/polyp/glib-mainloop.h ../src/polyp/mainloop.h ../src/polyp/mainloop-signal.h ../src/polyp/error.h ../src/polyp/operation.h ../src/polyp/simple.h ../src/polyp/version.h ../src/polyp/volume.h ../src/polyp/channelmap.h ../src/polyp/thread-mainloop.h ../src/polyp/xmalloc.h ../src/polyp/utf8.h ../src/polyp/util.h
+INPUT                  = ../src/polyp/context.h ../src/polyp/stream.h ../src/polyp/polypaudio.h ../src/polyp/sample.h ../src/polyp/def.h ../src/polyp/subscribe.h ../src/polyp/introspect.h ../src/polyp/scache.h ../src/polyp/mainloop-api.h ../src/polyp/glib-mainloop.h ../src/polyp/mainloop.h ../src/polyp/mainloop-signal.h ../src/polyp/error.h ../src/polyp/operation.h ../src/polyp/simple.h ../src/polyp/version.h ../src/polyp/volume.h ../src/polyp/channelmap.h ../src/polyp/thread-mainloop.h ../src/polyp/xmalloc.h ../src/polyp/utf8.h ../src/polyp/util.h ../src/polyp/timeval.h
 
 # If the value of the INPUT tag contains directories, you can use the 
 # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 
index e7ad2fd4ac6fe462ae9cf0c5ddb037af61d44131..b0401e650619346c4c2b508acd2c77302e37fc71 100644 (file)
@@ -351,6 +351,7 @@ libpolyp_la_SOURCES = \
                polyp/stream.c polyp/stream.h \
                polyp/subscribe.c polyp/subscribe.h \
                polyp/sample.c polyp/sample.h \
+               polyp/timeval.c polyp/timeval.h \
                polyp/volume.c polyp/volume.h \
                polyp/utf8.c polyp/utf8.h \
                polyp/mainloop.c polyp/mainloop.h \
@@ -493,9 +494,10 @@ libpolypcore_la_SOURCES = \
                polyp/mainloop-signal.c polyp/mainloop-signal.h \
                polyp/sample.c polyp/sample.h \
                polyp/volume.c polyp/volume.h \
+               polyp/timeval.c polyp/timeval.h \
                polyp/utf8.c polyp/utf8.h \
-               polyp/xmalloc.c polyp/xmalloc.h \
-               polyp/util.c polyp/util.h
+               polyp/util.c polyp/util.h \
+               polyp/xmalloc.c polyp/xmalloc.h
 
 # Pure core stuff (some are shared in libpolyp though).
 libpolypcore_la_SOURCES += \
index 5047fc306b55bad531b9e049cdc28afbe78f45e2..037cbaf719da49399c882172cb3e639295b5df73 100644 (file)
@@ -26,6 +26,7 @@
 #include <assert.h>
 #include <stdio.h>
 
+#include <polyp/timeval.h>
 #include <polyp/xmalloc.h>
 
 #include <polypcore/module.h>
index 78850011c4100829e4bd8f0687f6aa23c82a9328..a1555e672497becbeb7ef96a1f012f5ce12d7f1b 100644 (file)
@@ -33,6 +33,7 @@
 #include <unistd.h>
 #include <limits.h>
 
+#include <polyp/timeval.h>
 #include <polyp/xmalloc.h>
 
 #include <polypcore/iochannel.h>
index 81c322879d3be24e0ff80568a93691b6c8f912db..758d1bd6e8aca1671e0d1d589743a6e881feb6f6 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <polyp/timeval.h>
 #include <polyp/version.h>
 #include <polyp/xmalloc.h>
 
index a1196a2d32b758ef7d50229afbeba07fdbc56635..56fc91ef1f328811423d4bc2f8248f76bed23086 100644 (file)
@@ -31,6 +31,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include <polyp/timeval.h>
 #include <polyp/xmalloc.h>
 
 #include <polypcore/module.h>
index a88ea76af14387b7035571c7fd5fc95d35f003bf..4ca2b1e62343cb4db23234a2263f2d996f83c946 100644 (file)
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include <polyp/timeval.h>
 #include <polyp/xmalloc.h>
 
 #include <polypcore/module.h>
index f7459f192d0dedc6a9fe8e01204b737fb6663035..dfd6ff2f11165dddf26a13e2214a2f3084d22653 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <assert.h>
 
+#include <polyp/timeval.h>
 #include <polyp/xmalloc.h>
 
 #include <polypcore/idxset.h>
index 8f44c180c0ec141ac5b3c5788ee62fa66e3d49d8..6b5b3b252bf8e653f197dccc9120c33d0b690eb1 100644 (file)
@@ -44,6 +44,7 @@
 #include "../polypcore/pipe.h"
 #endif
 
+#include <polyp/timeval.h>
 #include <polyp/xmalloc.h>
 
 #include <polypcore/core-util.h>
index 51e3f97034364431c991737531f681df8e466163..c172315b2812830083966858f16882d598608bc8 100644 (file)
@@ -41,6 +41,7 @@
 #include <polyp/mainloop.h>
 #include <polyp/mainloop-signal.h>
 #include <polyp/util.h>
+#include <polyp/timeval.h>
 
 /** \file
  * Include all polyplib header files at once. The following
@@ -48,7 +49,8 @@
  * \ref context.h, \ref stream.h, \ref introspect.h, \ref subscribe.h,
  * \ref scache.h, \ref version.h, \ref error.h, \ref channelmap.h,
  * \ref operation.h,\ref volume.h, \ref xmalloc.h, \ref utf8.h, \ref
- * thread-mainloop.h, \ref mainloop.h, \ref util.h and \ref mainloop-signal.h at once */
+ * thread-mainloop.h, \ref mainloop.h, \ref util.h, \ref timeval.h and
+ * \ref mainloop-signal.h at once */
 
 /** \mainpage
  *
diff --git a/src/polyp/timeval.c b/src/polyp/timeval.c
new file mode 100644 (file)
index 0000000..6043d7f
--- /dev/null
@@ -0,0 +1,142 @@
+/* $Id$ */
+
+/***
+  This file is part of polypaudio.
+  polypaudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as
+  published by the Free Software Foundation; either version 2.1 of the
+  License, or (at your option) any later version.
+  polypaudio 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
+  Lesser General Public License for more details.
+  You should have received a copy of the GNU Lesser General Public
+  License along with polypaudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <stddef.h>
+#include <sys/time.h>
+
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
+
+#include "../polypcore/winsock.h"
+
+#include "timeval.h"
+
+struct timeval *pa_gettimeofday(struct timeval *tv) {
+#ifdef HAVE_GETTIMEOFDAY
+    assert(tv);
+    
+    return gettimeofday(tv, NULL) < 0 ? NULL : tv;
+#elif defined(OS_IS_WIN32)
+    /*
+     * Copied from implementation by Steven Edwards (LGPL).
+     * Found on wine mailing list.
+     */
+
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+#define EPOCHFILETIME (116444736000000000i64)
+#else
+#define EPOCHFILETIME (116444736000000000LL)
+#endif
+
+    FILETIME        ft;
+    LARGE_INTEGER   li;
+    __int64         t;
+
+    assert(tv);
+
+    GetSystemTimeAsFileTime(&ft);
+    li.LowPart  = ft.dwLowDateTime;
+    li.HighPart = ft.dwHighDateTime;
+    t  = li.QuadPart;       /* In 100-nanosecond intervals */
+    t -= EPOCHFILETIME;     /* Offset to the Epoch time */
+    t /= 10;                /* In microseconds */
+    tv->tv_sec  = (long)(t / 1000000);
+    tv->tv_usec = (long)(t % 1000000);
+
+    return tv;
+#else
+#error "Platform lacks gettimeofday() or equivalent function."
+#endif
+}
+
+pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
+    pa_usec_t r;
+    assert(a && b);
+
+    /* Check which whan is the earlier time and swap the two arguments if reuqired. */
+    if (pa_timeval_cmp(a, b) < 0) {
+        const struct timeval *c;
+        c = a;
+        a = b;
+        b = c;
+    }
+
+    /* Calculate the second difference*/
+    r = ((pa_usec_t) a->tv_sec - b->tv_sec)* 1000000;
+
+    /* Calculate the microsecond difference */
+    if (a->tv_usec > b->tv_usec)
+        r += ((pa_usec_t) a->tv_usec - b->tv_usec);
+    else if (a->tv_usec < b->tv_usec)
+        r -= ((pa_usec_t) b->tv_usec - a->tv_usec);
+
+    return r;
+}
+
+int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) {
+    assert(a && b);
+
+    if (a->tv_sec < b->tv_sec)
+        return -1;
+
+    if (a->tv_sec > b->tv_sec)
+        return 1;
+
+    if (a->tv_usec < b->tv_usec)
+        return -1;
+
+    if (a->tv_usec > b->tv_usec)
+        return 1;
+
+    return 0;
+}
+
+pa_usec_t pa_timeval_age(const struct timeval *tv) {
+    struct timeval now;
+    assert(tv);
+    
+    return pa_timeval_diff(pa_gettimeofday(&now), tv);
+}
+
+struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) {
+    unsigned long secs;
+    assert(tv);
+    
+    secs = (v/1000000);
+    tv->tv_sec += (unsigned long) secs;
+    v -= secs*1000000;
+
+    tv->tv_usec += v;
+
+    /* Normalize */
+    while (tv->tv_usec >= 1000000) {
+        tv->tv_sec++;
+        tv->tv_usec -= 1000000;
+    }
+
+    return tv;
+}
diff --git a/src/polyp/timeval.h b/src/polyp/timeval.h
new file mode 100644 (file)
index 0000000..9990d4c
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef footimevalhfoo
+#define footimevalhfoo
+
+/* $Id$ */
+
+/***
+  This file is part of polypaudio.
+  polypaudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as
+  published by the Free Software Foundation; either version 2.1 of the
+  License, or (at your option) any later version.
+  polypaudio 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
+  Lesser General Public License for more details.
+  You should have received a copy of the GNU Lesser General Public
+  License along with polypaudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#include <polyp/cdecl.h>
+#include <polyp/sample.h>
+
+/** \file
+ * Utility functions for handling timeval calculations */
+
+PA_C_DECL_BEGIN
+
+struct timeval;
+
+/** Return the current timestamp, just like UNIX gettimeofday() */
+struct timeval *pa_gettimeofday(struct timeval *tv);
+
+/** Calculate the difference between the two specified timeval
+ * structs. */
+pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b);
+
+/** Compare the two timeval structs and return 0 when equal, negative when a < b, positive otherwse */
+int pa_timeval_cmp(const struct timeval *a, const struct timeval *b);
+
+/** Return the time difference between now and the specified timestamp */
+pa_usec_t pa_timeval_age(const struct timeval *tv);
+
+/** Add the specified time inmicroseconds to the specified timeval structure */
+struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v);
+
+PA_C_DECL_END
+
+#endif
index 76b5c9b973b4873579ac3b29c8914e58a366190a..dcebff595b629d8e7d007d46e40a52c6d275b6a5 100644 (file)
 #include <config.h>
 #endif
 
-#include <stdarg.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <errno.h>
 #include <assert.h>
-#include <string.h>
+#include <errno.h>
 #include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
 #include <time.h>
-#include <ctype.h>
+#include <unistd.h>
 #include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
 
 #ifdef HAVE_PWD_H
 #include <pwd.h>
 #endif
 
-#ifdef HAVE_GRP_H
-#include <grp.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
 #endif
 
 #ifdef HAVE_WINDOWS_H
 #include <windows.h>
 #endif
 
-#include <polyp/xmalloc.h>
+#include "../polypcore/winsock.h"
+
 #include <polypcore/log.h>
 #include <polypcore/core-util.h>
 
@@ -154,112 +148,6 @@ char *pa_get_home_dir(char *s, size_t l) {
 #endif
 }
 
-struct timeval *pa_gettimeofday(struct timeval *tv) {
-#ifdef HAVE_GETTIMEOFDAY
-    assert(tv);
-    
-    return gettimeofday(tv, NULL) < 0 ? NULL : tv;
-#elif defined(OS_IS_WIN32)
-    /*
-     * Copied from implementation by Steven Edwards (LGPL).
-     * Found on wine mailing list.
-     */
-
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-#define EPOCHFILETIME (116444736000000000i64)
-#else
-#define EPOCHFILETIME (116444736000000000LL)
-#endif
-
-    FILETIME        ft;
-    LARGE_INTEGER   li;
-    __int64         t;
-
-    assert(tv);
-
-    GetSystemTimeAsFileTime(&ft);
-    li.LowPart  = ft.dwLowDateTime;
-    li.HighPart = ft.dwHighDateTime;
-    t  = li.QuadPart;       /* In 100-nanosecond intervals */
-    t -= EPOCHFILETIME;     /* Offset to the Epoch time */
-    t /= 10;                /* In microseconds */
-    tv->tv_sec  = (long)(t / 1000000);
-    tv->tv_usec = (long)(t % 1000000);
-
-    return tv;
-#else
-#error "Platform lacks gettimeofday() or equivalent function."
-#endif
-}
-
-pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
-    pa_usec_t r;
-    assert(a && b);
-
-    /* Check which whan is the earlier time and swap the two arguments if reuqired. */
-    if (pa_timeval_cmp(a, b) < 0) {
-        const struct timeval *c;
-        c = a;
-        a = b;
-        b = c;
-    }
-
-    /* Calculate the second difference*/
-    r = ((pa_usec_t) a->tv_sec - b->tv_sec)* 1000000;
-
-    /* Calculate the microsecond difference */
-    if (a->tv_usec > b->tv_usec)
-        r += ((pa_usec_t) a->tv_usec - b->tv_usec);
-    else if (a->tv_usec < b->tv_usec)
-        r -= ((pa_usec_t) b->tv_usec - a->tv_usec);
-
-    return r;
-}
-
-int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) {
-    assert(a && b);
-
-    if (a->tv_sec < b->tv_sec)
-        return -1;
-
-    if (a->tv_sec > b->tv_sec)
-        return 1;
-
-    if (a->tv_usec < b->tv_usec)
-        return -1;
-
-    if (a->tv_usec > b->tv_usec)
-        return 1;
-
-    return 0;
-}
-
-pa_usec_t pa_timeval_age(const struct timeval *tv) {
-    struct timeval now;
-    assert(tv);
-    
-    return pa_timeval_diff(pa_gettimeofday(&now), tv);
-}
-
-struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) {
-    unsigned long secs;
-    assert(tv);
-    
-    secs = (v/1000000);
-    tv->tv_sec += (unsigned long) secs;
-    v -= secs*1000000;
-
-    tv->tv_usec += v;
-
-    /* Normalize */
-    while (tv->tv_usec >= 1000000) {
-        tv->tv_sec++;
-        tv->tv_usec -= 1000000;
-    }
-
-    return tv;
-}
-
 char *pa_get_binary_name(char *s, size_t l) {
 
 #ifdef HAVE_READLINK
index 8bd03f98a563516d41edcdca2e8e4fe26987d5ea..cd8aab0bd8d30d4e5cbd46be809d3cd4fa614f00 100644 (file)
   USA.
 ***/
 
-#include <sys/types.h>
-#include <inttypes.h>
+#include <stddef.h>
 
-#include <polyp/sample.h>
 #include <polyp/cdecl.h>
 
 /** \file
@@ -33,8 +31,6 @@
 
 PA_C_DECL_BEGIN
 
-struct timeval;
-
 /** Return the current username in the specified string buffer. */
 char *pa_get_user_name(char *s, size_t l);
 
@@ -55,22 +51,6 @@ char *pa_get_binary_name(char *s, size_t l);
  * component). */
 const char *pa_path_get_filename(const char *p);
 
-/** Return the current timestamp, just like UNIX gettimeofday() */
-struct timeval *pa_gettimeofday(struct timeval *tv);
-
-/** Calculate the difference between the two specified timeval
- * structs. */
-pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b);
-
-/** Compare the two timeval structs and return 0 when equal, negative when a < b, positive otherwse */
-int pa_timeval_cmp(const struct timeval *a, const struct timeval *b);
-
-/** Return the time difference between now and the specified timestamp */
-pa_usec_t pa_timeval_age(const struct timeval *tv);
-
-/** Add the specified time inmicroseconds to the specified timeval structure */
-struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v);
-
 /** Wait t milliseconds */
 int pa_msleep(unsigned long t);
 
index 068f2361d97839bdfe8ad5f392b8f7caf930f12c..1ee3361f827044f6e506ab38aa37447ffd5af6af 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <polyp/mainloop.h>
 #include <polyp/channelmap.h>
+#include <polyp/timeval.h>
 #include <polyp/volume.h>
 #include <polyp/xmalloc.h>
 
index 43f7015e0567ceae843dbfc6369fecb1f711042b..09d023dce16f769dc8231c7fb5cea606d633a756 100644 (file)
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <signal.h>
 
+#include <polyp/timeval.h>
 #include <polyp/xmalloc.h>
 
 #include <polypcore/module.h>
index 52cde9c3907d67969fa84f58cb4cf5a6e4de55e6..0286bba85cb8d3e893bad69cc0f6786e4a5a0803 100644 (file)
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <errno.h>
 
+#include <polyp/timeval.h>
 #include <polyp/xmalloc.h>
 
 #include <polypcore/core-subscribe.h>
index 4b0d1bb27eb37236811732695bc8228a3fe170a9..c6f90bac47ad3c2dbfdea6607a7c6f8863f959f5 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <assert.h>
 
+#include <polyp/timeval.h>
 #include <polyp/xmalloc.h>
 
 #include <polypcore/native-common.h>
index 98738728a0954654d699079bdca1755cb6ae7ee3..c11bdb21cdf694a18edc1f208e27123f63ff6b81 100644 (file)
@@ -31,6 +31,7 @@
 #include <limits.h>
 
 #include <polyp/sample.h>
+#include <polyp/timeval.h>
 #include <polyp/utf8.h>
 #include <polyp/xmalloc.h>
 
index f0e50ec540f12fdaab9d84b0278cf24ff48e9bb4..0a408c6d6e7dba804c0f9137f7f3b8d0f9747d47 100644 (file)
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include <polyp/timeval.h>
 #include <polyp/version.h>
 #include <polyp/utf8.h>
 #include <polyp/xmalloc.h>
index 4fb0a5d89919185da33d75f92078b4b895662cff..ec2f9a9e3b8cd6864c2654893d4f6f82d34d9efc 100644 (file)
@@ -54,6 +54,7 @@
 
 #include "winsock.h"
 
+#include <polyp/timeval.h>
 #include <polyp/xmalloc.h>
 
 #include <polypcore/socket-util.h>
index 300884839424f4b1271f8bc6965b2a3a9a3d3efb..2936420c36c199f822bedcfb7b966fd9692e2cb0 100644 (file)
@@ -28,6 +28,8 @@
 #include <sys/time.h>
 #include <assert.h>
 
+#include <polyp/timeval.h>
+
 #include <polypcore/core-util.h>
 #include <polypcore/gccmacro.h>
 
index 676b8d37e1f769e3dc1cd3d416bd993977255ece..701444312c9d4acb72f7412cb62867da52ba8dd5 100644 (file)
@@ -28,6 +28,8 @@
 #include <unistd.h>
 #include <stdio.h>
 
+#include <polyp/timeval.h>
+
 #include <polypcore/gccmacro.h>
 #include <polypcore/core-util.h>
 #include <polyp/thread-mainloop.h>