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 internal enum DistanceUnit
24 Meter, // MAPS_DISTANCE_UNIT_M
25 Kilometer, // MAPS_DISTANCE_UNIT_KM
26 Foot, // MAPS_DISTANCE_UNIT_FT
27 Yard, // MAPS_DISTANCE_UNIT_YD
30 internal enum RouteOptimization
32 Fastest, // MAPS_ROUTE_TYPE_FASTEST
33 Shortest, // MAPS_ROUTE_TYPE_SHORTEST
34 Economic, // MAPS_ROUTE_TYPE_ECONOMIC
35 Scenic, // MAPS_ROUTE_TYPE_SCENIC
36 FastestNow, // MAPS_ROUTE_TYPE_FASTESTNOW
37 DirectDrive, // MAPS_ROUTE_TYPE_DIRECTDRIVE
40 internal enum RouteTransportMode
42 Car, // MAPS_ROUTE_TRANSPORT_MODE_CAR
43 Pedestrian, // MAPS_ROUTE_TRANSPORT_MODE_PEDESTRIAN
44 Bicycle, // MAPS_ROUTE_TRANSPORT_MODE_BICYCLE
45 PublicTransit, // MAPS_ROUTE_TRANSPORT_MODE_PUBLICTRANSIT
46 Truck, // MAPS_ROUTE_TRANSPORT_MODE_TRUCK
49 internal enum RouteFeatureWeight
51 Normal, // MAPS_ROUTE_FEATURE_WEIGHT_NORMAL
52 Prefer, // MAPS_ROUTE_FEATURE_WEIGHT_PREFER
53 Avoid, // MAPS_ROUTE_FEATURE_WEIGHT_AVOID
54 SoftExclude, // MAPS_ROUTE_FEATURE_WEIGHT_SOFTEXCLUDE
55 StrictExclude, // MAPS_ROUTE_FEATURE_WEIGHT_STRICTEXCLUDE
58 internal enum RouteRequestFeature
60 None, // MAPS_ROUTE_FEATURE_NO
61 Toll, // MAPS_ROUTE_FEATURE_TOLL
62 MotorWay, // MAPS_ROUTE_FEATURE_MOTORWAY
63 BoatFerry, // MAPS_ROUTE_FEATURE_BOATFERRY
64 RailFerry, // MAPS_ROUTE_FEATURE_RAILFERRY
65 PublicTransit, // MAPS_ROUTE_FEATURE_PUBLICTTRANSIT
66 Tunnel, // MAPS_ROUTE_FEATURE_TUNNEL
67 DirtRoad, // MAPS_ROUTE_FEATURE_DIRTROAD
68 Parks, // MAPS_ROUTE_FEATURE_PARKS
69 Hovlane, // MAPS_ROUTE_FEATURE_HOVLANE
70 Stairs, // MAPS_ROUTE_FEATURE_STAIRS
73 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_get_distance_unit")]
74 internal static extern ErrorCode GetDistanceUnit(this PreferenceHandle /* maps_preference_h */ preference, out DistanceUnit /* maps_distance_unit_e */ unit);
76 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_set_distance_unit")]
77 internal static extern ErrorCode SetDistanceUnit(this PreferenceHandle /* maps_preference_h */ preference, DistanceUnit /* maps_distance_unit_e */ unit);
79 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_get_language")]
80 internal static extern ErrorCode GetLanguage(this PreferenceHandle /* maps_preference_h */ preference, out string language);
82 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_set_language")]
83 internal static extern ErrorCode SetLanguage(this PreferenceHandle /* maps_preference_h */ preference, string language);
85 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_get_max_results")]
86 internal static extern ErrorCode GetMaxResults(this PreferenceHandle /* maps_preference_h */ preference, out int maxResults);
88 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_set_max_results")]
89 internal static extern ErrorCode SetMaxResults(this PreferenceHandle /* maps_preference_h */ preference, int maxResults);
91 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_get_country_code")]
92 internal static extern ErrorCode GetCountryCode(this PreferenceHandle /* maps_preference_h */ preference, out string countryCode);
94 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_set_country_code")]
95 internal static extern ErrorCode SetCountryCode(this PreferenceHandle /* maps_preference_h */ preference, string countryCode);
97 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_get_route_optimization")]
98 internal static extern ErrorCode GetRouteOptimization(this PreferenceHandle /* maps_preference_h */ preference, out RouteOptimization /* maps_route_optimization_e */ optimization);
100 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_set_route_optimization")]
101 internal static extern ErrorCode SetRouteOptimization(this PreferenceHandle /* maps_preference_h */ preference, RouteOptimization /* maps_route_optimization_e */ optimization);
103 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_get_route_transport_mode")]
104 internal static extern ErrorCode GetRouteTransportMode(this PreferenceHandle /* maps_preference_h */ preference, out RouteTransportMode /* maps_route_transport_mode_e */ transportMode);
106 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_set_route_transport_mode")]
107 internal static extern ErrorCode SetRouteTransportMode(this PreferenceHandle /* maps_preference_h */ preference, RouteTransportMode /* maps_route_transport_mode_e */ transportMode);
109 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_get_route_feature_weight")]
110 internal static extern ErrorCode GetRouteFeatureWeight(this PreferenceHandle /* maps_preference_h */ preference, out RouteFeatureWeight /* maps_route_feature_weight_e */ featureWeight);
112 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_set_route_feature_weight")]
113 internal static extern ErrorCode SetRouteFeatureWeight(this PreferenceHandle /* maps_preference_h */ preference, RouteFeatureWeight /* maps_route_feature_weight_e */ featureWeight);
115 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_get_route_feature")]
116 internal static extern ErrorCode GetRouteFeature(this PreferenceHandle /* maps_preference_h */ preference, out RouteRequestFeature /* maps_route_feature_e */ feature);
118 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_set_route_feature")]
119 internal static extern ErrorCode SetRouteFeature(this PreferenceHandle /* maps_preference_h */ preference, RouteRequestFeature /* maps_route_feature_e */ feature);
121 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_get_route_alternatives_enabled")]
122 internal static extern ErrorCode GetRouteAlternativesEnabled(this PreferenceHandle /* maps_preference_h */ preference, out bool enable);
124 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_set_route_alternatives_enabled")]
125 internal static extern ErrorCode SetRouteAlternativesEnabled(this PreferenceHandle /* maps_preference_h */ preference, bool enable);
127 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_get")]
128 internal static extern ErrorCode GetProperty(this PreferenceHandle /* maps_preference_h */ preference, string key, out string value);
130 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_set_property")]
131 internal static extern ErrorCode SetProperty(this PreferenceHandle /* maps_preference_h */ preference, string key, string value);
133 internal class PreferenceHandle : SafeMapsHandle
135 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
136 internal delegate bool PropertiesCallback(int index, int total, string key, string value, IntPtr /* void */ userData);
138 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_foreach_property")]
139 internal static extern ErrorCode ForeachProperty(IntPtr /* maps_preference_h */ preference, PropertiesCallback callback, IntPtr /* void */ userData);
142 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_create")]
143 internal static extern ErrorCode Create(out IntPtr /* maps_preference_h */ preference);
145 [DllImport(Libraries.MapService, EntryPoint = "maps_preference_destroy")]
146 internal static extern ErrorCode Destroy(IntPtr /* maps_preference_h */ preference);
148 internal DistanceUnit Unit
150 get { return NativeGet<DistanceUnit>(this.GetDistanceUnit); }
151 set { NativeSet(this.SetDistanceUnit, value); }
154 internal string Language
156 get { return NativeGet(this.GetLanguage); }
157 set { NativeSet(this.SetLanguage, value); }
160 internal int MaxResult
162 get { return NativeGet<int>(this.GetMaxResults); }
163 set { NativeSet(this.SetMaxResults, value); }
166 internal string CountryCode
168 get { return NativeGet(this.GetCountryCode); }
169 set { NativeSet(this.SetCountryCode, value); }
172 internal RouteOptimization Optimization
174 get { return NativeGet<RouteOptimization>(this.GetRouteOptimization); }
175 set { NativeSet(this.SetRouteOptimization, value); }
178 internal RouteTransportMode TransportMode
180 get { return NativeGet<RouteTransportMode>(this.GetRouteTransportMode); }
181 set { NativeSet(this.SetRouteTransportMode, value); }
184 internal RouteRequestFeature Feature
186 get { return NativeGet<RouteRequestFeature>(this.GetRouteFeature); }
187 set { NativeSet(this.SetRouteFeature, value); }
190 internal RouteFeatureWeight FeatureWeight
192 get { return NativeGet<RouteFeatureWeight>(this.GetRouteFeatureWeight); }
193 set { NativeSet(this.SetRouteFeatureWeight, value); }
196 internal bool AlternativesEnabled
198 get { return NativeGet<bool>(this.GetRouteAlternativesEnabled); }
199 set { NativeSet(this.SetRouteAlternativesEnabled, value); }
202 internal PreferenceHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
206 internal PreferenceHandle() : this(IntPtr.Zero, true)
208 Create(out handle).ThrowIfFailed("Failed to create native handle");
211 internal void ForeachProperty(Action<string, string> action)
213 PropertiesCallback callback = (index, total, key, value, userData) =>
219 ForeachProperty(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get property list from native handle");
222 internal static PreferenceHandle Create(IntPtr nativeHandle)
224 return new PreferenceHandle(nativeHandle, true);