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_view_plugin.h"
20 #include "maps_place_private.h"
21 #include "maps_route_private.h"
22 #include "empty_module.h"
24 extern int _maps_view_move_center(maps_view_h view, const int delta_x, const int delta_y);
26 extern int _maps_view_set_zoom_rotate(maps_view_h view,
27 const bool zoom_changed, const double zoom_factor,
28 const bool rotation_changed, const double rotation_angle);
30 extern bool maps_address_is_valid(const maps_address_h address);
31 extern bool maps_area_is_valid(const maps_area_h area);
32 extern bool maps_coordinates_is_valid(const maps_coordinates_h coordinates);
34 static int __put_to_hashtable(session::command_handler *ch,
35 maps_service_data_e feature,
36 maps_int_hashtable_h t)
39 return MAPS_ERROR_INVALID_PARAMETER;
40 bool supported = false;
41 ch->plugin()->interface.maps_plugin_is_data_supported(feature, &supported);
43 return maps_int_hashtable_set(t, feature, feature);
44 return MAPS_ERROR_NONE;
47 void session::command_handler::set_supported_place_data(maps_place_h place)
49 if (!place || !plugin()) return;
51 maps_int_hashtable_h data_supported = NULL;
52 if (maps_int_hashtable_create(&data_supported) != MAPS_ERROR_NONE) return;
54 __put_to_hashtable(this, MAPS_PLACE_ADDRESS, data_supported);
55 __put_to_hashtable(this, MAPS_PLACE_RATING, data_supported);
56 __put_to_hashtable(this, MAPS_PLACE_CATEGORIES, data_supported);
57 __put_to_hashtable(this, MAPS_PLACE_ATTRIBUTES, data_supported);
58 __put_to_hashtable(this, MAPS_PLACE_CONTACTS, data_supported);
59 __put_to_hashtable(this, MAPS_PLACE_EDITORIALS, data_supported);
60 __put_to_hashtable(this, MAPS_PLACE_REVIEWS, data_supported);
61 __put_to_hashtable(this, MAPS_PLACE_IMAGE, data_supported);
62 __put_to_hashtable(this, MAPS_PLACE_SUPPLIER, data_supported);
63 __put_to_hashtable(this, MAPS_PLACE_RELATED, data_supported);
65 _maps_place_set_supported_data(place, data_supported);
66 maps_int_hashtable_destroy(data_supported);
69 bool session::command_handler::set_supported_place_list_data_cb(int index, maps_place_h place, void *user_data)
71 if (!place || !user_data)
74 maps_int_hashtable_h data_supported = (maps_int_hashtable_h)user_data;
75 _maps_place_set_supported_data(place, data_supported);
79 void session::command_handler::set_supported_place_list_data(maps_place_list_h place_list)
81 if (!place_list || !plugin()) return;
83 maps_int_hashtable_h data_supported = NULL;
84 if (maps_int_hashtable_create(&data_supported) != MAPS_ERROR_NONE) return;
86 __put_to_hashtable(this, MAPS_PLACE_ADDRESS, data_supported);
87 __put_to_hashtable(this, MAPS_PLACE_RATING, data_supported);
88 __put_to_hashtable(this, MAPS_PLACE_CATEGORIES, data_supported);
89 __put_to_hashtable(this, MAPS_PLACE_ATTRIBUTES, data_supported);
90 __put_to_hashtable(this, MAPS_PLACE_CONTACTS, data_supported);
91 __put_to_hashtable(this, MAPS_PLACE_EDITORIALS, data_supported);
92 __put_to_hashtable(this, MAPS_PLACE_REVIEWS, data_supported);
93 __put_to_hashtable(this, MAPS_PLACE_IMAGE, data_supported);
94 __put_to_hashtable(this, MAPS_PLACE_SUPPLIER, data_supported);
95 __put_to_hashtable(this, MAPS_PLACE_RELATED, data_supported);
97 maps_place_list_foreach(place_list, set_supported_place_list_data_cb, data_supported);
98 maps_int_hashtable_destroy(data_supported);
101 void session::command_handler::set_supported_route_data(maps_route_h route)
103 if (!route || !plugin()) return;
105 maps_int_hashtable_h data_supported = NULL;
106 if (maps_int_hashtable_create(&data_supported) != MAPS_ERROR_NONE) return;
108 __put_to_hashtable(this, MAPS_ROUTE_PATH, data_supported);
109 __put_to_hashtable(this, MAPS_ROUTE_SEGMENTS_PATH, data_supported);
110 __put_to_hashtable(this, MAPS_ROUTE_SEGMENTS_MANEUVERS, data_supported);
112 _maps_route_set_supported_data(route, data_supported);
113 maps_int_hashtable_destroy(data_supported);
116 /*----------------------------------------------------------------------------*/
117 /*typedef int (*maps_plugin_geocode_f)(maps_service_h maps, const char *address,
118 * maps_service_geocode_cb callback, void *user_data, int *request_id); */
119 session::command_geocode::command_geocode(maps_service_h ms, const string a,
120 const maps_item_hashtable_h pref,
121 maps_service_geocode_cb cb,
122 void *ud, int *request_id)
130 *request_id = command::command_request_id++;
131 my_req_id = *request_id;
134 session::command_geocode::~command_geocode()
138 int session::command_geocode::run()
140 if (error != MAPS_ERROR_NONE) return error;
142 pending_request pr(plugin());
144 /* Get the plugin interface function */
145 maps_plugin_geocode_f func = interface()->maps_plugin_geocode;
146 command_geocode_handler *handler = NULL;
148 /* need to create the handler when the function is NULL */
150 handler = new command_geocode_handler(plugin(),
151 callback, user_data, my_req_id);
154 /* Run the plugin interface function */
155 error = func(address.c_str(), preference,
156 command_geocode_handler::foreach_geocode_cb, handler,
157 &handler->plg_req_id);
159 pr.update(my_req_id, handler);
161 MAPS_LOGD("session::command_geocode::run: %d", my_req_id);
163 error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
166 /* Plugin Function is NULL: use default empty function */
168 func = plugin::get_empty_interface().maps_plugin_geocode;
170 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
171 error = MAPS_ERROR_NOT_SUPPORTED;
174 const int ret = error;
180 session::command_geocode_handler::command_geocode_handler(plugin::plugin_s *p,
181 maps_service_geocode_cb cb,
183 : command_handler(p, ud, urid)
189 bool session::command_geocode_handler::foreach_geocode_cb(maps_error_e error,
197 command_geocode_handler *handler = (command_geocode_handler *) user_data;
199 if (request_id != handler->plg_req_id) {
201 MAPS_LOGE("\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n",
202 request_id, handler->plg_req_id);
206 /* Make a user's copy of result data */
207 maps_coordinates_h cloned_result = NULL;
208 if (error == MAPS_ERROR_NONE)
209 error = (maps_error_e) maps_coordinates_clone(coordinates, &cloned_result);
210 maps_coordinates_destroy(coordinates);
212 /* Send data to user */
213 const bool b = handler->callback(error, handler->user_req_id, index,
214 total_count, cloned_result, handler->user_data);
215 if (!b || (index >= (total_count - 1))) {
216 pending_request pr(handler->plugin());
217 pr.remove(handler->user_req_id);
223 /*----------------------------------------------------------------------------*/
224 /*typedef int (*maps_plugin_geocode_inside_area_f)(maps_service_h maps, const
225 * char *address, maps_area_h bounds, maps_service_geocode_cb callback,
226 * void *user_data, int *request_id); */
227 session::command_geocode_inside_bounds::command_geocode_inside_bounds(
231 const maps_item_hashtable_h pref,
232 maps_service_geocode_cb cb,
233 void *ud, int *request_id)
242 *request_id = command::command_request_id++;
243 my_req_id = *request_id;
245 if (maps_area_is_valid(b)) {
249 error = MAPS_ERROR_INVALID_PARAMETER;
255 session::command_geocode_inside_bounds::~command_geocode_inside_bounds()
259 int session::command_geocode_inside_bounds::run()
261 if (error != MAPS_ERROR_NONE) return error;
263 pending_request pr(plugin());
265 /* Get the plugin interface function */
266 maps_plugin_geocode_inside_area_f func =
267 interface()->maps_plugin_geocode_inside_area;
268 command_geocode_handler *handler = NULL;
270 /* No need to create the handler when the function is NULL */
272 handler = new command_geocode_handler(plugin(),
278 /* Run the plugin interface function */
279 error = func(address.c_str(), bounds, preference,
280 command_geocode_handler::foreach_geocode_cb,
281 handler, &handler->plg_req_id);
283 pr.update(my_req_id, handler);
285 MAPS_LOGD("session::command_geocode_inside_bounds::run: %d", my_req_id);
287 error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
290 /* Plugin Function is NULL: use default empty function */
292 func = plugin::get_empty_interface().
293 maps_plugin_geocode_inside_area;
295 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
296 error = MAPS_ERROR_NOT_SUPPORTED;
299 const int ret = error;
304 /*----------------------------------------------------------------------------*/
305 /*typedef int (*maps_plugin_geocode_by_structured_address_f)(
306 * maps_service_h maps, maps_address_h address, maps_preference_h preference,
307 * maps_service_geocode_cb callback, void *user_data, int *request_id); */
308 session::command_geocode_by_structured_address::
309 command_geocode_by_structured_address(maps_service_h ms,
310 const maps_address_h a,
311 const maps_item_hashtable_h pref,
312 maps_service_geocode_cb cb,
313 void *ud, int *request_id)
321 *request_id = command::command_request_id++;
322 my_req_id = *request_id;
324 if (maps_address_is_valid(a)) {
328 error = MAPS_ERROR_INVALID_PARAMETER;
330 MAPS_LOGD("Invalid parameter");
335 session::command_geocode_by_structured_address::
336 ~command_geocode_by_structured_address()
340 int session::command_geocode_by_structured_address::run()
342 if (error != MAPS_ERROR_NONE) return error;
344 pending_request pr(plugin());
346 /* Get the plugin interface function */
347 maps_plugin_geocode_by_structured_address_f func =
348 interface()->maps_plugin_geocode_by_structured_address;
349 command_geocode_handler *handler = NULL;
351 /* No need to create the handler when the function is NULL */
353 handler = new command_geocode_handler(plugin(),
359 /* Run the plugin interface function */
360 error = func(address,
361 preference, command_geocode_handler::foreach_geocode_cb,
362 handler, &handler->plg_req_id);
364 pr.update(my_req_id, handler);
366 error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
369 /* Plugin Function is NULL: use default empty function */
371 func = plugin::get_empty_interface().
372 maps_plugin_geocode_by_structured_address;
374 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
375 error = MAPS_ERROR_NOT_SUPPORTED;
378 const int ret = error;
383 /*----------------------------------------------------------------------------*/
384 /*typedef int (*maps_plugin_reverse_geocode_f)(maps_service_h maps,
385 * double latitude, double longitude, maps_service_reverse_geocode_cb callback,
386 * void *user_data, int *request_id); */
387 session::command_reverse_geocode::command_reverse_geocode(maps_service_h ms,
388 double lat, double lon,
389 const maps_item_hashtable_h pref,
390 maps_service_reverse_geocode_cb cb,
391 void *ud, int *request_id)
400 *request_id = command::command_request_id++;
401 my_req_id = *request_id;
404 session::command_reverse_geocode::~command_reverse_geocode()
408 int session::command_reverse_geocode::run()
410 if (error != MAPS_ERROR_NONE) return error;
412 pending_request pr(plugin());
414 /* Get the plugin interface function */
415 maps_plugin_reverse_geocode_f func = interface()->maps_plugin_reverse_geocode;
416 command_reverse_geocode_handler *handler = NULL;
418 /* No need to create the handler when the function is NULL */
420 handler = new command_reverse_geocode_handler(plugin(),
426 /* Run the plugin interface function */
427 error = func(latitude, longitude, preference,
428 command_reverse_geocode_handler::foreach_reverse_geocode_cb,
429 handler, &handler->plg_req_id);
431 pr.update(my_req_id, handler);
433 MAPS_LOGD("session::command_reverse_geocode::run: %d", my_req_id);
435 error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
438 /* Plugin Function is NULL: use default empty function */
440 func = plugin::get_empty_interface().
441 maps_plugin_reverse_geocode;
443 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
444 error = MAPS_ERROR_NOT_SUPPORTED;
447 const int ret = error;
453 session::command_reverse_geocode_handler::command_reverse_geocode_handler(
455 maps_service_reverse_geocode_cb cb,
457 : command_handler(p, ud, urid)
463 void session::command_reverse_geocode_handler::foreach_reverse_geocode_cb(
465 int request_id, int index,
467 maps_address_h address,
470 command_reverse_geocode_handler *handler =
471 (command_reverse_geocode_handler *) user_data;
473 if (request_id != handler->plg_req_id) {
475 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
476 request_id, handler->plg_req_id);
480 /* Make a user's copy of result data */
481 maps_address_h cloned_result = NULL;
482 if (error == MAPS_ERROR_NONE)
483 error = (maps_error_e) maps_address_clone(address,
485 maps_address_destroy(address);
487 /* Send data to user */
488 handler->callback(error, handler->user_req_id, index, total,
489 cloned_result, handler->user_data);
490 /*if(index>=(total-1)) */
492 pending_request pr(handler->plugin());
493 pr.remove(handler->user_req_id);
496 /*----------------------------------------------------------------------------*/
497 /*typedef int (*maps_plugin_multi_reverse_geocode_f) (maps_service_h maps,
498 * maps_coordinates_list_h maps_list, maps_preference_h preference,
499 * maps_service_multi_reverse_geocode_cb callback, void * user_data, int *request_id) */
500 session::command_multi_reverse_geocode::command_multi_reverse_geocode(
501 maps_service_h ms, const maps_coordinates_list_h list, const maps_item_hashtable_h pref,
502 maps_service_multi_reverse_geocode_cb cb, void *ud, int *request_id)
510 *request_id = command::command_request_id++;
511 my_req_id = *request_id;
514 maps_coordinates_list_get_length(list, &list_size);
515 if (list_size < 2 || list_size > 100) {
516 error = MAPS_ERROR_INVALID_PARAMETER;
522 session::command_multi_reverse_geocode::~command_multi_reverse_geocode()
526 int session::command_multi_reverse_geocode::run()
528 if (error != MAPS_ERROR_NONE) return error;
530 pending_request pr(plugin());
532 /* Get the plugin interface function */
533 maps_plugin_multi_reverse_geocode_f func =
534 interface()->maps_plugin_multi_reverse_geocode;
536 command_multi_reverse_geocode_handler *handler = NULL;
538 /* No need to create the handler when the function is NULL */
540 handler = new command_multi_reverse_geocode_handler(plugin(), callback, user_data, my_req_id);
543 /* Run the plugin interface function */
544 error = func(maps_list, preference,
545 command_multi_reverse_geocode_handler::foreach_multi_reverse_geocode_cb,
546 handler, &handler->plg_req_id);
548 pr.update(my_req_id, handler);
550 MAPS_LOGD("session::command_multi_reverse_geocode::run: %d", my_req_id);
552 error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
555 /* Plugin Function is NULL: use default empty function */
557 func = plugin::get_empty_interface().
558 maps_plugin_multi_reverse_geocode;
560 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
561 error = MAPS_ERROR_NOT_SUPPORTED;
564 const int ret = error;
570 session::command_multi_reverse_geocode_handler::command_multi_reverse_geocode_handler(
571 plugin::plugin_s *p, maps_service_multi_reverse_geocode_cb cb, void *ud, int urid)
572 : command_handler(p, ud, urid)
578 bool session::command_multi_reverse_geocode_handler::foreach_multi_reverse_geocode_cb(
579 maps_error_e error, int request_id, int total, maps_coordinates_list_h address_list, void *user_data)
581 command_multi_reverse_geocode_handler *handler =
582 (command_multi_reverse_geocode_handler *) user_data;
584 if (request_id != handler->plg_req_id) {
586 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
587 request_id, handler->plg_req_id);
591 /* Make a user's copy of result data */
592 maps_coordinates_list_h cloned_result = NULL;
593 cloned_result = address_list;
595 /* Send data to user */
596 const bool b = handler->callback(error, handler->user_req_id, total, cloned_result, handler->user_data);
597 /*if(index>=(total-1)) */
599 pending_request pr(handler->plugin());
600 pr.remove(handler->user_req_id);
605 /*----------------------------------------------------------------------------*/
606 /*typedef int (*maps_plugin_search_place_f)(maps_service_h maps,
607 * maps_coordinates_h position, int distance, maps_item_hashtable_h preference,
608 * maps_place_filter_h filter, maps_service_search_place_cb callback,
609 * void* user_data, int* request_id); */
610 session::command_search_place::command_search_place(maps_service_h ms,
611 const maps_coordinates_h pos,
613 const maps_item_hashtable_h pref,
614 const maps_place_filter_h flt,
615 maps_service_search_place_cb cb,
616 void *ud, int *request_id)
624 , error(MAPS_ERROR_NONE)
626 *request_id = command::command_request_id++;
627 my_req_id = *request_id;
629 if (maps_coordinates_is_valid(pos)) {
633 error = MAPS_ERROR_INVALID_PARAMETER;
635 MAPS_LOGD("Invalid parameter");
640 session::command_search_place::~command_search_place()
644 int session::command_search_place::run()
646 if (error != MAPS_ERROR_NONE) return error;
648 pending_request pr(plugin());
650 /* Get the plugin interface function */
651 maps_plugin_search_place_f func = interface()->maps_plugin_search_place;
652 command_search_place_handler *handler = NULL;
654 /* No need to create the handler when the function is NULL */
656 handler = new command_search_place_handler(plugin(),
661 /* Run the plugin interface function */
662 error = func(position, distance, filter, preference,
663 command_search_place_handler::foreach_place_cb, handler,
664 &handler->plg_req_id);
666 pr.update(my_req_id, handler);
668 MAPS_LOGD("session::command_search_place::run: %d", my_req_id);
670 error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
673 /* Plugin Function is NULL: use default empty function */
675 func = plugin::get_empty_interface().maps_plugin_search_place;
677 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
678 error = MAPS_ERROR_NOT_SUPPORTED;
681 const int ret = error;
687 session::command_search_place_handler::command_search_place_handler(
689 maps_service_search_place_cb cb,
691 : command_handler(p, ud, urid)
697 bool session::command_search_place_handler::foreach_place_cb(maps_error_e error,
704 command_search_place_handler *handler =
705 (command_search_place_handler *) user_data;
707 if (request_id != handler->plg_req_id) {
709 MAPS_LOGE("\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n",
710 request_id, handler->plg_req_id);
714 /* Make a user's copy of result data */
715 maps_place_h cloned_result = NULL;
716 if (error == MAPS_ERROR_NONE)
717 error = (maps_error_e) maps_place_clone(place, &cloned_result);
718 maps_place_destroy(place);
720 /* Check which data features are supported */
722 handler->set_supported_place_data(cloned_result);
724 /* Send data to user */
725 const bool b = handler->callback(error, handler->user_req_id, index, length,
726 cloned_result, handler->user_data);
727 if (!b || (index >= (length - 1))) {
728 pending_request pr(handler->plugin());
729 pr.remove(handler->user_req_id);
735 /*----------------------------------------------------------------------------*/
736 /*typedef int (*maps_plugin_search_place_by_area_f)(maps_service_h maps,
737 * maps_area_h boundary , maps_item_hashtable_h preference,
738 * maps_place_filter_h filter, maps_service_search_place_cb callback,
739 * void *user_data, int *request_id); */
740 session::command_search_by_area_place::command_search_by_area_place(
741 maps_service_h ms, const maps_area_h b,
742 const maps_item_hashtable_h pref,
743 const maps_place_filter_h flt,
744 maps_service_search_place_cb cb,
745 void *ud, int *request_id)
752 , error(MAPS_ERROR_NONE)
754 *request_id = command::command_request_id++;
755 my_req_id = *request_id;
757 if (maps_area_is_valid(b)) {
761 error = MAPS_ERROR_INVALID_PARAMETER;
767 session::command_search_by_area_place::~command_search_by_area_place()
771 int session::command_search_by_area_place::run()
773 if (error != MAPS_ERROR_NONE) return error;
775 pending_request pr(plugin());
777 /* Get the plugin interface function */
778 maps_plugin_search_place_by_area_f func =
779 interface()->maps_plugin_search_place_by_area;
780 command_search_place_handler *handler = NULL;
782 /* No need to create the handler when the function is NULL */
784 handler = new command_search_place_handler(plugin(),
789 /* Run the plugin interface function */
790 error = func(boundary, filter,
791 preference, command_search_place_handler::foreach_place_cb,
792 handler, &handler->plg_req_id);
794 pr.update(my_req_id, handler);
796 MAPS_LOGD("session::command_search_by_area_place::run: %d", my_req_id);
798 error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
801 /* Plugin Function is NULL: use default empty function */
803 func = plugin::get_empty_interface().
804 maps_plugin_search_place_by_area;
807 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
808 error = MAPS_ERROR_NOT_SUPPORTED;
811 const int ret = error;
816 /*----------------------------------------------------------------------------*/
817 /*typedef int (*maps_plugin_search_place_by_address_f)(maps_service_h maps,
818 * const char *address, maps_area_h boundary, maps_item_hashtable_h preference,
819 * maps_place_filter_h filter, maps_service_search_place_cb callback,
820 * void *user_data, int *request_id); */
821 session::command_search_by_address_place::command_search_by_address_place(
822 maps_service_h ms, const char *a,
824 const maps_item_hashtable_h pref,
825 const maps_place_filter_h flt,
826 maps_service_search_place_cb cb,
827 void *ud, int *request_id)
835 , error(MAPS_ERROR_NONE)
837 *request_id = command::command_request_id++;
838 my_req_id = *request_id;
840 if (maps_area_is_valid(b)) {
844 error = MAPS_ERROR_INVALID_PARAMETER;
846 MAPS_LOGD("Invalid parameter");
851 session::command_search_by_address_place::~command_search_by_address_place()
855 int session::command_search_by_address_place::run()
857 if (error != MAPS_ERROR_NONE)
860 pending_request pr(plugin());
862 /* Get the plugin interface function */
863 maps_plugin_search_place_by_address_f func =
864 interface()->maps_plugin_search_place_by_address;
865 command_search_place_handler *handler = NULL;
867 /* No need to create the handler when the function is NULL */
869 handler = new command_search_place_handler(plugin(),
874 /* Run the plugin interface function */
875 error = func(address.c_str(), boundary, filter, preference,
876 command_search_place_handler::foreach_place_cb, handler,
877 &handler->plg_req_id);
879 pr.update(my_req_id, handler);
881 MAPS_LOGD("session::command_search_by_address_place::run: %d", my_req_id);
883 error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
886 /* Plugin Function is NULL: use default empty function */
888 func = plugin::get_empty_interface().
889 maps_plugin_search_place_by_address;
891 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
892 error = MAPS_ERROR_NOT_SUPPORTED;
895 const int ret = error;
900 /*----------------------------------------------------------------------------*/
901 /*typedef int (*maps_plugin_search_place_list_f)(maps_service_h maps,
902 * maps_item_hashtable_h preference, maps_place_filter_h filter,
903 * maps_service_search_place_list_cb callback, void* user_data, int* request_id); */
904 session::command_search_place_list::command_search_place_list(maps_service_h ms,
906 const maps_item_hashtable_h pref,
907 const maps_place_filter_h flt,
908 maps_service_search_place_list_cb cb,
909 void *ud, int *request_id)
916 , error(MAPS_ERROR_NONE)
918 *request_id = command::command_request_id++;
919 my_req_id = *request_id;
921 if (maps_area_is_valid(b)) {
925 error = MAPS_ERROR_INVALID_PARAMETER;
927 MAPS_LOGD("Invalid parameter");
932 session::command_search_place_list::~command_search_place_list()
936 int session::command_search_place_list::run()
938 if (error != MAPS_ERROR_NONE)
941 pending_request pr(plugin());
943 /* Get the plugin interface function */
944 maps_plugin_search_place_list_f func = interface()->maps_plugin_search_place_list;
945 command_search_place_list_handler *handler = NULL;
947 /* No need to create the handler when the function is NULL */
949 handler = new command_search_place_list_handler(plugin(),
954 /* Run the plugin interface function */
955 error = func(boundary, filter, preference,
956 command_search_place_list_handler::foreach_place_list_cb, handler,
957 &handler->plg_req_id);
959 pr.update(my_req_id, handler);
961 MAPS_LOGD("session::command_search_place_list::run: %d", my_req_id);
963 error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
966 /* Plugin Function is NULL: use default empty function */
968 func = plugin::get_empty_interface().maps_plugin_search_place_list;
970 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
971 error = MAPS_ERROR_NOT_SUPPORTED;
974 const int ret = error;
980 session::command_search_place_list_handler::command_search_place_list_handler(
982 maps_service_search_place_list_cb cb,
984 : command_handler(p, ud, urid)
990 void session::command_search_place_list_handler::foreach_place_list_cb(maps_error_e error,
993 maps_place_list_h place_list,
996 command_search_place_list_handler *handler =
997 (command_search_place_list_handler *) user_data;
999 if (request_id != handler->plg_req_id) {
1001 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
1002 request_id, handler->plg_req_id);
1006 /* Check which data features are supported */
1008 handler->set_supported_place_list_data(place_list);
1010 /* Send data to user */
1011 handler->callback(error, handler->user_req_id, total, place_list, handler->user_data);
1013 pending_request pr(handler->plugin());
1014 pr.remove(handler->user_req_id);
1017 /*----------------------------------------------------------------------------*/
1018 /*typedef int (*maps_plugin_get_place_details_f) */
1019 session::command_get_place_details::command_get_place_details(
1020 maps_service_h ms, const char *a,
1021 maps_service_get_place_details_cb cb,
1022 void *ud, int *request_id)
1027 , error(MAPS_ERROR_NONE)
1029 *request_id = command::command_request_id++;
1030 my_req_id = *request_id;
1033 session::command_get_place_details::~command_get_place_details()
1037 int session::command_get_place_details::run()
1039 if (error != MAPS_ERROR_NONE)
1042 pending_request pr(plugin());
1044 /* Get the plugin interface function */
1045 maps_plugin_get_place_details_f func =
1046 interface()->maps_plugin_get_place_details;
1047 command_get_place_details_handler *handler = NULL;
1049 /* No need to create the handler when the function is NULL */
1051 handler = new command_get_place_details_handler(plugin(),
1052 callback, user_data, my_req_id);
1054 /* Run the plugin interface function */
1055 error = func(url.c_str(),
1056 command_get_place_details_handler::foreach_place_details_cb,
1057 handler, &handler->plg_req_id);
1059 pr.update(my_req_id, handler);
1061 MAPS_LOGD("session::command_get_place_details::run: %d",
1064 error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
1067 /* Plugin Function is NULL: use default empty function */
1069 func = plugin::get_empty_interface().
1070 maps_plugin_get_place_details;
1072 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
1073 error = MAPS_ERROR_NOT_SUPPORTED;
1076 const int ret = error;
1082 session::command_get_place_details_handler::command_get_place_details_handler(
1083 plugin::plugin_s* p,
1084 maps_service_get_place_details_cb cb,
1086 : command_handler(p, ud, urid)
1092 void session::command_get_place_details_handler::foreach_place_details_cb(maps_error_e error,
1093 int request_id, maps_place_h place, void *user_data)
1095 command_get_place_details_handler *handler =
1096 (command_get_place_details_handler *) user_data;
1098 if (request_id != handler->plg_req_id) {
1100 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
1101 request_id, handler->plg_req_id);
1105 /* Make a user's copy of result data */
1106 maps_place_h cloned_result = NULL;
1107 if (error == MAPS_ERROR_NONE)
1108 error = (maps_error_e) maps_place_clone(place, &cloned_result);
1109 maps_place_destroy(place);
1111 /* Check which data features are supported */
1113 handler->set_supported_place_data(cloned_result);
1115 /* Send data to user */
1116 handler->callback(error, handler->user_req_id, cloned_result, handler->user_data);
1118 pending_request pr(handler->plugin());
1119 pr.remove(handler->user_req_id);
1122 /*----------------------------------------------------------------------------*/
1123 /*typedef int (*maps_plugin_search_route_f)(maps_service_h maps,
1124 * maps_item_hashtable_h preference, maps_coordinates_h origin,
1125 * maps_coordinates_h destination, maps_service_search_route_cb callback,
1126 * void *user_data, int *request_id); */
1127 session::command_search_route::command_search_route(maps_service_h ms,
1128 const maps_item_hashtable_h pref,
1129 const maps_coordinates_h orig,
1130 const maps_coordinates_h dest,
1131 maps_service_search_route_cb cb,
1132 void *ud, int *request_id)
1139 , error(MAPS_ERROR_NONE)
1141 *request_id = command::command_request_id++;
1142 my_req_id = *request_id;
1144 if (maps_coordinates_is_valid(orig)) {
1147 error = MAPS_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1150 if (maps_coordinates_is_valid(dest)) {
1153 error = MAPS_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1159 MAPS_LOGD("Invalid parameter");
1164 session::command_search_route::~command_search_route()
1168 int session::command_search_route::run()
1170 if (error != MAPS_ERROR_NONE) return error;
1172 pending_request pr(plugin());
1174 /* Get the plugin interface function */
1175 maps_plugin_search_route_f func = interface()->maps_plugin_search_route;
1176 command_search_route_handler *handler = NULL;
1178 /* No need to create the handler when the function is NULL */
1180 handler = new command_search_route_handler(plugin(),
1181 callback, user_data, my_req_id);
1184 /* Run the plugin interface function */
1185 error = func(origin, destination, preference,
1186 command_search_route_handler::foreach_route_cb,
1187 handler, &handler->plg_req_id);
1189 pr.update(my_req_id, handler);
1191 MAPS_LOGD("session::command_search_route::run: %d", my_req_id);
1193 error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
1196 /* Plugin Function is NULL: use default empty function */
1198 func = plugin::get_empty_interface().maps_plugin_search_route;
1200 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
1201 error = MAPS_ERROR_NOT_SUPPORTED;
1204 const int ret = error;
1209 /*----------------------------------------------------------------------------*/
1210 /*typedef int (*maps_plugin_search_route_waypoints_f)(maps_service_h maps,
1211 * maps_item_hashtable_h preference, maps_coordinates_h *waypoint_list,
1212 * int waypoint_num, maps_service_search_route_cb callback, void *user_data,
1213 * int *request_id); */
1214 session::command_search_route_waypoints::command_search_route_waypoints(
1216 const maps_item_hashtable_h pref,
1217 const maps_coordinates_h *list,
1218 int num, maps_service_search_route_cb cb,
1219 void *ud, int *request_id)
1222 , waypoint_list(NULL)
1226 , error(MAPS_ERROR_NONE)
1228 *request_id = command::command_request_id++;
1229 my_req_id = *request_id;
1231 waypoint_list = new maps_coordinates_h[num];
1232 for (int index = 0; index < num; index++) {
1233 if (list[index] != NULL) {
1234 maps_coordinates_clone(list[index],
1235 &waypoint_list[index]);
1240 session::command_search_route_waypoints::~command_search_route_waypoints()
1242 for (int index = 0; index < waypoint_num; index++) {
1243 if (waypoint_list[index] != NULL) {
1244 maps_coordinates_destroy(waypoint_list[index]);
1247 delete [] waypoint_list;
1250 int session::command_search_route_waypoints::run()
1252 if (error != MAPS_ERROR_NONE)
1255 pending_request pr(plugin());
1257 /* Get the plugin interface function */
1258 maps_plugin_search_route_waypoints_f func =
1259 interface()->maps_plugin_search_route_waypoints;
1261 command_search_route_handler *handler = NULL;
1263 /* No need to create the handler when the function is NULL */
1265 handler = new command_search_route_handler(plugin(),
1270 /* Run the plugin interface function */
1271 error = func(waypoint_list, waypoint_num, preference,
1272 command_search_route_handler::foreach_route_cb, handler,
1273 &handler->plg_req_id);
1275 pr.update(my_req_id, handler);
1277 MAPS_LOGD("session::command_search_place::run: %d", my_req_id);
1279 error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
1282 /* Plugin Function is NULL: use default empty function */
1284 func = plugin::get_empty_interface().
1285 maps_plugin_search_route_waypoints;
1287 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
1288 error = MAPS_ERROR_NOT_SUPPORTED;
1291 const int ret = error;
1297 session::command_search_route_handler::command_search_route_handler(
1298 plugin::plugin_s *p,
1299 maps_service_search_route_cb cb,
1301 : command_handler(p, ud, urid)
1307 bool session::command_search_route_handler::foreach_route_cb(maps_error_e error,
1314 command_search_route_handler *handler =
1315 (command_search_route_handler *) user_data;
1317 if (request_id != handler->plg_req_id) {
1319 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
1320 request_id, handler->plg_req_id);
1324 /* Make a user's copy of result data */
1325 maps_route_h cloned_result = NULL;
1326 if (error == MAPS_ERROR_NONE)
1327 error = (maps_error_e) maps_route_clone(route, &cloned_result);
1328 maps_route_destroy(route);
1330 /* Check which data features are supported */
1332 handler->set_supported_route_data(cloned_result);
1334 /* Send data to user */
1336 handler->callback(error, handler->user_req_id, index, length,
1337 cloned_result, handler->user_data);
1338 if (!b || (index >= (length - 1))) {
1339 pending_request pr(handler->plugin());
1340 pr.remove(handler->user_req_id);
1346 /*----------------------------------------------------------------------------*/
1347 /*typedef int (*maps_plugin_cancel_request_f)(maps_service_h maps,
1348 * int request_id); */
1349 int session::command_cancel_request::run()
1351 pending_request pr(plugin());
1352 MAPS_LOGD("session::command_cancel_request::run: %d, %p", request_id, pr.look_up(request_id));
1353 const int error = (pr.contains(request_id)) ?
1354 interface()->maps_plugin_cancel_request(pr.extract_plg_id(request_id)) : MAPS_ERROR_NOT_FOUND;
1360 /*----------------------------------------------------------------------------*/
1362 * Mapping API commands
1364 /*----------------------------------------------------------------------------*/
1367 session::command_view_set_center::command_view_set_center(maps_service_h ms,
1369 const maps_coordinates_h coords)
1374 maps_coordinates_clone(coords, &c);
1377 session::command_view_set_center::~command_view_set_center()
1379 maps_coordinates_destroy(c);
1382 int session::command_view_set_center::run()
1384 { /* TODO: remove it in release */
1385 double lat = 0, lon = 0;
1386 maps_coordinates_get_latitude_longitude(c, &lat, &lon);
1387 MAPS_LOGD("session::command_view_set_center::run lat,lon=%f,%f",
1392 return MAPS_ERROR_INVALID_PARAMETER;
1394 int error = MAPS_ERROR_NONE;
1396 error = maps_view_set_center(v, c);
1397 if(error != MAPS_ERROR_NONE)
1401 const int ret = error;
1406 session::command_type_e session::command_view_set_center::get_type() const
1408 return MAPS_VIEW_SET_CENTER_COMMAND;
1411 int session::command_view_set_center::get_priority() const
1416 void session::command_view_set_center::merge(const command *c)
1418 if (!c || (get_type() != c->get_type())) return;
1419 command_view_set_center *cmd = (command_view_set_center *)c;
1423 maps_coordinates_get_latitude_longitude(cmd->c, &lat, &lon);
1424 maps_coordinates_set_latitude_longitude(this->c, lat, lon);
1430 /*----------------------------------------------------------------------------*/
1433 session::command_view_move_center::command_view_move_center(maps_service_h ms,
1444 session::command_view_move_center::~command_view_move_center()
1448 int session::command_view_move_center::run()
1450 MAPS_LOGD("session::command_view_move_center::run "
1451 "delta_x = %d, delta_y = %d",
1452 _delta_x, _delta_y);
1455 return MAPS_ERROR_INVALID_PARAMETER;
1457 int error = MAPS_ERROR_NONE;
1459 error = _maps_view_move_center(v, _delta_x, _delta_y);
1460 if(error != MAPS_ERROR_NONE)
1464 const int ret = error;
1469 session::command_type_e session::command_view_move_center::get_type() const
1471 return MAPS_VIEW_MOVE_CENTER_COMMAND;
1474 int session::command_view_move_center::get_priority() const
1479 void session::command_view_move_center::merge(const command *c)
1481 if (!c || (get_type() != c->get_type())) return;
1482 command_view_move_center *cmd = (command_view_move_center *)c;
1484 _delta_x += cmd->_delta_x;
1485 _delta_y += cmd->_delta_y;
1490 /*----------------------------------------------------------------------------*/
1492 int session::command_view_zoom::run()
1494 MAPS_LOGD("session::command_view_zoom::run factor = %f", zoom_factor);
1497 return MAPS_ERROR_INVALID_PARAMETER;
1499 const int ret = maps_view_set_zoom_factor(v, zoom_factor);
1505 session::command_type_e session::command_view_zoom::get_type() const
1507 return MAPS_VIEW_ZOOM_COMMAND;
1510 int session::command_view_zoom::get_priority() const
1515 void session::command_view_zoom::merge(const command *c)
1517 if (!c || (get_type() != c->get_type())) return;
1518 command_view_zoom *cmd = (command_view_zoom *)c;
1520 zoom_factor = cmd->zoom_factor;
1525 /*----------------------------------------------------------------------------*/
1526 int session::command_view_rotate::run()
1528 MAPS_LOGD("session::command_view_rotate::run angle = %f",
1532 return MAPS_ERROR_INVALID_PARAMETER;
1534 const int ret = maps_view_set_orientation(v, rotation_angle);
1540 session::command_type_e session::command_view_rotate::get_type() const
1542 return MAPS_VIEW_ROTATE_COMMAND;
1545 int session::command_view_rotate::get_priority() const
1550 void session::command_view_rotate::merge(const command *c)
1552 if (!c || (get_type() != c->get_type())) return;
1553 command_view_rotate *cmd = (command_view_rotate *)c;
1555 rotation_angle += cmd->rotation_angle;
1560 /*----------------------------------------------------------------------------*/
1562 int session::command_view_zoom_rotate::run()
1564 MAPS_LOGD("session::command_view_zoom_rotate::run "
1565 "factor = %f, angle = %f",
1566 zoom_factor, rotation_angle);
1569 return MAPS_ERROR_INVALID_PARAMETER;
1571 const int ret = _maps_view_set_zoom_rotate(v,
1573 true, rotation_angle);
1579 session::command_type_e session::command_view_zoom_rotate::get_type() const
1581 return MAPS_VIEW_ZOOM_ROTATE_COMMAND;
1584 int session::command_view_zoom_rotate::get_priority() const
1589 void session::command_view_zoom_rotate::merge(const command *c)
1591 if (!c || (get_type() != c->get_type())) return;
1592 command_view_zoom_rotate *cmd = (command_view_zoom_rotate *)c;
1594 zoom_factor = cmd->zoom_factor;
1595 rotation_angle += cmd->rotation_angle;