svn update: 48958 (latest:48959)
[framework/uifw/ecore.git] / src / lib / ecore / ecore_time.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #ifdef HAVE_CONFIG_H
6 # include <config.h>
7 #endif
8
9 #include <stdlib.h>
10
11 #ifdef HAVE_SYS_TIME_H
12 # include <sys/time.h>
13 #endif
14
15 #ifdef HAVE_EVIL
16 # include <Evil.h>
17 #endif
18
19 #include "Ecore.h"
20 #include "ecore_private.h"
21
22
23
24 /* FIXME: clock_gettime() is an option... */
25
26 /**
27  * Retrieves the current system time as a floating point value in seconds.
28  *
29  * Also see ecore_loop_time_get().
30  *
31  * @return  The number of seconds since 12.00AM 1st January 1970.
32  * @ingroup Ecore_Time_Group
33  */
34 EAPI double
35 ecore_time_get(void)
36 {
37 #ifdef HAVE_EVIL
38   return evil_time_get();
39 #else
40 # ifdef HAVE_GETTIMEOFDAY
41    struct timeval      timev;
42
43    gettimeofday(&timev, NULL);
44    return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
45 # else
46 #  error "Your platform isn't supported yet"
47 # endif
48 #endif
49 }
50
51 double _ecore_loop_time = -1.0;
52
53 /**
54  * Retrieves the time at which the last loop stopped waiting for timeouts or events
55  *
56  * This gets the time (since Jan 1st, 1970, 12:00AM) that the main loop ceased
57  * waiting for timouts and/or events to come in or for signals or any other
58  * interrupt source. This should be considered a reference point for all
59  * time based activity that should calculate its timepoint from the return
60  * of ecore_loop_time_get(). use this UNLESS you absolutely must get the
61  * current actual timepoint - then use ecore_time_get(). If this is called
62  * before any loop has ever been run, then it will call ecore_time_get() for
63  * you the first time and thus have an initial time reference.
64  *
65  * @return  The number of seconds since 12.00AM 1st January 1970.
66  * @ingroup Ecore_Time_Group
67  */
68 EAPI double
69 ecore_loop_time_get(void)
70 {
71    return _ecore_loop_time;
72 }