2 * Copyright (c) 2016 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 using System.Runtime.InteropServices;
20 internal static partial class Interop
22 [DllImport(Libraries.MapService, EntryPoint = "maps_route_get_route_id")]
23 internal static extern ErrorCode GetRouteId(this RouteHandle /* maps_route_h */ route, out string routeId);
25 [DllImport(Libraries.MapService, EntryPoint = "maps_route_get_origin")]
26 internal static extern ErrorCode GetOrigin(this RouteHandle /* maps_route_h */ route, out IntPtr /* maps_coordinates_h */ origin);
28 [DllImport(Libraries.MapService, EntryPoint = "maps_route_get_destination")]
29 internal static extern ErrorCode GetDestination(this RouteHandle /* maps_route_h */ route, out IntPtr /* maps_coordinates_h */ destination);
31 [DllImport(Libraries.MapService, EntryPoint = "maps_route_get_bounding_box")]
32 internal static extern ErrorCode GetBoundingBox(this RouteHandle /* maps_route_h */ route, out IntPtr /* maps_area_h */ boundingBox);
34 [DllImport(Libraries.MapService, EntryPoint = "maps_route_get_transport_mode")]
35 internal static extern ErrorCode GetTransportMode(this RouteHandle /* maps_route_h */ route, out RouteTransportMode /* maps_route_transport_mode_e */ transportMode);
37 [DllImport(Libraries.MapService, EntryPoint = "maps_route_get_total_distance")]
38 internal static extern ErrorCode GetTotalDistance(this RouteHandle /* maps_route_h */ route, out double totalDistance);
40 [DllImport(Libraries.MapService, EntryPoint = "maps_route_get_total_duration")]
41 internal static extern ErrorCode GetTotalDuration(this RouteHandle /* maps_route_h */ route, out long totalDuration);
43 [DllImport(Libraries.MapService, EntryPoint = "maps_route_get_distance_unit")]
44 internal static extern ErrorCode GetDistanceUnit(this RouteHandle /* maps_route_h */ route, out DistanceUnit /* maps_distance_unit_e */ distanceUnit);
46 internal class RouteHandle : SafeMapsHandle
48 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
49 internal delegate bool PropertiesCallback(int index, int total, string key, string /* void */ value, IntPtr /* void */ userData);
51 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
52 internal delegate bool PathCallback(int index, int total, IntPtr /* maps_coordinates_h */ coordinates, IntPtr /* void */ userData);
54 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
55 internal delegate bool SegmentCallback(int index, int total, IntPtr /* maps_route_segment_h */ segment, IntPtr /* void */ userData);
57 [DllImport(Libraries.MapService, EntryPoint = "maps_route_foreach_property")]
58 internal static extern ErrorCode ForeachProperty(IntPtr /* maps_route_h */ route, PropertiesCallback callback, IntPtr /* void */ userData);
60 [DllImport(Libraries.MapService, EntryPoint = "maps_route_foreach_path")]
61 internal static extern ErrorCode ForeachPath(IntPtr /* maps_route_h */ route, PathCallback callback, IntPtr /* void */ userData);
63 [DllImport(Libraries.MapService, EntryPoint = "maps_route_foreach_segment")]
64 internal static extern ErrorCode ForeachSegment(IntPtr /* maps_route_h */ route, SegmentCallback callback, IntPtr /* void */ userData);
66 [DllImport(Libraries.MapService, EntryPoint = "maps_route_destroy")]
67 internal static extern ErrorCode Destroy(IntPtr /* maps_route_h */ route);
71 get { return NativeGet(this.GetRouteId); }
74 internal double Distance
76 get { return NativeGet<double>(this.GetTotalDistance); }
79 internal long Duration
81 get { return NativeGet<long>(this.GetTotalDuration); }
84 internal DistanceUnit Unit
86 get { return NativeGet<DistanceUnit>(this.GetDistanceUnit); }
89 internal RouteTransportMode TransportMode
91 get { return NativeGet<RouteTransportMode>(this.GetTransportMode); }
94 internal CoordinatesHandle Origin
96 get { return NativeGet(this.GetOrigin, CoordinatesHandle.Create); }
99 internal CoordinatesHandle Destination
101 get { return NativeGet(this.GetDestination, CoordinatesHandle.Create); }
104 internal AreaHandle BoundingBox
106 get { return NativeGet(this.GetBoundingBox, AreaHandle.Create); }
109 public RouteHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
113 internal void ForeachProperty(Action<string, string> action)
115 PropertiesCallback callback = (index, total, key, value, userData) =>
121 ForeachProperty(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get property list from native handle");
124 internal void ForeachPath(Action<CoordinatesHandle> action)
126 PathCallback callback = (index, total, nativeHandle, userData) =>
128 if (handle != IntPtr.Zero)
130 action(CoordinatesHandle.CloneFrom(nativeHandle));
131 //Destroy(nativeHandle);
136 ForeachPath(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get path coordinates list from native handle");
139 internal void ForeachSegment(Action<RouteSegmentHandle> action)
141 SegmentCallback callback = (index, total, nativeHandle, userData) =>
143 if (handle != IntPtr.Zero)
145 action(RouteSegmentHandle.CloneFrom(nativeHandle));
146 //Destroy(nativeHandle);
151 ForeachSegment(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get segment list from native handle");