Tizen C++ Coding Rules
[platform/core/location/maps-plugin-here.git] / src / here_api.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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 "here_api.h"
18 #include "here_types.h"
19 #include "here_geocode.h"
20 #include "here_revgeocode.h"
21 #include "here_multirevgeocode.h"
22 #include "here_place.h"
23 #include "here_route.h"
24 #include "here_view.h"
25 #include <common/HereConfig.h>
26
27 using namespace HERE_PLUGIN_NAMESPACE_PREFIX;
28
29 int HerePluginInit(maps_plugin_h *hPlugin, const char *module)
30 {
31         if (!hPlugin)
32                 return HERE_ERROR_INVALID_PARAMETER;
33
34         here_error_e error = HereManager::CheckAgreement();
35         if (error != HERE_ERROR_NONE)
36                 return error;
37
38         HereManager::Create();
39
40         if (!HereManager::GetHandler())
41                 return HERE_ERROR_INVALID_OPERATION;
42
43         HereManager::GetHandler()->SetProxyAddress();
44
45         return HERE_ERROR_NONE;
46 }
47
48 int HerePluginShutdown(maps_plugin_h hPlugin)
49 {
50         if (!hPlugin)
51                 return HERE_ERROR_INVALID_PARAMETER;
52
53         if (HereManager::GetHandler())
54                 HereManager::GetHandler()->Close();
55
56         return HERE_ERROR_NONE;
57 }
58
59 int HerePluginSetProviderKey(const char* szKey)
60 {
61         if (!szKey)
62                 return HERE_ERROR_INVALID_PARAMETER;
63
64         if (!HereManager::GetHandler())
65                 return HERE_ERROR_INVALID_OPERATION;
66
67         return HereManager::GetHandler()->SetCredentials(szKey);
68 }
69
70 int HerePluginGetProviderKey(char** szKey)
71 {
72         if (!szKey)
73                 return HERE_ERROR_INVALID_PARAMETER;
74
75         if (!HereManager::GetHandler())
76                 return HERE_ERROR_INVALID_OPERATION;
77
78         return HereManager::GetHandler()->GetCredentials(szKey);
79 }
80
81 int HerePluginSetPreference(maps_preference_h hPref)
82 {
83         if (!hPref)
84                 return HERE_ERROR_INVALID_PARAMETER;
85
86         if (!HereManager::GetHandler())
87                 return HERE_ERROR_INVALID_OPERATION;
88
89         return HereManager::GetHandler()->SetPreference(hPref);
90 }
91
92 int HerePluginGetPreference(maps_preference_h *hPref)
93 {
94         if (!hPref)
95                 return HERE_ERROR_INVALID_PARAMETER;
96
97         if (!HereManager::GetHandler())
98                 return HERE_ERROR_INVALID_OPERATION;
99
100         return HereManager::GetHandler()->GetPreference(hPref);
101 }
102
103 int HerePluginGeocode(const char* szAddr,
104         maps_item_hashtable_h hPref, maps_service_geocode_cb pCbFunc,
105         void *pUserData, int *nReqId)
106 {
107         /* checking parmaters */
108         if (!szAddr || (szAddr && *szAddr == '\0') || !pCbFunc || !nReqId)
109                 return HERE_ERROR_INVALID_PARAMETER;
110
111         if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
112                 return HERE_ERROR_PERMISSION_DENIED;
113
114         if (!HereManager::GetHandler())
115                 return HERE_ERROR_INVALID_OPERATION;
116
117         /* creating instance */
118         HereGeocode *pGeocode =
119                 (HereGeocode*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_GEOCODE,
120                 (void*)pCbFunc, pUserData, nReqId));
121
122         if(!pGeocode)
123                 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
124
125         /* sending request */
126         here_error_e error = HERE_ERROR_NONE;
127
128         do {
129                 error = pGeocode->PrepareQuery();
130                 if (error != HERE_ERROR_NONE) break;
131
132                 error = pGeocode->PreparePreference(hPref);
133                 if (error != HERE_ERROR_NONE) break;
134
135                 error = pGeocode->StartGeocode(szAddr);
136         } while (0);
137
138         /* finishing task */
139         if(error != HERE_ERROR_NONE)
140                 pGeocode->TerminateService();
141
142         return error;
143 }
144
145 int HerePluginGeocodeByStructuredAddress(const maps_address_h hAddr,
146         maps_item_hashtable_h hPref, maps_service_geocode_cb pCbFunc,
147         void *pUserData, int *nReqId)
148 {
149         /* checking parmaters */
150         if (!hAddr || !pCbFunc || !nReqId)
151                 return HERE_ERROR_INVALID_PARAMETER;
152
153         if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
154                 return HERE_ERROR_PERMISSION_DENIED;
155
156         if (!HereManager::GetHandler())
157                 return HERE_ERROR_INVALID_OPERATION;
158
159         /* creating instance */
160         HereGeocode *pGeocode =
161                 (HereGeocode*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_GEOCODE,
162                 (void*)pCbFunc, pUserData, nReqId));
163
164         if(!pGeocode)
165                 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
166
167         /* sending request */
168         here_error_e error = HERE_ERROR_NONE;
169
170         do {
171                 error = pGeocode->PrepareQuery();
172                 if (error != HERE_ERROR_NONE) break;
173
174                 error = pGeocode->PreparePreference(hPref);
175                 if (error != HERE_ERROR_NONE) break;
176
177                 error = pGeocode->StartGeocodeByStructuredAddress(hAddr);
178         } while (0);
179
180         /* finishing task */
181         if(error != HERE_ERROR_NONE)
182                 pGeocode->TerminateService();
183
184         return error;
185 }
186
187 int HerePluginGeocodeInsideArea(const char* szAddr, maps_area_h hArea,
188         maps_item_hashtable_h hPref, maps_service_geocode_cb pCbFunc,
189         void *pUserData, int *nReqId)
190 {
191         /* checking parmaters */
192         if (!szAddr || (szAddr && *szAddr == '\0') || !pCbFunc || !nReqId)
193                 return HERE_ERROR_INVALID_PARAMETER;
194
195         if (!hArea || !HereUtils::IsValid(*(maps_area_s*)hArea))
196                 return HERE_ERROR_INVALID_PARAMETER;
197
198         if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
199                 return HERE_ERROR_PERMISSION_DENIED;
200
201         if (!HereManager::GetHandler())
202                 return HERE_ERROR_INVALID_OPERATION;
203
204         /* creating instance */
205         HereGeocode *pGeocode =
206                 (HereGeocode*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_GEOCODE,
207                 (void*)pCbFunc, pUserData, nReqId));
208
209         if(!pGeocode)
210                 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
211
212         /* sending request */
213         here_error_e error = HERE_ERROR_NONE;
214
215         do {
216                 error = pGeocode->PrepareQuery();
217                 if (error != HERE_ERROR_NONE) break;
218
219                 error = pGeocode->PreparePreference(hPref);
220                 if (error != HERE_ERROR_NONE) break;
221
222                 error = pGeocode->StartGeocodeInsideArea(szAddr, hArea);
223         } while (0);
224
225         /* finishing task */
226         if(error != HERE_ERROR_NONE)
227                 pGeocode->TerminateService();
228
229         return error;
230 }
231
232 int HerePluginReverseGeocode(double dLatitude, double dLongitude,
233         maps_item_hashtable_h hPref, maps_service_reverse_geocode_cb pCbFunc,
234         void *pUserData, int *nReqId)
235 {
236         /* checking parmaters */
237         if (!HereUtils::IsValidCoord(dLatitude, dLongitude))
238                 return HERE_ERROR_INVALID_PARAMETER;
239
240         if (!pCbFunc || !nReqId)
241                 return HERE_ERROR_INVALID_PARAMETER;
242
243         if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
244                 return HERE_ERROR_PERMISSION_DENIED;
245
246         if (!HereManager::GetHandler())
247                 return HERE_ERROR_INVALID_OPERATION;
248
249         /* creating instance */
250         HereRevGeocode *pRevGeocode =
251                 (HereRevGeocode*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_REV_GEOCODE,
252                 (void*)pCbFunc, pUserData, nReqId));
253
254         if(!pRevGeocode)
255                 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
256
257         /* sending request */
258         here_error_e error = HERE_ERROR_UNKNOWN;
259
260         do {
261                 error = pRevGeocode->PrepareQuery();
262                 if (error != HERE_ERROR_NONE) break;
263
264                 error = pRevGeocode->PreparePreference(hPref);
265                 if (error != HERE_ERROR_NONE) break;
266
267                 error = pRevGeocode->PreparePosition(dLatitude, dLongitude);
268                 if (error != HERE_ERROR_NONE) break;
269
270                 error = pRevGeocode->StartRevGeocode(hPref);
271         } while (0);
272
273         /* finishing task */
274         if(error != HERE_ERROR_NONE)
275                 pRevGeocode->TerminateService();
276
277         return error;
278 }
279
280 int HerePluginMultiReverseGeocode(const maps_coordinates_list_h hGeocodeList,
281         maps_item_hashtable_h hPref, maps_service_multi_reverse_geocode_cb pCbFunc,
282         void *pUserData, int *nReqId)
283 {
284         /* checking parmaters */
285         if (!hGeocodeList || !pCbFunc || !nReqId)
286                 return HERE_ERROR_INVALID_PARAMETER;
287
288         if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
289                 return HERE_ERROR_PERMISSION_DENIED;
290
291         if (!HereManager::GetHandler())
292                 return HERE_ERROR_INVALID_OPERATION;
293
294         /* creating instance */
295         HereMultiRevGeocode *pMultiRevGeocode =
296                 (HereMultiRevGeocode*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_MULTI_REV_GEOCODE,
297                 (void*)pCbFunc, pUserData, nReqId));
298
299         if(!pMultiRevGeocode)
300                 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
301
302         /* sending request */
303         here_error_e error = HERE_ERROR_UNKNOWN;
304
305         do {
306                 error = pMultiRevGeocode->PrepareQuery();
307                 if (error != HERE_ERROR_NONE) break;
308
309                 error = pMultiRevGeocode->PreparePositionList(hGeocodeList);
310                 if (error != HERE_ERROR_NONE) break;
311
312                 error = pMultiRevGeocode->StartMultiReverse(hPref);
313         } while (0);
314
315         /* finishing task */
316         if(error != HERE_ERROR_NONE)
317                 pMultiRevGeocode->TerminateService();
318
319         return error;
320 }
321
322 int HerePluginSearchPlace(maps_coordinates_h hPos, int nDistance,
323         maps_item_hashtable_h hPref, maps_place_filter_h hFilter, maps_service_search_place_cb pCbFunc,
324         void *pUserData, int *nReqId)
325 {
326         /* checking parmaters */
327         if (!hPos || !HereUtils::IsValid(*(maps_coordinates_s*)hPos) || nDistance <= 0)
328                 return HERE_ERROR_INVALID_PARAMETER;
329
330         if (!hFilter || !pCbFunc || !nReqId)
331                 return HERE_ERROR_INVALID_PARAMETER;
332
333         if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
334                 return HERE_ERROR_PERMISSION_DENIED;
335
336         if (!HereManager::GetHandler())
337                 return HERE_ERROR_INVALID_OPERATION;
338
339         /* creating instance */
340         HerePlace *pPlace =
341                 (HerePlace*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_PLACE,
342                 (void*)pCbFunc, pUserData, nReqId));
343
344         if(!pPlace)
345                 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
346
347         /* sending request */
348         here_error_e error = HERE_ERROR_NONE;
349
350         do {
351                 error = pPlace->PrepareDiscoveryQuery();
352                 if (error != HERE_ERROR_NONE) break;
353
354                 error = pPlace->PrepareDiscoveryPreference(hPref);
355                 if (error != HERE_ERROR_NONE) break;
356
357                 error = pPlace->PrepareDiscoveryFilter(hFilter);
358                 if (error != HERE_ERROR_NONE) break;
359
360                 error = pPlace->StartDiscoveryPlace(hPos, nDistance);
361         } while (0);
362
363         /* finishing task */
364         if(error != HERE_ERROR_NONE)
365                 pPlace->TerminateService();
366
367         return error;
368 }
369
370 int HerePluginSearchPlaceByArea(maps_area_h hArea,
371         maps_item_hashtable_h hPref, maps_place_filter_h hFilter, maps_service_search_place_cb pCbFunc,
372         void *pUserData, int *nReqId)
373 {
374         /* checking parmaters */
375         if (!hArea || !HereUtils::IsValid(*(maps_area_s*)hArea))
376                 return HERE_ERROR_INVALID_PARAMETER;
377
378         if (!hFilter || !pCbFunc || !nReqId)
379                 return HERE_ERROR_INVALID_PARAMETER;
380
381         if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
382                 return HERE_ERROR_PERMISSION_DENIED;
383
384         if (!HereManager::GetHandler())
385                 return HERE_ERROR_INVALID_OPERATION;
386
387         /* creating instance */
388         HerePlace *pPlace =
389                 (HerePlace*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_PLACE,
390                 (void*)pCbFunc, pUserData, nReqId));
391
392         if(!pPlace)
393                 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
394
395         /* sending request */
396         here_error_e error = HERE_ERROR_NONE;
397
398         do {
399                 error = pPlace->PrepareDiscoveryQuery();
400                 if (error != HERE_ERROR_NONE) break;
401
402                 error = pPlace->PrepareDiscoveryPreference(hPref);
403                 if (error != HERE_ERROR_NONE) break;
404
405                 error = pPlace->PrepareDiscoveryFilter(hFilter);
406                 if (error != HERE_ERROR_NONE) break;
407
408                 error = pPlace->StartDiscoveryPlace(hArea);
409         } while (0);
410
411         /* finishing task */
412         if(error != HERE_ERROR_NONE)
413                 pPlace->TerminateService();
414
415         return error;
416 }
417
418 int HerePluginSearchPlaceByAddress(const char* szAddr, maps_area_h hArea,
419         maps_item_hashtable_h hPref, maps_place_filter_h hFilter, maps_service_search_place_cb pCbFunc,
420         void * pUserData, int *nReqId)
421 {
422         /* checking parmaters */
423         if (!szAddr || (szAddr && *szAddr == '\0') || !hFilter || !pCbFunc || !nReqId)
424                 return HERE_ERROR_INVALID_PARAMETER;
425
426         if (!hArea || !HereUtils::IsValid(*(maps_area_s*)hArea))
427                 return HERE_ERROR_INVALID_PARAMETER;
428
429         if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
430                 return HERE_ERROR_PERMISSION_DENIED;
431
432         if (!HereManager::GetHandler())
433                 return HERE_ERROR_INVALID_OPERATION;
434
435         /* creating instance */
436         HerePlace *pPlace =
437                 (HerePlace*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_PLACE,
438                 (void*)pCbFunc, pUserData, nReqId));
439
440         if(!pPlace)
441                 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
442
443         /* sending request */
444         here_error_e error = HERE_ERROR_NONE;
445
446         do {
447                 error = pPlace->PrepareDiscoveryQuery();
448                 if (error != HERE_ERROR_NONE) break;
449
450                 error = pPlace->PrepareDiscoveryPreference(hPref);
451                 if (error != HERE_ERROR_NONE) break;
452
453                 error = pPlace->PrepareDiscoveryFilter(hFilter);
454                 if (error != HERE_ERROR_NONE) break;
455
456                 error = pPlace->StartDiscoveryPlace(hArea, szAddr);
457         } while (0);
458
459         /* finishing task */
460         if(error != HERE_ERROR_NONE)
461                 pPlace->TerminateService();
462
463         return error;
464 }
465
466 int HerePluginSearchPlaceList(maps_area_h hArea, maps_item_hashtable_h hPref,
467         maps_place_filter_h hFilter, maps_service_search_place_list_cb pCbFunc,
468         void *pUserData, int *nReqId)
469 {
470         /* checking parmaters */
471         if (!hFilter || !pCbFunc || !nReqId)
472                 return HERE_ERROR_INVALID_PARAMETER;
473
474         if (!hArea || !HereUtils::IsValid(*(maps_area_s*)hArea))
475                 return HERE_ERROR_INVALID_PARAMETER;
476
477         if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
478                 return HERE_ERROR_PERMISSION_DENIED;
479
480         if (!HereManager::GetHandler())
481                 return HERE_ERROR_INVALID_OPERATION;
482
483         /* creating instance */
484         HerePlace *pPlace =
485                 (HerePlace*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_PLACE,
486                 (void*)pCbFunc, pUserData, nReqId));
487
488         if(!pPlace)
489                 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
490
491         /* sending request */
492         here_error_e error = HERE_ERROR_NONE;
493
494         do {
495                 error = pPlace->PrepareDiscoveryQuery();
496                 if (error != HERE_ERROR_NONE) break;
497
498                 error = pPlace->PrepareDiscoveryPreference(hPref);
499                 if (error != HERE_ERROR_NONE) break;
500
501                 error = pPlace->PrepareDiscoveryFilter(hFilter);
502                 if (error != HERE_ERROR_NONE) break;
503
504                 error = pPlace->StartDiscoveryPlaceList(hArea);
505         } while (0);
506
507         /* finishing task */
508         if(error != HERE_ERROR_NONE)
509                 pPlace->TerminateService();
510
511         return error;
512 }
513
514 int HerePluginSearchPlaceDetails(const char* szUrl,
515         maps_service_get_place_details_cb pCbFunc,
516         void *pUserData, int *nReqId)
517 {
518         /* checking parmaters */
519         if (!szUrl || (szUrl && *szUrl == '\0') || !pCbFunc || !nReqId)
520                 return HERE_ERROR_INVALID_PARAMETER;
521
522         if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
523                 return HERE_ERROR_PERMISSION_DENIED;
524
525         if (!HereManager::GetHandler())
526                 return HERE_ERROR_INVALID_OPERATION;
527
528         /* creating instance */
529         HerePlace *pPlace =
530                 (HerePlace*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_PLACE,
531                 (void*)pCbFunc, pUserData, nReqId));
532
533         if(!pPlace)
534                 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
535
536         /* sending request */
537         here_error_e error = HERE_ERROR_NONE;
538
539         do {
540                 error = pPlace->PreparePlaceDetailsQuery();
541                 if (error != HERE_ERROR_NONE) break;
542
543                 error = pPlace->StartPlaceDetails(szUrl);
544         } while (0);
545
546         /* finishing task */
547         if(error != HERE_ERROR_NONE)
548                 pPlace->TerminateService();
549
550         return error;
551 }
552
553 int HerePluginSearchRoute(maps_coordinates_h hOrigin, maps_coordinates_h hDestination,
554         maps_item_hashtable_h hPref, maps_service_search_route_cb pCbFunc,
555         void *pUserData, int *nReqId)
556 {
557         /* checking parmaters */
558         if (!hOrigin || !hDestination || !pCbFunc || !nReqId)
559                 return HERE_ERROR_INVALID_PARAMETER;
560
561         if (!HereUtils::IsValid(*(maps_coordinates_s*)hOrigin) ||
562                 !HereUtils::IsValid(*(maps_coordinates_s*)hDestination))
563                 return HERE_ERROR_INVALID_PARAMETER;
564
565         if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
566                 return HERE_ERROR_PERMISSION_DENIED;
567
568         if (!HereManager::GetHandler())
569                 return HERE_ERROR_INVALID_OPERATION;
570
571         /* creating instance */
572         HereRoute *pRoute =
573                 (HereRoute*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_ROUTE,
574                 (void*)pCbFunc, pUserData, nReqId));
575
576         if(!pRoute)
577                 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
578
579         /* sending request */
580         here_error_e error = HERE_ERROR_NONE;
581
582         do {
583                 error = pRoute->PrepareQuery();
584                 if (error != HERE_ERROR_NONE) break;
585
586                 error = pRoute->PreparePreference(hPref);
587                 if (error != HERE_ERROR_NONE) break;
588
589                 error = pRoute->PrepareWaypoint(hOrigin, hDestination);
590                 if (error != HERE_ERROR_NONE) break;
591
592                 error = pRoute->StartRoute();
593         } while (0);
594
595         /* finishing task */
596         if(error != HERE_ERROR_NONE)
597                 pRoute->TerminateService();
598
599         return error;
600 }
601
602 int HerePluginSearchRouteWaypoints(const maps_coordinates_h* hWaypointList, int nWaypointNum,
603         maps_item_hashtable_h hPref, maps_service_search_route_cb pCbFunc,
604         void* pUserData, int *nReqId)
605 {
606         /* checking parmaters */
607         if (!hWaypointList || nWaypointNum < 2 || !pCbFunc || !nReqId)
608                 return HERE_ERROR_INVALID_PARAMETER;
609
610         for (int i = 0; i < nWaypointNum; i++)
611         {
612                 if (!HereUtils::IsValid(*(maps_coordinates_s*)hWaypointList[i]))
613                         return HERE_ERROR_INVALID_PARAMETER;
614         }
615
616         if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
617                 return HERE_ERROR_PERMISSION_DENIED;
618
619         if (!HereManager::GetHandler())
620                 return HERE_ERROR_INVALID_OPERATION;
621
622         /* creating instance */
623         HereRoute *pRoute =
624                 (HereRoute*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_ROUTE,
625                 (void*)pCbFunc, pUserData, nReqId));
626
627         if(!pRoute)
628                 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
629
630         /* sending request */
631         here_error_e error = HERE_ERROR_NONE;
632
633         do {
634                 error = pRoute->PrepareQuery();
635                 if (error != HERE_ERROR_NONE) break;
636
637                 error = pRoute->PrepareWaypoint(hWaypointList, nWaypointNum);
638                 if (error != HERE_ERROR_NONE) break;
639
640                 error = pRoute->PreparePreference(hPref);
641                 if (error != HERE_ERROR_NONE) break;
642
643                 error = pRoute->StartRoute();
644         } while (0);
645
646         /* finishing task */
647         if(error != HERE_ERROR_NONE)
648                 pRoute->TerminateService();
649
650         return error;
651 }
652
653 int HerePluginCancelRequest(int nReqId)
654 {
655         if (nReqId <= 0)
656                 return HERE_ERROR_INVALID_PARAMETER;
657
658         if (!HereManager::GetHandler())
659                 return HERE_ERROR_INVALID_OPERATION;
660
661         return (HereManager::GetHandler()->CancelInstance(nReqId));
662 }
663
664
665
666 /*****************************************************************************/
667 /*                                                                           */
668 /*  Maps Widget                                                              */
669 /*                                                                           */
670 /*****************************************************************************/
671
672 int HerePluginCreateMapView(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc)
673 {
674         HereView *vh = NULL, *ovh = NULL;
675         vh = new HereView();
676         if (!vh) return HERE_ERROR_OUT_OF_MEMORY;
677         maps_view_get_maps_plugin_view_handle(hView, (void**)&ovh);
678         maps_view_set_maps_plugin_view_handle(hView, vh);
679         if (ovh)
680                 delete ovh;
681         return vh->init(hView, pCbFunc);
682 }
683
684 int HerePluginDestroyMapView(maps_view_h hView)
685 {
686         HereView *vh = NULL;
687         int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&vh);
688         here_error_e error = (here_error_e)ConvertToHereError(maps_error);
689         if (error == HERE_ERROR_NONE && vh) {
690                 maps_view_set_maps_plugin_view_handle(hView, NULL);
691                 error = vh->close(hView);
692                 delete vh;
693         }
694         return error;
695 }
696
697 int HerePluginRenderMap(maps_view_h hView, const maps_coordinates_h mapsCoord,
698         double dZoom, double dAngle)
699 {
700         HereView *vh = NULL;
701         int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&vh);
702         here_error_e error = (here_error_e)ConvertToHereError(maps_error);
703         if (error == HERE_ERROR_NONE && vh)
704                 error = vh->renderMap(hView, mapsCoord, dZoom, dAngle);
705         return error;
706 }
707
708 int HerePluginMoveCenter(maps_view_h hView, int delta_x, int delta_y)
709 {
710         HereView *vh = NULL;
711         int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&vh);
712         here_error_e error = (here_error_e)ConvertToHereError(maps_error);
713         if (error == HERE_ERROR_NONE && vh)
714                 error = vh->moveCenter(hView, delta_x, delta_y);
715         return error;
716 }
717
718 int HerePluginSetScalebar(maps_view_h hView, bool enable)
719 {
720         HereView *vh = NULL;
721         int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&vh);
722         here_error_e error = (here_error_e)ConvertToHereError(maps_error);
723         if (error == HERE_ERROR_NONE && vh)
724                 error = vh->setScalebarEnabled(hView, enable);
725         return error;
726 }
727
728 int HerePluginGetScalebar(maps_view_h hView, bool *enabled)
729 {
730         HereView *vh = NULL;
731         int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&vh);
732         here_error_e error = (here_error_e)ConvertToHereError(maps_error);
733         if (error == HERE_ERROR_NONE && vh)
734                 error = vh->getScalebarEnabled(hView, enabled);
735         return error;
736 }
737
738 int HerePluginGetCenter(maps_view_h hView, maps_coordinates_h *center)
739 {
740         HereView *vh = NULL;
741         int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&vh);
742         here_error_e error = (here_error_e)ConvertToHereError(maps_error);
743         if (error == HERE_ERROR_NONE && vh)
744                 error = vh->getCenter(hView, center);
745         return error;
746 }
747
748 int HerePluginScreenToGeography(maps_view_h hView, int x, int y, maps_coordinates_h *mapsCoord)
749 {
750         HereView *vh = NULL;
751         int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&vh);
752         here_error_e error = (here_error_e)ConvertToHereError(maps_error);
753         if (error == HERE_ERROR_NONE && vh)
754                 error = vh->convertScreenToGeolocation(hView, x, y, mapsCoord);
755         return error;
756 }
757
758 int HerePluginGeographyToScreen(maps_view_h hView, const maps_coordinates_h mapsCoord, int *x, int *y)
759 {
760         HereView *vh = NULL;
761         int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&vh);
762         here_error_e error = (here_error_e)ConvertToHereError(maps_error);
763         if (error == HERE_ERROR_NONE && vh)
764                 error = vh->convertGeolocationToScreen(hView, mapsCoord, x, y);
765         return error;
766 }
767
768 int HerePluginGetMinZoomLevel(maps_view_h hView, int *nMinZoomLevel)
769 {
770         HereView *vh = NULL;
771         int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&vh);
772         here_error_e error = (here_error_e)ConvertToHereError(maps_error);
773         if (error == HERE_ERROR_NONE && vh)
774                 error = vh->getMinZoomLevel(hView, nMinZoomLevel);
775         return error;
776 }
777
778 int HerePluginGetMaxZoomLevel(maps_view_h hView, int *nMaxZoomLevel)
779 {
780         HereView *vh = NULL;
781         int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&vh);
782         here_error_e error = (here_error_e)ConvertToHereError(maps_error);
783         if (error == HERE_ERROR_NONE && vh)
784                 error = vh->getMaxZoomLevel(hView, nMaxZoomLevel);
785         return error;
786 }
787
788 int HerePluginOnViewObject(maps_view_h hView, const maps_view_object_h object,
789         maps_view_object_operation_e operation)
790 {
791         HereView *vh = NULL;
792         int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&vh);
793         here_error_e error = (here_error_e)ConvertToHereError(maps_error);
794         if (error == HERE_ERROR_NONE && vh)
795                 error = vh->onViewObject(hView, object, operation);
796         return error;
797 }