94552a9681a283279587f5d9c5144d8d04a4714f
[platform/core/api/maps-service.git] / src / api / maps_service.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_service.h"
19 #include "maps_error.h"
20 #include "maps_service.h"
21 #include "maps_util.h"
22 #include "maps_condition.h"
23
24 #include "command_queue.h"
25 #include "commands.h"
26 #include "discovery.h"
27 #include "module.h"
28
29 /*----------------------------------------------------------------------------*/
30 /* Structure of maps_service */
31 /* maps_service_s* is used as maps_service_h */
32 typedef struct _maps_service_s
33 {
34         maps_plugin_h plugin;
35 } maps_service_s;
36
37 const gsize _MAPS_PROVIDER_KEY_MAX_LENGTH = 1024;
38
39 /* This function is used in command class */
40 plugin::plugin_s *__extract_plugin(maps_service_h maps)
41 {
42         if (!maps)
43                 return NULL;
44         maps_service_s *maps_service = (maps_service_s *) maps;
45         return (plugin::plugin_s *) maps_service->plugin;
46 }
47
48 static bool __maps_provider_supported(maps_service_h maps, maps_service_e service)
49 {
50         if (!maps)
51                 return false;
52         bool supported = false;
53         if (maps_service_provider_is_service_supported(maps, service, &supported)
54                 != MAPS_ERROR_NONE)
55                 return false;
56         return supported;
57 }
58
59
60 /*----------------------------------------------------------------------------*/
61 /* */
62 /* Maps Service & Preference */
63
64 EXPORT_API int maps_service_foreach_provider(maps_service_provider_info_cb callback,
65                                              void *user_data)
66 {
67         if (!maps_condition_check_maps_feature())
68                 return MAPS_ERROR_NOT_SUPPORTED;
69         if (!callback)
70                 return MAPS_ERROR_INVALID_PARAMETER;
71
72         /* The list of map provider info, obtained by enumerating available plugins */
73         plugin::discovery pd;
74         vector <plugin::provider_info> v = pd.get_available_list();
75
76         /* Send obtained provider info to the user */
77         const int total = int(v.size());
78         for (int i = 0; i < total; i++) {
79                 /* Get a plugin info handle from the array */
80                 /* and send a callback with provider info to the user */
81                 char *provider = g_strdup(v[i].provider.c_str());
82                 if (!callback(provider, user_data))
83                         break;
84         }
85
86         return MAPS_ERROR_NONE;
87 }
88
89 EXPORT_API int maps_service_request_user_consent(const char *maps_provider,
90                                                                 maps_service_request_user_consent_cb callback, void *user_data)
91 {
92         if (!maps_condition_check_maps_feature())
93                 return MAPS_ERROR_NOT_SUPPORTED;
94         /* Check if parameters are valid */
95         if (!maps_provider || !callback)
96                 return MAPS_ERROR_INVALID_PARAMETER;
97
98         /* Check if privileges enough */
99         if (!maps_condition_check_privilege())
100                 return MAPS_ERROR_PERMISSION_DENIED;
101
102         int error = plugin::request_user_consent(maps_provider, (void*)callback, user_data);
103         return error;
104 }
105
106 EXPORT_API int maps_service_create(const char *maps_provider, maps_service_h *maps)
107 {
108         if (!maps_condition_check_maps_feature())
109                 return MAPS_ERROR_NOT_SUPPORTED;
110         if (!maps || !maps_provider)
111                 return MAPS_ERROR_INVALID_PARAMETER;
112         if (!maps_condition_check_privilege()) {
113                 MAPS_LOGD("ERROR: privilege is not included");
114                 return MAPS_ERROR_PERMISSION_DENIED;
115         }
116
117         int error = MAPS_ERROR_NOT_SUPPORTED;
118         char *provider = NULL, *module = NULL;
119
120         do {
121                 /* 0. Find the plugin, requested by the user */
122                 plugin::split_provider_name(maps_provider, &provider, &module);
123                 const plugin::provider_info info = plugin::find_by_names(provider);
124
125                 /* 1. Check whether provider info is valid */
126                 if (info.empty()) {
127                         MAPS_LOGE("ERROR! Provider info not found for name: %s", maps_provider);
128                         error = MAPS_ERROR_NOT_SUPPORTED;
129                         break;
130                 }
131
132                 /* 2. Setup maps service handling structure */
133                 maps_service_s *maps_service = g_slice_new0(maps_service_s);
134
135                 if (maps_service == NULL) {
136                         MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
137                         error = MAPS_ERROR_OUT_OF_MEMORY;
138                         break;
139                 }
140
141                 /* 3. Initialize the requested plugin */
142                 int init_error = MAPS_ERROR_NONE; /* Storage for init error code */
143                 maps_plugin_h plugin_h = plugin::binary_extractor().init(info, module, &init_error);
144                 if (!plugin_h) {
145                         error = init_error;
146                         MAPS_LOGE("ERROR! Plugin init failed");
147                         break;
148                 }
149
150                 maps_service->plugin = plugin_h;
151
152                 /* 4. Initialize an output pointer to maps service */
153                 *maps = maps_service;
154
155                 /* 5. Set status of completely correct plugin initialization */
156                 error = MAPS_ERROR_NONE;
157         } while (false);
158
159         if (error != MAPS_ERROR_NONE)
160                 maps_service_destroy(*maps);
161
162         g_free(provider);
163         g_free(module);
164         return error;
165 }
166
167 EXPORT_API int maps_service_destroy(maps_service_h maps)
168 {
169         if (!maps_condition_check_maps_feature())
170                 return MAPS_ERROR_NOT_SUPPORTED;
171         if (!maps)
172                 return MAPS_ERROR_INVALID_PARAMETER;
173         if (!maps_condition_check_privilege())
174                 return MAPS_ERROR_PERMISSION_DENIED;
175
176         maps_service_s *maps_service = (maps_service_s *) maps;
177
178         if (maps_service->plugin)
179                 plugin::binary_extractor().shutdown(maps_service->plugin);
180
181         g_slice_free(maps_service_s, maps);
182
183         return MAPS_ERROR_NONE;
184 }
185
186 EXPORT_API int maps_service_set_provider_key(maps_service_h maps,
187                                              const char *provider_key)
188 {
189         if (!maps_condition_check_maps_feature())
190                 return MAPS_ERROR_NOT_SUPPORTED;
191         if (!maps || !provider_key)
192                 return MAPS_ERROR_INVALID_PARAMETER;
193
194         const plugin::plugin_s *p = __extract_plugin(maps);
195         if (!p)
196                 return MAPS_ERROR_INVALID_PARAMETER;
197         return p->interface.maps_plugin_set_provider_key(provider_key);
198 }
199
200 EXPORT_API int maps_service_get_provider_key(const maps_service_h maps,
201                                              char **provider_key)
202 {
203         if (!maps_condition_check_maps_feature())
204                 return MAPS_ERROR_NOT_SUPPORTED;
205         if (!maps || !provider_key)
206                 return MAPS_ERROR_INVALID_PARAMETER;
207
208         const plugin::plugin_s *p = __extract_plugin(maps);
209         if (!p)
210                 return MAPS_ERROR_INVALID_PARAMETER;
211         return p->interface.maps_plugin_get_provider_key(provider_key);
212 }
213
214 EXPORT_API int maps_service_set_preference(maps_service_h maps,
215                                            maps_string_hashtable_h preference)
216 {
217         if (!maps_condition_check_maps_feature())
218                 return MAPS_ERROR_NOT_SUPPORTED;
219         if (!maps || !preference)
220                 return MAPS_ERROR_INVALID_PARAMETER;
221
222         const plugin::plugin_s *p = __extract_plugin(maps);
223         if (!p)
224                 return MAPS_ERROR_INVALID_PARAMETER;
225         return p->interface.maps_plugin_set_preference(preference);
226 }
227
228 EXPORT_API int maps_service_get_preference(maps_service_h maps,
229                                            maps_string_hashtable_h *preference)
230 {
231         if (!maps_condition_check_maps_feature())
232                 return MAPS_ERROR_NOT_SUPPORTED;
233         if (!maps || !preference)
234                 return MAPS_ERROR_INVALID_PARAMETER;
235
236         const plugin::plugin_s *p = __extract_plugin(maps);
237         if (!p)
238                 return MAPS_ERROR_INVALID_PARAMETER;
239         return p->interface.maps_plugin_get_preference(preference);
240 }
241
242 EXPORT_API int maps_service_provider_is_service_supported(const maps_service_h maps,
243                                                         maps_service_e service,
244                                                         bool *supported)
245 {
246         if (!maps_condition_check_maps_feature())
247                 return MAPS_ERROR_NOT_SUPPORTED;
248         if (!maps || !supported)
249                 return MAPS_ERROR_INVALID_PARAMETER;
250         if (!(service >= MAPS_SERVICE_GEOCODE && service <= MAPS_SERVICE_SEARCH_GET_PLACE_DETAILS) &&
251                 !(service >= MAPS_SERVICE_VIEW && service <= MAPS_SERVICE_VIEW_SNAPSHOT))
252                 return MAPS_ERROR_INVALID_PARAMETER;
253
254         const plugin::plugin_s *p = __extract_plugin(maps);
255         if (!p)
256                 return MAPS_ERROR_NOT_SUPPORTED;
257         return p->interface.maps_plugin_is_service_supported(service, supported);
258 }
259
260 EXPORT_API int maps_service_provider_is_data_supported(const maps_service_h maps,
261                                                        maps_service_data_e data,
262                                                        bool *supported)
263 {
264         if (!maps_condition_check_maps_feature())
265                 return MAPS_ERROR_NOT_SUPPORTED;
266         if (!maps || !supported)
267                 return MAPS_ERROR_INVALID_PARAMETER;
268         if (!(data >= MAPS_PLACE_ADDRESS && data <= MAPS_ROUTE_SEGMENTS_MANEUVERS) &&
269                 !(data >= MAPS_VIEW_TRAFFIC && data <= MAPS_VIEW_SCALEBAR))
270                 return MAPS_ERROR_INVALID_PARAMETER;
271
272         const plugin::plugin_s *p = __extract_plugin(maps);
273         if (!p)
274                 return MAPS_ERROR_NOT_SUPPORTED;
275         return p->interface.maps_plugin_is_data_supported(data, supported);
276 }
277
278 /*----------------------------------------------------------------------------*/
279 /* */
280 /* Geocoder Service */
281
282 EXPORT_API int maps_service_geocode(const maps_service_h maps,
283                                     const char *address,
284                                     const maps_preference_h preference,
285                                     maps_service_geocode_cb callback,
286                                     void *user_data,
287                                     int *request_id)
288 {
289         /* Check if internet feature is supported */
290         if (!maps_condition_check_maps_feature() || !maps_condition_check_internet_feature())
291                 return MAPS_ERROR_NOT_SUPPORTED;
292
293         /* Check if the handle of the Maps Service is valid */
294         if (!maps)
295                 return MAPS_ERROR_INVALID_PARAMETER;
296
297         /* Check if this API feature available */
298         if (!__maps_provider_supported(maps, MAPS_SERVICE_GEOCODE))
299                 return MAPS_ERROR_NOT_SUPPORTED;
300
301         /* Check if parameters are valid */
302         if (!address || !callback || !request_id)
303                 return MAPS_ERROR_INVALID_PARAMETER;
304
305         /* Check if privileges enough */
306         if (!maps_condition_check_privilege())
307                 return MAPS_ERROR_PERMISSION_DENIED;
308
309         session::command *cmd = new session::command_geocode(maps, address, preference,
310                         callback, user_data, request_id);
311
312         int ret = (cmd && cmd->plugin()) ? cmd->run() : MAPS_ERROR_INVALID_PARAMETER;
313         if (ret) MAPS_LOGE("Failed to run command.(%d)", ret);
314         return ret;
315 }
316
317 EXPORT_API int maps_service_geocode_inside_area(const maps_service_h maps,
318                                                 const char *address,
319                                                 const maps_area_h bounds,
320                                                 const maps_preference_h preference,
321                                                 maps_service_geocode_cb callback,
322                                                 void *user_data, int *request_id)
323 {
324         /* Check if internet feature is supported */
325         if (!maps_condition_check_maps_feature() || !maps_condition_check_internet_feature())
326                 return MAPS_ERROR_NOT_SUPPORTED;
327
328         /* Check if the handle of the Maps Service is valid */
329         if (!maps)
330                 return MAPS_ERROR_INVALID_PARAMETER;
331
332         /* Check if this API feature available */
333         if (!__maps_provider_supported(maps,
334                         MAPS_SERVICE_GEOCODE_INSIDE_AREA))
335                 return MAPS_ERROR_NOT_SUPPORTED;
336
337         /* Check if parameters are valid */
338         if (!address || !bounds || !callback || !request_id)
339                 return MAPS_ERROR_INVALID_PARAMETER;
340
341         /* Check if privileges enough */
342         if (!maps_condition_check_privilege())
343                 return MAPS_ERROR_PERMISSION_DENIED;
344
345         session::command *cmd = new session::command_geocode_inside_bounds(maps,
346                         address, bounds, preference, callback, user_data, request_id);
347
348         int ret = (cmd && cmd->plugin()) ? cmd->run() : MAPS_ERROR_INVALID_PARAMETER;
349         if (ret) MAPS_LOGE("Failed to run command.(%d)", ret);
350         return ret;
351 }
352
353 EXPORT_API int maps_service_geocode_by_structured_address(const maps_service_h maps,
354                                         const maps_address_h address,
355                                         const maps_preference_h preference,
356                                         maps_service_geocode_cb callback,
357                                         void *user_data, int *request_id)
358 {
359         /* Check if internet feature is supported */
360         if (!maps_condition_check_maps_feature() || !maps_condition_check_internet_feature())
361                 return MAPS_ERROR_NOT_SUPPORTED;
362
363         /* Check if the handle of the Maps Service is valid */
364         if (!maps)
365                 return MAPS_ERROR_INVALID_PARAMETER;
366
367         /* Check if this API feature available */
368         if (!__maps_provider_supported(maps,
369                         MAPS_SERVICE_GEOCODE_BY_STRUCTURED_ADDRESS))
370                 return MAPS_ERROR_NOT_SUPPORTED;
371
372         /* Check if parameters are valid */
373         if (!address || !callback || !request_id)
374                 return MAPS_ERROR_INVALID_PARAMETER;
375
376         /* Check if privileges enough */
377         if (!maps_condition_check_privilege())
378                 return MAPS_ERROR_PERMISSION_DENIED;
379
380         session::command *cmd = new session::command_geocode_by_structured_address(maps,
381                         address, preference, callback, user_data, request_id);
382
383         int ret = (cmd && cmd->plugin()) ? cmd->run() : MAPS_ERROR_INVALID_PARAMETER;
384         if (ret) MAPS_LOGE("Failed to run command.(%d)", ret);
385         return ret;
386 }
387
388 EXPORT_API int maps_service_reverse_geocode(const maps_service_h maps,
389                                             double latitude, double longitude,
390                                             const maps_preference_h preference,
391                                             maps_service_reverse_geocode_cb
392                                             callback, void * user_data,
393                                             int *request_id)
394 {
395         /* Check if internet feature is supported */
396         if (!maps_condition_check_maps_feature() || !maps_condition_check_internet_feature())
397                 return MAPS_ERROR_NOT_SUPPORTED;
398
399         /* Check if the handle of the Maps Service is valid */
400         if (!maps)
401                 return MAPS_ERROR_INVALID_PARAMETER;
402
403         /* Check if this API feature available */
404         if (!__maps_provider_supported(maps, MAPS_SERVICE_REVERSE_GEOCODE))
405                 return MAPS_ERROR_NOT_SUPPORTED;
406
407         /* Check if parameters are valid */
408         if (!callback || !request_id)
409                 return MAPS_ERROR_INVALID_PARAMETER;
410         if (latitude <= -90 || latitude >= 90)
411                 return MAPS_ERROR_INVALID_PARAMETER;
412         if (longitude <= -180 || longitude >= 180)
413                 return MAPS_ERROR_INVALID_PARAMETER;
414
415         /* Check if privileges enough */
416         if (!maps_condition_check_privilege())
417                 return MAPS_ERROR_PERMISSION_DENIED;
418
419         session::command *cmd = new session::command_reverse_geocode(maps, latitude,
420                         longitude, preference, callback, user_data, request_id);
421
422         int ret = (cmd && cmd->plugin()) ? cmd->run() : MAPS_ERROR_INVALID_PARAMETER;
423         if (ret) MAPS_LOGE("Failed to run command.(%d)", ret);
424         return ret;
425 }
426
427 /*----------------------------------------------------------------------------*/
428 /* */
429 /* Place Service */
430
431 EXPORT_API int maps_service_search_place(const maps_service_h maps,
432                                          const maps_coordinates_h position,
433                                          int distance,
434                                          const maps_place_filter_h filter,
435                                          maps_preference_h preference,
436                                          maps_service_search_place_cb callback,
437                                          void *user_data, int *request_id)
438 {
439         /* Check if internet feature is supported */
440         if (!maps_condition_check_maps_feature() || !maps_condition_check_internet_feature())
441                 return MAPS_ERROR_NOT_SUPPORTED;
442
443         /* Check if the handle of the Maps Service is valid */
444         if (!maps)
445                 return MAPS_ERROR_INVALID_PARAMETER;
446
447         /* Check if this API feature available */
448         if (!__maps_provider_supported(maps, MAPS_SERVICE_SEARCH_PLACE))
449                 return MAPS_ERROR_NOT_SUPPORTED;
450
451         /* Check if parameters are valid */
452         if (!position || (distance < 0) || !filter || !callback || !request_id)
453                 return MAPS_ERROR_INVALID_PARAMETER;
454
455         /* Check if privileges enough */
456         if (!maps_condition_check_privilege())
457                 return MAPS_ERROR_PERMISSION_DENIED;
458
459         session::command *cmd = new session::command_search_place(maps, position,
460                         distance, preference, filter, callback, user_data, request_id);
461
462         int ret = (cmd && cmd->plugin()) ? cmd->run() : MAPS_ERROR_INVALID_PARAMETER;
463         if (ret) MAPS_LOGE("Failed to run command.(%d)", ret);
464         return ret;
465 }
466
467 EXPORT_API int maps_service_search_place_by_area(const maps_service_h maps,
468                                                  const maps_area_h boundary,
469                                                  const maps_place_filter_h filter,
470                                                  maps_preference_h preference,
471                                                  maps_service_search_place_cb callback,
472                                                  void *user_data,
473                                                  int *request_id)
474 {
475         /* Check if internet feature is supported */
476         if (!maps_condition_check_maps_feature() || !maps_condition_check_internet_feature())
477                 return MAPS_ERROR_NOT_SUPPORTED;
478
479         /* Check if the handle of the Maps Service is valid */
480         if (!maps)
481                 return MAPS_ERROR_INVALID_PARAMETER;
482
483         /* Check if this API feature available */
484         if (!__maps_provider_supported(maps,
485                         MAPS_SERVICE_SEARCH_PLACE_BY_AREA))
486                 return MAPS_ERROR_NOT_SUPPORTED;
487
488         /* Check if parameters are valid */
489         if (!boundary || !filter || !callback || !request_id)
490                 return MAPS_ERROR_INVALID_PARAMETER;
491
492         /* Check if privileges enough */
493         if (!maps_condition_check_privilege())
494                 return MAPS_ERROR_PERMISSION_DENIED;
495
496         session::command *cmd = new session::command_search_by_area_place(maps,
497                         boundary, preference, filter, callback, user_data, request_id);
498
499         int ret = (cmd && cmd->plugin()) ? cmd->run() : MAPS_ERROR_INVALID_PARAMETER;
500         if (ret) MAPS_LOGE("Failed to run command.(%d)", ret);
501         return ret;
502 }
503
504 EXPORT_API int maps_service_search_place_by_address(const maps_service_h maps,
505                                                         const char *address,
506                                                         const maps_area_h boundary,
507                                                         const maps_place_filter_h filter,
508                                                         maps_preference_h preference,
509                                                         maps_service_search_place_cb callback,
510                                                         void *user_data,
511                                                         int *request_id)
512 {
513         /* Check if internet feature is supported */
514         if (!maps_condition_check_maps_feature() || !maps_condition_check_internet_feature())
515                 return MAPS_ERROR_NOT_SUPPORTED;
516
517         /* Check if the handle of the Maps Service is valid */
518         if (!maps)
519                 return MAPS_ERROR_INVALID_PARAMETER;
520
521         /* Check if this API feature available */
522         if (!__maps_provider_supported(maps,
523                         MAPS_SERVICE_SEARCH_PLACE_BY_ADDRESS))
524                 return MAPS_ERROR_NOT_SUPPORTED;
525
526         /* Check if parameters are valid */
527         if (!address || !boundary || !filter || !callback || !request_id)
528                 return MAPS_ERROR_INVALID_PARAMETER;
529
530         /* Check if privileges enough */
531         if (!maps_condition_check_privilege())
532                 return MAPS_ERROR_PERMISSION_DENIED;
533
534         session::command *cmd = new session::command_search_by_address_place(maps,
535                         address, boundary, preference, filter, callback, user_data, request_id);
536
537         int ret = (cmd && cmd->plugin()) ? cmd->run() : MAPS_ERROR_INVALID_PARAMETER;
538         if (ret) MAPS_LOGE("Failed to run command.(%d)", ret);
539         return ret;
540 }
541
542 EXPORT_API int maps_service_search_place_list(const maps_service_h maps,
543                                         const maps_area_h boundary,
544                                         const maps_place_filter_h filter,
545                                         maps_preference_h preference,
546                                         maps_service_search_place_list_cb callback,
547                                         void *user_data, int *request_id)
548 {
549         /* Check if internet feature is supported */
550         if (!maps_condition_check_maps_feature() || !maps_condition_check_internet_feature())
551                 return MAPS_ERROR_NOT_SUPPORTED;
552
553         if (!maps)
554                 return MAPS_ERROR_INVALID_PARAMETER;
555
556         if (!__maps_provider_supported(maps, MAPS_SERVICE_SEARCH_PLACE_LIST))
557                 return MAPS_ERROR_NOT_SUPPORTED;
558
559         if (!boundary || !filter || !callback || !request_id)
560                 return MAPS_ERROR_INVALID_PARAMETER;
561
562         if (!maps_condition_check_privilege())
563                 return MAPS_ERROR_PERMISSION_DENIED;
564
565         session::command *cmd = new session::command_search_place_list(maps,
566                         boundary, preference, filter, callback, user_data, request_id);
567
568         int ret = (cmd && cmd->plugin()) ? cmd->run() : MAPS_ERROR_INVALID_PARAMETER;
569         if (ret) MAPS_LOGE("Failed to run command.(%d)", ret);
570         return ret;
571 }
572
573 EXPORT_API int maps_service_get_place_details(const maps_service_h maps,
574         const char *url, maps_service_get_place_details_cb callback,
575         void *user_data, int *request_id)
576 {
577         /* Check if internet feature is supported */
578         if (!maps_condition_check_maps_feature() || !maps_condition_check_internet_feature())
579                 return MAPS_ERROR_NOT_SUPPORTED;
580
581         if (!maps)
582                 return MAPS_ERROR_INVALID_PARAMETER;
583
584         if (!__maps_provider_supported(maps, MAPS_SERVICE_SEARCH_PLACE_LIST))
585                 return MAPS_ERROR_NOT_SUPPORTED;
586
587         if (!url || !callback || !request_id)
588                 return MAPS_ERROR_INVALID_PARAMETER;
589
590         if (!maps_condition_check_privilege())
591                 return MAPS_ERROR_PERMISSION_DENIED;
592
593         session::command *cmd = new session::command_get_place_details(maps,
594                         url, callback, user_data, request_id);
595
596         int ret = (cmd && cmd->plugin()) ? cmd->run() : MAPS_ERROR_INVALID_PARAMETER;
597         if (ret) MAPS_LOGE("Failed to run command.(%d)", ret);
598         return ret;
599 }
600
601 /*----------------------------------------------------------------------------*/
602 /* */
603 /* Route Service */
604
605 EXPORT_API int maps_service_search_route(const maps_service_h maps,
606                                          const maps_coordinates_h origin,
607                                          const maps_coordinates_h destination,
608                                          maps_preference_h preference,
609                                          maps_service_search_route_cb callback,
610                                          void *user_data, int *request_id)
611 {
612         /* Check if internet feature is supported */
613         if (!maps_condition_check_maps_feature() || !maps_condition_check_internet_feature())
614                 return MAPS_ERROR_NOT_SUPPORTED;
615
616         /* Check if the handle of the Maps Service is valid */
617         if (!maps)
618                 return MAPS_ERROR_INVALID_PARAMETER;
619
620         /* Check if this API feature available */
621         if (!__maps_provider_supported(maps, MAPS_SERVICE_SEARCH_ROUTE))
622                 return MAPS_ERROR_NOT_SUPPORTED;
623
624         /* Check if parameters are valid */
625         if (!origin || !destination || !callback || !request_id)
626                 return MAPS_ERROR_INVALID_PARAMETER;
627
628         /* Check if privileges enough */
629         if (!maps_condition_check_privilege())
630                 return MAPS_ERROR_PERMISSION_DENIED;
631
632         session::command *cmd = new session::command_search_route(maps, preference,
633                         origin, destination, callback, user_data, request_id);
634
635         int ret = (cmd && cmd->plugin()) ? cmd->run() : MAPS_ERROR_INVALID_PARAMETER;
636         if (ret) MAPS_LOGE("Failed to run command.(%d)", ret);
637         return ret;
638 }
639
640 EXPORT_API int maps_service_search_route_waypoints(const maps_service_h maps,
641                                                    const maps_coordinates_h *waypoint_list,
642                                                    int waypoint_num,
643                                                    maps_preference_h preference,
644                                                    maps_service_search_route_cb callback,
645                                                    void *user_data,
646                                                    int *request_id)
647 {
648         /* Check if internet feature is supported */
649         if (!maps_condition_check_maps_feature() || !maps_condition_check_internet_feature())
650                 return MAPS_ERROR_NOT_SUPPORTED;
651
652         /* Check if the handle of the Maps Service is valid */
653         if (!maps)
654                 return MAPS_ERROR_INVALID_PARAMETER;
655
656         /* Check if this API feature available */
657         if (!__maps_provider_supported(maps,
658                         MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS))
659                 return MAPS_ERROR_NOT_SUPPORTED;
660
661         /* Check if parameters are valid */
662         if (!waypoint_list || (waypoint_num < 2) || !callback || !request_id)
663                 return MAPS_ERROR_INVALID_PARAMETER;
664
665         /* Check if privileges enough */
666         if (!maps_condition_check_privilege())
667                 return MAPS_ERROR_PERMISSION_DENIED;
668
669         session::command *cmd = new session::command_search_route_waypoints(maps,
670                         preference, waypoint_list, waypoint_num, callback, user_data, request_id);
671
672         int ret = (cmd && cmd->plugin()) ? cmd->run() : MAPS_ERROR_INVALID_PARAMETER;
673         if (ret) MAPS_LOGE("Failed to run command.(%d)", ret);
674         return ret;
675 }
676
677 /*----------------------------------------------------------------------------*/
678 /* */
679 /* Cancel Service Request */
680
681 EXPORT_API int maps_service_cancel_request(const maps_service_h maps, int request_id)
682 {
683         if (!maps_condition_check_maps_feature())
684                 return MAPS_ERROR_NOT_SUPPORTED;
685
686         /* Check if the handle of the Maps Service is valid */
687         if (!maps)
688                 return MAPS_ERROR_INVALID_PARAMETER;
689
690         /* Check if this API feature available */
691         if (!__maps_provider_supported(maps, MAPS_SERVICE_CANCEL_REQUEST))
692                 return MAPS_ERROR_NOT_SUPPORTED;
693
694         /* Check if parameters are valid */
695         if (request_id < 0)
696                 return MAPS_ERROR_INVALID_PARAMETER;
697
698         /* Check if privileges enough */
699         if (!maps_condition_check_privilege())
700                 return MAPS_ERROR_PERMISSION_DENIED;
701
702         session::command *cmd = new session::command_cancel_request(maps, request_id);
703
704         int ret = (cmd && cmd->plugin()) ? cmd->run() : MAPS_ERROR_INVALID_PARAMETER;
705         if (ret) MAPS_LOGE("Failed to run command.(%d)", ret);
706         return ret;
707 }
708
709 /*----------------------------------------------------------------------------*/
710 /* */
711 /* Multi geocoder */
712
713 EXPORT_API int maps_service_multi_reverse_geocode(const maps_service_h maps,
714         const maps_coordinates_list_h coordinates_list, const maps_preference_h preference,
715         maps_service_multi_reverse_geocode_cb callback, void *user_data, int *request_id)
716 {
717         if (!maps_condition_check_maps_feature() || !maps_condition_check_internet_feature())
718                 return MAPS_ERROR_NOT_SUPPORTED;
719
720         if (!maps)
721                 return MAPS_ERROR_INVALID_PARAMETER;
722
723         if (!__maps_provider_supported(maps, MAPS_SERVICE_MULTI_REVERSE_GEOCODE))
724                 return MAPS_ERROR_NOT_SUPPORTED;
725
726         if (!coordinates_list || !callback || !request_id)
727                 return MAPS_ERROR_INVALID_PARAMETER;
728
729         if (!maps_condition_check_privilege())
730                 return MAPS_ERROR_PERMISSION_DENIED;
731
732         session::command *cmd = new session::command_multi_reverse_geocode(maps,
733                         coordinates_list, preference, callback, user_data, request_id);
734
735         int ret = (cmd && cmd->plugin()) ? cmd->run() : MAPS_ERROR_INVALID_PARAMETER;
736         if (ret) MAPS_LOGE("Failed to run command.(%d)", ret);
737         return ret;
738 }
739