Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Interop / Interop.Service.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 ServiceType
23     {
24         Geocode, // MAPS_SERVICE_GEOCODE
25         GeocodeInsideArea, // MAPS_SERVICE_GEOCODE_INSIDE_AREA
26         GeocodeByStructuredAddress, // MAPS_SERVICE_GEOCODE_BY_STRUCTURED_ADDRESS
27         ReverseGeocode, // MAPS_SERVICE_REVERSE_GEOCODE
28         SearchPlace, // MAPS_SERVICE_SEARCH_PLACE
29         SearchPlaceByArea, // MAPS_SERVICE_SEARCH_PLACE_BY_AREA
30         SearchPlaceByAddress, // MAPS_SERVICE_SEARCH_PLACE_BY_ADDRESS
31         SearchRoute, // MAPS_SERVICE_SEARCH_ROUTE
32         SearchRouteWaypoints, // MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS
33         CancelRequest, // MAPS_SERVICE_CANCEL_REQUEST
34         MultiReverseGeocode, // MAPS_SERVICE_MULTI_REVERSE_GEOCODE
35         SearchPlaceList, // MAPS_SERVICE_SEARCH_PLACE_LIST
36         SearchGetPlaceDetails, // MAPS_SERVICE_SEARCH_GET_PLACE_DETAILS
37         View = 0x100, // MAPS_SERVICE_VIEW
38         ViewSnapshot, // MAPS_SERVICE_VIEW_SNAPSHOT
39     }
40
41     internal enum ServiceData
42     {
43         PlaceAddress, // MAPS_PLACE_ADDRESS
44         PlaceRating, // MAPS_PLACE_RATING
45         PlaceCategories, // MAPS_PLACE_CATEGORIES
46         PlaceAttributes, // MAPS_PLACE_ATTRIBUTES
47         PlaceContacts, // MAPS_PLACE_CONTACTS
48         PlaceEditorials, // MAPS_PLACE_EDITORIALS
49         PlaceReviews, // MAPS_PLACE_REVIEWS
50         PlaceImage, // MAPS_PLACE_IMAGE
51         PlaceSupplier, // MAPS_PLACE_SUPPLIER
52         PlaceRelated, // MAPS_PLACE_RELATED
53         RoutePath, // MAPS_ROUTE_PATH
54         RouteSegmentsPath, // MAPS_ROUTE_SEGMENTS_PATH
55         RouteSegmentsManeuvers, // MAPS_ROUTE_SEGMENTS_MANEUVERS
56         ViewTraffic = 0x100, // MAPS_VIEW_TRAFFIC
57         ViewPublicTransit, // MAPS_VIEW_PUBLIC_TRANSIT
58         ViewBuilding, // MAPS_VIEW_BUILDING
59         ViewScaleBar, // MAPS_VIEW_SCALEBAR
60     }
61
62
63     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
64     internal delegate bool GeocodeCallback(ErrorCode /* maps_error_e */ result, int requestId, int index, int total, IntPtr /* maps_coordinates_h */ coordinates, IntPtr /* void */ userData);
65
66     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
67     internal delegate void ReverseGeocodeCallback(ErrorCode /* maps_error_e */ result, int requestId, int index, int total, IntPtr /* maps_address_h */ address, IntPtr /* void */ userData);
68
69     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
70     internal delegate bool MultiReverseGeocodeCallback(ErrorCode /* maps_error_e */ result, int requestId, int total, IntPtr /* maps_address_list_h */ addressList, IntPtr /* void */ userData);
71
72     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
73     internal delegate bool SearchPlaceCallback(ErrorCode /* maps_error_e */ error, int requestId, int index, int total, IntPtr /* maps_place_h */ place, IntPtr /* void */ userData);
74
75     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
76     internal delegate void SearchPlaceListCallback(ErrorCode /* maps_error_e */ error, int requestId, int total, IntPtr /* maps_place_list_h */ placeList, IntPtr /* void */ userData);
77
78     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
79     internal delegate void GetPlaceDetailsCallback(ErrorCode /* maps_error_e */ error, int requestId, IntPtr /* maps_place_h */ place, IntPtr /* void */ userData);
80
81     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
82     internal delegate bool SearchRouteCallback(ErrorCode /* maps_error_e */ error, int requestId, int index, int total, IntPtr /* maps_route_h */ route, IntPtr /* void */ userData);
83
84     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
85     internal delegate void RequestUserConsentwithHandleCallback(bool consented, IntPtr /* void */ userData);
86
87
88     [DllImport(Libraries.MapService, EntryPoint = "maps_service_cancel_request")]
89     internal static extern ErrorCode CancelRequest(this ServiceHandle /* maps_service_h */ maps, int requestId);
90
91     [DllImport(Libraries.MapService, EntryPoint = "maps_service_geocode")]
92     internal static extern ErrorCode Geocode(this ServiceHandle /* maps_service_h */ maps, string address, PreferenceHandle /* maps_preference_h */ preference, GeocodeCallback callback, IntPtr /* void */ userData, out int requestId);
93
94     [DllImport(Libraries.MapService, EntryPoint = "maps_service_geocode_inside_area")]
95     internal static extern ErrorCode GeocodeInsideArea(this ServiceHandle /* maps_service_h */ maps, string address, AreaHandle /* maps_area_h */ bounds, PreferenceHandle /* maps_preference_h */ preference, GeocodeCallback callback, IntPtr /* void */ userData, out int requestId);
96
97     [DllImport(Libraries.MapService, EntryPoint = "maps_service_geocode_by_structured_address")]
98     internal static extern ErrorCode GeocodeByStructuredAddress(this ServiceHandle /* maps_service_h */ maps, AddressHandle /* maps_address_h */ address, PreferenceHandle /* maps_preference_h */ preference, GeocodeCallback callback, IntPtr /* void */ userData, out int requestId);
99
100     [DllImport(Libraries.MapService, EntryPoint = "maps_service_reverse_geocode")]
101     internal static extern ErrorCode ReverseGeocode(this ServiceHandle /* maps_service_h */ maps, double latitude, double longitude, PreferenceHandle /* maps_preference_h */ preference, ReverseGeocodeCallback callback, IntPtr /* void */ userData, out int requestId);
102
103     [DllImport(Libraries.MapService, EntryPoint = "maps_service_multi_reverse_geocode")]
104     internal static extern ErrorCode MultiReverseGeocode(this ServiceHandle /* maps_service_h */ maps, CoordinatesListHandle /* maps_coordinates_list_h */ coordinatesList, PreferenceHandle /* maps_preference_h */ preference, MultiReverseGeocodeCallback callback, IntPtr /* void */ userData, out int requestId);
105
106     [DllImport(Libraries.MapService, EntryPoint = "maps_service_search_place")]
107     internal static extern ErrorCode SearchPlace(this ServiceHandle /* maps_service_h */ maps, CoordinatesHandle /* maps_coordinates_h */ position, int distance, PlaceFilterHandle /* maps_place_filter_h */ filter, PreferenceHandle /* maps_preference_h */ preference, SearchPlaceCallback callback, IntPtr /* void */ userData, out int requestId);
108
109     [DllImport(Libraries.MapService, EntryPoint = "maps_service_search_place_by_area")]
110     internal static extern ErrorCode SearchPlaceByArea(this ServiceHandle /* maps_service_h */ maps, AreaHandle /* maps_area_h */ boundary, PlaceFilterHandle /* maps_place_filter_h */ filter, PreferenceHandle /* maps_preference_h */ preference, SearchPlaceCallback callback, IntPtr /* void */ userData, out int requestId);
111
112     [DllImport(Libraries.MapService, EntryPoint = "maps_service_search_place_by_address")]
113     internal static extern ErrorCode SearchPlaceByAddress(this ServiceHandle /* maps_service_h */ maps, string address, AreaHandle /* maps_area_h */ boundary, PlaceFilterHandle /* maps_place_filter_h */ filter, PreferenceHandle /* maps_preference_h */ preference, SearchPlaceCallback callback, IntPtr /* void */ userData, out int requestId);
114
115     [DllImport(Libraries.MapService, EntryPoint = "maps_service_search_place_list")]
116     internal static extern ErrorCode SearchPlaceList(this ServiceHandle /* maps_service_h */ maps, AreaHandle /* maps_area_h */ boundary, PlaceFilterHandle /* maps_place_filter_h */ filter, PreferenceHandle /* maps_preference_h */ preference, SearchPlaceListCallback callback, IntPtr /* void */ userData, out int requestId);
117
118     [DllImport(Libraries.MapService, EntryPoint = "maps_service_get_place_details")]
119     internal static extern ErrorCode GetPlaceDetails(this ServiceHandle /* maps_service_h */ maps, string uri, GetPlaceDetailsCallback callback, IntPtr /* void */ userData, out int requestId);
120
121     [DllImport(Libraries.MapService, EntryPoint = "maps_service_search_route")]
122     internal static extern ErrorCode SearchRoute(this ServiceHandle /* maps_service_h */ maps, CoordinatesHandle /* maps_coordinates_h */ origin, CoordinatesHandle /* maps_coordinates_h */ destination, PreferenceHandle /* maps_preference_h */ preference, SearchRouteCallback callback, IntPtr /* void */ userData, out int requestId);
123
124     [DllImport(Libraries.MapService, EntryPoint = "maps_service_search_route_waypoints")]
125     internal static extern ErrorCode SearchRouteWaypoints(this ServiceHandle /* maps_service_h */ maps, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] [In] IntPtr[] /* maps_coordinates_h */ waypointList, int waypointNum, PreferenceHandle /* maps_preference_h */ preference, SearchRouteCallback callback, IntPtr /* void */ userData, out int requestId);
126
127     [DllImport(Libraries.MapService, EntryPoint = "maps_service_get_user_consent")]
128     internal static extern ErrorCode GetUserConsent(this ServiceHandle /* maps_service_h */ maps, out bool consent);
129
130     [DllImport(Libraries.MapService, EntryPoint = "maps_service_set_provider_key")]
131     internal static extern ErrorCode SetProviderKey(this ServiceHandle /* maps_service_h */ maps, string providerKey);
132
133     [DllImport(Libraries.MapService, EntryPoint = "maps_service_get_provider_key")]
134     internal static extern ErrorCode GetProviderKey(this ServiceHandle /* maps_service_h */ maps, out string providerKey);
135
136     [DllImport(Libraries.MapService, EntryPoint = "maps_service_set_preference")]
137     internal static extern ErrorCode SetPreference(this ServiceHandle /* maps_service_h */ maps, PreferenceHandle /* maps_preference_h */ preference);
138
139     [DllImport(Libraries.MapService, EntryPoint = "maps_service_get_preference")]
140     internal static extern ErrorCode GetPreference(this ServiceHandle /* maps_service_h */ maps, out IntPtr /* maps_preference_h */ preference);
141
142     [DllImport(Libraries.MapService, EntryPoint = "maps_service_provider_is_service_supported")]
143     internal static extern ErrorCode IsServiceSupported(this ServiceHandle /* maps_service_h */ maps, ServiceType /* maps_service_e */ service, out bool supported);
144
145     [DllImport(Libraries.MapService, EntryPoint = "maps_service_provider_is_data_supported")]
146     internal static extern ErrorCode IsDataSupported(this ServiceHandle /* maps_service_h */ maps, ServiceData /* maps_service_data_e */ data, out bool supported);
147
148     [DllImport(Libraries.MapService, EntryPoint = "maps_service_request_user_consent_with_handle")]
149     internal static extern ErrorCode RequestUserConsent(this ServiceHandle /* maps_service_h */ maps, RequestUserConsentwithHandleCallback callback, IntPtr /* void */ userData);
150
151     internal class ServiceHandle : SafeMapsHandle
152     {
153         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
154         internal delegate bool ProviderInfoCallback(string mapsProvider, IntPtr /* void */ userData);
155
156         [DllImport(Libraries.MapService, EntryPoint = "maps_service_foreach_provider")]
157         internal static extern ErrorCode ForeachProvider(ProviderInfoCallback callback, IntPtr /* void */ userData);
158
159         [DllImport(Libraries.MapService, EntryPoint = "maps_service_create_without_user_consent")]
160         internal static extern ErrorCode Create(string provider, out IntPtr /* maps_service_h */ maps);
161
162         [DllImport(Libraries.MapService, EntryPoint = "maps_service_destroy")]
163         internal static extern ErrorCode Destroy(IntPtr /* maps_service_h */ maps);
164
165                 internal bool UserConsented
166                 {
167                         get { return NativeGet<bool>(this.GetUserConsent); }
168                 }
169
170         internal string ProviderKey
171         {
172             get { return NativeGet(this.GetProviderKey); }
173             set { NativeSet(this.SetProviderKey, value); }
174         }
175
176         internal PreferenceHandle Preferences
177         {
178             get { return NativeGet(this.GetPreference, PreferenceHandle.Create); }
179             set { NativeSet(this.SetPreference, value); }
180         }
181
182         public ServiceHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
183         {
184         }
185
186         public ServiceHandle(string serviceProvider) : this(IntPtr.Zero, true)
187         {
188             Create(serviceProvider, out handle).ThrowIfFailed($"Failed to create native handle for {serviceProvider}");
189         }
190
191         internal static void ForeachProvider(Action<string> action)
192         {
193             ProviderInfoCallback callback = (provider, userData) =>
194             {
195                 action(provider);
196                 return true;
197             };
198
199             ForeachProvider(callback, IntPtr.Zero).WarnIfFailed("Failed to get provider list from native handle");
200         }
201     }
202 }