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) {
40 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
41 return MAPS_ERROR_OUT_OF_MEMORY;
44 maps_place_filter_s *f = (maps_place_filter_s *) (*filter);
45 maps_item_hashtable_create(&f->table);
47 return MAPS_ERROR_NONE;
50 EXPORT_API int maps_place_filter_destroy(maps_place_filter_h filter)
52 if (!maps_condition_check_maps_feature())
53 return MAPS_ERROR_NOT_SUPPORTED;
55 return MAPS_ERROR_INVALID_PARAMETER;
57 maps_place_filter_s *f = (maps_place_filter_s *) filter;
60 maps_item_hashtable_destroy(f->table);
62 g_slice_free(maps_place_filter_s, filter);
63 return MAPS_ERROR_NONE;
66 EXPORT_API int maps_place_filter_clone(const maps_place_filter_h origin,
67 maps_place_filter_h *cloned)
69 if (!maps_condition_check_maps_feature())
70 return MAPS_ERROR_NOT_SUPPORTED;
71 if (!cloned || !origin)
72 return MAPS_ERROR_INVALID_PARAMETER;
74 int error = MAPS_ERROR_NONE;
76 error = maps_place_filter_create(cloned);
77 if (!(*cloned) || (error != MAPS_ERROR_NONE))
80 maps_place_filter_s *f = (maps_place_filter_s *) origin;
83 maps_place_filter_s *f_cloned =
84 (maps_place_filter_s *) (*cloned);
86 maps_item_hashtable_destroy(f_cloned->table);
88 error = maps_item_hashtable_clone(f->table, &f_cloned->table);
89 if (error != MAPS_ERROR_NONE)
93 return MAPS_ERROR_NONE;
96 maps_place_filter_destroy(*cloned);
101 /*----------------------------------------------------------------------------*/
103 EXPORT_API int maps_place_filter_get(const maps_place_filter_h filter,
104 const char *key, char **value)
106 if (!maps_condition_check_maps_feature())
107 return MAPS_ERROR_NOT_SUPPORTED;
109 return MAPS_ERROR_INVALID_PARAMETER;
110 if (!((maps_place_filter_s *) filter)->table)
111 return MAPS_ERROR_NOT_FOUND;
112 return maps_item_hashtable_get_string(((maps_place_filter_s *) filter)->table,
116 EXPORT_API int maps_place_filter_foreach_property(const maps_place_filter_h filter,
117 maps_place_filter_properties_cb callback,
120 if (!maps_condition_check_maps_feature())
121 return MAPS_ERROR_NOT_SUPPORTED;
122 if (!filter || !callback)
123 return MAPS_ERROR_INVALID_PARAMETER;
124 if (!((maps_place_filter_s *) filter)->table)
125 return MAPS_ERROR_NOT_FOUND;
126 return maps_item_hashtable_foreach(((maps_place_filter_s *) filter)->table,
127 callback, user_data);
130 EXPORT_API int maps_place_filter_get_keyword(const maps_place_filter_h filter,
133 if (!maps_condition_check_maps_feature())
134 return MAPS_ERROR_NOT_SUPPORTED;
135 if (!filter || !keyword)
136 return MAPS_ERROR_INVALID_PARAMETER;
137 if (!((maps_place_filter_s *) filter)->table)
138 return MAPS_ERROR_NOT_FOUND;
139 return maps_item_hashtable_get_string(((maps_place_filter_s *) filter)->table,
140 "MAPS_PLACE_FILTER_KEYWORD", keyword);
143 EXPORT_API int maps_place_filter_get_place_name(const maps_place_filter_h filter,
146 if (!maps_condition_check_maps_feature())
147 return MAPS_ERROR_NOT_SUPPORTED;
148 if (!filter || !place_name)
149 return MAPS_ERROR_INVALID_PARAMETER;
150 if (!((maps_place_filter_s *) filter)->table)
151 return MAPS_ERROR_NOT_FOUND;
152 return maps_item_hashtable_get_string(((maps_place_filter_s *) filter)->table,
153 "MAPS_PLACE_FILTER_PLACE_NAME", place_name);
156 EXPORT_API int maps_place_filter_get_category(const maps_place_filter_h filter,
157 maps_place_category_h *category)
159 if (!maps_condition_check_maps_feature())
160 return MAPS_ERROR_NOT_SUPPORTED;
161 if (!filter || !category)
162 return MAPS_ERROR_INVALID_PARAMETER;
163 if (!((maps_place_filter_s *) filter)->table)
164 return MAPS_ERROR_NOT_FOUND;
165 return maps_item_hashtable_get(((maps_place_filter_s *) filter)->table,
166 "MAPS_PLACE_FILTER_CATEGORY", (void **) category);
169 EXPORT_API int maps_place_filter_get_place_address(const maps_place_filter_h filter,
170 char **place_address)
172 if (!maps_condition_check_maps_feature())
173 return MAPS_ERROR_NOT_SUPPORTED;
174 if (!filter || !place_address)
175 return MAPS_ERROR_INVALID_PARAMETER;
176 if (!((maps_place_filter_s *) filter)->table)
177 return MAPS_ERROR_NOT_FOUND;
178 return maps_item_hashtable_get_string(((maps_place_filter_s *) filter)->table,
179 "MAPS_PLACE_FILTER_PLACE_ADDRESS", place_address);
182 /*----------------------------------------------------------------------------*/
184 EXPORT_API int maps_place_filter_set(maps_place_filter_h filter,
185 const char *key, const char *value)
187 if (!maps_condition_check_maps_feature())
188 return MAPS_ERROR_NOT_SUPPORTED;
190 return MAPS_ERROR_INVALID_PARAMETER;
191 return maps_item_hashtable_set_string(((maps_place_filter_s *) filter)->table,
195 EXPORT_API int maps_place_filter_set_keyword(maps_place_filter_h filter,
198 if (!maps_condition_check_maps_feature())
199 return MAPS_ERROR_NOT_SUPPORTED;
200 if (!filter || !keyword)
201 return MAPS_ERROR_INVALID_PARAMETER;
202 return maps_item_hashtable_set_string(((maps_place_filter_s *) filter)->table,
203 "MAPS_PLACE_FILTER_KEYWORD", keyword);
206 EXPORT_API int maps_place_filter_set_place_name(maps_place_filter_h filter,
207 const char *place_name)
209 if (!maps_condition_check_maps_feature())
210 return MAPS_ERROR_NOT_SUPPORTED;
211 if (!filter || !place_name)
212 return MAPS_ERROR_INVALID_PARAMETER;
213 return maps_item_hashtable_set_string(((maps_place_filter_s *) filter)->table,
214 "MAPS_PLACE_FILTER_PLACE_NAME", place_name);
217 EXPORT_API int maps_place_filter_set_category(maps_place_filter_h filter,
218 const maps_place_category_h category)
220 if (!maps_condition_check_maps_feature())
221 return MAPS_ERROR_NOT_SUPPORTED;
222 if (!filter || !category)
223 return MAPS_ERROR_INVALID_PARAMETER;
224 return maps_item_hashtable_set(((maps_place_filter_s *) filter)->table,
225 "MAPS_PLACE_FILTER_CATEGORY", (void **) category,
226 maps_place_category_clone, maps_place_category_destroy);
229 EXPORT_API int maps_place_filter_set_place_address(maps_place_filter_h filter,
230 const char *place_address)
232 if (!maps_condition_check_maps_feature())
233 return MAPS_ERROR_NOT_SUPPORTED;
234 if (!filter || !place_address)
235 return MAPS_ERROR_INVALID_PARAMETER;
236 return maps_item_hashtable_set_string(((maps_place_filter_s *) filter)->table,
237 "MAPS_PLACE_FILTER_PLACE_ADDRESS", place_address);