Deprecating Tizen.Location.Geofence APIs (#5598)
[platform/core/csapi/tizenfx.git] / src / Tizen.Location.Geofence / Tizen.Location.Geofence / Fence.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
19 namespace Tizen.Location.Geofence
20 {
21     /// <summary>
22     /// Geofence defines a virtual perimeter for a real-world geographic area.
23     /// If you create a geofence, you can trigger some activities when a device enters (or exits) the geofences defined by you.
24     /// You can create a geofence with the information of the Geopoint, Wi-Fi, or BT.
25     /// <list type="bullet">
26     /// <item><description>Geopoint: Geofence is specified by the coordinates (Latitude and Longitude) and radius.</description></item>
27     /// <item><description>WIFI: Geofence is specified by the BSSID of the Wi-Fi access point.</description></item>
28     /// <item><description>BT: Geofence is specified by the Bluetooth address.</description></item>
29     /// </list>
30     /// The Basic service set identifier (BSSID) is the MAC address of the wireless access point (WAP) generated by combining the 24-bit Organization Unique Identifier (the manufacturer's identity)
31     /// and the manufacturer's assigned 24-bit identifier for the radio chipset in the WAP.
32     /// </summary>
33     /// <since_tizen> 3 </since_tizen>
34     [Obsolete("Deprecated since API11. Might be removed in API13")]
35     public class Fence : IDisposable
36     {
37         private bool _disposed = false;
38
39         internal IntPtr Handle
40         {
41             get;
42             set;
43         }
44
45         internal Fence(IntPtr handle)
46         {
47             Handle = handle;
48         }
49
50         /// <summary>
51         /// The destructor of the Fence class.
52         /// </summary>
53         /// <since_tizen> 3 </since_tizen>
54         ~Fence()
55         {
56             Dispose(false);
57         }
58
59         /// <summary>
60         /// Gets the type of geofence.
61         /// </summary>
62         /// <since_tizen> 3 </since_tizen>
63         [Obsolete("Deprecated since API11. Might be removed in API13")]
64         public FenceType Type
65         {
66             get
67             {
68                 FenceType val;
69                 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceType(Handle, out val);
70                 if (ret != GeofenceError.None)
71                 {
72                     Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get GeofenceType");
73                 }
74
75                 return val;
76             }
77         }
78
79         /// <summary>
80         /// Gets the ID of the place.
81         /// </summary>
82         /// <since_tizen> 3 </since_tizen>
83         [Obsolete("Deprecated since API11. Might be removed in API13")]
84         public int PlaceId
85         {
86             get
87             {
88                 int result = -1;
89                 GeofenceError ret = (GeofenceError)Interop.Geofence.FencePlaceID(Handle, out result);
90                 if (ret != GeofenceError.None)
91                 {
92                     Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get PlaceId");
93                 }
94
95                 return result;
96             }
97         }
98
99         /// <summary>
100         /// Gets the longitude of geofence.
101         /// </summary>
102         /// <since_tizen> 3 </since_tizen>
103         [Obsolete("Deprecated since API11. Might be removed in API13")]
104         public double Longitude
105         {
106             get
107             {
108                 double result = -1;
109                 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceLongitude(Handle, out result);
110                 if (ret != GeofenceError.None)
111                 {
112                     Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Longitude");
113                 }
114
115                 return result;
116
117             }
118         }
119
120         /// <summary>
121         /// Gets the latitude of geofence.
122         /// </summary>
123         /// <since_tizen> 3 </since_tizen>
124         [Obsolete("Deprecated since API11. Might be removed in API13")]
125         public double Latitude
126         {
127             get
128             {
129                 double result = -1;
130                 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceLatitude(Handle, out result);
131                 if (ret != GeofenceError.None)
132                 {
133                     Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Latitude");
134                 }
135
136                 return result;
137             }
138         }
139
140         /// <summary>
141         /// Gets the radius of geofence.
142         /// </summary>
143         /// <since_tizen> 3 </since_tizen>
144         [Obsolete("Deprecated since API11. Might be removed in API13")]
145         public int Radius
146         {
147             get
148             {
149                 int result = -1;
150                 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceRadius(Handle, out result);
151                 if (ret != GeofenceError.None)
152                 {
153                     Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Radius");
154                 }
155
156                 return result;
157             }
158         }
159
160         /// <summary>
161         /// Gets the address of geofence.
162         /// </summary>
163         /// <since_tizen> 3 </since_tizen>
164         [Obsolete("Deprecated since API11. Might be removed in API13")]
165         public string Address
166         {
167             get
168             {
169                 string result = "";
170                 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceAddress(Handle, out result);
171                 if (ret != GeofenceError.None)
172                 {
173                     Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Adress");
174                 }
175
176                 return result;
177             }
178         }
179
180         /// <summary>
181         /// Gets the BSSID of geofence.
182         /// </summary>
183         /// <since_tizen> 3 </since_tizen>
184         [Obsolete("Deprecated since API11. Might be removed in API13")]
185         public string Bssid
186         {
187             get
188             {
189                 string result = "";
190                 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceBSSID(Handle, out result);
191                 if (ret != GeofenceError.None)
192                 {
193                     Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Bssid");
194                 }
195
196                 return result;
197             }
198         }
199
200         /// <summary>
201         /// Gets the SSID of geofence.
202         /// </summary>
203         /// <since_tizen> 3 </since_tizen>
204         [Obsolete("Deprecated since API11. Might be removed in API13")]
205         public string Ssid
206         {
207             get
208             {
209                 string result = "";
210                 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceSSID(Handle, out result);
211                 if (ret != GeofenceError.None)
212                 {
213                     Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Ssid");
214                 }
215
216                 return result;
217             }
218         }
219
220         /// <summary>
221         /// Creates a geopoint type of the new geofence.
222         /// </summary>
223         /// <since_tizen> 4 </since_tizen>
224         /// <param name="placeId">The current place ID.</param>
225         /// <param name="latitude">Specifies the value of latitude of the geofence [-90.0 ~ 90.0] \(degrees).</param>
226         /// <param name="longitude">Specifies the value of longitude of the geofence [-180.0 ~ 180.0] \(degrees).</param>
227         /// <param name="radius">Specifies the value of radius of the geofence [100 ~ 500] \(meter).</param>
228         /// <param name="address">Specifies the value of the address.</param>
229         /// <returns>The newly created geofence instance.</returns>
230         /// <exception cref="ArgumentException">In case of an invalid parameter.</exception>
231         /// <exception cref="InvalidOperationException">In case of any system error.</exception>
232         /// <exception cref="NotSupportedException">In case the geofence is not supported.</exception>
233         [Obsolete("Deprecated since API11. Might be removed in API13")]
234         public static Fence CreateGPSFence(int placeId, double latitude, double longitude, int radius, string address)
235         {
236             IntPtr handle = IntPtr.Zero;
237             GeofenceError ret = (GeofenceError)Interop.Geofence.CreateGPSFence(placeId, latitude, longitude, radius,address, out handle);
238             if (ret != GeofenceError.None)
239             {
240                 throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence from GPS Data for " + placeId);
241             }
242
243             return new Fence(handle);
244         }
245
246         /// <summary>
247         /// Creates a Wi-Fi type of the new geofence.
248         /// </summary>
249         /// <since_tizen> 3 </since_tizen>
250         /// <param name="placeId">The current place ID.</param>
251         /// <param name="bssid">Specifies the value of BSSID of the Wi-Fi MAC address.</param>
252         /// <param name="ssid"> Specifies the value of SSID of the Wi-Fi device.</param>
253         /// <returns>The newly created geofence instance.</returns>
254         /// <exception cref="ArgumentException">In case of an invalid parameter.</exception>
255         /// <exception cref="InvalidOperationException">In case of any system error.</exception>
256         /// <exception cref="NotSupportedException">In case the geofence is not supported.</exception>
257         [Obsolete("Deprecated since API11. Might be removed in API13")]
258         public static Fence CreateWifiFence(int placeId, string bssid, string ssid)
259         {
260             IntPtr handle = IntPtr.Zero;
261             GeofenceError ret = (GeofenceError)Interop.Geofence.CreateWiFiFence(placeId, bssid, ssid, out handle);
262             if (ret != GeofenceError.None)
263             {
264                 throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence from Wifi Data for " + placeId);
265             }
266
267             return new Fence(handle);
268         }
269
270         /// <summary>
271         /// Creates a Bluetooth type of the new geofence.
272         /// </summary>
273         /// <since_tizen> 3 </since_tizen>
274         /// <param name="placeId">The current place ID.</param>
275         /// <param name="bssid">Specifies the value of BSSID of BT MAC address.</param>
276         /// <param name="ssid"> Specifies the value of SSID of BT Device.</param>
277         /// <returns>The newly created geofence instance.</returns>
278         /// <exception cref="ArgumentException">In case of an invalid parameter.</exception>
279         /// <exception cref="InvalidOperationException">In case of any system error.</exception>
280         /// <exception cref="NotSupportedException">In case the geofence is not supported.</exception>
281         [Obsolete("Deprecated since API11. Might be removed in API13")]
282         public static Fence CreateBTFence(int placeId, string bssid, string ssid)
283         {
284             IntPtr handle = IntPtr.Zero;
285             GeofenceError ret = (GeofenceError)Interop.Geofence.CreateBTFence(placeId, bssid, ssid, out handle);
286             if (ret != GeofenceError.None)
287             {
288                 throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence from Bluetooth Data for " + placeId);
289             }
290
291             return new Fence(handle);
292         }
293
294         /// <summary>
295         /// The overloaded Dispose API for destroying the fence handle.
296         /// </summary>
297         /// <since_tizen> 3 </since_tizen>
298         [Obsolete("Deprecated since API11. Might be removed in API13")]
299         public void Dispose()
300         {
301             Dispose(true);
302             GC.SuppressFinalize(this);
303         }
304
305         /// <summary>
306         /// Dispose.
307         /// </summary>
308         /// <since_tizen> 3 </since_tizen>
309         [Obsolete("Deprecated since API11. Might be removed in API13")]
310         protected virtual void Dispose(bool disposing)
311         {
312             if (_disposed)
313                 return;
314
315             if (Handle != IntPtr.Zero)
316             {
317                 Interop.Geofence.Destroy(Handle);
318                 Handle = IntPtr.Zero;
319             }
320
321             _disposed = true;
322         }
323     }
324 }