modify DB schema.
[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_image.h>
19 #include <media_content.h>
20 #include <media_info_private.h>
21 #include <media-svc.h>
22
23
24 int image_meta_destroy(image_meta_h image)
25 {
26         int ret = MEDIA_CONTENT_ERROR_NONE;
27         image_meta_s *_image = (image_meta_s*)image;
28
29         if(_image)
30         {
31                 SAFE_FREE(_image->media_id);
32                 SAFE_FREE(_image->date_taken);
33                 SAFE_FREE(_image->title);
34                 SAFE_FREE(_image->weather);
35                 SAFE_FREE(_image->burst_id);
36                 SAFE_FREE(_image);
37
38                 ret = MEDIA_CONTENT_ERROR_NONE;
39         }
40         else
41         {
42                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
43                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
44         }
45
46         return ret;
47 }
48
49 int image_meta_clone(image_meta_h *dst, image_meta_h src)
50 {
51         int ret = MEDIA_CONTENT_ERROR_NONE;
52         image_meta_s *_src = (image_meta_s*)src;
53
54         if(_src != NULL)
55         {
56                 image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
57                 if(NULL == _dst)
58                 {
59                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
60                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
61                 }
62
63                 if(STRING_VALID(_src->media_id))
64                 {
65                         _dst->media_id = strdup(_src->media_id);
66                         if(_dst->media_id == NULL)
67                         {
68                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
69                                 image_meta_destroy((image_meta_h)_dst);
70                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
71                         }
72                 }
73
74                 if(STRING_VALID(_src->date_taken))
75                 {
76                         _dst->date_taken = strdup(_src->date_taken);
77                         if(_dst->date_taken == NULL)
78                         {
79                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
80                                 image_meta_destroy((image_meta_h)_dst);
81                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
82                         }
83                 }
84
85                 if(STRING_VALID(_src->title))
86                 {
87                         _dst->title = strdup(_src->title);
88                         if(_dst->title == NULL)
89                         {
90                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
91                                 image_meta_destroy((image_meta_h)_dst);
92                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
93                         }
94                 }
95
96                 if(STRING_VALID(_src->weather))
97                 {
98                         _dst->weather = strdup(_src->weather);
99                         if(_dst->weather == NULL)
100                         {
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                 if(STRING_VALID(_src->burst_id))
108                 {
109                         _dst->burst_id = strdup(_src->burst_id);
110                         if(_dst->burst_id == NULL)
111                         {
112                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
113                                 image_meta_destroy((image_meta_h)_dst);
114                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
115                         }
116                 }
117
118                 _dst->width = _src->width;
119                 _dst->height = _src->height;
120                 _dst->orientation = _src->orientation;
121
122                 *dst = (image_meta_h)_dst;
123
124                 ret = MEDIA_CONTENT_ERROR_NONE;
125         }
126         else
127         {
128                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
129                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
130         }
131
132         return ret;
133 }
134
135 int image_meta_get_media_id(image_meta_h image, char **media_id)
136 {
137         int ret = MEDIA_CONTENT_ERROR_NONE;
138         image_meta_s *_image = (image_meta_s*)image;
139
140         if(_image && media_id)
141         {
142                 if(STRING_VALID(_image->media_id))
143                 {
144                         char *new_string = strdup(_image->media_id);
145                         if(NULL == new_string)
146                         {
147                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
148                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
149                         }
150                         *media_id = new_string;
151                 }
152                 else
153                 {
154                         *media_id = NULL;
155                 }
156                 ret = MEDIA_CONTENT_ERROR_NONE;
157
158         }
159         else
160         {
161                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
162                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
163         }
164
165         return ret;
166
167 }
168
169 int image_meta_get_width(image_meta_h image, int *width)
170 {
171         int ret = MEDIA_CONTENT_ERROR_NONE;
172         image_meta_s *_image = (image_meta_s*)image;
173
174         if(_image && width)
175         {
176                 *width = _image->width;
177                 ret = MEDIA_CONTENT_ERROR_NONE;
178         }
179         else
180         {
181                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
182                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
183         }
184
185         return ret;
186 }
187 int image_meta_get_height(image_meta_h image, int *height)
188 {
189         int ret = MEDIA_CONTENT_ERROR_NONE;
190         image_meta_s *_image = (image_meta_s*)image;
191
192         if(_image && height)
193         {
194                 *height = _image->height;
195                 ret = MEDIA_CONTENT_ERROR_NONE;
196         }
197         else
198         {
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_orientation(image_meta_h image, media_content_orientation_e* orientation)
207 {
208         int ret = MEDIA_CONTENT_ERROR_NONE;
209         image_meta_s *_image = (image_meta_s*)image;
210
211         if(_image && orientation)
212         {
213                 *orientation = _image->orientation;
214                 ret = MEDIA_CONTENT_ERROR_NONE;
215         }
216         else
217         {
218                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
219                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
220         }
221
222         return ret;
223 }
224
225 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
226 {
227         int ret = MEDIA_CONTENT_ERROR_NONE;
228         image_meta_s *_image = (image_meta_s*)image;
229
230         if(_image && date_taken)
231         {
232                 if(STRING_VALID(_image->date_taken))
233                 {
234                         char *new_string = strdup(_image->date_taken);
235                         if(NULL == new_string)
236                         {
237                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
238                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
239                         }
240                         *date_taken = new_string;
241                 }
242                 else
243                 {
244                         *date_taken = NULL;
245                 }
246
247                 ret = MEDIA_CONTENT_ERROR_NONE;
248         }
249         else
250         {
251                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
252                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
253         }
254
255         return ret;
256 }
257
258 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
259 {
260         int ret = MEDIA_CONTENT_ERROR_NONE;
261         image_meta_s *_image = (image_meta_s*)image;
262
263         if(_image && burst_id)
264         {
265                 if(STRING_VALID(_image->burst_id))
266                 {
267                         *burst_id = strdup(_image->burst_id);
268                         if(*burst_id == NULL)
269                         {
270                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
271                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
272                         }
273                 }
274                 else
275                 {
276                         *burst_id = NULL;
277                 }
278                 ret = MEDIA_CONTENT_ERROR_NONE;
279         }
280         else
281         {
282                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
283                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
284         }
285
286         return ret;
287 }
288
289 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
290 {
291         int ret = MEDIA_CONTENT_ERROR_NONE;
292         image_meta_s *_image = (image_meta_s*)image;
293
294         if(_image && is_burst_shot)
295         {
296                 if(STRING_VALID(_image->burst_id))
297                         *is_burst_shot = true;
298                 else
299                         *is_burst_shot = false;
300
301                 ret = MEDIA_CONTENT_ERROR_NONE;
302         }
303         else
304         {
305                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
306                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
307         }
308
309         return ret;
310 }
311
312 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
313 {
314         int ret = MEDIA_CONTENT_ERROR_NONE;
315         image_meta_s *_image = (image_meta_s*)image;
316
317         if(_image == NULL)
318         {
319                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
320                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
321         }
322
323         if((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270))
324         {
325                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
326                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
327         }
328
329         _image->orientation = orientation;
330
331         return ret;
332 }
333
334 int image_meta_update_to_db(image_meta_h image)
335 {
336         int ret = MEDIA_CONTENT_ERROR_NONE;
337         image_meta_s *_image = (image_meta_s*)image;
338         char *sql = NULL;
339
340         if(_image != NULL && STRING_VALID(_image->media_id))
341         {
342                 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->weather, _image->media_id);
343                 ret = _content_query_sql(sql);
344                 sqlite3_free(sql);
345         }
346         else
347         {
348                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
349                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
350         }
351
352         return ret;
353 }