4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7 * Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
26 #include "location-types.h"
27 #include "location-route.h"
28 #include "location-route-ext.h"
29 #include "location-boundary.h"
30 #include "map-service.h"
33 struct _LocationRoute {
34 // gint req_id; //< Request id : for expandability
35 LocationPosition *origin; //< Coordinate StartCoord
36 LocationPosition *destination; //< Coordinates destCoord
37 LocationBoundary *bbox; //< a rectangular geographical area
38 gdouble total_distance; //< Total distance
39 gchar *distance_unit; //< Distance Unit
40 glong total_duration; //< Total duration
41 GHashTable *properties; //<Key/Value>
46 struct _LocationRouteSegment {
47 LocationPosition *start; //< Coordinate StartCoord;
48 LocationPosition *end; //< Coordinates destCoord;
49 LocationBoundary *bbox; //< a rectangular geographical area
52 GHashTable *properties; //<Key/Value>
57 struct _LocationRouteStep {
58 LocationPosition *start; //< Coordinate StartCoord;
59 LocationPosition *end; //< Coordinates destCoord;
60 LocationBoundary *bbox; //< a rectangular geographical area
63 gchar *transport_mode;
67 GHashTable *properties;
70 struct _LocationRoutePreference {
73 GList* feature_to_avoid;
74 GList* freeformed_addr_to_avoid;
75 LocationBoundary* bbox;
76 guint max_matches_count;
80 gchar *transport_mode;
81 gboolean is_geometry_used;
82 gboolean is_instruction_bounding_box_used;
83 gboolean is_instruction_geometry_used;
84 gboolean is_instruction_used;
85 gboolean is_traffic_data_used;
87 // AvoidFreeways, Easy, Fastest, MoreFreeways, NoFreeways, Pedestrian, Shortest
88 GHashTable *properties;
92 static void route_pref_addr_to_avoid_copy_cb (gpointer data, gpointer user_data)
94 g_return_if_fail(data);
95 g_return_if_fail(user_data);
97 LocationAddress *address = (LocationAddress *)data;
98 LocationRoutePreference *pref = (LocationRoutePreference *)user_data;
100 pref->addr_to_avoid = g_list_append (pref->addr_to_avoid, location_address_copy(address));
103 static void addr_to_avoid_free_cb (gpointer data)
105 g_return_if_fail (data);
107 LocationAddress *addr = (LocationAddress *)data;
109 location_address_free (addr);
113 location_route_pref_set_addr_to_avoid (LocationRoutePreference *pref, GList *addr)
115 g_return_val_if_fail(pref, FALSE);
117 if (pref->addr_to_avoid) {
118 g_list_free_full (pref->addr_to_avoid, addr_to_avoid_free_cb);
119 pref->addr_to_avoid = NULL;
122 if (addr) g_list_foreach (addr, route_pref_addr_to_avoid_copy_cb, pref);
127 static void route_pref_area_to_avoid_copy_cb (gpointer data, gpointer user_data)
129 g_return_if_fail(data);
130 g_return_if_fail(user_data);
132 LocationBoundary *area = (LocationBoundary *)data;
133 LocationRoutePreference *pref = (LocationRoutePreference *)user_data;
135 pref->area_to_avoid = g_list_append (pref->area_to_avoid, location_boundary_copy((const LocationBoundary *)area));
138 static void route_pref_area_to_avoid_free_cb (gpointer data)
140 g_return_if_fail (data);
142 LocationBoundary *boundary = (LocationBoundary *)data;
144 location_boundary_free (boundary);
148 location_route_pref_set_area_to_avoid (LocationRoutePreference *pref, GList *area)
150 g_return_val_if_fail(pref, FALSE);
152 if (pref->area_to_avoid) {
153 g_list_free_full (pref->area_to_avoid, route_pref_area_to_avoid_free_cb);
154 pref->area_to_avoid = NULL;
157 if (area) g_list_foreach (area, route_pref_area_to_avoid_copy_cb, pref);
162 static void route_pref_feature_to_avoid_copy_cb (gpointer data, gpointer user_data)
164 g_return_if_fail (data);
165 g_return_if_fail (user_data);
167 gchar *feature = (gchar *)data;
168 LocationRoutePreference *pref = (LocationRoutePreference *) user_data;
170 pref->feature_to_avoid = g_list_append (pref->feature_to_avoid, g_strdup (feature));
174 location_route_pref_set_feature_to_avoid (LocationRoutePreference *pref, GList * feature)
176 g_return_val_if_fail(pref, FALSE);
178 if (pref->feature_to_avoid) {
179 g_list_free_full (pref->feature_to_avoid, g_free);
180 pref->feature_to_avoid = NULL;
183 g_list_foreach (feature, route_pref_feature_to_avoid_copy_cb, pref);
188 static void route_pref_freeforemd_addr_to_avoid_foreach_copy (gpointer data, gpointer user_data)
190 g_return_if_fail(data);
191 g_return_if_fail(user_data);
193 gchar *freeformed_addr = (gchar *)data;
194 LocationRoutePreference *pref = (LocationRoutePreference *)user_data;
196 pref->freeformed_addr_to_avoid = g_list_append (pref->freeformed_addr_to_avoid, g_strdup(freeformed_addr));
200 location_route_pref_set_freeformed_addr_to_avoid (LocationRoutePreference *pref, GList *freeformed_addr)
202 g_return_val_if_fail(pref, FALSE);
204 if (pref->freeformed_addr_to_avoid) {
205 g_list_free_full (pref->freeformed_addr_to_avoid, g_free);
206 pref->freeformed_addr_to_avoid = NULL;
209 if (freeformed_addr) g_list_foreach (freeformed_addr, route_pref_freeforemd_addr_to_avoid_foreach_copy, pref);
215 location_route_pref_set_bounding_box (LocationRoutePreference *pref, const LocationBoundary *bbox)
217 g_return_val_if_fail(pref, FALSE);
220 location_boundary_free (pref->bbox);
224 if (bbox) pref->bbox = location_boundary_copy (bbox);
230 location_route_pref_set_max_result (LocationRoutePreference *pref, guint max_num)
232 g_return_val_if_fail(pref, FALSE);
233 g_return_val_if_fail(max_num > 0, FALSE);
235 pref->max_matches_count = max_num;
241 location_route_pref_set_route_type (LocationRoutePreference *pref, const gchar *type)
243 g_return_val_if_fail(pref, FALSE);
245 if (pref->route_type) {
246 g_free(pref->route_type);
247 pref->route_type = NULL;
250 if (type) pref->route_type = g_strdup (type);
256 location_route_pref_set_transport_mode (LocationRoutePreference *pref, const gchar *mode)
258 g_return_val_if_fail(pref, FALSE);
260 if (pref->transport_mode) {
261 g_free(pref->transport_mode);
262 pref->transport_mode = NULL;
265 if (mode) pref->transport_mode = g_strdup (mode);
271 location_route_pref_set_geometry_used (LocationRoutePreference *pref, gboolean is_used)
273 g_return_val_if_fail(pref, FALSE);
275 pref->is_geometry_used = is_used;
281 location_route_pref_set_instruction_bounding_box_used (LocationRoutePreference *pref, gboolean is_used)
283 g_return_val_if_fail(pref, FALSE);
285 pref->is_instruction_bounding_box_used = is_used;
291 location_route_pref_set_instruction_geometry_used (LocationRoutePreference *pref, gboolean is_used)
293 g_return_val_if_fail(pref, FALSE);
295 pref->is_instruction_geometry_used = is_used;
301 location_route_pref_set_instruction_used (LocationRoutePreference *pref, gboolean is_used)
303 g_return_val_if_fail(pref, FALSE);
305 pref->is_instruction_used = is_used;
311 location_route_pref_set_traffic_data_used (LocationRoutePreference *pref, gboolean is_used)
313 g_return_val_if_fail(pref, FALSE);
315 pref->is_traffic_data_used = is_used;
321 location_route_pref_set_property (LocationRoutePreference *pref, gconstpointer key, gconstpointer value)
323 g_return_val_if_fail(pref, FALSE);
324 g_return_val_if_fail(key, FALSE);
327 gchar *re_key = g_strdup(key);
328 gchar *re_val = g_strdup(value);
329 g_hash_table_insert (pref->properties, re_key, re_val);
330 } else g_hash_table_remove (pref->properties, key);
336 location_route_pref_get_addr_to_avoid (const LocationRoutePreference *pref)
338 g_return_val_if_fail(pref, NULL);
340 return pref->addr_to_avoid;
344 location_route_pref_get_area_to_avoid (const LocationRoutePreference *pref)
346 g_return_val_if_fail(pref, NULL);
348 return pref->area_to_avoid;
352 location_route_pref_get_feature_to_avoid (const LocationRoutePreference *pref)
354 g_return_val_if_fail(pref, NULL);
356 return pref->feature_to_avoid;
360 location_route_pref_get_freeformed_addr_to_avoid (const LocationRoutePreference *pref)
362 g_return_val_if_fail(pref, NULL);
364 return pref->freeformed_addr_to_avoid;
367 EXPORT_API LocationBoundary *
368 location_route_pref_get_bounding_box (const LocationRoutePreference *pref)
370 g_return_val_if_fail(pref, NULL);
376 location_route_pref_get_max_result (const LocationRoutePreference *pref)
378 g_return_val_if_fail(pref, 0);
380 return pref->max_matches_count;
384 location_route_pref_get_route_type (const LocationRoutePreference *pref)
386 g_return_val_if_fail(pref, NULL);
388 return pref->route_type;
392 location_route_pref_get_transport_mode (const LocationRoutePreference *pref)
394 g_return_val_if_fail(pref, NULL);
396 return pref->transport_mode;
400 location_route_pref_get_geometry_used (const LocationRoutePreference *pref)
402 g_return_val_if_fail(pref, FALSE);
404 return pref->is_geometry_used;
408 location_route_pref_get_instruction_bounding_box_used (const LocationRoutePreference *pref)
410 g_return_val_if_fail(pref, FALSE);
412 return pref->is_instruction_bounding_box_used;
416 location_route_pref_get_instruction_geometry_used (const LocationRoutePreference *pref)
418 g_return_val_if_fail(pref, FALSE);
420 return pref->is_instruction_geometry_used;
424 location_route_pref_get_instruction_used (const LocationRoutePreference *pref)
426 g_return_val_if_fail(pref, FALSE);
428 return pref->is_instruction_used;
432 location_route_pref_get_traffic_data_used (const LocationRoutePreference *pref)
434 g_return_val_if_fail(pref, FALSE);
436 return pref->is_traffic_data_used;
440 location_route_pref_get_property_key (const LocationRoutePreference *pref)
442 g_return_val_if_fail(pref, NULL);
444 return g_hash_table_get_keys(pref->properties);
448 location_route_pref_get_property (const LocationRoutePreference *pref, gconstpointer key)
450 g_return_val_if_fail(pref, NULL);
451 g_return_val_if_fail(key, NULL);
453 return g_hash_table_lookup(pref->properties, key);
456 EXPORT_API LocationRoutePreference *
457 location_route_pref_new (void)
459 LocationRoutePreference *pref = g_slice_new0(LocationRoutePreference);
460 g_return_val_if_fail (pref, NULL);
462 pref->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
466 static void route_pref_property_copy_cb (gpointer key, gpointer value, gpointer user_data)
468 g_return_if_fail(key);
469 g_return_if_fail(value);
470 g_return_if_fail(user_data);
472 LocationRoutePreference *pref = (LocationRoutePreference *)user_data;
474 if (pref->properties) {
475 gchar *re_key = g_strdup (key);
476 gchar *re_val = g_strdup (value);
477 g_hash_table_insert (pref->properties, re_key, re_val);
481 EXPORT_API LocationRoutePreference *
482 location_route_pref_copy (const LocationRoutePreference *pref)
484 g_return_val_if_fail(pref, NULL);
486 LocationRoutePreference *new_pref = location_route_pref_new();
487 g_return_val_if_fail (pref, NULL);
489 location_route_pref_set_addr_to_avoid(new_pref, location_route_pref_get_addr_to_avoid (pref));
490 location_route_pref_set_area_to_avoid(new_pref, location_route_pref_get_area_to_avoid (pref));
491 location_route_pref_set_feature_to_avoid(new_pref, location_route_pref_get_feature_to_avoid (pref));
492 location_route_pref_set_freeformed_addr_to_avoid(new_pref, location_route_pref_get_freeformed_addr_to_avoid (pref));
493 location_route_pref_set_bounding_box(new_pref, location_route_pref_get_bounding_box (pref));
494 location_route_pref_set_max_result(new_pref, location_route_pref_get_max_result (pref));
495 location_route_pref_set_route_type(new_pref, location_route_pref_get_route_type (pref));
496 location_route_pref_set_transport_mode(new_pref, location_route_pref_get_transport_mode (pref));
497 location_route_pref_set_geometry_used(new_pref, location_route_pref_get_geometry_used (pref));
498 location_route_pref_set_instruction_bounding_box_used(new_pref, location_route_pref_get_instruction_bounding_box_used (pref));
499 location_route_pref_set_instruction_geometry_used(new_pref, location_route_pref_get_instruction_geometry_used (pref));
500 location_route_pref_set_instruction_used(new_pref, location_route_pref_get_instruction_used (pref));
501 location_route_pref_set_traffic_data_used(new_pref, location_route_pref_get_traffic_data_used (pref));
502 location_route_pref_set_traffic_data_used(new_pref, location_route_pref_get_traffic_data_used (pref));
504 if (new_pref->properties) g_hash_table_foreach (pref->properties, route_pref_property_copy_cb, new_pref);
511 location_route_pref_free (LocationRoutePreference *pref)
513 g_return_if_fail(pref);
515 location_route_pref_set_addr_to_avoid(pref, NULL);
516 location_route_pref_set_area_to_avoid(pref, NULL);
517 location_route_pref_set_feature_to_avoid(pref, NULL);
518 location_route_pref_set_freeformed_addr_to_avoid(pref, NULL);
519 location_route_pref_set_bounding_box(pref, NULL);
520 location_route_pref_set_route_type(pref, NULL);
521 location_route_pref_set_transport_mode(pref, NULL);
523 if (pref->properties) {
524 g_hash_table_destroy (pref->properties);
525 pref->properties = NULL;
528 g_slice_free (LocationRoutePreference, pref);
533 location_route_get_req_id (const LocationRoute *route)
535 g_return_val_if_fail(route, 0);
537 return route->req_id;
541 EXPORT_API LocationPosition *
542 location_route_get_origin (const LocationRoute *route)
544 g_return_val_if_fail(route, NULL);
546 return route->origin;
549 EXPORT_API LocationPosition *
550 location_route_get_destination (const LocationRoute *route)
552 g_return_val_if_fail(route, NULL);
554 return route->destination;
557 EXPORT_API LocationBoundary *
558 location_route_get_bounding_box (const LocationRoute *route)
560 g_return_val_if_fail(route, NULL);
566 location_route_get_total_distance (const LocationRoute *route)
568 g_return_val_if_fail(route, 0.0);
570 return route->total_distance;
574 location_route_get_distance_unit (const LocationRoute *route)
576 g_return_val_if_fail(route, NULL);
578 return route->distance_unit;
582 location_route_get_total_duration (const LocationRoute *route)
584 g_return_val_if_fail(route, 0);
586 return route->total_duration;
590 location_route_get_property_key (const LocationRoute *route)
592 g_return_val_if_fail(route, NULL);
594 return g_hash_table_get_keys(route->properties);
598 location_route_get_property (const LocationRoute *route, gconstpointer key)
600 g_return_val_if_fail(route, NULL);
601 g_return_val_if_fail(key, NULL);
603 return g_hash_table_lookup(route->properties, key);
607 location_route_get_route_segment (const LocationRoute *route)
609 g_return_val_if_fail(route, NULL);
611 return route->segment;
616 location_route_set_req_id (LocationRoute *route, gint req_id)
618 g_return_val_if_fail(route, FALSE);
620 route->req_id = req_id;
627 location_route_set_origin (LocationRoute *route, const LocationPosition* origin)
629 g_return_val_if_fail(route, FALSE);
632 location_position_free(route->origin);
633 route->origin = NULL;
636 if (origin) route->origin = location_position_copy(origin);
642 location_route_set_destination (LocationRoute *route, const LocationPosition* destination)
644 g_return_val_if_fail(route, FALSE);
646 if (route->destination) {
647 location_position_free(route->destination);
648 route->destination = NULL;
651 if (destination) route->destination = location_position_copy(destination);
657 location_route_set_bounding_box (LocationRoute *route, const LocationBoundary* bbox)
659 g_return_val_if_fail(route, FALSE);
662 location_boundary_free(route->bbox);
666 if (bbox) route->bbox = location_boundary_copy(bbox);
672 gboolean location_route_set_total_distance (LocationRoute *route, gdouble total_distance)
674 g_return_val_if_fail(route, FALSE);
676 route->total_distance = total_distance;
682 gboolean location_route_set_distance_unit (LocationRoute *route, const gchar* distance_unit)
684 g_return_val_if_fail(route, FALSE);
686 if (route->distance_unit) {
687 g_free(route->distance_unit);
688 route->distance_unit = NULL;
691 if (distance_unit) route->distance_unit = g_strdup(distance_unit);
697 location_route_set_total_duration (LocationRoute *route, glong total_duration)
699 g_return_val_if_fail(route, FALSE);
701 route->total_duration = total_duration;
707 location_route_set_property (LocationRoute *route, gconstpointer key, gconstpointer value)
709 g_return_val_if_fail(route, FALSE);
710 g_return_val_if_fail(key, FALSE);
711 if (!route->properties) return FALSE;
714 gchar *re_key = g_strdup (key);
715 gchar *re_val = g_strdup (value);
716 g_hash_table_insert(route->properties, re_key, re_val);
717 } else g_hash_table_remove (route->properties, key);
722 static void route_segment_foreach_copy (gpointer data, gpointer user_data)
724 g_return_if_fail (data);
726 LocationRouteSegment *segment = (LocationRouteSegment *) data;
727 LocationRoute *route = (LocationRoute *) user_data;
729 route->segment = g_list_append (route->segment, location_route_segment_copy (segment));
732 static void route_segment_foreach_free (gpointer data)
734 g_return_if_fail (data);
736 LocationRouteSegment *segment = (LocationRouteSegment *)data;
738 location_route_segment_free(segment);
743 location_route_set_route_segment (LocationRoute *route, GList* segment)
745 g_return_val_if_fail(route, FALSE);
747 if (route->segment) {
748 g_list_free_full (route->segment, route_segment_foreach_free);
749 route->segment = NULL;
752 if (segment) g_list_foreach (segment, route_segment_foreach_copy, route);
757 EXPORT_API LocationRoute *
758 location_route_new (void)
760 LocationRoute *route = g_slice_new0(LocationRoute);
761 g_return_val_if_fail (route, NULL);
763 route->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
768 static void route_property_copy_cb (gpointer key, gpointer value, gpointer user_data)
770 g_return_if_fail (key);
771 g_return_if_fail (value);
772 g_return_if_fail (user_data);
774 LocationRoute *route = (LocationRoute *)user_data;
776 if (route->properties) {
777 gchar *re_key = g_strdup (key);
778 gchar *re_val = g_strdup (value);
779 g_hash_table_insert (route->properties, re_key, re_val);
783 EXPORT_API LocationRoute *
784 location_route_copy (const LocationRoute *route)
786 g_return_val_if_fail(route, NULL);
787 LocationRoute *new_route = location_route_new();
788 g_return_val_if_fail(new_route, NULL);
790 location_route_set_origin (new_route, location_route_get_origin(route));
791 location_route_set_destination (new_route, location_route_get_destination(route));
792 location_route_set_bounding_box (new_route, location_route_get_bounding_box(route));
793 location_route_set_total_distance (new_route, location_route_get_total_distance(route));
794 location_route_set_distance_unit (new_route, location_route_get_distance_unit(route));
795 location_route_set_total_duration (new_route, location_route_get_total_duration(route));
797 g_list_foreach(route->segment, route_segment_foreach_copy, new_route);
799 if (route->properties) g_hash_table_foreach (route->properties, route_property_copy_cb, new_route);
805 location_route_free (LocationRoute *route)
807 g_return_if_fail (route);
809 location_route_set_origin (route, NULL);
810 location_route_set_destination (route, NULL);
811 location_route_set_bounding_box (route, NULL);
812 location_route_set_distance_unit (route, NULL);
813 location_route_set_route_segment (route, NULL);
815 if (route->properties) {
816 g_hash_table_destroy (route->properties);
817 route->properties = NULL;
820 g_slice_free (LocationRoute, route);
823 EXPORT_API LocationPosition *
824 location_route_segment_get_start_point (const LocationRouteSegment *segment)
826 g_return_val_if_fail(segment, NULL);
828 return segment->start;
831 EXPORT_API LocationPosition *
832 location_route_segment_get_end_point (const LocationRouteSegment *segment)
834 g_return_val_if_fail(segment, NULL);
839 EXPORT_API LocationBoundary *
840 location_route_segment_get_bounding_box (const LocationRouteSegment *segment)
842 g_return_val_if_fail(segment, NULL);
844 return segment->bbox;
848 location_route_segment_get_distance (const LocationRouteSegment *segment)
850 g_return_val_if_fail(segment, 0.0);
852 return segment->distance;
856 location_route_segment_get_duration (const LocationRouteSegment *segment)
858 g_return_val_if_fail(segment, 0);
860 return segment->duration;
864 location_route_segment_get_property_key (const LocationRouteSegment *segment)
866 g_return_val_if_fail(segment, NULL);
868 return g_hash_table_get_keys(segment->properties);
872 location_route_segment_get_property (const LocationRouteSegment *segment, gconstpointer key)
874 g_return_val_if_fail(segment, NULL);
875 g_return_val_if_fail(key, NULL);
877 return g_hash_table_lookup(segment->properties, (gpointer) key);
881 location_route_segment_get_route_step (const LocationRouteSegment *segment)
883 g_return_val_if_fail(segment, NULL);
885 return segment->step;
889 location_route_segment_set_start_point (LocationRouteSegment *segment, const LocationPosition *start)
891 g_return_val_if_fail (segment, FALSE);
893 if (segment->start) {
894 location_position_free(segment->start);
895 segment->start = NULL;
898 if (start) segment->start = location_position_copy (start);
904 location_route_segment_set_end_point (LocationRouteSegment *segment, const LocationPosition *end)
906 g_return_val_if_fail (segment, FALSE);
909 location_position_free(segment->end);
913 if (end) segment->end = location_position_copy (end);
920 location_route_segment_set_bounding_box (LocationRouteSegment *segment, const LocationBoundary *bbox)
922 g_return_val_if_fail (segment, FALSE);
925 location_boundary_free(segment->bbox);
926 segment->bbox = NULL;
929 if (bbox) segment->bbox = location_boundary_copy (bbox);
935 location_route_segment_set_distance (LocationRouteSegment *segment, gdouble distance)
937 g_return_val_if_fail (segment, FALSE);
939 segment->distance = distance;
945 location_route_segment_set_duration (LocationRouteSegment *segment, glong duration)
947 g_return_val_if_fail (segment, FALSE);
949 segment->duration = duration;
955 location_route_segment_set_property (LocationRouteSegment *segment, gconstpointer key, gconstpointer value)
957 g_return_val_if_fail (segment, FALSE);
958 g_return_val_if_fail (key, FALSE);
959 if (!segment->properties) return FALSE;
962 gchar *re_key = g_strdup (key);
963 gchar *re_val = g_strdup (value);
964 g_hash_table_insert(segment->properties, re_key, re_val);
965 } else g_hash_table_remove (segment->properties, key);
970 static void route_step_foreach_free (gpointer data)
972 g_return_if_fail (data);
974 LocationRouteStep *step = (LocationRouteStep *) data;
976 location_route_step_free(step);
979 static void route_step_foreach_copy (gpointer data, gpointer user_data)
981 g_return_if_fail (data);
982 g_return_if_fail (user_data);
984 LocationRouteStep *step = (LocationRouteStep *) data;
985 LocationRouteSegment *segment = (LocationRouteSegment *) user_data;
987 LocationRouteStep *step_new = location_route_step_copy(step);
988 segment->step = g_list_append(segment->step, step_new);
993 location_route_segment_set_route_step (LocationRouteSegment *segment, GList* step)
995 g_return_val_if_fail (segment, FALSE);
998 g_list_free_full (segment->step, route_step_foreach_free);
999 segment->step = NULL;
1002 if (step) g_list_foreach (step, route_step_foreach_copy, segment);
1008 EXPORT_API LocationRouteSegment *
1009 location_route_segment_new (void)
1011 LocationRouteSegment *segment = g_slice_new0 (LocationRouteSegment);
1012 g_return_val_if_fail (segment, NULL);
1014 segment->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
1019 static void segment_property_copy_cb (gpointer key, gpointer value, gpointer user_data)
1021 g_return_if_fail (key);
1022 g_return_if_fail (value);
1023 g_return_if_fail (user_data);
1025 LocationRouteSegment *segment = (LocationRouteSegment *)user_data;
1027 if (segment->properties) {
1028 gchar *re_key = g_strdup (key);
1029 gchar *re_val = g_strdup (value);
1030 g_hash_table_insert (segment->properties, re_key, re_val);
1034 EXPORT_API LocationRouteSegment *
1035 location_route_segment_copy (LocationRouteSegment *segment)
1037 g_return_val_if_fail(segment, NULL);
1039 LocationRouteSegment *new_segment = location_route_segment_new();
1040 g_return_val_if_fail(new_segment, NULL);
1042 location_route_segment_set_start_point(new_segment, location_route_segment_get_start_point(segment));
1043 location_route_segment_set_end_point(new_segment, location_route_segment_get_end_point(segment));
1044 location_route_segment_set_bounding_box(new_segment, location_route_segment_get_bounding_box(segment));
1045 location_route_segment_set_distance(new_segment, location_route_segment_get_distance(segment));
1046 location_route_segment_set_duration(new_segment, location_route_segment_get_duration(segment));
1047 location_route_segment_set_route_step(new_segment, location_route_segment_get_route_step(segment));
1049 if (segment->properties) g_hash_table_foreach (segment->properties, segment_property_copy_cb, new_segment);
1055 location_route_segment_free (LocationRouteSegment *segment)
1057 g_return_if_fail(segment);
1059 location_route_segment_set_start_point(segment, NULL);
1060 location_route_segment_set_end_point(segment, NULL);
1061 location_route_segment_set_bounding_box(segment, NULL);
1062 location_route_segment_set_distance(segment, 0.0);
1063 location_route_segment_set_duration(segment, 0);
1064 location_route_segment_set_route_step(segment, NULL);
1066 if (segment->properties) {
1067 g_hash_table_destroy (segment->properties);
1068 segment->properties = NULL;
1071 g_slice_free(LocationRouteSegment, segment);
1074 EXPORT_API LocationPosition*
1075 location_route_step_get_start_point (const LocationRouteStep *step)
1077 g_return_val_if_fail(step, NULL);
1082 EXPORT_API LocationPosition*
1083 location_route_step_get_end_point (const LocationRouteStep *step)
1085 g_return_val_if_fail(step, NULL);
1090 EXPORT_API LocationBoundary*
1091 location_route_step_get_bounding_box (const LocationRouteStep *step)
1093 g_return_val_if_fail(step, NULL);
1099 location_route_step_get_distance (const LocationRouteStep *step)
1101 g_return_val_if_fail(step, 0.0);
1103 return step->distance;
1107 location_route_step_get_duration (const LocationRouteStep *step)
1109 g_return_val_if_fail(step, 0);
1111 return step->duration;
1115 location_route_step_get_transport_mode (const LocationRouteStep *step)
1117 g_return_val_if_fail(step, NULL);
1119 return step->transport_mode;
1123 location_route_step_get_instruction (const LocationRouteStep *step)
1125 g_return_val_if_fail(step, NULL);
1127 return step->instruction;
1131 location_route_step_get_geometry (const LocationRouteStep *step)
1133 g_return_val_if_fail(step, NULL);
1135 return step->geometry;
1139 location_route_step_get_property_key (const LocationRouteStep *step)
1141 g_return_val_if_fail(step, NULL);
1143 return g_hash_table_get_keys (step->properties);
1147 location_route_step_get_property (const LocationRouteStep *step, gconstpointer key)
1149 g_return_val_if_fail(step, NULL);
1150 g_return_val_if_fail(key, NULL);
1152 return g_hash_table_lookup (step->properties, key);
1156 location_route_step_set_start_point (LocationRouteStep *step, const LocationPosition *start)
1158 g_return_val_if_fail (step, FALSE);
1161 location_position_free (step->start);
1165 if (start) step->start = location_position_copy (start);
1171 location_route_step_set_end_point (LocationRouteStep *step, const LocationPosition *end)
1173 g_return_val_if_fail (step, FALSE);
1176 location_position_free (step->end);
1180 if (end) step->end = location_position_copy (end);
1186 location_route_step_set_bounding_box (LocationRouteStep *step, const LocationBoundary *bbox)
1188 g_return_val_if_fail (step, FALSE);
1191 location_boundary_free (step->bbox);
1195 if (bbox) step->bbox = location_boundary_copy (bbox);
1201 location_route_step_set_distance (LocationRouteStep *step, gdouble distance)
1203 g_return_val_if_fail (step, FALSE);
1205 step->distance = distance;
1212 location_route_step_set_duration (LocationRouteStep *step, glong duration)
1214 g_return_val_if_fail (step, FALSE);
1216 step->duration = duration;
1222 location_route_step_set_transport_mode (LocationRouteStep *step, const gchar *transport_mode)
1224 g_return_val_if_fail (step, FALSE);
1226 if (step->transport_mode) {
1227 g_free(step->transport_mode);
1228 step->transport_mode = NULL;
1231 if (transport_mode) step->transport_mode = g_strdup(transport_mode);
1238 location_route_step_set_instruction (LocationRouteStep *step, const gchar *instruction)
1240 g_return_val_if_fail (step, FALSE);
1242 if (step->instruction) {
1243 g_free(step->instruction);
1244 step->instruction = NULL;
1247 if (instruction) step->instruction = g_strdup(instruction);
1253 static void route_step_geometry_foreach_copy (gpointer data, gpointer user_data)
1255 g_return_if_fail (data);
1256 g_return_if_fail (user_data);
1258 LocationPosition *pos = (LocationPosition *)data;
1259 LocationRouteStep *step = (LocationRouteStep *)user_data;
1261 step->geometry = g_list_append (step->geometry, location_position_copy (pos));
1264 static void route_step_geometry_free (gpointer data)
1266 g_return_if_fail (data);
1268 LocationPosition *pos = (LocationPosition *)data;
1270 location_position_free(pos);
1274 location_route_step_set_geometry (LocationRouteStep *step, GList *geometry)
1276 g_return_val_if_fail (step, FALSE);
1278 if (step->geometry) {
1279 g_list_free_full (step->geometry, route_step_geometry_free);
1280 step->geometry = NULL;
1283 if (geometry) g_list_foreach (geometry, route_step_foreach_copy, step);
1290 location_route_step_set_property (LocationRouteStep *step, gconstpointer key, gconstpointer value)
1292 g_return_val_if_fail(step, FALSE);
1293 g_return_val_if_fail(key, FALSE);
1295 if (!step->properties) return FALSE;
1298 gchar *re_key = g_strdup (key);
1299 gchar *re_val = g_strdup (value);
1300 g_hash_table_insert (step->properties, re_key, re_val);
1302 else g_hash_table_remove (step->properties, key);
1307 EXPORT_API LocationRouteStep *
1308 location_route_step_new (void)
1310 LocationRouteStep *step = g_slice_new0 (LocationRouteStep);
1311 g_return_val_if_fail(step, NULL);
1313 step->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
1318 static void step_property_copy_cb (gpointer key, gpointer value, gpointer user_data)
1320 g_return_if_fail (key);
1321 g_return_if_fail (value);
1322 g_return_if_fail (user_data);
1324 LocationRouteStep *step = (LocationRouteStep *) user_data;
1326 if (step->properties) {
1327 gchar *re_key = g_strdup (key);
1328 gchar *re_val = g_strdup (value);
1329 g_hash_table_insert (step->properties, re_key, re_val);
1334 EXPORT_API LocationRouteStep *
1335 location_route_step_copy (LocationRouteStep *step)
1337 g_return_val_if_fail(step, NULL);
1339 LocationRouteStep *new_step = location_route_step_new ();
1340 g_return_val_if_fail (new_step, NULL);
1342 location_route_step_set_start_point (new_step, location_route_step_get_start_point(step));
1343 location_route_step_set_end_point (new_step, location_route_step_get_end_point(step));
1344 location_route_step_set_bounding_box (new_step, location_route_step_get_bounding_box(step));
1345 location_route_step_set_distance (new_step, location_route_step_get_distance(step));
1346 location_route_step_set_duration (new_step, location_route_step_get_duration(step));
1347 location_route_step_set_instruction (new_step, location_route_step_get_instruction(step));
1348 location_route_step_set_geometry (new_step, location_route_step_get_geometry(step));
1350 if (step->properties) g_hash_table_foreach (step->properties, step_property_copy_cb, new_step);
1355 location_route_step_free (LocationRouteStep *step)
1357 g_return_if_fail(step);
1359 location_route_step_set_start_point (step, NULL);
1360 location_route_step_set_end_point (step, NULL);
1361 location_route_step_set_bounding_box (step, NULL);
1362 location_route_step_set_distance (step, 0.0);
1363 location_route_step_set_duration (step, 0);
1364 location_route_step_set_instruction (step, NULL);
1365 location_route_step_set_geometry (step, NULL);
1367 if (step->properties) {
1368 g_hash_table_destroy (step->properties);
1369 step->properties = NULL;
1371 g_slice_free(LocationRouteStep, step);