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 public class Fence : IDisposable
36 private bool _disposed = false;
38 internal IntPtr Handle
44 internal Fence(IntPtr handle)
50 /// The destructor of the Fence class.
52 /// <since_tizen> 3 </since_tizen>
59 /// Gets the type of geofence.
61 /// <since_tizen> 3 </since_tizen>
67 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceType(Handle, out val);
68 if (ret != GeofenceError.None)
70 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get GeofenceType");
78 /// Gets the ID of the place.
80 /// <since_tizen> 3 </since_tizen>
86 GeofenceError ret = (GeofenceError)Interop.Geofence.FencePlaceID(Handle, out result);
87 if (ret != GeofenceError.None)
89 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get PlaceId");
97 /// Gets the longitude of geofence.
99 /// <since_tizen> 3 </since_tizen>
100 public double Longitude
105 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceLongitude(Handle, out result);
106 if (ret != GeofenceError.None)
108 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Longitude");
117 /// Gets the latitude of geofence.
119 /// <since_tizen> 3 </since_tizen>
120 public double Latitude
125 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceLatitude(Handle, out result);
126 if (ret != GeofenceError.None)
128 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Latitude");
136 /// Gets the radius of geofence.
138 /// <since_tizen> 3 </since_tizen>
144 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceRadius(Handle, out result);
145 if (ret != GeofenceError.None)
147 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Radius");
155 /// Gets the address of geofence.
157 /// <since_tizen> 3 </since_tizen>
158 public string Address
163 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceAddress(Handle, out result);
164 if (ret != GeofenceError.None)
166 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Adress");
174 /// Gets the BSSID of geofence.
176 /// <since_tizen> 3 </since_tizen>
182 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceBSSID(Handle, out result);
183 if (ret != GeofenceError.None)
185 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Bssid");
193 /// Gets the SSID of geofence.
195 /// <since_tizen> 3 </since_tizen>
201 GeofenceError ret = (GeofenceError)Interop.Geofence.FenceSSID(Handle, out result);
202 if (ret != GeofenceError.None)
204 Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Ssid");
212 /// Creates a geopoint type of the new geofence.
214 /// <since_tizen> 4 </since_tizen>
215 /// <param name="placeId">The current place ID.</param>
216 /// <param name="latitude">Specifies the value of latitude of the geofence [-90.0 ~ 90.0] \(degrees).</param>
217 /// <param name="longitude">Specifies the value of longitude of the geofence [-180.0 ~ 180.0] \(degrees).</param>
218 /// <param name="radius">Specifies the value of radius of the geofence [100 ~ 500] \(meter).</param>
219 /// <param name="address">Specifies the value of the address.</param>
220 /// <returns>The newly created geofence instance.</returns>
221 /// <exception cref="ArgumentException">In case of an invalid parameter.</exception>
222 /// <exception cref="InvalidOperationException">In case of any system error.</exception>
223 /// <exception cref="NotSupportedException">In case the geofence is not supported.</exception>
224 public static Fence CreateGPSFence(int placeId, double latitude, double longitude, int radius, string address)
226 IntPtr handle = IntPtr.Zero;
227 GeofenceError ret = (GeofenceError)Interop.Geofence.CreateGPSFence(placeId, latitude, longitude, radius,address, out handle);
228 if (ret != GeofenceError.None)
230 throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence from GPS Data for " + placeId);
233 return new Fence(handle);
237 /// Creates a Wi-Fi type of the new geofence.
239 /// <since_tizen> 3 </since_tizen>
240 /// <param name="placeId">The current place ID.</param>
241 /// <param name="bssid">Specifies the value of BSSID of the Wi-Fi MAC address.</param>
242 /// <param name="ssid"> Specifies the value of SSID of the Wi-Fi device.</param>
243 /// <returns>The newly created geofence instance.</returns>
244 /// <exception cref="ArgumentException">In case of an invalid parameter.</exception>
245 /// <exception cref="InvalidOperationException">In case of any system error.</exception>
246 /// <exception cref="NotSupportedException">In case the geofence is not supported.</exception>
247 public static Fence CreateWifiFence(int placeId, string bssid, string ssid)
249 IntPtr handle = IntPtr.Zero;
250 GeofenceError ret = (GeofenceError)Interop.Geofence.CreateWiFiFence(placeId, bssid, ssid, out handle);
251 if (ret != GeofenceError.None)
253 throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence from Wifi Data for " + placeId);
256 return new Fence(handle);
260 /// Creates a Bluetooth type of the new geofence.
262 /// <since_tizen> 3 </since_tizen>
263 /// <param name="placeId">The current place ID.</param>
264 /// <param name="bssid">Specifies the value of BSSID of BT MAC address.</param>
265 /// <param name="ssid"> Specifies the value of SSID of BT Device.</param>
266 /// <returns>The newly created geofence instance.</returns>
267 /// <exception cref="ArgumentException">In case of an invalid parameter.</exception>
268 /// <exception cref="InvalidOperationException">In case of any system error.</exception>
269 /// <exception cref="NotSupportedException">In case the geofence is not supported.</exception>
270 public static Fence CreateBTFence(int placeId, string bssid, string ssid)
272 IntPtr handle = IntPtr.Zero;
273 GeofenceError ret = (GeofenceError)Interop.Geofence.CreateBTFence(placeId, bssid, ssid, out handle);
274 if (ret != GeofenceError.None)
276 throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence from Bluetooth Data for " + placeId);
279 return new Fence(handle);
283 /// The overloaded Dispose API for destroying the fence handle.
285 /// <since_tizen> 3 </since_tizen>
286 public void Dispose()
289 GC.SuppressFinalize(this);
295 /// <since_tizen> 3 </since_tizen>
296 protected virtual void Dispose(bool disposing)
301 if (Handle != IntPtr.Zero)
303 Interop.Geofence.Destroy(Handle);
304 Handle = IntPtr.Zero;