e20fdbc5c14863ce8b3f29a9b950849981c35c5e
[platform/core/api/maps-service.git] / src / session / commands.cpp
1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
2  *
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "commands.h"
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"
23
24 extern int _maps_view_move_center(maps_view_h view, const int delta_x, const int delta_y);
25
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);
29
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);
33
34 static int __put_to_hashtable(session::command_handler *ch,
35                                                                 maps_service_data_e feature,
36                                                                 maps_int_hashtable_h t)
37 {
38         if (!ch || !t)
39                 return MAPS_ERROR_INVALID_PARAMETER;
40         bool supported = false;
41         ch->plugin()->interface.maps_plugin_is_data_supported(feature, &supported);
42         if(supported)
43                 return  maps_int_hashtable_set(t, feature, feature);
44         return MAPS_ERROR_NONE;
45 }
46
47 void session::command_handler::set_supported_place_data(maps_place_h place)
48 {
49         if (!place || !plugin()) return;
50
51         maps_int_hashtable_h data_supported = NULL;
52         if (maps_int_hashtable_create(&data_supported) != MAPS_ERROR_NONE) return;
53
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);
64
65         _maps_place_set_supported_data(place, data_supported);
66         maps_int_hashtable_destroy(data_supported);
67 }
68
69 bool session::command_handler::set_supported_place_list_data_cb(int index, maps_place_h place, void *user_data)
70 {
71         if (!place || !user_data)
72                 return false;
73
74         maps_int_hashtable_h data_supported = (maps_int_hashtable_h)user_data;
75         _maps_place_set_supported_data(place, data_supported);
76         return true;
77 }
78
79 void session::command_handler::set_supported_place_list_data(maps_place_list_h place_list)
80 {
81         if (!place_list || !plugin()) return;
82
83         maps_int_hashtable_h data_supported = NULL;
84         if (maps_int_hashtable_create(&data_supported) != MAPS_ERROR_NONE) return;
85
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);
96
97         maps_place_list_foreach(place_list, set_supported_place_list_data_cb, data_supported);
98         maps_int_hashtable_destroy(data_supported);
99 }
100
101 void session::command_handler::set_supported_route_data(maps_route_h route)
102 {
103         if (!route || !plugin()) return;
104
105         maps_int_hashtable_h data_supported = NULL;
106         if (maps_int_hashtable_create(&data_supported) != MAPS_ERROR_NONE) return;
107
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);
111
112         _maps_route_set_supported_data(route, data_supported);
113         maps_int_hashtable_destroy(data_supported);
114 }
115
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)
123  : command(ms)
124  , address(a)
125  , preference(pref)
126  , callback(cb)
127  , user_data(ud)
128  , error(0)
129 {
130         *request_id = command::command_request_id++;
131         my_req_id = *request_id;
132 }
133
134 session::command_geocode::~command_geocode()
135 {
136 }
137
138 int session::command_geocode::run()
139 {
140         if (error != MAPS_ERROR_NONE) return error;
141
142         pending_request pr(plugin());
143
144         /* Get the plugin interface function */
145         maps_plugin_geocode_f func = interface()->maps_plugin_geocode;
146         command_geocode_handler *handler = NULL;
147         if (func) {
148                 /*  need to create the handler when the function is NULL */
149                 pr.add(my_req_id);
150                 handler = new command_geocode_handler(plugin(),
151                                              callback, user_data, my_req_id);
152
153                 if (handler) {
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);
158
159                         pr.update(my_req_id, handler);
160
161                         MAPS_LOGD("session::command_geocode::run: %d", my_req_id);
162                 } else {
163                         error = MAPS_ERROR_OUT_OF_MEMORY;
164                 }
165         } else {
166                 /* Plugin Function is NULL: use default empty function */
167                 /*
168                 func = plugin::get_empty_interface().maps_plugin_geocode;
169                 */
170                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
171                 error = MAPS_ERROR_NOT_SUPPORTED;
172         }
173
174         const int ret = error;
175         destroy();
176         return ret;
177 }
178
179 session::command_geocode_handler::command_geocode_handler(plugin::plugin_s *p,
180                                                 maps_service_geocode_cb cb,
181                                                 void *ud, int urid)
182  : command_handler(p, ud, urid)
183  , callback(cb)
184 {
185 }
186
187 bool session::command_geocode_handler::foreach_geocode_cb(maps_error_e error,
188                                                           int request_id,
189                                                           int index,
190                                                           int total_count,
191                                                           maps_coordinates_h
192                                                           coordinates,
193                                                           void *user_data)
194 {
195         command_geocode_handler *handler = (command_geocode_handler *) user_data;
196
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);
200         }
201
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);
207
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);
214         }
215
216         return b;
217 }
218
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(
224                                         maps_service_h ms,
225                                         const char *a,
226                                         const maps_area_h b,
227                                         const maps_item_hashtable_h pref,
228                                         maps_service_geocode_cb cb,
229                                         void *ud, int *request_id)
230  : command(ms)
231  , address(a)
232  , bounds(NULL)
233  , preference(pref)
234  , callback(cb)
235  , user_data(ud)
236  , error(0)
237 {
238         *request_id = command::command_request_id++;
239         my_req_id = *request_id;
240
241         if (maps_area_is_valid(b)) {
242                 bounds = b;
243         } else {
244                 error = MAPS_ERROR_INVALID_PARAMETER;
245                 *request_id = -1;
246         }
247 }
248
249 session::command_geocode_inside_bounds::~command_geocode_inside_bounds()
250 {
251 }
252
253 int session::command_geocode_inside_bounds::run()
254 {
255         if (error != MAPS_ERROR_NONE) return error;
256
257         pending_request pr(plugin());
258
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;
263         if (func) {
264                 /* No need to create the handler when the function is NULL */
265                 pr.add(my_req_id);
266                 handler = new command_geocode_handler(plugin(),
267                                                       callback,
268                                                       user_data,
269                                                       my_req_id);
270
271                 if (handler) {
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);
276
277                         pr.update(my_req_id, handler);
278
279                         MAPS_LOGD("session::command_geocode_inside_bounds::run: %d", my_req_id);
280                 } else {
281                         error = MAPS_ERROR_OUT_OF_MEMORY;
282                 }
283         } else {
284                 /* Plugin Function is NULL: use default empty function */
285                 /*
286                 func = plugin::get_empty_interface().
287                         maps_plugin_geocode_inside_area;
288                 */
289                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
290                 error = MAPS_ERROR_NOT_SUPPORTED;
291         }
292
293         const int ret = error;
294         destroy();
295         return ret;
296 }
297
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)
308  : command(ms)
309  , address(NULL)
310  , preference(pref)
311  , callback(cb)
312  , user_data(ud)
313  , error(0)
314 {
315         *request_id = command::command_request_id++;
316         my_req_id = *request_id;
317
318         if (maps_address_is_valid(a)) {
319                 address = a;
320         } else {
321                 error = MAPS_ERROR_INVALID_PARAMETER;
322                 *request_id = -1;
323                 MAPS_LOGD("Invalid parameter");
324         }
325 }
326
327 session::command_geocode_by_structured_address::
328         ~command_geocode_by_structured_address()
329 {
330 }
331
332 int session::command_geocode_by_structured_address::run()
333 {
334         if (error != MAPS_ERROR_NONE) return error;
335
336         pending_request pr(plugin());
337
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;
342         if (func) {
343                 /* No need to create the handler when the function is NULL */
344                 pr.add(my_req_id);
345                 handler = new command_geocode_handler(plugin(),
346                                                       callback,
347                                                       user_data,
348                                                       my_req_id);
349
350                 if (handler) {
351                         /* Run the plugin interface function */
352                         error = func(address,
353                                                  preference, command_geocode_handler::foreach_geocode_cb,
354                                                  handler, &handler->plg_req_id);
355
356                         pr.update(my_req_id, handler);
357                 } else {
358                         error = MAPS_ERROR_OUT_OF_MEMORY;
359                 }
360         } else {
361                 /* Plugin Function is NULL: use default empty function */
362                 /*
363                 func = plugin::get_empty_interface().
364                         maps_plugin_geocode_by_structured_address;
365                 */
366                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
367                 error = MAPS_ERROR_NOT_SUPPORTED;
368         }
369
370         const int ret = error;
371         destroy();
372         return ret;
373 }
374
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)
384  : command(ms)
385  , latitude(lat)
386  , longitude(lon)
387  , preference(pref)
388  , callback(cb)
389  , user_data(ud)
390  , error(0)
391 {
392         *request_id = command::command_request_id++;
393         my_req_id = *request_id;
394 }
395
396 session::command_reverse_geocode::~command_reverse_geocode()
397 {
398 }
399
400 int session::command_reverse_geocode::run()
401 {
402         if (error != MAPS_ERROR_NONE) return error;
403
404         pending_request pr(plugin());
405
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;
409         if (func) {
410                 /* No need to create the handler when the function is NULL */
411                 pr.add(my_req_id);
412                 handler = new command_reverse_geocode_handler(plugin(),
413                                                               callback,
414                                                               user_data,
415                                                               my_req_id);
416
417                 if (handler) {
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);
422
423                         pr.update(my_req_id, handler);
424
425                         MAPS_LOGD("session::command_reverse_geocode::run: %d", my_req_id);
426                 } else {
427                         error = MAPS_ERROR_OUT_OF_MEMORY;
428                 }
429         } else {
430                 /* Plugin Function is NULL: use default empty function */
431                 /*
432                 func = plugin::get_empty_interface().
433                         maps_plugin_reverse_geocode;
434                 */
435                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
436                 error = MAPS_ERROR_NOT_SUPPORTED;
437         }
438
439         const int ret = error;
440         destroy();
441         return ret;
442 }
443
444 session::command_reverse_geocode_handler::command_reverse_geocode_handler(
445                                         plugin::plugin_s *p,
446                                         maps_service_reverse_geocode_cb cb,
447                                         void *ud, int urid)
448  : command_handler(p, ud, urid)
449  , callback(cb)
450 {
451 }
452
453 void session::command_reverse_geocode_handler::foreach_reverse_geocode_cb(
454                                                 maps_error_e error,
455                                                 int request_id, int index,
456                                                 int total,
457                                                 maps_address_h address,
458                                                 void *user_data)
459 {
460         command_reverse_geocode_handler *handler =
461                 (command_reverse_geocode_handler *) user_data;
462
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);
466         }
467
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,
472                         &cloned_result);
473         maps_address_destroy(address);
474
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)) */
479
480         pending_request pr(handler->plugin());
481         pr.remove(handler->user_req_id);
482 }
483
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)
491  : command(ms)
492  , maps_list(NULL)
493  , preference(pref)
494  , callback(cb)
495  , user_data(ud)
496  , error(0)
497 {
498         *request_id = command::command_request_id++;
499         my_req_id = *request_id;
500
501         int list_size = 0;
502         maps_coordinates_list_get_length(list, &list_size);
503         if (list_size < 2 || list_size > 100) {
504                 error = MAPS_ERROR_INVALID_PARAMETER;
505                 *request_id = -1;
506         }
507         maps_list = list;
508 }
509
510 session::command_multi_reverse_geocode::~command_multi_reverse_geocode()
511 {
512 }
513
514 int session::command_multi_reverse_geocode::run()
515 {
516         if (error != MAPS_ERROR_NONE) return error;
517
518         pending_request pr(plugin());
519
520         /* Get the plugin interface function */
521         maps_plugin_multi_reverse_geocode_f func =
522                 interface()->maps_plugin_multi_reverse_geocode;
523
524         command_multi_reverse_geocode_handler *handler = NULL;
525         if (func) {
526                 /* No need to create the handler when the function is NULL */
527                 pr.add(my_req_id);
528                 handler = new command_multi_reverse_geocode_handler(plugin(), callback, user_data, my_req_id);
529
530                 if (handler) {
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);
535
536                         pr.update(my_req_id, handler);
537
538                         MAPS_LOGD("session::command_multi_reverse_geocode::run: %d", my_req_id);
539                 } else {
540                         error = MAPS_ERROR_OUT_OF_MEMORY;
541                 }
542         } else {
543                 /* Plugin Function is NULL: use default empty function */
544                 /*
545                 func = plugin::get_empty_interface().
546                         maps_plugin_multi_reverse_geocode;
547                 */
548                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
549                 error = MAPS_ERROR_NOT_SUPPORTED;
550         }
551
552         const int ret = error;
553         destroy();
554         return ret;
555 }
556
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)
560  , callback(cb)
561 {
562 }
563
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)
566 {
567         command_multi_reverse_geocode_handler *handler =
568                 (command_multi_reverse_geocode_handler *) user_data;
569
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);
573         }
574
575         /* Make a user's copy of result data */
576         maps_coordinates_list_h cloned_result = NULL;
577         cloned_result = address_list;
578
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)) */
582
583         pending_request pr(handler->plugin());
584         pr.remove(handler->user_req_id);
585
586         return b;
587 }
588
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,
596                                         int dst,
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)
601  : command(ms)
602  , position(NULL)
603  , distance(dst)
604  , preference(pref)
605  , filter(flt)
606  , callback(cb)
607  , user_data(ud)
608  , error(MAPS_ERROR_NONE)
609 {
610         *request_id = command::command_request_id++;
611         my_req_id = *request_id;
612
613         if (maps_coordinates_is_valid(pos)) {
614                 position = pos;
615         } else {
616                 error = MAPS_ERROR_INVALID_PARAMETER;
617                 *request_id = -1;
618                 MAPS_LOGD("Invalid parameter");
619         }
620 }
621
622 session::command_search_place::~command_search_place()
623 {
624 }
625
626 int session::command_search_place::run()
627 {
628         if (error != MAPS_ERROR_NONE) return error;
629
630         pending_request pr(plugin());
631
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;
635         if (func) {
636                 /* No need to create the handler when the function is NULL */
637                 pr.add(my_req_id);
638                 handler = new command_search_place_handler(plugin(),
639                                                            callback,
640                                                            user_data,
641                                                            my_req_id);
642                 if (handler) {
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);
647
648                         pr.update(my_req_id, handler);
649
650                         MAPS_LOGD("session::command_search_place::run: %d", my_req_id);
651                 } else {
652                         error = MAPS_ERROR_OUT_OF_MEMORY;
653                 }
654         } else {
655                 /* Plugin Function is NULL: use default empty function */
656                 /*
657                 func = plugin::get_empty_interface().maps_plugin_search_place;
658                 */
659                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
660                 error = MAPS_ERROR_NOT_SUPPORTED;
661         }
662
663         const int ret = error;
664         destroy();
665         return ret;
666 }
667
668 session::command_search_place_handler::command_search_place_handler(
669                                                 plugin::plugin_s* p,
670                                                 maps_service_search_place_cb cb,
671                                                 void *ud, int urid)
672  : command_handler(p, ud, urid)
673  , callback(cb)
674 {
675 }
676
677 bool session::command_search_place_handler::foreach_place_cb(maps_error_e error,
678                                                              int request_id,
679                                                              int index,
680                                                              int length,
681                                                              maps_place_h place,
682                                                              void *user_data)
683 {
684         command_search_place_handler *handler =
685                 (command_search_place_handler *) user_data;
686
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);
690         }
691
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);
697
698         /* Check which data features are supported */
699         if (cloned_result)
700                 handler->set_supported_place_data(cloned_result);
701
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);
708         }
709
710         return b;
711 }
712
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)
724  : command(ms)
725  , boundary(NULL)
726  , preference(pref)
727  , filter(flt)
728  , callback(cb)
729  , user_data(ud)
730  , error(MAPS_ERROR_NONE)
731 {
732         *request_id = command::command_request_id++;
733         my_req_id = *request_id;
734
735         if (maps_area_is_valid(b)) {
736                 boundary = b;
737         } else {
738                 error = MAPS_ERROR_INVALID_PARAMETER;
739                 *request_id = -1;
740         }
741 }
742
743 session::command_search_by_area_place::~command_search_by_area_place()
744 {
745 }
746
747 int session::command_search_by_area_place::run()
748 {
749         if (error != MAPS_ERROR_NONE) return error;
750
751         pending_request pr(plugin());
752
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;
757         if (func) {
758                 /* No need to create the handler when the function is NULL */
759                 pr.add(my_req_id);
760                 handler = new command_search_place_handler(plugin(),
761                                                            callback,
762                                                            user_data,
763                                                            my_req_id);
764                 if (handler) {
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);
769
770                         pr.update(my_req_id, handler);
771
772                         MAPS_LOGD("session::command_search_by_area_place::run: %d", my_req_id);
773                 } else {
774                         error = MAPS_ERROR_OUT_OF_MEMORY;
775                 }
776         } else {
777                 /* Plugin Function is NULL: use default empty function */
778                 /*
779                 func = plugin::get_empty_interface().
780                         maps_plugin_search_place_by_area;
781                 */
782
783                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
784                 error = MAPS_ERROR_NOT_SUPPORTED;
785         }
786
787         const int ret = error;
788         destroy();
789         return ret;
790 }
791
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,
799                                         const maps_area_h b,
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)
804  : command(ms)
805  , address(a)
806  , boundary(NULL)
807  , preference(pref)
808  , filter(flt)
809  , callback(cb)
810  , user_data(ud)
811  , error(MAPS_ERROR_NONE)
812 {
813         *request_id = command::command_request_id++;
814         my_req_id = *request_id;
815
816         if (maps_area_is_valid(b)) {
817                 boundary = b;
818         } else {
819                 error = MAPS_ERROR_INVALID_PARAMETER;
820                 *request_id = -1;
821                 MAPS_LOGD("Invalid parameter");
822         }
823 }
824
825 session::command_search_by_address_place::~command_search_by_address_place()
826 {
827 }
828
829 int session::command_search_by_address_place::run()
830 {
831         if (error != MAPS_ERROR_NONE)
832                 return error;
833
834         pending_request pr(plugin());
835
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;
840         if (func) {
841                 /* No need to create the handler when the function is NULL */
842                 pr.add(my_req_id);
843                 handler = new command_search_place_handler(plugin(),
844                                                            callback,
845                                                            user_data,
846                                                            my_req_id);
847                 if (handler) {
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);
852
853                         pr.update(my_req_id, handler);
854
855                         MAPS_LOGD("session::command_search_by_address_place::run: %d", my_req_id);
856                 } else {
857                         error = MAPS_ERROR_OUT_OF_MEMORY;
858                 }
859         } else {
860                 /* Plugin Function is NULL: use default empty function */
861                 /*
862                 func = plugin::get_empty_interface().
863                         maps_plugin_search_place_by_address;
864                 */
865                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
866                 error = MAPS_ERROR_NOT_SUPPORTED;
867         }
868
869         const int ret = error;
870         destroy();
871         return ret;
872 }
873
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,
879                                         const maps_area_h b,
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)
884  : command(ms)
885  , boundary(NULL)
886  , preference(pref)
887  , filter(flt)
888  , callback(cb)
889  , user_data(ud)
890  , error(MAPS_ERROR_NONE)
891 {
892         *request_id = command::command_request_id++;
893         my_req_id = *request_id;
894
895         if (maps_area_is_valid(b)) {
896                 boundary = b;
897         } else {
898                 error = MAPS_ERROR_INVALID_PARAMETER;
899                 *request_id = -1;
900                 MAPS_LOGD("Invalid parameter");
901         }
902 }
903
904 session::command_search_place_list::~command_search_place_list()
905 {
906 }
907
908 int session::command_search_place_list::run()
909 {
910         if (error != MAPS_ERROR_NONE)
911                 return error;
912
913         pending_request pr(plugin());
914
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;
918         if (func) {
919                 /* No need to create the handler when the function is NULL */
920                 pr.add(my_req_id);
921                 handler = new command_search_place_list_handler(plugin(),
922                                                            callback,
923                                                            user_data,
924                                                            my_req_id);
925                 if (handler) {
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);
930
931                         pr.update(my_req_id, handler);
932
933                         MAPS_LOGD("session::command_search_place_list::run: %d", my_req_id);
934                 } else {
935                         error = MAPS_ERROR_OUT_OF_MEMORY;
936                 }
937         } else {
938                 /* Plugin Function is NULL: use default empty function */
939                 /*
940                 func = plugin::get_empty_interface().maps_plugin_search_place_list;
941                 */
942                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
943                 error = MAPS_ERROR_NOT_SUPPORTED;
944         }
945
946         const int ret = error;
947         destroy();
948         return ret;
949 }
950
951 session::command_search_place_list_handler::command_search_place_list_handler(
952                                                 plugin::plugin_s* p,
953                                                 maps_service_search_place_list_cb cb,
954                                                 void *ud, int urid)
955  : command_handler(p, ud, urid)
956  , callback(cb)
957 {
958 }
959
960 void session::command_search_place_list_handler::foreach_place_list_cb(maps_error_e error,
961                                                              int request_id,
962                                                                  int total,
963                                                              maps_place_list_h place_list,
964                                                              void *user_data)
965 {
966         command_search_place_list_handler *handler =
967                 (command_search_place_list_handler *) user_data;
968
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);
972         }
973
974         /* Check which data features are supported */
975         if (place_list)
976                 handler->set_supported_place_list_data(place_list);
977
978         /* Send data to user */
979         handler->callback(error, handler->user_req_id, total, place_list, handler->user_data);
980
981         pending_request pr(handler->plugin());
982         pr.remove(handler->user_req_id);
983 }
984
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)
991  : command(ms)
992  , url(a)
993  , callback(cb)
994  , user_data(ud)
995  , error(MAPS_ERROR_NONE)
996 {
997         *request_id = command::command_request_id++;
998         my_req_id = *request_id;
999 }
1000
1001 session::command_get_place_details::~command_get_place_details()
1002 {
1003 }
1004
1005 int session::command_get_place_details::run()
1006 {
1007         if (error != MAPS_ERROR_NONE)
1008                 return error;
1009
1010         pending_request pr(plugin());
1011
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;
1016         if (func) {
1017                 /* No need to create the handler when the function is NULL */
1018                 pr.add(my_req_id);
1019                 handler = new command_get_place_details_handler(plugin(),
1020                                                            callback, user_data, my_req_id);
1021                 if (handler) {
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);
1026
1027                         pr.update(my_req_id, handler);
1028
1029                         MAPS_LOGD("session::command_get_place_details::run: %d",
1030                                 my_req_id);
1031                 } else {
1032                         error = MAPS_ERROR_OUT_OF_MEMORY;
1033                 }
1034         } else {
1035                 /* Plugin Function is NULL: use default empty function */
1036                 /*
1037                 func = plugin::get_empty_interface().
1038                         maps_plugin_get_place_details;
1039                 */
1040                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
1041                 error = MAPS_ERROR_NOT_SUPPORTED;
1042         }
1043
1044         const int ret = error;
1045         destroy();
1046         return ret;
1047 }
1048
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,
1052                                                 void *ud, int urid)
1053  : command_handler(p, ud, urid)
1054  , callback(cb)
1055 {
1056 }
1057
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)
1060 {
1061         command_get_place_details_handler *handler =
1062                 (command_get_place_details_handler *) user_data;
1063
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);
1067         }
1068
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);
1074
1075         /* Check which data features are supported */
1076         if (cloned_result)
1077                 handler->set_supported_place_data(cloned_result);
1078
1079         /* Send data to user */
1080         handler->callback(error, handler->user_req_id, cloned_result, handler->user_data);
1081
1082         pending_request pr(handler->plugin());
1083         pr.remove(handler->user_req_id);
1084 }
1085
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)
1097  : command(ms)
1098  , preference(pref)
1099  , origin(NULL)
1100  , destination(NULL)
1101  , callback(cb)
1102  , user_data(ud)
1103  , error(MAPS_ERROR_NONE)
1104 {
1105         *request_id = command::command_request_id++;
1106         my_req_id = *request_id;
1107
1108         if (maps_coordinates_is_valid(orig)) {
1109                 origin = orig;
1110         } else {
1111                 error = MAPS_ERROR_INVALID_PARAMETER;
1112         }
1113
1114         if (maps_coordinates_is_valid(dest)) {
1115                 destination = dest;
1116         } else {
1117                 error = MAPS_ERROR_INVALID_PARAMETER;
1118         }
1119
1120         if (error) {
1121                 *request_id = -1;
1122                 MAPS_LOGD("Invalid parameter");
1123         }
1124 }
1125
1126 session::command_search_route::~command_search_route()
1127 {
1128 }
1129
1130 int session::command_search_route::run()
1131 {
1132         if (error != MAPS_ERROR_NONE) return error;
1133
1134         pending_request pr(plugin());
1135
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;
1139         if (func) {
1140                 /* No need to create the handler when the function is NULL */
1141                 pr.add(my_req_id);
1142                 handler = new command_search_route_handler(plugin(),
1143                                                         callback, user_data, my_req_id);
1144
1145                 if (handler) {
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);
1150
1151                         pr.update(my_req_id, handler);
1152
1153                         MAPS_LOGD("session::command_search_route::run: %d", my_req_id);
1154                 } else {
1155                         error = MAPS_ERROR_OUT_OF_MEMORY;
1156                 }
1157         } else {
1158                 /* Plugin Function is NULL: use default empty function */
1159                 /*
1160                 func = plugin::get_empty_interface().maps_plugin_search_route;
1161                 */
1162                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
1163                 error = MAPS_ERROR_NOT_SUPPORTED;
1164         }
1165
1166         const int ret = error;
1167         destroy();
1168         return ret;
1169 }
1170
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(
1177                                 maps_service_h ms,
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)
1182  : command(ms)
1183  , preference(pref)
1184  , waypoint_list(NULL)
1185  , waypoint_num(num)
1186  , callback(cb)
1187  , user_data(ud)
1188  , error(MAPS_ERROR_NONE)
1189 {
1190         *request_id = command::command_request_id++;
1191         my_req_id = *request_id;
1192
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]);
1198                 }
1199         }
1200 }
1201
1202 session::command_search_route_waypoints::~command_search_route_waypoints()
1203 {
1204         for (int index = 0; index < waypoint_num; index++) {
1205                 if (waypoint_list[index] != NULL) {
1206                         maps_coordinates_destroy(waypoint_list[index]);
1207                 }
1208         }
1209         delete [] waypoint_list;
1210 }
1211
1212 int session::command_search_route_waypoints::run()
1213 {
1214         if (error != MAPS_ERROR_NONE)
1215                 return error;
1216
1217         pending_request pr(plugin());
1218
1219         /* Get the plugin interface function */
1220         maps_plugin_search_route_waypoints_f func =
1221                 interface()->maps_plugin_search_route_waypoints;
1222
1223         command_search_route_handler *handler = NULL;
1224         if (func) {
1225                 /* No need to create the handler when the function is NULL */
1226                 pr.add(my_req_id);
1227                 handler = new command_search_route_handler(plugin(),
1228                                                  callback,
1229                                                  user_data,
1230                                                  my_req_id);
1231                 if (handler) {
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);
1236
1237                         pr.update(my_req_id, handler);
1238
1239                         MAPS_LOGD("session::command_search_place::run: %d", my_req_id);
1240                 } else {
1241                         error = MAPS_ERROR_OUT_OF_MEMORY;
1242                 }
1243         } else {
1244                 /* Plugin Function is NULL: use default empty function */
1245                 /*
1246                 func = plugin::get_empty_interface().
1247                         maps_plugin_search_route_waypoints;
1248                 */
1249                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
1250                 error = MAPS_ERROR_NOT_SUPPORTED;
1251         }
1252
1253         const int ret = error;
1254         destroy();
1255         return ret;
1256 }
1257
1258 session::command_search_route_handler::command_search_route_handler(
1259                                                 plugin::plugin_s *p,
1260                                                 maps_service_search_route_cb cb,
1261                                                 void *ud, int urid)
1262  : command_handler(p, ud, urid)
1263  , callback(cb)
1264 {
1265 }
1266
1267 bool session::command_search_route_handler::foreach_route_cb(maps_error_e error,
1268                                                              int request_id,
1269                                                              int index,
1270                                                              int length,
1271                                                              maps_route_h route,
1272                                                              void *user_data)
1273 {
1274         command_search_route_handler *handler =
1275                 (command_search_route_handler *) user_data;
1276
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);
1280         }
1281
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);
1287
1288         /* Check which data features are supported */
1289         if (cloned_result)
1290                 handler->set_supported_route_data(cloned_result);
1291
1292         /* Send data to user */
1293         const bool b =
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);
1299         }
1300
1301         return b;
1302 }
1303
1304 /*----------------------------------------------------------------------------*/
1305 /*typedef int (*maps_plugin_cancel_request_f)(maps_service_h maps,
1306 * int request_id); */
1307 int session::command_cancel_request::run()
1308 {
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;
1313         destroy();
1314         return error;
1315 }
1316
1317
1318 /*----------------------------------------------------------------------------*/
1319 /*
1320  *              Mapping API commands
1321  */
1322 /*----------------------------------------------------------------------------*/
1323
1324 session::command_view_set_center::command_view_set_center(maps_service_h ms,
1325                                                            maps_view_h view,
1326                                                 const maps_coordinates_h coords)
1327         : command(ms)
1328         , v(view)
1329         , c(NULL)
1330 {
1331         maps_coordinates_clone(coords, &c);
1332 }
1333
1334 session::command_view_set_center::~command_view_set_center()
1335 {
1336         maps_coordinates_destroy(c);
1337 }
1338
1339 int session::command_view_set_center::run()
1340 {
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",
1345                           lat, lon);
1346         }
1347
1348         if (!v)
1349                 return MAPS_ERROR_INVALID_PARAMETER;
1350
1351         int error = MAPS_ERROR_NONE;
1352         do {
1353                 error = maps_view_set_center(v, c);
1354                 if(error != MAPS_ERROR_NONE)
1355                         break;
1356         } while (false);
1357
1358         const int ret = error;
1359         destroy();
1360         return ret;
1361 }
1362
1363 session::command_type_e session::command_view_set_center::get_type() const
1364 {
1365         return MAPS_VIEW_SET_CENTER_COMMAND;
1366 }
1367
1368 int session::command_view_set_center::get_priority() const
1369 {
1370         return 3;
1371 }
1372
1373 void session::command_view_set_center::merge(const command *c)
1374 {
1375         if (!c || (get_type() != c->get_type())) return;
1376         command_view_set_center *cmd = (command_view_set_center *)c;
1377         if (v == cmd->v) {
1378                 double lat = .0;
1379                 double lon = .0;
1380                 maps_coordinates_get_latitude_longitude(cmd->c, &lat, &lon);
1381                 maps_coordinates_set_latitude_longitude(this->c, lat, lon);
1382                 cmd->set_merged();
1383         }
1384 }
1385
1386
1387 /*----------------------------------------------------------------------------*/
1388
1389
1390 session::command_view_move_center::command_view_move_center(maps_service_h ms,
1391                                                            maps_view_h view,
1392                                                            const int delta_x,
1393                                                            const int delta_y)
1394         : command(ms)
1395         , v(view)
1396         , _delta_x(delta_x)
1397         , _delta_y(delta_y)
1398 {
1399 }
1400
1401 session::command_view_move_center::~command_view_move_center()
1402 {
1403 }
1404
1405 int session::command_view_move_center::run()
1406 {
1407         MAPS_LOGD("session::command_view_move_center::run "
1408                   "delta_x = %d, delta_y = %d",
1409                   _delta_x, _delta_y);
1410
1411         if(!v)
1412                 return MAPS_ERROR_INVALID_PARAMETER;
1413
1414         int error = MAPS_ERROR_NONE;
1415         do {
1416                 error = _maps_view_move_center(v, _delta_x, _delta_y);
1417                 if(error != MAPS_ERROR_NONE)
1418                         break;
1419         } while (false);
1420
1421         const int ret = error;
1422         destroy();
1423         return ret;
1424 }
1425
1426 session::command_type_e session::command_view_move_center::get_type() const
1427 {
1428         return MAPS_VIEW_MOVE_CENTER_COMMAND;
1429 }
1430
1431 int session::command_view_move_center::get_priority() const
1432 {
1433         return 3;
1434 }
1435
1436 void session::command_view_move_center::merge(const command *c)
1437 {
1438         if (!c || (get_type() != c->get_type())) return;
1439         command_view_move_center *cmd = (command_view_move_center *)c;
1440         if (v == cmd->v) {
1441                 _delta_x += cmd->_delta_x;
1442                 _delta_y += cmd->_delta_y;
1443                 cmd->set_merged();
1444         }
1445 }
1446
1447 /*----------------------------------------------------------------------------*/
1448
1449 int session::command_view_zoom::run()
1450 {
1451         MAPS_LOGD("session::command_view_zoom::run factor = %f", zoom_factor);
1452
1453         if (!v)
1454                 return MAPS_ERROR_INVALID_PARAMETER;
1455
1456         const int ret = maps_view_set_zoom_factor(v, zoom_factor);
1457
1458         destroy();
1459         return ret;
1460 }
1461
1462 session::command_type_e session::command_view_zoom::get_type() const
1463 {
1464         return MAPS_VIEW_ZOOM_COMMAND;
1465 }
1466
1467 int session::command_view_zoom::get_priority() const
1468 {
1469         return 2;
1470 }
1471
1472 void session::command_view_zoom::merge(const command *c)
1473 {
1474         if (!c || (get_type() != c->get_type())) return;
1475         command_view_zoom *cmd = (command_view_zoom *)c;
1476         if (v == cmd->v) {
1477                 zoom_factor = cmd->zoom_factor;
1478                 cmd->set_merged();
1479         }
1480 }
1481
1482 /*----------------------------------------------------------------------------*/
1483 int session::command_view_rotate::run()
1484 {
1485         MAPS_LOGD("session::command_view_rotate::run angle = %f",
1486                   rotation_angle);
1487
1488         if (!v)
1489                 return MAPS_ERROR_INVALID_PARAMETER;
1490
1491         const int ret = maps_view_set_orientation(v, rotation_angle);
1492
1493         destroy();
1494         return ret;
1495 }
1496
1497 session::command_type_e session::command_view_rotate::get_type() const
1498 {
1499         return MAPS_VIEW_ROTATE_COMMAND;
1500 }
1501
1502 int session::command_view_rotate::get_priority() const
1503 {
1504         return 2;
1505 }
1506
1507 void session::command_view_rotate::merge(const command *c)
1508 {
1509         if (!c || (get_type() != c->get_type())) return;
1510         command_view_rotate *cmd = (command_view_rotate *)c;
1511         if (v == cmd->v) {
1512                 rotation_angle += cmd->rotation_angle;
1513                 cmd->set_merged();
1514         }
1515 }
1516
1517 /*----------------------------------------------------------------------------*/
1518
1519 int session::command_view_zoom_rotate::run()
1520 {
1521         MAPS_LOGD("session::command_view_zoom_rotate::run "
1522                    "factor = %f, angle = %f",
1523                    zoom_factor, rotation_angle);
1524
1525         if (!v)
1526                 return MAPS_ERROR_INVALID_PARAMETER;
1527
1528         const int ret = _maps_view_set_zoom_rotate(v,
1529                                                   true, zoom_factor,
1530                                                   true, rotation_angle);
1531
1532         destroy();
1533         return ret;
1534 }
1535
1536 session::command_type_e session::command_view_zoom_rotate::get_type() const
1537 {
1538         return MAPS_VIEW_ZOOM_ROTATE_COMMAND;
1539 }
1540
1541 int session::command_view_zoom_rotate::get_priority() const
1542 {
1543         return 2;
1544 }
1545
1546 void session::command_view_zoom_rotate::merge(const command *c)
1547 {
1548         if (!c || (get_type() != c->get_type())) return;
1549         command_view_zoom_rotate *cmd = (command_view_zoom_rotate *)c;
1550         if (v == cmd->v) {
1551                 zoom_factor = cmd->zoom_factor;
1552                 rotation_angle += cmd->rotation_angle;
1553                 cmd->set_merged();
1554         }
1555 }