ACR-436 Modify getter API return value from Unknown to empty string()
[platform/core/api/media-content.git] / src / media_image.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #include <media_info_private.h>
19
20
21 int image_meta_destroy(image_meta_h image)
22 {
23         int ret = MEDIA_CONTENT_ERROR_NONE;
24         image_meta_s *_image = (image_meta_s*)image;
25
26         if (_image) {
27                 SAFE_FREE(_image->media_id);
28                 SAFE_FREE(_image->date_taken);
29                 SAFE_FREE(_image->title);
30                 SAFE_FREE(_image->weather);
31                 SAFE_FREE(_image->burst_id);
32                 SAFE_FREE(_image->exposure_time);
33                 SAFE_FREE(_image->model);
34                 SAFE_FREE(_image);
35
36                 ret = MEDIA_CONTENT_ERROR_NONE;
37         } else {
38                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
39                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
40         }
41
42         return ret;
43 }
44
45 int image_meta_clone(image_meta_h *dst, image_meta_h src)
46 {
47         int ret = MEDIA_CONTENT_ERROR_NONE;
48         image_meta_s *_src = (image_meta_s*)src;
49
50         if (_src != NULL) {
51                 image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
52                 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
53
54                 if (STRING_VALID(_src->media_id)) {
55                         _dst->media_id = strdup(_src->media_id);
56                         if (_dst->media_id == NULL) {
57                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
58                                 image_meta_destroy((image_meta_h)_dst);
59                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
60                         }
61                 }
62
63                 if (STRING_VALID(_src->date_taken)) {
64                         _dst->date_taken = strdup(_src->date_taken);
65                         if (_dst->date_taken == NULL) {
66                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
67                                 image_meta_destroy((image_meta_h)_dst);
68                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
69                         }
70                 }
71
72                 if (STRING_VALID(_src->title)) {
73                         _dst->title = strdup(_src->title);
74                         if (_dst->title == NULL) {
75                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
76                                 image_meta_destroy((image_meta_h)_dst);
77                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
78                         }
79                 }
80
81                 if (STRING_VALID(_src->weather)) {
82                         _dst->weather = strdup(_src->weather);
83                         if (_dst->weather == NULL) {
84                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
85                                 image_meta_destroy((image_meta_h)_dst);
86                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
87                         }
88                 }
89
90                 if (STRING_VALID(_src->burst_id)) {
91                         _dst->burst_id = strdup(_src->burst_id);
92                         if (_dst->burst_id == NULL) {
93                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
94                                 image_meta_destroy((image_meta_h)_dst);
95                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
96                         }
97                 }
98
99                 if (STRING_VALID(_src->exposure_time)) {
100                         _dst->exposure_time = strdup(_src->exposure_time);
101                         if (_dst->exposure_time == NULL) {
102                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
103                                 image_meta_destroy((image_meta_h)_dst);
104                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
105                         }
106                 }
107
108                 if (STRING_VALID(_src->model)) {
109                         _dst->model = strdup(_src->model);
110                         if (_dst->model == NULL) {
111                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
112                                 image_meta_destroy((image_meta_h)_dst);
113                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
114                         }
115                 }
116
117                 _dst->fnumber = _src->fnumber;
118                 _dst->iso = _src->iso;
119                 _dst->width = _src->width;
120                 _dst->height = _src->height;
121                 _dst->orientation = _src->orientation;
122
123                 *dst = (image_meta_h)_dst;
124
125                 ret = MEDIA_CONTENT_ERROR_NONE;
126         } else {
127                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
128                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
129         }
130
131         return ret;
132 }
133
134 int image_meta_get_media_id(image_meta_h image, char **media_id)
135 {
136         int ret = MEDIA_CONTENT_ERROR_NONE;
137         image_meta_s *_image = (image_meta_s*)image;
138
139         if (_image && media_id) {
140                 if (STRING_VALID(_image->media_id)) {
141                         char *new_string = strdup(_image->media_id);
142                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
143
144                         *media_id = new_string;
145                 } else {
146                         *media_id = NULL;
147                 }
148                 ret = MEDIA_CONTENT_ERROR_NONE;
149
150         } else {
151                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
152                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
153         }
154
155         return ret;
156
157 }
158
159 int image_meta_get_width(image_meta_h image, int *width)
160 {
161         int ret = MEDIA_CONTENT_ERROR_NONE;
162         image_meta_s *_image = (image_meta_s*)image;
163
164         if (_image && width) {
165                 *width = _image->width;
166                 ret = MEDIA_CONTENT_ERROR_NONE;
167         } else {
168                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
169                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
170         }
171
172         return ret;
173 }
174 int image_meta_get_height(image_meta_h image, int *height)
175 {
176         int ret = MEDIA_CONTENT_ERROR_NONE;
177         image_meta_s *_image = (image_meta_s*)image;
178
179         if (_image && height) {
180                 *height = _image->height;
181                 ret = MEDIA_CONTENT_ERROR_NONE;
182         } else {
183                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
184                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
185         }
186
187         return ret;
188 }
189
190 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
191 {
192         int ret = MEDIA_CONTENT_ERROR_NONE;
193         image_meta_s *_image = (image_meta_s*)image;
194
195         if (_image && orientation) {
196                 *orientation = _image->orientation;
197                 ret = MEDIA_CONTENT_ERROR_NONE;
198         } else {
199                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
200                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
201         }
202
203         return ret;
204 }
205
206 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
207 {
208         int ret = MEDIA_CONTENT_ERROR_NONE;
209         image_meta_s *_image = (image_meta_s*)image;
210
211         if (_image && date_taken) {
212                 if (STRING_VALID(_image->date_taken)) {
213                         char *new_string = strdup(_image->date_taken);
214                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
215
216                         *date_taken = new_string;
217                 } else {
218                         *date_taken = NULL;
219                 }
220
221                 ret = MEDIA_CONTENT_ERROR_NONE;
222         } else {
223                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
224                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
225         }
226
227         return ret;
228 }
229
230 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
231 {
232         int ret = MEDIA_CONTENT_ERROR_NONE;
233         image_meta_s *_image = (image_meta_s*)image;
234
235         if (_image && burst_id) {
236                 if (STRING_VALID(_image->burst_id)) {
237                         *burst_id = strdup(_image->burst_id);
238                         media_content_retvm_if(*burst_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
239                 } else {
240                         *burst_id = NULL;
241                 }
242                 ret = MEDIA_CONTENT_ERROR_NONE;
243         } else {
244                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
245                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
246         }
247
248         return ret;
249 }
250
251 int image_meta_get_exposure_time(image_meta_h image, char **exposure_time)
252 {
253         int ret = MEDIA_CONTENT_ERROR_NONE;
254         image_meta_s *_image = (image_meta_s*)image;
255
256         if (_image && exposure_time) {
257                 if (STRING_VALID(_image->exposure_time)) {
258                         *exposure_time = strdup(_image->exposure_time);
259                         media_content_retvm_if(*exposure_time == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
260                 } else {
261                         *exposure_time = NULL;
262                 }
263                 ret = MEDIA_CONTENT_ERROR_NONE;
264         } else {
265                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
266                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
267         }
268
269         return ret;
270 }
271
272 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
273 {
274         int ret = MEDIA_CONTENT_ERROR_NONE;
275         image_meta_s *_image = (image_meta_s*)image;
276
277         if (_image && fnumber) {
278                 *fnumber = _image->fnumber;
279                 ret = MEDIA_CONTENT_ERROR_NONE;
280         } else {
281                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
282                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
283         }
284
285         return ret;
286 }
287
288 int image_meta_get_iso(image_meta_h image, int *iso)
289 {
290         int ret = MEDIA_CONTENT_ERROR_NONE;
291         image_meta_s *_image = (image_meta_s*)image;
292
293         if (_image && iso) {
294                 *iso = _image->iso;
295                 ret = MEDIA_CONTENT_ERROR_NONE;
296         } else {
297                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
298                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
299         }
300
301         return ret;
302 }
303
304 int image_meta_get_model(image_meta_h image, char **model)
305 {
306         int ret = MEDIA_CONTENT_ERROR_NONE;
307         image_meta_s *_image = (image_meta_s*)image;
308
309         if (_image && model) {
310                 if (STRING_VALID(_image->model)) {
311                         *model = strdup(_image->model);
312                         media_content_retvm_if(*model == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
313                 } else {
314                         *model = NULL;
315                 }
316                 ret = MEDIA_CONTENT_ERROR_NONE;
317         } else {
318                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
319                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
320         }
321
322         return ret;
323 }
324
325 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
326 {
327         int ret = MEDIA_CONTENT_ERROR_NONE;
328         image_meta_s *_image = (image_meta_s*)image;
329
330         if (_image && is_burst_shot) {
331                 if (STRING_VALID(_image->burst_id))
332                         *is_burst_shot = true;
333                 else
334                         *is_burst_shot = false;
335
336                 ret = MEDIA_CONTENT_ERROR_NONE;
337         } else {
338                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
339                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
340         }
341
342         return ret;
343 }
344
345 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
346 {
347         int ret = MEDIA_CONTENT_ERROR_NONE;
348         image_meta_s *_image = (image_meta_s*)image;
349
350         if (_image == NULL) {
351                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
352                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
353         }
354
355         if ((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270)) {
356                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
357                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
358         }
359
360         _image->orientation = orientation;
361
362         return ret;
363 }
364
365 int image_meta_update_to_db(image_meta_h image)
366 {
367         int ret = MEDIA_CONTENT_ERROR_NONE;
368         image_meta_s *_image = (image_meta_s*)image;
369         char *sql = NULL;
370
371         if (_image != NULL && STRING_VALID(_image->media_id)) {
372                 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
373                 memset(storage_id, 0x00, sizeof(storage_id));
374
375                 ret = _media_db_get_storage_id_by_media_id(_image->media_id, storage_id);
376                 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
377
378                 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, storage_id, _image->orientation, _image->weather, _image->media_id);
379                 ret = _content_query_sql(sql);
380                 SQLITE3_SAFE_FREE(sql);
381         } else {
382                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
383                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
384         }
385
386         return ret;
387 }