This example shows the difference between calling ecore_time_get(), ecore_loop_time_get() and ecore_time_unix_get().
It initializes ecore, then sets a timer with a callback that, when called, will retrieve the system time using these 3 different functions. After displaying the time, it sleeps for 1 second, then call display the time again using the 3 functions.
Since everything occurs inside the same main loop iteration, the internal ecore time variable will not be updated, and calling ecore_loop_time_get() before and after the sleep() call will return the same result.
The two other functions will return a difference of 1 second, as expected. But ecore_time_unix_get() returns the number of seconds since 00:00:00 1st January 1970, while ecore_time_get() will return the time since a unspecified point, but that never goes back in time, even when the timezone of the machine changes.
- Note
- The usage of ecore_loop_time_get() should be preferred against the two other functions, for most time calculations, since it won't produce a system call to get the current time. Use ecore_time_unix_get() when you need to know the current time and date, and ecore_time_get() when you need a monotonic and more precise time than ecore_loop_time_get().
#include <Ecore.h>
#include <unistd.h>
{
printf("\nSleep for 1 second...\n\n");
sleep(1);
}
int
main(void)
{
{
printf("ERROR: Cannot init Ecore!\n");
return -1;
}
}
EAPI int ecore_shutdown(void)
Shuts down connections, signal handlers sockets etc.
Definition: ecore.c:371
EAPI int ecore_init(void)
Sets up connections, signal handlers, sockets etc.
Definition: ecore.c:230
void ecore_main_loop_quit(void)
Quits the main loop once all the events currently on the queue have been processed.
Definition: ecore_main.c:1321
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1311
double ecore_time_unix_get(void)
Retrieves the current UNIX time as a floating point value in seconds.
Definition: ecore_time.c:61
double ecore_time_get(void)
Retrieves the current system time as a floating point value in seconds.
Definition: ecore_time.c:33
double ecore_loop_time_get(void)
Retrieves the time at which the last loop stopped waiting for timeouts or events.
Definition: ecore_time.c:74
Ecore_Timer * ecore_timer_add(double in, Ecore_Task_Cb func, const void *data)
Creates a timer to call the given function in the given period of time.
Definition: ecore_timer.c:189
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition: eina_types.h:533
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:527
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339