1 /* Copyright (c) 2010-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 "maps_error.h"
19 #include "maps_route_maneuver_plugin.h"
20 #include "maps_extra_types.h"
21 #include "maps_util.h"
22 #include "maps_condition.h"
24 typedef struct _maps_route_maneuver_s
26 maps_route_direction_e direction_id;
27 maps_route_turn_type_e turn_type;
28 maps_coordinates_h position;
29 char *instruction_text;
31 char *locale; /* locale of instruction_text; */
32 int time_to_next_instruction; /* duration */
33 double distance_to_next_instruction; /* distance */
34 } maps_route_maneuver_s;
36 const gsize _MAPS_ROUTE_MANEUVER_ROAD_NAME_MAX_LENGTH = MAPS_BASE_NAME_MAX_LEN;
37 const gsize _MAPS_ROUTE_MANEUVER_INSTRUCTION_TEXT_MAX_LENGTH = MAPS_BASE_DESC_MAX_LEN;
38 const gsize _MAPS_ROUTE_MANEUVER_LOCALE_MAX_LENGTH = MAPS_BASE_TYPE_MAX_LEN;
40 /*----------------------------------------------------------------------------*/
42 EXPORT_API int maps_route_maneuver_create(maps_route_maneuver_h *maneuver)
44 if (!maps_condition_check_maps_feature())
45 return MAPS_ERROR_NOT_SUPPORTED;
47 return MAPS_ERROR_INVALID_PARAMETER;
48 *maneuver = (maps_route_maneuver_h) g_slice_new0(maps_route_maneuver_s);
50 if (*maneuver == NULL) {
51 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
52 return MAPS_ERROR_OUT_OF_MEMORY;
55 return MAPS_ERROR_NONE;
58 EXPORT_API int maps_route_maneuver_destroy(maps_route_maneuver_h maneuver)
60 if (!maps_condition_check_maps_feature())
61 return MAPS_ERROR_NOT_SUPPORTED;
63 return MAPS_ERROR_INVALID_PARAMETER;
65 maps_route_maneuver_s *p = (maps_route_maneuver_s *) maneuver;
68 maps_coordinates_destroy(p->position);
69 if (p->instruction_text)
70 g_free(p->instruction_text);
76 g_slice_free(maps_route_maneuver_s, maneuver);
77 return MAPS_ERROR_NONE;
80 EXPORT_API int maps_route_maneuver_clone(const maps_route_maneuver_h origin,
81 maps_route_maneuver_h *cloned)
83 if (!maps_condition_check_maps_feature())
84 return MAPS_ERROR_NOT_SUPPORTED;
85 if (!cloned || !origin)
86 return MAPS_ERROR_INVALID_PARAMETER;
88 int error = MAPS_ERROR_NONE;
90 error = maps_route_maneuver_create(cloned);
91 if (!(*cloned) || (error != MAPS_ERROR_NONE))
94 maps_route_maneuver_s *p = (maps_route_maneuver_s *) origin;
96 error = maps_route_maneuver_set_direction_id(*cloned, p->direction_id);
97 if (error != MAPS_ERROR_NONE)
100 error = maps_route_maneuver_set_turn_type(*cloned, p->turn_type);
101 if (error != MAPS_ERROR_NONE)
105 error = maps_route_maneuver_set_position(*cloned, p->position);
106 if (error != MAPS_ERROR_NONE)
110 if (p->instruction_text) {
111 error = maps_route_maneuver_set_instruction_text(*cloned, p->instruction_text);
112 if (error != MAPS_ERROR_NONE)
117 error = maps_route_maneuver_set_road_name(*cloned, p->road_name);
118 if (error != MAPS_ERROR_NONE)
123 error = maps_route_maneuver_set_locale(*cloned, p->locale);
124 if (error != MAPS_ERROR_NONE)
128 error = maps_route_maneuver_set_time_to_next_instruction
129 (*cloned, p->time_to_next_instruction);
130 if (error != MAPS_ERROR_NONE)
133 error = maps_route_maneuver_set_distance_to_next_instruction
134 (*cloned, p->distance_to_next_instruction);
135 if (error != MAPS_ERROR_NONE)
138 return MAPS_ERROR_NONE;
141 maps_route_maneuver_destroy(*cloned);
146 /*----------------------------------------------------------------------------*/
148 EXPORT_API int maps_route_maneuver_get_direction_id(const maps_route_maneuver_h maneuver,
149 maps_route_direction_e *direction_id)
151 if (!maps_condition_check_maps_feature())
152 return MAPS_ERROR_NOT_SUPPORTED;
153 if (!maneuver || !direction_id)
154 return MAPS_ERROR_INVALID_PARAMETER;
155 *direction_id = ((maps_route_maneuver_s *) maneuver)->direction_id;
156 return MAPS_ERROR_NONE;
159 EXPORT_API int maps_route_maneuver_get_turn_type(const maps_route_maneuver_h maneuver,
160 maps_route_turn_type_e *turn_type)
162 if (!maps_condition_check_maps_feature())
163 return MAPS_ERROR_NOT_SUPPORTED;
164 if (!maneuver || !turn_type)
165 return MAPS_ERROR_INVALID_PARAMETER;
166 *turn_type = ((maps_route_maneuver_s *) maneuver)->turn_type;
167 return MAPS_ERROR_NONE;
170 EXPORT_API int maps_route_maneuver_get_position(const maps_route_maneuver_h maneuver,
171 maps_coordinates_h *position)
173 if (!maps_condition_check_maps_feature())
174 return MAPS_ERROR_NOT_SUPPORTED;
175 if (!maneuver || !position)
176 return MAPS_ERROR_INVALID_PARAMETER;
177 if (!((maps_route_maneuver_s *) maneuver)->position)
178 return MAPS_ERROR_NOT_FOUND;
179 return maps_coordinates_clone(((maps_route_maneuver_s *) maneuver)->position, position);
182 EXPORT_API int maps_route_maneuver_get_road_name(const maps_route_maneuver_h maneuver,
185 if (!maps_condition_check_maps_feature())
186 return MAPS_ERROR_NOT_SUPPORTED;
187 if (!maneuver || !road_name)
188 return MAPS_ERROR_INVALID_PARAMETER;
189 if (!((maps_route_maneuver_s *) maneuver)->road_name)
190 return MAPS_ERROR_NOT_FOUND;
191 return maps_get_string(((maps_route_maneuver_s *) maneuver)->road_name,
192 _MAPS_ROUTE_MANEUVER_ROAD_NAME_MAX_LENGTH, road_name);
195 EXPORT_API int maps_route_maneuver_get_instruction_text(const maps_route_maneuver_h maneuver,
196 char ** instruction_text)
198 if (!maps_condition_check_maps_feature())
199 return MAPS_ERROR_NOT_SUPPORTED;
200 if (!maneuver || !instruction_text)
201 return MAPS_ERROR_INVALID_PARAMETER;
202 if (!((maps_route_maneuver_s *) maneuver)->instruction_text)
203 return MAPS_ERROR_NOT_FOUND;
204 return maps_get_string(((maps_route_maneuver_s *) maneuver)->instruction_text,
205 _MAPS_ROUTE_MANEUVER_INSTRUCTION_TEXT_MAX_LENGTH, instruction_text);
208 EXPORT_API int maps_route_maneuver_get_locale(const maps_route_maneuver_h maneuver,
211 if (!maps_condition_check_maps_feature())
212 return MAPS_ERROR_NOT_SUPPORTED;
213 if (!maneuver || !locale)
214 return MAPS_ERROR_INVALID_PARAMETER;
215 if (!((maps_route_maneuver_s *) maneuver)->locale)
216 return MAPS_ERROR_NOT_FOUND;
217 return maps_get_string(((maps_route_maneuver_s *) maneuver)->locale,
218 _MAPS_ROUTE_MANEUVER_LOCALE_MAX_LENGTH, locale);
221 EXPORT_API int maps_route_maneuver_get_time_to_next_instruction(const
222 maps_route_maneuver_h maneuver,
223 int *time_to_next_instruction)
225 if (!maps_condition_check_maps_feature())
226 return MAPS_ERROR_NOT_SUPPORTED;
227 if (!maneuver || !time_to_next_instruction)
228 return MAPS_ERROR_INVALID_PARAMETER;
229 *time_to_next_instruction =
230 ((maps_route_maneuver_s *) maneuver)->time_to_next_instruction;
231 return MAPS_ERROR_NONE;
234 EXPORT_API int maps_route_maneuver_get_distance_to_next_instruction(const
235 maps_route_maneuver_h maneuver,
236 double *distance_to_next_instruction)
238 if (!maps_condition_check_maps_feature())
239 return MAPS_ERROR_NOT_SUPPORTED;
240 if (!maneuver || !distance_to_next_instruction)
241 return MAPS_ERROR_INVALID_PARAMETER;
242 *distance_to_next_instruction =
243 ((maps_route_maneuver_s *) maneuver)->distance_to_next_instruction;
244 return MAPS_ERROR_NONE;
247 /*----------------------------------------------------------------------------*/
249 EXPORT_API int maps_route_maneuver_set_direction_id(maps_route_maneuver_h maneuver,
250 const maps_route_direction_e direction_id)
252 if (!maps_condition_check_maps_feature())
253 return MAPS_ERROR_NOT_SUPPORTED;
255 return MAPS_ERROR_INVALID_PARAMETER;
256 if ((direction_id < MAPS_ROUTE_DIRECTION_NONE)
257 || (direction_id > MAPS_ROUTE_DIRECTION_EAST))
258 return MAPS_ERROR_INVALID_PARAMETER;
259 ((maps_route_maneuver_s *) maneuver)->direction_id = direction_id;
260 return MAPS_ERROR_NONE;
263 EXPORT_API int maps_route_maneuver_set_turn_type(maps_route_maneuver_h maneuver,
264 const maps_route_turn_type_e turn_type)
266 if (!maps_condition_check_maps_feature())
267 return MAPS_ERROR_NOT_SUPPORTED;
269 return MAPS_ERROR_INVALID_PARAMETER;
270 if ((turn_type < MAPS_ROUTE_TURN_TYPE_NONE)
271 || (turn_type > MAPS_ROUTE_TURN_TYPE_STRAIGHT_FORK))
272 return MAPS_ERROR_INVALID_PARAMETER;
273 ((maps_route_maneuver_s *) maneuver)->turn_type = turn_type;
274 return MAPS_ERROR_NONE;
277 EXPORT_API int maps_route_maneuver_set_position(maps_route_maneuver_h maneuver,
278 const maps_coordinates_h position)
280 if (!maps_condition_check_maps_feature())
281 return MAPS_ERROR_NOT_SUPPORTED;
282 if (!maneuver || !position)
283 return MAPS_ERROR_INVALID_PARAMETER;
284 maps_route_maneuver_s *p = (maps_route_maneuver_s *) maneuver;
286 maps_coordinates_destroy(p->position);
287 return maps_coordinates_clone(position, &p->position);
290 EXPORT_API int maps_route_maneuver_set_road_name(maps_route_maneuver_h maneuver,
291 const char *road_name)
293 if (!maps_condition_check_maps_feature())
294 return MAPS_ERROR_NOT_SUPPORTED;
295 if (!maneuver || !road_name)
296 return MAPS_ERROR_INVALID_PARAMETER;
297 return maps_set_string(road_name,
298 _MAPS_ROUTE_MANEUVER_ROAD_NAME_MAX_LENGTH,
299 &((maps_route_maneuver_s *) maneuver)->road_name);
302 EXPORT_API int maps_route_maneuver_set_instruction_text(maps_route_maneuver_h maneuver,
303 const char * instruction_text)
305 if (!maps_condition_check_maps_feature())
306 return MAPS_ERROR_NOT_SUPPORTED;
307 if (!maneuver || !instruction_text)
308 return MAPS_ERROR_INVALID_PARAMETER;
309 return maps_set_string(instruction_text,
310 _MAPS_ROUTE_MANEUVER_INSTRUCTION_TEXT_MAX_LENGTH,
311 &((maps_route_maneuver_s *) maneuver)->instruction_text);
314 EXPORT_API int maps_route_maneuver_set_locale(maps_route_maneuver_h maneuver,
317 if (!maps_condition_check_maps_feature())
318 return MAPS_ERROR_NOT_SUPPORTED;
319 if (!maneuver || !locale)
320 return MAPS_ERROR_INVALID_PARAMETER;
321 maps_route_maneuver_s *p = (maps_route_maneuver_s *) maneuver;
322 return maps_set_string(locale, _MAPS_ROUTE_MANEUVER_LOCALE_MAX_LENGTH, &p->locale);
325 EXPORT_API int maps_route_maneuver_set_time_to_next_instruction(
326 maps_route_maneuver_h maneuver,
327 const int time_to_next_instruction)
329 if (!maps_condition_check_maps_feature())
330 return MAPS_ERROR_NOT_SUPPORTED;
331 if (!maneuver || time_to_next_instruction < 0)
332 return MAPS_ERROR_INVALID_PARAMETER;
333 ((maps_route_maneuver_s *) maneuver)->time_to_next_instruction =
334 time_to_next_instruction;
335 return MAPS_ERROR_NONE;
338 EXPORT_API int maps_route_maneuver_set_distance_to_next_instruction(
339 maps_route_maneuver_h maneuver,
340 const double distance_to_next_instruction)
342 if (!maps_condition_check_maps_feature())
343 return MAPS_ERROR_NOT_SUPPORTED;
344 if (!maneuver || distance_to_next_instruction < 0)
345 return MAPS_ERROR_INVALID_PARAMETER;
346 ((maps_route_maneuver_s *) maneuver)->distance_to_next_instruction =
347 distance_to_next_instruction;
348 return MAPS_ERROR_NONE;