Replace gettimeofday with clock_get_time
authorSung-jae Park <nicesj.park@samsung.com>
Thu, 26 Sep 2013 02:24:52 +0000 (11:24 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Thu, 26 Sep 2013 02:24:52 +0000 (11:24 +0900)
Change-Id: I88e8eee0ab2dfd031a807aa4c4c7fb701fdd7cdf

lib/CMakeLists.txt
lib/src/icon.c
packaging/libshortcut.spec

index f02c651..924ab26 100644 (file)
@@ -28,6 +28,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
 ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
 ADD_DEFINITIONS("-DLOG_TAG=\"SHORTCUT\"")
+ADD_DEFINITIONS("-D_USE_ECORE_TIME_GET")
 
 ADD_LIBRARY(${PROJECT_NAME} SHARED 
        src/main.c
index 0fb83da..06877fc 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/ioctl.h>
 #include <libgen.h>
 #include <sys/time.h>
+#include <time.h>
 
 #include <dlog.h>
 #include <glib.h>
@@ -44,7 +45,6 @@
 #define CREATED        0x00BEEF00
 #define DESTROYED 0x00DEAD00
 
-
 static struct info {
        int fd;
        int (*init_cb)(int status, void *data);
@@ -54,6 +54,9 @@ static struct info {
        const char *utility_socket;
 
        struct dlist *pending_list;
+#if defined(_USE_ECORE_TIME_GET)
+       clockid_t type;
+#endif
 } s_info = {
        .fd = -1,
        .init_cb = NULL,
@@ -62,6 +65,9 @@ static struct info {
 
        .utility_socket = "/tmp/.utility.service",
        .pending_list = NULL,
+#if defined(_USE_ECORE_TIME_GET)
+       .type = CLOCK_MONOTONIC,
+#endif
 };
 
 
@@ -672,7 +678,6 @@ EAPI int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type,
        struct packet *packet;
        struct request_item *item;
        char *filename;
-       struct timeval tv;
        int len;
 
        if (!handle || handle->state != CREATED) {
@@ -695,6 +700,26 @@ EAPI int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type,
                return -ENOMEM;
        }
 
+#if defined(_USE_ECORE_TIME_GET)
+       struct timespec ts;
+       double tv;
+       do {
+               if (clock_gettime(s_info.type, &ts) == 0) {
+                       tv = ts.tv_sec + ts.tv_nsec / 1000000000.0f;
+                       break;
+               }
+
+               ErrPrint("%d: %s\n", s_info.type, strerror(errno));
+               if (s_info.type == CLOCK_MONOTONIC) {
+                       s_info.type = CLOCK_REALTIME;
+               } else if (s_info.type == CLOCK_REALTIME) {
+                       tv = rand();
+                       break;
+               }
+       } while (1);
+       ret = snprintf(filename, len, "%s.%lf.desc", outfile, tv);
+#else
+       struct timeval tv;
        if (gettimeofday(&tv, NULL) != 0) {
                ErrPrint("gettimeofday: %s\n", strerror(errno));
                tv.tv_sec = rand();
@@ -702,6 +727,7 @@ EAPI int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type,
        }
 
        ret = snprintf(filename, len, "%s.%lu.%lu.desc", outfile, tv.tv_sec, tv.tv_usec);
+#endif
        if (ret < 0) {
                ErrPrint("snprintf: %s\n", strerror(errno));
                goto out;
index fc813fb..78f746b 100644 (file)
@@ -1,6 +1,6 @@
 Name: libshortcut
 Summary: Shortcut add feature supporting library
-Version: 0.6.7
+Version: 0.6.8
 Release: 0
 Group: HomeTF/Framework
 License: Apache License