1 /* Copyright (c) 2010-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_util.h"
19 #include "maps_place_private.h"
20 #include "maps_route_private.h"
21 #include "empty_module.h"
23 static int __put_to_hashtable(session::command_handler *ch,
24 maps_service_data_e feature,
25 const char *feature_str,
26 maps_string_hashtable_h t)
28 if (!ch || !feature_str || !t)
29 return MAPS_ERROR_INVALID_PARAMETER;
30 bool supported = false;
31 ch->plugin()->interface.maps_plugin_is_data_supported(feature,
33 return (supported) ? maps_string_hashtable_set(t, feature_str,
34 feature_str) : MAPS_ERROR_NONE;
37 /*----------------------------------------------------------------------------*/
38 /*typedef int (*maps_plugin_geocode_f)(maps_service_h maps, const char *address,
39 * maps_service_geocode_cb callback, void *user_data, int *request_id); */
40 session::command_geocode::command_geocode(maps_service_h ms, const string a,
41 const maps_item_hashtable_h pref,
42 maps_service_geocode_cb cb,
43 void *ud, int *request_id)
51 *request_id = command::command_request_id++;
52 my_req_id = *request_id;
55 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
56 error = MAPS_ERROR_INVALID_PARAMETER;
59 session::command_geocode::~command_geocode()
61 maps_item_hashtable_destroy(preference);
64 int session::command_geocode::run()
67 if (error != MAPS_ERROR_NONE)
70 pending_request pr(plugin());
72 /* Get the plugin interface function */
73 maps_plugin_geocode_f func = interface()->maps_plugin_geocode;
74 command_geocode_handler *handler = NULL;
76 /* need to create the handler when the function is NULL */
78 handler = new command_geocode_handler(plugin(),
84 /* Run the plugin interface function */
85 error = func(address.c_str(), preference,
86 command_geocode_handler::foreach_geocode_cb, handler,
87 &handler->plg_req_id);
89 pr.update(my_req_id, handler);
91 MAPS_LOGD("session::command_geocode::run: %d", my_req_id);
94 error = MAPS_ERROR_OUT_OF_MEMORY;
98 /* Plugin Function is NULL: use default empty function */
100 func = plugin::get_empty_interface().maps_plugin_geocode;
102 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
103 error = MAPS_ERROR_NOT_SUPPORTED;
106 const int ret = error;
111 session::command_geocode_handler::command_geocode_handler(plugin::plugin_s *p,
112 maps_service_geocode_cb cb,
114 : command_handler(p, ud, urid)
119 bool session::command_geocode_handler::foreach_geocode_cb(maps_error_e error,
128 command_geocode_handler *handler =
129 (command_geocode_handler *) user_data;
131 if (request_id != handler->plg_req_id) {
133 "\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
134 request_id, handler->plg_req_id);
137 /* Make a user's copy of result data */
138 maps_coordinates_h cloned_result = NULL;
139 if (error == MAPS_ERROR_NONE)
140 error = (maps_error_e) maps_coordinates_clone(coordinates,
142 maps_coordinates_destroy(coordinates);
144 /* Send data to user */
146 handler->callback(error, handler->user_req_id, index,
147 total_count, cloned_result, handler->user_data);
148 if (!b || (index >= (total_count - 1))) {
149 pending_request pr(handler->plugin());
150 pr.remove(handler->user_req_id);
156 /*----------------------------------------------------------------------------*/
157 /*typedef int (*maps_plugin_geocode_inside_area_f)(maps_service_h maps, const
158 * char *address, maps_area_h bounds, maps_service_geocode_cb callback,
159 * void *user_data, int *request_id); */
160 session::command_geocode_inside_bounds::command_geocode_inside_bounds(
164 const maps_item_hashtable_h pref,
165 maps_service_geocode_cb cb,
166 void *ud, int *request_id)
175 *request_id = command::command_request_id++;
176 my_req_id = *request_id;
178 if (maps_area_clone(b, &bounds) != MAPS_ERROR_NONE)
179 error = MAPS_ERROR_INVALID_PARAMETER;
182 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
183 error = MAPS_ERROR_INVALID_PARAMETER;
186 session::command_geocode_inside_bounds::~command_geocode_inside_bounds()
188 maps_area_destroy(bounds);
189 maps_item_hashtable_destroy(preference);
192 int session::command_geocode_inside_bounds::run()
194 if (error != MAPS_ERROR_NONE)
197 pending_request pr(plugin());
199 /* Get the plugin interface function */
200 maps_plugin_geocode_inside_area_f func =
201 interface()->maps_plugin_geocode_inside_area;
202 command_geocode_handler *handler = NULL;
204 /* No need to create the handler when the function is NULL */
206 handler = new command_geocode_handler(plugin(),
212 /* Run the plugin interface function */
213 error = func(address.c_str(), bounds, preference,
214 command_geocode_handler::foreach_geocode_cb,
215 handler, &handler->plg_req_id);
217 pr.update(my_req_id, handler);
219 MAPS_LOGD("session::command_geocode_inside_bounds::run: %d", my_req_id);
222 error = MAPS_ERROR_OUT_OF_MEMORY;
226 /* Plugin Function is NULL: use default empty function */
228 func = plugin::get_empty_interface().
229 maps_plugin_geocode_inside_area;
231 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
232 error = MAPS_ERROR_NOT_SUPPORTED;
235 const int ret = error;
240 /*----------------------------------------------------------------------------*/
241 /*typedef int (*maps_plugin_geocode_by_structured_address_f)(
242 * maps_service_h maps, maps_address_h address, maps_preference_h preference,
243 * maps_service_geocode_cb callback, void *user_data, int *request_id); */
244 session::command_geocode_by_structured_address::
245 command_geocode_by_structured_address(maps_service_h ms,
246 const maps_address_h a,
247 const maps_item_hashtable_h pref,
248 maps_service_geocode_cb cb,
249 void *ud, int *request_id)
257 *request_id = command::command_request_id++;
258 my_req_id = *request_id;
260 if (maps_address_clone(a, &address) != MAPS_ERROR_NONE)
261 error = MAPS_ERROR_INVALID_PARAMETER;
264 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
265 error = MAPS_ERROR_INVALID_PARAMETER;
268 session::command_geocode_by_structured_address::
269 ~command_geocode_by_structured_address()
271 maps_address_destroy(address);
272 maps_item_hashtable_destroy(preference);
275 int session::command_geocode_by_structured_address::run()
277 if (error != MAPS_ERROR_NONE)
280 pending_request pr(plugin());
282 /* Get the plugin interface function */
283 maps_plugin_geocode_by_structured_address_f func =
284 interface()->maps_plugin_geocode_by_structured_address;
285 command_geocode_handler *handler = NULL;
287 /* No need to create the handler when the function is NULL */
289 handler = new command_geocode_handler(plugin(),
295 /* Run the plugin interface function */
296 error = func(address,
297 preference, command_geocode_handler::foreach_geocode_cb,
298 handler, &handler->plg_req_id);
300 pr.update(my_req_id, handler);
303 error = MAPS_ERROR_OUT_OF_MEMORY;
307 /* Plugin Function is NULL: use default empty function */
309 func = plugin::get_empty_interface().
310 maps_plugin_geocode_by_structured_address;
312 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
313 error = MAPS_ERROR_NOT_SUPPORTED;
316 const int ret = error;
321 /*----------------------------------------------------------------------------*/
322 /*typedef int (*maps_plugin_reverse_geocode_f)(maps_service_h maps,
323 * double latitude, double longitude, maps_service_reverse_geocode_cb callback,
324 * void *user_data, int *request_id); */
325 session::command_reverse_geocode::command_reverse_geocode(maps_service_h ms,
326 double lat, double lon,
327 const maps_item_hashtable_h pref,
328 maps_service_reverse_geocode_cb cb,
329 void *ud, int *request_id)
338 *request_id = command::command_request_id++;
339 my_req_id = *request_id;
342 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
343 error = MAPS_ERROR_INVALID_PARAMETER;
346 session::command_reverse_geocode::~command_reverse_geocode()
348 maps_item_hashtable_destroy(preference);
351 int session::command_reverse_geocode::run()
354 if (error != MAPS_ERROR_NONE)
357 pending_request pr(plugin());
359 /* Get the plugin interface function */
360 maps_plugin_reverse_geocode_f func =
361 interface()->maps_plugin_reverse_geocode;
362 command_reverse_geocode_handler *handler = NULL;
364 /* No need to create the handler when the function is NULL */
366 handler = new command_reverse_geocode_handler(plugin(),
372 /* Run the plugin interface function */
373 error = func(latitude, longitude, preference,
374 command_reverse_geocode_handler::foreach_reverse_geocode_cb,
375 handler, &handler->plg_req_id);
377 pr.update(my_req_id, handler);
379 MAPS_LOGD("session::command_reverse_geocode::run: %d", my_req_id);
382 error = MAPS_ERROR_OUT_OF_MEMORY;
386 /* Plugin Function is NULL: use default empty function */
388 func = plugin::get_empty_interface().
389 maps_plugin_reverse_geocode;
391 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
392 error = MAPS_ERROR_NOT_SUPPORTED;
395 const int ret = error;
400 session::command_reverse_geocode_handler::command_reverse_geocode_handler(
402 maps_service_reverse_geocode_cb cb,
404 : command_handler(p, ud, urid)
409 void session::command_reverse_geocode_handler::foreach_reverse_geocode_cb(
411 int request_id, int index,
413 maps_address_h address,
417 command_reverse_geocode_handler *handler =
418 (command_reverse_geocode_handler *) user_data;
420 if (request_id != handler->plg_req_id) {
422 "\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
423 request_id, handler->plg_req_id);
426 /* Make a user's copy of result data */
427 maps_address_h cloned_result = NULL;
428 if (error == MAPS_ERROR_NONE)
429 error = (maps_error_e) maps_address_clone(address,
431 maps_address_destroy(address);
433 /* Send data to user */
434 handler->callback(error, handler->user_req_id, index, total,
435 cloned_result, handler->user_data);
436 /*if(index>=(total-1)) */
438 pending_request pr(handler->plugin());
439 pr.remove(handler->user_req_id);
442 /*----------------------------------------------------------------------------*/
443 /*typedef int (*maps_plugin_search_place_f)(maps_service_h maps,
444 * maps_coordinates_h position, int distance, maps_item_hashtable_h preference,
445 * maps_place_filter_h filter, maps_service_search_place_cb callback,
446 * void* user_data, int* request_id); */
447 session::command_search_place::command_search_place(maps_service_h ms,
448 const maps_coordinates_h pos,
450 const maps_item_hashtable_h pref,
451 const maps_place_filter_h flt,
452 maps_service_search_place_cb cb,
453 void *ud, int *request_id)
461 , error(MAPS_ERROR_NONE)
463 *request_id = command::command_request_id++;
464 my_req_id = *request_id;
466 if (maps_coordinates_clone(pos, &position) != MAPS_ERROR_NONE)
467 error = MAPS_ERROR_INVALID_PARAMETER;
470 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
471 error = MAPS_ERROR_INVALID_PARAMETER;
473 if (maps_place_filter_clone(flt, &filter) != MAPS_ERROR_NONE)
474 error = MAPS_ERROR_INVALID_PARAMETER;
477 session::command_search_place::~command_search_place()
479 maps_coordinates_destroy(position);
480 maps_item_hashtable_destroy(preference);
481 maps_place_filter_destroy(filter);
484 int session::command_search_place::run()
487 if (error != MAPS_ERROR_NONE)
490 pending_request pr(plugin());
492 /* Get the plugin interface function */
493 maps_plugin_search_place_f func = interface()->maps_plugin_search_place;
494 command_search_place_handler *handler = NULL;
496 /* No need to create the handler when the function is NULL */
498 handler = new command_search_place_handler(plugin(),
503 /* Run the plugin interface function */
504 error = func(position, distance, filter, preference,
505 command_search_place_handler::foreach_place_cb, handler,
506 &handler->plg_req_id);
508 pr.update(my_req_id, handler);
510 MAPS_LOGD("session::command_search_place::run: %d", my_req_id);
513 error = MAPS_ERROR_OUT_OF_MEMORY;
517 /* Plugin Function is NULL: use default empty function */
519 func = plugin::get_empty_interface().maps_plugin_search_place;
521 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
522 error = MAPS_ERROR_NOT_SUPPORTED;
525 const int ret = error;
530 session::command_search_place_handler::command_search_place_handler(
532 maps_service_search_place_cb cb,
534 : command_handler(p, ud, urid)
539 void session::command_search_place_handler::set_supported_data(maps_place_h
542 if (!place || !plugin())
545 maps_string_hashtable_h data_supported = NULL;
546 if (maps_string_hashtable_create(&data_supported) != MAPS_ERROR_NONE)
549 __put_to_hashtable(this, MAPS_PLACE_ADDRESS, _S(MAPS_PLACE_ADDRESS),
551 __put_to_hashtable(this, MAPS_PLACE_RATING, _S(MAPS_PLACE_RATING),
553 __put_to_hashtable(this, MAPS_PLACE_CATEGORIES,
554 _S(MAPS_PLACE_CATEGORIES), data_supported);
555 __put_to_hashtable(this, MAPS_PLACE_ATTRIBUTES,
556 _S(MAPS_PLACE_ATTRIBUTES), data_supported);
557 __put_to_hashtable(this, MAPS_PLACE_CONTACTS, _S(MAPS_PLACE_CONTACTS),
559 __put_to_hashtable(this, MAPS_PLACE_EDITORIALS,
560 _S(MAPS_PLACE_EDITORIALS), data_supported);
561 __put_to_hashtable(this, MAPS_PLACE_REVIEWS, _S(MAPS_PLACE_REVIEWS),
563 __put_to_hashtable(this, MAPS_PLACE_IMAGE, _S(MAPS_PLACE_IMAGE),
565 __put_to_hashtable(this, MAPS_PLACE_SUPPLIER, _S(MAPS_PLACE_SUPPLIER),
567 __put_to_hashtable(this, MAPS_PLACE_RELATED, _S(MAPS_PLACE_RELATED),
570 _maps_place_set_supported_data(place, data_supported);
571 maps_string_hashtable_destroy(data_supported);
574 bool session::command_search_place_handler::foreach_place_cb(maps_error_e error,
582 command_search_place_handler *handler =
583 (command_search_place_handler *) user_data;
585 if (request_id != handler->plg_req_id) {
587 "\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
588 request_id, handler->plg_req_id);
591 /* Make a user's copy of result data */
592 maps_place_h cloned_result = NULL;
593 if (error == MAPS_ERROR_NONE)
594 error = (maps_error_e) maps_place_clone(place, &cloned_result);
595 maps_place_destroy(place);
597 /* Check which data features are supported */
599 handler->set_supported_data(cloned_result);
601 /* Send data to user */
603 handler->callback(error, handler->user_req_id, index, length,
604 cloned_result, handler->user_data);
605 if (!b || (index >= (length - 1))) {
606 pending_request pr(handler->plugin());
607 pr.remove(handler->user_req_id);
613 /*----------------------------------------------------------------------------*/
614 /*typedef int (*maps_plugin_search_place_by_area_f)(maps_service_h maps,
615 * maps_area_h boundary , maps_item_hashtable_h preference,
616 * maps_place_filter_h filter, maps_service_search_place_cb callback,
617 * void *user_data, int *request_id); */
618 session::command_search_by_area_place::command_search_by_area_place(
619 maps_service_h ms, const maps_area_h b,
620 const maps_item_hashtable_h pref,
621 const maps_place_filter_h flt,
622 maps_service_search_place_cb cb,
623 void *ud, int *request_id)
630 , error(MAPS_ERROR_NONE)
632 *request_id = command::command_request_id++;
633 my_req_id = *request_id;
635 if (maps_area_clone(b, &boundary) != MAPS_ERROR_NONE)
636 error = MAPS_ERROR_INVALID_PARAMETER;
639 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
640 error = MAPS_ERROR_INVALID_PARAMETER;
642 if (maps_place_filter_clone(flt, &filter) != MAPS_ERROR_NONE)
643 error = MAPS_ERROR_INVALID_PARAMETER;
646 session::command_search_by_area_place::~command_search_by_area_place()
648 maps_area_destroy(boundary);
649 maps_item_hashtable_destroy(preference);
650 maps_place_filter_destroy(filter);
653 int session::command_search_by_area_place::run()
656 if (error != MAPS_ERROR_NONE)
659 pending_request pr(plugin());
661 /* Get the plugin interface function */
662 maps_plugin_search_place_by_area_f func =
663 interface()->maps_plugin_search_place_by_area;
664 command_search_place_handler *handler = NULL;
666 /* No need to create the handler when the function is NULL */
668 handler = new command_search_place_handler(plugin(),
674 /* Run the plugin interface function */
675 error = func(boundary, filter,
676 preference, command_search_place_handler::foreach_place_cb,
677 handler, &handler->plg_req_id);
679 pr.update(my_req_id, handler);
681 MAPS_LOGD("session::command_search_by_area_place::run: %d", my_req_id);
684 error = MAPS_ERROR_OUT_OF_MEMORY;
688 /* Plugin Function is NULL: use default empty function */
690 func = plugin::get_empty_interface().
691 maps_plugin_search_place_by_area;
694 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
695 error = MAPS_ERROR_NOT_SUPPORTED;
698 const int ret = error;
703 /*----------------------------------------------------------------------------*/
704 /*typedef int (*maps_plugin_search_place_by_address_f)(maps_service_h maps,
705 * const char *address, maps_area_h boundary, maps_item_hashtable_h preference,
706 * maps_place_filter_h filter, maps_service_search_place_cb callback,
707 * void *user_data, int *request_id); */
708 session::command_search_by_address_place::command_search_by_address_place(
709 maps_service_h ms, const char *a,
711 const maps_item_hashtable_h pref,
712 const maps_place_filter_h flt,
713 maps_service_search_place_cb cb,
714 void *ud, int *request_id)
722 , error(MAPS_ERROR_NONE)
724 *request_id = command::command_request_id++;
725 my_req_id = *request_id;
727 if (maps_area_clone(b, &boundary) != MAPS_ERROR_NONE)
728 error = MAPS_ERROR_INVALID_PARAMETER;
731 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
732 error = MAPS_ERROR_INVALID_PARAMETER;
734 if (maps_place_filter_clone(flt, &filter) != MAPS_ERROR_NONE)
735 error = MAPS_ERROR_INVALID_PARAMETER;
738 session::command_search_by_address_place::~command_search_by_address_place()
740 maps_area_destroy(boundary);
741 maps_item_hashtable_destroy(preference);
742 maps_place_filter_destroy(filter);
745 int session::command_search_by_address_place::run()
747 if (error != MAPS_ERROR_NONE)
750 pending_request pr(plugin());
752 /* Get the plugin interface function */
753 maps_plugin_search_place_by_address_f func =
754 interface()->maps_plugin_search_place_by_address;
755 command_search_place_handler *handler = NULL;
757 /* No need to create the handler when the function is NULL */
759 handler = new command_search_place_handler(plugin(),
764 /* Run the plugin interface function */
765 error = func(address.c_str(), boundary, filter, preference,
766 command_search_place_handler::foreach_place_cb, handler,
767 &handler->plg_req_id);
769 pr.update(my_req_id, handler);
771 MAPS_LOGD("session::command_search_by_address_place::run: %d",
776 error = MAPS_ERROR_OUT_OF_MEMORY;
780 /* Plugin Function is NULL: use default empty function */
782 func = plugin::get_empty_interface().
783 maps_plugin_search_place_by_address;
785 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
786 error = MAPS_ERROR_NOT_SUPPORTED;
789 const int ret = error;
794 /*----------------------------------------------------------------------------*/
795 /*typedef int (*maps_plugin_search_route_f)(maps_service_h maps,
796 * maps_item_hashtable_h preference, maps_coordinates_h origin,
797 * maps_coordinates_h destination, maps_service_search_route_cb callback,
798 * void *user_data, int *request_id); */
799 session::command_search_route::command_search_route(maps_service_h ms,
800 const maps_item_hashtable_h pref,
801 const maps_coordinates_h orig,
802 const maps_coordinates_h dest,
803 maps_service_search_route_cb cb,
804 void *ud, int *request_id)
811 , error(MAPS_ERROR_NONE)
813 *request_id = command::command_request_id++;
814 my_req_id = *request_id;
817 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
818 error = MAPS_ERROR_INVALID_PARAMETER;
820 if (maps_coordinates_clone(orig, &origin) != MAPS_ERROR_NONE)
821 error = MAPS_ERROR_INVALID_PARAMETER;
823 if (maps_coordinates_clone(dest, &destination) != MAPS_ERROR_NONE)
824 error = MAPS_ERROR_INVALID_PARAMETER;
828 session::command_search_route::~command_search_route()
830 maps_item_hashtable_destroy(preference);
831 maps_coordinates_destroy(origin);
832 maps_coordinates_destroy(destination);
835 int session::command_search_route::run()
838 if (error != MAPS_ERROR_NONE)
841 pending_request pr(plugin());
843 /* Get the plugin interface function */
844 maps_plugin_search_route_f func = interface()->maps_plugin_search_route;
845 command_search_route_handler *handler = NULL;
847 /* No need to create the handler when the function is NULL */
849 handler = new command_search_route_handler(plugin(),
855 /* Run the plugin interface function */
856 error = func(origin, destination, preference,
857 command_search_route_handler::foreach_route_cb,
858 handler, &handler->plg_req_id);
860 pr.update(my_req_id, handler);
862 MAPS_LOGD("session::command_search_route::run: %d", my_req_id);
865 error = MAPS_ERROR_OUT_OF_MEMORY;
869 /* Plugin Function is NULL: use default empty function */
871 func = plugin::get_empty_interface().maps_plugin_search_route;
873 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
874 error = MAPS_ERROR_NOT_SUPPORTED;
877 const int ret = error;
882 /*----------------------------------------------------------------------------*/
883 /*typedef int (*maps_plugin_search_route_waypoints_f)(maps_service_h maps,
884 * maps_item_hashtable_h preference, maps_coordinates_h *waypoint_list,
885 * int waypoint_num, maps_service_search_route_cb callback, void *user_data,
886 * int *request_id); */
887 session::command_search_route_waypoints::command_search_route_waypoints(
889 const maps_item_hashtable_h pref,
890 const maps_coordinates_h *list,
891 int num, maps_service_search_route_cb cb,
892 void *ud, int *request_id)
895 , waypoint_list(NULL)
899 , error(MAPS_ERROR_NONE)
901 *request_id = command::command_request_id++;
902 my_req_id = *request_id;
905 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
906 error = MAPS_ERROR_INVALID_PARAMETER;
908 waypoint_list = new maps_coordinates_h[num];
909 for (int index = 0; index < num; index++) {
910 if (list[index] != NULL) {
911 maps_coordinates_clone(list[index],
912 &waypoint_list[index]);
917 session::command_search_route_waypoints::~command_search_route_waypoints()
919 maps_item_hashtable_destroy(preference);
921 for (int index = 0; index < waypoint_num; index++) {
922 if (waypoint_list[index] != NULL) {
923 maps_coordinates_destroy(waypoint_list[index]);
926 delete [] waypoint_list;
929 int session::command_search_route_waypoints::run()
932 if (error != MAPS_ERROR_NONE)
935 pending_request pr(plugin());
937 /* Get the plugin interface function */
938 maps_plugin_search_route_waypoints_f func =
939 interface()->maps_plugin_search_route_waypoints;
941 command_search_route_handler *handler = NULL;
943 /* No need to create the handler when the function is NULL */
945 handler = new command_search_route_handler(plugin(),
950 /* Run the plugin interface function */
951 error = func(waypoint_list, waypoint_num, preference,
952 command_search_route_handler::foreach_route_cb, handler,
953 &handler->plg_req_id);
955 pr.update(my_req_id, handler);
957 MAPS_LOGD("session::command_search_place::run: %d", my_req_id);
960 error = MAPS_ERROR_OUT_OF_MEMORY;
964 /* Plugin Function is NULL: use default empty function */
966 func = plugin::get_empty_interface().
967 maps_plugin_search_route_waypoints;
969 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
970 error = MAPS_ERROR_NOT_SUPPORTED;
973 const int ret = error;
978 session::command_search_route_handler::command_search_route_handler(
980 maps_service_search_route_cb cb,
982 : command_handler(p, ud, urid)
987 void session::command_search_route_handler::set_supported_data(maps_route_h
990 if (!route || !plugin())
993 maps_string_hashtable_h data_supported = NULL;
994 if (maps_string_hashtable_create(&data_supported) != MAPS_ERROR_NONE)
997 __put_to_hashtable(this, MAPS_ROUTE_PATH, _S(MAPS_ROUTE_PATH),
999 __put_to_hashtable(this, MAPS_ROUTE_SEGMENTS_PATH,
1000 _S(MAPS_ROUTE_SEGMENTS_PATH), data_supported);
1001 __put_to_hashtable(this, MAPS_ROUTE_SEGMENTS_MANEUVERS,
1002 _S(MAPS_ROUTE_SEGMENTS_MANEUVERS), data_supported);
1004 _maps_route_set_supported_data(route, data_supported);
1005 maps_string_hashtable_destroy(data_supported);
1008 bool session::command_search_route_handler::foreach_route_cb(maps_error_e error,
1015 command_search_route_handler *handler =
1016 (command_search_route_handler *) user_data;
1018 if (request_id != handler->plg_req_id) {
1020 "\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
1021 request_id, handler->plg_req_id);
1024 /* Make a user's copy of result data */
1025 maps_route_h cloned_result = NULL;
1026 if (error == MAPS_ERROR_NONE)
1027 error = (maps_error_e) maps_route_clone(route, &cloned_result);
1028 maps_route_destroy(route);
1030 /* Check which data features are supported */
1032 handler->set_supported_data(cloned_result);
1034 /* Send data to user */
1036 handler->callback(error, handler->user_req_id, index, length,
1037 cloned_result, handler->user_data);
1038 if (!b || (index >= (length - 1))) {
1039 pending_request pr(handler->plugin());
1040 pr.remove(handler->user_req_id);
1046 /*----------------------------------------------------------------------------*/
1047 /*typedef int (*maps_plugin_cancel_request_f)(maps_service_h maps,
1048 * int request_id); */
1049 int session::command_cancel_request::run()
1051 pending_request pr(plugin());
1052 MAPS_LOGD("session::command_cancel_request::run: %d, %d", request_id,
1053 pr.look_up(request_id));
1055 (pr.contains(request_id)) ? interface()->
1056 maps_plugin_cancel_request(pr.
1057 extract_plg_id(request_id)) : MAPS_ERROR_NOT_FOUND;
1059 const int ret = error;