change License boilerplate
[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         public static extern int Create(int locationMethod, out IntPtr handle);
27
28         [DllImport(Libraries.Location, EntryPoint = "location_manager_destroy")]
29         public static extern int Destroy(IntPtr handle);
30
31         [DllImport(Libraries.Location, EntryPoint = "location_manager_start")]
32         public static extern int Start(IntPtr handle);
33
34         [DllImport(Libraries.Location, EntryPoint = "location_manager_stop")]
35         public static extern int Stop(IntPtr handle);
36
37         [DllImport(Libraries.Location, EntryPoint = "location_manager_enable_mock_location")]
38         public static extern int EnableMock(bool enable);
39
40         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_mock_location")]
41         public static extern int SetMockLocation(IntPtr handle, double latitude, double longitude, double altitude, double speed, double direction, double accuracy);
42
43         [DllImport(Libraries.Location, EntryPoint = "location_manager_clear_mock_location")]
44         public static extern int ClearMock(IntPtr handle);
45
46         [DllImport(Libraries.Location, EntryPoint = "location_manager_get_method")]
47         public static extern int GetLocationType(IntPtr handle, out LocationType method);
48
49         [DllImport(Libraries.Location, EntryPoint = "location_manager_get_location")]
50         public 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 LocationAccuracy level, out double horizontal, out double vertical, out int timestamp);
51
52         [DllImport(Libraries.Location, EntryPoint = "location_manager_get_last_location")]
53         public 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 LocationAccuracy level, out double horizontal, out double vertical, out int timestamp);
54
55         [DllImport(Libraries.Location, EntryPoint = "location_manager_add_boundary")]
56         public static extern int AddBoundary(IntPtr managerHandle, IntPtr boundsHandle);
57
58         [DllImport(Libraries.Location, EntryPoint = "location_manager_remove_boundary")]
59         public static extern int RemoveBoundary(IntPtr managerHandle, IntPtr boundsHandle);
60     }
61
62     internal static partial class LocatorHelper
63     {
64         [DllImport(Libraries.Location, EntryPoint = "location_manager_is_enabled_method")]
65         public static extern int IsEnabled(int locationMethod, out bool status);
66
67         [DllImport(Libraries.Location, EntryPoint = "location_manager_is_supported_method")]
68         public static extern bool IsSupported(int locationMethod);
69     }
70
71     internal static partial class Location
72     {
73         [DllImport(Libraries.Location, EntryPoint = "location_manager_get_distance")]
74         public static extern int GetDistanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude, out double distance);
75     }
76
77     internal static partial class LocatorEvent
78     {
79         public delegate void ServiceStatechangedCallback(ServiceState state, IntPtr userData);
80         public delegate void ZonechangedCallback(BoundaryState state, double latitude, double longitude, double altitude, int timesatmp, IntPtr userData);
81         public delegate void SettingchangedCallback(LocationType method, bool enable, IntPtr userData);
82         public delegate void LocationchangedCallback(double latitude, double longitude, double altitude, double speed, double direction, double horizontalAcc, int timeStamp, IntPtr userData);
83         public delegate void LocationUpdatedCallback(LocationError error, double latitude, double longitude, double altitude, int timestamp, double speed, double direction, double climb, IntPtr userData);
84
85         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_service_state_changed_cb")]
86         public static extern int SetServiceStateChangedCallback(IntPtr handle, ServiceStatechangedCallback callback, IntPtr userData);
87
88         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_service_state_changed_cb")]
89         public static extern int UnSetServiceStateChangedCallback(IntPtr handle);
90
91         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_zone_changed_cb")]
92         public static extern int SetZoneChangedCallback(IntPtr handle, ZonechangedCallback callback, IntPtr userData);
93
94         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_zone_changed_cb")]
95         public static extern int UnSetZoneChangedCallback(IntPtr handle);
96
97         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_setting_changed_cb")]
98         public static extern int SetSettingChangedCallback(int method, SettingchangedCallback callback, IntPtr userData);
99
100         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_setting_changed_cb")]
101         public static extern int UnSetSettingChangedCallback(int method);
102
103         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_distance_based_location_changed_cb")]
104         public static extern int SetDistanceBasedLocationChangedCallback(IntPtr handle, LocationchangedCallback callback, int interval, double distance, IntPtr userData);
105
106         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_distance_based_location_changed_cb")]
107         public static extern int UnSetDistanceBasedLocationChangedCallback(IntPtr handle);
108
109         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_location_changed_cb")]
110         public static extern int SetLocationChangedCallback(IntPtr handle, LocationchangedCallback callback, int interval, IntPtr userData);
111
112         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_location_changed_cb")]
113         public static extern int UnSetLocationChangedCallback(IntPtr handle);
114
115         [DllImport(Libraries.Location, EntryPoint = "location_manager_request_single_location")]
116         public static extern int GetSingleLocation(IntPtr handle, int timeout, LocationUpdatedCallback callback, IntPtr userData);
117     }
118
119     internal static partial class LocationBoundary
120     {
121         public delegate bool PolygonCoordinatesCallback(Coordinate coordinates, IntPtr userData);
122
123         [DllImport(Libraries.Location, EntryPoint = "location_bounds_create_rect")]
124         public static extern int CreateRectangularBoundary(Coordinate topLeft, Coordinate bottomLeft, out IntPtr boundsHandle);
125
126         [DllImport(Libraries.Location, EntryPoint = "location_bounds_create_circle")]
127         public static extern int CreateCircleBoundary(Coordinate center, double radius, out IntPtr boundsHandle);
128
129         [DllImport(Libraries.Location, EntryPoint = "location_bounds_create_polygon")]
130         public static extern int CreatePolygonBoundary(IntPtr list, int listLength, out IntPtr boundsHandle);
131
132         [DllImport(Libraries.Location, EntryPoint = "location_bounds_get_rect_coords")]
133         public static extern int GetRectangleCoordinates(IntPtr handle, out Coordinate topLeft, out Coordinate bottomRight);
134
135         [DllImport(Libraries.Location, EntryPoint = "location_bounds_get_circle_coords")]
136         public static extern int GetCircleCoordinates(IntPtr handle, out Coordinate center, out double radius);
137
138         [DllImport(Libraries.Location, EntryPoint = "location_bounds_foreach_polygon_coords")]
139         public static extern int GetForEachPolygonCoordinates(IntPtr handle, PolygonCoordinatesCallback callback, IntPtr userData);
140
141         [DllImport(Libraries.Location, EntryPoint = "location_bounds_contains_coordinates")]
142         public static extern bool IsValidCoordinates(IntPtr handle, Coordinate coordinate);
143
144         [DllImport(Libraries.Location, EntryPoint = "location_bounds_destroy")]
145         public static extern bool DestroyBoundary(IntPtr handle);
146     }
147
148     internal static partial class GpsSatellite
149     {
150         public delegate void SatelliteStatuschangedCallback(uint numActive, uint numInView, int timeStamp, IntPtr userData);
151         public delegate bool SatelliteStatusinfomationCallback(uint azimuth, uint elevation, uint prn, uint snr, bool isActive, IntPtr userData);
152
153         [DllImport(Libraries.Location, EntryPoint = "gps_status_get_nmea")]
154         public static extern int GetNMEAData(IntPtr handle, out string nmea);
155
156         [DllImport(Libraries.Location, EntryPoint = "gps_status_get_satellite")]
157         public static extern int GetSatelliteStatus(IntPtr handle, out uint numberOfActive, out uint numberInView, out int timestamp);
158
159         [DllImport(Libraries.Location, EntryPoint = "gps_status_set_satellite_updated_cb")]
160         public static extern int SetSatelliteStatusChangedCallback(IntPtr handle, SatelliteStatuschangedCallback callback, int interval, IntPtr userData);
161
162         [DllImport(Libraries.Location, EntryPoint = "gps_status_unset_satellite_updated_cb")]
163         public static extern int UnSetSatelliteStatusChangedCallback(IntPtr handle);
164
165         [DllImport(Libraries.Location, EntryPoint = "gps_status_foreach_satellites_in_view")]
166         public static extern int GetForEachSatelliteInView(IntPtr handle, SatelliteStatusinfomationCallback callback, IntPtr userData);
167     }
168
169     internal static DateTime ConvertDateTime(int timestamp)
170     {
171         DateTime dateTime = DateTime.Now;
172
173         DateTime start = DateTime.SpecifyKind(new DateTime(1970, 1, 1).AddSeconds(timestamp), DateTimeKind.Utc);
174         dateTime = start.ToLocalTime();
175
176         return dateTime;
177     }
178 }