Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Interop / Interop.Preference.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     internal enum DistanceUnit
23     {
24         Meter, // MAPS_DISTANCE_UNIT_M
25         Kilometer, // MAPS_DISTANCE_UNIT_KM
26         Foot, // MAPS_DISTANCE_UNIT_FT
27         Yard, // MAPS_DISTANCE_UNIT_YD
28     }
29
30     internal enum RouteOptimization
31     {
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
38     }
39
40     internal enum RouteTransportMode
41     {
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
47     }
48
49     internal enum RouteFeatureWeight
50     {
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
56     }
57
58     internal enum RouteRequestFeature
59     {
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
71     }
72
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);
75
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);
78
79     [DllImport(Libraries.MapService, EntryPoint = "maps_preference_get_language")]
80     internal static extern ErrorCode GetLanguage(this PreferenceHandle /* maps_preference_h */ preference, out string language);
81
82     [DllImport(Libraries.MapService, EntryPoint = "maps_preference_set_language")]
83     internal static extern ErrorCode SetLanguage(this PreferenceHandle /* maps_preference_h */ preference, string language);
84
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);
87
88     [DllImport(Libraries.MapService, EntryPoint = "maps_preference_set_max_results")]
89     internal static extern ErrorCode SetMaxResults(this PreferenceHandle /* maps_preference_h */ preference, int maxResults);
90
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);
93
94     [DllImport(Libraries.MapService, EntryPoint = "maps_preference_set_country_code")]
95     internal static extern ErrorCode SetCountryCode(this PreferenceHandle /* maps_preference_h */ preference, string countryCode);
96
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);
99
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);
102
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);
105
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);
108
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);
111
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);
114
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);
117
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);
120
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);
123
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);
126
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);
129
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);
132
133     internal class PreferenceHandle : SafeMapsHandle
134     {
135         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
136         internal delegate bool PropertiesCallback(int index, int total, string key, string value, IntPtr /* void */ userData);
137
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);
140
141
142         [DllImport(Libraries.MapService, EntryPoint = "maps_preference_create")]
143         internal static extern ErrorCode Create(out IntPtr /* maps_preference_h */ preference);
144
145         [DllImport(Libraries.MapService, EntryPoint = "maps_preference_destroy")]
146         internal static extern ErrorCode Destroy(IntPtr /* maps_preference_h */ preference);
147
148         internal DistanceUnit Unit
149         {
150             get { return NativeGet<DistanceUnit>(this.GetDistanceUnit); }
151             set { NativeSet(this.SetDistanceUnit, value); }
152         }
153
154         internal string Language
155         {
156             get { return NativeGet(this.GetLanguage); }
157             set { NativeSet(this.SetLanguage, value); }
158         }
159
160         internal int MaxResult
161         {
162             get { return NativeGet<int>(this.GetMaxResults); }
163             set { NativeSet(this.SetMaxResults, value); }
164         }
165
166         internal string CountryCode
167         {
168             get { return NativeGet(this.GetCountryCode); }
169             set { NativeSet(this.SetCountryCode, value); }
170         }
171
172         internal RouteOptimization Optimization
173         {
174             get { return NativeGet<RouteOptimization>(this.GetRouteOptimization); }
175             set { NativeSet(this.SetRouteOptimization, value); }
176         }
177
178         internal RouteTransportMode TransportMode
179         {
180             get { return NativeGet<RouteTransportMode>(this.GetRouteTransportMode); }
181             set { NativeSet(this.SetRouteTransportMode, value); }
182         }
183
184         internal RouteRequestFeature Feature
185         {
186             get { return NativeGet<RouteRequestFeature>(this.GetRouteFeature); }
187             set { NativeSet(this.SetRouteFeature, value); }
188         }
189
190         internal RouteFeatureWeight FeatureWeight
191         {
192             get { return NativeGet<RouteFeatureWeight>(this.GetRouteFeatureWeight); }
193             set { NativeSet(this.SetRouteFeatureWeight, value); }
194         }
195
196         internal bool AlternativesEnabled
197         {
198             get { return NativeGet<bool>(this.GetRouteAlternativesEnabled); }
199             set { NativeSet(this.SetRouteAlternativesEnabled, value); }
200         }
201
202         internal PreferenceHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
203         {
204         }
205
206         internal PreferenceHandle() : this(IntPtr.Zero, true)
207         {
208             Create(out handle).ThrowIfFailed("Failed to create native handle");
209         }
210
211         internal void ForeachProperty(Action<string, string> action)
212         {
213             PropertiesCallback callback = (index, total, key, value, userData) =>
214             {
215                 action(key, value);
216                 return true;
217             };
218
219             ForeachProperty(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get property list from native handle");
220         }
221
222         internal static PreferenceHandle Create(IntPtr nativeHandle)
223         {
224             return new PreferenceHandle(nativeHandle, true);
225         }
226     }
227 }