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