Remove weather in image struct
[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->burst_id);
31                 SAFE_FREE(_image->exposure_time);
32                 SAFE_FREE(_image->model);
33                 SAFE_FREE(_image);
34
35                 ret = MEDIA_CONTENT_ERROR_NONE;
36         } else {
37                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
38                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
39         }
40
41         return ret;
42 }
43
44 int image_meta_clone(image_meta_h *dst, image_meta_h src)
45 {
46         int ret = MEDIA_CONTENT_ERROR_NONE;
47         image_meta_s *_src = (image_meta_s*)src;
48
49         if (_src != NULL) {
50                 image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
51                 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
52
53                 if (STRING_VALID(_src->media_id)) {
54                         _dst->media_id = strdup(_src->media_id);
55                         if (_dst->media_id == NULL) {
56                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
57                                 image_meta_destroy((image_meta_h)_dst);
58                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
59                         }
60                 }
61
62                 if (STRING_VALID(_src->date_taken)) {
63                         _dst->date_taken = strdup(_src->date_taken);
64                         if (_dst->date_taken == NULL) {
65                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
66                                 image_meta_destroy((image_meta_h)_dst);
67                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
68                         }
69                 }
70
71                 if (STRING_VALID(_src->title)) {
72                         _dst->title = strdup(_src->title);
73                         if (_dst->title == NULL) {
74                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
75                                 image_meta_destroy((image_meta_h)_dst);
76                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
77                         }
78                 }
79
80                 if (STRING_VALID(_src->burst_id)) {
81                         _dst->burst_id = strdup(_src->burst_id);
82                         if (_dst->burst_id == NULL) {
83                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
84                                 image_meta_destroy((image_meta_h)_dst);
85                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
86                         }
87                 }
88
89                 if (STRING_VALID(_src->exposure_time)) {
90                         _dst->exposure_time = strdup(_src->exposure_time);
91                         if (_dst->exposure_time == NULL) {
92                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
93                                 image_meta_destroy((image_meta_h)_dst);
94                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
95                         }
96                 }
97
98                 if (STRING_VALID(_src->model)) {
99                         _dst->model = strdup(_src->model);
100                         if (_dst->model == NULL) {
101                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
102                                 image_meta_destroy((image_meta_h)_dst);
103                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
104                         }
105                 }
106
107                 _dst->fnumber = _src->fnumber;
108                 _dst->iso = _src->iso;
109                 _dst->width = _src->width;
110                 _dst->height = _src->height;
111                 _dst->orientation = _src->orientation;
112
113                 *dst = (image_meta_h)_dst;
114
115                 ret = MEDIA_CONTENT_ERROR_NONE;
116         } else {
117                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
118                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
119         }
120
121         return ret;
122 }
123
124 int image_meta_get_media_id(image_meta_h image, char **media_id)
125 {
126         int ret = MEDIA_CONTENT_ERROR_NONE;
127         image_meta_s *_image = (image_meta_s*)image;
128
129         if (_image && media_id) {
130                 if (STRING_VALID(_image->media_id)) {
131                         char *new_string = strdup(_image->media_id);
132                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
133
134                         *media_id = new_string;
135                 } else {
136                         *media_id = NULL;
137                 }
138                 ret = MEDIA_CONTENT_ERROR_NONE;
139
140         } else {
141                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
142                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
143         }
144
145         return ret;
146
147 }
148
149 int image_meta_get_width(image_meta_h image, int *width)
150 {
151         int ret = MEDIA_CONTENT_ERROR_NONE;
152         image_meta_s *_image = (image_meta_s*)image;
153
154         if (_image && width) {
155                 *width = _image->width;
156                 ret = MEDIA_CONTENT_ERROR_NONE;
157         } else {
158                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
159                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
160         }
161
162         return ret;
163 }
164 int image_meta_get_height(image_meta_h image, int *height)
165 {
166         int ret = MEDIA_CONTENT_ERROR_NONE;
167         image_meta_s *_image = (image_meta_s*)image;
168
169         if (_image && height) {
170                 *height = _image->height;
171                 ret = MEDIA_CONTENT_ERROR_NONE;
172         } else {
173                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
174                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
175         }
176
177         return ret;
178 }
179
180 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
181 {
182         int ret = MEDIA_CONTENT_ERROR_NONE;
183         image_meta_s *_image = (image_meta_s*)image;
184
185         if (_image && orientation) {
186                 *orientation = _image->orientation;
187                 ret = MEDIA_CONTENT_ERROR_NONE;
188         } else {
189                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
190                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
191         }
192
193         return ret;
194 }
195
196 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
197 {
198         int ret = MEDIA_CONTENT_ERROR_NONE;
199         image_meta_s *_image = (image_meta_s*)image;
200
201         if (_image && date_taken) {
202                 if (STRING_VALID(_image->date_taken)) {
203                         char *new_string = strdup(_image->date_taken);
204                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
205
206                         *date_taken = new_string;
207                 } else {
208                         *date_taken = NULL;
209                 }
210
211                 ret = MEDIA_CONTENT_ERROR_NONE;
212         } else {
213                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
214                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
215         }
216
217         return ret;
218 }
219
220 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
221 {
222         int ret = MEDIA_CONTENT_ERROR_NONE;
223         media_content_warn("DEPRECATION WARNING: image_meta_get_burst_id() is deprecated and will be removed from next release.");
224         image_meta_s *_image = (image_meta_s*)image;
225
226         if (_image && burst_id) {
227                 if (STRING_VALID(_image->burst_id)) {
228                         *burst_id = strdup(_image->burst_id);
229                         media_content_retvm_if(*burst_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
230                 } else {
231                         *burst_id = NULL;
232                 }
233                 ret = MEDIA_CONTENT_ERROR_NONE;
234         } else {
235                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
236                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
237         }
238
239         return ret;
240 }
241
242 int image_meta_get_exposure_time(image_meta_h image, char **exposure_time)
243 {
244         int ret = MEDIA_CONTENT_ERROR_NONE;
245         image_meta_s *_image = (image_meta_s*)image;
246
247         if (_image && exposure_time) {
248                 if (STRING_VALID(_image->exposure_time)) {
249                         *exposure_time = strdup(_image->exposure_time);
250                         media_content_retvm_if(*exposure_time == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
251                 } else {
252                         *exposure_time = NULL;
253                 }
254                 ret = MEDIA_CONTENT_ERROR_NONE;
255         } else {
256                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
257                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
258         }
259
260         return ret;
261 }
262
263 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
264 {
265         int ret = MEDIA_CONTENT_ERROR_NONE;
266         image_meta_s *_image = (image_meta_s*)image;
267
268         if (_image && fnumber) {
269                 *fnumber = _image->fnumber;
270                 ret = MEDIA_CONTENT_ERROR_NONE;
271         } else {
272                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
273                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
274         }
275
276         return ret;
277 }
278
279 int image_meta_get_iso(image_meta_h image, int *iso)
280 {
281         int ret = MEDIA_CONTENT_ERROR_NONE;
282         image_meta_s *_image = (image_meta_s*)image;
283
284         if (_image && iso) {
285                 *iso = _image->iso;
286                 ret = MEDIA_CONTENT_ERROR_NONE;
287         } else {
288                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
289                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
290         }
291
292         return ret;
293 }
294
295 int image_meta_get_model(image_meta_h image, char **model)
296 {
297         int ret = MEDIA_CONTENT_ERROR_NONE;
298         image_meta_s *_image = (image_meta_s*)image;
299
300         if (_image && model) {
301                 if (STRING_VALID(_image->model)) {
302                         *model = strdup(_image->model);
303                         media_content_retvm_if(*model == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
304                 } else {
305                         *model = NULL;
306                 }
307                 ret = MEDIA_CONTENT_ERROR_NONE;
308         } else {
309                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
310                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
311         }
312
313         return ret;
314 }
315
316 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
317 {
318         int ret = MEDIA_CONTENT_ERROR_NONE;
319         media_content_warn("DEPRECATION WARNING: image_meta_is_burst_shot() is deprecated and will be removed from next release.");
320         image_meta_s *_image = (image_meta_s*)image;
321
322         if (_image && is_burst_shot) {
323                 if (STRING_VALID(_image->burst_id))
324                         *is_burst_shot = true;
325                 else
326                         *is_burst_shot = false;
327
328                 ret = MEDIA_CONTENT_ERROR_NONE;
329         } else {
330                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
331                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
332         }
333
334         return ret;
335 }
336
337 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
338 {
339         int ret = MEDIA_CONTENT_ERROR_NONE;
340         media_content_warn("DEPRECATION WARNING: image_meta_set_orientation() is deprecated and will be removed from next release.");
341         image_meta_s *_image = (image_meta_s*)image;
342
343         if (_image == NULL) {
344                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
345                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
346         }
347
348         if ((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270)) {
349                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
350                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
351         }
352
353         _image->orientation = orientation;
354
355         return ret;
356 }
357
358 int image_meta_update_to_db(image_meta_h image)
359 {
360         int ret = MEDIA_CONTENT_ERROR_NONE;
361         media_content_warn("DEPRECATION WARNING: image_meta_update_to_db() is deprecated and will be removed from next release.");
362         image_meta_s *_image = (image_meta_s*)image;
363         char *sql = NULL;
364
365         if (_image != NULL && STRING_VALID(_image->media_id)) {
366                 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
367                 memset(storage_id, 0x00, sizeof(storage_id));
368
369                 ret = _media_db_get_storage_id_by_media_id(_image->media_id, storage_id);
370                 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
371
372                 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, storage_id, _image->orientation, _image->media_id);
373                 ret = _content_query_sql(sql);
374                 SQLITE3_SAFE_FREE(sql);
375         } else {
376                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
377                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
378         }
379
380         return ret;
381 }