Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Interop / Interop.Route.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_get_route_id")]
23     internal static extern ErrorCode GetRouteId(this RouteHandle /* maps_route_h */ route, out string routeId);
24
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);
27
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);
30
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);
33
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);
36
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);
39
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);
42
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);
45
46     internal class RouteHandle : SafeMapsHandle
47     {
48         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
49         internal delegate bool PropertiesCallback(int index, int total, string key, string /* void */ value, IntPtr /* void */ userData);
50
51         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
52         internal delegate bool PathCallback(int index, int total, IntPtr /* maps_coordinates_h */ coordinates, IntPtr /* void */ userData);
53
54         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
55         internal delegate bool SegmentCallback(int index, int total, IntPtr /* maps_route_segment_h */ segment, IntPtr /* void */ userData);
56
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);
59
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);
62
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);
65
66         [DllImport(Libraries.MapService, EntryPoint = "maps_route_destroy")]
67         internal static extern ErrorCode Destroy(IntPtr /* maps_route_h */ route);
68
69         internal string Id
70         {
71             get { return NativeGet(this.GetRouteId); }
72         }
73
74         internal double Distance
75         {
76             get { return NativeGet<double>(this.GetTotalDistance); }
77         }
78
79         internal long Duration
80         {
81             get { return NativeGet<long>(this.GetTotalDuration); }
82         }
83
84         internal DistanceUnit Unit
85         {
86             get { return NativeGet<DistanceUnit>(this.GetDistanceUnit); }
87         }
88
89         internal RouteTransportMode TransportMode
90         {
91             get { return NativeGet<RouteTransportMode>(this.GetTransportMode); }
92         }
93
94         internal CoordinatesHandle Origin
95         {
96             get { return NativeGet(this.GetOrigin, CoordinatesHandle.Create); }
97         }
98
99         internal CoordinatesHandle Destination
100         {
101             get { return NativeGet(this.GetDestination, CoordinatesHandle.Create); }
102         }
103
104         internal AreaHandle BoundingBox
105         {
106             get { return NativeGet(this.GetBoundingBox, AreaHandle.Create); }
107         }
108
109         public RouteHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
110         {
111         }
112
113         internal void ForeachProperty(Action<string, string> action)
114         {
115             PropertiesCallback callback = (index, total, key, value, userData) =>
116             {
117                 action(key, value);
118                 return true;
119             };
120
121             ForeachProperty(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get property list from native handle");
122         }
123
124         internal void ForeachPath(Action<CoordinatesHandle> action)
125         {
126             PathCallback callback = (index, total, nativeHandle, userData) =>
127             {
128                 if (handle != IntPtr.Zero)
129                 {
130                     action(CoordinatesHandle.CloneFrom(nativeHandle));
131                     //Destroy(nativeHandle);
132                 }
133                 return true;
134             };
135
136             ForeachPath(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get path coordinates list from native handle");
137         }
138
139         internal void ForeachSegment(Action<RouteSegmentHandle> action)
140         {
141             SegmentCallback callback = (index, total, nativeHandle, userData) =>
142             {
143                 if (handle != IntPtr.Zero)
144                 {
145                     action(RouteSegmentHandle.CloneFrom(nativeHandle));
146                     //Destroy(nativeHandle);
147                 }
148                 return true;
149             };
150
151             ForeachSegment(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get segment list from native handle");
152         }
153     }
154 }