Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / api / maps_place_image.cpp
1 /* Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <glib.h>
17 #include "maps_error.h"
18 #include "maps_place_image_plugin.h"
19 #include "maps_place_media_plugin.h"
20 #include "maps_place_link_object_plugin.h"
21 #include "maps_util.h"
22 #include "maps_condition.h"
23
24 typedef struct _maps_place_image_s
25 {
26         char *id;
27         char *url;
28         int width;
29         int height;
30         maps_place_media_h media;
31         maps_place_link_object_h user;
32 } maps_place_image_s;
33
34 const gsize _MAPS_PLACE_IMAGE_ID_MAX_LENGTH = MAPS_BASE_ID_MAX_LEN;
35 const gsize _MAPS_PLACE_IMAGE_URL_MAX_LENGTH = MAPS_BASE_URL_MAX_LEN;
36
37 /*----------------------------------------------------------------------------*/
38
39 EXPORT_API int maps_place_image_create(maps_place_image_h *place)
40 {
41         if (!maps_condition_check_maps_feature())
42                 return MAPS_ERROR_NOT_SUPPORTED;
43         if (!place)
44                 return MAPS_ERROR_INVALID_PARAMETER;
45         *place = (maps_place_image_h) g_slice_new0(maps_place_image_s);
46
47         if (*place == NULL) {
48                 //LCOV_EXCL_START
49                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
50                 return MAPS_ERROR_OUT_OF_MEMORY;
51                 //LCOV_EXCL_STOP
52         }
53
54         return MAPS_ERROR_NONE;
55 }
56
57 EXPORT_API int maps_place_image_destroy(maps_place_image_h place)
58 {
59         if (!maps_condition_check_maps_feature())
60                 return MAPS_ERROR_NOT_SUPPORTED;
61         if (!place)
62                 return MAPS_ERROR_INVALID_PARAMETER;
63
64         maps_place_image_s *i = (maps_place_image_s *) place;
65
66         if (i->id)
67                 g_free(i->id);
68         if (i->url)
69                 g_free(i->url);
70
71         if (i->media)
72                 maps_place_media_destroy(i->media);
73         if (i->user)
74                 maps_place_link_object_destroy(i->user);
75
76         g_slice_free(maps_place_image_s, place);
77         return MAPS_ERROR_NONE;
78 }
79
80 EXPORT_API int maps_place_image_clone(const maps_place_image_h origin,
81                                       maps_place_image_h *cloned)
82 {
83         if (!maps_condition_check_maps_feature())
84                 return MAPS_ERROR_NOT_SUPPORTED;
85         if (!cloned || !origin)
86                 return MAPS_ERROR_INVALID_PARAMETER;
87
88         int error = MAPS_ERROR_NONE;
89         do {
90                 error = maps_place_image_create(cloned);
91                 if (!(*cloned) || (error != MAPS_ERROR_NONE))
92                         break;
93
94                 maps_place_image_s *i = (maps_place_image_s *) origin;
95
96                 if (i->id) {
97                         error = maps_place_image_set_id(*cloned, i->id);
98                         if (error != MAPS_ERROR_NONE)
99                                 break;
100                 }
101
102                 if (i->url) {
103                         error = maps_place_image_set_url(*cloned, i->url);
104                         if (error != MAPS_ERROR_NONE)
105                                 break;
106                 }
107
108                 error = maps_place_image_set_width(*cloned, i->width);
109                 if (error != MAPS_ERROR_NONE)
110                         break;
111
112                 error = maps_place_image_set_height(*cloned, i->height);
113                 if (error != MAPS_ERROR_NONE)
114                         break;
115
116                 if (i->media) {
117                         error = maps_place_image_set_media(*cloned, i->media);
118                         if (error != MAPS_ERROR_NONE)
119                                 break;
120                 }
121
122                 if (i->user) {
123                         error = maps_place_image_set_user_link(*cloned, i->user);
124                         if (error != MAPS_ERROR_NONE)
125                                 break;
126                 }
127
128                 return MAPS_ERROR_NONE;
129         } while (false);
130
131         //LCOV_EXCL_START
132         maps_place_image_destroy(*cloned);
133         *cloned = NULL;
134         return error;
135         //LCOV_EXCL_STOP
136 }
137
138 /*----------------------------------------------------------------------------*/
139
140 EXPORT_API int maps_place_image_get_url(const maps_place_image_h place, char **url)
141 {
142         if (!maps_condition_check_maps_feature())
143                 return MAPS_ERROR_NOT_SUPPORTED;
144         if (!place || !url)
145                 return MAPS_ERROR_INVALID_PARAMETER;
146         if (!((maps_place_image_s *) place)->url)
147                 return MAPS_ERROR_NOT_FOUND;
148         return maps_get_string(((maps_place_image_s *) place)->url,
149                 _MAPS_PLACE_IMAGE_URL_MAX_LENGTH, url);
150 }
151
152 EXPORT_API int maps_place_image_get_id(const maps_place_image_h place, char **id)
153 {
154         if (!maps_condition_check_maps_feature())
155                 return MAPS_ERROR_NOT_SUPPORTED;
156         if (!place || !id)
157                 return MAPS_ERROR_INVALID_PARAMETER;
158         if (!((maps_place_image_s *) place)->id)
159                 return MAPS_ERROR_NOT_FOUND;
160         return maps_get_string(((maps_place_image_s *) place)->id,
161                 _MAPS_PLACE_IMAGE_ID_MAX_LENGTH, id);
162 }
163
164 EXPORT_API int maps_place_image_get_width(const maps_place_image_h place, int *width)
165 {
166         if (!maps_condition_check_maps_feature())
167                 return MAPS_ERROR_NOT_SUPPORTED;
168         if (!place || !width)
169                 return MAPS_ERROR_INVALID_PARAMETER;
170         if (!((maps_place_image_s *) place)->width)
171                 return MAPS_ERROR_NOT_FOUND;
172         *width = ((maps_place_image_s *) place)->width;
173         return MAPS_ERROR_NONE;
174 }
175
176 EXPORT_API int maps_place_image_get_height(const maps_place_image_h place, int *height)
177 {
178         if (!maps_condition_check_maps_feature())
179                 return MAPS_ERROR_NOT_SUPPORTED;
180         if (!place || !height)
181                 return MAPS_ERROR_INVALID_PARAMETER;
182         if (!((maps_place_image_s *) place)->height)
183                 return MAPS_ERROR_NOT_FOUND;
184         *height = ((maps_place_image_s *) place)->height;
185         return MAPS_ERROR_NONE;
186 }
187
188 EXPORT_API int maps_place_image_get_user_link(const maps_place_image_h place,
189                                               maps_place_link_object_h *user)
190 {
191         if (!maps_condition_check_maps_feature())
192                 return MAPS_ERROR_NOT_SUPPORTED;
193         if (!place || !user)
194                 return MAPS_ERROR_INVALID_PARAMETER;
195         if (!((maps_place_image_s *) place)->user)
196                 return MAPS_ERROR_NOT_FOUND;
197         return maps_place_link_object_clone(((maps_place_image_s *) place)->user, user);
198 }
199
200 EXPORT_API int maps_place_image_get_media(const maps_place_image_h place,
201                                           maps_place_media_h *media)
202 {
203         if (!maps_condition_check_maps_feature())
204                 return MAPS_ERROR_NOT_SUPPORTED;
205         if (!place || !media)
206                 return MAPS_ERROR_INVALID_PARAMETER;
207         if (!((maps_place_image_s *) place)->media)
208                 return MAPS_ERROR_NOT_FOUND;
209         return maps_place_media_clone(((maps_place_image_s *) place)->media, media);
210 }
211
212 /*----------------------------------------------------------------------------*/
213
214 EXPORT_API int maps_place_image_set_id(maps_place_image_h place, const char *id)
215 {
216         if (!maps_condition_check_maps_feature())
217                 return MAPS_ERROR_NOT_SUPPORTED;
218         if (!place || !id)
219                 return MAPS_ERROR_INVALID_PARAMETER;
220         return maps_set_string(id, _MAPS_PLACE_IMAGE_ID_MAX_LENGTH,
221                 &((maps_place_image_s *) place)->id);
222 }
223
224 EXPORT_API int maps_place_image_set_url(maps_place_image_h place,
225                                         const char *url)
226 {
227         if (!maps_condition_check_maps_feature())
228                 return MAPS_ERROR_NOT_SUPPORTED;
229         if (!place || !url)
230                 return MAPS_ERROR_INVALID_PARAMETER;
231         return maps_set_string(url, _MAPS_PLACE_IMAGE_URL_MAX_LENGTH,
232                 &((maps_place_image_s *) place)->url);
233 }
234
235 EXPORT_API int maps_place_image_set_width(maps_place_image_h place,
236                                           const int width)
237 {
238         if (!maps_condition_check_maps_feature())
239                 return MAPS_ERROR_NOT_SUPPORTED;
240         if (!place || width < 0)
241                 return MAPS_ERROR_INVALID_PARAMETER;
242         ((maps_place_image_s *) place)->width = width;
243         return MAPS_ERROR_NONE;
244 }
245
246 EXPORT_API int maps_place_image_set_height(maps_place_image_h place,
247                                            const int height)
248 {
249         if (!maps_condition_check_maps_feature())
250                 return MAPS_ERROR_NOT_SUPPORTED;
251         if (!place || height < 0)
252                 return MAPS_ERROR_INVALID_PARAMETER;
253         ((maps_place_image_s *) place)->height = height;
254         return MAPS_ERROR_NONE;
255 }
256
257 EXPORT_API int maps_place_image_set_user_link(maps_place_image_h place,
258                                               const maps_place_link_object_h
259                                               user)
260 {
261         if (!maps_condition_check_maps_feature())
262                 return MAPS_ERROR_NOT_SUPPORTED;
263         if (!place || !user)
264                 return MAPS_ERROR_INVALID_PARAMETER;
265         maps_place_image_s *i = (maps_place_image_s *) place;
266         if (i->user)
267                 maps_place_link_object_destroy(i->user);
268         return maps_place_link_object_clone(user, &i->user);
269 }
270
271 EXPORT_API int maps_place_image_set_media(maps_place_image_h place,
272                                           const maps_place_media_h media)
273 {
274         if (!maps_condition_check_maps_feature())
275                 return MAPS_ERROR_NOT_SUPPORTED;
276         if (!place || !media)
277                 return MAPS_ERROR_INVALID_PARAMETER;
278         maps_place_image_s *i = (maps_place_image_s *) place;
279         if (i->media)
280                 maps_place_media_destroy(i->media);
281         return maps_place_media_clone(media, &i->media);
282 }