Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Interop / Interop.Route.Segment.cs
1 /*
2  * Copyright (c) 2016 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 using System;
18 using System.Runtime.InteropServices;
19
20 internal static partial class Interop
21 {
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);
24
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);
27
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);
30
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);
33
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);
36
37     internal class RouteSegmentHandle : SafeMapsHandle
38     {
39         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
40         internal delegate bool PathCallback(int index, int total, IntPtr /* maps_coordinates_h */ coordinates, IntPtr /* void */ userData);
41
42         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
43         internal delegate bool ManeuverCallback(int index, int total, IntPtr /* maps_route_maneuver_h */ maneuver, IntPtr /* void */ userData);
44
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);
47
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);
50
51
52         [DllImport(Libraries.MapService, EntryPoint = "maps_route_segment_destroy")]
53         internal static extern ErrorCode Destroy(IntPtr /* maps_route_segment_h */ segment);
54
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);
57
58         internal double Distance
59         {
60             get { return NativeGet<double>(this.GetDistance); }
61         }
62
63         internal long Duration
64         {
65             get { return NativeGet<long>(this.GetDuration); }
66         }
67
68         internal CoordinatesHandle Origin
69         {
70             get { return NativeGet(this.GetOrigin, CoordinatesHandle.Create); }
71         }
72
73         internal CoordinatesHandle Destination
74         {
75             get { return NativeGet(this.GetDestination, CoordinatesHandle.Create); }
76         }
77
78         internal AreaHandle BoundingBox
79         {
80             get { return NativeGet(this.GetBoundingBox, AreaHandle.Create); }
81         }
82
83         public RouteSegmentHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
84         {
85         }
86
87         internal static RouteSegmentHandle CloneFrom(IntPtr nativeHandle)
88         {
89             IntPtr handle;
90             Clone(nativeHandle, out handle).ThrowIfFailed("Failed to clone native handle");
91             return new RouteSegmentHandle(handle, true);
92         }
93
94         internal void ForeachPath(Action<CoordinatesHandle> action)
95         {
96             PathCallback callback = (index, total, nativeHandle, userData) =>
97             {
98                 if (handle != IntPtr.Zero)
99                 {
100                     action(CoordinatesHandle.CloneFrom(nativeHandle));
101                     //Destroy(nativeHandle);
102                 }
103                 return true;
104             };
105
106             ForeachPath(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get path coordinates list from native handle");
107         }
108
109         internal void ForeachManeuver(Action<RouteManeuverHandle> action)
110         {
111             ManeuverCallback callback = (index, total, nativeHandle, userData) =>
112             {
113                 if (handle != IntPtr.Zero)
114                 {
115                     action(RouteManeuverHandle.CloneFrom(nativeHandle));
116                     //Destroy(nativeHandle);
117                 }
118                 return true;
119             };
120
121             ForeachManeuver(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get segment list from native handle");
122         }
123     }
124 }