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