Replace gettimeofday with ecore_time_get
authorSung-jae Park <nicesj.park@samsung.com>
Thu, 26 Sep 2013 01:50:08 +0000 (10:50 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Thu, 26 Sep 2013 01:50:08 +0000 (10:50 +0900)
Change-Id: I42075e0f216e525c5f7def389246ef0bead558d9

CMakeLists.txt
include/event.h
packaging/data-provider-master.spec
src/event.c
src/instance.c
src/slave_life.c
src/util.c

index 60e28df..d9e79d4 100644 (file)
@@ -65,6 +65,8 @@ ADD_DEFINITIONS("-DBADGE_SMACK_LABEL=\"data-provider-master::badge\"")
 ADD_DEFINITIONS("-DDEFAULT_MASTER_CONF=\"/usr/share/data-provider-master/conf.ini\"")
 
 ADD_DEFINITIONS("-DNDEBUG")
+
+ADD_DEFINITIONS("-D_USE_ECORE_TIME_GET")
 #ADD_DEFINITIONS("-DFLOG")
 ADD_DEFINITIONS(${pkg_CFLAGS})
 ADD_DEFINITIONS(${pkg_LDFLAGS})
index 5d554d0..acc5bdc 100644 (file)
@@ -28,7 +28,11 @@ struct event_data {
                int minor;
        } width;
        int distance;   /* Hovering */
+#if defined(_USE_ECORE_TIME_GET)
+       double tv;
+#else
        struct timeval tv;
+#endif
 };
 
 enum event_state {
index fe2df9f..18d8de2 100644 (file)
@@ -1,6 +1,6 @@
 Name: data-provider-master
 Summary: Master service provider for liveboxes.
-Version: 0.25.14
+Version: 0.25.15
 Release: 1
 Group: HomeTF/Livebox
 License: Flora License
index 37ea6a6..0802ea0 100644 (file)
@@ -83,7 +83,11 @@ struct event_listener {
 
        enum event_state state;
 
+#if defined(_USE_ECORE_TIME_GET)
+       double tv;
+#else
        struct timeval tv; /* Recording Activate / Deactivate time */
+#endif
        int x; /* RelX */
        int y; /* RelY */
 };
@@ -132,9 +136,13 @@ static inline int processing_input_event(struct input_event *event)
                        if (item) {
                                char event_ch = EVENT_CH;
 
+#if defined(_USE_ECORE_TIME_GET)
+                               s_info.event_data.tv = ecore_time_get();
+#else
                                if (gettimeofday(&s_info.event_data.tv, NULL) < 0) {
                                        ErrPrint("gettimeofday: %s\n", strerror(errno));
                                }
+#endif
 
                                memcpy(item, &s_info.event_data, sizeof(*item));
 
@@ -376,21 +384,36 @@ static Eina_Bool event_read_cb(void *data, Ecore_Fd_Handler *handler)
                EINA_LIST_FOREACH_SAFE(s_info.event_listener_list, l, n, listener) {
                        switch (listener->state) {
                        case EVENT_STATE_ACTIVATE:
+#if defined(_USE_ECORE_TIME_GET)
+                               if (listener->tv > item->tv) {
+                                       continue;
+                               }
+#else
                                if (timercmp(&listener->tv, &item->tv, >)) {
                                        /* Ignore previous events before activating this listener */
                                        continue;
                                }
+#endif
 
                                next_state = EVENT_STATE_ACTIVATED;
                                cur_state = listener->state;
                                break;
                        case EVENT_STATE_DEACTIVATE:
+#if defined(_USE_ECORE_TIME_GET)
+                               if (listener->tv > item->tv) {
+                                       /* Consuming all events occurred while activating this listener */
+                                       cur_state = EVENT_STATE_ACTIVATED;
+                                       next_state = EVENT_STATE_ACTIVATED;
+                                       break;
+                               }
+#else
                                if (timercmp(&listener->tv, &item->tv, >)) {
                                        /* Consuming all events occurred while activating this listener */
                                        cur_state = EVENT_STATE_ACTIVATED;
                                        next_state = EVENT_STATE_ACTIVATED;
                                        break;
                                }
+#endif
 
                                cur_state = listener->state;
                                next_state = EVENT_STATE_DEACTIVATED;
@@ -536,11 +559,15 @@ HAPI int event_activate(int x, int y, int (*event_cb)(enum event_state state, st
                return LB_STATUS_ERROR_MEMORY;
        }
 
+#if defined(_USE_ECORE_TIME_GET)
+       listener->tv = ecore_time_get();
+#else
        if (gettimeofday(&listener->tv, NULL) < 0) {
                ErrPrint("gettimeofday: %s\n", strerror(errno));
                DbgFree(listener);
                return LB_STATUS_ERROR_FAULT;
        }
+#endif
 
        listener->event_cb = event_cb;
        listener->cbdata = data;
index 0afe99b..beaa65b 100644 (file)
@@ -183,19 +183,23 @@ static inline void timer_thaw(struct inst_info *inst)
 
 static inline void timer_freeze(struct inst_info *inst)
 {
-       struct timeval tv;
        ecore_timer_freeze(inst->update_timer);
 
        if (ecore_timer_interval_get(inst->update_timer) <= 1.0f) {
                return;
        }
 
+#if defined(_USE_ECORE_TIME_GET)
+       inst->sleep_at = ecore_time_get();
+#else
+       struct timeval tv;
        if (gettimeofday(&tv, NULL) < 0) {
                ErrPrint("gettimeofday: %s\n", strerror(errno));
                tv.tv_sec = 0;
                tv.tv_usec = 0;
        }
        inst->sleep_at = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
+#endif
 }
 
 
index 383c8cc..781aefd 100644 (file)
@@ -80,7 +80,11 @@ struct slave_node {
        Ecore_Timer *relaunch_timer; /* Try to relaunch service app */
        int relaunch_count;
 
+#if defined(_USE_ECORE_TIME_GET)
+       double activated_at;
+#else
        struct timeval activated_at;
+#endif
 };
 
 struct event {
@@ -673,11 +677,15 @@ HAPI int slave_activated(struct slave_node *slave)
        slave_set_reactivation(slave, 0);
        slave_set_reactivate_instances(slave, 0);
 
+#if defined(_USE_ECORE_TIME_GET)
+       slave->activated_at = ecore_time_get();
+#else
        if (gettimeofday(&slave->activated_at, NULL) < 0) {
                ErrPrint("Failed to get time of day: %s\n", strerror(errno));
                slave->activated_at.tv_sec = 0;
                slave->activated_at.tv_usec = 0;
        }
+#endif
 
        if (slave->activate_timer) {
                ecore_timer_del(slave->activate_timer);
@@ -803,7 +811,6 @@ HAPI struct slave_node *slave_deactivated(struct slave_node *slave)
 HAPI struct slave_node *slave_deactivated_by_fault(struct slave_node *slave)
 {
        int ret;
-       struct timeval faulted_at;
        int reactivate = 1;
        int reactivate_instances = 1;
 
@@ -828,6 +835,31 @@ HAPI struct slave_node *slave_deactivated_by_fault(struct slave_node *slave)
                }
        }
 
+#if defined(_USE_ECORE_TIME_GET)
+       double faulted_at;
+
+       faulted_at = ecore_time_get();
+       if (faulted_at - slave->activated_at < MINIMUM_REACTIVATION_TIME) {
+               slave->critical_fault_count++;
+               if (!slave_loaded_instance(slave) || slave->critical_fault_count >= SLAVE_MAX_LOAD) {
+                       ErrPrint("Reactivation time is too fast and frequently occurred - Stop to auto reactivation\n");
+                       reactivate = 0;
+                       reactivate_instances = 0;
+                       slave->critical_fault_count = 0;
+                       /*!
+                        * \note
+                        * Fault callback can access the slave information.
+                        */
+                       invoke_fault_cb(slave);
+               } else {
+                       slave->critical_fault_count = 0;
+               }
+       } else {
+               ErrPrint("Failed to get time of day: %s\n", strerror(errno));
+       }
+#else
+       struct timeval faulted_at;
+
        if (gettimeofday(&faulted_at, NULL) == 0) {
                struct timeval rtv;
 
@@ -851,6 +883,7 @@ HAPI struct slave_node *slave_deactivated_by_fault(struct slave_node *slave)
        } else {
                ErrPrint("Failed to get time of day: %s\n", strerror(errno));
        }
+#endif
 
        slave_set_reactivation(slave, reactivate);
        slave_set_reactivate_instances(slave, reactivate_instances);
index fb86297..1caee09 100644 (file)
@@ -50,8 +50,10 @@ HAPI unsigned long util_string_hash(const char *str)
 
 HAPI double util_timestamp(void)
 {
+#if defined(_USE_ECORE_TIME_GET)
+       return ecore_time_get();
+#else
        struct timeval tv;
-
        if (gettimeofday(&tv, NULL) < 0) {
                static unsigned long internal_count = 0;
                ErrPrint("failed to get time of day: %s\n", strerror(errno));
@@ -60,6 +62,7 @@ HAPI double util_timestamp(void)
        }
 
        return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
+#endif
 }
 
 HAPI int util_check_ext(const char *filename, const char *check_ptr)
@@ -354,7 +357,6 @@ HAPI const char *util_uri_to_path(const char *uri)
 
 HAPI double util_time_delay_for_compensation(double period)
 {
-       struct timeval tv;
        unsigned long long curtime;
        unsigned long long _period;
        unsigned long long remain;
@@ -365,12 +367,20 @@ HAPI double util_time_delay_for_compensation(double period)
                return 0.0f;
        }
 
+#if defined(_USE_ECORE_TIME_GET)
+       double tv;
+       tv = ecore_time_get();
+       curtime = tv * 1000000llu;
+#else
+       struct timeval tv;
        if (gettimeofday(&tv, NULL) < 0){
                ErrPrint("gettimeofday: %s\n", strerror(errno));
                return period;
        }
 
        curtime = (unsigned long long)tv.tv_sec * 1000000llu + (unsigned long long)tv.tv_usec;
+#endif
+
        _period = (unsigned long long)(period * (double)1000000);
        if (_period == 0llu) {
                ErrPrint("%lf <> %llu\n", period, _period);