Tizen C++ Coding Rules
[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_set_provider_key(const char* provider_key)
65 {
66         int ret = HerePluginSetProviderKey(provider_key);
67
68         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
69
70         return ConvertToMapsError(ret);
71 }
72
73 EXPORT_API int maps_plugin_get_provider_key(char** provider_key)
74 {
75         int ret = HerePluginGetProviderKey(provider_key);
76
77         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
78
79         return ConvertToMapsError(ret);
80 }
81
82 EXPORT_API int maps_plugin_set_preference(maps_preference_h preference)
83 {
84         int ret = HerePluginSetPreference(preference);
85
86         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
87
88         return ConvertToMapsError(ret);
89 }
90
91 EXPORT_API int maps_plugin_get_preference(maps_preference_h* preference)
92 {
93         int ret = HerePluginGetPreference(preference);
94
95         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
96
97         return ConvertToMapsError(ret);
98 }
99
100 EXPORT_API int maps_plugin_is_service_supported(maps_service_e service, bool *supported)
101 {
102         if (!supported)
103                 return MAPS_ERROR_INVALID_PARAMETER;
104
105         switch(service)
106         {
107                 case MAPS_SERVICE_GEOCODE:
108                 case MAPS_SERVICE_GEOCODE_INSIDE_AREA:
109                 case MAPS_SERVICE_GEOCODE_BY_STRUCTURED_ADDRESS:
110                 case MAPS_SERVICE_REVERSE_GEOCODE:
111                 case MAPS_SERVICE_SEARCH_PLACE:
112                 case MAPS_SERVICE_SEARCH_PLACE_BY_AREA:
113                 case MAPS_SERVICE_SEARCH_PLACE_BY_ADDRESS:
114                 case MAPS_SERVICE_SEARCH_ROUTE:
115                 case MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS:
116                 case MAPS_SERVICE_CANCEL_REQUEST:
117                 case MAPS_SERVICE_MULTI_REVERSE_GEOCODE:
118                 case MAPS_SERVICE_SEARCH_PLACE_LIST:
119                 case MAPS_SERVICE_SEARCH_GET_PLACE_DETAILS:
120                 case MAPS_SERVICE_VIEW:
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                 case MAPS_VIEW_TRAFFIC:
151                 case MAPS_VIEW_PUBLIC_TRANSIT:
152                 case MAPS_VIEW_SCALEBAR:
153                         *supported = TRUE;
154                         break;
155                 case MAPS_VIEW_BUILDING:
156                 default:
157                         *supported = FALSE;
158                         break;
159         }
160         return MAPS_ERROR_NONE;
161 }
162
163 EXPORT_API int maps_plugin_geocode(const char* address, const maps_preference_h preference,
164         maps_service_geocode_cb callback, void *user_data, int* request_id)
165 {
166         int ret = HerePluginGeocode(address, preference, callback, user_data, request_id);
167
168         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
169
170         return ConvertToMapsError(ret);
171 }
172
173 EXPORT_API int maps_plugin_geocode_inside_area(const char* address, const maps_area_h bounds,
174         const maps_preference_h preference, maps_service_geocode_cb callback,
175         void* user_data, int* request_id)
176 {
177         int ret = HerePluginGeocodeInsideArea(address, bounds, preference, callback, user_data, request_id);
178
179         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
180
181         return ConvertToMapsError(ret);
182 }
183
184 EXPORT_API int maps_plugin_geocode_by_structured_address(const maps_address_h address,
185         const maps_preference_h preference, maps_service_geocode_cb callback,
186         void *user_data, int* request_id)
187 {
188         int ret = HerePluginGeocodeByStructuredAddress(address, preference, callback, user_data, request_id);
189
190         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
191
192         return ConvertToMapsError(ret);
193 }
194
195 EXPORT_API int maps_plugin_reverse_geocode(double latitude, double longitude,
196         const maps_preference_h preference, maps_service_reverse_geocode_cb callback,
197         void *user_data, int* request_id)
198 {
199         int ret = HerePluginReverseGeocode(latitude, longitude, preference, callback, user_data, request_id);
200
201         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
202
203         return ConvertToMapsError(ret);
204 }
205
206 EXPORT_API int maps_plugin_multi_reverse_geocode(const maps_coordinates_list_h geocode_list,
207         const maps_preference_h preference, maps_service_multi_reverse_geocode_cb callback,
208         void *user_data, int *request_id)
209 {
210         int ret = HerePluginMultiReverseGeocode(geocode_list, preference, callback, user_data, request_id);
211
212         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
213
214         return ConvertToMapsError(ret);
215 }
216
217 EXPORT_API int maps_plugin_search_place(const maps_coordinates_h position, int distance,
218         const maps_place_filter_h filter, maps_preference_h preference, maps_service_search_place_cb callback,
219         void* user_data, int* request_id)
220 {
221         int ret = HerePluginSearchPlace(position, distance, preference, filter, callback, user_data, request_id);
222
223         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
224
225         return ConvertToMapsError(ret);
226 }
227
228 EXPORT_API int maps_plugin_search_place_by_area(const maps_area_h boundary,
229         const maps_place_filter_h filter, maps_preference_h preference, maps_service_search_place_cb callback,
230         void* user_data, int* request_id)
231 {
232         int ret = HerePluginSearchPlaceByArea(boundary, preference, filter, callback, user_data, request_id);
233
234         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
235
236         return ConvertToMapsError(ret);
237 }
238
239 EXPORT_API int maps_plugin_search_place_by_address(const char* address, const maps_area_h boundary,
240         const maps_place_filter_h filter, maps_preference_h preference, maps_service_search_place_cb callback,
241         void* user_data, int* request_id)
242 {
243         int ret = HerePluginSearchPlaceByAddress(address, boundary, preference, filter, callback, user_data, request_id);
244
245         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
246
247         return ConvertToMapsError(ret);
248 }
249
250 EXPORT_API int maps_plugin_search_place_list(const maps_area_h boundary, const maps_place_filter_h filter,
251         maps_preference_h preference, maps_service_search_place_list_cb callback, void* user_data, int* request_id)
252 {
253         int ret = HerePluginSearchPlaceList(boundary, preference, filter, callback, user_data, request_id);
254
255         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
256
257         return ConvertToMapsError(ret);
258 }
259
260 EXPORT_API int maps_plugin_get_place_details(const char* url,
261         maps_service_get_place_details_cb callback, void* user_data, int* request_id)
262 {
263         int ret = HerePluginSearchPlaceDetails(url, callback, user_data, request_id);
264
265         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
266
267         return ConvertToMapsError(ret);
268 }
269
270 EXPORT_API int maps_plugin_search_route(const maps_coordinates_h origin, const maps_coordinates_h destination,
271         maps_preference_h preference, maps_service_search_route_cb callback, void* user_data, int* request_id)
272 {
273         int ret = HerePluginSearchRoute(origin, destination, preference, callback, user_data, request_id);
274
275         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
276
277         return ConvertToMapsError(ret);
278 }
279
280 EXPORT_API int maps_plugin_search_route_waypoints(const maps_coordinates_h* waypoint_list, int waypoint_num,
281         maps_preference_h preference, maps_service_search_route_cb callback,
282         void* user_data, int* request_id)
283 {
284         int ret = HerePluginSearchRouteWaypoints(waypoint_list, waypoint_num, preference, callback, user_data, request_id);
285
286         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
287
288         return ConvertToMapsError(ret);
289 }
290
291 EXPORT_API int maps_plugin_cancel_request(int request_id)
292 {
293         int ret = HerePluginCancelRequest(request_id);
294
295         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
296
297         return ConvertToMapsError(ret);
298 }
299
300 /* Mapping */
301 EXPORT_API int maps_plugin_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc)
302 {
303         int ret = HerePluginCreateMapView(hView, pCbFunc);
304
305         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
306
307         return ConvertToMapsError(ret);
308 }
309
310 EXPORT_API int maps_plugin_destroy_map_view(maps_view_h hView)
311 {
312         int ret = HerePluginDestroyMapView(hView);
313
314         MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
315
316         return ConvertToMapsError(ret);
317 }
318
319 EXPORT_API int maps_plugin_render_map(maps_view_h hView,
320         const maps_coordinates_h coordinates, double zoom_factor, double rotation_angle)
321 {
322         int ret = HerePluginRenderMap(hView, coordinates, zoom_factor, rotation_angle);
323
324         if (ret != HERE_ERROR_NONE)
325                 MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
326
327         return ConvertToMapsError(ret);
328 }
329
330 EXPORT_API int maps_plugin_move_center(maps_view_h hView, int delta_x, int delta_y)
331 {
332         int ret = HerePluginMoveCenter(hView, delta_x, delta_y);
333
334         if (ret != HERE_ERROR_NONE)
335                 MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
336
337         return ConvertToMapsError(ret);
338 }
339
340 EXPORT_API int maps_plugin_set_scalebar(maps_view_h hView, bool enable)
341 {
342         int ret = HerePluginSetScalebar(hView, enable);
343
344         if (ret != HERE_ERROR_NONE)
345                 MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
346
347         return ConvertToMapsError(ret);
348 }
349
350 EXPORT_API int maps_plugin_get_scalebar(maps_view_h hView, bool *enabled)
351 {
352         int ret = HerePluginGetScalebar(hView, enabled);
353         return ConvertToMapsError(ret);
354 }
355
356 EXPORT_API int maps_plugin_on_object(maps_view_h hView, const maps_view_object_h object, maps_view_object_operation_e operation)
357 {
358         int ret = HerePluginOnViewObject(hView, object, operation);
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_screen_to_geography(maps_view_h hView, int x, int y, maps_coordinates_h *mapsCoord)
367 {
368         int ret = HerePluginScreenToGeography(hView, x, y, mapsCoord);
369         return ConvertToMapsError(ret);
370 }
371
372 EXPORT_API int maps_plugin_geography_to_screen(maps_view_h hView, const maps_coordinates_h mapsCoord, int* x, int* y)
373 {
374         int ret = HerePluginGeographyToScreen(hView, mapsCoord, x, y);
375         return ConvertToMapsError(ret);
376 }
377
378 EXPORT_API int maps_plugin_get_min_zoom_level(maps_view_h hView, int *min_zoom_level)
379 {
380         int ret = HerePluginGetMinZoomLevel(hView, min_zoom_level);
381         return ConvertToMapsError(ret);
382 }
383
384 EXPORT_API int maps_plugin_get_max_zoom_level(maps_view_h hView, int *max_zoom_level)
385 {
386         int ret = HerePluginGetMaxZoomLevel(hView, max_zoom_level);
387         return ConvertToMapsError(ret);
388 }
389
390 EXPORT_API int maps_plugin_get_center(maps_view_h hView, maps_coordinates_h *center)
391 {
392         int ret = HerePluginGetCenter(hView, center);
393         return ConvertToMapsError(ret);
394 }
395
396 } // end of extern "C"
397