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;
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;
179 session::command_geocode_handler::command_geocode_handler(plugin::plugin_s *p,
180 maps_service_geocode_cb cb,
182 : command_handler(p, ud, urid)
187 bool session::command_geocode_handler::foreach_geocode_cb(maps_error_e error,
195 command_geocode_handler *handler = (command_geocode_handler *) user_data;
197 if (request_id != handler->plg_req_id) {
198 MAPS_LOGE("\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n",
199 request_id, handler->plg_req_id);
202 /* Make a user's copy of result data */
203 maps_coordinates_h cloned_result = NULL;
204 if (error == MAPS_ERROR_NONE)
205 error = (maps_error_e) maps_coordinates_clone(coordinates, &cloned_result);
206 maps_coordinates_destroy(coordinates);
208 /* Send data to user */
209 const bool b = handler->callback(error, handler->user_req_id, index,
210 total_count, cloned_result, handler->user_data);
211 if (!b || (index >= (total_count - 1))) {
212 pending_request pr(handler->plugin());
213 pr.remove(handler->user_req_id);
219 /*----------------------------------------------------------------------------*/
220 /*typedef int (*maps_plugin_geocode_inside_area_f)(maps_service_h maps, const
221 * char *address, maps_area_h bounds, maps_service_geocode_cb callback,
222 * void *user_data, int *request_id); */
223 session::command_geocode_inside_bounds::command_geocode_inside_bounds(
227 const maps_item_hashtable_h pref,
228 maps_service_geocode_cb cb,
229 void *ud, int *request_id)
238 *request_id = command::command_request_id++;
239 my_req_id = *request_id;
241 if (maps_area_is_valid(b)) {
244 error = MAPS_ERROR_INVALID_PARAMETER;
249 session::command_geocode_inside_bounds::~command_geocode_inside_bounds()
253 int session::command_geocode_inside_bounds::run()
255 if (error != MAPS_ERROR_NONE) return error;
257 pending_request pr(plugin());
259 /* Get the plugin interface function */
260 maps_plugin_geocode_inside_area_f func =
261 interface()->maps_plugin_geocode_inside_area;
262 command_geocode_handler *handler = NULL;
264 /* No need to create the handler when the function is NULL */
266 handler = new command_geocode_handler(plugin(),
272 /* Run the plugin interface function */
273 error = func(address.c_str(), bounds, preference,
274 command_geocode_handler::foreach_geocode_cb,
275 handler, &handler->plg_req_id);
277 pr.update(my_req_id, handler);
279 MAPS_LOGD("session::command_geocode_inside_bounds::run: %d", my_req_id);
281 error = MAPS_ERROR_OUT_OF_MEMORY;
284 /* Plugin Function is NULL: use default empty function */
286 func = plugin::get_empty_interface().
287 maps_plugin_geocode_inside_area;
289 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
290 error = MAPS_ERROR_NOT_SUPPORTED;
293 const int ret = error;
298 /*----------------------------------------------------------------------------*/
299 /*typedef int (*maps_plugin_geocode_by_structured_address_f)(
300 * maps_service_h maps, maps_address_h address, maps_preference_h preference,
301 * maps_service_geocode_cb callback, void *user_data, int *request_id); */
302 session::command_geocode_by_structured_address::
303 command_geocode_by_structured_address(maps_service_h ms,
304 const maps_address_h a,
305 const maps_item_hashtable_h pref,
306 maps_service_geocode_cb cb,
307 void *ud, int *request_id)
315 *request_id = command::command_request_id++;
316 my_req_id = *request_id;
318 if (maps_address_is_valid(a)) {
321 error = MAPS_ERROR_INVALID_PARAMETER;
323 MAPS_LOGD("Invalid parameter");
327 session::command_geocode_by_structured_address::
328 ~command_geocode_by_structured_address()
332 int session::command_geocode_by_structured_address::run()
334 if (error != MAPS_ERROR_NONE) return error;
336 pending_request pr(plugin());
338 /* Get the plugin interface function */
339 maps_plugin_geocode_by_structured_address_f func =
340 interface()->maps_plugin_geocode_by_structured_address;
341 command_geocode_handler *handler = NULL;
343 /* No need to create the handler when the function is NULL */
345 handler = new command_geocode_handler(plugin(),
351 /* Run the plugin interface function */
352 error = func(address,
353 preference, command_geocode_handler::foreach_geocode_cb,
354 handler, &handler->plg_req_id);
356 pr.update(my_req_id, handler);
358 error = MAPS_ERROR_OUT_OF_MEMORY;
361 /* Plugin Function is NULL: use default empty function */
363 func = plugin::get_empty_interface().
364 maps_plugin_geocode_by_structured_address;
366 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
367 error = MAPS_ERROR_NOT_SUPPORTED;
370 const int ret = error;
375 /*----------------------------------------------------------------------------*/
376 /*typedef int (*maps_plugin_reverse_geocode_f)(maps_service_h maps,
377 * double latitude, double longitude, maps_service_reverse_geocode_cb callback,
378 * void *user_data, int *request_id); */
379 session::command_reverse_geocode::command_reverse_geocode(maps_service_h ms,
380 double lat, double lon,
381 const maps_item_hashtable_h pref,
382 maps_service_reverse_geocode_cb cb,
383 void *ud, int *request_id)
392 *request_id = command::command_request_id++;
393 my_req_id = *request_id;
396 session::command_reverse_geocode::~command_reverse_geocode()
400 int session::command_reverse_geocode::run()
402 if (error != MAPS_ERROR_NONE) return error;
404 pending_request pr(plugin());
406 /* Get the plugin interface function */
407 maps_plugin_reverse_geocode_f func = interface()->maps_plugin_reverse_geocode;
408 command_reverse_geocode_handler *handler = NULL;
410 /* No need to create the handler when the function is NULL */
412 handler = new command_reverse_geocode_handler(plugin(),
418 /* Run the plugin interface function */
419 error = func(latitude, longitude, preference,
420 command_reverse_geocode_handler::foreach_reverse_geocode_cb,
421 handler, &handler->plg_req_id);
423 pr.update(my_req_id, handler);
425 MAPS_LOGD("session::command_reverse_geocode::run: %d", my_req_id);
427 error = MAPS_ERROR_OUT_OF_MEMORY;
430 /* Plugin Function is NULL: use default empty function */
432 func = plugin::get_empty_interface().
433 maps_plugin_reverse_geocode;
435 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
436 error = MAPS_ERROR_NOT_SUPPORTED;
439 const int ret = error;
444 session::command_reverse_geocode_handler::command_reverse_geocode_handler(
446 maps_service_reverse_geocode_cb cb,
448 : command_handler(p, ud, urid)
453 void session::command_reverse_geocode_handler::foreach_reverse_geocode_cb(
455 int request_id, int index,
457 maps_address_h address,
460 command_reverse_geocode_handler *handler =
461 (command_reverse_geocode_handler *) user_data;
463 if (request_id != handler->plg_req_id) {
464 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
465 request_id, handler->plg_req_id);
468 /* Make a user's copy of result data */
469 maps_address_h cloned_result = NULL;
470 if (error == MAPS_ERROR_NONE)
471 error = (maps_error_e) maps_address_clone(address,
473 maps_address_destroy(address);
475 /* Send data to user */
476 handler->callback(error, handler->user_req_id, index, total,
477 cloned_result, handler->user_data);
478 /*if(index>=(total-1)) */
480 pending_request pr(handler->plugin());
481 pr.remove(handler->user_req_id);
484 /*----------------------------------------------------------------------------*/
485 /*typedef int (*maps_plugin_multi_reverse_geocode_f) (maps_service_h maps,
486 * maps_coordinates_list_h maps_list, maps_preference_h preference,
487 * maps_service_multi_reverse_geocode_cb callback, void * user_data, int *request_id) */
488 session::command_multi_reverse_geocode::command_multi_reverse_geocode(
489 maps_service_h ms, const maps_coordinates_list_h list, const maps_item_hashtable_h pref,
490 maps_service_multi_reverse_geocode_cb cb, void *ud, int *request_id)
498 *request_id = command::command_request_id++;
499 my_req_id = *request_id;
502 maps_coordinates_list_get_length(list, &list_size);
503 if (list_size < 2 || list_size > 100) {
504 error = MAPS_ERROR_INVALID_PARAMETER;
510 session::command_multi_reverse_geocode::~command_multi_reverse_geocode()
514 int session::command_multi_reverse_geocode::run()
516 if (error != MAPS_ERROR_NONE) return error;
518 pending_request pr(plugin());
520 /* Get the plugin interface function */
521 maps_plugin_multi_reverse_geocode_f func =
522 interface()->maps_plugin_multi_reverse_geocode;
524 command_multi_reverse_geocode_handler *handler = NULL;
526 /* No need to create the handler when the function is NULL */
528 handler = new command_multi_reverse_geocode_handler(plugin(), callback, user_data, my_req_id);
531 /* Run the plugin interface function */
532 error = func(maps_list, preference,
533 command_multi_reverse_geocode_handler::foreach_multi_reverse_geocode_cb,
534 handler, &handler->plg_req_id);
536 pr.update(my_req_id, handler);
538 MAPS_LOGD("session::command_multi_reverse_geocode::run: %d", my_req_id);
540 error = MAPS_ERROR_OUT_OF_MEMORY;
543 /* Plugin Function is NULL: use default empty function */
545 func = plugin::get_empty_interface().
546 maps_plugin_multi_reverse_geocode;
548 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
549 error = MAPS_ERROR_NOT_SUPPORTED;
552 const int ret = error;
557 session::command_multi_reverse_geocode_handler::command_multi_reverse_geocode_handler(
558 plugin::plugin_s *p, maps_service_multi_reverse_geocode_cb cb, void *ud, int urid)
559 : command_handler(p, ud, urid)
564 bool session::command_multi_reverse_geocode_handler::foreach_multi_reverse_geocode_cb(
565 maps_error_e error, int request_id, int total, maps_coordinates_list_h address_list, void *user_data)
567 command_multi_reverse_geocode_handler *handler =
568 (command_multi_reverse_geocode_handler *) user_data;
570 if (request_id != handler->plg_req_id) {
571 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
572 request_id, handler->plg_req_id);
575 /* Make a user's copy of result data */
576 maps_coordinates_list_h cloned_result = NULL;
577 cloned_result = address_list;
579 /* Send data to user */
580 const bool b = handler->callback(error, handler->user_req_id, total, cloned_result, handler->user_data);
581 /*if(index>=(total-1)) */
583 pending_request pr(handler->plugin());
584 pr.remove(handler->user_req_id);
589 /*----------------------------------------------------------------------------*/
590 /*typedef int (*maps_plugin_search_place_f)(maps_service_h maps,
591 * maps_coordinates_h position, int distance, maps_item_hashtable_h preference,
592 * maps_place_filter_h filter, maps_service_search_place_cb callback,
593 * void* user_data, int* request_id); */
594 session::command_search_place::command_search_place(maps_service_h ms,
595 const maps_coordinates_h pos,
597 const maps_item_hashtable_h pref,
598 const maps_place_filter_h flt,
599 maps_service_search_place_cb cb,
600 void *ud, int *request_id)
608 , error(MAPS_ERROR_NONE)
610 *request_id = command::command_request_id++;
611 my_req_id = *request_id;
613 if (maps_coordinates_is_valid(pos)) {
616 error = MAPS_ERROR_INVALID_PARAMETER;
618 MAPS_LOGD("Invalid parameter");
622 session::command_search_place::~command_search_place()
626 int session::command_search_place::run()
628 if (error != MAPS_ERROR_NONE) return error;
630 pending_request pr(plugin());
632 /* Get the plugin interface function */
633 maps_plugin_search_place_f func = interface()->maps_plugin_search_place;
634 command_search_place_handler *handler = NULL;
636 /* No need to create the handler when the function is NULL */
638 handler = new command_search_place_handler(plugin(),
643 /* Run the plugin interface function */
644 error = func(position, distance, filter, preference,
645 command_search_place_handler::foreach_place_cb, handler,
646 &handler->plg_req_id);
648 pr.update(my_req_id, handler);
650 MAPS_LOGD("session::command_search_place::run: %d", my_req_id);
652 error = MAPS_ERROR_OUT_OF_MEMORY;
655 /* Plugin Function is NULL: use default empty function */
657 func = plugin::get_empty_interface().maps_plugin_search_place;
659 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
660 error = MAPS_ERROR_NOT_SUPPORTED;
663 const int ret = error;
668 session::command_search_place_handler::command_search_place_handler(
670 maps_service_search_place_cb cb,
672 : command_handler(p, ud, urid)
677 bool session::command_search_place_handler::foreach_place_cb(maps_error_e error,
684 command_search_place_handler *handler =
685 (command_search_place_handler *) user_data;
687 if (request_id != handler->plg_req_id) {
688 MAPS_LOGE("\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n",
689 request_id, handler->plg_req_id);
692 /* Make a user's copy of result data */
693 maps_place_h cloned_result = NULL;
694 if (error == MAPS_ERROR_NONE)
695 error = (maps_error_e) maps_place_clone(place, &cloned_result);
696 maps_place_destroy(place);
698 /* Check which data features are supported */
700 handler->set_supported_place_data(cloned_result);
702 /* Send data to user */
703 const bool b = handler->callback(error, handler->user_req_id, index, length,
704 cloned_result, handler->user_data);
705 if (!b || (index >= (length - 1))) {
706 pending_request pr(handler->plugin());
707 pr.remove(handler->user_req_id);
713 /*----------------------------------------------------------------------------*/
714 /*typedef int (*maps_plugin_search_place_by_area_f)(maps_service_h maps,
715 * maps_area_h boundary , maps_item_hashtable_h preference,
716 * maps_place_filter_h filter, maps_service_search_place_cb callback,
717 * void *user_data, int *request_id); */
718 session::command_search_by_area_place::command_search_by_area_place(
719 maps_service_h ms, const maps_area_h b,
720 const maps_item_hashtable_h pref,
721 const maps_place_filter_h flt,
722 maps_service_search_place_cb cb,
723 void *ud, int *request_id)
730 , error(MAPS_ERROR_NONE)
732 *request_id = command::command_request_id++;
733 my_req_id = *request_id;
735 if (maps_area_is_valid(b)) {
738 error = MAPS_ERROR_INVALID_PARAMETER;
743 session::command_search_by_area_place::~command_search_by_area_place()
747 int session::command_search_by_area_place::run()
749 if (error != MAPS_ERROR_NONE) return error;
751 pending_request pr(plugin());
753 /* Get the plugin interface function */
754 maps_plugin_search_place_by_area_f func =
755 interface()->maps_plugin_search_place_by_area;
756 command_search_place_handler *handler = NULL;
758 /* No need to create the handler when the function is NULL */
760 handler = new command_search_place_handler(plugin(),
765 /* Run the plugin interface function */
766 error = func(boundary, filter,
767 preference, command_search_place_handler::foreach_place_cb,
768 handler, &handler->plg_req_id);
770 pr.update(my_req_id, handler);
772 MAPS_LOGD("session::command_search_by_area_place::run: %d", my_req_id);
774 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_area;
783 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
784 error = MAPS_ERROR_NOT_SUPPORTED;
787 const int ret = error;
792 /*----------------------------------------------------------------------------*/
793 /*typedef int (*maps_plugin_search_place_by_address_f)(maps_service_h maps,
794 * const char *address, maps_area_h boundary, maps_item_hashtable_h preference,
795 * maps_place_filter_h filter, maps_service_search_place_cb callback,
796 * void *user_data, int *request_id); */
797 session::command_search_by_address_place::command_search_by_address_place(
798 maps_service_h ms, const char *a,
800 const maps_item_hashtable_h pref,
801 const maps_place_filter_h flt,
802 maps_service_search_place_cb cb,
803 void *ud, int *request_id)
811 , error(MAPS_ERROR_NONE)
813 *request_id = command::command_request_id++;
814 my_req_id = *request_id;
816 if (maps_area_is_valid(b)) {
819 error = MAPS_ERROR_INVALID_PARAMETER;
821 MAPS_LOGD("Invalid parameter");
825 session::command_search_by_address_place::~command_search_by_address_place()
829 int session::command_search_by_address_place::run()
831 if (error != MAPS_ERROR_NONE)
834 pending_request pr(plugin());
836 /* Get the plugin interface function */
837 maps_plugin_search_place_by_address_f func =
838 interface()->maps_plugin_search_place_by_address;
839 command_search_place_handler *handler = NULL;
841 /* No need to create the handler when the function is NULL */
843 handler = new command_search_place_handler(plugin(),
848 /* Run the plugin interface function */
849 error = func(address.c_str(), boundary, filter, preference,
850 command_search_place_handler::foreach_place_cb, handler,
851 &handler->plg_req_id);
853 pr.update(my_req_id, handler);
855 MAPS_LOGD("session::command_search_by_address_place::run: %d", my_req_id);
857 error = MAPS_ERROR_OUT_OF_MEMORY;
860 /* Plugin Function is NULL: use default empty function */
862 func = plugin::get_empty_interface().
863 maps_plugin_search_place_by_address;
865 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
866 error = MAPS_ERROR_NOT_SUPPORTED;
869 const int ret = error;
874 /*----------------------------------------------------------------------------*/
875 /*typedef int (*maps_plugin_search_place_list_f)(maps_service_h maps,
876 * maps_item_hashtable_h preference, maps_place_filter_h filter,
877 * maps_service_search_place_list_cb callback, void* user_data, int* request_id); */
878 session::command_search_place_list::command_search_place_list(maps_service_h ms,
880 const maps_item_hashtable_h pref,
881 const maps_place_filter_h flt,
882 maps_service_search_place_list_cb cb,
883 void *ud, int *request_id)
890 , error(MAPS_ERROR_NONE)
892 *request_id = command::command_request_id++;
893 my_req_id = *request_id;
895 if (maps_area_is_valid(b)) {
898 error = MAPS_ERROR_INVALID_PARAMETER;
900 MAPS_LOGD("Invalid parameter");
904 session::command_search_place_list::~command_search_place_list()
908 int session::command_search_place_list::run()
910 if (error != MAPS_ERROR_NONE)
913 pending_request pr(plugin());
915 /* Get the plugin interface function */
916 maps_plugin_search_place_list_f func = interface()->maps_plugin_search_place_list;
917 command_search_place_list_handler *handler = NULL;
919 /* No need to create the handler when the function is NULL */
921 handler = new command_search_place_list_handler(plugin(),
926 /* Run the plugin interface function */
927 error = func(boundary, filter, preference,
928 command_search_place_list_handler::foreach_place_list_cb, handler,
929 &handler->plg_req_id);
931 pr.update(my_req_id, handler);
933 MAPS_LOGD("session::command_search_place_list::run: %d", my_req_id);
935 error = MAPS_ERROR_OUT_OF_MEMORY;
938 /* Plugin Function is NULL: use default empty function */
940 func = plugin::get_empty_interface().maps_plugin_search_place_list;
942 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
943 error = MAPS_ERROR_NOT_SUPPORTED;
946 const int ret = error;
951 session::command_search_place_list_handler::command_search_place_list_handler(
953 maps_service_search_place_list_cb cb,
955 : command_handler(p, ud, urid)
960 void session::command_search_place_list_handler::foreach_place_list_cb(maps_error_e error,
963 maps_place_list_h place_list,
966 command_search_place_list_handler *handler =
967 (command_search_place_list_handler *) user_data;
969 if (request_id != handler->plg_req_id) {
970 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
971 request_id, handler->plg_req_id);
974 /* Check which data features are supported */
976 handler->set_supported_place_list_data(place_list);
978 /* Send data to user */
979 handler->callback(error, handler->user_req_id, total, place_list, handler->user_data);
981 pending_request pr(handler->plugin());
982 pr.remove(handler->user_req_id);
985 /*----------------------------------------------------------------------------*/
986 /*typedef int (*maps_plugin_get_place_details_f) */
987 session::command_get_place_details::command_get_place_details(
988 maps_service_h ms, const char *a,
989 maps_service_get_place_details_cb cb,
990 void *ud, int *request_id)
995 , error(MAPS_ERROR_NONE)
997 *request_id = command::command_request_id++;
998 my_req_id = *request_id;
1001 session::command_get_place_details::~command_get_place_details()
1005 int session::command_get_place_details::run()
1007 if (error != MAPS_ERROR_NONE)
1010 pending_request pr(plugin());
1012 /* Get the plugin interface function */
1013 maps_plugin_get_place_details_f func =
1014 interface()->maps_plugin_get_place_details;
1015 command_get_place_details_handler *handler = NULL;
1017 /* No need to create the handler when the function is NULL */
1019 handler = new command_get_place_details_handler(plugin(),
1020 callback, user_data, my_req_id);
1022 /* Run the plugin interface function */
1023 error = func(url.c_str(),
1024 command_get_place_details_handler::foreach_place_details_cb,
1025 handler, &handler->plg_req_id);
1027 pr.update(my_req_id, handler);
1029 MAPS_LOGD("session::command_get_place_details::run: %d",
1032 error = MAPS_ERROR_OUT_OF_MEMORY;
1035 /* Plugin Function is NULL: use default empty function */
1037 func = plugin::get_empty_interface().
1038 maps_plugin_get_place_details;
1040 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
1041 error = MAPS_ERROR_NOT_SUPPORTED;
1044 const int ret = error;
1049 session::command_get_place_details_handler::command_get_place_details_handler(
1050 plugin::plugin_s* p,
1051 maps_service_get_place_details_cb cb,
1053 : command_handler(p, ud, urid)
1058 void session::command_get_place_details_handler::foreach_place_details_cb(maps_error_e error,
1059 int request_id, maps_place_h place, void *user_data)
1061 command_get_place_details_handler *handler =
1062 (command_get_place_details_handler *) user_data;
1064 if (request_id != handler->plg_req_id) {
1065 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
1066 request_id, handler->plg_req_id);
1069 /* Make a user's copy of result data */
1070 maps_place_h cloned_result = NULL;
1071 if (error == MAPS_ERROR_NONE)
1072 error = (maps_error_e) maps_place_clone(place, &cloned_result);
1073 maps_place_destroy(place);
1075 /* Check which data features are supported */
1077 handler->set_supported_place_data(cloned_result);
1079 /* Send data to user */
1080 handler->callback(error, handler->user_req_id, cloned_result, handler->user_data);
1082 pending_request pr(handler->plugin());
1083 pr.remove(handler->user_req_id);
1086 /*----------------------------------------------------------------------------*/
1087 /*typedef int (*maps_plugin_search_route_f)(maps_service_h maps,
1088 * maps_item_hashtable_h preference, maps_coordinates_h origin,
1089 * maps_coordinates_h destination, maps_service_search_route_cb callback,
1090 * void *user_data, int *request_id); */
1091 session::command_search_route::command_search_route(maps_service_h ms,
1092 const maps_item_hashtable_h pref,
1093 const maps_coordinates_h orig,
1094 const maps_coordinates_h dest,
1095 maps_service_search_route_cb cb,
1096 void *ud, int *request_id)
1103 , error(MAPS_ERROR_NONE)
1105 *request_id = command::command_request_id++;
1106 my_req_id = *request_id;
1108 if (maps_coordinates_is_valid(orig)) {
1111 error = MAPS_ERROR_INVALID_PARAMETER;
1114 if (maps_coordinates_is_valid(dest)) {
1117 error = MAPS_ERROR_INVALID_PARAMETER;
1122 MAPS_LOGD("Invalid parameter");
1126 session::command_search_route::~command_search_route()
1130 int session::command_search_route::run()
1132 if (error != MAPS_ERROR_NONE) return error;
1134 pending_request pr(plugin());
1136 /* Get the plugin interface function */
1137 maps_plugin_search_route_f func = interface()->maps_plugin_search_route;
1138 command_search_route_handler *handler = NULL;
1140 /* No need to create the handler when the function is NULL */
1142 handler = new command_search_route_handler(plugin(),
1143 callback, user_data, my_req_id);
1146 /* Run the plugin interface function */
1147 error = func(origin, destination, preference,
1148 command_search_route_handler::foreach_route_cb,
1149 handler, &handler->plg_req_id);
1151 pr.update(my_req_id, handler);
1153 MAPS_LOGD("session::command_search_route::run: %d", my_req_id);
1155 error = MAPS_ERROR_OUT_OF_MEMORY;
1158 /* Plugin Function is NULL: use default empty function */
1160 func = plugin::get_empty_interface().maps_plugin_search_route;
1162 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
1163 error = MAPS_ERROR_NOT_SUPPORTED;
1166 const int ret = error;
1171 /*----------------------------------------------------------------------------*/
1172 /*typedef int (*maps_plugin_search_route_waypoints_f)(maps_service_h maps,
1173 * maps_item_hashtable_h preference, maps_coordinates_h *waypoint_list,
1174 * int waypoint_num, maps_service_search_route_cb callback, void *user_data,
1175 * int *request_id); */
1176 session::command_search_route_waypoints::command_search_route_waypoints(
1178 const maps_item_hashtable_h pref,
1179 const maps_coordinates_h *list,
1180 int num, maps_service_search_route_cb cb,
1181 void *ud, int *request_id)
1184 , waypoint_list(NULL)
1188 , error(MAPS_ERROR_NONE)
1190 *request_id = command::command_request_id++;
1191 my_req_id = *request_id;
1193 waypoint_list = new maps_coordinates_h[num];
1194 for (int index = 0; index < num; index++) {
1195 if (list[index] != NULL) {
1196 maps_coordinates_clone(list[index],
1197 &waypoint_list[index]);
1202 session::command_search_route_waypoints::~command_search_route_waypoints()
1204 for (int index = 0; index < waypoint_num; index++) {
1205 if (waypoint_list[index] != NULL) {
1206 maps_coordinates_destroy(waypoint_list[index]);
1209 delete [] waypoint_list;
1212 int session::command_search_route_waypoints::run()
1214 if (error != MAPS_ERROR_NONE)
1217 pending_request pr(plugin());
1219 /* Get the plugin interface function */
1220 maps_plugin_search_route_waypoints_f func =
1221 interface()->maps_plugin_search_route_waypoints;
1223 command_search_route_handler *handler = NULL;
1225 /* No need to create the handler when the function is NULL */
1227 handler = new command_search_route_handler(plugin(),
1232 /* Run the plugin interface function */
1233 error = func(waypoint_list, waypoint_num, preference,
1234 command_search_route_handler::foreach_route_cb, handler,
1235 &handler->plg_req_id);
1237 pr.update(my_req_id, handler);
1239 MAPS_LOGD("session::command_search_place::run: %d", my_req_id);
1241 error = MAPS_ERROR_OUT_OF_MEMORY;
1244 /* Plugin Function is NULL: use default empty function */
1246 func = plugin::get_empty_interface().
1247 maps_plugin_search_route_waypoints;
1249 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
1250 error = MAPS_ERROR_NOT_SUPPORTED;
1253 const int ret = error;
1258 session::command_search_route_handler::command_search_route_handler(
1259 plugin::plugin_s *p,
1260 maps_service_search_route_cb cb,
1262 : command_handler(p, ud, urid)
1267 bool session::command_search_route_handler::foreach_route_cb(maps_error_e error,
1274 command_search_route_handler *handler =
1275 (command_search_route_handler *) user_data;
1277 if (request_id != handler->plg_req_id) {
1278 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
1279 request_id, handler->plg_req_id);
1282 /* Make a user's copy of result data */
1283 maps_route_h cloned_result = NULL;
1284 if (error == MAPS_ERROR_NONE)
1285 error = (maps_error_e) maps_route_clone(route, &cloned_result);
1286 maps_route_destroy(route);
1288 /* Check which data features are supported */
1290 handler->set_supported_route_data(cloned_result);
1292 /* Send data to user */
1294 handler->callback(error, handler->user_req_id, index, length,
1295 cloned_result, handler->user_data);
1296 if (!b || (index >= (length - 1))) {
1297 pending_request pr(handler->plugin());
1298 pr.remove(handler->user_req_id);
1304 /*----------------------------------------------------------------------------*/
1305 /*typedef int (*maps_plugin_cancel_request_f)(maps_service_h maps,
1306 * int request_id); */
1307 int session::command_cancel_request::run()
1309 pending_request pr(plugin());
1310 MAPS_LOGD("session::command_cancel_request::run: %d, %p", request_id, pr.look_up(request_id));
1311 const int error = (pr.contains(request_id)) ?
1312 interface()->maps_plugin_cancel_request(pr.extract_plg_id(request_id)) : MAPS_ERROR_NOT_FOUND;
1318 /*----------------------------------------------------------------------------*/
1320 * Mapping API commands
1322 /*----------------------------------------------------------------------------*/
1324 session::command_view_set_center::command_view_set_center(maps_service_h ms,
1326 const maps_coordinates_h coords)
1331 maps_coordinates_clone(coords, &c);
1334 session::command_view_set_center::~command_view_set_center()
1336 maps_coordinates_destroy(c);
1339 int session::command_view_set_center::run()
1341 { /* TODO: remove it in release */
1342 double lat = 0, lon = 0;
1343 maps_coordinates_get_latitude_longitude(c, &lat, &lon);
1344 MAPS_LOGD("session::command_view_set_center::run lat,lon=%f,%f",
1349 return MAPS_ERROR_INVALID_PARAMETER;
1351 int error = MAPS_ERROR_NONE;
1353 error = maps_view_set_center(v, c);
1354 if(error != MAPS_ERROR_NONE)
1358 const int ret = error;
1363 session::command_type_e session::command_view_set_center::get_type() const
1365 return MAPS_VIEW_SET_CENTER_COMMAND;
1368 int session::command_view_set_center::get_priority() const
1373 void session::command_view_set_center::merge(const command *c)
1375 if (!c || (get_type() != c->get_type())) return;
1376 command_view_set_center *cmd = (command_view_set_center *)c;
1380 maps_coordinates_get_latitude_longitude(cmd->c, &lat, &lon);
1381 maps_coordinates_set_latitude_longitude(this->c, lat, lon);
1387 /*----------------------------------------------------------------------------*/
1390 session::command_view_move_center::command_view_move_center(maps_service_h ms,
1401 session::command_view_move_center::~command_view_move_center()
1405 int session::command_view_move_center::run()
1407 MAPS_LOGD("session::command_view_move_center::run "
1408 "delta_x = %d, delta_y = %d",
1409 _delta_x, _delta_y);
1412 return MAPS_ERROR_INVALID_PARAMETER;
1414 int error = MAPS_ERROR_NONE;
1416 error = _maps_view_move_center(v, _delta_x, _delta_y);
1417 if(error != MAPS_ERROR_NONE)
1421 const int ret = error;
1426 session::command_type_e session::command_view_move_center::get_type() const
1428 return MAPS_VIEW_MOVE_CENTER_COMMAND;
1431 int session::command_view_move_center::get_priority() const
1436 void session::command_view_move_center::merge(const command *c)
1438 if (!c || (get_type() != c->get_type())) return;
1439 command_view_move_center *cmd = (command_view_move_center *)c;
1441 _delta_x += cmd->_delta_x;
1442 _delta_y += cmd->_delta_y;
1447 /*----------------------------------------------------------------------------*/
1449 int session::command_view_zoom::run()
1451 MAPS_LOGD("session::command_view_zoom::run factor = %f", zoom_factor);
1454 return MAPS_ERROR_INVALID_PARAMETER;
1456 const int ret = maps_view_set_zoom_factor(v, zoom_factor);
1462 session::command_type_e session::command_view_zoom::get_type() const
1464 return MAPS_VIEW_ZOOM_COMMAND;
1467 int session::command_view_zoom::get_priority() const
1472 void session::command_view_zoom::merge(const command *c)
1474 if (!c || (get_type() != c->get_type())) return;
1475 command_view_zoom *cmd = (command_view_zoom *)c;
1477 zoom_factor = cmd->zoom_factor;
1482 /*----------------------------------------------------------------------------*/
1483 int session::command_view_rotate::run()
1485 MAPS_LOGD("session::command_view_rotate::run angle = %f",
1489 return MAPS_ERROR_INVALID_PARAMETER;
1491 const int ret = maps_view_set_orientation(v, rotation_angle);
1497 session::command_type_e session::command_view_rotate::get_type() const
1499 return MAPS_VIEW_ROTATE_COMMAND;
1502 int session::command_view_rotate::get_priority() const
1507 void session::command_view_rotate::merge(const command *c)
1509 if (!c || (get_type() != c->get_type())) return;
1510 command_view_rotate *cmd = (command_view_rotate *)c;
1512 rotation_angle += cmd->rotation_angle;
1517 /*----------------------------------------------------------------------------*/
1519 int session::command_view_zoom_rotate::run()
1521 MAPS_LOGD("session::command_view_zoom_rotate::run "
1522 "factor = %f, angle = %f",
1523 zoom_factor, rotation_angle);
1526 return MAPS_ERROR_INVALID_PARAMETER;
1528 const int ret = _maps_view_set_zoom_rotate(v,
1530 true, rotation_angle);
1536 session::command_type_e session::command_view_zoom_rotate::get_type() const
1538 return MAPS_VIEW_ZOOM_ROTATE_COMMAND;
1541 int session::command_view_zoom_rotate::get_priority() const
1546 void session::command_view_zoom_rotate::merge(const command *c)
1548 if (!c || (get_type() != c->get_type())) return;
1549 command_view_zoom_rotate *cmd = (command_view_zoom_rotate *)c;
1551 zoom_factor = cmd->zoom_factor;
1552 rotation_angle += cmd->rotation_angle;