4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include "media-thumbnail.h"
23 #include "media-thumb-debug.h"
24 #include "media-thumb-util.h"
25 #include "media-thumb-internal.h"
26 #include "media-thumb-ipc.h"
30 int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length, uid_t uid)
32 int err = MS_MEDIA_ERR_NONE;
34 if (origin_path == NULL || thumb_path == NULL) {
35 thumb_err("Invalid parameter");
36 return MS_MEDIA_ERR_INVALID_PARAMETER;
39 if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
40 thumb_err("Original path(%s) doesn't exist.", origin_path);
41 return MS_MEDIA_ERR_INVALID_PARAMETER;
44 if (max_length <= 0) {
45 thumb_err("Length is invalid");
46 return MS_MEDIA_ERR_INVALID_PARAMETER;
49 ms_user_storage_type_t store_type = -1;
50 err = ms_user_get_storage_type(uid, origin_path, &store_type);
52 if((err != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) {
53 thumb_err_slog("origin path(%s) is invalid. err : [%d] store_type [%d]", origin_path, err, store_type);
54 return MS_MEDIA_ERR_INVALID_PARAMETER;
57 thumb_dbg_slog("Path : %s", origin_path);
59 /* Request for thumb file to the daemon "Thumbnail generator" */
60 err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, origin_path, thumb_path, max_length, uid);
61 if (err != MS_MEDIA_ERR_NONE) {
62 thumb_err("_media_thumb_request failed : %d", err);
66 return MS_MEDIA_ERR_NONE;
69 int thumbnail_request_from_db_async(unsigned int request_id, const char *origin_path, ThumbFunc func, void *user_data, uid_t uid)
71 int err = MS_MEDIA_ERR_NONE;
73 if (origin_path == NULL) {
74 thumb_err("Invalid parameter");
75 return MS_MEDIA_ERR_INVALID_PARAMETER;
78 if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
79 thumb_err("Original path(%s) doesn't exist.", origin_path);
80 return MS_MEDIA_ERR_INVALID_PARAMETER;
83 ms_user_storage_type_t store_type = -1;
84 err = ms_user_get_storage_type(uid, origin_path, &store_type);
86 if((err != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) {
87 thumb_err_slog("origin path(%s) is invalid. err : [%d] store_type [%d]", origin_path, err, store_type);
88 return MS_MEDIA_ERR_INVALID_PARAMETER;
91 thumb_dbg_slog("Path : %s", origin_path);
93 thumbUserData *userData = (thumbUserData*)malloc(sizeof(thumbUserData));
94 if (userData == NULL) {
95 thumb_err("memory allocation failed");
96 return MS_MEDIA_ERR_OUT_OF_MEMORY;
98 userData->func = (ThumbFunc)func;
99 userData->user_data = user_data;
101 /* Request for thumb file to the daemon "Thumbnail generator" */
102 err = _media_thumb_request_async(THUMB_REQUEST_DB_INSERT, request_id, origin_path, userData, uid);
103 if (err != MS_MEDIA_ERR_NONE) {
104 thumb_err("_media_thumb_request failed : %d", err);
109 return MS_MEDIA_ERR_NONE;
112 int thumbnail_request_extract_raw_data_async(int request_id, const char *origin_path, int width, int height, ThumbRawFunc func, void *user_data, uid_t uid)
114 int err = MS_MEDIA_ERR_NONE;
117 if (origin_path == NULL || request_id == 0) {
118 thumb_err("original path is NULL. Or there is an error in request_id.");
119 return MS_MEDIA_ERR_INVALID_PARAMETER;
122 /* check the file exits actually */
123 exist = open(origin_path, O_RDONLY);
125 thumb_err("Fail to open original_path[%s]", origin_path);
126 if (errno == EACCES || errno == EPERM)
127 return MS_MEDIA_ERR_PERMISSION_DENIED;
129 return MS_MEDIA_ERR_INVALID_PARAMETER;
133 thumb_dbg_slog("Path : %s", origin_path);
135 thumbRawUserData *userData = (thumbRawUserData*)malloc(sizeof(thumbRawUserData));
136 if (userData == NULL) {
137 thumb_err("userData malloc failed : %d", err);
138 return MS_MEDIA_ERR_OUT_OF_MEMORY;
140 userData->func = func;
141 userData->user_data = user_data;
143 err = _media_thumb_request_raw_data_async(THUMB_REQUEST_RAW_DATA, request_id, origin_path, width, height, userData, uid);
144 if (err != MS_MEDIA_ERR_NONE) {
145 thumb_err("_media_raw_thumb_request failed : %d", err);
150 return MS_MEDIA_ERR_NONE;
153 int thumbnail_request_cancel_media(unsigned int request_id, const char *origin_path)
155 int err = MS_MEDIA_ERR_NONE;
157 if (origin_path == NULL) {
158 thumb_err("Invalid parameter");
159 return MS_MEDIA_ERR_INVALID_PARAMETER;
162 err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, request_id, origin_path, NULL, 0);
163 if (err != MS_MEDIA_ERR_NONE) {
164 thumb_err("_media_thumb_request failed : %d", err);
168 return MS_MEDIA_ERR_NONE;
171 int thumbnail_request_cancel_raw_data(int request_id)
173 int err = MS_MEDIA_ERR_NONE;
175 if (request_id == 0) {
176 thumb_err("Invalid parameter");
177 return MS_MEDIA_ERR_INVALID_PARAMETER;
180 err = _media_thumb_request_raw_data_async(THUMB_REQUEST_CANCEL_RAW_DATA, request_id, NULL, 0, 0, NULL, 0);
181 if (err != MS_MEDIA_ERR_NONE) {
182 thumb_err("_media_thumb_request failed : %d", err);
186 return MS_MEDIA_ERR_NONE;
189 int thumbnail_request_cancel_all(bool is_raw_data)
191 int err = MS_MEDIA_ERR_NONE;
194 err = _media_thumb_request_cancel_all(true);
196 err = _media_thumb_request_cancel_all(false);