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_service.h"
19 #include "maps_error.h"
20 #include "maps_service.h"
21 #include "maps_util.h"
23 #include "command_queue.h"
25 #include "discovery.h"
28 #include <privilege_checker.h>
30 /*----------------------------------------------------------------------------*/
31 /* Structure of maps_service */
32 /* maps_service_s* is used as maps_service_h */
33 typedef struct _maps_service_s
38 const gsize _MAPS_PROVIDER_KEY_MAX_LENGTH = 1024;
40 static session::command_queue *q()
42 return session::command_queue::interface();
45 /* This function is used in command class */
46 plugin::plugin_s *__extract_plugin(maps_service_h maps)
50 maps_service_s *maps_service = (maps_service_s *) maps;
51 return (plugin::plugin_s *) maps_service->plugin;
54 static bool __maps_provider_supported(maps_service_h maps,
55 maps_service_e service)
59 bool supported = false;
60 if (maps_service_provider_is_service_supported(maps, service,
61 &supported) != MAPS_ERROR_NONE)
66 static bool __has_maps_service_privilege()
68 return (privilege_checker_check_privilege(
69 "http://tizen.org/privilege/mapservice")
70 == PRIVILEGE_CHECKER_ERR_NONE);
73 /*----------------------------------------------------------------------------*/
75 /* Maps Service & Preference */
77 EXPORT_API int maps_service_foreach_provider(maps_service_provider_info_cb
82 return MAPS_ERROR_INVALID_PARAMETER;
84 /* The list of map provider info, obtained by enumerating available
87 vector < plugin::provider_info > v = pd.get_available_list();
89 /* Send obtained provider info to the user */
90 const int total = int(v.size());
91 for (int i = 0; i < total; i++) {
92 /* Get a plugin info handle from the array */
93 /* and send a callback with provider info to the user */
94 char *provider = g_strdup(v[i].provider.c_str());
95 if (!callback(provider, user_data))
99 return MAPS_ERROR_NONE;
102 EXPORT_API int maps_service_create(const char *maps_provider,
103 maps_service_h *maps)
105 /* Check if parameters are valid */
106 if (!maps || !maps_provider)
107 return MAPS_ERROR_INVALID_PARAMETER;
109 /* Check if privileges enough */
110 if (!__has_maps_service_privilege())
111 return MAPS_ERROR_PERMISSION_DENIED;
113 int error = MAPS_ERROR_NOT_SUPPORTED;
116 /* 0. Find the plugin, requested by the user */
117 const plugin::provider_info info =
118 plugin::find_by_names(string(maps_provider));
120 /* 1. Check whether provider info is valid */
122 MAPS_LOGE("ERROR! Provider info not found for name: %s",
124 error = MAPS_ERROR_NOT_SUPPORTED;
128 /* 2. Setup maps service handling structure */
129 maps_service_s *maps_service = g_slice_new0(maps_service_s);
131 if (maps_service == NULL) {
132 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)",
133 MAPS_ERROR_OUT_OF_MEMORY);
134 error = MAPS_ERROR_OUT_OF_MEMORY;
138 /* 3. Initialize the requested plugin */
140 int init_error = MAPS_ERROR_NONE; /* Storage for init error code */
142 maps_plugin_h plugin_h =
143 plugin::binary_extractor().init(info, &init_error);
146 MAPS_LOGE("ERROR! Plugin init failed");
150 maps_service->plugin = plugin_h;
152 /* 4. Initialize an output pointer to maps service */
153 *maps = maps_service;
155 /* 5. Set status of completely correct plugin initialization */
156 error = MAPS_ERROR_NONE;
160 if (error != MAPS_ERROR_NONE)
161 maps_service_destroy(*maps);
166 EXPORT_API int maps_service_destroy(maps_service_h maps)
168 /* Check if parameters are valid */
170 return MAPS_ERROR_INVALID_PARAMETER;
172 /* Check if privileges enough */
173 if (!__has_maps_service_privilege())
174 return MAPS_ERROR_PERMISSION_DENIED;
176 maps_service_s *maps_service = (maps_service_s *) maps;
178 if (maps_service->plugin)
179 plugin::binary_extractor().shutdown(maps_service->plugin);
181 g_slice_free(maps_service_s, maps);
183 return MAPS_ERROR_NONE;
186 EXPORT_API int maps_service_set_provider_key(maps_service_h maps,
187 const char *provider_key)
189 if (!maps || !provider_key)
190 return MAPS_ERROR_INVALID_PARAMETER;
191 const plugin::plugin_s *p = __extract_plugin(maps);
193 return MAPS_ERROR_INVALID_PARAMETER;
194 return p->interface.maps_plugin_set_provider_key(provider_key);
197 EXPORT_API int maps_service_get_provider_key(const maps_service_h maps,
200 if (!maps || !provider_key)
201 return MAPS_ERROR_INVALID_PARAMETER;
202 const plugin::plugin_s *p = __extract_plugin(maps);
204 return MAPS_ERROR_INVALID_PARAMETER;
205 return p->interface.maps_plugin_get_provider_key(provider_key);
208 EXPORT_API int maps_service_set_preference(maps_service_h maps,
209 maps_string_hashtable_h preference)
211 if (!maps || !preference)
212 return MAPS_ERROR_INVALID_PARAMETER;
213 const plugin::plugin_s *p = __extract_plugin(maps);
215 return MAPS_ERROR_INVALID_PARAMETER;
216 return p->interface.maps_plugin_set_preference(preference);
219 EXPORT_API int maps_service_get_preference(maps_service_h maps,
220 maps_string_hashtable_h *preference)
222 if (!maps || !preference)
223 return MAPS_ERROR_INVALID_PARAMETER;
224 const plugin::plugin_s *p = __extract_plugin(maps);
226 return MAPS_ERROR_INVALID_PARAMETER;
227 return p->interface.maps_plugin_get_preference(preference);
230 EXPORT_API int maps_service_provider_is_service_supported(const maps_service_h
232 maps_service_e service,
235 if (!maps || !supported)
236 return MAPS_ERROR_INVALID_PARAMETER;
237 if ((service < MAPS_SERVICE_GEOCODE)
238 || (service > MAPS_SERVICE_CANCEL_REQUEST))
239 return MAPS_ERROR_INVALID_PARAMETER;
240 const plugin::plugin_s *p = __extract_plugin(maps);
242 return MAPS_ERROR_NOT_SUPPORTED;
243 return p->interface.maps_plugin_is_service_supported(service,
247 EXPORT_API int maps_service_provider_is_data_supported(const maps_service_h
249 maps_service_data_e data,
252 if (!maps || !supported)
253 return MAPS_ERROR_INVALID_PARAMETER;
254 if ((data < MAPS_PLACE_ADDRESS)
255 || (data > MAPS_ROUTE_SEGMENTS_MANEUVERS))
256 return MAPS_ERROR_INVALID_PARAMETER;
258 const plugin::plugin_s *p = __extract_plugin(maps);
260 return MAPS_ERROR_NOT_SUPPORTED;
261 return p->interface.maps_plugin_is_data_supported(data, supported);
264 /*----------------------------------------------------------------------------*/
266 /* Geocoder Service */
268 EXPORT_API int maps_service_geocode(const maps_service_h maps,
270 const maps_preference_h preference,
271 maps_service_geocode_cb callback,
275 /* Check if the handle of the Maps Service is valid */
277 return MAPS_ERROR_INVALID_PARAMETER;
279 /* Check if this API feature available */
280 if (!__maps_provider_supported(maps, MAPS_SERVICE_GEOCODE))
281 return MAPS_ERROR_NOT_SUPPORTED;
283 /* Check if parameters are valid */
284 if (!address || !callback || !request_id)
285 return MAPS_ERROR_INVALID_PARAMETER;
287 /* Check if privileges enough */
288 if (!__has_maps_service_privilege())
289 return MAPS_ERROR_PERMISSION_DENIED;
291 return q()->push(new session::command_geocode(maps, address, preference,
292 callback, user_data, request_id));
295 EXPORT_API int maps_service_geocode_inside_area(const maps_service_h maps,
297 const maps_area_h bounds,
298 const maps_preference_h preference,
299 maps_service_geocode_cb callback,
300 void *user_data, int *request_id)
302 /* Check if the handle of the Maps Service is valid */
304 return MAPS_ERROR_INVALID_PARAMETER;
306 /* Check if this API feature available */
307 if (!__maps_provider_supported(maps,
308 MAPS_SERVICE_GEOCODE_INSIDE_AREA))
309 return MAPS_ERROR_NOT_SUPPORTED;
311 /* Check if parameters are valid */
312 if (!address || !bounds || !callback || !request_id)
313 return MAPS_ERROR_INVALID_PARAMETER;
315 /* Check if privileges enough */
316 if (!__has_maps_service_privilege())
317 return MAPS_ERROR_PERMISSION_DENIED;
319 return q()->push(new session::command_geocode_inside_bounds(maps,
320 address, bounds, preference, callback, user_data,
324 EXPORT_API int maps_service_geocode_by_structured_address(const maps_service_h
326 const maps_address_h address,
327 const maps_preference_h preference,
328 maps_service_geocode_cb callback,
329 void *user_data, int *request_id)
331 /* Check if the handle of the Maps Service is valid */
333 return MAPS_ERROR_INVALID_PARAMETER;
335 /* Check if this API feature available */
336 if (!__maps_provider_supported(maps,
337 MAPS_SERVICE_GEOCODE_BY_STRUCTURED_ADDRESS))
338 return MAPS_ERROR_NOT_SUPPORTED;
340 /* Check if parameters are valid */
341 if (!address || !callback || !request_id)
342 return MAPS_ERROR_INVALID_PARAMETER;
344 /* Check if privileges enough */
345 if (!__has_maps_service_privilege())
346 return MAPS_ERROR_PERMISSION_DENIED;
349 push(new session::command_geocode_by_structured_address(maps,
350 address, preference, callback, user_data, request_id));
353 EXPORT_API int maps_service_reverse_geocode(const maps_service_h maps,
354 double latitude, double longitude,
355 const maps_preference_h preference,
356 maps_service_reverse_geocode_cb
357 callback, void * user_data,
360 /* Check if the handle of the Maps Service is valid */
362 return MAPS_ERROR_INVALID_PARAMETER;
364 /* Check if this API feature available */
365 if (!__maps_provider_supported(maps, MAPS_SERVICE_REVERSE_GEOCODE))
366 return MAPS_ERROR_NOT_SUPPORTED;
368 /* Check if parameters are valid */
369 if (!callback || !request_id)
370 return MAPS_ERROR_INVALID_PARAMETER;
371 if (latitude <= -90 && latitude >= 90)
372 return MAPS_ERROR_INVALID_PARAMETER;
373 if (longitude <= -180 && longitude >= 180)
374 return MAPS_ERROR_INVALID_PARAMETER;
376 /* Check if privileges enough */
377 if (!__has_maps_service_privilege())
378 return MAPS_ERROR_PERMISSION_DENIED;
380 return q()->push(new session::command_reverse_geocode(maps, latitude,
381 longitude, preference, callback, user_data,
385 /*----------------------------------------------------------------------------*/
389 EXPORT_API int maps_service_search_place(const maps_service_h maps,
390 const maps_coordinates_h position,
392 const maps_place_filter_h filter,
393 maps_preference_h preference,
394 maps_service_search_place_cb callback,
395 void *user_data, int *request_id)
397 /* Check if the handle of the Maps Service is valid */
399 return MAPS_ERROR_INVALID_PARAMETER;
401 /* Check if this API feature available */
402 if (!__maps_provider_supported(maps, MAPS_SERVICE_SEARCH_PLACE))
403 return MAPS_ERROR_NOT_SUPPORTED;
405 /* Check if parameters are valid */
406 if (!position || !filter || !callback || !request_id)
407 return MAPS_ERROR_INVALID_PARAMETER;
409 /* Check if privileges enough */
410 if (!__has_maps_service_privilege())
411 return MAPS_ERROR_PERMISSION_DENIED;
413 return q()->push(new session::command_search_place(maps, position,
414 distance, preference, filter, callback, user_data,
418 EXPORT_API int maps_service_search_place_by_area(const maps_service_h maps,
419 const maps_area_h boundary,
420 const maps_place_filter_h
422 maps_preference_h preference,
423 maps_service_search_place_cb
428 /* Check if the handle of the Maps Service is valid */
430 return MAPS_ERROR_INVALID_PARAMETER;
432 /* Check if this API feature available */
433 if (!__maps_provider_supported(maps,
434 MAPS_SERVICE_SEARCH_PLACE_BY_AREA))
435 return MAPS_ERROR_NOT_SUPPORTED;
437 /* Check if parameters are valid */
438 if (!boundary || !filter || !callback || !request_id)
439 return MAPS_ERROR_INVALID_PARAMETER;
441 /* Check if privileges enough */
442 if (!__has_maps_service_privilege())
443 return MAPS_ERROR_PERMISSION_DENIED;
445 return q()->push(new session::command_search_by_area_place(maps,
446 boundary, preference, filter, callback, user_data,
450 EXPORT_API int maps_service_search_place_by_address(const maps_service_h maps,
452 const maps_area_h boundary,
453 const maps_place_filter_h
457 maps_service_search_place_cb
462 /* Check if the handle of the Maps Service is valid */
464 return MAPS_ERROR_INVALID_PARAMETER;
466 /* Check if this API feature available */
467 if (!__maps_provider_supported(maps,
468 MAPS_SERVICE_SEARCH_PLACE_BY_ADDRESS))
469 return MAPS_ERROR_NOT_SUPPORTED;
471 /* Check if parameters are valid */
472 if (!address || !boundary || !filter || !callback || !request_id)
473 return MAPS_ERROR_INVALID_PARAMETER;
475 /* Check if privileges enough */
476 if (!__has_maps_service_privilege())
477 return MAPS_ERROR_PERMISSION_DENIED;
479 return q()->push(new session::command_search_by_address_place(maps,
480 address, boundary, preference, filter, callback,
481 user_data, request_id));
484 /*----------------------------------------------------------------------------*/
488 EXPORT_API int maps_service_search_route(const maps_service_h maps,
489 const maps_coordinates_h origin,
490 const maps_coordinates_h destination,
491 maps_preference_h preference,
492 maps_service_search_route_cb callback,
493 void *user_data, int *request_id)
495 /* Check if the handle of the Maps Service is valid */
497 return MAPS_ERROR_INVALID_PARAMETER;
499 /* Check if this API feature available */
500 if (!__maps_provider_supported(maps, MAPS_SERVICE_SEARCH_ROUTE))
501 return MAPS_ERROR_NOT_SUPPORTED;
503 /* Check if parameters are valid */
504 if (!origin || !destination || !callback || !request_id)
505 return MAPS_ERROR_INVALID_PARAMETER;
507 /* Check if privileges enough */
508 if (!__has_maps_service_privilege())
509 return MAPS_ERROR_PERMISSION_DENIED;
511 return q()->push(new session::command_search_route(maps, preference,
512 origin, destination, callback, user_data, request_id));
515 EXPORT_API int maps_service_search_route_waypoints(const maps_service_h maps,
516 const maps_coordinates_h *
519 maps_preference_h preference,
520 maps_service_search_route_cb
525 /* Check if the handle of the Maps Service is valid */
527 return MAPS_ERROR_INVALID_PARAMETER;
529 /* Check if this API feature available */
530 if (!__maps_provider_supported(maps,
531 MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS))
532 return MAPS_ERROR_NOT_SUPPORTED;
534 /* Check if parameters are valid */
535 if (!waypoint_list || (waypoint_num < 2) || !callback || !request_id)
536 return MAPS_ERROR_INVALID_PARAMETER;
538 /* Check if privileges enough */
539 if (!__has_maps_service_privilege())
540 return MAPS_ERROR_PERMISSION_DENIED;
542 return q()->push(new session::command_search_route_waypoints(maps,
543 preference, waypoint_list, waypoint_num, callback,
544 user_data, request_id));
547 /*----------------------------------------------------------------------------*/
549 /* Cancel Service Request */
551 EXPORT_API int maps_service_cancel_request(const maps_service_h maps,
554 /* Check if the handle of the Maps Service is valid */
556 return MAPS_ERROR_INVALID_PARAMETER;
558 /* Check if this API feature available */
559 if (!__maps_provider_supported(maps, MAPS_SERVICE_CANCEL_REQUEST))
560 return MAPS_ERROR_NOT_SUPPORTED;
562 /* Check if parameters are valid */
564 return MAPS_ERROR_INVALID_PARAMETER;
566 /* Check if privileges enough */
567 if (!__has_maps_service_privilege())
568 return MAPS_ERROR_PERMISSION_DENIED;
570 return q()->push(new session::command_cancel_request(maps, request_id));