1 /*
 2  * Timestampc.h
 3  */
 4 #ifndef XMLBLASTER_UTIL_TIMESTAMPC_H_
 5 #define XMLBLASTER_UTIL_TIMESTAMPC_H_
 6 
 7 #include <util/basicDefs.h> /* for int64_t (C99), Dll_Export, inline, bool etc. */
 8 
 9 #if defined(_WINDOWS)
10 #  if defined(XB_USE_PTHREADS)
11 #     include <pthreads/pthread.h> /* Our pthreads.h: For timespec, for logging output of thread ID, for Windows and WinCE downloaded from http://sources.redhat.com/pthreads-win32 */
12 #  else
13 #  endif
14 #else
15 # include <pthread.h>
16 # define XB_USE_PTHREADS 1
17 #endif
18 
19 #ifdef __cplusplus
20 #ifndef XMLBLASTER_C_COMPILE_AS_CPP /* 'g++ -DXMLBLASTER_C_COMPILE_AS_CPP ...' allows to compile the lib as C++ code */
21 extern "C" {
22 #endif
23 #endif
24 
25 /**
26  * Unique for each call.
27  * <p>
28  * Is thread safe
29  * @return unique for each call, with nano counter
30  */
31 Dll_Export extern int64_t getTimestamp(void);   /* if no 'int64_t=long long' support we need a workaround */
32 
33 /**
34  * Unique for each call.
35  * <p>
36  * Is thread safe
37  * @param buf Used to write the timestamp into
38  * @param buflen The size of above
39  * @return buf
40  */
41 Dll_Export char *getTimestampStr(char *buf, size_t buflen);
42 
43 /**
44  * Fills the given abstime with absolute time, using the given timeout relativeTimeFromNow in milliseconds
45  * On Linux < 2.5.64 does not support high resolution timers clock_gettime(),
46  * but patches are available at http://sourceforge.net/projects/high-res-timers
47  * @param relativeTimeFromNow the relative time from now in milliseconds
48  * @param abstime
49  * @return true If implemented
50  */
51 Dll_Export extern bool getAbsoluteTime(long relativeTimeFromNow, struct timespec *abstime); /* timespec forces pthread */
52 /**
53  * Get a human readable time string for logging.
54  * @param timeStr out parameter, e.g. "12:34:46" or "2006-11-14 12:34:46"
55  * @param bufSize The size of timeStr
56  * @return timeStr Your parameter given (for easy usage in printf())
57  */
58 Dll_Export extern const char *getCurrentTimeStr(char *timeStr, int bufSize);
59 /**
60  * Get current timestamp string in ISO 8601 notation.
61  * @param bufSize at least 26
62  * @param timeStr out parameter, filled with e.g. "1997-07-16T19:20:30.45-02:00"
63  * @return Your param timeStr for easy usage in printf() and such
64  * @see http://en.wikipedia.org/wiki/ISO_8601
65  */
66 Dll_Export extern const char *getCurrentLocalIsoTimestampStr(char *timeStr, int bufSize);
67 
68 
69 #ifdef __cplusplus
70 #ifndef XMLBLASTER_C_COMPILE_AS_CPP
71 }
72 #endif
73 #endif
74 
75 
76 #endif /* XMLBLASTER_UTIL_TIMESTAMPC_H_ */


syntax highlighted by Code2HTML, v. 0.9.1