2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "here_types.h"
19 #include "here_geocode.h"
20 #include "here_revgeocode.h"
21 #include "here_place.h"
22 #include "here_route.h"
23 #include <common/HereConfig.h>
26 using namespace HERE_PLUGIN_NAMESPACE_PREFIX;
28 int HerePluginInit(maps_plugin_h *hPlugin)
31 return HERE_ERROR_INVALID_PARAMETER;
33 HereManager::Create();
35 if (!HereManager::GetHandler())
36 return HERE_ERROR_INVALID_OPERATION;
38 HereManager::GetHandler()->SetProxyAddress();
40 return HERE_ERROR_NONE;
43 int HerePluginShutdown(maps_plugin_h hPlugin)
46 return HERE_ERROR_INVALID_PARAMETER;
48 if (HereManager::GetHandler())
50 HereManager::GetHandler()->TerminateAllServices();
51 HereManager::GetHandler()->Close();
54 return HERE_ERROR_NONE;
57 int HerePluginSetProviderKey(const char* szKey)
60 return HERE_ERROR_INVALID_PARAMETER;
62 if (!HereManager::GetHandler())
63 return HERE_ERROR_INVALID_OPERATION;
65 here_error_e error = HereManager::GetHandler()->SetCredentials(szKey);
70 int HerePluginGetProviderKey(char** szKey)
73 return HERE_ERROR_INVALID_PARAMETER;
75 if (!HereManager::GetHandler())
76 return HERE_ERROR_INVALID_OPERATION;
78 here_error_e error = HereManager::GetHandler()->GetCredentials(szKey);
83 int HerePluginSetPreference(maps_preference_h hPref)
86 return HERE_ERROR_INVALID_PARAMETER;
88 if (!HereManager::GetHandler())
89 return HERE_ERROR_INVALID_OPERATION;
91 here_error_e error = HereManager::GetHandler()->SetPreference(hPref);
96 int HerePluginGetPreference(maps_preference_h *hPref)
99 return HERE_ERROR_INVALID_PARAMETER;
101 if (!HereManager::GetHandler())
102 return HERE_ERROR_INVALID_OPERATION;
104 here_error_e error = HereManager::GetHandler()->GetPreference(hPref);
109 int HerePluginGeocode(const char* szAddr,
110 maps_item_hashtable_h hPref, maps_service_geocode_cb pCbFunc,
111 void *pUserData, int *nReqId)
113 /* checking parmaters */
114 if (!szAddr || (szAddr && *szAddr == '\0') || !pCbFunc || !nReqId)
115 return HERE_ERROR_INVALID_PARAMETER;
117 if (!HereManager::GetHandler())
118 return HERE_ERROR_INVALID_OPERATION;
120 /* creating instance */
121 HereGeocode *pGeocode =
122 (HereGeocode*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_GEOCODE,
123 (void*)pCbFunc, pUserData, nReqId));
126 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
128 /* sending request */
129 here_error_e error = HERE_ERROR_NONE;
132 error = pGeocode->PrepareQuery();
133 if (error != HERE_ERROR_NONE) break;
135 error = pGeocode->PreparePreference(hPref);
137 error = pGeocode->StartGeocode(szAddr);
141 if(error != HERE_ERROR_NONE)
142 pGeocode->TerminateService();
147 int HerePluginGeocodeByStructuredAddress(const maps_address_h hAddr,
148 maps_item_hashtable_h hPref, maps_service_geocode_cb pCbFunc,
149 void *pUserData, int *nReqId)
151 /* checking parmaters */
152 if (!hAddr || !pCbFunc || !nReqId)
153 return HERE_ERROR_INVALID_PARAMETER;
155 if (!HereManager::GetHandler())
156 return HERE_ERROR_INVALID_OPERATION;
158 /* creating instance */
159 HereGeocode *pGeocode =
160 (HereGeocode*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_GEOCODE,
161 (void*)pCbFunc, pUserData, nReqId));
164 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
166 /* sending request */
167 here_error_e error = HERE_ERROR_NONE;
170 error = pGeocode->PrepareQuery();
171 if (error != HERE_ERROR_NONE) break;
173 error = pGeocode->PreparePreference(hPref);
175 error = pGeocode->StartGeocodeByStructuredAddress(hAddr);
179 if(error != HERE_ERROR_NONE)
180 pGeocode->TerminateService();
185 int HerePluginGeocodeInsideArea(const char* szAddr, maps_area_h hArea,
186 maps_item_hashtable_h hPref, maps_service_geocode_cb pCbFunc,
187 void *pUserData, int *nReqId)
189 /* checking parmaters */
190 if (!szAddr || (szAddr && *szAddr == '\0') || !pCbFunc || !nReqId)
191 return HERE_ERROR_INVALID_PARAMETER;
193 if (!hArea || !HereUtils::IsValid(*(maps_area_s*)hArea))
194 return HERE_ERROR_INVALID_PARAMETER;
196 if (!HereManager::GetHandler())
197 return HERE_ERROR_INVALID_OPERATION;
199 /* creating instance */
200 HereGeocode *pGeocode =
201 (HereGeocode*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_GEOCODE,
202 (void*)pCbFunc, pUserData, nReqId));
205 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
207 /* sending request */
208 here_error_e error = HERE_ERROR_NONE;
211 error = pGeocode->PrepareQuery();
212 if (error != HERE_ERROR_NONE) break;
214 error = pGeocode->PreparePreference(hPref);
216 error = pGeocode->StartGeocodeInsideArea(szAddr, hArea);
220 if(error != HERE_ERROR_NONE)
221 pGeocode->TerminateService();
226 int HerePluginReverseGeocode(double dLatitude, double dLongitude,
227 maps_item_hashtable_h hPref, maps_service_reverse_geocode_cb pCbFunc,
228 void *pUserData, int *nReqId)
230 /* checking parmaters */
231 if (!HereUtils::IsValidCoord(dLatitude, dLongitude))
232 return HERE_ERROR_INVALID_PARAMETER;
234 if (!pCbFunc || !nReqId)
235 return HERE_ERROR_INVALID_PARAMETER;
237 if (!HereManager::GetHandler())
238 return HERE_ERROR_INVALID_OPERATION;
240 /* creating instance */
241 HereRevGeocode *pRevGeocode =
242 (HereRevGeocode*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_REV_GEOCODE,
243 (void*)pCbFunc, pUserData, nReqId));
246 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
248 /* sending request */
249 here_error_e error = HERE_ERROR_UNKNOWN;
252 error = pRevGeocode->PrepareQuery();
253 if (error != HERE_ERROR_NONE) break;
255 error = pRevGeocode->PreparePreference(hPref);
257 error = pRevGeocode->PreparePosition(dLatitude, dLongitude);
258 if (error != HERE_ERROR_NONE) break;
260 error = pRevGeocode->StartRevGeocode(hPref);
264 if(error != HERE_ERROR_NONE)
265 pRevGeocode->TerminateService();
270 int HerePluginSearchPlace(maps_coordinates_h hPos, int nDistance,
271 maps_item_hashtable_h hPref, maps_place_filter_h hFilter, maps_service_search_place_cb pCbFunc,
272 void *pUserData, int *nReqId)
274 /* checking parmaters */
275 if (!hPos || !HereUtils::IsValid(*(maps_coordinates_s*)hPos) || nDistance <= 0)
276 return HERE_ERROR_INVALID_PARAMETER;
278 if (!hFilter || !pCbFunc || !nReqId)
279 return HERE_ERROR_INVALID_PARAMETER;
281 if (!HereManager::GetHandler())
282 return HERE_ERROR_INVALID_OPERATION;
284 /* creating instance */
286 (HerePlace*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_PLACE,
287 (void*)pCbFunc, pUserData, nReqId));
290 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
292 /* sending request */
293 here_error_e error = HERE_ERROR_NONE;
296 error = pPlace->PrepareDiscoveryQuery();
297 if (error != HERE_ERROR_NONE) break;
299 error = pPlace->PrepareDiscoveryPreference(hPref);
301 error = pPlace->PrepareDiscoveryFilter(hFilter);
302 if (error != HERE_ERROR_NONE) break;
304 error = pPlace->StartDiscoveryPlace(hPos, nDistance);
308 if(error != HERE_ERROR_NONE)
309 pPlace->TerminateService();
314 int HerePluginSearchPlaceByArea(maps_area_h hArea,
315 maps_item_hashtable_h hPref, maps_place_filter_h hFilter, maps_service_search_place_cb pCbFunc,
316 void *pUserData, int *nReqId)
318 /* checking parmaters */
319 if (!hArea || !HereUtils::IsValid(*(maps_area_s*)hArea))
320 return HERE_ERROR_INVALID_PARAMETER;
322 if (!hFilter || !pCbFunc || !nReqId)
323 return HERE_ERROR_INVALID_PARAMETER;
325 if (!HereManager::GetHandler())
326 return HERE_ERROR_INVALID_OPERATION;
328 /* creating instance */
330 (HerePlace*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_PLACE,
331 (void*)pCbFunc, pUserData, nReqId));
334 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
336 /* sending request */
337 here_error_e error = HERE_ERROR_NONE;
340 error = pPlace->PrepareDiscoveryQuery();
341 if (error != HERE_ERROR_NONE) break;
343 error = pPlace->PrepareDiscoveryPreference(hPref);
345 error = pPlace->PrepareDiscoveryFilter(hFilter);
346 if (error != HERE_ERROR_NONE) break;
348 error = pPlace->StartDiscoveryPlaceByArea(hArea);
352 if(error != HERE_ERROR_NONE)
353 pPlace->TerminateService();
358 int HerePluginSearchPlaceByAddress(const char* szAddr, maps_area_h hArea,
359 maps_item_hashtable_h hPref, maps_place_filter_h hFilter, maps_service_search_place_cb pCbFunc,
360 void * pUserData, int *nReqId)
362 /* checking parmaters */
363 if (!szAddr || (szAddr && *szAddr == '\0') || !hFilter || !pCbFunc || !nReqId)
364 return HERE_ERROR_INVALID_PARAMETER;
366 if (!hArea || !HereUtils::IsValid(*(maps_area_s*)hArea))
367 return HERE_ERROR_INVALID_PARAMETER;
369 if (!HereManager::GetHandler())
370 return HERE_ERROR_INVALID_OPERATION;
372 /* creating instance */
374 (HerePlace*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_PLACE,
375 (void*)pCbFunc, pUserData, nReqId));
378 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
380 /* sending request */
381 here_error_e error = HERE_ERROR_NONE;
384 error = pPlace->PrepareDiscoveryQuery();
385 if (error != HERE_ERROR_NONE) break;
387 error = pPlace->PrepareDiscoveryPreference(hPref);
389 error = pPlace->PrepareDiscoveryFilter(hFilter);
390 if (error != HERE_ERROR_NONE) break;
392 error = pPlace->StartDiscoveryPlaceByAddress(szAddr, hArea);
396 if(error != HERE_ERROR_NONE)
397 pPlace->TerminateService();
402 int HerePluginSearchPlaceDetails(const char* szUrl,
403 maps_item_hashtable_h hPref, maps_service_search_place_cb pCbFunc,
404 void *pUserData, int *nReqId)
406 /* checking parmaters */
407 if (!szUrl || (szUrl && *szUrl == '\0') || !pCbFunc || !nReqId)
408 return HERE_ERROR_INVALID_PARAMETER;
410 if (!HereManager::GetHandler())
411 return HERE_ERROR_INVALID_OPERATION;
413 /* creating instance */
415 (HerePlace*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_PLACE,
416 (void*)pCbFunc, pUserData, nReqId));
419 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
421 /* sending request */
422 here_error_e error = HERE_ERROR_NONE;
425 error = pPlace->PreparePlaceDetailsQuery();
426 if (error != HERE_ERROR_NONE) break;
428 error = pPlace->PreparePlaceDetailsPreference(hPref);
430 error = pPlace->StartPlaceDetails(szUrl);
434 if(error != HERE_ERROR_NONE)
435 pPlace->TerminateService();
440 int HerePluginSearchRoute(maps_coordinates_h hOrigin, maps_coordinates_h hDestination,
441 maps_item_hashtable_h hPref, maps_service_search_route_cb pCbFunc,
442 void *pUserData, int *nReqId)
444 /* checking parmaters */
445 if (!hOrigin || !hDestination || !pCbFunc || !nReqId)
446 return HERE_ERROR_INVALID_PARAMETER;
448 if (!HereUtils::IsValid(*(maps_coordinates_s*)hOrigin) ||
449 !HereUtils::IsValid(*(maps_coordinates_s*)hDestination))
450 return HERE_ERROR_INVALID_PARAMETER;
452 if (!HereManager::GetHandler())
453 return HERE_ERROR_INVALID_OPERATION;
455 /* creating instance */
457 (HereRoute*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_ROUTE,
458 (void*)pCbFunc, pUserData, nReqId));
461 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
463 /* sending request */
464 here_error_e error = HERE_ERROR_NONE;
467 error = pRoute->PrepareQuery();
468 if (error != HERE_ERROR_NONE) break;
470 error = pRoute->PreparePreference(hPref);
472 error = pRoute->PrepareWaypoint(hOrigin, hDestination);
473 if (error != HERE_ERROR_NONE) break;
475 error = pRoute->StartRoute();
479 if(error != HERE_ERROR_NONE)
480 pRoute->TerminateService();
485 int HerePluginSearchRouteWaypoints(const maps_coordinates_h* hWaypointList, int nWaypointNum,
486 maps_item_hashtable_h hPref, maps_service_search_route_cb pCbFunc,
487 void* pUserData, int *nReqId)
489 /* checking parmaters */
490 if (!hWaypointList || nWaypointNum < 2 || !pCbFunc || !nReqId)
491 return HERE_ERROR_INVALID_PARAMETER;
493 for (int i=0; i<nWaypointNum; i++)
495 if (!HereUtils::IsValid(*(maps_coordinates_s*)hWaypointList[i]))
496 return HERE_ERROR_INVALID_PARAMETER;
499 if (!HereManager::GetHandler())
500 return HERE_ERROR_INVALID_OPERATION;
502 /* creating instance */
504 (HereRoute*)(HereManager::GetHandler()->CreateInstance(HereManager::HERE_SVC_ROUTE,
505 (void*)pCbFunc, pUserData, nReqId));
508 return HERE_ERROR_SERVICE_NOT_AVAILABLE;
510 /* sending request */
511 here_error_e error = HERE_ERROR_NONE;
514 error = pRoute->PrepareQuery();
515 if (error != HERE_ERROR_NONE) break;
517 error = pRoute->PrepareWaypoint(hWaypointList, nWaypointNum);
518 if (error != HERE_ERROR_NONE) break;
520 error = pRoute->PreparePreference(hPref);
522 error = pRoute->StartRoute();
526 if(error != HERE_ERROR_NONE)
527 pRoute->TerminateService();
532 int HerePluginCancelRequest(int nReqId)
535 return HERE_ERROR_INVALID_PARAMETER;
537 if (!HereManager::GetHandler())
538 return HERE_ERROR_INVALID_OPERATION;
540 return (HereManager::GetHandler()->CancelInstance(nReqId));