2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 namespace Tizen.Location.Geofence
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>
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.
33 /// <since_tizen> 3 </since_tizen>
34 [Obsolete("Deprecated since API11. Might be removed in API13")]
35 public class Fence : IDisposable
37 private bool _disposed = false;
39 internal IntPtr Handle
45 internal Fence(IntPtr handle)
51 /// The destructor of the Fence class.
53 /// <since_tizen> 3 </since_tizen>
60 /// Gets the type of geofence.
62 /// <since_tizen> 3 </since_tizen>
63 [Obsolete("Deprecated since API11. Might be removed in API13")]
69 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceType(Handle, out val);
70 if (ret != GeofenceError.None)
72 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get GeofenceType");
80 /// Gets the ID of the place.
82 /// <since_tizen> 3 </since_tizen>
83 [Obsolete("Deprecated since API11. Might be removed in API13")]
89 GeofenceError ret = (GeofenceError)Interop.Geofence.FencePlaceID(Handle, out result);
90 if (ret != GeofenceError.None)
92 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get PlaceId");
100 /// Gets the longitude of geofence.
102 /// <since_tizen> 3 </since_tizen>
103 [Obsolete("Deprecated since API11. Might be removed in API13")]
104 public double Longitude
109 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceLongitude(Handle, out result);
110 if (ret != GeofenceError.None)
112 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Longitude");
121 /// Gets the latitude of geofence.
123 /// <since_tizen> 3 </since_tizen>
124 [Obsolete("Deprecated since API11. Might be removed in API13")]
125 public double Latitude
130 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceLatitude(Handle, out result);
131 if (ret != GeofenceError.None)
133 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Latitude");
141 /// Gets the radius of geofence.
143 /// <since_tizen> 3 </since_tizen>
144 [Obsolete("Deprecated since API11. Might be removed in API13")]
150 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceRadius(Handle, out result);
151 if (ret != GeofenceError.None)
153 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Radius");
161 /// Gets the address of geofence.
163 /// <since_tizen> 3 </since_tizen>
164 [Obsolete("Deprecated since API11. Might be removed in API13")]
165 public string Address
170 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceAddress(Handle, out result);
171 if (ret != GeofenceError.None)
173 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Adress");
181 /// Gets the BSSID of geofence.
183 /// <since_tizen> 3 </since_tizen>
184 [Obsolete("Deprecated since API11. Might be removed in API13")]
190 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceBSSID(Handle, out result);
191 if (ret != GeofenceError.None)
193 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Bssid");
201 /// Gets the SSID of geofence.
203 /// <since_tizen> 3 </since_tizen>
204 [Obsolete("Deprecated since API11. Might be removed in API13")]
210 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceSSID(Handle, out result);
211 if (ret != GeofenceError.None)
213 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Ssid");
221 /// Creates a geopoint type of the new geofence.
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)
236 IntPtr handle = IntPtr.Zero;
237 GeofenceError ret = (GeofenceError)Interop.Geofence.CreateGPSFence(placeId, latitude, longitude, radius,address, out handle);
238 if (ret != GeofenceError.None)
240 throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence from GPS Data for " + placeId);
243 return new Fence(handle);
247 /// Creates a Wi-Fi type of the new geofence.
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)
260 IntPtr handle = IntPtr.Zero;
261 GeofenceError ret = (GeofenceError)Interop.Geofence.CreateWiFiFence(placeId, bssid, ssid, out handle);
262 if (ret != GeofenceError.None)
264 throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence from Wifi Data for " + placeId);
267 return new Fence(handle);
271 /// Creates a Bluetooth type of the new geofence.
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)
284 IntPtr handle = IntPtr.Zero;
285 GeofenceError ret = (GeofenceError)Interop.Geofence.CreateBTFence(placeId, bssid, ssid, out handle);
286 if (ret != GeofenceError.None)
288 throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence from Bluetooth Data for " + placeId);
291 return new Fence(handle);
295 /// The overloaded Dispose API for destroying the fence handle.
297 /// <since_tizen> 3 </since_tizen>
298 [Obsolete("Deprecated since API11. Might be removed in API13")]
299 public void Dispose()
302 GC.SuppressFinalize(this);
308 /// <since_tizen> 3 </since_tizen>
309 [Obsolete("Deprecated since API11. Might be removed in API13")]
310 protected virtual void Dispose(bool disposing)
315 if (Handle != IntPtr.Zero)
317 Interop.Geofence.Destroy(Handle);
318 Handle = IntPtr.Zero;