[ACR-1618] Add API to get media handle by path
[platform/core/api/media-content.git] / src / media_image.c
index 587f4ab..b114c12 100755 (executable)
 
 #include <media_info_private.h>
 
-#define media_content_retv_free_image_if(expr, val, p_str) do { \
-                               if (expr) {     \
-                                       LOGE(FONT_COLOR_RED"Memory allocation failure"FONT_COLOR_RESET);        \
-                                       image_meta_destroy(p_str);      \
-                                       return (val);   \
-                               }       \
-                       } while (0)
-
-
 int image_meta_destroy(image_meta_h image)
 {
        image_meta_s *_image = (image_meta_s*)image;
-       media_content_retvm_if(_image == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Image handle is null");
 
-       SAFE_FREE(_image->media_id);
-       SAFE_FREE(_image->date_taken);
-       SAFE_FREE(_image->title);
-       SAFE_FREE(_image->exposure_time);
-       SAFE_FREE(_image->model);
-       SAFE_FREE(_image);
+       content_retip_if_fail(image);
+
+       g_free(_image->media_id);
+       g_free(_image->date_taken);
+       g_free(_image->exposure_time);
+       g_free(_image->model);
+       g_free(_image);
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
@@ -44,36 +35,16 @@ int image_meta_destroy(image_meta_h image)
 int image_meta_clone(image_meta_h *dst, image_meta_h src)
 {
        image_meta_s *_src = (image_meta_s*)src;
-       media_content_retvm_if(_src == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Source handle is null");
-
-       image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
-       media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
-
-       if (STRING_VALID(_src->media_id)) {
-               _dst->media_id = strdup(_src->media_id);
-               media_content_retv_free_image_if(_dst->media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
-       }
-
-       if (STRING_VALID(_src->date_taken)) {
-               _dst->date_taken = strdup(_src->date_taken);
-               media_content_retv_free_image_if(_dst->date_taken == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
-       }
-
-       if (STRING_VALID(_src->title)) {
-               _dst->title = strdup(_src->title);
-               media_content_retv_free_image_if(_dst->title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
-       }
 
-       if (STRING_VALID(_src->exposure_time)) {
-               _dst->exposure_time = strdup(_src->exposure_time);
-               media_content_retv_free_image_if(_dst->exposure_time == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
-       }
+       content_retip_if_fail(dst);
+       content_retip_if_fail(src);
 
-       if (STRING_VALID(_src->model)) {
-               _dst->model = strdup(_src->model);
-               media_content_retv_free_image_if(_dst->model == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
-       }
+       image_meta_s *_dst = g_new0(image_meta_s, 1);
 
+       _dst->media_id = g_strdup(_src->media_id);
+       _dst->date_taken = g_strdup(_src->date_taken);
+       _dst->exposure_time = g_strdup(_src->exposure_time);
+       _dst->model = g_strdup(_src->model);
        _dst->fnumber = _src->fnumber;
        _dst->iso = _src->iso;
        _dst->width = _src->width;
@@ -87,216 +58,145 @@ int image_meta_clone(image_meta_h *dst, image_meta_h src)
 
 int image_meta_get_media_id(image_meta_h image, char **media_id)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
        image_meta_s *_image = (image_meta_s*)image;
 
-       if (_image && media_id) {
-               if (STRING_VALID(_image->media_id)) {
-                       char *new_string = strdup(_image->media_id);
-                       media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
-
-                       *media_id = new_string;
-               } else {
-                       *media_id = NULL;
-               }
-               ret = MEDIA_CONTENT_ERROR_NONE;
-
-       } else {
-               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_retip_if_fail(image);
+       content_retip_if_fail(media_id);
 
-       return ret;
+       *media_id = g_strdup(_image->media_id);
 
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int image_meta_get_width(image_meta_h image, int *width)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
        image_meta_s *_image = (image_meta_s*)image;
 
-       if (_image && width) {
-               *width = _image->width;
-               ret = MEDIA_CONTENT_ERROR_NONE;
-       } else {
-               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_retip_if_fail(image);
+       content_retip_if_fail(width);
 
-       return ret;
+       *width = _image->width;
+
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 int image_meta_get_height(image_meta_h image, int *height)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
        image_meta_s *_image = (image_meta_s*)image;
 
-       if (_image && height) {
-               *height = _image->height;
-               ret = MEDIA_CONTENT_ERROR_NONE;
-       } else {
-               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_retip_if_fail(image);
+       content_retip_if_fail(height);
 
-       return ret;
+       *height = _image->height;
+
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
        image_meta_s *_image = (image_meta_s*)image;
 
-       if (_image && orientation) {
-               *orientation = _image->orientation;
-               ret = MEDIA_CONTENT_ERROR_NONE;
-       } else {
-               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_retip_if_fail(image);
+       content_retip_if_fail(orientation);
 
-       return ret;
+       *orientation = _image->orientation;
+
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
        image_meta_s *_image = (image_meta_s*)image;
 
-       if (_image && date_taken) {
-               if (STRING_VALID(_image->date_taken)) {
-                       char *new_string = strdup(_image->date_taken);
-                       media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+       content_retip_if_fail(image);
+       content_retip_if_fail(date_taken);
 
-                       *date_taken = new_string;
-               } else {
-                       *date_taken = NULL;
-               }
+       *date_taken = g_strdup(_image->date_taken);
 
-               ret = MEDIA_CONTENT_ERROR_NONE;
-       } else {
-               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
-
-       return ret;
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int image_meta_get_exposure_time(image_meta_h image, char **exposure_time)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
        image_meta_s *_image = (image_meta_s*)image;
 
-       if (_image && exposure_time) {
-               if (STRING_VALID(_image->exposure_time)) {
-                       *exposure_time = strdup(_image->exposure_time);
-                       media_content_retvm_if(*exposure_time == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
-               } else {
-                       *exposure_time = NULL;
-               }
-               ret = MEDIA_CONTENT_ERROR_NONE;
-       } else {
-               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_retip_if_fail(image);
+       content_retip_if_fail(exposure_time);
 
-       return ret;
+       *exposure_time = g_strdup(_image->exposure_time);
+
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
        image_meta_s *_image = (image_meta_s*)image;
 
-       if (_image && fnumber) {
-               *fnumber = _image->fnumber;
-               ret = MEDIA_CONTENT_ERROR_NONE;
-       } else {
-               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_retip_if_fail(image);
+       content_retip_if_fail(fnumber);
 
-       return ret;
+       *fnumber = _image->fnumber;
+
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int image_meta_get_iso(image_meta_h image, int *iso)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
        image_meta_s *_image = (image_meta_s*)image;
 
-       if (_image && iso) {
-               *iso = _image->iso;
-               ret = MEDIA_CONTENT_ERROR_NONE;
-       } else {
-               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_retip_if_fail(image);
+       content_retip_if_fail(iso);
 
-       return ret;
+       *iso = _image->iso;
+
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int image_meta_get_model(image_meta_h image, char **model)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
        image_meta_s *_image = (image_meta_s*)image;
 
-       if (_image && model) {
-               if (STRING_VALID(_image->model)) {
-                       *model = strdup(_image->model);
-                       media_content_retvm_if(*model == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
-               } else {
-                       *model = NULL;
-               }
-               ret = MEDIA_CONTENT_ERROR_NONE;
-       } else {
-               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_retip_if_fail(image);
+       content_retip_if_fail(model);
 
-       return ret;
+       *model = g_strdup(_image->model);
+
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       media_content_warn("DEPRECATION WARNING: image_meta_set_orientation() is deprecated and will be removed from next release.");
+       content_warn("DEPRECATION WARNING: image_meta_set_orientation() is deprecated and will be removed from next release.");
        image_meta_s *_image = (image_meta_s*)image;
 
-       if (_image == NULL) {
-               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
-
-       if ((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270)) {
-               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
+       content_retip_if_fail(image);
+       content_retvm_if(orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE || orientation > MEDIA_CONTENT_ORIENTATION_ROT_270, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid orientation");
 
        _image->orientation = orientation;
 
-       return ret;
+       return MEDIA_CONTENT_ERROR_NONE;
 }
 
 int image_meta_update_to_db(image_meta_h image)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
-       media_content_warn("DEPRECATION WARNING: image_meta_update_to_db() is deprecated and will be removed from next release.");
+       content_warn("DEPRECATION WARNING: image_meta_update_to_db() is deprecated and will be removed from next release.");
        image_meta_s *_image = (image_meta_s*)image;
        char *sql = NULL;
 
-       if (_image != NULL && STRING_VALID(_image->media_id)) {
-               char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
-               memset(storage_id, 0x00, sizeof(storage_id));
-
-               ret = _media_db_get_storage_id_by_media_id(_image->media_id, storage_id);
-               media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+       content_retip_if_fail(image);
+       content_retip_if_fail(STRING_VALID(_image->media_id));
 
+#ifdef _USE_TVPD_MODE
+               char *storage_id = NULL;
+               ret = _media_db_get_storage_id_by_media_id(_image->media_id, &storage_id);
+               content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
                sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, storage_id, _image->orientation, _image->media_id);
+               g_free(storage_id);
+#else
+               sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->media_id);
+#endif
                ret = _content_query_sql(sql);
                SQLITE3_SAFE_FREE(sql);
-       } else {
-               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
 
        return ret;
 }