Remove unused product APIs
[platform/core/api/media-content.git] / src / media_face.c
index 745dcf0..fdcbe15 100755 (executable)
@@ -17,6 +17,8 @@
 
 #include <media_info_private.h>
 
+#define MAX_SIZE 16
+// LCOV_EXCL_START
 static int __media_face_check_media_id(const char *media_id)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
@@ -24,122 +26,107 @@ static int __media_face_check_media_id(const char *media_id)
        sqlite3_stmt *stmt = NULL;
        int item_count = 0;
 
-       media_content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media_id");
+       content_retip_if_fail(STRING_VALID(media_id));
 
-       query_str = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_MEDIA_BY_ID, media_id);
-       ret = _content_query_prepare(&stmt, query_str, NULL, NULL);
+       /* Get image count */
+       query_str = sqlite3_mprintf(SELECT_IMAGE_COUNT_FROM_MEDIA_BY_ID, media_id);
+       ret = _content_get_result(query_str, &stmt);
        SQLITE3_SAFE_FREE(query_str);
-       media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+       content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       while (sqlite3_step(stmt) == SQLITE_ROW)
+       if (sqlite3_step(stmt) == SQLITE_ROW)
                item_count = (int)sqlite3_column_int(stmt, 0);
 
        SQLITE3_FINALIZE(stmt);
 
-       media_content_retvm_if(item_count == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id");
+       content_retvm_if(item_count == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id");
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int media_face_destroy(media_face_h face)
 {
+       content_warn("DEPRECATION WARNING: media_face_destroy() is deprecated and will be removed from next release.");
        media_face_s *_face = (media_face_s*)face;
 
-       media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
+       content_retip_if_fail(face);
 
-       SAFE_FREE(_face->face_id);
-       SAFE_FREE(_face->media_id);
-       SAFE_FREE(_face->face_tag);
-       SAFE_FREE(_face);
+       g_free(_face->media_id);
+       g_free(_face->face_tag);
+       g_free(_face);
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int media_face_clone(media_face_h *dst, media_face_h src)
 {
+       content_warn("DEPRECATION WARNING: media_face_clone() is deprecated and will be removed from next release.");
        media_face_s *_src = (media_face_s*)src;
 
-       media_content_retvm_if(src == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid src handle");
-
-       media_face_s *_dst = (media_face_s *)calloc(1, sizeof(media_face_s));
-       media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
-
-       if (STRING_VALID(_src->face_id)) {
-               _dst->face_id = strdup(_src->face_id);
-               if (_dst->face_id == NULL) {
-                       media_face_destroy((media_face_h)_dst);
-                       media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
-                       return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
-               }
-       }
-
-       if (STRING_VALID(_src->media_id)) {
-               _dst->media_id = strdup(_src->media_id);
-               if (_dst->media_id == NULL) {
-                       media_face_destroy((media_face_h)_dst);
-                       media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
-                       return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
-               }
-       }
+       content_retip_if_fail(dst);
+       content_retip_if_fail(src);
 
+       media_face_s *_dst = g_new0(media_face_s, 1);
+
+       _dst->media_id = g_strdup(_src->media_id);
+       _dst->face_id = _src->face_id;
        _dst->face_rect_x = _src->face_rect_x;
        _dst->face_rect_y = _src->face_rect_y;
        _dst->face_rect_w = _src->face_rect_w;
        _dst->face_rect_h = _src->face_rect_h;
        _dst->orientation = _src->orientation;
-
-       if (STRING_VALID(_src->face_tag)) {
-               _dst->face_tag = strdup(_src->face_tag);
-               if (_dst->face_tag == NULL) {
-                       media_face_destroy((media_face_h)_dst);
-                       media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
-                       return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
-               }
-       }
+       _dst->face_tag = g_strdup(_src->face_tag);
 
        *dst = (media_face_h)_dst;
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
 
+static void __media_face_convert_itoa(int face_id, char **face_strid)
+{
+       char buf[MAX_SIZE] = {0, };
+
+       snprintf(buf, MAX_SIZE, "%d", face_id);
+       *face_strid = g_strndup(buf, strlen(buf));
+}
+
 int media_face_get_face_id(media_face_h face, char **face_id)
 {
+       content_warn("DEPRECATION WARNING: media_face_get_face_id() is deprecated and will be removed from next release.");
        media_face_s* _face = (media_face_s*)face;
 
-       media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
+       content_retip_if_fail(face);
+       content_retip_if_fail(face_id);
 
-       if (STRING_VALID(_face->face_id)) {
-               *face_id = strdup(_face->face_id);
-               media_content_retvm_if(*face_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Out of memory");
-       } else {
-               *face_id = NULL;
-       }
+       if (_face->face_id > 0)
+               __media_face_convert_itoa(_face->face_id, face_id);
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int media_face_get_media_id(media_face_h face, char **media_id)
 {
+       content_warn("DEPRECATION WARNING: media_face_get_media_id() is deprecated and will be removed from next release.");
        media_face_s* _face = (media_face_s*)face;
 
-       media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
+       content_retip_if_fail(face);
+       content_retip_if_fail(media_id);
 
-       if (STRING_VALID(_face->media_id)) {
-               *media_id = strdup(_face->media_id);
-               media_content_retvm_if(*media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Out of memory");
-       } else {
-               *media_id = NULL;
-       }
+       *media_id = g_strdup(_face->media_id);
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int media_face_get_face_rect(media_face_h face, unsigned int *rect_x, unsigned int *rect_y, unsigned int *rect_w, unsigned int *rect_h)
 {
+       content_warn("DEPRECATION WARNING: media_face_get_face_rect() is deprecated and will be removed from next release.");
        media_face_s* _face = (media_face_s*)face;
 
-       media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
-       media_content_retvm_if(!(rect_x && rect_y && rect_w && rect_h), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect");
+       content_retip_if_fail(face);
+       content_retip_if_fail(rect_x);
+       content_retip_if_fail(rect_y);
+       content_retip_if_fail(rect_w);
+       content_retip_if_fail(rect_h);
 
        *rect_x = _face->face_rect_x;
        *rect_y = _face->face_rect_y;
@@ -151,10 +138,11 @@ int media_face_get_face_rect(media_face_h face, unsigned int *rect_x, unsigned i
 
 int media_face_get_orientation(media_face_h face, media_content_orientation_e *orientation)
 {
+       content_warn("DEPRECATION WARNING: media_face_get_orientation() is deprecated and will be removed from next release.");
        media_face_s* _face = (media_face_s*)face;
 
-       media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
-       media_content_retvm_if(orientation == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid orientation");
+       content_retip_if_fail(face);
+       content_retip_if_fail(orientation);
 
        *orientation = _face->orientation;
 
@@ -163,34 +151,30 @@ int media_face_get_orientation(media_face_h face, media_content_orientation_e *o
 
 int media_face_get_tag(media_face_h face, char **tag)
 {
+       content_warn("DEPRECATION WARNING: media_face_get_tag() is deprecated and will be removed from next release.");
        media_face_s* _face = (media_face_s*)face;
 
-       media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
+       content_retip_if_fail(face);
+       content_retip_if_fail(tag);
 
-       if (STRING_VALID(_face->face_tag)) {
-               *tag = strdup(_face->face_tag);
-               media_content_retvm_if(*tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Out of memory");
-       } else {
-               *tag = NULL;
-       }
+       *tag = g_strdup(_face->face_tag);
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int media_face_create(const char *media_id, media_face_h *face)
 {
+       content_warn("DEPRECATION WARNING: media_face_create() is deprecated and will be removed from next release.");
        int ret = MEDIA_CONTENT_ERROR_NONE;
 
-       media_content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media_id");
-       media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
+       content_retip_if_fail(face);
 
        ret = __media_face_check_media_id(media_id);
-       media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Not exist media_id");
+       content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "media_id does not exist or is not an image");
 
-       media_face_s* _face = calloc(1, sizeof(media_face_s));
-       media_content_retvm_if(_face == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Out of memory");
+       media_face_s* _face = g_new0(media_face_s, 1);
 
-       _face->media_id = strdup(media_id);
+       _face->media_id = g_strdup(media_id);
 
        *face = (media_face_h)_face;
 
@@ -199,11 +183,12 @@ int media_face_create(const char *media_id, media_face_h *face)
 
 int media_face_set_face_rect(media_face_h face, unsigned int rect_x, unsigned int rect_y, unsigned int rect_w, unsigned int rect_h)
 {
+       content_warn("DEPRECATION WARNING: media_face_set_face_rect() is deprecated and will be removed from next release.");
        media_face_s* _face = (media_face_s*)face;
 
-       media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
-       media_content_retvm_if(rect_w == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_w");
-       media_content_retvm_if(rect_h == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_h");
+       content_retip_if_fail(face);
+       content_retip_if_fail(rect_w > 0);
+       content_retip_if_fail(rect_h > 0);
 
        _face->face_rect_x = rect_x;
        _face->face_rect_y = rect_y;
@@ -215,9 +200,10 @@ int media_face_set_face_rect(media_face_h face, unsigned int rect_x, unsigned in
 
 int media_face_set_orientation(media_face_h face, media_content_orientation_e orientation)
 {
+       content_warn("DEPRECATION WARNING: media_face_set_orientation() is deprecated and will be removed from next release.");
        media_face_s* _face = (media_face_s*)face;
 
-       media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
+       content_retip_if_fail(face);
 
        _face->orientation = orientation;
 
@@ -226,58 +212,63 @@ int media_face_set_orientation(media_face_h face, media_content_orientation_e or
 
 int media_face_set_tag(media_face_h face, const char *tag)
 {
+       content_warn("DEPRECATION WARNING: media_face_set_tag() is deprecated and will be removed from next release.");
        media_face_s* _face = (media_face_s*)face;
 
-       media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
+       content_retip_if_fail(face);
 
-       if (STRING_VALID(tag))
-               _face->face_tag = strdup(tag);
-       else
-               _face->face_tag = NULL;
+       g_free(_face->face_tag);
+       _face->face_tag = g_strdup(tag);
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int media_face_insert_to_db(media_face_h face)
 {
+       content_warn("DEPRECATION WARNING: media_face_insert_to_db() is deprecated and will be removed from next release.");
        int ret = MEDIA_CONTENT_ERROR_NONE;
        char *query_str = NULL;
-       char *face_uuid = NULL;
+       sqlite3_stmt *stmt = NULL;
 
        media_face_s* _face = (media_face_s*)face;
 
-       media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
-       media_content_retvm_if(_face->media_id == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id");
-       media_content_retvm_if(_face->face_rect_w == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_w");
-       media_content_retvm_if(_face->face_rect_h == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_h");
-
-       ret = media_svc_generate_uuid(&face_uuid);
-       media_content_retvm_if(ret != MS_MEDIA_ERR_NONE, MEDIA_CONTENT_ERROR_INVALID_OPERATION, "Fail to generate face_id");
+       content_retip_if_fail(face);
+       content_retip_if_fail(_face->media_id);
+       content_retip_if_fail(_face->face_rect_w > 0);
+       content_retip_if_fail(_face->face_rect_h > 0);
 
-       SAFE_FREE(_face->face_id);
-       _face->face_id = strdup(face_uuid);
-       SAFE_FREE(face_uuid);
-
-       query_str = sqlite3_mprintf(INSERT_FACE_TO_FACE, _face->face_id, _face->media_id, _face->face_rect_x, _face->face_rect_y, _face->face_rect_w, _face->face_rect_h, _face->orientation, _face->face_tag);
+       query_str = sqlite3_mprintf(INSERT_FACE_TO_FACE, _face->media_id, _face->face_rect_x, _face->face_rect_y, _face->face_rect_w, _face->face_rect_h, _face->orientation, _face->face_tag);
 
        ret = _content_query_sql(query_str);
        SQLITE3_SAFE_FREE(query_str);
 
+       query_str = sqlite3_mprintf(SELECT_FACE_ID, _face->media_id, _face->face_rect_x, _face->face_rect_y, _face->face_rect_w, _face->face_rect_h, _face->orientation);
+       ret = _content_get_result(query_str, &stmt);
+       SQLITE3_SAFE_FREE(query_str);
+       content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+
+       if (sqlite3_step(stmt) == SQLITE_ROW)
+               _face->face_id = (int)sqlite3_column_int(stmt, 0);
+
+       SQLITE3_FINALIZE(stmt);
+
+
        return ret;
 }
 
 int media_face_update_to_db(media_face_h face)
 {
+       content_warn("DEPRECATION WARNING: media_face_update_to_db() is deprecated and will be removed from next release.");
        int ret = MEDIA_CONTENT_ERROR_NONE;
        char *query_str = NULL;
 
        media_face_s* _face = (media_face_s*)face;
 
-       media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
-       media_content_retvm_if(_face->face_id == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid face_id");
-       media_content_retvm_if(_face->media_id == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id");
-       media_content_retvm_if(_face->face_rect_w == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_w");
-       media_content_retvm_if(_face->face_rect_h == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_h");
+       content_retip_if_fail(face);
+       content_retip_if_fail(_face->media_id);
+       content_retip_if_fail(_face->face_id > 0);
+       content_retip_if_fail(_face->face_rect_w > 0);
+       content_retip_if_fail(_face->face_rect_h > 0);
 
        query_str = sqlite3_mprintf(UPDATE_FACE_TO_FACE, _face->face_rect_x, _face->face_rect_y, _face->face_rect_w, _face->face_rect_h, _face->orientation, _face->face_tag, _face->face_id);
 
@@ -287,35 +278,44 @@ int media_face_update_to_db(media_face_h face)
        return ret;
 }
 
+static int __media_face_safe_atoi(const char *buffer, int *si)
+{
+       char *end = NULL;
+       errno = 0;
+
+       content_retip_if_fail(buffer);
+       content_retip_if_fail(si);
+
+       const long sl = strtol(buffer, &end, 10);
+
+       content_retvm_if(end == buffer, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "not a decimal number");
+       content_retvm_if('\0' != *end, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "extra characters at end of input: %s", end);
+       content_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "out of range of type long");
+       content_retvm_if(sl > INT_MAX, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "greater than INT_MAX");
+       content_retvm_if(sl < INT_MIN, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "less than INT_MIN");
+
+       *si = (int)sl;
+
+       return MEDIA_CONTENT_ERROR_NONE;
+}
+
 int media_face_delete_from_db(const char *face_id)
 {
+       content_warn("DEPRECATION WARNING: media_face_delete_from_db() is deprecated and will be removed from next release.");
        int ret = MEDIA_CONTENT_ERROR_NONE;
        char *query_str = NULL;
-       char *media_id = NULL;
-       sqlite3_stmt *stmt = NULL;
-       media_content_retvm_if(!STRING_VALID(face_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid face_id");
+       int query_face_id = 0;
 
-       /*To refresh face information(User try to start_face_detection again for the already scanned item),
-       mark media modified_time to '0' if user delete system extracted face info. */
+       ret = __media_face_safe_atoi(face_id, &query_face_id);
+       content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid face_id");
 
-       query_str = sqlite3_mprintf(SELECT_MEDIA_FROM_FACE, face_id);
-       ret = _content_query_prepare(&stmt, query_str, NULL, NULL);
+       /*Update modified_time to 0.. It will restore the deleted face when media_info_start_face_detection() is called */
+       query_str = sqlite3_mprintf(UPDATE_MEDIA_INFO_IN_FACE_SCAN_LIST, query_face_id);
+       ret = _content_query_sql(query_str);
        SQLITE3_SAFE_FREE(query_str);
-       media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
-
-       while (sqlite3_step(stmt) == SQLITE_ROW)
-               media_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
-       SQLITE3_FINALIZE(stmt);
-
-       if (STRING_VALID(media_id)) {
-               query_str = sqlite3_mprintf(UPDATE_MEDIA_INFO, media_id);
-               ret = _content_query_sql(query_str);
-               SQLITE3_SAFE_FREE(query_str);
-       }
-       SAFE_FREE(media_id);
-
-       query_str = sqlite3_mprintf(DELETE_FACE_FROM_FACE, face_id);
+       content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
+       query_str = sqlite3_mprintf(DELETE_FACE_FROM_FACE, query_face_id);
        ret = _content_query_sql(query_str);
        SQLITE3_SAFE_FREE(query_str);
 
@@ -324,25 +324,17 @@ int media_face_delete_from_db(const char *face_id)
 
 int media_face_get_face_count_from_db(filter_h filter, int *face_count)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       if (face_count == NULL) {
-               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_warn("DEPRECATION WARNING: media_face_get_face_count_from_db() is deprecated and will be removed from next release.");
+       content_retip_if_fail(face_count);
 
-       ret = _media_db_get_group_count(filter, MEDIA_GROUP_FACE, face_count);
-
-       return ret;
+       return _media_db_get_group_count(filter, MEDIA_GROUP_FACE, face_count);
 }
 
 int media_face_foreach_face_from_db(filter_h filter, media_face_cb callback, void *user_data)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       media_content_retvm_if(callback == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid paramter");
+       content_warn("DEPRECATION WARNING: media_face_foreach_face_from_db() is deprecated and will be removed from next release.");
+       content_retip_if_fail(callback);
 
-       ret = _media_db_get_face(NULL, filter, callback, user_data);
-
-       return ret;
+       return _media_db_get_face(NULL, filter, callback, user_data);
 }
+// LCOV_EXCL_STOP
\ No newline at end of file