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_rating_plugin.h"
19 #include "maps_util.h"
20 #include "maps_condition.h"
22 typedef struct _maps_place_rating_s
26 } maps_place_rating_s;
28 /*----------------------------------------------------------------------------*/
30 EXPORT_API int maps_place_rating_create(maps_place_rating_h *place)
32 if (!maps_condition_check_maps_feature())
33 return MAPS_ERROR_NOT_SUPPORTED;
35 return MAPS_ERROR_INVALID_PARAMETER;
36 *place = (maps_place_rating_h) g_slice_new0(maps_place_rating_s);
40 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
41 return MAPS_ERROR_OUT_OF_MEMORY;
45 return MAPS_ERROR_NONE;
48 EXPORT_API int maps_place_rating_destroy(maps_place_rating_h place)
50 if (!maps_condition_check_maps_feature())
51 return MAPS_ERROR_NOT_SUPPORTED;
53 return MAPS_ERROR_INVALID_PARAMETER;
54 g_slice_free(maps_place_rating_s, place);
55 return MAPS_ERROR_NONE;
58 EXPORT_API int maps_place_rating_clone(const maps_place_rating_h origin,
59 maps_place_rating_h *cloned)
61 if (!maps_condition_check_maps_feature())
62 return MAPS_ERROR_NOT_SUPPORTED;
63 if (!cloned || !origin)
64 return MAPS_ERROR_INVALID_PARAMETER;
66 int error = MAPS_ERROR_NONE;
68 error = maps_place_rating_create(cloned);
69 if (!(*cloned) || (error != MAPS_ERROR_NONE))
72 maps_place_rating_s *r = (maps_place_rating_s *) origin;
74 error = maps_place_rating_set_count(*cloned, r->count);
75 if (error != MAPS_ERROR_NONE)
78 error = maps_place_rating_set_average(*cloned, r->average);
79 if (error != MAPS_ERROR_NONE)
82 return MAPS_ERROR_NONE;
86 maps_place_rating_destroy(*cloned);
92 /*----------------------------------------------------------------------------*/
94 EXPORT_API int maps_place_rating_get_count(const maps_place_rating_h place,
97 if (!maps_condition_check_maps_feature())
98 return MAPS_ERROR_NOT_SUPPORTED;
100 return MAPS_ERROR_INVALID_PARAMETER;
101 *count = ((maps_place_rating_s *) place)->count;
102 return MAPS_ERROR_NONE;
105 EXPORT_API int maps_place_rating_get_average(const maps_place_rating_h place,
108 if (!maps_condition_check_maps_feature())
109 return MAPS_ERROR_NOT_SUPPORTED;
110 if (!place || !average)
111 return MAPS_ERROR_INVALID_PARAMETER;
112 *average = ((maps_place_rating_s *) place)->average;
113 return MAPS_ERROR_NONE;
116 /*----------------------------------------------------------------------------*/
118 EXPORT_API int maps_place_rating_set_count(maps_place_rating_h place,
121 if (!maps_condition_check_maps_feature())
122 return MAPS_ERROR_NOT_SUPPORTED;
123 if (!place || (count < 0))
124 return MAPS_ERROR_INVALID_PARAMETER;
125 ((maps_place_rating_s *) place)->count = count;
126 return MAPS_ERROR_NONE;
129 EXPORT_API int maps_place_rating_set_average(maps_place_rating_h place,
130 const double average)
132 if (!maps_condition_check_maps_feature())
133 return MAPS_ERROR_NOT_SUPPORTED;
134 if (!place || (average < 0))
135 return MAPS_ERROR_INVALID_PARAMETER;
136 ((maps_place_rating_s *) place)->average = average;
137 return MAPS_ERROR_NONE;