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)
50 *request_id = command::command_request_id++;
51 my_req_id = *request_id;
54 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
55 error = MAPS_ERROR_INVALID_PARAMETER;
58 session::command_geocode::~command_geocode()
60 maps_item_hashtable_destroy(preference);
63 int session::command_geocode::run()
66 if (error != MAPS_ERROR_NONE)
69 pending_request pr(plugin());
71 /* Get the plugin interface function */
72 maps_plugin_geocode_f func = interface()->maps_plugin_geocode;
73 command_geocode_handler *handler = NULL;
75 /* need to create the handler when the function is NULL */
77 handler = new command_geocode_handler(plugin(),
83 /* Run the plugin interface function */
84 error = func(address.c_str(), preference,
85 command_geocode_handler::foreach_geocode_cb, handler,
86 &handler->plg_req_id);
88 pr.update(my_req_id, handler);
90 MAPS_LOGD("session::command_geocode::run: %d", my_req_id);
93 error = MAPS_ERROR_OUT_OF_MEMORY;
97 /* Plugin Function is NULL: use default empty function */
99 func = plugin::get_empty_interface().maps_plugin_geocode;
101 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
102 error = MAPS_ERROR_NOT_SUPPORTED;
105 const int ret = error;
110 session::command_geocode_handler::command_geocode_handler(plugin::plugin_s *p,
111 maps_service_geocode_cb cb,
113 : command_handler(p, ud, urid)
118 bool session::command_geocode_handler::foreach_geocode_cb(maps_error_e error,
127 command_geocode_handler *handler =
128 (command_geocode_handler *) user_data;
130 if (request_id != handler->plg_req_id) {
132 "\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
133 request_id, handler->plg_req_id);
136 /* Make a user's copy of result data */
137 maps_coordinates_h cloned_result = NULL;
138 if (error == MAPS_ERROR_NONE)
139 error = (maps_error_e) maps_coordinates_clone(coordinates,
141 maps_coordinates_destroy(coordinates);
143 /* Send data to user */
145 handler->callback(error, handler->user_req_id, index,
146 total_count, cloned_result, handler->user_data);
147 if (!b || (index >= (total_count - 1))) {
148 pending_request pr(handler->plugin());
149 pr.remove(handler->user_req_id);
155 /*----------------------------------------------------------------------------*/
156 /*typedef int (*maps_plugin_geocode_inside_area_f)(maps_service_h maps, const
157 * char *address, maps_area_h bounds, maps_service_geocode_cb callback,
158 * void *user_data, int *request_id); */
159 session::command_geocode_inside_bounds::command_geocode_inside_bounds(
163 const maps_item_hashtable_h pref,
164 maps_service_geocode_cb cb,
165 void *ud, int *request_id)
173 *request_id = command::command_request_id++;
174 my_req_id = *request_id;
176 if (maps_area_clone(b, &bounds) != MAPS_ERROR_NONE)
177 error = MAPS_ERROR_INVALID_PARAMETER;
180 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
181 error = MAPS_ERROR_INVALID_PARAMETER;
184 session::command_geocode_inside_bounds::~command_geocode_inside_bounds()
186 maps_area_destroy(bounds);
187 maps_item_hashtable_destroy(preference);
190 int session::command_geocode_inside_bounds::run()
192 if (error != MAPS_ERROR_NONE)
195 pending_request pr(plugin());
197 /* Get the plugin interface function */
198 maps_plugin_geocode_inside_area_f func =
199 interface()->maps_plugin_geocode_inside_area;
200 command_geocode_handler *handler = NULL;
202 /* No need to create the handler when the function is NULL */
204 handler = new command_geocode_handler(plugin(),
210 /* Run the plugin interface function */
211 error = func(address.c_str(), bounds, preference,
212 command_geocode_handler::foreach_geocode_cb,
213 handler, &handler->plg_req_id);
215 pr.update(my_req_id, handler);
217 MAPS_LOGD("session::command_geocode_inside_bounds::run: %d", my_req_id);
220 error = MAPS_ERROR_OUT_OF_MEMORY;
224 /* Plugin Function is NULL: use default empty function */
226 func = plugin::get_empty_interface().
227 maps_plugin_geocode_inside_area;
229 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
230 error = MAPS_ERROR_NOT_SUPPORTED;
233 const int ret = error;
238 /*----------------------------------------------------------------------------*/
239 /*typedef int (*maps_plugin_geocode_by_structured_address_f)(
240 * maps_service_h maps, maps_address_h address, maps_preference_h preference,
241 * maps_service_geocode_cb callback, void *user_data, int *request_id); */
242 session::command_geocode_by_structured_address::
243 command_geocode_by_structured_address(maps_service_h ms,
244 const maps_address_h a,
245 const maps_item_hashtable_h pref,
246 maps_service_geocode_cb cb,
247 void *ud, int *request_id)
254 *request_id = command::command_request_id++;
255 my_req_id = *request_id;
257 if (maps_address_clone(a, &address) != MAPS_ERROR_NONE)
258 error = MAPS_ERROR_INVALID_PARAMETER;
261 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
262 error = MAPS_ERROR_INVALID_PARAMETER;
265 session::command_geocode_by_structured_address::
266 ~command_geocode_by_structured_address()
268 maps_address_destroy(address);
269 maps_item_hashtable_destroy(preference);
272 int session::command_geocode_by_structured_address::run()
274 if (error != MAPS_ERROR_NONE)
277 pending_request pr(plugin());
279 /* Get the plugin interface function */
280 maps_plugin_geocode_by_structured_address_f func =
281 interface()->maps_plugin_geocode_by_structured_address;
282 command_geocode_handler *handler = NULL;
284 /* No need to create the handler when the function is NULL */
286 handler = new command_geocode_handler(plugin(),
292 /* Run the plugin interface function */
293 error = func(address,
294 preference, command_geocode_handler::foreach_geocode_cb,
295 handler, &handler->plg_req_id);
297 pr.update(my_req_id, handler);
300 error = MAPS_ERROR_OUT_OF_MEMORY;
304 /* Plugin Function is NULL: use default empty function */
306 func = plugin::get_empty_interface().
307 maps_plugin_geocode_by_structured_address;
309 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
310 error = MAPS_ERROR_NOT_SUPPORTED;
313 const int ret = error;
318 /*----------------------------------------------------------------------------*/
319 /*typedef int (*maps_plugin_reverse_geocode_f)(maps_service_h maps,
320 * double latitude, double longitude, maps_service_reverse_geocode_cb callback,
321 * void *user_data, int *request_id); */
322 session::command_reverse_geocode::command_reverse_geocode(maps_service_h ms,
323 double lat, double lon,
324 const maps_item_hashtable_h pref,
325 maps_service_reverse_geocode_cb cb,
326 void *ud, int *request_id)
334 *request_id = command::command_request_id++;
335 my_req_id = *request_id;
338 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
339 error = MAPS_ERROR_INVALID_PARAMETER;
342 session::command_reverse_geocode::~command_reverse_geocode()
344 maps_item_hashtable_destroy(preference);
347 int session::command_reverse_geocode::run()
350 if (error != MAPS_ERROR_NONE)
353 pending_request pr(plugin());
355 /* Get the plugin interface function */
356 maps_plugin_reverse_geocode_f func =
357 interface()->maps_plugin_reverse_geocode;
358 command_reverse_geocode_handler *handler = NULL;
360 /* No need to create the handler when the function is NULL */
362 handler = new command_reverse_geocode_handler(plugin(),
368 /* Run the plugin interface function */
369 error = func(latitude, longitude, preference,
370 command_reverse_geocode_handler::foreach_reverse_geocode_cb,
371 handler, &handler->plg_req_id);
373 pr.update(my_req_id, handler);
375 MAPS_LOGD("session::command_reverse_geocode::run: %d", my_req_id);
378 error = MAPS_ERROR_OUT_OF_MEMORY;
382 /* Plugin Function is NULL: use default empty function */
384 func = plugin::get_empty_interface().
385 maps_plugin_reverse_geocode;
387 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
388 error = MAPS_ERROR_NOT_SUPPORTED;
391 const int ret = error;
396 session::command_reverse_geocode_handler::command_reverse_geocode_handler(
398 maps_service_reverse_geocode_cb cb,
400 : command_handler(p, ud, urid)
405 void session::command_reverse_geocode_handler::foreach_reverse_geocode_cb(
407 int request_id, int index,
409 maps_address_h address,
413 command_reverse_geocode_handler *handler =
414 (command_reverse_geocode_handler *) user_data;
416 if (request_id != handler->plg_req_id) {
418 "\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
419 request_id, handler->plg_req_id);
422 /* Make a user's copy of result data */
423 maps_address_h cloned_result = NULL;
424 if (error == MAPS_ERROR_NONE)
425 error = (maps_error_e) maps_address_clone(address,
427 maps_address_destroy(address);
429 /* Send data to user */
430 handler->callback(error, handler->user_req_id, index, total,
431 cloned_result, handler->user_data);
432 /*if(index>=(total-1)) */
434 pending_request pr(handler->plugin());
435 pr.remove(handler->user_req_id);
438 /*----------------------------------------------------------------------------*/
439 /*typedef int (*maps_plugin_search_place_f)(maps_service_h maps,
440 * maps_coordinates_h position, int distance, maps_item_hashtable_h preference,
441 * maps_place_filter_h filter, maps_service_search_place_cb callback,
442 * void* user_data, int* request_id); */
443 session::command_search_place::command_search_place(maps_service_h ms,
444 const maps_coordinates_h pos,
446 const maps_item_hashtable_h pref,
447 const maps_place_filter_h flt,
448 maps_service_search_place_cb cb,
449 void *ud, int *request_id)
458 *request_id = command::command_request_id++;
459 my_req_id = *request_id;
461 if (maps_coordinates_clone(pos, &position) != MAPS_ERROR_NONE)
462 error = MAPS_ERROR_INVALID_PARAMETER;
465 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
466 error = MAPS_ERROR_INVALID_PARAMETER;
468 if (maps_place_filter_clone(flt, &filter) != MAPS_ERROR_NONE)
469 error = MAPS_ERROR_INVALID_PARAMETER;
472 session::command_search_place::~command_search_place()
474 maps_coordinates_destroy(position);
475 maps_item_hashtable_destroy(preference);
476 maps_place_filter_destroy(filter);
479 int session::command_search_place::run()
482 if (error != MAPS_ERROR_NONE)
485 pending_request pr(plugin());
487 /* Get the plugin interface function */
488 maps_plugin_search_place_f func = interface()->maps_plugin_search_place;
489 command_search_place_handler *handler = NULL;
491 /* No need to create the handler when the function is NULL */
493 handler = new command_search_place_handler(plugin(),
498 /* Run the plugin interface function */
499 error = func(position, distance, filter, preference,
500 command_search_place_handler::foreach_place_cb, handler,
501 &handler->plg_req_id);
503 pr.update(my_req_id, handler);
505 MAPS_LOGD("session::command_search_place::run: %d", my_req_id);
508 error = MAPS_ERROR_OUT_OF_MEMORY;
512 /* Plugin Function is NULL: use default empty function */
514 func = plugin::get_empty_interface().maps_plugin_search_place;
516 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
517 error = MAPS_ERROR_NOT_SUPPORTED;
520 const int ret = error;
525 session::command_search_place_handler::command_search_place_handler(
527 maps_service_search_place_cb cb,
529 : command_handler(p, ud, urid)
534 void session::command_search_place_handler::set_supported_data(maps_place_h
537 if (!place || !plugin())
540 maps_string_hashtable_h data_supported = NULL;
541 if (maps_string_hashtable_create(&data_supported) != MAPS_ERROR_NONE)
544 __put_to_hashtable(this, MAPS_PLACE_ADDRESS, _S(MAPS_PLACE_ADDRESS),
546 __put_to_hashtable(this, MAPS_PLACE_RATING, _S(MAPS_PLACE_RATING),
548 __put_to_hashtable(this, MAPS_PLACE_CATEGORIES,
549 _S(MAPS_PLACE_CATEGORIES), data_supported);
550 __put_to_hashtable(this, MAPS_PLACE_ATTRIBUTES,
551 _S(MAPS_PLACE_ATTRIBUTES), data_supported);
552 __put_to_hashtable(this, MAPS_PLACE_CONTACTS, _S(MAPS_PLACE_CONTACTS),
554 __put_to_hashtable(this, MAPS_PLACE_EDITORIALS,
555 _S(MAPS_PLACE_EDITORIALS), data_supported);
556 __put_to_hashtable(this, MAPS_PLACE_REVIEWS, _S(MAPS_PLACE_REVIEWS),
558 __put_to_hashtable(this, MAPS_PLACE_IMAGE, _S(MAPS_PLACE_IMAGE),
560 __put_to_hashtable(this, MAPS_PLACE_SUPPLIER, _S(MAPS_PLACE_SUPPLIER),
562 __put_to_hashtable(this, MAPS_PLACE_RELATED, _S(MAPS_PLACE_RELATED),
565 _maps_place_set_supported_data(place, data_supported);
566 maps_string_hashtable_destroy(data_supported);
569 bool session::command_search_place_handler::foreach_place_cb(maps_error_e error,
577 command_search_place_handler *handler =
578 (command_search_place_handler *) user_data;
580 if (request_id != handler->plg_req_id) {
582 "\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
583 request_id, handler->plg_req_id);
586 /* Make a user's copy of result data */
587 maps_place_h cloned_result = NULL;
588 if (error == MAPS_ERROR_NONE)
589 error = (maps_error_e) maps_place_clone(place, &cloned_result);
590 maps_place_destroy(place);
592 /* Check which data features are supported */
594 handler->set_supported_data(cloned_result);
596 /* Send data to user */
598 handler->callback(error, handler->user_req_id, index, length,
599 cloned_result, handler->user_data);
600 if (!b || (index >= (length - 1))) {
601 pending_request pr(handler->plugin());
602 pr.remove(handler->user_req_id);
608 /*----------------------------------------------------------------------------*/
609 /*typedef int (*maps_plugin_search_place_by_area_f)(maps_service_h maps,
610 * maps_area_h boundary , maps_item_hashtable_h preference,
611 * maps_place_filter_h filter, maps_service_search_place_cb callback,
612 * void *user_data, int *request_id); */
613 session::command_search_by_area_place::command_search_by_area_place(
614 maps_service_h ms, const maps_area_h b,
615 const maps_item_hashtable_h pref,
616 const maps_place_filter_h flt,
617 maps_service_search_place_cb cb,
618 void *ud, int *request_id)
626 *request_id = command::command_request_id++;
627 my_req_id = *request_id;
629 if (maps_area_clone(b, &boundary) != MAPS_ERROR_NONE)
630 error = MAPS_ERROR_INVALID_PARAMETER;
633 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
634 error = MAPS_ERROR_INVALID_PARAMETER;
636 if (maps_place_filter_clone(flt, &filter) != MAPS_ERROR_NONE)
637 error = MAPS_ERROR_INVALID_PARAMETER;
640 session::command_search_by_area_place::~command_search_by_area_place()
642 maps_area_destroy(boundary);
643 maps_item_hashtable_destroy(preference);
644 maps_place_filter_destroy(filter);
647 int session::command_search_by_area_place::run()
650 if (error != MAPS_ERROR_NONE)
653 pending_request pr(plugin());
655 /* Get the plugin interface function */
656 maps_plugin_search_place_by_area_f func =
657 interface()->maps_plugin_search_place_by_area;
658 command_search_place_handler *handler = NULL;
660 /* No need to create the handler when the function is NULL */
662 handler = new command_search_place_handler(plugin(),
668 /* Run the plugin interface function */
669 error = func(boundary, filter,
671 command_search_place_handler::foreach_place_cb,
672 handler, &handler->plg_req_id);
674 pr.update(my_req_id, handler);
676 MAPS_LOGD("session::command_search_by_area_place::run: %d",
680 error = MAPS_ERROR_OUT_OF_MEMORY;
684 /* Plugin Function is NULL: use default empty function */
686 func = plugin::get_empty_interface().
687 maps_plugin_search_place_by_area;
690 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
691 error = MAPS_ERROR_NOT_SUPPORTED;
694 const int ret = error;
699 /*----------------------------------------------------------------------------*/
700 /*typedef int (*maps_plugin_search_place_by_address_f)(maps_service_h maps,
701 * const char *address, maps_area_h boundary, maps_item_hashtable_h preference,
702 * maps_place_filter_h filter, maps_service_search_place_cb callback,
703 * void *user_data, int *request_id); */
704 session::command_search_by_address_place::command_search_by_address_place(
705 maps_service_h ms, const char *a,
707 const maps_item_hashtable_h pref,
708 const maps_place_filter_h flt,
709 maps_service_search_place_cb cb,
710 void *ud, int *request_id)
719 *request_id = command::command_request_id++;
720 my_req_id = *request_id;
722 if (maps_area_clone(b, &boundary) != MAPS_ERROR_NONE)
723 error = MAPS_ERROR_INVALID_PARAMETER;
726 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
727 error = MAPS_ERROR_INVALID_PARAMETER;
729 if (maps_place_filter_clone(flt, &filter) != MAPS_ERROR_NONE)
730 error = MAPS_ERROR_INVALID_PARAMETER;
733 session::command_search_by_address_place::~command_search_by_address_place()
735 maps_area_destroy(boundary);
736 maps_item_hashtable_destroy(preference);
737 maps_place_filter_destroy(filter);
740 int session::command_search_by_address_place::run()
742 if (error != MAPS_ERROR_NONE)
745 pending_request pr(plugin());
747 /* Get the plugin interface function */
748 maps_plugin_search_place_by_address_f func =
749 interface()->maps_plugin_search_place_by_address;
750 command_search_place_handler *handler = NULL;
752 /* No need to create the handler when the function is NULL */
754 handler = new command_search_place_handler(plugin(),
759 /* Run the plugin interface function */
760 error = func(address.c_str(), boundary, filter,
762 command_search_place_handler::foreach_place_cb,
764 &handler->plg_req_id);
766 pr.update(my_req_id, handler);
768 MAPS_LOGD("session::command_search_by_address_place::run: %d",
773 error = MAPS_ERROR_OUT_OF_MEMORY;
777 /* Plugin Function is NULL: use default empty function */
779 func = plugin::get_empty_interface().
780 maps_plugin_search_place_by_address;
782 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
783 error = MAPS_ERROR_NOT_SUPPORTED;
786 const int ret = error;
791 /*----------------------------------------------------------------------------*/
792 /*typedef int (*maps_plugin_search_route_f)(maps_service_h maps,
793 * maps_item_hashtable_h preference, maps_coordinates_h origin,
794 * maps_coordinates_h destination, maps_service_search_route_cb callback,
795 * void *user_data, int *request_id); */
796 session::command_search_route::command_search_route(maps_service_h ms,
797 const maps_item_hashtable_h pref,
798 const maps_coordinates_h orig,
799 const maps_coordinates_h dest,
800 maps_service_search_route_cb cb,
801 void *ud, int *request_id)
809 *request_id = command::command_request_id++;
810 my_req_id = *request_id;
813 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
814 error = MAPS_ERROR_INVALID_PARAMETER;
816 if (maps_coordinates_clone(orig, &origin) != MAPS_ERROR_NONE)
817 error = MAPS_ERROR_INVALID_PARAMETER;
819 if (maps_coordinates_clone(dest, &destination) != MAPS_ERROR_NONE)
820 error = MAPS_ERROR_INVALID_PARAMETER;
824 session::command_search_route::~command_search_route()
826 maps_item_hashtable_destroy(preference);
827 maps_coordinates_destroy(origin);
828 maps_coordinates_destroy(destination);
831 int session::command_search_route::run()
834 if (error != MAPS_ERROR_NONE)
837 pending_request pr(plugin());
839 /* Get the plugin interface function */
840 maps_plugin_search_route_f func = interface()->maps_plugin_search_route;
841 command_search_route_handler *handler = NULL;
843 /* No need to create the handler when the function is NULL */
845 handler = new command_search_route_handler(plugin(),
851 /* Run the plugin interface function */
852 error = func(origin, destination, preference,
853 command_search_route_handler::foreach_route_cb,
854 handler, &handler->plg_req_id);
856 pr.update(my_req_id, handler);
858 MAPS_LOGD("session::command_search_route::run: %d",
862 error = MAPS_ERROR_OUT_OF_MEMORY;
866 /* Plugin Function is NULL: use default empty function */
868 func = plugin::get_empty_interface().maps_plugin_search_route;
870 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
871 error = MAPS_ERROR_NOT_SUPPORTED;
874 const int ret = error;
879 /*----------------------------------------------------------------------------*/
880 /*typedef int (*maps_plugin_search_route_waypoints_f)(maps_service_h maps,
881 * maps_item_hashtable_h preference, maps_coordinates_h *waypoint_list,
882 * int waypoint_num, maps_service_search_route_cb callback, void *user_data,
883 * int *request_id); */
884 session::command_search_route_waypoints::command_search_route_waypoints(
886 const maps_item_hashtable_h pref,
887 const maps_coordinates_h *list,
888 int num, maps_service_search_route_cb cb,
889 void *ud, int *request_id)
892 , waypoint_list(NULL)
897 *request_id = command::command_request_id++;
898 my_req_id = *request_id;
901 (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE))
902 error = MAPS_ERROR_INVALID_PARAMETER;
904 waypoint_list = new maps_coordinates_h[num];
905 for (int index = 0; index < num; index++) {
906 if (list[index] != NULL) {
907 maps_coordinates_clone(list[index],
908 &waypoint_list[index]);
913 session::command_search_route_waypoints::~command_search_route_waypoints()
915 maps_item_hashtable_destroy(preference);
917 for (int index = 0; index < waypoint_num; index++) {
918 if (waypoint_list[index] != NULL) {
919 maps_coordinates_destroy(waypoint_list[index]);
922 delete [] waypoint_list;
925 int session::command_search_route_waypoints::run()
928 if (error != MAPS_ERROR_NONE)
931 pending_request pr(plugin());
933 /* Get the plugin interface function */
934 maps_plugin_search_route_waypoints_f func =
935 interface()->maps_plugin_search_route_waypoints;
937 command_search_route_handler *handler = NULL;
939 /* No need to create the handler when the function is NULL */
941 handler = new command_search_route_handler(plugin(),
946 /* Run the plugin interface function */
947 error = func(waypoint_list, waypoint_num, preference,
948 command_search_route_handler::foreach_route_cb,
950 &handler->plg_req_id);
952 pr.update(my_req_id, handler);
954 MAPS_LOGD("session::command_search_place::run: %d",
958 error = MAPS_ERROR_OUT_OF_MEMORY;
962 /* Plugin Function is NULL: use default empty function */
964 func = plugin::get_empty_interface().
965 maps_plugin_search_route_waypoints;
967 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
968 error = MAPS_ERROR_NOT_SUPPORTED;
971 const int ret = error;
976 session::command_search_route_handler::command_search_route_handler(
978 maps_service_search_route_cb cb,
980 : command_handler(p, ud, urid)
985 void session::command_search_route_handler::set_supported_data(maps_route_h
988 if (!route || !plugin())
991 maps_string_hashtable_h data_supported = NULL;
992 if (maps_string_hashtable_create(&data_supported) != MAPS_ERROR_NONE)
995 __put_to_hashtable(this, MAPS_ROUTE_PATH, _S(MAPS_ROUTE_PATH),
997 __put_to_hashtable(this, MAPS_ROUTE_SEGMENTS_PATH,
998 _S(MAPS_ROUTE_SEGMENTS_PATH), data_supported);
999 __put_to_hashtable(this, MAPS_ROUTE_SEGMENTS_MANEUVERS,
1000 _S(MAPS_ROUTE_SEGMENTS_MANEUVERS), data_supported);
1002 _maps_route_set_supported_data(route, data_supported);
1003 maps_string_hashtable_destroy(data_supported);
1006 bool session::command_search_route_handler::foreach_route_cb(maps_error_e error,
1013 command_search_route_handler *handler =
1014 (command_search_route_handler *) user_data;
1016 if (request_id != handler->plg_req_id) {
1017 MAPS_LOGE("\n\nERROR! Incorrect request "
1018 "id [%d] come from the plugin; expected [%d]\n\n",
1019 request_id, handler->plg_req_id);
1022 /* Make a user's copy of result data */
1023 maps_route_h cloned_result = NULL;
1024 if (error == MAPS_ERROR_NONE)
1025 error = (maps_error_e) maps_route_clone(route, &cloned_result);
1026 maps_route_destroy(route);
1028 /* Check which data features are supported */
1030 handler->set_supported_data(cloned_result);
1032 /* Send data to user */
1034 handler->callback(error, handler->user_req_id, index, length,
1035 cloned_result, handler->user_data);
1036 if (!b || (index >= (length - 1))) {
1037 pending_request pr(handler->plugin());
1038 pr.remove(handler->user_req_id);
1044 /*----------------------------------------------------------------------------*/
1045 /*typedef int (*maps_plugin_cancel_request_f)(maps_service_h maps,
1046 * int request_id); */
1047 int session::command_cancel_request::run()
1049 pending_request pr(plugin());
1050 MAPS_LOGD("session::command_cancel_request::run: %d, %d", request_id,
1051 pr.look_up(request_id));
1053 (pr.contains(request_id)) ? interface()->
1054 maps_plugin_cancel_request(pr.
1055 extract_plg_id(request_id)) : MAPS_ERROR_NOT_FOUND;
1057 const int ret = error;