Name: csapi-geofence
Summary: Tizen location geofence API for C#
-Version: 1.0.0
+Version: 1.0.1
Release: 1
Group: Development/Libraries
License: Apache-2.0
{
internal static partial class Libraries
{
- public const string Geofence = "libcapi-geofence-manager.so.0";
- public const string Libc = "libc.so.6";
+ internal const string Geofence = "libcapi-geofence-manager.so.0";
+ internal const string Libc = "libc.so.6";
}
}
internal static partial class Geofence
{
[DllImport(Libraries.Geofence, EntryPoint = "geofence_create_geopoint")]
- public static extern int CreateGPSFence(int placeId, double latitude, double longitude, int radius, string address, out IntPtr handle);
+ internal static extern int CreateGPSFence(int placeId, double latitude, double longitude, int radius, string address, out IntPtr handle);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_create_bluetooth")]
- public static extern int CreateBTFence(int placeId, string bssid, string ssid, out IntPtr handle);
+ internal static extern int CreateBTFence(int placeId, string bssid, string ssid, out IntPtr handle);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_create_wifi")]
- public static extern int CreateWiFiFence(int placeId, string bssid, string ssid, out IntPtr handle);
+ internal static extern int CreateWiFiFence(int placeId, string bssid, string ssid, out IntPtr handle);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_destroy")]
- public static extern int Destroy(IntPtr handle);
-
- [DllImport(Libraries.Geofence, EntryPoint = "geofence_status_create")]
- public static extern int CreateFenceStatus(int placeId, out IntPtr statusHandle);
-
- [DllImport(Libraries.Geofence, EntryPoint = "geofence_status_destroy")]
- public static extern int ReleaseFenceStatus(IntPtr statusHandle);
+ internal static extern int Destroy(IntPtr handle);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_get_type")]
- public static extern int FenceType(IntPtr handle, out FenceType type);
+ internal static extern int FenceType(IntPtr handle, out FenceType type);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_get_place_id")]
- public static extern int FencePlaceID(IntPtr handle, out int placeId);
+ internal static extern int FencePlaceID(IntPtr handle, out int placeId);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_get_latitude")]
- public static extern int FenceLatitude(IntPtr handle, out double latitude);
+ internal static extern int FenceLatitude(IntPtr handle, out double latitude);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_get_longitude")]
- public static extern int FenceLongitude(IntPtr handle, out double longitude);
+ internal static extern int FenceLongitude(IntPtr handle, out double longitude);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_get_radius")]
- public static extern int FenceRadius(IntPtr handle, out int radius);
+ internal static extern int FenceRadius(IntPtr handle, out int radius);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_get_address")]
- public static extern int FenceAddress(IntPtr handle, out string address);
+ internal static extern int FenceAddress(IntPtr handle, out string address);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_get_bssid")]
- public static extern int FenceBSSID(IntPtr handle, out string bssid);
+ internal static extern int FenceBSSID(IntPtr handle, out string bssid);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_get_ssid")]
- public static extern int FenceSSID(IntPtr handle, out string ssid);
+ internal static extern int FenceSSID(IntPtr handle, out string ssid);
+ }
+
+ internal static partial class GeofenceStatus
+ {
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_status_create")]
+ internal static extern int Create(int fenceId, out IntPtr statusHandle);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_status_destroy")]
+ internal static extern int Destroy(IntPtr statusHandle);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_status_get_state")]
- public static extern int FenceState(IntPtr statusHandle, out GeofenceState state);
+ internal static extern int State(IntPtr statusHandle, out GeofenceState state);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_status_get_duration")]
- public static extern int FenceDuration(IntPtr statusHandle, out int seconds);
-
+ internal static extern int Duration(IntPtr statusHandle, out int seconds);
}
internal static partial class GeofenceManager
{
- public delegate bool StateChangedCallback(int fenceId,GeofenceState state,IntPtr userData);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool StateChangedCallback(int fenceId, GeofenceState state, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool ProximityStateChangedCallback(int fenceId, ProximityState state, ProximityProvider provider, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool GeofenceEventCallback(int placeId, int fenceId, GeofenceError error, GeoFenceEventType eventType, IntPtr userData);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_is_supported")]
- public static extern int IsSupported(out bool supported);
+ internal static extern int IsSupported(out bool supported);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_create")]
- public static extern int Create(out IntPtr handle);
+ internal static extern int Create(out IntPtr handle);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_destroy")]
- public static extern int Destroy(IntPtr handle);
+ internal static extern int Destroy(IntPtr handle);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_start")]
- public static extern int Start(IntPtr handle, int fenceId);
+ internal static extern int Start(IntPtr handle, int fenceId);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_stop")]
- public static extern int Stop(IntPtr handle, int fenceId);
+ internal static extern int Stop(IntPtr handle, int fenceId);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_set_geofence_state_changed_cb")]
- public static extern int SetStateChangedCB(IntPtr handle, StateChangedCallback callback, IntPtr userData);
+ internal static extern int SetStateChangedCB(IntPtr handle, StateChangedCallback callback, IntPtr userData);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_unset_geofence_state_changed_cb")]
- public static extern int UnsetStateChangedCB(IntPtr handle);
+ internal static extern int UnsetStateChangedCB(IntPtr handle);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_set_geofence_proximity_state_changed_cb")]
+ internal static extern int SetProximityStateCB(IntPtr handle, ProximityStateChangedCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_unset_geofence_proximity_state_changed_cb")]
+ internal static extern int UnsetProximityStateCB(IntPtr handle);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_set_geofence_event_cb")]
+ internal static extern int SetGeofenceEventCB(IntPtr handle, GeofenceEventCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_unset_geofence_event_cb")]
+ internal static extern int UnsetGeofenceEventCB(IntPtr handle);
}
internal static partial class VirtualPerimeter
{
- public delegate bool ForEachPlaceListCallback(int placeId, string placeName, int placeIndex, int placeCount, IntPtr userData);
-
- public delegate bool ForEachFenceListCallback(int fenceId, IntPtr fenceHandle, int placeIndex, int placeCount, IntPtr userData);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool ForEachPlaceListCallback(int placeId, string placeName, int placeIndex, int placeCount, IntPtr userData);
- public delegate bool ProximityStateChangedCallback(int fenceId, ProximityState state, ProximityProvider provider, IntPtr userData);
-
- public delegate bool GeofenceEventCallback(int placeId,int fenceId, GeofenceError error, GeoFenceEventType eventType, IntPtr userData);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool ForEachFenceListCallback(int fenceId, IntPtr fenceHandle, int placeIndex, int placeCount, IntPtr userData);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_add_place")]
- public static extern int AddPlace(IntPtr handle, string placeName, out int placeId);
+ internal static extern int AddPlace(IntPtr handle, string placeName, out int placeId);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_update_place")]
- public static extern int UpdatePlace(IntPtr handle, int placeId, string placeName);
+ internal static extern int UpdatePlace(IntPtr handle, int placeId, string placeName);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_remove_place")]
- public static extern int RemovePlace(IntPtr handle, int placeId);
+ internal static extern int RemovePlace(IntPtr handle, int placeId);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_add_fence")]
- public static extern int AddFence(IntPtr handle, IntPtr fenceHandle, out int fenceId);
+ internal static extern int AddFence(IntPtr handle, IntPtr fenceHandle, out int fenceId);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_remove_fence")]
- public static extern int RemoveFence(IntPtr handle, int fenceId);
-
- [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_set_geofence_event_cb")]
- public static extern int SetGeofenceEventCB(IntPtr handle, GeofenceEventCallback callback, IntPtr userData);
-
- [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_unset_geofence_event_cb")]
- public static extern int UnsetGeofenceEventCB(IntPtr handle);
-
- [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_set_geofence_proximity_state_changed_cb")]
- public static extern int SetProximityStateCB(IntPtr handle, ProximityStateChangedCallback callback, IntPtr userData);
-
- [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_unset_geofence_proximity_state_changed_cb")]
- public static extern int UnsetProximityStateCB(IntPtr handle);
+ internal static extern int RemoveFence(IntPtr handle, int fenceId);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_foreach_geofence_list")]
- public static extern int GetForEachFenceList(IntPtr handle, ForEachFenceListCallback callback, IntPtr userData);
+ internal static extern int GetForEachFenceList(IntPtr handle, ForEachFenceListCallback callback, IntPtr userData);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_foreach_place_geofence_list")]
- public static extern int GetForEachPlaceFenceList(IntPtr handle,int placeId, ForEachFenceListCallback callback, IntPtr userData);
+ internal static extern int GetForEachPlaceFenceList(IntPtr handle, int placeId, ForEachFenceListCallback callback, IntPtr userData);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_foreach_place_list")]
- public static extern int GetForEachPlaceList(IntPtr handle, ForEachPlaceListCallback callback, IntPtr userData);
+ internal static extern int GetForEachPlaceList(IntPtr handle, ForEachPlaceListCallback callback, IntPtr userData);
[DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_get_place_name")]
- public static extern int GetPlaceName(IntPtr handle, int placeId, out string placeName);
-
+ internal static extern int GetPlaceName(IntPtr handle, int placeId, out string placeName);
}
}
<Compile Include="Tizen.Location.Geofence\FenceData.cs" />
<Compile Include="Tizen.Location.Geofence\VirtualPerimeter.cs" />
<Compile Include="Tizen.Location.Geofence\GeofenceManager.cs" />
+ <Compile Include="Tizen.Location.Geofence\FenceStatus.cs" />
<Compile Include="Tizen.Location.Geofence\Fence.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Compile Include="Tizen.Location.Geofence\FenceData.cs" />
<Compile Include="Tizen.Location.Geofence\VirtualPerimeter.cs" />
<Compile Include="Tizen.Location.Geofence\GeofenceManager.cs" />
+ <Compile Include="Tizen.Location.Geofence\FenceStatus.cs" />
<Compile Include="Tizen.Location.Geofence\Fence.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
/// </summary>
public class Fence : IDisposable
{
+ private bool _disposed = false;
+
internal IntPtr Handle
{
get;
set;
}
-
internal Fence(IntPtr handle)
{
Handle = handle;
}
/// <summary>
- /// Gets the state of geofence.
- /// </summary>
- public GeofenceState FenceState
- {
- get
- {
- GeofenceState state;
- GeofenceError ret = (GeofenceError)Interop.Geofence.FenceState(Handle, out state);
- if (ret != GeofenceError.None)
- {
- Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get GeofenceState");
- }
-
- return state;
- }
- }
-
- /// <summary>
- /// Gets the amount of seconds geofence is in the current state.
- /// </summary>
- public int Duration
- {
- get
- {
- int result = -1;
- GeofenceError ret = (GeofenceError)Interop.Geofence.FenceDuration(Handle, out result);
- if (ret != GeofenceError.None)
- {
- Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Duration");
- }
-
- return result;
- }
- }
-
- /// <summary>
/// Gets the address of geofence.
/// </summary>
public string Address
public static Fence CreateGPSFence(int placeId, int latitude, int longitude, int radius, string address)
{
IntPtr handle = IntPtr.Zero;
- GeofenceError ret = (GeofenceError)Interop.Geofence.CreateGPSFence(placeId,latitude, longitude, radius,address,out handle);
+ GeofenceError ret = (GeofenceError)Interop.Geofence.CreateGPSFence(placeId, latitude, longitude, radius,address, out handle);
if (ret != GeofenceError.None)
{
throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence from GPS Data for " + placeId);
private void Dispose(bool disposing)
{
- if (!disposing)
+ if (_disposed)
+ return;
+
+ if (Handle != IntPtr.Zero)
{
- if (Handle != IntPtr.Zero)
- {
- Interop.Geofence.Destroy(Handle);
- Handle = IntPtr.Zero;
- }
+ Interop.Geofence.Destroy(Handle);
+ Handle = IntPtr.Zero;
}
+
+ _disposed = true;
}
}
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Location.Geofence
+{
+ /// <summary>
+ /// The geofence status describes the current state and duration of a geofence.
+ /// <list>
+ /// <item>State: State is specified by current state of fence</item>
+ /// <item>Duration: Geofence is specified by duration of current state</item>
+ /// </list>
+ /// </summary>
+ public class FenceStatus : IDisposable
+ {
+ private bool _disposed = false;
+
+ internal IntPtr Handle
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Creates a new geofence status.
+ /// </summary>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException">Incase of Pvivileges are not defined</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported</exception>
+ public FenceStatus(int fenceId)
+ {
+ IntPtr handle;
+ GeofenceError ret = (GeofenceError)Interop.GeofenceStatus.Create(fenceId, out handle);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence Status instance");
+ }
+
+ Handle = handle;
+ }
+
+ ~FenceStatus()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// Gets the state of geofence.
+ /// </summary>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported</exception>
+ public GeofenceState State
+ {
+ get
+ {
+ GeofenceState state;
+ GeofenceError ret = (GeofenceError)Interop.GeofenceStatus.State(Handle, out state);
+ if (ret != GeofenceError.None)
+ {
+ Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get FenceState");
+ }
+
+ return state;
+ }
+ }
+
+ /// <summary>
+ /// Gets the amount of seconds geofence is in the current state.
+ /// </summary>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported</exception>
+ public int Duration
+ {
+ get
+ {
+ int result = -1;
+ GeofenceError ret = (GeofenceError)Interop.GeofenceStatus.Duration(Handle, out result);
+ if (ret != GeofenceError.None)
+ {
+ Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get FenceDuration");
+ }
+
+ return result;
+ }
+ }
+
+ /// <summary>
+ /// Overloaded Dispose API for destroying the fence Handle.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ private void Dispose(bool disposing)
+ {
+ if (_disposed)
+ return;
+
+ if (Handle != IntPtr.Zero)
+ {
+ Interop.GeofenceStatus.Destroy(Handle);
+ Handle = IntPtr.Zero;
+ }
+
+ _disposed = true;
+ }
+ }
+}
};
/// <summary>
- /// Enumerations for the state of geofence manager.
+ /// Enumerations for the state of geofence.
/// </summary>
public enum GeofenceState
{
/// <summary>
/// Proximity is specified by geospatial coordinate
/// </summary>
- Location,
+ Location = 0,
/// <summary>
/// Proximity is specified by Wi-Fi access point
/// </summary>
- WiFi,
+ Wifi,
/// <summary>
/// Proximity is specified by Bluetooth device
/// <summary>
/// Uncertain state of proximity
/// </summary>
- Uncertain,
+ Uncertain = 0,
/// <summary>
/// Far state of proximity
/// <summary>
/// Event arguments passed when Event is triggered to notify proximity state change.
/// </summary>
- public class ProximityStateEventArgs: EventArgs
+ public class ProximityStateEventArgs : EventArgs
{
/// <summary>
/// Internal constructor
/// <summary>
/// Event arguments passed when Event is triggered to notify Geofence state change.
/// </summary>
- public class GeofenceStateEventArgs :EventArgs
+ public class GeofenceStateEventArgs : EventArgs
{
/// <summary>
/// Internal constructor
/// A geofence is a virtual perimeter for a real-world geographic area.
/// This API provides functions to set geofence with geopoint, MAC address of Wi-Fi and Bluetooth address.
/// And, notifications on events like changing in service status are provided.
- /// <list type="ul" There are two kinds of places and fences:>
+ /// <list type="ul">There are two kinds of places and fences:
/// <item>Public places and fences that are created by MyPlace app can be used by all apps.</item>
/// <item>Private places and fences that are created by specified app can be used by the same app.</item>
/// </list>
- /// <list >Notifications can be received about the following events:
+ /// <list>Notifications can be received about the following events:
/// <item>Zone in when a device enters a specific area</item>
/// <item>Zone out when a device exits a specific area</item>
/// <item>Results and errors for each event requested to geofence module</item>
/// </summary>
public class GeofenceManager : IDisposable
{
+ private bool _disposed = false;
+
internal IntPtr Handle
{
get;
}
}
+ private static readonly Interop.GeofenceManager.ProximityStateChangedCallback s_proximityChangedCallback = (int fenceId, ProximityState state, ProximityProvider provider, IntPtr data) =>
+ {
+ ProximityStateEventArgs evenArgs = new ProximityStateEventArgs(fenceId, state, provider);
+ s_proximityChanged?.Invoke(null, evenArgs);
+ return true;
+ };
+
+ private static event EventHandler<ProximityStateEventArgs> s_proximityChanged;
+
+ /// <summary>
+ /// Called when a proximity state of device is changed.
+ /// </summary>
+ /// <remarks>
+ /// Call to Start() will invoke this event.
+ /// </remarks>
+ /// <exception cref="NotSupportedException">Incase of feature Not supported</exception>
+ public event EventHandler<ProximityStateEventArgs> ProximityChanged
+ {
+ add
+ {
+ if (s_proximityChanged == null)
+ {
+ GeofenceError ret = (GeofenceError)Interop.GeofenceManager.SetProximityStateCB(Handle, s_proximityChangedCallback, IntPtr.Zero);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to register proximity change callback");
+ }
+ s_proximityChanged += value;
+ }
+ }
+ remove
+ {
+ s_proximityChanged -= value;
+ if (s_proximityChanged == null)
+ {
+ GeofenceError ret = (GeofenceError)Interop.GeofenceManager.UnsetProximityStateCB(Handle);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to un register proximity change callback");
+ }
+ }
+ }
+ }
+
+ private static readonly Interop.GeofenceManager.GeofenceEventCallback s_geofenceEventCallback = (int placeId, int fenceId, GeofenceError error, GeoFenceEventType eventType, IntPtr data) =>
+ {
+ GeofenceResponseEventArgs evenArgs = new GeofenceResponseEventArgs(placeId, fenceId, error, eventType);
+ s_geofenceEventChanged?.Invoke(null, evenArgs);
+ return true;
+ };
+
+ private static event EventHandler<GeofenceResponseEventArgs> s_geofenceEventChanged;
+
+ /// <summary>
+ /// Called when the some event occurs in geofence and place such as add, update, etc..
+ /// The events of public geofence is also received if there are public geofences.
+ /// </summary>
+ /// <remarks>
+ /// Call to Start() will invoke this event.
+ /// The value of place_id or geofence_id is -1 when the place id or geofence id is not assigned.
+ /// </remarks>
+ /// <exception cref="NotSupportedException">Incase of feature Not supported</exception>
+ public event EventHandler<GeofenceResponseEventArgs> GeoFenceEventChanged
+ {
+ add
+ {
+ if (s_geofenceEventChanged == null)
+ {
+ GeofenceError ret = (GeofenceError)Interop.GeofenceManager.SetGeofenceEventCB(Handle, s_geofenceEventCallback, IntPtr.Zero);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to register geofence event change callback");
+ }
+ s_geofenceEventChanged += value;
+ }
+ }
+ remove
+ {
+ s_geofenceEventChanged -= value;
+ if (s_geofenceEventChanged == null)
+ {
+ GeofenceError ret = (GeofenceError)Interop.GeofenceManager.UnsetGeofenceEventCB(Handle);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to unregister geofence event change callback");
+ }
+ }
+ }
+ }
+
/// <summary>
/// Overloaded Dispose API for destroying the GeofenceManager Handle.
/// </summary>
private void Dispose(bool disposing)
{
- if (!disposing)
+ if (_disposed)
+ return;
+
+ if (Handle != IntPtr.Zero)
{
- if (Handle != IntPtr.Zero)
- {
- Interop.GeofenceManager.Destroy(Handle);
- Handle = IntPtr.Zero;
- }
+ Interop.GeofenceManager.Destroy(Handle);
+ Handle = IntPtr.Zero;
}
+
+ _disposed = true;
}
}
}
return fences;
}
-
- private static readonly Interop.VirtualPerimeter.ProximityStateChangedCallback s_proximityChangedCallback = (int fenceId, ProximityState state, ProximityProvider provider, IntPtr data) =>
- {
- ProximityStateEventArgs evenArgs = new ProximityStateEventArgs(fenceId, state, provider);
- s_proximityChanged?.Invoke(null, evenArgs);
- return true;
- };
-
- private static event EventHandler<ProximityStateEventArgs> s_proximityChanged;
-
- /// <summary>
- /// Called when a proximity state of device is changed.
- /// </summary>
- /// <remarks>
- /// Call to Start() will invoke this event.
- /// </remarks>
- /// <exception cref="NotSupportedException">Incase of feature Not supported</exception>
- public event EventHandler<ProximityStateEventArgs> ProximityChanged
- {
- add
- {
- if (s_proximityChanged == null)
- {
- GeofenceError ret = (GeofenceError)Interop.VirtualPerimeter.SetProximityStateCB(Handle, s_proximityChangedCallback, IntPtr.Zero);
- if (ret != GeofenceError.None)
- {
- throw GeofenceErrorFactory.CreateException(ret, "Failed to register proximity change callback");
- }
- s_proximityChanged += value;
- }
- }
- remove
- {
- s_proximityChanged -= value;
- if (s_proximityChanged == null)
- {
- GeofenceError ret = (GeofenceError)Interop.VirtualPerimeter.UnsetProximityStateCB(Handle);
- if (ret != GeofenceError.None)
- {
- throw GeofenceErrorFactory.CreateException(ret, "Failed to un register proximity change callback");
- }
- }
- }
- }
-
- private static readonly Interop.VirtualPerimeter.GeofenceEventCallback s_geofenceEventCallback = (int placeId, int fenceId, GeofenceError error, GeoFenceEventType eventType, IntPtr data) =>
- {
- GeofenceResponseEventArgs evenArgs = new GeofenceResponseEventArgs(placeId, fenceId, error, eventType);
- s_geofenceEventChanged?.Invoke(null, evenArgs);
- return true;
- };
-
- private static event EventHandler<GeofenceResponseEventArgs> s_geofenceEventChanged;
-
- /// <summary>
- /// Called when the some event occurs in geofence and place such as add, update, etc..
- /// The events of public geofence is also received if there are public geofences.
- /// </summary>
- /// <remarks>
- /// Call to Start() will invoke this event.
- /// The value of place_id or geofence_id is -1 when the place id or geofence id is not assigned.
- /// </remarks>
- /// <exception cref="NotSupportedException">Incase of feature Not supported</exception>
- public event EventHandler<GeofenceResponseEventArgs> GeoFenceEventChanged
- {
- add
- {
- if (s_geofenceEventChanged == null)
- {
- GeofenceError ret = (GeofenceError)Interop.VirtualPerimeter.SetGeofenceEventCB(Handle, s_geofenceEventCallback, IntPtr.Zero);
- if (ret != GeofenceError.None)
- {
- throw GeofenceErrorFactory.CreateException(ret, "Failed to register geofence event change callback");
- }
- s_geofenceEventChanged += value;
- }
- }
- remove
- {
- s_geofenceEventChanged -= value;
- if (s_geofenceEventChanged == null)
- {
- GeofenceError ret = (GeofenceError)Interop.VirtualPerimeter.UnsetGeofenceEventCB(Handle);
- if (ret != GeofenceError.None)
- {
- throw GeofenceErrorFactory.CreateException(ret, "Failed to un register geofence event change callback");
- }
- }
- }
- }
}
}