int origin_h = 0;
int max_length = 0;
char *thumb_path = NULL;
+ int need_update_db = 0;
if (req_msg == NULL || res_msg == NULL) {
thumb_err("Invalid msg!");
media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
thumb_path = res_msg->dst_path;
+ thumb_path[0] = '\0';
max_length = sizeof(res_msg->dst_path);
+ err = _media_thumb_db_connect();
+ if (err < 0) {
+ thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
if (msg_type == THUMB_REQUEST_DB_INSERT) {
+ err = _media_thumb_get_thumb_from_db_with_size(origin_path, thumb_path, max_length, &need_update_db, &origin_w, &origin_h);
+ if (err == 0) {
+ res_msg->origin_width = origin_w;
+ res_msg->origin_width = origin_h;
+ _media_thumb_db_disconnect();
+ return MEDIA_THUMB_ERROR_NONE;
+ } else {
+ if (strlen(thumb_path) == 0) {
+ err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length);
+ if (err < 0) {
+ thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
+ strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+ _media_thumb_db_disconnect();
+ return err;
+ }
+
+ thumb_path[strlen(thumb_path)] = '\0';
+ }
+ }
+
+ } else if (msg_type == THUMB_REQUEST_SAVE_FILE) {
+ strncpy(thumb_path, req_msg->dst_path, max_length);
+
+ } else if (msg_type == THUMB_REQUEST_ALL_MEDIA) {
err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length);
if (err < 0) {
thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+ _media_thumb_db_disconnect();
return err;
}
thumb_path[strlen(thumb_path)] = '\0';
- } else if (msg_type == THUMB_REQUEST_SAVE_FILE) {
- strncpy(thumb_path, req_msg->dst_path, max_length);
}
thumb_dbg("Thumb path : %s", thumb_path);
if (g_file_test(thumb_path,
G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
- thumb_warn("thumb path already exists in file system");
- return 0;
+ thumb_warn("thumb path already exists in file system.. remove the existed file");
+ _media_thumb_remove_file(thumb_path);
}
err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h);
SAFE_FREE(data);
strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+ _media_thumb_db_disconnect();
return err;
}
thumb_err("save_to_file_with_evas failed - %d\n", err);
SAFE_FREE(data);
- if (msg_type == THUMB_REQUEST_DB_INSERT)
+ if (msg_type == THUMB_REQUEST_DB_INSERT || msg_type == THUMB_REQUEST_ALL_MEDIA)
strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+ _media_thumb_db_disconnect();
return err;
} else {
thumb_dbg("file save success\n");
/* End of fsync */
SAFE_FREE(data);
-
+
+ /* DB update if needed */
+ if (need_update_db == 1) {
+ err = _media_thumb_update_db(origin_path, thumb_path, res_msg->origin_width, res_msg->origin_height);
+ if (err < 0) {
+ thumb_err("_media_thumb_update_db failed : %d", err);
+ }
+ }
+
+ _media_thumb_db_disconnect();
+
return 0;
}
#include "media-thumb-util.h"
#include "media-thumb-internal.h"
#include "media-thumb-ipc.h"
-#include "media-thumb-db.h"
+//#include "media-thumb-db.h"
#include <glib.h>
int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length)
{
int err = -1;
- int need_update_db = 0;
+ //int need_update_db = 0;
media_thumb_info thumb_info;
if (origin_path == NULL || thumb_path == NULL) {
}
thumb_err("Path : %s", origin_path);
-
+/*
err = _media_thumb_db_connect();
if (err < 0) {
thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
_media_thumb_db_disconnect();
return MEDIA_THUMB_ERROR_NONE;
}
-
+*/
/* Request for thumb file to the daemon "Thumbnail generator" */
err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info);
if (err < 0) {
thumb_err("_media_thumb_request failed : %d", err);
- _media_thumb_db_disconnect();
+ //_media_thumb_db_disconnect();
return err;
}
-
- /* Need to update DB once generating thumb is done */
+/*
+ // Need to update DB once generating thumb is done
if (need_update_db) {
err = _media_thumb_update_db(origin_path, thumb_path, thumb_info.origin_width, thumb_info.origin_height);
if (err < 0) {
}
_media_thumb_db_disconnect();
+*/
return MEDIA_THUMB_ERROR_NONE;
}
int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height)
{
int err = -1;
- int need_update_db = 0;
- int width, height = 0;
+ //int need_update_db = 0;
media_thumb_info thumb_info;
if (origin_path == NULL || thumb_path == NULL) {
}
thumb_err("Path : %s", origin_path);
-
+/*
err = _media_thumb_db_connect();
if (err < 0) {
thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
_media_thumb_db_disconnect();
return MEDIA_THUMB_ERROR_NONE;
}
-
+*/
/* Request for thumb file to the daemon "Thumbnail generator" */
err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info);
if (err < 0) {
thumb_err("_media_thumb_request failed : %d", err);
- _media_thumb_db_disconnect();
+ //_media_thumb_db_disconnect();
return err;
}
*origin_width = thumb_info.origin_width;
*origin_height = thumb_info.origin_height;
- _media_thumb_db_disconnect();
+ //_media_thumb_db_disconnect();
return MEDIA_THUMB_ERROR_NONE;
}