Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / api / maps_place_filter.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <glib.h>
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"
23
24 typedef struct _maps_place_filter_s
25 {
26         maps_item_hashtable_h table;
27 } maps_place_filter_s;
28
29 /*----------------------------------------------------------------------------*/
30
31 EXPORT_API int maps_place_filter_create(maps_place_filter_h *filter)
32 {
33         if (!maps_condition_check_maps_feature())
34                 return MAPS_ERROR_NOT_SUPPORTED;
35         if (!filter)
36                 return MAPS_ERROR_INVALID_PARAMETER;
37
38         *filter = (maps_place_filter_h) g_slice_new0(maps_place_filter_s);
39         if (*filter == NULL) {
40                 //LCOV_EXCL_START
41                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
42                 return MAPS_ERROR_OUT_OF_MEMORY;
43                 //LCOV_EXCL_STOP
44         }
45
46         maps_place_filter_s *f = (maps_place_filter_s *) (*filter);
47         maps_item_hashtable_create(&f->table);
48
49         return MAPS_ERROR_NONE;
50 }
51
52 EXPORT_API int maps_place_filter_destroy(maps_place_filter_h filter)
53 {
54         if (!maps_condition_check_maps_feature())
55                 return MAPS_ERROR_NOT_SUPPORTED;
56         if (!filter)
57                 return MAPS_ERROR_INVALID_PARAMETER;
58
59         maps_place_filter_s *f = (maps_place_filter_s *) filter;
60
61         if (f->table)
62                 maps_item_hashtable_destroy(f->table);
63
64         g_slice_free(maps_place_filter_s, filter);
65         return MAPS_ERROR_NONE;
66 }
67
68 EXPORT_API int maps_place_filter_clone(const maps_place_filter_h origin,
69                                                                 maps_place_filter_h *cloned)
70 {
71         if (!maps_condition_check_maps_feature())
72                 return MAPS_ERROR_NOT_SUPPORTED;
73         if (!cloned || !origin)
74                 return MAPS_ERROR_INVALID_PARAMETER;
75
76         int error = MAPS_ERROR_NONE;
77         do {
78                 error = maps_place_filter_create(cloned);
79                 if (!(*cloned) || (error != MAPS_ERROR_NONE))
80                         break;
81
82                 maps_place_filter_s *f = (maps_place_filter_s *) origin;
83
84                 if (f->table) {
85                         maps_place_filter_s *f_cloned =
86                                 (maps_place_filter_s *) (*cloned);
87                         if (f_cloned->table)
88                                 maps_item_hashtable_destroy(f_cloned->table);
89
90                         error = maps_item_hashtable_clone(f->table, &f_cloned->table);
91                         if (error != MAPS_ERROR_NONE)
92                                 break;
93                 }
94
95                 return MAPS_ERROR_NONE;
96         } while (false);
97
98         //LCOV_EXCL_START
99         maps_place_filter_destroy(*cloned);
100         *cloned = NULL;
101         return error;
102         //LCOV_EXCL_STOP
103 }
104
105 /*----------------------------------------------------------------------------*/
106
107 EXPORT_API int maps_place_filter_get(const maps_place_filter_h filter,
108                                                                 const char *key, char **value)
109 {
110         if (!maps_condition_check_maps_feature())
111                 return MAPS_ERROR_NOT_SUPPORTED;
112         if (!filter)
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,
117                 key, value);
118 }
119
120 EXPORT_API int maps_place_filter_foreach_property(const maps_place_filter_h filter,
121                                                                 maps_place_filter_properties_cb callback,
122                                                                 void *user_data)
123 {
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);
132 }
133
134 EXPORT_API int maps_place_filter_get_keyword(const maps_place_filter_h filter,
135                                                                 char **keyword)
136 {
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);
145 }
146
147 EXPORT_API int maps_place_filter_get_place_name(const maps_place_filter_h filter,
148                                                                 char **place_name)
149 {
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);
158 }
159
160 EXPORT_API int maps_place_filter_get_category(const maps_place_filter_h filter,
161                                                                 maps_place_category_h *category)
162 {
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);
171 }
172
173 EXPORT_API int maps_place_filter_get_place_address(const maps_place_filter_h filter,
174                                                                 char **place_address)
175 {
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);
184 }
185
186 /*----------------------------------------------------------------------------*/
187
188 EXPORT_API int maps_place_filter_set(maps_place_filter_h filter,
189                                                                 const char *key, const char *value)
190 {
191         if (!maps_condition_check_maps_feature())
192                 return MAPS_ERROR_NOT_SUPPORTED;
193         if (!filter)
194                 return MAPS_ERROR_INVALID_PARAMETER;
195         return maps_item_hashtable_set_string(((maps_place_filter_s *) filter)->table,
196                 key, value);
197 }
198
199 EXPORT_API int maps_place_filter_set_keyword(maps_place_filter_h filter,
200                                                                 const char *keyword)
201 {
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);
208 }
209
210 EXPORT_API int maps_place_filter_set_place_name(maps_place_filter_h filter,
211                                                                 const char *place_name)
212 {
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);
219 }
220
221 EXPORT_API int maps_place_filter_set_category(maps_place_filter_h filter,
222                                                                 const maps_place_category_h category)
223 {
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);
231 }
232
233 EXPORT_API int maps_place_filter_set_place_address(maps_place_filter_h filter,
234                                                                 const char *place_address)
235 {
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);
242 }