uihv: move the creation of the screenshot path
[platform/core/system/swap-manager.git] / ui_viewer / ui_viewer_utils.c
index ad1b369..59ca801 100644 (file)
@@ -58,7 +58,7 @@ void reset_pid_tid()
 }
 
 // return current process id
-pid_t _getpid()
+static pid_t _getpid()
 {
        if (gPid == -1)
                gPid = getpid();
@@ -66,7 +66,7 @@ pid_t _getpid()
 }
 
 // return current thread id
-pid_t _gettid()
+static pid_t _gettid()
 {
        if(gTid == -1)
                gTid = syscall(__NR_gettid);    // syscall is very expensive
@@ -529,12 +529,36 @@ static void screenshot_send_to_socket_error(enum ErrorCode err)
        msg_send(APP_MSG_GET_UI_SCREENSHOT, buf, sizeof(buf));
 }
 
+static bool make_screenshot_path(char *buf, size_t size)
+{
+       static int index = 0;
+       int n;
+
+       __atomic_fetch_add(&index, 1, __ATOMIC_SEQ_CST);
+       n = snprintf(buf, size, TMP_DIR "/ui_screenshot_%d_%d.png",
+                    _getpid(), index);
+       if (n < 0) {
+               PRINTERR("Cannot create path, an output error occurred");
+               return false;
+       } else if ((size_t)n >= size) {
+               PRINTERR("Cannot create path, buffer is very small");
+               return false;
+       }
+
+       return true;
+}
+
 bool print_log_ui_obj_screenshot(Evas_Object *obj)
 {
        int ret = -1;
        enum ErrorCode err;
        char path[PATH_MAX];
 
+       if (!make_screenshot_path(path, sizeof(path))) {
+               PRINTERR("Cannot create screenshot path");
+               return false;
+       }
+
        err = ui_obj_screenshot(obj, path);
        if (err == ERR_NO) {
                ret = screenshot_send_to_socket(path);