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_segment_get_origin")]
23 internal static extern ErrorCode GetOrigin(this RouteSegmentHandle /* maps_route_segment_h */ segment, out IntPtr /* maps_coordinates_h */ origin);
25 [DllImport(Libraries.MapService, EntryPoint = "maps_route_segment_get_destination")]
26 internal static extern ErrorCode GetDestination(this RouteSegmentHandle /* maps_route_segment_h */ segment, out IntPtr /* maps_coordinates_h */ destination);
28 [DllImport(Libraries.MapService, EntryPoint = "maps_route_segment_get_bounding_box")]
29 internal static extern ErrorCode GetBoundingBox(this RouteSegmentHandle /* maps_route_segment_h */ segment, out IntPtr /* maps_area_h */ boundingBox);
31 [DllImport(Libraries.MapService, EntryPoint = "maps_route_segment_get_distance")]
32 internal static extern ErrorCode GetDistance(this RouteSegmentHandle /* maps_route_segment_h */ segment, out double distance);
34 [DllImport(Libraries.MapService, EntryPoint = "maps_route_segment_get_duration")]
35 internal static extern ErrorCode GetDuration(this RouteSegmentHandle /* maps_route_segment_h */ segment, out long duration);
37 internal class RouteSegmentHandle : SafeMapsHandle
39 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
40 internal delegate bool PathCallback(int index, int total, IntPtr /* maps_coordinates_h */ coordinates, IntPtr /* void */ userData);
42 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
43 internal delegate bool ManeuverCallback(int index, int total, IntPtr /* maps_route_maneuver_h */ maneuver, IntPtr /* void */ userData);
45 [DllImport(Libraries.MapService, EntryPoint = "maps_route_segment_foreach_path")]
46 internal static extern ErrorCode ForeachPath(IntPtr /* maps_route_segment_h */ segment, PathCallback callback, IntPtr /* void */ userData);
48 [DllImport(Libraries.MapService, EntryPoint = "maps_route_segment_foreach_maneuver")]
49 internal static extern ErrorCode ForeachManeuver(IntPtr /* maps_route_segment_h */ segment, ManeuverCallback callback, IntPtr /* void */ userData);
52 [DllImport(Libraries.MapService, EntryPoint = "maps_route_segment_destroy")]
53 internal static extern ErrorCode Destroy(IntPtr /* maps_route_segment_h */ segment);
55 [DllImport(Libraries.MapService, EntryPoint = "maps_route_segment_clone")]
56 internal static extern ErrorCode Clone(IntPtr /* maps_route_segment_h */ origin, out IntPtr /* maps_route_segment_h */ cloned);
58 internal double Distance
60 get { return NativeGet<double>(this.GetDistance); }
63 internal long Duration
65 get { return NativeGet<long>(this.GetDuration); }
68 internal CoordinatesHandle Origin
70 get { return NativeGet(this.GetOrigin, CoordinatesHandle.Create); }
73 internal CoordinatesHandle Destination
75 get { return NativeGet(this.GetDestination, CoordinatesHandle.Create); }
78 internal AreaHandle BoundingBox
80 get { return NativeGet(this.GetBoundingBox, AreaHandle.Create); }
83 public RouteSegmentHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
87 internal static RouteSegmentHandle CloneFrom(IntPtr nativeHandle)
90 Clone(nativeHandle, out handle).ThrowIfFailed("Failed to clone native handle");
91 return new RouteSegmentHandle(handle, true);
94 internal void ForeachPath(Action<CoordinatesHandle> action)
96 PathCallback callback = (index, total, nativeHandle, userData) =>
98 if (handle != IntPtr.Zero)
100 action(CoordinatesHandle.CloneFrom(nativeHandle));
101 //Destroy(nativeHandle);
106 ForeachPath(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get path coordinates list from native handle");
109 internal void ForeachManeuver(Action<RouteManeuverHandle> action)
111 ManeuverCallback callback = (index, total, nativeHandle, userData) =>
113 if (handle != IntPtr.Zero)
115 action(RouteManeuverHandle.CloneFrom(nativeHandle));
116 //Destroy(nativeHandle);
121 ForeachManeuver(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get segment list from native handle");