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);
48 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
49 return MAPS_ERROR_OUT_OF_MEMORY;
52 return MAPS_ERROR_NONE;
55 EXPORT_API int maps_place_image_destroy(maps_place_image_h place)
57 if (!maps_condition_check_maps_feature())
58 return MAPS_ERROR_NOT_SUPPORTED;
60 return MAPS_ERROR_INVALID_PARAMETER;
62 maps_place_image_s *i = (maps_place_image_s *) place;
70 maps_place_media_destroy(i->media);
72 maps_place_link_object_destroy(i->user);
74 g_slice_free(maps_place_image_s, place);
75 return MAPS_ERROR_NONE;
78 EXPORT_API int maps_place_image_clone(const maps_place_image_h origin,
79 maps_place_image_h *cloned)
81 if (!maps_condition_check_maps_feature())
82 return MAPS_ERROR_NOT_SUPPORTED;
83 if (!cloned || !origin)
84 return MAPS_ERROR_INVALID_PARAMETER;
86 int error = MAPS_ERROR_NONE;
88 error = maps_place_image_create(cloned);
89 if (!(*cloned) || (error != MAPS_ERROR_NONE))
92 maps_place_image_s *i = (maps_place_image_s *) origin;
95 error = maps_place_image_set_id(*cloned, i->id);
96 if (error != MAPS_ERROR_NONE)
101 error = maps_place_image_set_url(*cloned, i->url);
102 if (error != MAPS_ERROR_NONE)
106 error = maps_place_image_set_width(*cloned, i->width);
107 if (error != MAPS_ERROR_NONE)
110 error = maps_place_image_set_height(*cloned, i->height);
111 if (error != MAPS_ERROR_NONE)
115 error = maps_place_image_set_media(*cloned, i->media);
116 if (error != MAPS_ERROR_NONE)
121 error = maps_place_image_set_user_link(*cloned, i->user);
122 if (error != MAPS_ERROR_NONE)
126 return MAPS_ERROR_NONE;
129 maps_place_image_destroy(*cloned);
134 /*----------------------------------------------------------------------------*/
136 EXPORT_API int maps_place_image_get_url(const maps_place_image_h place, char **url)
138 if (!maps_condition_check_maps_feature())
139 return MAPS_ERROR_NOT_SUPPORTED;
141 return MAPS_ERROR_INVALID_PARAMETER;
142 if (!((maps_place_image_s *) place)->url)
143 return MAPS_ERROR_NOT_FOUND;
144 return maps_get_string(((maps_place_image_s *) place)->url,
145 _MAPS_PLACE_IMAGE_URL_MAX_LENGTH, url);
148 EXPORT_API int maps_place_image_get_id(const maps_place_image_h place, char **id)
150 if (!maps_condition_check_maps_feature())
151 return MAPS_ERROR_NOT_SUPPORTED;
153 return MAPS_ERROR_INVALID_PARAMETER;
154 if (!((maps_place_image_s *) place)->id)
155 return MAPS_ERROR_NOT_FOUND;
156 return maps_get_string(((maps_place_image_s *) place)->id,
157 _MAPS_PLACE_IMAGE_ID_MAX_LENGTH, id);
160 EXPORT_API int maps_place_image_get_width(const maps_place_image_h place, int *width)
162 if (!maps_condition_check_maps_feature())
163 return MAPS_ERROR_NOT_SUPPORTED;
164 if (!place || !width)
165 return MAPS_ERROR_INVALID_PARAMETER;
166 if (!((maps_place_image_s *) place)->width)
167 return MAPS_ERROR_NOT_FOUND;
168 *width = ((maps_place_image_s *) place)->width;
169 return MAPS_ERROR_NONE;
172 EXPORT_API int maps_place_image_get_height(const maps_place_image_h place, int *height)
174 if (!maps_condition_check_maps_feature())
175 return MAPS_ERROR_NOT_SUPPORTED;
176 if (!place || !height)
177 return MAPS_ERROR_INVALID_PARAMETER;
178 if (!((maps_place_image_s *) place)->height)
179 return MAPS_ERROR_NOT_FOUND;
180 *height = ((maps_place_image_s *) place)->height;
181 return MAPS_ERROR_NONE;
184 EXPORT_API int maps_place_image_get_user_link(const maps_place_image_h place,
185 maps_place_link_object_h *user)
187 if (!maps_condition_check_maps_feature())
188 return MAPS_ERROR_NOT_SUPPORTED;
190 return MAPS_ERROR_INVALID_PARAMETER;
191 if (!((maps_place_image_s *) place)->user)
192 return MAPS_ERROR_NOT_FOUND;
193 return maps_place_link_object_clone(((maps_place_image_s *) place)->user, user);
196 EXPORT_API int maps_place_image_get_media(const maps_place_image_h place,
197 maps_place_media_h *media)
199 if (!maps_condition_check_maps_feature())
200 return MAPS_ERROR_NOT_SUPPORTED;
201 if (!place || !media)
202 return MAPS_ERROR_INVALID_PARAMETER;
203 if (!((maps_place_image_s *) place)->media)
204 return MAPS_ERROR_NOT_FOUND;
205 return maps_place_media_clone(((maps_place_image_s *) place)->media, media);
208 /*----------------------------------------------------------------------------*/
210 EXPORT_API int maps_place_image_set_id(maps_place_image_h place, const char *id)
212 if (!maps_condition_check_maps_feature())
213 return MAPS_ERROR_NOT_SUPPORTED;
215 return MAPS_ERROR_INVALID_PARAMETER;
216 return maps_set_string(id, _MAPS_PLACE_IMAGE_ID_MAX_LENGTH,
217 &((maps_place_image_s *) place)->id);
220 EXPORT_API int maps_place_image_set_url(maps_place_image_h place,
223 if (!maps_condition_check_maps_feature())
224 return MAPS_ERROR_NOT_SUPPORTED;
226 return MAPS_ERROR_INVALID_PARAMETER;
227 return maps_set_string(url, _MAPS_PLACE_IMAGE_URL_MAX_LENGTH,
228 &((maps_place_image_s *) place)->url);
231 EXPORT_API int maps_place_image_set_width(maps_place_image_h place,
234 if (!maps_condition_check_maps_feature())
235 return MAPS_ERROR_NOT_SUPPORTED;
236 if (!place || width < 0)
237 return MAPS_ERROR_INVALID_PARAMETER;
238 ((maps_place_image_s *) place)->width = width;
239 return MAPS_ERROR_NONE;
242 EXPORT_API int maps_place_image_set_height(maps_place_image_h place,
245 if (!maps_condition_check_maps_feature())
246 return MAPS_ERROR_NOT_SUPPORTED;
247 if (!place || height < 0)
248 return MAPS_ERROR_INVALID_PARAMETER;
249 ((maps_place_image_s *) place)->height = height;
250 return MAPS_ERROR_NONE;
253 EXPORT_API int maps_place_image_set_user_link(maps_place_image_h place,
254 const maps_place_link_object_h
257 if (!maps_condition_check_maps_feature())
258 return MAPS_ERROR_NOT_SUPPORTED;
260 return MAPS_ERROR_INVALID_PARAMETER;
261 maps_place_image_s *i = (maps_place_image_s *) place;
263 maps_place_link_object_destroy(i->user);
264 return maps_place_link_object_clone(user, &i->user);
267 EXPORT_API int maps_place_image_set_media(maps_place_image_h place,
268 const maps_place_media_h media)
270 if (!maps_condition_check_maps_feature())
271 return MAPS_ERROR_NOT_SUPPORTED;
272 if (!place || !media)
273 return MAPS_ERROR_INVALID_PARAMETER;
274 maps_place_image_s *i = (maps_place_image_s *) place;
276 maps_place_media_destroy(i->media);
277 return maps_place_media_clone(media, &i->media);