[UTC][thumbnail-util][Non-ACR] Simplify the code 21/265221/3
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 13 Oct 2021 01:38:00 +0000 (10:38 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Wed, 13 Oct 2021 03:38:24 +0000 (12:38 +0900)
Change-Id: Iee29cf63454deb7a04e6ac6b41e046b6c207760f
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/utc/thumbnail-util/utc-thumbnail-util.c

index 2c10b496e0d12205ceb8462523cbfabca39d03de..467d72da92355368fa80c934f772f6415cea91a5 100755 (executable)
 
 #include "tct_common.h"
 #include <glib.h>
-#include <limits.h>
 #include <thumbnail_util.h>
 
 #define THUMB_WIDTH 320
 #define THUMB_HEIGHT 240
 
-#define API_NAMESPACE  "[THUMBNAIL-UTIL]"
-
 static int _retv = 0;
-static const char *image = "res/sample.jpg";
-static const char *video = "res/sample.mp4";
-static const char *unsupported_image = "res/sample.tif";
-static const char *thumb = "res/thumbnail.jpg";
-static const char *unsupported_thumb = "res/thumbnail.png";
-
-static char g_image_path[PATH_MAX + 1] = { 0, };
-static char g_video_path[PATH_MAX + 1] = { 0, };
-static char g_unsupported_image_path[PATH_MAX + 1] = { 0, };
-static char g_thumb_path[PATH_MAX + 1] = { 0, };
-static char g_unsupported_thumb_path[PATH_MAX + 1] = { 0, };
-
-GSource *source = NULL;
-GMainContext *context = NULL;
+
+static char *g_image_path;
+static char *g_video_path;
+static char *g_unsupported_image_path;
+static char *g_thumb_path;
+static char *g_unsupported_thumb_path;
+
 GMainLoop *g_loop = NULL;
 
 /**
@@ -51,17 +41,16 @@ void utc_thumbnail_util_startup(void)
 {
        char pszValue[CONFIG_VALUE_LEN_MAX] = { 0, };
 
-       if (true == GetValueForTCTSetting("DEVICE_SUITE_TARGET_30", pszValue, API_NAMESPACE)) {
-               PRINT_UTC_LOG("[Line : %d][%s] 'DEVICE_SUITE_TARGET_30' Values Received = %s\\n", __LINE__, API_NAMESPACE, pszValue);
-
-               snprintf(g_image_path, PATH_MAX, "%s/%s", pszValue, image);
-               snprintf(g_video_path, PATH_MAX, "%s/%s", pszValue, video);
-               snprintf(g_unsupported_image_path, PATH_MAX, "%s/%s", pszValue, unsupported_image);
-               snprintf(g_thumb_path, PATH_MAX, "%s/%s", pszValue, thumb);
-               snprintf(g_unsupported_thumb_path, PATH_MAX, "%s/%s", pszValue, unsupported_thumb);
-       } else {
-               PRINT_UTC_LOG("[Line : %d][%s] GetValueForTCTSetting returned error for 'DEVICE_SUITE_TARGET_30'\\n", __LINE__, API_NAMESPACE);
+       if (!GetValueForTCTSetting("DEVICE_SUITE_TARGET_30", pszValue, "[THUMBNAIL-UTIL]")) {
+               FPRINTF("[Line : %d] GetValueForTCTSetting failed\\n", __LINE__);
+               return;
        }
+
+       g_image_path = g_strdup_printf("%s/res/sample.jpg", pszValue);
+       g_video_path = g_strdup_printf("%s/res/sample.mp4", pszValue);
+       g_unsupported_image_path = g_strdup_printf("%s/res/sample.tif", pszValue);
+       g_thumb_path = g_strdup_printf("%s/res/thumbnail.jpg", pszValue);
+       g_unsupported_thumb_path = g_strdup_printf("%s/res/thumbnail.png", pszValue);
 }
 
 /**
@@ -72,11 +61,11 @@ void utc_thumbnail_util_startup(void)
  */
 void utc_thumbnail_util_cleanup(void)
 {
-       memset(&g_image_path, 0, PATH_MAX + 1);
-       memset(&g_video_path, 0, PATH_MAX + 1);
-       memset(&g_unsupported_image_path, 0, PATH_MAX + 1);
-       memset(&g_thumb_path, 0, PATH_MAX + 1);
-       memset(&g_unsupported_thumb_path, 0, PATH_MAX + 1);
+       FREE_MEMORY(g_image_path);
+       FREE_MEMORY(g_video_path);
+       FREE_MEMORY(g_unsupported_image_path);
+       FREE_MEMORY(g_thumb_path);
+       FREE_MEMORY(g_unsupported_thumb_path);
 }
 
 /**
@@ -113,14 +102,13 @@ int utc_thumbnail_util_create_p(void)
        return 0;
 }
 
-void thumbnail_completed_cb(thumbnail_util_error_e e, const char *id, int width, int height, unsigned char *data, int size, void *user_data)
+static void __completed_cb(thumbnail_util_error_e e, const char *id, int width, int height, unsigned char *data, int size, void *user_data)
 {
        _retv = e;
-       PRINT_UTC_LOG("[Line : %d][%s] thumbnail_completed_cb returned %d(%0x) error\\n", __LINE__, API_NAMESPACE, e, e);
        g_main_loop_quit(g_loop);
 }
 
-gboolean extract_thumbnail_start(gpointer data)
+static gboolean __extract_cb(gpointer data)
 {
        int ret = THUMBNAIL_UTIL_ERROR_NONE;
        char *request_id = NULL;
@@ -138,7 +126,7 @@ gboolean extract_thumbnail_start(gpointer data)
        if (ret != THUMBNAIL_UTIL_ERROR_NONE)
                goto FINALIZE;
 
-       ret = thumbnail_util_extract(test_info, thumbnail_completed_cb, NULL, &request_id);
+       ret = thumbnail_util_extract(test_info, __completed_cb, NULL, &request_id);
        FREE_MEMORY(request_id);
 
  FINALIZE:
@@ -166,7 +154,7 @@ int utc_thumbnail_util_extract_n1(void)
        ret = thumbnail_util_create(&test_info);
        assert_eq(ret, THUMBNAIL_UTIL_ERROR_NONE);
 
-       ret = thumbnail_util_extract(test_info, thumbnail_completed_cb, NULL, &request_id);
+       ret = thumbnail_util_extract(test_info, __completed_cb, NULL, &request_id);
        assert_eq(ret, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER);
        FREE_MEMORY(request_id);
 
@@ -183,11 +171,8 @@ int utc_thumbnail_util_extract_n1(void)
  */
 int utc_thumbnail_util_extract_n2(void)
 {
-       g_loop = g_main_loop_new(NULL, false);
-       context = g_main_loop_get_context(g_loop);
-       source = g_idle_source_new();
-       g_source_set_callback(source, extract_thumbnail_start, (gpointer) g_unsupported_image_path, NULL);
-       g_source_attach(source, context);
+       g_loop = g_main_loop_new(NULL, FALSE);
+       g_idle_add(__extract_cb, (gpointer) g_unsupported_image_path);
 
        g_main_loop_run(g_loop);
        g_main_loop_unref(g_loop);
@@ -206,11 +191,8 @@ int utc_thumbnail_util_extract_n2(void)
  */
 int utc_thumbnail_util_extract_p(void)
 {
-       g_loop = g_main_loop_new(NULL, false);
-       context = g_main_loop_get_context(g_loop);
-       source = g_idle_source_new();
-       g_source_set_callback(source, extract_thumbnail_start, (gpointer) g_image_path, NULL);
-       g_source_attach(source, context);
+       g_loop = g_main_loop_new(NULL, FALSE);
+       g_idle_add(__extract_cb, (gpointer) g_image_path);
 
        g_main_loop_run(g_loop);
        g_main_loop_unref(g_loop);
@@ -341,7 +323,7 @@ int utc_thumbnail_util_cancel_n(void)
        return 0;
 }
 
-void thumbnail_cancel_cb(thumbnail_util_error_e e, const char *id, int width, int height, unsigned char *data, int size, void *user_data)
+static void __cancel_cb(thumbnail_util_error_e e, const char *id, int width, int height, unsigned char *data, int size, void *user_data)
 {
 }
 
@@ -360,10 +342,10 @@ int utc_thumbnail_util_cancel_p(void)
        thumbnail_util_set_path(test_info, g_image_path);
        thumbnail_util_set_size(test_info, THUMB_WIDTH, THUMB_HEIGHT);
 
-       ret = thumbnail_util_extract(test_info, thumbnail_cancel_cb, NULL, &request_id);
+       ret = thumbnail_util_extract(test_info, __cancel_cb, NULL, &request_id);
        FREE_MEMORY(request_id);
 
-       ret = thumbnail_util_extract(test_info, thumbnail_cancel_cb, NULL, &request_id);
+       ret = thumbnail_util_extract(test_info, __cancel_cb, NULL, &request_id);
        assert_eq(ret, THUMBNAIL_UTIL_ERROR_NONE);
 
        ret = thumbnail_util_cancel(test_info, request_id);