Add LCOV remarkers to increase line coverage rate
[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; //LCOV_EXCL_LINE
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 //LCOV_EXCL_START
180 session::command_geocode_handler::command_geocode_handler(plugin::plugin_s *p,
181                                                 maps_service_geocode_cb cb,
182                                                 void *ud, int urid)
183  : command_handler(p, ud, urid)
184  , callback(cb)
185 {
186 }
187 //LCOV_EXCL_STOP
188
189 bool session::command_geocode_handler::foreach_geocode_cb(maps_error_e error,
190                                                           int request_id,
191                                                           int index,
192                                                           int total_count,
193                                                           maps_coordinates_h
194                                                           coordinates,
195                                                           void *user_data)
196 {
197         command_geocode_handler *handler = (command_geocode_handler *) user_data;
198
199         if (request_id != handler->plg_req_id) {
200                 //LCOV_EXCL_START
201                 MAPS_LOGE("\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n",
202                         request_id, handler->plg_req_id);
203                 //LCOV_EXCL_STOP
204         }
205
206         /* Make a user's copy of result data */
207         maps_coordinates_h cloned_result = NULL;
208         if (error == MAPS_ERROR_NONE)
209                 error = (maps_error_e) maps_coordinates_clone(coordinates, &cloned_result);
210         maps_coordinates_destroy(coordinates);
211
212         /* Send data to user */
213         const bool b = handler->callback(error, handler->user_req_id, index,
214                 total_count, cloned_result, handler->user_data);
215         if (!b || (index >= (total_count - 1))) {
216                 pending_request pr(handler->plugin());
217                 pr.remove(handler->user_req_id);
218         }
219
220         return b;
221 }
222
223 /*----------------------------------------------------------------------------*/
224 /*typedef int (*maps_plugin_geocode_inside_area_f)(maps_service_h maps, const
225 * char *address, maps_area_h bounds, maps_service_geocode_cb callback,
226 * void *user_data, int *request_id); */
227 session::command_geocode_inside_bounds::command_geocode_inside_bounds(
228                                         maps_service_h ms,
229                                         const char *a,
230                                         const maps_area_h b,
231                                         const maps_item_hashtable_h pref,
232                                         maps_service_geocode_cb cb,
233                                         void *ud, int *request_id)
234  : command(ms)
235  , address(a)
236  , bounds(NULL)
237  , preference(pref)
238  , callback(cb)
239  , user_data(ud)
240  , error(0)
241 {
242         *request_id = command::command_request_id++;
243         my_req_id = *request_id;
244
245         if (maps_area_is_valid(b)) {
246                 bounds = b;
247         } else {
248                 //LCOV_EXCL_START
249                 error = MAPS_ERROR_INVALID_PARAMETER;
250                 *request_id = -1;
251                 //LCOV_EXCL_STOP
252         }
253 }
254
255 session::command_geocode_inside_bounds::~command_geocode_inside_bounds()
256 {
257 }
258
259 int session::command_geocode_inside_bounds::run()
260 {
261         if (error != MAPS_ERROR_NONE) return error;
262
263         pending_request pr(plugin());
264
265         /* Get the plugin interface function */
266         maps_plugin_geocode_inside_area_f func =
267                 interface()->maps_plugin_geocode_inside_area;
268         command_geocode_handler *handler = NULL;
269         if (func) {
270                 /* No need to create the handler when the function is NULL */
271                 pr.add(my_req_id);
272                 handler = new command_geocode_handler(plugin(),
273                                                       callback,
274                                                       user_data,
275                                                       my_req_id);
276
277                 if (handler) {
278                         /* Run the plugin interface function */
279                         error = func(address.c_str(), bounds, preference,
280                                      command_geocode_handler::foreach_geocode_cb,
281                                      handler, &handler->plg_req_id);
282
283                         pr.update(my_req_id, handler);
284
285                         MAPS_LOGD("session::command_geocode_inside_bounds::run: %d", my_req_id);
286                 } else {
287                         error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
288                 }
289         } else {
290                 /* Plugin Function is NULL: use default empty function */
291                 /*
292                 func = plugin::get_empty_interface().
293                         maps_plugin_geocode_inside_area;
294                 */
295                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
296                 error = MAPS_ERROR_NOT_SUPPORTED;
297         }
298
299         const int ret = error;
300         destroy();
301         return ret;
302 }
303
304 /*----------------------------------------------------------------------------*/
305 /*typedef int (*maps_plugin_geocode_by_structured_address_f)(
306 * maps_service_h maps, maps_address_h address, maps_preference_h preference,
307 * maps_service_geocode_cb callback, void *user_data, int *request_id); */
308 session::command_geocode_by_structured_address::
309         command_geocode_by_structured_address(maps_service_h ms,
310                                               const maps_address_h a,
311                                               const maps_item_hashtable_h pref,
312                                               maps_service_geocode_cb cb,
313                                               void *ud, int *request_id)
314  : command(ms)
315  , address(NULL)
316  , preference(pref)
317  , callback(cb)
318  , user_data(ud)
319  , error(0)
320 {
321         *request_id = command::command_request_id++;
322         my_req_id = *request_id;
323
324         if (maps_address_is_valid(a)) {
325                 address = a;
326         } else {
327                 //LCOV_EXCL_START
328                 error = MAPS_ERROR_INVALID_PARAMETER;
329                 *request_id = -1;
330                 MAPS_LOGD("Invalid parameter");
331                 //LCOV_EXCL_STOP
332         }
333 }
334
335 session::command_geocode_by_structured_address::
336         ~command_geocode_by_structured_address()
337 {
338 }
339
340 int session::command_geocode_by_structured_address::run()
341 {
342         if (error != MAPS_ERROR_NONE) return error;
343
344         pending_request pr(plugin());
345
346         /* Get the plugin interface function */
347         maps_plugin_geocode_by_structured_address_f func =
348                 interface()->maps_plugin_geocode_by_structured_address;
349         command_geocode_handler *handler = NULL;
350         if (func) {
351                 /* No need to create the handler when the function is NULL */
352                 pr.add(my_req_id);
353                 handler = new command_geocode_handler(plugin(),
354                                                       callback,
355                                                       user_data,
356                                                       my_req_id);
357
358                 if (handler) {
359                         /* Run the plugin interface function */
360                         error = func(address,
361                                                  preference, command_geocode_handler::foreach_geocode_cb,
362                                                  handler, &handler->plg_req_id);
363
364                         pr.update(my_req_id, handler);
365                 } else {
366                         error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
367                 }
368         } else {
369                 /* Plugin Function is NULL: use default empty function */
370                 /*
371                 func = plugin::get_empty_interface().
372                         maps_plugin_geocode_by_structured_address;
373                 */
374                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
375                 error = MAPS_ERROR_NOT_SUPPORTED;
376         }
377
378         const int ret = error;
379         destroy();
380         return ret;
381 }
382
383 /*----------------------------------------------------------------------------*/
384 /*typedef int (*maps_plugin_reverse_geocode_f)(maps_service_h maps,
385 * double latitude, double longitude, maps_service_reverse_geocode_cb callback,
386 * void *user_data, int *request_id); */
387 session::command_reverse_geocode::command_reverse_geocode(maps_service_h ms,
388                                         double lat, double lon,
389                                         const maps_item_hashtable_h pref,
390                                         maps_service_reverse_geocode_cb cb,
391                                         void *ud, int *request_id)
392  : command(ms)
393  , latitude(lat)
394  , longitude(lon)
395  , preference(pref)
396  , callback(cb)
397  , user_data(ud)
398  , error(0)
399 {
400         *request_id = command::command_request_id++;
401         my_req_id = *request_id;
402 }
403
404 session::command_reverse_geocode::~command_reverse_geocode()
405 {
406 }
407
408 int session::command_reverse_geocode::run()
409 {
410         if (error != MAPS_ERROR_NONE) return error;
411
412         pending_request pr(plugin());
413
414         /* Get the plugin interface function */
415         maps_plugin_reverse_geocode_f func = interface()->maps_plugin_reverse_geocode;
416         command_reverse_geocode_handler *handler = NULL;
417         if (func) {
418                 /* No need to create the handler when the function is NULL */
419                 pr.add(my_req_id);
420                 handler = new command_reverse_geocode_handler(plugin(),
421                                                               callback,
422                                                               user_data,
423                                                               my_req_id);
424
425                 if (handler) {
426                         /* Run the plugin interface function */
427                         error = func(latitude, longitude, preference,
428                                                 command_reverse_geocode_handler::foreach_reverse_geocode_cb,
429                                                 handler, &handler->plg_req_id);
430
431                         pr.update(my_req_id, handler);
432
433                         MAPS_LOGD("session::command_reverse_geocode::run: %d", my_req_id);
434                 } else {
435                         error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
436                 }
437         } else {
438                 /* Plugin Function is NULL: use default empty function */
439                 /*
440                 func = plugin::get_empty_interface().
441                         maps_plugin_reverse_geocode;
442                 */
443                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
444                 error = MAPS_ERROR_NOT_SUPPORTED;
445         }
446
447         const int ret = error;
448         destroy();
449         return ret;
450 }
451
452 //LCOV_EXCL_START
453 session::command_reverse_geocode_handler::command_reverse_geocode_handler(
454                                         plugin::plugin_s *p,
455                                         maps_service_reverse_geocode_cb cb,
456                                         void *ud, int urid)
457  : command_handler(p, ud, urid)
458  , callback(cb)
459 {
460 }
461 //LCOV_EXCL_STOP
462
463 void session::command_reverse_geocode_handler::foreach_reverse_geocode_cb(
464                                                 maps_error_e error,
465                                                 int request_id, int index,
466                                                 int total,
467                                                 maps_address_h address,
468                                                 void *user_data)
469 {
470         command_reverse_geocode_handler *handler =
471                 (command_reverse_geocode_handler *) user_data;
472
473         if (request_id != handler->plg_req_id) {
474                 //LCOV_EXCL_START
475                 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
476                         request_id, handler->plg_req_id);
477                 //LCOV_EXCL_STOP
478         }
479
480         /* Make a user's copy of result data */
481         maps_address_h cloned_result = NULL;
482         if (error == MAPS_ERROR_NONE)
483                 error = (maps_error_e) maps_address_clone(address,
484                         &cloned_result);
485         maps_address_destroy(address);
486
487         /* Send data to user */
488         handler->callback(error, handler->user_req_id, index, total,
489                 cloned_result, handler->user_data);
490         /*if(index>=(total-1)) */
491
492         pending_request pr(handler->plugin());
493         pr.remove(handler->user_req_id);
494 }
495
496 /*----------------------------------------------------------------------------*/
497 /*typedef int (*maps_plugin_multi_reverse_geocode_f) (maps_service_h maps,
498 * maps_coordinates_list_h maps_list, maps_preference_h preference,
499 * maps_service_multi_reverse_geocode_cb callback, void * user_data, int *request_id) */
500 session::command_multi_reverse_geocode::command_multi_reverse_geocode(
501                         maps_service_h ms, const maps_coordinates_list_h list, const maps_item_hashtable_h pref,
502                         maps_service_multi_reverse_geocode_cb cb, void *ud, int *request_id)
503  : command(ms)
504  , maps_list(NULL)
505  , preference(pref)
506  , callback(cb)
507  , user_data(ud)
508  , error(0)
509 {
510         *request_id = command::command_request_id++;
511         my_req_id = *request_id;
512
513         int list_size = 0;
514         maps_coordinates_list_get_length(list, &list_size);
515         if (list_size < 2 || list_size > 100) {
516                 error = MAPS_ERROR_INVALID_PARAMETER;
517                 *request_id = -1;
518         }
519         maps_list = list;
520 }
521
522 session::command_multi_reverse_geocode::~command_multi_reverse_geocode()
523 {
524 }
525
526 int session::command_multi_reverse_geocode::run()
527 {
528         if (error != MAPS_ERROR_NONE) return error;
529
530         pending_request pr(plugin());
531
532         /* Get the plugin interface function */
533         maps_plugin_multi_reverse_geocode_f func =
534                 interface()->maps_plugin_multi_reverse_geocode;
535
536         command_multi_reverse_geocode_handler *handler = NULL;
537         if (func) {
538                 /* No need to create the handler when the function is NULL */
539                 pr.add(my_req_id);
540                 handler = new command_multi_reverse_geocode_handler(plugin(), callback, user_data, my_req_id);
541
542                 if (handler) {
543                         /* Run the plugin interface function */
544                         error = func(maps_list, preference,
545                                                 command_multi_reverse_geocode_handler::foreach_multi_reverse_geocode_cb,
546                                                 handler, &handler->plg_req_id);
547
548                         pr.update(my_req_id, handler);
549
550                         MAPS_LOGD("session::command_multi_reverse_geocode::run: %d", my_req_id);
551                 } else {
552                         error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
553                 }
554         } else {
555                 /* Plugin Function is NULL: use default empty function */
556                 /*
557                 func = plugin::get_empty_interface().
558                         maps_plugin_multi_reverse_geocode;
559                 */
560                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
561                 error = MAPS_ERROR_NOT_SUPPORTED;
562         }
563
564         const int ret = error;
565         destroy();
566         return ret;
567 }
568
569 //LCOV_EXCL_START
570 session::command_multi_reverse_geocode_handler::command_multi_reverse_geocode_handler(
571                         plugin::plugin_s *p, maps_service_multi_reverse_geocode_cb cb, void *ud, int urid)
572  : command_handler(p, ud, urid)
573  , callback(cb)
574 {
575 }
576 //LCOV_EXCL_STOP
577
578 bool session::command_multi_reverse_geocode_handler::foreach_multi_reverse_geocode_cb(
579                         maps_error_e error, int request_id, int total, maps_coordinates_list_h address_list, void *user_data)
580 {
581         command_multi_reverse_geocode_handler *handler =
582                 (command_multi_reverse_geocode_handler *) user_data;
583
584         if (request_id != handler->plg_req_id) {
585                 //LCOV_EXCL_START
586                 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
587                         request_id, handler->plg_req_id);
588                 //LCOV_EXCL_STOP
589         }
590
591         /* Make a user's copy of result data */
592         maps_coordinates_list_h cloned_result = NULL;
593         cloned_result = address_list;
594
595         /* Send data to user */
596         const bool b = handler->callback(error, handler->user_req_id, total, cloned_result, handler->user_data);
597         /*if(index>=(total-1)) */
598
599         pending_request pr(handler->plugin());
600         pr.remove(handler->user_req_id);
601
602         return b;
603 }
604
605 /*----------------------------------------------------------------------------*/
606 /*typedef int (*maps_plugin_search_place_f)(maps_service_h maps,
607 * maps_coordinates_h position, int distance, maps_item_hashtable_h preference,
608 * maps_place_filter_h filter, maps_service_search_place_cb callback,
609 * void* user_data, int* request_id); */
610 session::command_search_place::command_search_place(maps_service_h ms,
611                                         const maps_coordinates_h pos,
612                                         int dst,
613                                         const maps_item_hashtable_h pref,
614                                         const maps_place_filter_h flt,
615                                         maps_service_search_place_cb cb,
616                                         void *ud, int *request_id)
617  : command(ms)
618  , position(NULL)
619  , distance(dst)
620  , preference(pref)
621  , filter(flt)
622  , callback(cb)
623  , user_data(ud)
624  , error(MAPS_ERROR_NONE)
625 {
626         *request_id = command::command_request_id++;
627         my_req_id = *request_id;
628
629         if (maps_coordinates_is_valid(pos)) {
630                 position = pos;
631         } else {
632                 //LCOV_EXCL_START
633                 error = MAPS_ERROR_INVALID_PARAMETER;
634                 *request_id = -1;
635                 MAPS_LOGD("Invalid parameter");
636                 //LCOV_EXCL_STOP
637         }
638 }
639
640 session::command_search_place::~command_search_place()
641 {
642 }
643
644 int session::command_search_place::run()
645 {
646         if (error != MAPS_ERROR_NONE) return error;
647
648         pending_request pr(plugin());
649
650         /* Get the plugin interface function */
651         maps_plugin_search_place_f func = interface()->maps_plugin_search_place;
652         command_search_place_handler *handler = NULL;
653         if (func) {
654                 /* No need to create the handler when the function is NULL */
655                 pr.add(my_req_id);
656                 handler = new command_search_place_handler(plugin(),
657                                                            callback,
658                                                            user_data,
659                                                            my_req_id);
660                 if (handler) {
661                         /* Run the plugin interface function */
662                         error = func(position, distance, filter, preference,
663                                          command_search_place_handler::foreach_place_cb, handler,
664                                          &handler->plg_req_id);
665
666                         pr.update(my_req_id, handler);
667
668                         MAPS_LOGD("session::command_search_place::run: %d", my_req_id);
669                 } else {
670                         error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
671                 }
672         } else {
673                 /* Plugin Function is NULL: use default empty function */
674                 /*
675                 func = plugin::get_empty_interface().maps_plugin_search_place;
676                 */
677                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
678                 error = MAPS_ERROR_NOT_SUPPORTED;
679         }
680
681         const int ret = error;
682         destroy();
683         return ret;
684 }
685
686 //LCOV_EXCL_START
687 session::command_search_place_handler::command_search_place_handler(
688                                                 plugin::plugin_s* p,
689                                                 maps_service_search_place_cb cb,
690                                                 void *ud, int urid)
691  : command_handler(p, ud, urid)
692  , callback(cb)
693 {
694 }
695 //LCOV_EXCL_STOP
696
697 bool session::command_search_place_handler::foreach_place_cb(maps_error_e error,
698                                                              int request_id,
699                                                              int index,
700                                                              int length,
701                                                              maps_place_h place,
702                                                              void *user_data)
703 {
704         command_search_place_handler *handler =
705                 (command_search_place_handler *) user_data;
706
707         if (request_id != handler->plg_req_id) {
708         //LCOV_EXCL_START
709                 MAPS_LOGE("\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n",
710                         request_id, handler->plg_req_id);
711         //LCOV_EXCL_STOP
712         }
713
714         /* Make a user's copy of result data */
715         maps_place_h cloned_result = NULL;
716         if (error == MAPS_ERROR_NONE)
717                 error = (maps_error_e) maps_place_clone(place, &cloned_result);
718         maps_place_destroy(place);
719
720         /* Check which data features are supported */
721         if (cloned_result)
722                 handler->set_supported_place_data(cloned_result);
723
724         /* Send data to user */
725         const bool b = handler->callback(error, handler->user_req_id, index, length,
726                 cloned_result, handler->user_data);
727         if (!b || (index >= (length - 1))) {
728                 pending_request pr(handler->plugin());
729                 pr.remove(handler->user_req_id);
730         }
731
732         return b;
733 }
734
735 /*----------------------------------------------------------------------------*/
736 /*typedef int (*maps_plugin_search_place_by_area_f)(maps_service_h maps,
737 * maps_area_h boundary , maps_item_hashtable_h preference,
738 * maps_place_filter_h filter, maps_service_search_place_cb callback,
739 * void *user_data, int *request_id); */
740 session::command_search_by_area_place::command_search_by_area_place(
741                                         maps_service_h ms, const maps_area_h b,
742                                         const maps_item_hashtable_h pref,
743                                         const maps_place_filter_h flt,
744                                         maps_service_search_place_cb cb,
745                                         void *ud, int *request_id)
746  : command(ms)
747  , boundary(NULL)
748  , preference(pref)
749  , filter(flt)
750  , callback(cb)
751  , user_data(ud)
752  , error(MAPS_ERROR_NONE)
753 {
754         *request_id = command::command_request_id++;
755         my_req_id = *request_id;
756
757         if (maps_area_is_valid(b)) {
758                 boundary = b;
759         } else {
760                 //LCOV_EXCL_START
761                 error = MAPS_ERROR_INVALID_PARAMETER;
762                 *request_id = -1;
763                 //LCOV_EXCL_STOP
764         }
765 }
766
767 session::command_search_by_area_place::~command_search_by_area_place()
768 {
769 }
770
771 int session::command_search_by_area_place::run()
772 {
773         if (error != MAPS_ERROR_NONE) return error;
774
775         pending_request pr(plugin());
776
777         /* Get the plugin interface function */
778         maps_plugin_search_place_by_area_f func =
779                 interface()->maps_plugin_search_place_by_area;
780         command_search_place_handler *handler = NULL;
781         if (func) {
782                 /* No need to create the handler when the function is NULL */
783                 pr.add(my_req_id);
784                 handler = new command_search_place_handler(plugin(),
785                                                            callback,
786                                                            user_data,
787                                                            my_req_id);
788                 if (handler) {
789                         /* Run the plugin interface function */
790                         error = func(boundary, filter,
791                                 preference, command_search_place_handler::foreach_place_cb,
792                                 handler, &handler->plg_req_id);
793
794                         pr.update(my_req_id, handler);
795
796                         MAPS_LOGD("session::command_search_by_area_place::run: %d", my_req_id);
797                 } else {
798                         error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
799                 }
800         } else {
801                 /* Plugin Function is NULL: use default empty function */
802                 /*
803                 func = plugin::get_empty_interface().
804                         maps_plugin_search_place_by_area;
805                 */
806
807                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
808                 error = MAPS_ERROR_NOT_SUPPORTED;
809         }
810
811         const int ret = error;
812         destroy();
813         return ret;
814 }
815
816 /*----------------------------------------------------------------------------*/
817 /*typedef int (*maps_plugin_search_place_by_address_f)(maps_service_h maps,
818 * const char *address, maps_area_h boundary, maps_item_hashtable_h preference,
819 * maps_place_filter_h filter, maps_service_search_place_cb callback,
820 * void *user_data, int *request_id); */
821 session::command_search_by_address_place::command_search_by_address_place(
822                                         maps_service_h ms, const char *a,
823                                         const maps_area_h b,
824                                         const maps_item_hashtable_h pref,
825                                         const maps_place_filter_h flt,
826                                         maps_service_search_place_cb cb,
827                                         void *ud, int *request_id)
828  : command(ms)
829  , address(a)
830  , boundary(NULL)
831  , preference(pref)
832  , filter(flt)
833  , callback(cb)
834  , user_data(ud)
835  , error(MAPS_ERROR_NONE)
836 {
837         *request_id = command::command_request_id++;
838         my_req_id = *request_id;
839
840         if (maps_area_is_valid(b)) {
841                 boundary = b;
842         } else {
843                 //LCOV_EXCL_START
844                 error = MAPS_ERROR_INVALID_PARAMETER;
845                 *request_id = -1;
846                 MAPS_LOGD("Invalid parameter");
847                 //LCOV_EXCL_STOP
848         }
849 }
850
851 session::command_search_by_address_place::~command_search_by_address_place()
852 {
853 }
854
855 int session::command_search_by_address_place::run()
856 {
857         if (error != MAPS_ERROR_NONE)
858                 return error;
859
860         pending_request pr(plugin());
861
862         /* Get the plugin interface function */
863         maps_plugin_search_place_by_address_f func =
864                 interface()->maps_plugin_search_place_by_address;
865         command_search_place_handler *handler = NULL;
866         if (func) {
867                 /* No need to create the handler when the function is NULL */
868                 pr.add(my_req_id);
869                 handler = new command_search_place_handler(plugin(),
870                                                            callback,
871                                                            user_data,
872                                                            my_req_id);
873                 if (handler) {
874                         /* Run the plugin interface function */
875                         error = func(address.c_str(), boundary, filter, preference,
876                                          command_search_place_handler::foreach_place_cb, handler,
877                                          &handler->plg_req_id);
878
879                         pr.update(my_req_id, handler);
880
881                         MAPS_LOGD("session::command_search_by_address_place::run: %d", my_req_id);
882                 } else {
883                         error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
884                 }
885         } else {
886                 /* Plugin Function is NULL: use default empty function */
887                 /*
888                 func = plugin::get_empty_interface().
889                         maps_plugin_search_place_by_address;
890                 */
891                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
892                 error = MAPS_ERROR_NOT_SUPPORTED;
893         }
894
895         const int ret = error;
896         destroy();
897         return ret;
898 }
899
900 /*----------------------------------------------------------------------------*/
901 /*typedef int (*maps_plugin_search_place_list_f)(maps_service_h maps,
902 * maps_item_hashtable_h preference, maps_place_filter_h filter,
903 * maps_service_search_place_list_cb callback, void* user_data, int* request_id); */
904 session::command_search_place_list::command_search_place_list(maps_service_h ms,
905                                         const maps_area_h b,
906                                         const maps_item_hashtable_h pref,
907                                         const maps_place_filter_h flt,
908                                         maps_service_search_place_list_cb cb,
909                                         void *ud, int *request_id)
910  : command(ms)
911  , boundary(NULL)
912  , preference(pref)
913  , filter(flt)
914  , callback(cb)
915  , user_data(ud)
916  , error(MAPS_ERROR_NONE)
917 {
918         *request_id = command::command_request_id++;
919         my_req_id = *request_id;
920
921         if (maps_area_is_valid(b)) {
922                 boundary = b;
923         } else {
924                 //LCOV_EXCL_START
925                 error = MAPS_ERROR_INVALID_PARAMETER;
926                 *request_id = -1;
927                 MAPS_LOGD("Invalid parameter");
928                 //LCOV_EXCL_STOP
929         }
930 }
931
932 session::command_search_place_list::~command_search_place_list()
933 {
934 }
935
936 int session::command_search_place_list::run()
937 {
938         if (error != MAPS_ERROR_NONE)
939                 return error;
940
941         pending_request pr(plugin());
942
943         /* Get the plugin interface function */
944         maps_plugin_search_place_list_f func = interface()->maps_plugin_search_place_list;
945         command_search_place_list_handler *handler = NULL;
946         if (func) {
947                 /* No need to create the handler when the function is NULL */
948                 pr.add(my_req_id);
949                 handler = new command_search_place_list_handler(plugin(),
950                                                            callback,
951                                                            user_data,
952                                                            my_req_id);
953                 if (handler) {
954                         /* Run the plugin interface function */
955                         error = func(boundary, filter, preference,
956                                          command_search_place_list_handler::foreach_place_list_cb, handler,
957                                          &handler->plg_req_id);
958
959                         pr.update(my_req_id, handler);
960
961                         MAPS_LOGD("session::command_search_place_list::run: %d", my_req_id);
962                 } else {
963                         error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
964                 }
965         } else {
966                 /* Plugin Function is NULL: use default empty function */
967                 /*
968                 func = plugin::get_empty_interface().maps_plugin_search_place_list;
969                 */
970                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
971                 error = MAPS_ERROR_NOT_SUPPORTED;
972         }
973
974         const int ret = error;
975         destroy();
976         return ret;
977 }
978
979 //LCOV_EXCL_START
980 session::command_search_place_list_handler::command_search_place_list_handler(
981                                                 plugin::plugin_s* p,
982                                                 maps_service_search_place_list_cb cb,
983                                                 void *ud, int urid)
984  : command_handler(p, ud, urid)
985  , callback(cb)
986 {
987 }
988 //LCOV_EXCL_STOP
989
990 void session::command_search_place_list_handler::foreach_place_list_cb(maps_error_e error,
991                                                              int request_id,
992                                                                  int total,
993                                                              maps_place_list_h place_list,
994                                                              void *user_data)
995 {
996         command_search_place_list_handler *handler =
997                 (command_search_place_list_handler *) user_data;
998
999         if (request_id != handler->plg_req_id) {
1000                 //LCOV_EXCL_START
1001                 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
1002                         request_id, handler->plg_req_id);
1003                 //LCOV_EXCL_STOP
1004         }
1005
1006         /* Check which data features are supported */
1007         if (place_list)
1008                 handler->set_supported_place_list_data(place_list);
1009
1010         /* Send data to user */
1011         handler->callback(error, handler->user_req_id, total, place_list, handler->user_data);
1012
1013         pending_request pr(handler->plugin());
1014         pr.remove(handler->user_req_id);
1015 }
1016
1017 /*----------------------------------------------------------------------------*/
1018 /*typedef int (*maps_plugin_get_place_details_f) */
1019 session::command_get_place_details::command_get_place_details(
1020                                         maps_service_h ms, const char *a,
1021                                         maps_service_get_place_details_cb cb,
1022                                         void *ud, int *request_id)
1023  : command(ms)
1024  , url(a)
1025  , callback(cb)
1026  , user_data(ud)
1027  , error(MAPS_ERROR_NONE)
1028 {
1029         *request_id = command::command_request_id++;
1030         my_req_id = *request_id;
1031 }
1032
1033 session::command_get_place_details::~command_get_place_details()
1034 {
1035 }
1036
1037 int session::command_get_place_details::run()
1038 {
1039         if (error != MAPS_ERROR_NONE)
1040                 return error;
1041
1042         pending_request pr(plugin());
1043
1044         /* Get the plugin interface function */
1045         maps_plugin_get_place_details_f func =
1046                 interface()->maps_plugin_get_place_details;
1047         command_get_place_details_handler *handler = NULL;
1048         if (func) {
1049                 /* No need to create the handler when the function is NULL */
1050                 pr.add(my_req_id);
1051                 handler = new command_get_place_details_handler(plugin(),
1052                                                            callback, user_data, my_req_id);
1053                 if (handler) {
1054                         /* Run the plugin interface function */
1055                         error = func(url.c_str(),
1056                                          command_get_place_details_handler::foreach_place_details_cb,
1057                                          handler, &handler->plg_req_id);
1058
1059                         pr.update(my_req_id, handler);
1060
1061                         MAPS_LOGD("session::command_get_place_details::run: %d",
1062                                 my_req_id);
1063                 } else {
1064                         error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
1065                 }
1066         } else {
1067                 /* Plugin Function is NULL: use default empty function */
1068                 /*
1069                 func = plugin::get_empty_interface().
1070                         maps_plugin_get_place_details;
1071                 */
1072                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
1073                 error = MAPS_ERROR_NOT_SUPPORTED;
1074         }
1075
1076         const int ret = error;
1077         destroy();
1078         return ret;
1079 }
1080
1081 //LCOV_EXCL_START
1082 session::command_get_place_details_handler::command_get_place_details_handler(
1083                                                 plugin::plugin_s* p,
1084                                                 maps_service_get_place_details_cb cb,
1085                                                 void *ud, int urid)
1086  : command_handler(p, ud, urid)
1087  , callback(cb)
1088 {
1089 }
1090 //LCOV_EXCL_STOP
1091
1092 void session::command_get_place_details_handler::foreach_place_details_cb(maps_error_e error,
1093                                                              int request_id, maps_place_h place, void *user_data)
1094 {
1095         command_get_place_details_handler *handler =
1096                 (command_get_place_details_handler *) user_data;
1097
1098         if (request_id != handler->plg_req_id) {
1099                 //LCOV_EXCL_START
1100                 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
1101                         request_id, handler->plg_req_id);
1102                 //LCOV_EXCL_STOP
1103         }
1104
1105         /* Make a user's copy of result data */
1106         maps_place_h cloned_result = NULL;
1107         if (error == MAPS_ERROR_NONE)
1108                 error = (maps_error_e) maps_place_clone(place, &cloned_result);
1109         maps_place_destroy(place);
1110
1111         /* Check which data features are supported */
1112         if (cloned_result)
1113                 handler->set_supported_place_data(cloned_result);
1114
1115         /* Send data to user */
1116         handler->callback(error, handler->user_req_id, cloned_result, handler->user_data);
1117
1118         pending_request pr(handler->plugin());
1119         pr.remove(handler->user_req_id);
1120 }
1121
1122 /*----------------------------------------------------------------------------*/
1123 /*typedef int (*maps_plugin_search_route_f)(maps_service_h maps,
1124 * maps_item_hashtable_h preference, maps_coordinates_h origin,
1125 * maps_coordinates_h destination, maps_service_search_route_cb callback,
1126 * void *user_data, int *request_id); */
1127 session::command_search_route::command_search_route(maps_service_h ms,
1128                                         const maps_item_hashtable_h pref,
1129                                         const maps_coordinates_h orig,
1130                                         const maps_coordinates_h dest,
1131                                         maps_service_search_route_cb cb,
1132                                         void *ud, int *request_id)
1133  : command(ms)
1134  , preference(pref)
1135  , origin(NULL)
1136  , destination(NULL)
1137  , callback(cb)
1138  , user_data(ud)
1139  , error(MAPS_ERROR_NONE)
1140 {
1141         *request_id = command::command_request_id++;
1142         my_req_id = *request_id;
1143
1144         if (maps_coordinates_is_valid(orig)) {
1145                 origin = orig;
1146         } else {
1147                 error = MAPS_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1148         }
1149
1150         if (maps_coordinates_is_valid(dest)) {
1151                 destination = dest;
1152         } else {
1153                 error = MAPS_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1154         }
1155
1156         if (error) {
1157                 //LCOV_EXCL_START
1158                 *request_id = -1;
1159                 MAPS_LOGD("Invalid parameter");
1160                 //LCOV_EXCL_STOP
1161         }
1162 }
1163
1164 session::command_search_route::~command_search_route()
1165 {
1166 }
1167
1168 int session::command_search_route::run()
1169 {
1170         if (error != MAPS_ERROR_NONE) return error;
1171
1172         pending_request pr(plugin());
1173
1174         /* Get the plugin interface function */
1175         maps_plugin_search_route_f func = interface()->maps_plugin_search_route;
1176         command_search_route_handler *handler = NULL;
1177         if (func) {
1178                 /* No need to create the handler when the function is NULL */
1179                 pr.add(my_req_id);
1180                 handler = new command_search_route_handler(plugin(),
1181                                                         callback, user_data, my_req_id);
1182
1183                 if (handler) {
1184                         /* Run the plugin interface function */
1185                         error = func(origin, destination, preference,
1186                                                         command_search_route_handler::foreach_route_cb,
1187                                                         handler, &handler->plg_req_id);
1188
1189                         pr.update(my_req_id, handler);
1190
1191                         MAPS_LOGD("session::command_search_route::run: %d", my_req_id);
1192                 } else {
1193                         error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
1194                 }
1195         } else {
1196                 /* Plugin Function is NULL: use default empty function */
1197                 /*
1198                 func = plugin::get_empty_interface().maps_plugin_search_route;
1199                 */
1200                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
1201                 error = MAPS_ERROR_NOT_SUPPORTED;
1202         }
1203
1204         const int ret = error;
1205         destroy();
1206         return ret;
1207 }
1208
1209 /*----------------------------------------------------------------------------*/
1210 /*typedef int (*maps_plugin_search_route_waypoints_f)(maps_service_h maps,
1211 * maps_item_hashtable_h preference, maps_coordinates_h *waypoint_list,
1212 * int waypoint_num, maps_service_search_route_cb callback, void *user_data,
1213 * int *request_id); */
1214 session::command_search_route_waypoints::command_search_route_waypoints(
1215                                 maps_service_h ms,
1216                                 const maps_item_hashtable_h pref,
1217                                 const maps_coordinates_h *list,
1218                                 int num, maps_service_search_route_cb cb,
1219                                 void *ud, int *request_id)
1220  : command(ms)
1221  , preference(pref)
1222  , waypoint_list(NULL)
1223  , waypoint_num(num)
1224  , callback(cb)
1225  , user_data(ud)
1226  , error(MAPS_ERROR_NONE)
1227 {
1228         *request_id = command::command_request_id++;
1229         my_req_id = *request_id;
1230
1231         waypoint_list = new maps_coordinates_h[num];
1232         for (int index = 0; index < num; index++) {
1233                 if (list[index] != NULL) {
1234                         maps_coordinates_clone(list[index],
1235                                 &waypoint_list[index]);
1236                 }
1237         }
1238 }
1239
1240 session::command_search_route_waypoints::~command_search_route_waypoints()
1241 {
1242         for (int index = 0; index < waypoint_num; index++) {
1243                 if (waypoint_list[index] != NULL) {
1244                         maps_coordinates_destroy(waypoint_list[index]);
1245                 }
1246         }
1247         delete [] waypoint_list;
1248 }
1249
1250 int session::command_search_route_waypoints::run()
1251 {
1252         if (error != MAPS_ERROR_NONE)
1253                 return error;
1254
1255         pending_request pr(plugin());
1256
1257         /* Get the plugin interface function */
1258         maps_plugin_search_route_waypoints_f func =
1259                 interface()->maps_plugin_search_route_waypoints;
1260
1261         command_search_route_handler *handler = NULL;
1262         if (func) {
1263                 /* No need to create the handler when the function is NULL */
1264                 pr.add(my_req_id);
1265                 handler = new command_search_route_handler(plugin(),
1266                                                  callback,
1267                                                  user_data,
1268                                                  my_req_id);
1269                 if (handler) {
1270                         /* Run the plugin interface function */
1271                         error = func(waypoint_list, waypoint_num, preference,
1272                                          command_search_route_handler::foreach_route_cb, handler,
1273                                          &handler->plg_req_id);
1274
1275                         pr.update(my_req_id, handler);
1276
1277                         MAPS_LOGD("session::command_search_place::run: %d", my_req_id);
1278                 } else {
1279                         error = MAPS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
1280                 }
1281         } else {
1282                 /* Plugin Function is NULL: use default empty function */
1283                 /*
1284                 func = plugin::get_empty_interface().
1285                         maps_plugin_search_route_waypoints;
1286                 */
1287                 MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin");
1288                 error = MAPS_ERROR_NOT_SUPPORTED;
1289         }
1290
1291         const int ret = error;
1292         destroy();
1293         return ret;
1294 }
1295
1296 //LCOV_EXCL_START
1297 session::command_search_route_handler::command_search_route_handler(
1298                                                 plugin::plugin_s *p,
1299                                                 maps_service_search_route_cb cb,
1300                                                 void *ud, int urid)
1301  : command_handler(p, ud, urid)
1302  , callback(cb)
1303 {
1304 }
1305 //LCOV_EXCL_STOP
1306
1307 bool session::command_search_route_handler::foreach_route_cb(maps_error_e error,
1308                                                              int request_id,
1309                                                              int index,
1310                                                              int length,
1311                                                              maps_route_h route,
1312                                                              void *user_data)
1313 {
1314         command_search_route_handler *handler =
1315                 (command_search_route_handler *) user_data;
1316
1317         if (request_id != handler->plg_req_id) {
1318                 //LCOV_EXCL_START
1319                 MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n",
1320                         request_id, handler->plg_req_id);
1321                 //LCOV_EXCL_STOP
1322         }
1323
1324         /* Make a user's copy of result data */
1325         maps_route_h cloned_result = NULL;
1326         if (error == MAPS_ERROR_NONE)
1327                 error = (maps_error_e) maps_route_clone(route, &cloned_result);
1328         maps_route_destroy(route);
1329
1330         /* Check which data features are supported */
1331         if (cloned_result)
1332                 handler->set_supported_route_data(cloned_result);
1333
1334         /* Send data to user */
1335         const bool b =
1336                 handler->callback(error, handler->user_req_id, index, length,
1337                                                         cloned_result, handler->user_data);
1338         if (!b || (index >= (length - 1))) {
1339                 pending_request pr(handler->plugin());
1340                 pr.remove(handler->user_req_id);
1341         }
1342
1343         return b;
1344 }
1345
1346 /*----------------------------------------------------------------------------*/
1347 /*typedef int (*maps_plugin_cancel_request_f)(maps_service_h maps,
1348 * int request_id); */
1349 int session::command_cancel_request::run()
1350 {
1351         pending_request pr(plugin());
1352         MAPS_LOGD("session::command_cancel_request::run: %d, %p", request_id, pr.look_up(request_id));
1353         const int error = (pr.contains(request_id)) ?
1354                 interface()->maps_plugin_cancel_request(pr.extract_plg_id(request_id)) : MAPS_ERROR_NOT_FOUND;
1355         destroy();
1356         return error;
1357 }
1358
1359
1360 /*----------------------------------------------------------------------------*/
1361 /*
1362  *              Mapping API commands
1363  */
1364 /*----------------------------------------------------------------------------*/
1365 //LCOV_EXCL_START
1366
1367 session::command_view_set_center::command_view_set_center(maps_service_h ms,
1368                                                            maps_view_h view,
1369                                                 const maps_coordinates_h coords)
1370         : command(ms)
1371         , v(view)
1372         , c(NULL)
1373 {
1374         maps_coordinates_clone(coords, &c);
1375 }
1376
1377 session::command_view_set_center::~command_view_set_center()
1378 {
1379         maps_coordinates_destroy(c);
1380 }
1381
1382 int session::command_view_set_center::run()
1383 {
1384         { /* TODO: remove it in release */
1385                 double lat = 0, lon = 0;
1386                 maps_coordinates_get_latitude_longitude(c, &lat, &lon);
1387                 MAPS_LOGD("session::command_view_set_center::run lat,lon=%f,%f",
1388                           lat, lon);
1389         }
1390
1391         if (!v)
1392                 return MAPS_ERROR_INVALID_PARAMETER;
1393
1394         int error = MAPS_ERROR_NONE;
1395         do {
1396                 error = maps_view_set_center(v, c);
1397                 if(error != MAPS_ERROR_NONE)
1398                         break;
1399         } while (false);
1400
1401         const int ret = error;
1402         destroy();
1403         return ret;
1404 }
1405
1406 session::command_type_e session::command_view_set_center::get_type() const
1407 {
1408         return MAPS_VIEW_SET_CENTER_COMMAND;
1409 }
1410
1411 int session::command_view_set_center::get_priority() const
1412 {
1413         return 3;
1414 }
1415
1416 void session::command_view_set_center::merge(const command *c)
1417 {
1418         if (!c || (get_type() != c->get_type())) return;
1419         command_view_set_center *cmd = (command_view_set_center *)c;
1420         if (v == cmd->v) {
1421                 double lat = .0;
1422                 double lon = .0;
1423                 maps_coordinates_get_latitude_longitude(cmd->c, &lat, &lon);
1424                 maps_coordinates_set_latitude_longitude(this->c, lat, lon);
1425                 cmd->set_merged();
1426         }
1427 }
1428
1429
1430 /*----------------------------------------------------------------------------*/
1431
1432
1433 session::command_view_move_center::command_view_move_center(maps_service_h ms,
1434                                                            maps_view_h view,
1435                                                            const int delta_x,
1436                                                            const int delta_y)
1437         : command(ms)
1438         , v(view)
1439         , _delta_x(delta_x)
1440         , _delta_y(delta_y)
1441 {
1442 }
1443
1444 session::command_view_move_center::~command_view_move_center()
1445 {
1446 }
1447
1448 int session::command_view_move_center::run()
1449 {
1450         MAPS_LOGD("session::command_view_move_center::run "
1451                   "delta_x = %d, delta_y = %d",
1452                   _delta_x, _delta_y);
1453
1454         if(!v)
1455                 return MAPS_ERROR_INVALID_PARAMETER;
1456
1457         int error = MAPS_ERROR_NONE;
1458         do {
1459                 error = _maps_view_move_center(v, _delta_x, _delta_y);
1460                 if(error != MAPS_ERROR_NONE)
1461                         break;
1462         } while (false);
1463
1464         const int ret = error;
1465         destroy();
1466         return ret;
1467 }
1468
1469 session::command_type_e session::command_view_move_center::get_type() const
1470 {
1471         return MAPS_VIEW_MOVE_CENTER_COMMAND;
1472 }
1473
1474 int session::command_view_move_center::get_priority() const
1475 {
1476         return 3;
1477 }
1478
1479 void session::command_view_move_center::merge(const command *c)
1480 {
1481         if (!c || (get_type() != c->get_type())) return;
1482         command_view_move_center *cmd = (command_view_move_center *)c;
1483         if (v == cmd->v) {
1484                 _delta_x += cmd->_delta_x;
1485                 _delta_y += cmd->_delta_y;
1486                 cmd->set_merged();
1487         }
1488 }
1489
1490 /*----------------------------------------------------------------------------*/
1491
1492 int session::command_view_zoom::run()
1493 {
1494         MAPS_LOGD("session::command_view_zoom::run factor = %f", zoom_factor);
1495
1496         if (!v)
1497                 return MAPS_ERROR_INVALID_PARAMETER;
1498
1499         const int ret = maps_view_set_zoom_factor(v, zoom_factor);
1500
1501         destroy();
1502         return ret;
1503 }
1504
1505 session::command_type_e session::command_view_zoom::get_type() const
1506 {
1507         return MAPS_VIEW_ZOOM_COMMAND;
1508 }
1509
1510 int session::command_view_zoom::get_priority() const
1511 {
1512         return 2;
1513 }
1514
1515 void session::command_view_zoom::merge(const command *c)
1516 {
1517         if (!c || (get_type() != c->get_type())) return;
1518         command_view_zoom *cmd = (command_view_zoom *)c;
1519         if (v == cmd->v) {
1520                 zoom_factor = cmd->zoom_factor;
1521                 cmd->set_merged();
1522         }
1523 }
1524
1525 /*----------------------------------------------------------------------------*/
1526 int session::command_view_rotate::run()
1527 {
1528         MAPS_LOGD("session::command_view_rotate::run angle = %f",
1529                   rotation_angle);
1530
1531         if (!v)
1532                 return MAPS_ERROR_INVALID_PARAMETER;
1533
1534         const int ret = maps_view_set_orientation(v, rotation_angle);
1535
1536         destroy();
1537         return ret;
1538 }
1539
1540 session::command_type_e session::command_view_rotate::get_type() const
1541 {
1542         return MAPS_VIEW_ROTATE_COMMAND;
1543 }
1544
1545 int session::command_view_rotate::get_priority() const
1546 {
1547         return 2;
1548 }
1549
1550 void session::command_view_rotate::merge(const command *c)
1551 {
1552         if (!c || (get_type() != c->get_type())) return;
1553         command_view_rotate *cmd = (command_view_rotate *)c;
1554         if (v == cmd->v) {
1555                 rotation_angle += cmd->rotation_angle;
1556                 cmd->set_merged();
1557         }
1558 }
1559
1560 /*----------------------------------------------------------------------------*/
1561
1562 int session::command_view_zoom_rotate::run()
1563 {
1564         MAPS_LOGD("session::command_view_zoom_rotate::run "
1565                    "factor = %f, angle = %f",
1566                    zoom_factor, rotation_angle);
1567
1568         if (!v)
1569                 return MAPS_ERROR_INVALID_PARAMETER;
1570
1571         const int ret = _maps_view_set_zoom_rotate(v,
1572                                                   true, zoom_factor,
1573                                                   true, rotation_angle);
1574
1575         destroy();
1576         return ret;
1577 }
1578
1579 session::command_type_e session::command_view_zoom_rotate::get_type() const
1580 {
1581         return MAPS_VIEW_ZOOM_ROTATE_COMMAND;
1582 }
1583
1584 int session::command_view_zoom_rotate::get_priority() const
1585 {
1586         return 2;
1587 }
1588
1589 void session::command_view_zoom_rotate::merge(const command *c)
1590 {
1591         if (!c || (get_type() != c->get_type())) return;
1592         command_view_zoom_rotate *cmd = (command_view_zoom_rotate *)c;
1593         if (v == cmd->v) {
1594                 zoom_factor = cmd->zoom_factor;
1595                 rotation_angle += cmd->rotation_angle;
1596                 cmd->set_merged();
1597         }
1598 }
1599 //LCOV_EXCL_STOP