Beispiel #1
0
/**
 * Retrieves the current system time as a floating point value in seconds.
 *
 * This uses a monotonic clock and thus never goes back in time while
 * machine is live (even if user changes time or timezone changes,
 * however it may be reset whenever the machine is restarted).
 *
 * @see ecore_loop_time_get().
 * @see ecore_time_unix_get().
 *
 * @return The number of seconds. Start time is not defined (it may be
 *         when the machine was booted, unix time, etc), all it is
 *         defined is that it never goes backwards (unless you got big critical
 *         messages when the application started).
 */
EAPI double
ecore_time_get(void)
{
#if defined (HAVE_CLOCK_GETTIME) || defined (EXOTIC_PROVIDE_CLOCK_GETTIME) 
   struct timespec t;

   if (EINA_UNLIKELY(_ecore_time_clock_id < 0))
     return ecore_time_unix_get();

   if (EINA_UNLIKELY(clock_gettime(_ecore_time_clock_id, &t)))
     {
        CRI("Cannot get current time.");
        /* Try to at least return the latest value retrieved*/
        return _ecore_time_loop_time;
     }

   return (double)t.tv_sec + (((double)t.tv_nsec) / 1000000000.0);
#elif defined(HAVE_EVIL)
   return evil_time_get();
#elif defined(__APPLE__) && defined(__MACH__)
   return _ecore_time_clock_conversion * (double)mach_absolute_time();
#else
   return ecore_time_unix_get();
#endif
}
Beispiel #2
0
/**
 * Retrieves the current system time as a floating point value in seconds.
 *
 * This uses a monotonic clock and thus never goes back in time while
 * machine is live (even if user changes time or timezone changes,
 * however it may be reset whenever the machine is restarted).
 *
 * @see ecore_loop_time_get().
 * @see ecore_time_unix_get().
 *
 * @return The number of seconds. Start time is not defined (it may be
 *         when the machine was booted, unix time, etc), all it is
 *         defined is that it never goes backwards (unless you got big critical
 *         messages when the application started).
 */
EAPI double
ecore_time_get(void)
{
#ifdef HAVE_CLOCK_GETTIME
   struct timespec t;

   if (EINA_UNLIKELY(_ecore_time_clock_id < 0))
      return ecore_time_unix_get();

   if (EINA_UNLIKELY(clock_gettime(_ecore_time_clock_id, &t)))
     {
        CRIT("Cannot get current time.");
        /* Try to at least return the latest value retrieved*/
        return _ecore_time_loop_time;
     }

   return (double)t.tv_sec + (((double)t.tv_nsec) / 1000000000.0);
#else
# ifdef HAVE_EVIL
   return evil_time_get();
# else
   return ecore_time_unix_get();
# endif
#endif
}
static Eina_Bool
_cb_alarms_ring_etimer(void *data)
{
   Eina_List *l;
   double now;

   if (alarm_config->alarms_state == ALARM_STATE_OFF)
     {
        alarm_config->alarms_ring_etimer = NULL;
        return EINA_FALSE;
     }

   now = ecore_time_unix_get();

   for(l=alarm_config->alarms; l; l=eina_list_next(l))
     {
        Alarm *al;

        al = eina_list_data_get(l);
        if (al->state != ALARM_STATE_ON)
          continue;

        if (al->sched.date_epoch <= now)
          alarm_alarm_ring(al, 0);
     }

   return EINA_TRUE;
}
Beispiel #4
0
static Eina_Bool storage_item_write(AppData *ad, CNP_ITEM *item)
{
	CALLED();
	StorageData *sd = ad->storage;
	int index = getMinIndex(sd->indexTable, STORAGE_ITEM_CNT);
	sd->indexTable[index] = ecore_time_unix_get();
	sd->itemTable[index] = item;

	item_write(sd->ef, index, item);
	storage_index_write(sd);
	dump_items(sd);
	return EINA_TRUE;
}
static char *
_item_label_get(void *data, Evas_Object *obj, const char *part)
{
    time_t t = (time_t)ecore_time_unix_get();
    char buf[256];
    int i = (int)(long)data;
    if (i % 2)
    {
        int n;
        snprintf(buf, sizeof(buf), "Very Long Item # %i - realized at %s", i, ctime(&t));
        n = strlen(buf);
        buf[n - 1] = '\0';
    }
    else
        snprintf(buf, sizeof(buf), "short item # %i", i);
    return strdup(buf);
}
static char *
_item_label_get(void *data, Evas_Object *obj, const char *part)
{
    time_t t = (time_t)ecore_time_unix_get();
    char buf[256];
    int i = (int)(long)data;

    if (!strcmp(part, "elm.text"))
        snprintf(buf, sizeof(buf), "Item # %i", i);
    else
    {
        int n;
        snprintf(buf, sizeof(buf), "created at %s", ctime(&t));
        n = strlen(buf);
        buf[n - 1] = '\0';
    }

    return strdup(buf);
}
Beispiel #7
0
static char *
_item_label_get(void *data, Evas_Object *obj, const char *part)
{
   time_t t = (time_t)ecore_time_unix_get();
   char buf[256];
   int i = (int)(long)data;
   struct tm timeinfo;
   localtime_r(&t, &timeinfo);

   if (!strcmp(part, "elm.text"))
     g_snprintf(buf, sizeof(buf), "Item # %i", i);
   else
     {
        int n;
        strftime(buf, sizeof(buf), "realized at %c", &timeinfo);
        n = strlen(buf);
        buf[n - 1] = '\0';
     }

   return strdup(buf);
}
double currentTime()
{
    return ecore_time_unix_get();
}
static int
_alarm_check_date(Alarm *al, int strict)
{
   switch(al->sched.type)
     {
     case ALARM_SCHED_DAY:
        if (al->sched.date_epoch <= ecore_time_unix_get())
          {
             printf("check_date : before ! state %d\n", al->state);
             if (strict)
               return 0;
             else
               {
                  if (al->autoremove)
                    alarm_alarm_del(al);
                  else
                    {
                       printf("state : %d\n", al->state);
                       /*
                         if (al->state == ALARM_STATE_RINGING)
                         alarm_alarm_ring_stop(al, 0);
                       */
                       if (al->state == ALARM_STATE_ON)
                         al->state = ALARM_STATE_OFF;
                    }
               }
          }
        else
          {
             printf("check_date : after (%f < %f) ! state %d\n", al->sched.date_epoch, ecore_time_unix_get(), al->state);
             /*
               if (al->state == ALARM_STATE_RINGING)
               alarm_alarm_ring_stop(al, 0);
             */
          }
        break;

     case ALARM_SCHED_WEEK:
        if ((al->sched.day_monday || 
             al->sched.day_tuesday || 
             al->sched.day_wenesday || 
             al->sched.day_thursday || 
             al->sched.day_friday || 
             al->sched.day_saturday || 
             al->sched.day_sunday) == 0)
          return 0;

        if (al->sched.date_epoch <= ecore_time_unix_get())
          {
             al->sched.date_epoch =
                _epoch_find_next(al->sched.day_monday,
                                 al->sched.day_tuesday,
                                 al->sched.day_wenesday,
                                 al->sched.day_thursday,
                                 al->sched.day_friday,
                                 al->sched.day_saturday,
                                 al->sched.day_sunday,
                                 al->sched.hour,
                                 al->sched.minute);
          }
        break;
     }

   if (alarm_config->config_dialog)
     alarm_config_refresh_alarms_ilist(alarm_config->config_dialog->cfdata);

   return 1;
}
Alarm *
alarm_alarm_add(int state, char *name, int type,
                char *date, int day_monday, int day_tuesday, int day_wenesday, int day_thursday, int day_friday, int day_saturday, int day_sunday,
                int hour, int minute,
                int autoremove, char *description,
                int open_popup, int run_program, char *program,
                int *error)
{
   Alarm *al = NULL;

   if (!name)
     {
        ALARM_ADD_FAIL(ALARM_ADD_ERROR_NAME);
     }
   if (!strlen(name))
     {
        ALARM_ADD_FAIL(ALARM_ADD_ERROR_NAME);
     }

   al = E_NEW(Alarm, 1);

   if (state)
     al->state = ALARM_STATE_ON;
   else
     al->state = ALARM_STATE_OFF;
   al->name = eina_stringshare_add(name);
   al->sched.type = type;
   switch(type)
     {
     case ALARM_SCHED_DAY:
        if ( !(al->sched.date_epoch = _epoch_find_date(date, hour, minute)) )
          {
             ALARM_ADD_FAIL(ALARM_ADD_ERROR_SCHED_DAY);
          }
        if (al->sched.date_epoch <= ecore_time_unix_get())
          {
             ALARM_ADD_FAIL(ALARM_ADD_ERROR_SCHED_BEFORE);
          }
        break;

     case ALARM_SCHED_WEEK:
        al->sched.day_monday = day_monday;
        al->sched.day_tuesday = day_tuesday;
        al->sched.day_wenesday = day_wenesday;
        al->sched.day_thursday = day_thursday;
        al->sched.day_friday = day_friday;
        al->sched.day_saturday = day_saturday;
        al->sched.day_sunday = day_sunday;
        if ( !(al->sched.date_epoch = _epoch_find_next(day_monday,
                                                       day_tuesday,
                                                       day_wenesday,
                                                       day_thursday,
                                                       day_friday,
                                                       day_saturday,
                                                       day_sunday,
                                                       hour, minute)) )
          {
             ALARM_ADD_FAIL(ALARM_ADD_ERROR_SCHED_WEEK);
          }
        break;

     default:
        ALARM_ADD_FAIL(ALARM_ADD_ERROR_UNKNOWN);
     }

   al->sched.hour = hour;
   al->sched.minute = minute;
   al->snooze.minute = ALARM_SNOOZE_MINUTE_DEFAULT;
   al->snooze.hour = ALARM_SNOOZE_HOUR_DEFAULT;
   al->autoremove = autoremove;
   if (description)
     al->description = eina_stringshare_add(description);
   al->open_popup = open_popup;
   al->run_program = run_program;
   if (program)
     if (strlen(program))
       al->program = eina_stringshare_add(program);

   if (!_alarm_check_date(al, 1))
     {
        ALARM_ADD_FAIL(ALARM_ADD_ERROR_UNKNOWN);
     }
   
   if (!alarm_config->alarms_ring_etimer)
     alarm_config->alarms_ring_etimer = ecore_timer_add(ALARMS_CHECK_TIMER,
                                                        _cb_alarms_ring_etimer,
                                                        NULL);

   return al;
}
Beispiel #11
0
                   void (*shutdown_func) (void),
                   void (*logout_func) (void),
                   void (*resume_func) (void))
{
   _e_sys_suspend_func = suspend_func;
   _e_sys_hibernate_func = hibernate_func;
   _e_sys_reboot_func = reboot_func;
   _e_sys_shutdown_func = shutdown_func;
   _e_sys_logout_func = logout_func;
   _e_sys_resume_func = resume_func;
}

static Eina_Bool
_e_sys_susp_hib_check_timer_cb(void *data __UNUSED__)
{
   double t = ecore_time_unix_get();

   if ((t - _e_sys_susp_hib_check_last_tick) > 0.2)
     {
        _e_sys_susp_hib_check_timer = NULL;
        if (_e_sys_dialog)
          {
             e_object_del(E_OBJECT(_e_sys_dialog));
             _e_sys_dialog = NULL;
          }
        if (_e_sys_resume_func) _e_sys_resume_func();
        return EINA_FALSE;
     }
   _e_sys_susp_hib_check_last_tick = t;
   return EINA_TRUE;
}
Beispiel #12
0
#include <time.h>
#include <Elementary.h>
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#else
# define __UNUSED__
#endif

#define N_ITEMS 300

static Elm_Genlist_Item_Class _itc;

static char *
_item_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
{
   time_t t = (time_t)ecore_time_unix_get();
   char buf[256];
   int i = (int)(long)data;
   if (i % 2)
     {
	int n;
	snprintf(buf, sizeof(buf), "Very Long Item # %i - realized at %s", i, ctime(&t));
	n = strlen(buf);
	buf[n - 1] = '\0';
     }
   else
     snprintf(buf, sizeof(buf), "short item # %i", i);
   return strdup(buf);
}

static Evas_Object *