1 /* Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
24 typedef struct _maps_place_image_s
30 maps_place_media_h media;
31 maps_place_link_object_h user;
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;
37 /*----------------------------------------------------------------------------*/
39 EXPORT_API int maps_place_image_create(maps_place_image_h *place)
41 if (!maps_condition_check_maps_feature())
42 return MAPS_ERROR_NOT_SUPPORTED;
44 return MAPS_ERROR_INVALID_PARAMETER;
45 *place = (maps_place_image_h) g_slice_new0(maps_place_image_s);
49 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
50 return MAPS_ERROR_OUT_OF_MEMORY;
54 return MAPS_ERROR_NONE;
57 EXPORT_API int maps_place_image_destroy(maps_place_image_h place)
59 if (!maps_condition_check_maps_feature())
60 return MAPS_ERROR_NOT_SUPPORTED;
62 return MAPS_ERROR_INVALID_PARAMETER;
64 maps_place_image_s *i = (maps_place_image_s *) place;
72 maps_place_media_destroy(i->media);
74 maps_place_link_object_destroy(i->user);
76 g_slice_free(maps_place_image_s, place);
77 return MAPS_ERROR_NONE;
80 EXPORT_API int maps_place_image_clone(const maps_place_image_h origin,
81 maps_place_image_h *cloned)
83 if (!maps_condition_check_maps_feature())
84 return MAPS_ERROR_NOT_SUPPORTED;
85 if (!cloned || !origin)
86 return MAPS_ERROR_INVALID_PARAMETER;
88 int error = MAPS_ERROR_NONE;
90 error = maps_place_image_create(cloned);
91 if (!(*cloned) || (error != MAPS_ERROR_NONE))
94 maps_place_image_s *i = (maps_place_image_s *) origin;
97 error = maps_place_image_set_id(*cloned, i->id);
98 if (error != MAPS_ERROR_NONE)
103 error = maps_place_image_set_url(*cloned, i->url);
104 if (error != MAPS_ERROR_NONE)
108 error = maps_place_image_set_width(*cloned, i->width);
109 if (error != MAPS_ERROR_NONE)
112 error = maps_place_image_set_height(*cloned, i->height);
113 if (error != MAPS_ERROR_NONE)
117 error = maps_place_image_set_media(*cloned, i->media);
118 if (error != MAPS_ERROR_NONE)
123 error = maps_place_image_set_user_link(*cloned, i->user);
124 if (error != MAPS_ERROR_NONE)
128 return MAPS_ERROR_NONE;
132 maps_place_image_destroy(*cloned);
138 /*----------------------------------------------------------------------------*/
140 EXPORT_API int maps_place_image_get_url(const maps_place_image_h place, char **url)
142 if (!maps_condition_check_maps_feature())
143 return MAPS_ERROR_NOT_SUPPORTED;
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);
152 EXPORT_API int maps_place_image_get_id(const maps_place_image_h place, char **id)
154 if (!maps_condition_check_maps_feature())
155 return MAPS_ERROR_NOT_SUPPORTED;
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);
164 EXPORT_API int maps_place_image_get_width(const maps_place_image_h place, int *width)
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;
176 EXPORT_API int maps_place_image_get_height(const maps_place_image_h place, int *height)
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;
188 EXPORT_API int maps_place_image_get_user_link(const maps_place_image_h place,
189 maps_place_link_object_h *user)
191 if (!maps_condition_check_maps_feature())
192 return MAPS_ERROR_NOT_SUPPORTED;
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);
200 EXPORT_API int maps_place_image_get_media(const maps_place_image_h place,
201 maps_place_media_h *media)
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);
212 /*----------------------------------------------------------------------------*/
214 EXPORT_API int maps_place_image_set_id(maps_place_image_h place, const char *id)
216 if (!maps_condition_check_maps_feature())
217 return MAPS_ERROR_NOT_SUPPORTED;
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);
224 EXPORT_API int maps_place_image_set_url(maps_place_image_h place,
227 if (!maps_condition_check_maps_feature())
228 return MAPS_ERROR_NOT_SUPPORTED;
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);
235 EXPORT_API int maps_place_image_set_width(maps_place_image_h place,
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;
246 EXPORT_API int maps_place_image_set_height(maps_place_image_h place,
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;
257 EXPORT_API int maps_place_image_set_user_link(maps_place_image_h place,
258 const maps_place_link_object_h
261 if (!maps_condition_check_maps_feature())
262 return MAPS_ERROR_NOT_SUPPORTED;
264 return MAPS_ERROR_INVALID_PARAMETER;
265 maps_place_image_s *i = (maps_place_image_s *) place;
267 maps_place_link_object_destroy(i->user);
268 return maps_place_link_object_clone(user, &i->user);
271 EXPORT_API int maps_place_image_set_media(maps_place_image_h place,
272 const maps_place_media_h media)
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;
280 maps_place_media_destroy(i->media);
281 return maps_place_media_clone(media, &i->media);