Maps Deadlock Issue Fix
[platform/core/location/maps-plugin-here.git] / src / here_plugin.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 <stdio.h>
18 #include <stdlib.h>
19
20 #include <maps_plugin.h>
21 #include "here_api.h"
22 #include "here_types.h"
23 #include "here_utils.h"
24
25 extern "C"
26 {
27 EXPORT_API int maps_plugin_init(maps_plugin_h *plugin)
28 {
29         int ret = HerePluginInit(plugin);
30
31         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
32
33         return ConvertToMapsError(ret);
34 }
35
36 EXPORT_API int maps_plugin_init_module(maps_plugin_h *plugin, const char *module)
37 {
38         int ret = HerePluginInit(plugin, module);
39
40         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
41
42         return ConvertToMapsError(ret);
43 }
44
45 EXPORT_API int maps_plugin_shutdown(maps_plugin_h plugin)
46 {
47         int ret = HerePluginShutdown(plugin);
48
49         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
50
51         return ConvertToMapsError(ret);
52 }
53
54 EXPORT_API int maps_plugin_get_info(maps_plugin_info_h* info)
55 {
56         int ret = maps_plugin_info_create(info);
57
58         if (ret == MAPS_ERROR_NONE)
59                 ret = maps_plugin_info_set_provider_name(*info, "HERE");
60
61         return ret;
62 }
63
64 EXPORT_API int maps_plugin_request_user_consent(const char *provider,
65                                                                 maps_service_request_user_consent_cb callback,
66                                                                 void *user_data)
67 {
68         MAPS_LOGD("maps_plugin_request_user_consent");
69         int ret = HerePluginRequestUC(provider, (void *)callback, user_data);
70         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
71         return ConvertToMapsError(ret);
72 }
73
74 EXPORT_API int maps_plugin_request_user_consent_with_handle(maps_service_request_user_consent_with_handle_cb callback,
75                                                                 void *user_data)
76 {
77         MAPS_LOGD("maps_plugin_request_user_consent_with_handle");
78         int ret = HerePluginRequestUC(NULL, (void *)callback, user_data);
79         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
80         return ConvertToMapsError(ret);
81 }
82
83 EXPORT_API int maps_plugin_get_user_consent(bool *consent)
84 {
85         MAPS_LOGD("maps_plugin_get_user_consent");
86         int ret = HerePluginGetUC(consent);
87         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
88         return ConvertToMapsError(ret);
89 }
90
91 EXPORT_API int maps_plugin_set_user_consent(bool consent)
92 {
93         MAPS_LOGD("maps_plugin_set_user_consent");
94         int ret = HerePluginSetUserConsent(consent);
95         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
96         return ConvertToMapsError(ret);
97 }
98
99 EXPORT_API int maps_plugin_set_provider_key(const char* provider_key)
100 {
101         int ret = HerePluginSetProviderKey(provider_key);
102
103         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
104
105         return ConvertToMapsError(ret);
106 }
107
108 EXPORT_API int maps_plugin_get_provider_key(char** provider_key)
109 {
110         int ret = HerePluginGetProviderKey(provider_key);
111
112         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
113
114         return ConvertToMapsError(ret);
115 }
116
117 EXPORT_API int maps_plugin_set_preference(maps_preference_h preference)
118 {
119         int ret = HerePluginSetPreference(preference);
120
121         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
122
123         return ConvertToMapsError(ret);
124 }
125
126 EXPORT_API int maps_plugin_get_preference(maps_preference_h* preference)
127 {
128         int ret = HerePluginGetPreference(preference);
129
130         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
131
132         return ConvertToMapsError(ret);
133 }
134
135 EXPORT_API int maps_plugin_is_service_supported(maps_service_e service, bool *supported)
136 {
137         if (!supported)
138                 return MAPS_ERROR_INVALID_PARAMETER;
139
140         switch(service)
141         {
142                 case MAPS_SERVICE_GEOCODE:
143                 case MAPS_SERVICE_GEOCODE_INSIDE_AREA:
144                 case MAPS_SERVICE_GEOCODE_BY_STRUCTURED_ADDRESS:
145                 case MAPS_SERVICE_REVERSE_GEOCODE:
146                 case MAPS_SERVICE_SEARCH_PLACE:
147                 case MAPS_SERVICE_SEARCH_PLACE_BY_AREA:
148                 case MAPS_SERVICE_SEARCH_PLACE_BY_ADDRESS:
149                 case MAPS_SERVICE_SEARCH_ROUTE:
150                 case MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS:
151                 case MAPS_SERVICE_CANCEL_REQUEST:
152                 case MAPS_SERVICE_MULTI_REVERSE_GEOCODE:
153                 case MAPS_SERVICE_SEARCH_PLACE_LIST:
154                 case MAPS_SERVICE_SEARCH_GET_PLACE_DETAILS:
155                 case MAPS_SERVICE_VIEW:
156                 case MAPS_SERVICE_VIEW_SNAPSHOT:
157                         *supported = TRUE;
158                         break;
159                 default:
160                         *supported = FALSE;
161                         break;
162         }
163         return MAPS_ERROR_NONE;
164 }
165
166 EXPORT_API int maps_plugin_is_data_supported(maps_service_data_e service, bool *supported)
167 {
168         if (!supported)
169                 return MAPS_ERROR_INVALID_PARAMETER;
170
171         switch(service)
172         {
173                 case MAPS_PLACE_ADDRESS:
174                 case MAPS_PLACE_RATING:
175                 case MAPS_PLACE_CATEGORIES:
176                 case MAPS_PLACE_ATTRIBUTES:
177                 case MAPS_PLACE_CONTACTS:
178                 case MAPS_PLACE_EDITORIALS:
179                 case MAPS_PLACE_REVIEWS:
180                 case MAPS_PLACE_IMAGE:
181                 case MAPS_PLACE_SUPPLIER:
182                 case MAPS_PLACE_RELATED:
183                 case MAPS_ROUTE_PATH:
184                 case MAPS_ROUTE_SEGMENTS_PATH:
185                 case MAPS_ROUTE_SEGMENTS_MANEUVERS:
186                 case MAPS_VIEW_TRAFFIC:
187                 case MAPS_VIEW_PUBLIC_TRANSIT:
188                 case MAPS_VIEW_SCALEBAR:
189                         *supported = TRUE;
190                         break;
191                 case MAPS_VIEW_BUILDING:
192                 default:
193                         *supported = FALSE;
194                         break;
195         }
196         return MAPS_ERROR_NONE;
197 }
198
199 EXPORT_API int maps_plugin_geocode(const char* address, const maps_preference_h preference,
200         maps_service_geocode_cb callback, void *user_data, int* request_id)
201 {
202         int ret = HerePluginGeocode(address, preference, callback, user_data, request_id);
203
204         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
205
206         return ConvertToMapsError(ret);
207 }
208
209 EXPORT_API int maps_plugin_geocode_inside_area(const char* address, const maps_area_h bounds,
210         const maps_preference_h preference, maps_service_geocode_cb callback,
211         void* user_data, int* request_id)
212 {
213         int ret = HerePluginGeocodeInsideArea(address, bounds, preference, callback, user_data, request_id);
214
215         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
216
217         return ConvertToMapsError(ret);
218 }
219
220 EXPORT_API int maps_plugin_geocode_by_structured_address(const maps_address_h address,
221         const maps_preference_h preference, maps_service_geocode_cb callback,
222         void *user_data, int* request_id)
223 {
224         int ret = HerePluginGeocodeByStructuredAddress(address, preference, callback, user_data, request_id);
225
226         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
227
228         return ConvertToMapsError(ret);
229 }
230
231 EXPORT_API int maps_plugin_reverse_geocode(double latitude, double longitude,
232         const maps_preference_h preference, maps_service_reverse_geocode_cb callback,
233         void *user_data, int* request_id)
234 {
235         int ret = HerePluginReverseGeocode(latitude, longitude, preference, callback, user_data, request_id);
236
237         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
238
239         return ConvertToMapsError(ret);
240 }
241
242 EXPORT_API int maps_plugin_multi_reverse_geocode(const maps_coordinates_list_h geocode_list,
243         const maps_preference_h preference, maps_service_multi_reverse_geocode_cb callback,
244         void *user_data, int *request_id)
245 {
246         int ret = HerePluginMultiReverseGeocode(geocode_list, preference, callback, user_data, request_id);
247
248         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
249
250         return ConvertToMapsError(ret);
251 }
252
253 EXPORT_API int maps_plugin_search_place(const maps_coordinates_h position, int distance,
254         const maps_place_filter_h filter, maps_preference_h preference, maps_service_search_place_cb callback,
255         void* user_data, int* request_id)
256 {
257         int ret = HerePluginSearchPlace(position, distance, preference, filter, callback, user_data, request_id);
258
259         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
260
261         return ConvertToMapsError(ret);
262 }
263
264 EXPORT_API int maps_plugin_search_place_by_area(const maps_area_h boundary,
265         const maps_place_filter_h filter, maps_preference_h preference, maps_service_search_place_cb callback,
266         void* user_data, int* request_id)
267 {
268         int ret = HerePluginSearchPlaceByArea(boundary, preference, filter, callback, user_data, request_id);
269
270         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
271
272         return ConvertToMapsError(ret);
273 }
274
275 EXPORT_API int maps_plugin_search_place_by_address(const char* address, const maps_area_h boundary,
276         const maps_place_filter_h filter, maps_preference_h preference, maps_service_search_place_cb callback,
277         void* user_data, int* request_id)
278 {
279         int ret = HerePluginSearchPlaceByAddress(address, boundary, preference, filter, callback, user_data, request_id);
280
281         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
282
283         return ConvertToMapsError(ret);
284 }
285
286 EXPORT_API int maps_plugin_search_place_list(const maps_area_h boundary, const maps_place_filter_h filter,
287         maps_preference_h preference, maps_service_search_place_list_cb callback, void* user_data, int* request_id)
288 {
289         int ret = HerePluginSearchPlaceList(boundary, preference, filter, callback, user_data, request_id);
290
291         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
292
293         return ConvertToMapsError(ret);
294 }
295
296 EXPORT_API int maps_plugin_get_place_details(const char* url,
297         maps_service_get_place_details_cb callback, void* user_data, int* request_id)
298 {
299         int ret = HerePluginSearchPlaceDetails(url, callback, user_data, request_id);
300
301         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
302
303         return ConvertToMapsError(ret);
304 }
305
306 EXPORT_API int maps_plugin_search_route(const maps_coordinates_h origin, const maps_coordinates_h destination,
307         maps_preference_h preference, maps_service_search_route_cb callback, void* user_data, int* request_id)
308 {
309         int ret = HerePluginSearchRoute(origin, destination, preference, callback, user_data, request_id);
310
311         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
312
313         return ConvertToMapsError(ret);
314 }
315
316 EXPORT_API int maps_plugin_search_route_waypoints(const maps_coordinates_h* waypoint_list, int waypoint_num,
317         maps_preference_h preference, maps_service_search_route_cb callback,
318         void* user_data, int* request_id)
319 {
320         int ret = HerePluginSearchRouteWaypoints(waypoint_list, waypoint_num, preference, callback, user_data, request_id);
321
322         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
323
324         return ConvertToMapsError(ret);
325 }
326
327 EXPORT_API int maps_plugin_cancel_request(int request_id)
328 {
329         int ret = HerePluginCancelRequest(request_id);
330
331         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
332
333         return ConvertToMapsError(ret);
334 }
335
336 /* Mapping */
337 EXPORT_API int maps_plugin_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc)
338 {
339         int ret = HerePluginCreateMapView(hView, pCbFunc);
340
341         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
342
343         return ConvertToMapsError(ret);
344 }
345
346 EXPORT_API int maps_plugin_destroy_map_view(maps_view_h hView)
347 {
348         int ret = HerePluginDestroyMapView(hView);
349
350         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
351
352         return ConvertToMapsError(ret);
353 }
354
355 EXPORT_API int maps_plugin_render_map(maps_view_h hView,
356         const maps_coordinates_h coordinates, double zoom_factor, double rotation_angle)
357 {
358         int ret = HerePluginRenderMap(hView, coordinates, zoom_factor, rotation_angle);
359
360         if (ret != HERE_ERROR_NONE)
361                 MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
362
363         return ConvertToMapsError(ret);
364 }
365
366 EXPORT_API int maps_plugin_move_center(maps_view_h hView, int delta_x, int delta_y)
367 {
368         int ret = HerePluginMoveCenter(hView, delta_x, delta_y);
369
370         if (ret != HERE_ERROR_NONE)
371                 MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
372
373         return ConvertToMapsError(ret);
374 }
375
376 EXPORT_API int maps_plugin_set_scalebar(maps_view_h hView, bool enable)
377 {
378         int ret = HerePluginSetScalebar(hView, enable);
379
380         if (ret != HERE_ERROR_NONE)
381                 MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
382
383         return ConvertToMapsError(ret);
384 }
385
386 EXPORT_API int maps_plugin_get_scalebar(maps_view_h hView, bool *enabled)
387 {
388         int ret = HerePluginGetScalebar(hView, enabled);
389         return ConvertToMapsError(ret);
390 }
391
392 EXPORT_API int maps_plugin_on_object(maps_view_h hView, const maps_view_object_h object, maps_view_object_operation_e operation)
393 {
394         int ret = HerePluginOnViewObject(hView, object, operation);
395
396         if (ret != HERE_ERROR_NONE)
397                 MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
398
399         return ConvertToMapsError(ret);
400 }
401
402 EXPORT_API int maps_plugin_screen_to_geography(maps_view_h hView, int x, int y, maps_coordinates_h *mapsCoord)
403 {
404         int ret = HerePluginScreenToGeography(hView, x, y, mapsCoord);
405         return ConvertToMapsError(ret);
406 }
407
408 EXPORT_API int maps_plugin_geography_to_screen(maps_view_h hView, const maps_coordinates_h mapsCoord, int* x, int* y)
409 {
410         int ret = HerePluginGeographyToScreen(hView, mapsCoord, x, y);
411         return ConvertToMapsError(ret);
412 }
413
414 EXPORT_API int maps_plugin_get_min_zoom_level(maps_view_h hView, int *min_zoom_level)
415 {
416         int ret = HerePluginGetMinZoomLevel(hView, min_zoom_level);
417         return ConvertToMapsError(ret);
418 }
419
420 EXPORT_API int maps_plugin_get_max_zoom_level(maps_view_h hView, int *max_zoom_level)
421 {
422         int ret = HerePluginGetMaxZoomLevel(hView, max_zoom_level);
423         return ConvertToMapsError(ret);
424 }
425
426 EXPORT_API int maps_plugin_get_center(maps_view_h hView, maps_coordinates_h *center)
427 {
428         int ret = HerePluginGetCenter(hView, center);
429         return ConvertToMapsError(ret);
430 }
431
432 EXPORT_API int maps_plugin_capture_snapshot(maps_view_h view, void **data,
433         int *width, int *height, maps_view_colorspace_type_e *cs)
434 {
435         int ret = HerePluginCaptureSnapshot(view, data, width, height, cs);
436
437         if (ret != HERE_ERROR_NONE)
438                 MAPS_LOGD("here_error_e = %d", ret);
439
440         return ConvertToMapsError(ret);
441 }
442
443 EXPORT_API int maps_plugin_get_view_scale_factor(maps_view_h hView, double *scale)
444 {
445         int ret = HerePluginGetViewScale(hView, scale);
446         return ConvertToMapsError(ret);
447 }
448
449 EXPORT_API int maps_plugin_set_view_scale_factor(maps_view_h hView, double scale)
450 {
451         int ret = HerePluginSetViewScale(hView, scale);
452         return ConvertToMapsError(ret);
453 }
454
455 } // end of extern "C"
456