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