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