tizen 2.4 release
[framework/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         if (!plugin)
31                 return MAPS_ERROR_INVALID_PARAMETER;
32
33         int ret = HerePluginInit(plugin);
34
35         MAPS_LOGD("here_error_e = %d", ret);
36
37         return ConvertToMapsError(ret);
38 }
39
40 EXPORT_API int maps_plugin_shutdown(maps_plugin_h plugin)
41 {
42         if (!plugin)
43                 return MAPS_ERROR_INVALID_PARAMETER;
44
45         int ret = HerePluginShutdown(plugin);
46
47         MAPS_LOGD("here_error_e = %d", ret);
48
49         return ConvertToMapsError(ret);
50 }
51
52 EXPORT_API int maps_plugin_get_info(maps_plugin_info_h* info)
53 {
54         if (!info)
55                 return MAPS_ERROR_INVALID_PARAMETER;
56
57         maps_plugin_info_create(info);
58         maps_plugin_info_set_provider_name(*info, "HERE");
59
60         return MAPS_ERROR_NONE;
61 }
62
63 EXPORT_API int maps_plugin_set_provider_key(const char* provider_key)
64 {
65         if (!provider_key)
66                 return MAPS_ERROR_INVALID_PARAMETER;
67
68         int ret = HerePluginSetProviderKey(provider_key);
69
70         MAPS_LOGD("here_error_e = %d", ret);
71
72         return ConvertToMapsError(ret);
73 }
74
75 EXPORT_API int maps_plugin_get_provider_key(char** provider_key)
76 {
77         if (!provider_key)
78                 return MAPS_ERROR_INVALID_PARAMETER;
79
80         int ret = HerePluginGetProviderKey(provider_key);
81
82         MAPS_LOGD("here_error_e = %d", ret);
83
84         return ConvertToMapsError(ret);
85 }
86
87 EXPORT_API int maps_plugin_set_preference(maps_preference_h preference)
88 {
89         if (!preference)
90                 return MAPS_ERROR_INVALID_PARAMETER;
91
92         int ret = HerePluginSetPreference(preference);
93
94         MAPS_LOGD("here_error_e = %d", ret);
95
96         return ConvertToMapsError(ret);
97 }
98
99 EXPORT_API int maps_plugin_get_preference(maps_preference_h* preference)
100 {
101         if (!preference)
102                 return MAPS_ERROR_INVALID_PARAMETER;
103
104         int ret = HerePluginGetPreference(preference);
105
106         MAPS_LOGD("here_error_e = %d", ret);
107
108         return ConvertToMapsError(ret);
109 }
110
111 EXPORT_API int maps_plugin_is_service_supported(maps_service_e service, bool *supported)
112 {
113         if (!supported)
114                 return MAPS_ERROR_INVALID_PARAMETER;
115
116         switch(service)
117         {
118                 case MAPS_SERVICE_GEOCODE:
119                 case MAPS_SERVICE_GEOCODE_INSIDE_AREA:
120                 case MAPS_SERVICE_GEOCODE_BY_STRUCTURED_ADDRESS:
121                 case MAPS_SERVICE_REVERSE_GEOCODE:
122                 case MAPS_SERVICE_SEARCH_PLACE:
123                 case MAPS_SERVICE_SEARCH_PLACE_BY_AREA:
124                 case MAPS_SERVICE_SEARCH_PLACE_BY_ADDRESS:
125                 case MAPS_SERVICE_SEARCH_ROUTE:
126                 case MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS:
127                 case MAPS_SERVICE_CANCEL_REQUEST:
128                         *supported = TRUE;
129                         return MAPS_ERROR_NONE;
130                 default:
131                         *supported = FALSE;
132                         return MAPS_ERROR_NOT_SUPPORTED;
133         }
134 }
135
136 EXPORT_API int maps_plugin_is_data_supported(maps_service_data_e service, bool *supported)
137 {
138         if (!supported)
139                 return MAPS_ERROR_INVALID_PARAMETER;
140
141         switch(service)
142         {
143                 case MAPS_PLACE_ADDRESS:
144                 case MAPS_PLACE_RATING:
145                 case MAPS_PLACE_CATEGORIES:
146                 case MAPS_PLACE_ATTRIBUTES:
147                 case MAPS_PLACE_CONTACTS:
148                 case MAPS_PLACE_EDITORIALS:
149                 case MAPS_PLACE_REVIEWS:
150                 case MAPS_PLACE_IMAGE:
151                 case MAPS_PLACE_SUPPLIER:
152                 case MAPS_PLACE_RELATED:
153                 case MAPS_ROUTE_PATH:
154                 case MAPS_ROUTE_SEGMENTS_PATH:
155                 case MAPS_ROUTE_SEGMENTS_MANEUVERS:
156                         *supported = TRUE;
157                         return MAPS_ERROR_NONE;
158                 default:
159                         *supported = FALSE;
160                         return MAPS_ERROR_NOT_SUPPORTED;
161         }
162 }
163
164 EXPORT_API int maps_plugin_geocode(const char* address, const maps_preference_h preference,
165         maps_service_geocode_cb callback, void *user_data, int* request_id)
166 {
167         if (!address || !callback || !request_id)
168                 return MAPS_ERROR_INVALID_PARAMETER;
169
170         int ret = HerePluginGeocode(address, preference, callback, user_data, request_id);
171
172         MAPS_LOGD("here_error_e = %d", ret);
173
174         return ConvertToMapsError(ret);
175 }
176
177 EXPORT_API int maps_plugin_geocode_inside_area(const char* address, const maps_area_h bounds,
178         const maps_preference_h preference, maps_service_geocode_cb callback,
179         void* user_data, int* request_id)
180 {
181         if (!bounds || !address || !callback || !request_id)
182                 return MAPS_ERROR_INVALID_PARAMETER;
183
184         int ret = HerePluginGeocodeInsideArea(address, bounds, 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_geocode_by_structured_address(const maps_address_h address,
192         const maps_preference_h preference, maps_service_geocode_cb callback,
193         void *user_data, int* request_id)
194 {
195         if (!address || !callback || !request_id)
196                 return MAPS_ERROR_INVALID_PARAMETER;
197
198         int ret = HerePluginGeocodeByStructuredAddress(address, preference, callback, user_data, request_id);
199
200         MAPS_LOGD("here_error_e = %d", ret);
201
202         return ConvertToMapsError(ret);
203 }
204
205 EXPORT_API int maps_plugin_reverse_geocode(double latitude, double longitude,
206         const maps_preference_h preference, maps_service_reverse_geocode_cb callback,
207         void *user_data, int* request_id)
208 {
209         if (!callback || !request_id)
210                 return MAPS_ERROR_INVALID_PARAMETER;
211
212         int ret = HerePluginReverseGeocode(latitude, longitude, preference, callback, user_data, request_id);
213
214         MAPS_LOGD("here_error_e = %d", ret);
215
216         return ConvertToMapsError(ret);
217 }
218
219 EXPORT_API int maps_plugin_search_place(const maps_coordinates_h position, int distance,
220         const maps_place_filter_h filter, maps_preference_h preference, maps_service_search_place_cb callback,
221         void* user_data, int* request_id)
222 {
223         if (!position || !filter || !callback || !request_id)
224                 return MAPS_ERROR_INVALID_PARAMETER;
225
226         int ret = HerePluginSearchPlace(position, distance, preference, filter, callback, user_data, request_id);
227
228         MAPS_LOGD("here_error_e = %d", ret);
229
230         return ConvertToMapsError(ret);
231 }
232
233 EXPORT_API int maps_plugin_search_place_by_area(const maps_area_h boundary,
234         const maps_place_filter_h filter, maps_preference_h preference, maps_service_search_place_cb callback,
235         void* user_data, int* request_id)
236 {
237         if (!boundary || !filter || !callback || !request_id)
238                 return MAPS_ERROR_INVALID_PARAMETER;
239
240         int ret = HerePluginSearchPlaceByArea(boundary, preference, filter, callback, user_data, request_id);
241
242         MAPS_LOGD("here_error_e = %d", ret);
243
244         return ConvertToMapsError(ret);
245 }
246
247 EXPORT_API int maps_plugin_search_place_by_address(const char* address, const maps_area_h boundary,
248         const maps_place_filter_h filter, maps_preference_h preference, maps_service_search_place_cb callback,
249         void* user_data, int* request_id)
250 {
251         if (!address || !boundary || !filter || !callback || !request_id)
252                 return MAPS_ERROR_INVALID_PARAMETER;
253
254         int ret = HerePluginSearchPlaceByAddress(address, boundary, preference, filter, callback, user_data, request_id);
255
256         MAPS_LOGD("here_error_e = %d", ret);
257
258         return ConvertToMapsError(ret);
259 }
260
261 EXPORT_API int maps_plugin_search_route(const maps_coordinates_h origin, const maps_coordinates_h destination,
262         maps_preference_h preference, maps_service_search_route_cb callback,
263         void* user_data, int* request_id)
264 {
265         if (!origin || !destination || !callback || !request_id)
266                 return MAPS_ERROR_INVALID_PARAMETER;
267
268         int ret = HerePluginSearchRoute(origin, destination, preference, callback, user_data, request_id);
269
270         MAPS_LOGD("here_error_e = %d", ret);
271
272         return ConvertToMapsError(ret);
273 }
274
275 EXPORT_API int maps_plugin_search_route_waypoints(const maps_coordinates_h* waypoint_list, int waypoint_num,
276         maps_preference_h preference, maps_service_search_route_cb callback,
277         void* user_data, int* request_id)
278 {
279         if (!waypoint_list || waypoint_num <= 0 || !callback || !request_id)
280                 return MAPS_ERROR_INVALID_PARAMETER;
281
282         int ret = HerePluginSearchRouteWaypoints(waypoint_list, waypoint_num, preference, callback, user_data, request_id);
283
284         MAPS_LOGD("here_error_e = %d", ret);
285
286         return ConvertToMapsError(ret);
287 }
288
289 EXPORT_API int maps_plugin_cancel_request(int request_id)
290 {
291         if (request_id < 0)
292                 return MAPS_ERROR_INVALID_PARAMETER;
293
294         int ret = HerePluginCancelRequest(request_id);
295
296         MAPS_LOGD("here_error_e = %d", ret);
297
298         return ConvertToMapsError(ret);
299 }
300
301 } // end of extern "C"
302