Deprecated APIs cleanup 89/280189/1
authorminje.ahn <minje.ahn@samsung.com>
Thu, 25 Aug 2022 05:29:34 +0000 (14:29 +0900)
committerminje.ahn <minje.ahn@samsung.com>
Thu, 25 Aug 2022 05:29:34 +0000 (14:29 +0900)
Clean up deprecated APIs in 5.0 to improve code quality.

Change-Id: If96fd6ea3807ba1fe7408779fbe4d91b5058b78d
Signed-off-by: minje.ahn <minje.ahn@samsung.com>
include/thumbnail_util_private.h
packaging/capi-media-thumbnail-util.spec
src/thumbnail_util.c
test/thumbnail_util_test.c

index 69d6d70b9bf8e40f240f32cbc74195d33a804c09..bdc2809a5227cb30d9dba1d9404cc1bc87f4b6fe 100755 (executable)
@@ -41,9 +41,6 @@ extern "C" {
 
 #define LOG_TAG "CAPI_MEDIA_THUMBNAIL_UTIL"
 
-#define SAFE_FREE(src)         {if (src) {free(src); src = NULL; } }
-#define STRING_VALID(str)              ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
-
 typedef enum {
        THUMBNAIL_UTIL_IMAGE    = 0,
        THUMBNAIL_UTIL_VIDEO,
@@ -51,16 +48,8 @@ typedef enum {
 
 typedef struct {
        int request_id;
-       char *file_path;
-       unsigned int dst_width;
-       unsigned int dst_height;
 } thumbnail_s;
 
-typedef struct {
-       thumbnail_extracted_cb thumb_extract_cb;
-       void *user_data;
-} thumbnail_extract_cb_s;
-
 #define FONT_COLOR_RESET    "\033[0m"
 #define FONT_COLOR_RED      "\033[31m"
 #define FONT_COLOR_GREEN    "\033[32m"
index b7fafd5fecc85e1960e4ca99b243507d563950f0..bf967678c63e4bfa51973af4b86fe0ac6f2e4a65 100644 (file)
@@ -1,7 +1,7 @@
 Name:       capi-media-thumbnail-util
 Summary:    A media thumbnail util library in Tizen Native API
-Version:    0.1.25
-Release:    1
+Version:    0.1.26
+Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index 069cbce0f797d3fb66eb0158b08f7cf5722573ac..6cf3cf7e131ded1fd7f3a94fcb4343d8afc5b334 100644 (file)
@@ -42,141 +42,43 @@ static int __thumbnail_util_error_capi(int internal_error)
                return THUMBNAIL_UTIL_ERROR_INVALID_OPERATION;
        }
 }
-
-static void __thumbnail_util_extract_completed_cb(int error,
-                                                                                               int request_id,
-                                                                                               const char *path,
-                                                                                               int thumb_width,
-                                                                                               int thumb_height,
-                                                                                               unsigned char *thumb_data,
-                                                                                               int thumb_size,
-                                                                                               void *user_data)
-{
-       thumbnail_extract_cb_s *_thumb_cb = (thumbnail_extract_cb_s *)user_data;
-       char *request_id_str = NULL;
-
-       if (!_thumb_cb || !_thumb_cb->thumb_extract_cb)
-               return;
-
-       request_id_str = g_strdup_printf("%d", request_id);
-       _thumb_cb->thumb_extract_cb(__thumbnail_util_error_capi(error),
-                                                               request_id_str,
-                                                               thumb_width,
-                                                               thumb_height,
-                                                               thumb_data,
-                                                               thumb_size,
-                                                               _thumb_cb->user_data);
-
-       g_free(request_id_str);
-       g_free(_thumb_cb);
-}
-
+// LCOV_EXCL_START
 int thumbnail_util_create(thumbnail_h *thumb)
 {
-       thumbnail_s *_thumb = NULL;
-
        thumbnail_util_warn("DEPRECATION WARNING: thumbnail_util_create() is deprecated and will be removed from next release.");
-       thumbnail_util_retvm_if(!thumb, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
-
-       _thumb = g_new0(thumbnail_s, 1);
-
-       _thumb->dst_width = CONTENT_THUMB_DEFAULT_WIDTH;
-       _thumb->dst_height = CONTENT_THUMB_DEFAULT_HEIGHT;
-
-       *thumb = (thumbnail_h)_thumb;
-
        return THUMBNAIL_UTIL_ERROR_NONE;
 }
 
 int thumbnail_util_extract(thumbnail_h thumb, thumbnail_extracted_cb callback, void *user_data, char **request_id)
 {
        thumbnail_util_warn("DEPRECATION WARNING: thumbnail_util_extract() is deprecated and will be removed from next release. Use thumbnail_util_extract_to_file() or thumbnail_util_extract_to_buffer() instead.");
-       int ret = THUMBNAIL_UTIL_ERROR_NONE;
-       static int g_thumbnail_req_id = 0;
-       thumbnail_extract_cb_s *_thumb_cb = NULL;
-       thumbnail_s *_thumb = (thumbnail_s *)thumb;
-
-       thumbnail_util_retvm_if(!_thumb, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
-       thumbnail_util_retvm_if(!STRING_VALID(_thumb->file_path), THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Invalid path");
-
-       _thumb->request_id = ++g_thumbnail_req_id;
-
-       _thumb_cb = g_new0(thumbnail_extract_cb_s, 1);
-       _thumb_cb->user_data = user_data;
-       _thumb_cb->thumb_extract_cb = callback;
-
-       ret = thumbnail_request_extract_raw_data_async(_thumb->request_id,
-                                                                                               _thumb->file_path,
-                                                                                               _thumb->dst_width,
-                                                                                               _thumb->dst_height,
-                                                                                               __thumbnail_util_extract_completed_cb,
-                                                                                               (void *)_thumb_cb,
-                                                                                               tzplatform_getuid(TZ_USER_NAME));
-
-       if (ret == MS_MEDIA_ERR_NONE)
-               *request_id = g_strdup_printf("%d", g_thumbnail_req_id);
-       else
-               g_free(_thumb_cb);
-
-       return __thumbnail_util_error_capi(ret);
+       return THUMBNAIL_UTIL_ERROR_NONE;
 }
 
 int thumbnail_util_set_path(thumbnail_h thumb, const char *path)
 {
        thumbnail_util_warn("DEPRECATION WARNING: thumbnail_util_set_path() is deprecated and will be removed from next release.");
-       thumbnail_s *_thumb = (thumbnail_s *)thumb;
-
-       thumbnail_util_retvm_if(!_thumb, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
-       thumbnail_util_retvm_if(!STRING_VALID(path), THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Invalid path");
-
-       g_free(_thumb->file_path);
-       _thumb->file_path = g_strdup(path);
-
        return THUMBNAIL_UTIL_ERROR_NONE;
 }
 
 int thumbnail_util_set_size(thumbnail_h thumb, int width, int height)
 {
        thumbnail_util_warn("DEPRECATION WARNING: thumbnail_util_set_size() is deprecated and will be removed from next release.");
-       thumbnail_s *_thumb = (thumbnail_s *)thumb;
-
-       thumbnail_util_retvm_if(!_thumb, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
-       thumbnail_util_retvm_if(width <= 0, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Invalid width");
-       thumbnail_util_retvm_if(height <= 0, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Invalid height");
-
-       _thumb->dst_width = width;
-       _thumb->dst_height = height;
-
        return THUMBNAIL_UTIL_ERROR_NONE;
 }
 
 int thumbnail_util_cancel(thumbnail_h thumb, const char *request_id)
 {
-       int ret = THUMBNAIL_UTIL_ERROR_NONE;
        thumbnail_util_warn("DEPRECATION WARNING: thumbnail_util_cancel() is deprecated and will be removed from next release.");
-       thumbnail_s *_thumb = (thumbnail_s *)thumb;
-
-       thumbnail_util_retvm_if(!_thumb, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
-       thumbnail_util_retvm_if(!STRING_VALID(request_id), THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Invalid request id");
-
-       ret = thumbnail_request_cancel_raw_data(atoi(request_id));
-
-       return __thumbnail_util_error_capi(ret);
+       return THUMBNAIL_UTIL_ERROR_NONE;
 }
 
 int thumbnail_util_destroy(thumbnail_h thumb)
 {
        thumbnail_util_warn("DEPRECATION WARNING: thumbnail_util_destroy() is deprecated and will be removed from next release.");
-       thumbnail_s *_thumb = (thumbnail_s *)thumb;
-
-       thumbnail_util_retvm_if(!_thumb, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
-
-       g_free(_thumb->file_path);
-       g_free(_thumb);
-
        return THUMBNAIL_UTIL_ERROR_NONE;
 }
-
+// LCOV_EXCL_STOP
 static int __thumbnail_util_check_media_type(const char *path, thumbnail_util_media_type_e *type)
 {
        int ret = THUMBNAIL_UTIL_ERROR_NONE;
index e94c6ad42068130b71569c538871c9d7c75cdb9c..86e020115d6d7e4f26bfa7bc21c4d73173e155d9 100644 (file)
 * limitations under the License.
 */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdbool.h>
-#include <glib.h>
 #include <thumbnail_util.h>
 #include <thumbnail_util_private.h>
-#include <tzplatform_config.h>
 
 #define MAX_SIZE 4096
-GMainLoop *g_loop = NULL;
-char *g_id = NULL;
-
-void thumbnail_completed_cb(thumbnail_util_error_e error, const char *request_id, int raw_width, int raw_height, unsigned char *raw_data, int raw_size, void *user_data)
-{
-#if 0
-       FILE *fp;
-       char file_name[MAX_SIZE + 1] = {0, };
-
-       memset(file_name, 0, MAX_SIZE);
-       snprintf(file_name, MAX_SIZE, "test_%s.raw", request_id);
-       fp = fopen(file_name, "w");
-       fwrite(raw_data, 1, raw_size, fp);
-       fclose(fp);
-#endif
-       thumbnail_util_debug("=================[RESULT]");
-       thumbnail_util_debug("error_code [%d]", error);
-       thumbnail_util_debug("request id [%s]", request_id);
-       thumbnail_util_debug("width [%d], height [%d]", raw_width, raw_height);
-       thumbnail_util_debug("raw_data [0x%x], size [%d]", *raw_data, raw_size);
-#if 0
-       if (strncmp(request_id, "50", 2) == 0)
-               g_main_loop_quit(g_loop);
-#else
-       g_main_loop_quit(g_loop);
-#endif
-}
-
-void __convert_i_to_a(unsigned int request_id, char **req_str)
-{
-       char *buf = NULL;
-       buf = malloc(MAX_SIZE * sizeof(char));
-
-       if (buf != NULL) {
-               snprintf(buf, MAX_SIZE, "%d", request_id);
-               *req_str = strndup(buf, strlen(buf));
-               SAFE_FREE(buf);
-       }
-}
-
-gboolean extract_thumbnail_start(gpointer data)
-{
-       int ret = THUMBNAIL_UTIL_ERROR_NONE;
-#if 0
-       int i;
-       thumbnail_h test_info;
-       thumbnail_util_create(&test_info);
-       thumbnail_util_set_size(test_info, 512, 288);
-
-       for (i = 0; i < 50; i++) {
-               char filepath[255] = {0,};
-               snprintf(filepath, sizeof(filepath), "%s%d.jpg", "/home/owner/content/Images/test_image", i + 1);
-               thumbnail_util_debug("File : %s", filepath);
-               thumbnail_util_set_path(test_info, filepath);
-               ret = thumbnail_util_extract(test_info, thumbnail_completed_cb, test_info, &g_id);
-               thumbnail_util_debug("GENERATED ID [%s]", g_id);
-       }
-#else
-       thumbnail_h test_info;
-       thumbnail_util_create(&test_info);
-       thumbnail_util_set_path(test_info, tzplatform_mkpath(TZ_USER_IMAGES, "test_image1.jpg"));
-       thumbnail_util_set_size(test_info, 511, 288);
-       ret = thumbnail_util_extract(test_info, thumbnail_completed_cb, test_info, &g_id);
-       if (ret != THUMBNAIL_UTIL_ERROR_NONE)
-               thumbnail_util_error("thumbnail_util_extract failed[%d]", ret);
-#endif
-       thumbnail_util_destroy(test_info);
-
-       if (ret == THUMBNAIL_UTIL_ERROR_NONE)
-               thumbnail_util_debug("extract raw data is success");
-       else
-               thumbnail_util_error("extract raw data is failed");
-
-       return false;
-}
-
-
-gboolean cancel_all(gpointer data)
-{
-       int ret = THUMBNAIL_UTIL_ERROR_NONE;
-       thumbnail_h _media_thumb;
-       thumbnail_util_create(&_media_thumb);
-
-       int i, num;
-       num = atoi(g_id);
-       char *req_str = NULL;
-       for (i = num - 20; i < num; i++) {
-               __convert_i_to_a(i, &req_str);
-               ret = thumbnail_util_cancel(_media_thumb, req_str);
-               if (ret == THUMBNAIL_UTIL_ERROR_NONE)
-                       thumbnail_util_debug("thumbnail_util_cancel[%d] is success", i);
-               else
-                       thumbnail_util_error("thumbnail_util_cancel[%d] is failed", i);
-               if (req_str) {
-                       free(req_str);
-                       req_str = NULL;
-               }
-       }
-       thumbnail_util_destroy(_media_thumb);
-
-       return false;
-}
-
-int test_extract_thumbnail(bool cancel)
-{
-       int ret = THUMBNAIL_UTIL_ERROR_NONE;
-       GSource *source = NULL;
-       GMainContext *context = NULL;
-
-       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, NULL, NULL);
-       g_source_attach(source, context);
-
-       /* Logic to cancel */
-       if (cancel) {
-               GSource *cancel_src = NULL;
-               cancel_src = g_idle_source_new();
-               g_source_set_callback(cancel_src, cancel_all, NULL, NULL);
-               g_source_attach(cancel_src, context);
-       }
-
-       g_main_loop_run(g_loop);
-       g_main_loop_unref(g_loop);
-
-       return ret;
-}
 
 int main(int argc, char *argv[])
 {
@@ -165,11 +30,6 @@ int main(int argc, char *argv[])
        char file_name[MAX_SIZE + 1] = {0, };
 
        thumbnail_util_debug("--- Thumbnail util test start ---");
-#if 0
-       ret = test_extract_thumbnail(false);
-       if (ret != THUMBNAIL_UTIL_ERROR_NONE)
-               thumbnail_util_debug("test_extract_thumbnail failed[%d]", ret);
-#endif
        thumbnail_util_debug("--- thumbnail_util_extract_to_file start :: IMAGE ---");
        ret = thumbnail_util_extract_to_file(tzplatform_mkpath(TZ_USER_IMAGES, "test_image1.jpg"), 320, 240, tzplatform_mkpath(TZ_USER_IMAGES, "save_image1.jpg"));
        if (ret != THUMBNAIL_UTIL_ERROR_NONE)
@@ -186,7 +46,10 @@ int main(int argc, char *argv[])
                fwrite(data, 1, size, fp);
                fclose(fp);
 
-               SAFE_FREE(data);
+               if (data) {
+                       free(data);
+                       data = NULL;
+               }
        }
 
        thumbnail_util_debug("--- thumbnail_util_extract_to_file start :: VIDEO ---");
@@ -205,7 +68,10 @@ int main(int argc, char *argv[])
                fwrite(data, 1, size, fp);
                fclose(fp);
 
-               SAFE_FREE(data);
+               if (data) {
+                       free(data);
+                       data = NULL;
+               }
        }
 
        thumbnail_util_debug("--- Thumbnail util test end ---");