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_review_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_review_s
31 maps_place_media_h media;
32 maps_place_link_object_h user;
33 } maps_place_review_s;
35 const gsize _MAPS_PLACE_REVIEW_DATE_MAX_LENGTH = MAPS_BASE_DATE_MAX_LEN;
36 const gsize _MAPS_PLACE_REVIEW_TITLE_MAX_LENGTH = MAPS_BASE_NAME_MAX_LEN;
37 const gsize _MAPS_PLACE_REVIEW_DESCRIPTION_MAX_LENGTH = MAPS_BASE_DESC_MAX_LEN;
38 const gsize _MAPS_PLACE_REVIEW_LANGUAGE_MAX_LENGTH = MAPS_BASE_TYPE_MAX_LEN;
40 /*----------------------------------------------------------------------------*/
42 EXPORT_API int maps_place_review_create(maps_place_review_h *place)
44 if (!maps_condition_check_maps_feature())
45 return MAPS_ERROR_NOT_SUPPORTED;
47 return MAPS_ERROR_INVALID_PARAMETER;
48 *place = (maps_place_review_h) g_slice_new0(maps_place_review_s);
52 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
53 return MAPS_ERROR_OUT_OF_MEMORY;
57 return MAPS_ERROR_NONE;
60 EXPORT_API int maps_place_review_destroy(maps_place_review_h place)
62 if (!maps_condition_check_maps_feature())
63 return MAPS_ERROR_NOT_SUPPORTED;
65 return MAPS_ERROR_INVALID_PARAMETER;
67 maps_place_review_s *r = (maps_place_review_s *) place;
74 g_free(r->description);
79 maps_place_media_destroy(r->media);
81 maps_place_link_object_destroy(r->user);
83 g_slice_free(maps_place_review_s, place);
84 return MAPS_ERROR_NONE;
87 EXPORT_API int maps_place_review_clone(const maps_place_review_h origin,
88 maps_place_review_h *cloned)
90 if (!maps_condition_check_maps_feature())
91 return MAPS_ERROR_NOT_SUPPORTED;
92 if (!cloned || !origin)
93 return MAPS_ERROR_INVALID_PARAMETER;
95 int error = MAPS_ERROR_NONE;
97 error = maps_place_review_create(cloned);
98 if (!(*cloned) || (error != MAPS_ERROR_NONE))
101 maps_place_review_s *r = (maps_place_review_s *) origin;
104 error = maps_place_review_set_date(*cloned, r->date);
105 if (error != MAPS_ERROR_NONE)
110 error = maps_place_review_set_title(*cloned, r->title);
111 if (error != MAPS_ERROR_NONE)
115 ((maps_place_review_s *) (*cloned))->rating = r->rating;
117 if (r->description) {
118 error = maps_place_review_set_description(*cloned, r->description);
119 if (error != MAPS_ERROR_NONE)
123 error = maps_place_review_set_language(*cloned, r->language);
124 if (error != MAPS_ERROR_NONE)
128 error = maps_place_review_set_media(*cloned, r->media);
129 if (error != MAPS_ERROR_NONE)
133 error = maps_place_review_set_user_link(*cloned, r->user);
134 if (error != MAPS_ERROR_NONE)
138 return MAPS_ERROR_NONE;
142 maps_place_review_destroy(*cloned);
148 /*----------------------------------------------------------------------------*/
150 EXPORT_API int maps_place_review_get_date(const maps_place_review_h place,
153 if (!maps_condition_check_maps_feature())
154 return MAPS_ERROR_NOT_SUPPORTED;
156 return MAPS_ERROR_INVALID_PARAMETER;
157 if (!((maps_place_review_s *) place)->date)
158 return MAPS_ERROR_NOT_FOUND;
159 return maps_get_string(((maps_place_review_s *) place)->date,
160 _MAPS_PLACE_REVIEW_DATE_MAX_LENGTH, date);
163 EXPORT_API int maps_place_review_get_title(const maps_place_review_h place,
166 if (!maps_condition_check_maps_feature())
167 return MAPS_ERROR_NOT_SUPPORTED;
168 if (!place || !title)
169 return MAPS_ERROR_INVALID_PARAMETER;
170 if (!((maps_place_review_s *) place)->title)
171 return MAPS_ERROR_NOT_FOUND;
172 return maps_get_string(((maps_place_review_s *) place)->title,
173 _MAPS_PLACE_REVIEW_TITLE_MAX_LENGTH, title);
176 EXPORT_API int maps_place_review_get_rating(const maps_place_review_h place,
179 if (!maps_condition_check_maps_feature())
180 return MAPS_ERROR_NOT_SUPPORTED;
181 if (!place || !rating)
182 return MAPS_ERROR_INVALID_PARAMETER;
183 if (!((maps_place_review_s *) place)->rating)
184 return MAPS_ERROR_NOT_FOUND;
185 *rating = ((maps_place_review_s *) place)->rating;
186 return MAPS_ERROR_NONE;
189 EXPORT_API int maps_place_review_get_description(const maps_place_review_h place,
192 if (!maps_condition_check_maps_feature())
193 return MAPS_ERROR_NOT_SUPPORTED;
194 if (!place || !description)
195 return MAPS_ERROR_INVALID_PARAMETER;
196 if (!((maps_place_review_s *) place)->description)
197 return MAPS_ERROR_NOT_FOUND;
198 return maps_get_string(((maps_place_review_s *) place)->description,
199 _MAPS_PLACE_REVIEW_DESCRIPTION_MAX_LENGTH, description);
202 EXPORT_API int maps_place_review_get_language(const maps_place_review_h place,
205 if (!maps_condition_check_maps_feature())
206 return MAPS_ERROR_NOT_SUPPORTED;
207 if (!place || !language)
208 return MAPS_ERROR_INVALID_PARAMETER;
209 if (!((maps_place_review_s *) place)->language)
210 return MAPS_ERROR_NOT_FOUND;
211 return maps_get_string(((maps_place_review_s *) place)->language,
212 _MAPS_PLACE_REVIEW_LANGUAGE_MAX_LENGTH, language);
215 EXPORT_API int maps_place_review_get_media(const maps_place_review_h place,
216 maps_place_media_h *media)
218 if (!maps_condition_check_maps_feature())
219 return MAPS_ERROR_NOT_SUPPORTED;
220 if (!place || !media)
221 return MAPS_ERROR_INVALID_PARAMETER;
222 if (!((maps_place_review_s *) place)->media)
223 return MAPS_ERROR_NOT_FOUND;
224 return maps_place_media_clone(((maps_place_review_s *) place)->media,
228 EXPORT_API int maps_place_review_get_user_link(const maps_place_review_h place,
229 maps_place_link_object_h *user)
231 if (!maps_condition_check_maps_feature())
232 return MAPS_ERROR_NOT_SUPPORTED;
234 return MAPS_ERROR_INVALID_PARAMETER;
235 if (!((maps_place_review_s *) place)->user)
236 return MAPS_ERROR_NOT_FOUND;
237 return maps_place_link_object_clone(((maps_place_review_s *) place)->user, user);
240 /*----------------------------------------------------------------------------*/
242 EXPORT_API int maps_place_review_set_date(maps_place_review_h place,
245 if (!maps_condition_check_maps_feature())
246 return MAPS_ERROR_NOT_SUPPORTED;
248 return MAPS_ERROR_INVALID_PARAMETER;
249 return maps_set_string(date, _MAPS_PLACE_REVIEW_DATE_MAX_LENGTH,
250 &((maps_place_review_s *) place)->date);
253 EXPORT_API int maps_place_review_set_title(maps_place_review_h place,
256 if (!maps_condition_check_maps_feature())
257 return MAPS_ERROR_NOT_SUPPORTED;
258 if (!place || !title)
259 return MAPS_ERROR_INVALID_PARAMETER;
260 return maps_set_string(title, _MAPS_PLACE_REVIEW_TITLE_MAX_LENGTH,
261 &((maps_place_review_s *) place)->title);
264 EXPORT_API int maps_place_review_set_rating(maps_place_review_h place,
267 if (!maps_condition_check_maps_feature())
268 return MAPS_ERROR_NOT_SUPPORTED;
270 return MAPS_ERROR_INVALID_PARAMETER;
271 ((maps_place_review_s *) place)->rating = rating;
272 return MAPS_ERROR_NONE;
275 EXPORT_API int maps_place_review_set_description(maps_place_review_h place,
276 const char *description)
278 if (!maps_condition_check_maps_feature())
279 return MAPS_ERROR_NOT_SUPPORTED;
280 if (!place || !description)
281 return MAPS_ERROR_INVALID_PARAMETER;
282 return maps_set_string(description,
283 _MAPS_PLACE_REVIEW_DESCRIPTION_MAX_LENGTH,
284 &((maps_place_review_s *) place)->description);
287 EXPORT_API int maps_place_review_set_language(maps_place_review_h place,
288 const char *language)
290 if (!maps_condition_check_maps_feature())
291 return MAPS_ERROR_NOT_SUPPORTED;
292 if (!place || !language)
293 return MAPS_ERROR_INVALID_PARAMETER;
294 return maps_set_string(language, _MAPS_PLACE_REVIEW_LANGUAGE_MAX_LENGTH,
295 &((maps_place_review_s *) place)->language);
298 EXPORT_API int maps_place_review_set_media(maps_place_review_h place,
299 const maps_place_media_h media)
301 if (!maps_condition_check_maps_feature())
302 return MAPS_ERROR_NOT_SUPPORTED;
303 if (!place || !media)
304 return MAPS_ERROR_INVALID_PARAMETER;
305 maps_place_review_s *r = (maps_place_review_s *) place;
307 maps_place_media_destroy(r->media);
308 return maps_place_media_clone(media, &r->media);
311 EXPORT_API int maps_place_review_set_user_link(maps_place_review_h place,
312 const maps_place_link_object_h user)
314 if (!maps_condition_check_maps_feature())
315 return MAPS_ERROR_NOT_SUPPORTED;
317 return MAPS_ERROR_INVALID_PARAMETER;
318 maps_place_review_s *r = (maps_place_review_s *) place;
320 maps_place_link_object_destroy(r->user);
321 return maps_place_link_object_clone(user, &r->user);