2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "maps_error.h"
19 #include "maps_place_filter.h"
20 #include "maps_extra_types.h"
21 #include "maps_util.h"
22 #include "maps_condition.h"
24 typedef struct _maps_place_filter_s
26 maps_item_hashtable_h table;
27 } maps_place_filter_s;
29 /*----------------------------------------------------------------------------*/
31 EXPORT_API int maps_place_filter_create(maps_place_filter_h *filter)
33 if (!maps_condition_check_maps_feature())
34 return MAPS_ERROR_NOT_SUPPORTED;
36 return MAPS_ERROR_INVALID_PARAMETER;
38 *filter = (maps_place_filter_h) g_slice_new0(maps_place_filter_s);
39 if (*filter == NULL) {
41 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
42 return MAPS_ERROR_OUT_OF_MEMORY;
46 maps_place_filter_s *f = (maps_place_filter_s *) (*filter);
47 maps_item_hashtable_create(&f->table);
49 return MAPS_ERROR_NONE;
52 EXPORT_API int maps_place_filter_destroy(maps_place_filter_h filter)
54 if (!maps_condition_check_maps_feature())
55 return MAPS_ERROR_NOT_SUPPORTED;
57 return MAPS_ERROR_INVALID_PARAMETER;
59 maps_place_filter_s *f = (maps_place_filter_s *) filter;
62 maps_item_hashtable_destroy(f->table);
64 g_slice_free(maps_place_filter_s, filter);
65 return MAPS_ERROR_NONE;
68 EXPORT_API int maps_place_filter_clone(const maps_place_filter_h origin,
69 maps_place_filter_h *cloned)
71 if (!maps_condition_check_maps_feature())
72 return MAPS_ERROR_NOT_SUPPORTED;
73 if (!cloned || !origin)
74 return MAPS_ERROR_INVALID_PARAMETER;
76 int error = MAPS_ERROR_NONE;
78 error = maps_place_filter_create(cloned);
79 if (!(*cloned) || (error != MAPS_ERROR_NONE))
82 maps_place_filter_s *f = (maps_place_filter_s *) origin;
85 maps_place_filter_s *f_cloned =
86 (maps_place_filter_s *) (*cloned);
88 maps_item_hashtable_destroy(f_cloned->table);
90 error = maps_item_hashtable_clone(f->table, &f_cloned->table);
91 if (error != MAPS_ERROR_NONE)
95 return MAPS_ERROR_NONE;
99 maps_place_filter_destroy(*cloned);
105 /*----------------------------------------------------------------------------*/
107 EXPORT_API int maps_place_filter_get(const maps_place_filter_h filter,
108 const char *key, char **value)
110 if (!maps_condition_check_maps_feature())
111 return MAPS_ERROR_NOT_SUPPORTED;
113 return MAPS_ERROR_INVALID_PARAMETER;
114 if (!((maps_place_filter_s *) filter)->table)
115 return MAPS_ERROR_NOT_FOUND;
116 return maps_item_hashtable_get_string(((maps_place_filter_s *) filter)->table,
120 EXPORT_API int maps_place_filter_foreach_property(const maps_place_filter_h filter,
121 maps_place_filter_properties_cb callback,
124 if (!maps_condition_check_maps_feature())
125 return MAPS_ERROR_NOT_SUPPORTED;
126 if (!filter || !callback)
127 return MAPS_ERROR_INVALID_PARAMETER;
128 if (!((maps_place_filter_s *) filter)->table)
129 return MAPS_ERROR_NOT_FOUND;
130 return maps_item_hashtable_foreach(((maps_place_filter_s *) filter)->table,
131 callback, user_data);
134 EXPORT_API int maps_place_filter_get_keyword(const maps_place_filter_h filter,
137 if (!maps_condition_check_maps_feature())
138 return MAPS_ERROR_NOT_SUPPORTED;
139 if (!filter || !keyword)
140 return MAPS_ERROR_INVALID_PARAMETER;
141 if (!((maps_place_filter_s *) filter)->table)
142 return MAPS_ERROR_NOT_FOUND;
143 return maps_item_hashtable_get_string(((maps_place_filter_s *) filter)->table,
144 "MAPS_PLACE_FILTER_KEYWORD", keyword);
147 EXPORT_API int maps_place_filter_get_place_name(const maps_place_filter_h filter,
150 if (!maps_condition_check_maps_feature())
151 return MAPS_ERROR_NOT_SUPPORTED;
152 if (!filter || !place_name)
153 return MAPS_ERROR_INVALID_PARAMETER;
154 if (!((maps_place_filter_s *) filter)->table)
155 return MAPS_ERROR_NOT_FOUND;
156 return maps_item_hashtable_get_string(((maps_place_filter_s *) filter)->table,
157 "MAPS_PLACE_FILTER_PLACE_NAME", place_name);
160 EXPORT_API int maps_place_filter_get_category(const maps_place_filter_h filter,
161 maps_place_category_h *category)
163 if (!maps_condition_check_maps_feature())
164 return MAPS_ERROR_NOT_SUPPORTED;
165 if (!filter || !category)
166 return MAPS_ERROR_INVALID_PARAMETER;
167 if (!((maps_place_filter_s *) filter)->table)
168 return MAPS_ERROR_NOT_FOUND;
169 return maps_item_hashtable_get(((maps_place_filter_s *) filter)->table,
170 "MAPS_PLACE_FILTER_CATEGORY", (void **) category);
173 EXPORT_API int maps_place_filter_get_place_address(const maps_place_filter_h filter,
174 char **place_address)
176 if (!maps_condition_check_maps_feature())
177 return MAPS_ERROR_NOT_SUPPORTED;
178 if (!filter || !place_address)
179 return MAPS_ERROR_INVALID_PARAMETER;
180 if (!((maps_place_filter_s *) filter)->table)
181 return MAPS_ERROR_NOT_FOUND;
182 return maps_item_hashtable_get_string(((maps_place_filter_s *) filter)->table,
183 "MAPS_PLACE_FILTER_PLACE_ADDRESS", place_address);
186 /*----------------------------------------------------------------------------*/
188 EXPORT_API int maps_place_filter_set(maps_place_filter_h filter,
189 const char *key, const char *value)
191 if (!maps_condition_check_maps_feature())
192 return MAPS_ERROR_NOT_SUPPORTED;
194 return MAPS_ERROR_INVALID_PARAMETER;
195 return maps_item_hashtable_set_string(((maps_place_filter_s *) filter)->table,
199 EXPORT_API int maps_place_filter_set_keyword(maps_place_filter_h filter,
202 if (!maps_condition_check_maps_feature())
203 return MAPS_ERROR_NOT_SUPPORTED;
204 if (!filter || !keyword)
205 return MAPS_ERROR_INVALID_PARAMETER;
206 return maps_item_hashtable_set_string(((maps_place_filter_s *) filter)->table,
207 "MAPS_PLACE_FILTER_KEYWORD", keyword);
210 EXPORT_API int maps_place_filter_set_place_name(maps_place_filter_h filter,
211 const char *place_name)
213 if (!maps_condition_check_maps_feature())
214 return MAPS_ERROR_NOT_SUPPORTED;
215 if (!filter || !place_name)
216 return MAPS_ERROR_INVALID_PARAMETER;
217 return maps_item_hashtable_set_string(((maps_place_filter_s *) filter)->table,
218 "MAPS_PLACE_FILTER_PLACE_NAME", place_name);
221 EXPORT_API int maps_place_filter_set_category(maps_place_filter_h filter,
222 const maps_place_category_h category)
224 if (!maps_condition_check_maps_feature())
225 return MAPS_ERROR_NOT_SUPPORTED;
226 if (!filter || !category)
227 return MAPS_ERROR_INVALID_PARAMETER;
228 return maps_item_hashtable_set(((maps_place_filter_s *) filter)->table,
229 "MAPS_PLACE_FILTER_CATEGORY", (void **) category,
230 maps_place_category_clone, maps_place_category_destroy);
233 EXPORT_API int maps_place_filter_set_place_address(maps_place_filter_h filter,
234 const char *place_address)
236 if (!maps_condition_check_maps_feature())
237 return MAPS_ERROR_NOT_SUPPORTED;
238 if (!filter || !place_address)
239 return MAPS_ERROR_INVALID_PARAMETER;
240 return maps_item_hashtable_set_string(((maps_place_filter_s *) filter)->table,
241 "MAPS_PLACE_FILTER_PLACE_ADDRESS", place_address);