Merge remote-tracking branch 'usb/tizen'
[platform/core/csapi/tizenfx.git] / src / Tizen.Location / Interop / Interop.Location.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 using Tizen.Location;
20
21 internal static partial class Interop
22 {
23     internal static partial class Locator
24     {
25         [DllImport(Libraries.Location, EntryPoint = "location_manager_create")]
26         internal static extern int Create(int locationMethod, out IntPtr handle);
27
28         [DllImport(Libraries.Location, EntryPoint = "location_manager_destroy")]
29         internal static extern int Destroy(IntPtr handle);
30
31         [DllImport(Libraries.Location, EntryPoint = "location_manager_start")]
32         internal static extern int Start(IntPtr handle);
33
34         [DllImport(Libraries.Location, EntryPoint = "location_manager_stop")]
35         internal static extern int Stop(IntPtr handle);
36
37         [DllImport(Libraries.Location, EntryPoint = "location_manager_start_batch")]
38         internal static extern int StartBatch(IntPtr handle);
39
40         [DllImport(Libraries.Location, EntryPoint = "location_manager_stop_batch")]
41         internal static extern int StopBatch(IntPtr handle);
42
43         [DllImport(Libraries.Location, EntryPoint = "location_manager_is_enabled_mock_location")]
44         internal static extern int IsEnabledMock(out bool status);
45
46         [DllImport(Libraries.Location, EntryPoint = "location_manager_enable_mock_location")]
47         internal static extern int EnableMock(bool enable);
48
49         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_mock_location")]
50         internal static extern int SetMockLocation(IntPtr handle, double latitude, double longitude, double altitude, double speed, double direction, double accuracy);
51
52         [DllImport(Libraries.Location, EntryPoint = "location_manager_clear_mock_location")]
53         internal static extern int ClearMock(IntPtr handle);
54
55         [DllImport(Libraries.Location, EntryPoint = "location_manager_get_location")]
56         internal static extern int GetLocation(IntPtr handle, out double altitude, out double latitude, out double longitude, out double climb, out double direction, out double speed, out int level, out double horizontal, out double vertical, out int timestamp);
57
58         [DllImport(Libraries.Location, EntryPoint = "location_manager_get_last_location")]
59         internal static extern int GetLastLocation(IntPtr handle, out double altitude, out double latitude, out double longitude, out double climb, out double direction, out double speed, out int level, out double horizontal, out double vertical, out int timestamp);
60
61         [DllImport(Libraries.Location, EntryPoint = "location_manager_add_boundary")]
62         internal static extern int AddBoundary(IntPtr managerHandle, IntPtr boundsHandle);
63
64         [DllImport(Libraries.Location, EntryPoint = "location_manager_remove_boundary")]
65         internal static extern int RemoveBoundary(IntPtr managerHandle, IntPtr boundsHandle);
66     }
67
68     internal static partial class LocatorHelper
69     {
70         [DllImport(Libraries.Location, EntryPoint = "location_manager_is_enabled_method")]
71         internal static extern int IsEnabled(int locationMethod, out bool status);
72
73         [DllImport(Libraries.Location, EntryPoint = "location_manager_is_supported_method")]
74         internal static extern bool IsSupported(int locationMethod);
75     }
76
77     internal static partial class Location
78     {
79         [DllImport(Libraries.Location, EntryPoint = "location_manager_get_distance")]
80         internal static extern int GetDistanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude, out double distance);
81     }
82
83     internal static partial class LocatorEvent
84     {
85         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
86         internal delegate void ServiceStatechangedCallback(ServiceState state, IntPtr userData);
87
88         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
89         internal delegate void ZonechangedCallback(BoundaryState state, double latitude, double longitude, double altitude, int timesatmp, IntPtr userData);
90
91         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
92         internal delegate void SettingchangedCallback(LocationType method, bool enable, IntPtr userData);
93
94         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
95         internal delegate void LocationchangedCallback(double latitude, double longitude, double altitude, double speed, double direction, double accuracy, int timeStamp, IntPtr userData);
96
97         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
98         internal delegate void LocationUpdatedCallback(LocationError error, double latitude, double longitude, double altitude, int timestamp, double speed, double direction, double climb, IntPtr userData);
99
100         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
101         internal delegate void LocationBatchCallback(int batch_size, IntPtr userData);
102
103         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
104         internal delegate void LocationBatchGetCallback(double latitude, double longitude, double altitude, double speed, double direction, double horizontal, double vertical, int timeStamp, IntPtr userData);
105
106         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_service_state_changed_cb")]
107         internal static extern int SetServiceStateChangedCallback(IntPtr handle, ServiceStatechangedCallback callback, IntPtr userData);
108
109         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_service_state_changed_cb")]
110         internal static extern int UnSetServiceStateChangedCallback(IntPtr handle);
111
112         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_zone_changed_cb")]
113         internal static extern int SetZoneChangedCallback(IntPtr handle, ZonechangedCallback callback, IntPtr userData);
114
115         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_zone_changed_cb")]
116         internal static extern int UnSetZoneChangedCallback(IntPtr handle);
117
118         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_setting_changed_cb")]
119         internal static extern int SetSettingChangedCallback(int method, SettingchangedCallback callback, IntPtr userData);
120
121         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_setting_changed_cb")]
122         internal static extern int UnSetSettingChangedCallback(int method);
123
124         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_distance_based_location_changed_cb")]
125         internal static extern int SetDistanceBasedLocationChangedCallback(IntPtr handle, LocationchangedCallback callback, int interval, double distance, IntPtr userData);
126
127         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_distance_based_location_changed_cb")]
128         internal static extern int UnSetDistanceBasedLocationChangedCallback(IntPtr handle);
129
130         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_location_changed_cb")]
131         internal static extern int SetLocationChangedCallback(IntPtr handle, LocationchangedCallback callback, int interval, IntPtr userData);
132
133         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_location_changed_cb")]
134         internal static extern int UnSetLocationChangedCallback(IntPtr handle);
135
136         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_location_batch_cb")]
137         internal static extern int SetLocationBatchCallback(IntPtr handle, LocationBatchCallback callback, int batchInterval, int batchPeriod, IntPtr userData);
138
139         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_location_batch_cb")]
140         internal static extern int UnSetLocationBatchCallback(IntPtr handle);
141
142         [DllImport(Libraries.Location, EntryPoint = "location_manager_foreach_location_batch")]
143         internal static extern int GetLocationBatch(IntPtr handle, LocationBatchGetCallback callback, IntPtr userData);
144
145         [DllImport(Libraries.Location, EntryPoint = "location_manager_request_single_location")]
146         internal static extern int GetSingleLocation(IntPtr handle, int timeout, LocationUpdatedCallback callback, IntPtr userData);
147     }
148
149     internal static partial class LocationBoundary
150     {
151         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
152         internal delegate bool PolygonCoordinatesCallback(Coordinate coordinates, IntPtr userData);
153
154         [DllImport(Libraries.Location, EntryPoint = "location_bounds_create_rect")]
155         internal static extern int CreateRectangularBoundary(Coordinate topLeft, Coordinate bottomLeft, out IntPtr boundsHandle);
156
157         [DllImport(Libraries.Location, EntryPoint = "location_bounds_create_circle")]
158         internal static extern int CreateCircleBoundary(Coordinate center, double radius, out IntPtr boundsHandle);
159
160         [DllImport(Libraries.Location, EntryPoint = "location_bounds_create_polygon")]
161         internal static extern int CreatePolygonBoundary(IntPtr list, int listLength, out IntPtr boundsHandle);
162
163         [DllImport(Libraries.Location, EntryPoint = "location_bounds_get_rect_coords")]
164         internal static extern int GetRectangleCoordinates(IntPtr handle, out Coordinate topLeft, out Coordinate bottomRight);
165
166         [DllImport(Libraries.Location, EntryPoint = "location_bounds_get_circle_coords")]
167         internal static extern int GetCircleCoordinates(IntPtr handle, out Coordinate center, out double radius);
168
169         [DllImport(Libraries.Location, EntryPoint = "location_bounds_foreach_polygon_coords")]
170         internal static extern int GetForEachPolygonCoordinates(IntPtr handle, PolygonCoordinatesCallback callback, IntPtr userData);
171
172         [DllImport(Libraries.Location, EntryPoint = "location_bounds_contains_coordinates")]
173         internal static extern bool IsValidCoordinates(IntPtr handle, Coordinate coordinate);
174
175         [DllImport(Libraries.Location, EntryPoint = "location_bounds_destroy")]
176         internal static extern int DestroyBoundary(IntPtr handle);
177     }
178
179     internal static partial class GpsSatellite
180     {
181         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
182         internal delegate void SatelliteStatuschangedCallback(uint numActive, uint numInView, int timeStamp, IntPtr userData);
183
184         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
185         internal delegate bool SatelliteStatusinfomationCallback(uint azimuth, uint elevation, uint prn, uint snr, bool active, IntPtr userData);
186
187         [DllImport(Libraries.Location, EntryPoint = "gps_status_get_nmea")]
188         internal static extern int GetNMEAData(IntPtr handle, out string nmea);
189
190         [DllImport(Libraries.Location, EntryPoint = "gps_status_get_satellite")]
191         internal static extern int GetSatelliteStatus(IntPtr handle, out uint numberOfActive, out uint numberInView, out int timestamp);
192
193         [DllImport(Libraries.Location, EntryPoint = "gps_status_set_satellite_updated_cb")]
194         internal static extern int SetSatelliteStatusChangedCallback(IntPtr handle, SatelliteStatuschangedCallback callback, int interval, IntPtr userData);
195
196         [DllImport(Libraries.Location, EntryPoint = "gps_status_unset_satellite_updated_cb")]
197         internal static extern int UnSetSatelliteStatusChangedCallback(IntPtr handle);
198
199         [DllImport(Libraries.Location, EntryPoint = "gps_status_foreach_satellites_in_view")]
200         internal static extern int GetForEachSatelliteInView(IntPtr handle, SatelliteStatusinfomationCallback callback, IntPtr userData);
201     }
202
203     internal static DateTime ConvertDateTime(int timestamp)
204     {
205         DateTime dateTime = DateTime.Now;
206
207         DateTime start = DateTime.SpecifyKind(new DateTime(1970, 1, 1).AddSeconds(timestamp), DateTimeKind.Utc);
208         dateTime = start.ToLocalTime();
209
210         return dateTime;
211     }
212 }