summaryrefslogtreecommitdiff
path: root/src/Tizen.Location.Geofence
diff options
context:
space:
mode:
Diffstat (limited to 'src/Tizen.Location.Geofence')
-rwxr-xr-xsrc/Tizen.Location.Geofence/Interop/Interop.Libraries.cs24
-rwxr-xr-xsrc/Tizen.Location.Geofence/Interop/Interop.Location.cs157
-rw-r--r--src/Tizen.Location.Geofence/Tizen.Location.Geofence.csproj14
-rwxr-xr-xsrc/Tizen.Location.Geofence/Tizen.Location.Geofence/Fence.cs302
-rwxr-xr-xsrc/Tizen.Location.Geofence/Tizen.Location.Geofence/FenceData.cs129
-rw-r--r--src/Tizen.Location.Geofence/Tizen.Location.Geofence/FenceStatus.cs126
-rwxr-xr-xsrc/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceEnum.cs197
-rwxr-xr-xsrc/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceErrorFactory.cs174
-rwxr-xr-xsrc/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceEventArgs.cs164
-rwxr-xr-xsrc/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceManager.cs298
-rwxr-xr-xsrc/Tizen.Location.Geofence/Tizen.Location.Geofence/NamespaceDoc.cs33
-rwxr-xr-xsrc/Tizen.Location.Geofence/Tizen.Location.Geofence/VirtualPerimeter.cs269
12 files changed, 1887 insertions, 0 deletions
diff --git a/src/Tizen.Location.Geofence/Interop/Interop.Libraries.cs b/src/Tizen.Location.Geofence/Interop/Interop.Libraries.cs
new file mode 100755
index 0000000..40b8453
--- /dev/null
+++ b/src/Tizen.Location.Geofence/Interop/Interop.Libraries.cs
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+internal static partial class Interop
+{
+ internal static partial class Libraries
+ {
+ internal const string Geofence = "libcapi-geofence-manager.so.0";
+ internal const string Libc = "libc.so.6";
+ }
+}
diff --git a/src/Tizen.Location.Geofence/Interop/Interop.Location.cs b/src/Tizen.Location.Geofence/Interop/Interop.Location.cs
new file mode 100755
index 0000000..89eed6a
--- /dev/null
+++ b/src/Tizen.Location.Geofence/Interop/Interop.Location.cs
@@ -0,0 +1,157 @@
+/*
+ * 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;
+using System.Runtime.InteropServices;
+using Tizen.Location.Geofence;
+
+internal static partial class Interop
+{
+ internal static partial class Geofence
+ {
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_create_geopoint")]
+ 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")]
+ internal static extern int CreateBTFence(int placeId, string bssid, string ssid, out IntPtr handle);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_create_wifi")]
+ internal static extern int CreateWiFiFence(int placeId, string bssid, string ssid, out IntPtr handle);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_destroy")]
+ internal static extern int Destroy(IntPtr handle);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_get_type")]
+ internal static extern int FenceType(IntPtr handle, out FenceType type);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_get_place_id")]
+ internal static extern int FencePlaceID(IntPtr handle, out int placeId);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_get_latitude")]
+ internal static extern int FenceLatitude(IntPtr handle, out double latitude);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_get_longitude")]
+ internal static extern int FenceLongitude(IntPtr handle, out double longitude);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_get_radius")]
+ internal static extern int FenceRadius(IntPtr handle, out int radius);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_get_address")]
+ internal static extern int FenceAddress(IntPtr handle, out string address);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_get_bssid")]
+ internal static extern int FenceBSSID(IntPtr handle, out string bssid);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_get_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")]
+ internal static extern int State(IntPtr statusHandle, out GeofenceState state);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_status_get_duration")]
+ internal static extern int Duration(IntPtr statusHandle, out int seconds);
+ }
+
+ internal static partial class GeofenceManager
+ {
+ [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")]
+ internal static extern int IsSupported(out bool supported);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_create")]
+ internal static extern int Create(out IntPtr handle);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_destroy")]
+ internal static extern int Destroy(IntPtr handle);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_start")]
+ internal static extern int Start(IntPtr handle, int fenceId);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_stop")]
+ internal static extern int Stop(IntPtr handle, int fenceId);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_set_geofence_state_changed_cb")]
+ internal static extern int SetStateChangedCB(IntPtr handle, StateChangedCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_unset_geofence_state_changed_cb")]
+ 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
+ {
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool ForEachPlaceListCallback(int placeId, string placeName, int placeIndex, int placeCount, 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")]
+ internal static extern int AddPlace(IntPtr handle, string placeName, out int placeId);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_update_place")]
+ internal static extern int UpdatePlace(IntPtr handle, int placeId, string placeName);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_remove_place")]
+ internal static extern int RemovePlace(IntPtr handle, int placeId);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_add_fence")]
+ internal static extern int AddFence(IntPtr handle, IntPtr fenceHandle, out int fenceId);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_remove_fence")]
+ internal static extern int RemoveFence(IntPtr handle, int fenceId);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_foreach_geofence_list")]
+ internal static extern int GetForEachFenceList(IntPtr handle, ForEachFenceListCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_foreach_place_geofence_list")]
+ internal static extern int GetForEachPlaceFenceList(IntPtr handle, int placeId, ForEachFenceListCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_foreach_place_list")]
+ internal static extern int GetForEachPlaceList(IntPtr handle, ForEachPlaceListCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_get_place_name")]
+ internal static extern int GetPlaceName(IntPtr handle, int placeId, out string placeName);
+ }
+}
diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence.csproj b/src/Tizen.Location.Geofence/Tizen.Location.Geofence.csproj
new file mode 100644
index 0000000..5ed2f1f
--- /dev/null
+++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence.csproj
@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+ <Import Project="../../build/common.props" />
+
+ <PropertyGroup>
+ <TargetFramework>netstandard1.6</TargetFramework>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\Tizen\Tizen.csproj" />
+ <ProjectReference Include="..\Tizen.Log\Tizen.Log.csproj" />
+ </ItemGroup>
+
+ <Import Project="../../build/common.targets" />
+</Project>
diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence/Fence.cs b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/Fence.cs
new file mode 100755
index 0000000..d22b94a
--- /dev/null
+++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/Fence.cs
@@ -0,0 +1,302 @@
+/*
+ * 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>
+ /// Geo-fence defines a virtual perimeter for a real-world geographic area.
+ /// If you create a geofence, you can trigger some activities when a device enters(or exits) the geofences defined by you.
+ /// You can create a geofence with the information of Geopoint, Wi-Fi, or BT.
+ /// <list>
+ /// <item>Geopoint: Geofence is specified by coordinates (Latitude and Longitude) and Radius</item>
+ /// <item>WIFI: Geofence is specified by BSSID of Wi-Fi access point</item>
+ /// <item>BT: Geofence is specified by Bluetooth address</item>
+ /// </list>
+ /// Basic service set identification(BSSID) The BSSID is the MAC address of the wireless access point(WAP) generated by combining the 24 bit Organization Unique Identifier(the manufacturer's identity)
+ /// and the manufacturer's assigned 24-bit identifier for the radio chipset in the WAP.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public class Fence : IDisposable
+ {
+ private bool _disposed = false;
+
+ internal IntPtr Handle
+ {
+ get;
+ set;
+ }
+
+ internal Fence(IntPtr handle)
+ {
+ Handle = handle;
+ }
+
+ ~Fence()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// Gets the type of geofence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public FenceType Type
+ {
+ get
+ {
+ FenceType val;
+ GeofenceError ret = (GeofenceError)Interop.Geofence.FenceType(Handle, out val);
+ if (ret != GeofenceError.None)
+ {
+ Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get GeofenceType");
+ }
+
+ return val;
+ }
+ }
+
+ /// <summary>
+ /// Gets the id of place.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public int PlaceId
+ {
+ get
+ {
+ int result = -1;
+ GeofenceError ret = (GeofenceError)Interop.Geofence.FencePlaceID(Handle, out result);
+ if (ret != GeofenceError.None)
+ {
+ Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get PlaceId");
+ }
+
+ return result;
+ }
+ }
+
+ /// <summary>
+ /// Gets the longitude of geofence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public double Longitude
+ {
+ get
+ {
+ double result = -1;
+ GeofenceError ret = (GeofenceError)Interop.Geofence.FenceLongitude(Handle, out result);
+ if (ret != GeofenceError.None)
+ {
+ Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Longitude");
+ }
+
+ return result;
+
+ }
+ }
+
+ /// <summary>
+ /// Gets the latitude of geofence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public double Latitude
+ {
+ get
+ {
+ double result = -1;
+ GeofenceError ret = (GeofenceError)Interop.Geofence.FenceLatitude(Handle, out result);
+ if (ret != GeofenceError.None)
+ {
+ Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Latitude");
+ }
+
+ return result;
+ }
+ }
+
+ /// <summary>
+ /// Gets the radius of geofence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public int Radius
+ {
+ get
+ {
+ int result = -1;
+ GeofenceError ret = (GeofenceError)Interop.Geofence.FenceRadius(Handle, out result);
+ if (ret != GeofenceError.None)
+ {
+ Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Radius");
+ }
+
+ return result;
+ }
+ }
+
+ /// <summary>
+ /// Gets the address of geofence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public string Address
+ {
+ get
+ {
+ string result = "";
+ GeofenceError ret = (GeofenceError)Interop.Geofence.FenceAddress(Handle, out result);
+ if (ret != GeofenceError.None)
+ {
+ Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Adress");
+ }
+
+ return result;
+ }
+ }
+
+ /// <summary>
+ /// Gets the bssid of geofence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public string Bssid
+ {
+ get
+ {
+ string result = "";
+ GeofenceError ret = (GeofenceError)Interop.Geofence.FenceBSSID(Handle, out result);
+ if (ret != GeofenceError.None)
+ {
+ Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Bssid");
+ }
+
+ return result;
+ }
+ }
+
+ /// <summary>
+ /// Gets the ssid of geofence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public string Ssid
+ {
+ get
+ {
+ string result = "";
+ GeofenceError ret = (GeofenceError)Interop.Geofence.FenceSSID(Handle, out result);
+ if (ret != GeofenceError.None)
+ {
+ Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get Ssid");
+ }
+
+ return result;
+ }
+ }
+
+ /// <summary>
+ /// Creates a geopoint type of new geofence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="placeId">The current place id.</param>
+ /// <param name="latitude">Specifies the value of latitude of geofence [-90.0 ~ 90.0] (degrees).</param>
+ /// <param name="longitude">Specifies the value of longitude of geofence [-180.0 ~ 180.0] (degrees).</param>
+ /// <param name="radius">Specifies the value of radius of geofence [100 ~ 500](meter).</param>
+ /// <param name="address">Specifies the value of address.</param>
+ /// <returns>Newly created geofence instance.</returns>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter.</exception>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ 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);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence from GPS Data for " + placeId);
+ }
+
+ return new Fence(handle);
+ }
+
+ /// <summary>
+ /// Creates a Wi-Fi type of new geofence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="placeId">The current place id.</param>
+ /// <param name="bssid">Specifies the value of BSSID of Wi-Fi MAC address.</param>
+ /// <param name="ssid"> Specifies the value of SSID of Wi-Fi Device.</param>
+ /// <returns>Newly created geofence instance.</returns>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter.</exception>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public static Fence CreateWifiFence(int placeId, string bssid, string ssid)
+ {
+ IntPtr handle = IntPtr.Zero;
+ GeofenceError ret = (GeofenceError)Interop.Geofence.CreateWiFiFence(placeId, bssid, ssid, out handle);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence from Wifi Data for " + placeId);
+ }
+
+ return new Fence(handle);
+ }
+
+ /// <summary>
+ /// Creates a bluetooth type of new geofence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="placeId">The current place id.</param>
+ /// <param name="bssid">Specifies the value of BSSID of BT MAC address.</param>
+ /// <param name="ssid"> Specifies the value of SSID of BT Device.</param>
+ /// <returns>Newly created geofence instance.</returns>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter.</exception>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public static Fence CreateBTFence(int placeId, string bssid, string ssid)
+ {
+ IntPtr handle = IntPtr.Zero;
+ GeofenceError ret = (GeofenceError)Interop.Geofence.CreateBTFence(placeId, bssid, ssid, out handle);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence from Bluetooth Data for " + placeId);
+ }
+
+ return new Fence(handle);
+ }
+
+ /// <summary>
+ /// Overloaded Dispose API for destroying the fence Handle.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ private void Dispose(bool disposing)
+ {
+ if (_disposed)
+ return;
+
+ if (Handle != IntPtr.Zero)
+ {
+ Interop.Geofence.Destroy(Handle);
+ Handle = IntPtr.Zero;
+ }
+
+ _disposed = true;
+ }
+ }
+}
diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence/FenceData.cs b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/FenceData.cs
new file mode 100755
index 0000000..cfda8cf
--- /dev/null
+++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/FenceData.cs
@@ -0,0 +1,129 @@
+/*
+ * 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>
+ /// Represents the Geofence list Item data.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public class FenceData
+ {
+ internal FenceData(int fenceId, IntPtr handle, int index, int count)
+ {
+ GeofenceId = fenceId;
+ Fence = new Fence(handle);
+ Index = index;
+ Count = count;
+ }
+ /// <summary>
+ /// Geofence instance.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public Fence Fence
+ {
+ get;
+ internal set;
+ }
+
+ /// <summary>
+ /// The geofence id.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public int GeofenceId
+ {
+ get;
+ internal set;
+ }
+
+ /// <summary>
+ /// The index number of the fences in the list.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <value>Index value starts from 1.</value>
+ public int Index
+ {
+ get;
+ internal set;
+ }
+
+ /// <summary>
+ /// The total number of fences that exists for the requester.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public int Count
+ {
+ get;
+ internal set;
+ }
+ };
+
+ /// <summary>
+ /// Represents the Place list Item data.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public class PlaceData
+ {
+ internal PlaceData(int id, string name, int index, int count)
+ {
+ PlaceId = id;
+ Name = name;
+ Index = index;
+ Count = count;
+ }
+ /// <summary>
+ /// The current place id.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public int PlaceId
+ {
+ get;
+ internal set;
+ }
+
+ /// <summary>
+ /// The current place name.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public string Name
+ {
+ get;
+ internal set;
+ }
+
+ /// <summary>
+ /// The index number of the places in the list.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <value>Index value starts from 1.</value>
+ public int Index
+ {
+ get;
+ internal set;
+ }
+
+ /// <summary>
+ /// The total number of places that exists for the requester.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public int Count
+ {
+ get;
+ internal set;
+ }
+ };
+}
diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence/FenceStatus.cs b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/FenceStatus.cs
new file mode 100644
index 0000000..46e5e66
--- /dev/null
+++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/FenceStatus.cs
@@ -0,0 +1,126 @@
+/*
+ * 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>
+ /// <since_tizen>3</since_tizen>
+ public class FenceStatus : IDisposable
+ {
+ private bool _disposed = false;
+
+ internal IntPtr Handle
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Creates a new geofence status.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter.</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>
+ /// <since_tizen>3</since_tizen>
+ /// <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>
+ /// <since_tizen>3</since_tizen>
+ /// <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>
+ /// <since_tizen>3</since_tizen>
+ 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;
+ }
+ }
+}
diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceEnum.cs b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceEnum.cs
new file mode 100755
index 0000000..b5be383
--- /dev/null
+++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceEnum.cs
@@ -0,0 +1,197 @@
+/*
+ * 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.
+ */
+
+namespace Tizen.Location.Geofence
+{
+ /// <summary>
+ /// Enumeration for geofence type.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public enum FenceType
+ {
+ /// <summary>
+ /// Geofence is specified by geospatial coordinate.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ GeoPoint = 1,
+
+ /// <summary>
+ /// Geofence is specified by Wi-Fi access point.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ Wifi,
+
+ /// <summary>
+ /// Geofence is specified by Bluetooth device.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ Bluetooth
+ };
+
+ /// <summary>
+ /// Enumerations for the state of geofence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public enum GeofenceState
+ {
+ /// <summary>
+ /// Uncertain state of geofence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ Uncertain = 0,
+
+ /// <summary>
+ /// Geofence In state.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ In,
+
+ /// <summary>
+ /// Geofence Out state.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ Out
+ };
+
+ /// <summary>
+ /// Enumerations for geofence management events.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public enum GeofenceEventType
+ {
+ /// <summary>
+ /// Geofence is added.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ FenceAdded = 0,
+
+ /// <summary>
+ /// Geofence is removed.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ FenceRemoved,
+
+ /// <summary>
+ /// Geofencing is started.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ FenceStarted,
+
+ /// <summary>
+ /// Geofencing is stopped.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ FenceStopped,
+
+ /// <summary>
+ /// Place is added.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ PlaceAdded = 0x10,
+
+ /// <summary>
+ /// Place is removed.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ PlaceRemoved,
+
+ /// <summary>
+ /// Place is updated.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ PlaceUpdated,
+
+ /// <summary>
+ /// Setting for geofencing is enabled.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ SettingEnabled = 0x20,
+
+ /// <summary>
+ /// Setting for geofencing is disabled.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ SettingDisabled
+ };
+
+ /// <summary>
+ /// Enumeration for the provider of proximity.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public enum ProximityProvider
+ {
+ /// <summary>
+ /// Proximity is specified by geospatial coordinate.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ Location = 0,
+
+ /// <summary>
+ /// Proximity is specified by Wi-Fi access point.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ Wifi,
+
+ /// <summary>
+ /// Proximity is specified by Bluetooth device.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ Bluetooth,
+
+ /// <summary>
+ /// Proximity is specified by Bluetooth low energy device.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ BLE,
+
+ /// <summary>
+ /// Proximity is specified by Sensor.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ Sensor
+ }
+
+ /// <summary>
+ /// Enumeration for the state of proximity.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public enum ProximityState
+ {
+ /// <summary>
+ /// Uncertain state of proximity.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ Uncertain = 0,
+
+ /// <summary>
+ /// Far state of proximity.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ Far,
+
+ /// <summary>
+ /// Far state of proximity.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ Near,
+
+ /// <summary>
+ /// Immediate state of proximity.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ Immediate
+ }
+}
diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceErrorFactory.cs b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceErrorFactory.cs
new file mode 100755
index 0000000..e9fc3ad
--- /dev/null
+++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceErrorFactory.cs
@@ -0,0 +1,174 @@
+/*
+ * 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;
+using Tizen;
+
+
+namespace Tizen.Location.Geofence
+{
+ /// <summary>
+ /// Enum to give the type of error occured, if any.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public enum GeofenceError
+ {
+ /// <summary>
+ /// Successful.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ None = Tizen.Internals.Errors.ErrorCode.None,
+
+ /// <summary>
+ /// Out of memory.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
+
+ /// <summary>
+ /// Invalid parameter.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
+
+ /// <summary>
+ /// Permission denied.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
+
+ /// <summary>
+ /// Not Supported.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported,
+
+ /// <summary>
+ /// Geofence Manager is not initialized.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ NotInitialized = -0x02C00000 | 0x100 | 0x01,
+
+ /// <summary>
+ /// Invalid geofence ID.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ InvalidID = -0x02C00000 | 0x100 | 0x02,
+
+ /// <summary>
+ /// Exception occurs.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ Exception = -0x02C00000 | 0x100 | 0x03,
+
+ /// <summary>
+ /// Geofencing is already started.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ AlreadyStarted = -0x02C00000 | 0x100 | 0x04,
+
+ /// <summary>
+ /// Too many geofence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ TooManyGeofence = -0x02C00000 | 0x100 | 0x05,
+
+ /// <summary>
+ /// Error in GPS, Wi-Fi, or BT.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ IPC = -0x02C00000 | 0x100 | 0x06,
+
+ /// <summary>
+ /// DB error in the server side.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ DBFailed = -0x02C00000 | 0x100 | 0x07,
+
+ /// <summary>
+ /// Access to specified place is denied.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ PlaceAccessDenied = -0x02C00000 | 0x100 | 0x08,
+
+ /// <summary>
+ /// Access to specified geofence is denied.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ GeofenceAccessDenied = -0x02C00000 | 0x100 | 0x09
+ };
+
+ internal class GeofenceErrorFactory
+ {
+ internal const string LogTag = "Tizen.Location.Geofence";
+
+ internal static Exception CreateException(GeofenceError err, string msg)
+ {
+ Log.Info(LogTag, "Got Error " + err + " throwing Exception with msg " + msg);
+ Exception exp;
+ switch (err)
+ {
+ case GeofenceError.InvalidParameter:
+ {
+ exp = new ArgumentException(msg + " Invalid Parameters Provided");
+ break;
+ }
+
+ case GeofenceError.OutOfMemory:
+ {
+ exp = new OutOfMemoryException(msg + " Out Of Memory");
+ break;
+ }
+
+ case GeofenceError.NotInitialized:
+ {
+ exp = new InvalidOperationException(msg + " Not initializded");
+ break;
+ }
+
+ case GeofenceError.NotSupported:
+ {
+ exp = new NotSupportedException(msg + " Not supported");
+ break;
+ }
+
+ case GeofenceError.PermissionDenied:
+ // fall through
+ case GeofenceError.GeofenceAccessDenied:
+ //fall through
+ case GeofenceError.PlaceAccessDenied:
+ {
+ exp = new UnauthorizedAccessException(msg + " Permission Denied");
+ break;
+ }
+
+ case GeofenceError.DBFailed:
+ {
+ exp = new InvalidOperationException(msg + " DataBase Failed");
+ break;
+ }
+
+ default:
+ {
+ exp = new InvalidOperationException(msg);
+ break;
+ }
+ }
+
+ return exp;
+ }
+ }
+}
diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceEventArgs.cs b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceEventArgs.cs
new file mode 100755
index 0000000..f5ef780
--- /dev/null
+++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceEventArgs.cs
@@ -0,0 +1,164 @@
+/*
+ * 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>
+ /// Event arguments passed when Event is triggered to notify proximity state change.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public class ProximityStateEventArgs : EventArgs
+ {
+ /// <summary>
+ /// Internal constructor.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="id">The geofence id.</param>
+ /// <param name="state">The proximity state.</param>
+ /// <param name="provider">The proximity provider.</param>
+ internal ProximityStateEventArgs(int id, ProximityState state, ProximityProvider provider)
+ {
+ GeofenceId = id;
+ State = state;
+ Provider = provider;
+ }
+
+ /// <summary>
+ /// The geofence id.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public int GeofenceId
+ {
+ get;
+ }
+
+ /// <summary>
+ /// The proximity state.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public ProximityState State
+ {
+ get;
+ }
+
+ /// <summary>
+ /// The proximity provider.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public ProximityProvider Provider
+ {
+ get;
+ }
+ };
+
+ /// <summary>
+ /// Event arguments passed when Event is triggered to notify Geofence state change.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public class GeofenceStateEventArgs : EventArgs
+ {
+ /// <summary>
+ /// Internal constructor.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="fenceId">The specified geofence id.</param>
+ /// <param name="state">The geofence state.</param>
+ internal GeofenceStateEventArgs(int fenceId, GeofenceState state)
+ {
+ GeofenceId = fenceId;
+ State = state;
+ }
+
+ /// <summary>
+ /// The specified geofence id.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public int GeofenceId
+ {
+ get;
+ }
+
+ /// <summary>
+ /// The geofence state.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public GeofenceState State
+ {
+ get;
+ }
+ }
+
+ /// <summary>
+ /// Event arguments passed when Event occurs in geofence and place such as add, update, etc..
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public class GeofenceResponseEventArgs : EventArgs
+ {
+ /// <summary>
+ /// Internal constructor.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="placeId">The place id.</param>
+ /// <param name="fenceId">The specified geofence id.</param>
+ /// <param name="error">The error code for the particular action.</param>
+ /// <param name="eventType">The result code for the particular place and geofence management.</param>
+ internal GeofenceResponseEventArgs(int placeId, int fenceId, GeofenceError error, GeofenceEventType eventType)
+ {
+ PlaceId = placeId;
+ FenceId = fenceId;
+ ErrorCode = error;
+ EventType = eventType;
+ }
+
+ /// <summary>
+ /// The place id.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public int PlaceId
+ {
+ get;
+ }
+
+ /// <summary>
+ /// The specified geofence id.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public int FenceId
+ {
+ get;
+ }
+
+ /// <summary>
+ /// The error code for the particular action.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public GeofenceError ErrorCode
+ {
+ get;
+ }
+
+ /// <summary>
+ /// The result code for the particular place and geofence management.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public GeofenceEventType EventType
+ {
+ get;
+ }
+ };
+}
diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceManager.cs b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceManager.cs
new file mode 100755
index 0000000..ad69b02
--- /dev/null
+++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceManager.cs
@@ -0,0 +1,298 @@
+/*
+ * 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>
+ /// This Geofence Manager API provides service related to geofence(geo-fence).
+ /// 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.
+ /// There are two kinds of places and fences:
+ /// <list>
+ /// <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>
+ /// Notifications can be received about the following events:
+ /// <list>
+ /// <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>
+ /// </list>
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public class GeofenceManager : IDisposable
+ {
+ private bool _disposed = false;
+
+ internal IntPtr Handle
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Creates a new geofence manager.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <exception cref="OutOfMemoryException">Incase of OutOfMemory condition.</exception>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public GeofenceManager()
+ {
+ IntPtr handle;
+ GeofenceError ret = (GeofenceError) Interop.GeofenceManager.Create(out handle);
+ if(ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence Manager instance");
+ }
+
+ Handle = handle;
+ }
+
+ ~GeofenceManager()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// Checks whether the geofence manager is available or not.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public static bool IsSupported
+ {
+ get
+ {
+ bool ret = false;
+ GeofenceError res= (GeofenceError)Interop.GeofenceManager.IsSupported(out ret);
+ if(res != GeofenceError.None)
+ {
+ Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get IsSupported feature for Geofence manager");
+ }
+
+ return ret;
+ }
+ }
+
+ /// <summary>
+ /// Starts the geofencing service.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="geofenceId">The specified geofence id.</param>
+ /// <privilege>http://tizen.org/privilege/location</privilege>
+ /// <remarks>
+ /// When the location service is enabled, the StateChanged event is invoked and the service starts.
+ /// </remarks>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter.</exception>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="UnauthorizedAccessException">Incase of Privileges are not defined.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public void Start(int geofenceId)
+ {
+ GeofenceError ret = (GeofenceError)Interop.GeofenceManager.Start(Handle, geofenceId);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to start service for " + geofenceId);
+ }
+ }
+
+ /// <summary>
+ /// Stops the geofenceing service.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="geofenceId">The specified geofence id.</param>
+ /// <privilege>http://tizen.org/privilege/location</privilege>
+ /// <remarks>
+ /// This function initiates the process of stopping the service.
+ /// You can stop and start the geofence manager as needed.
+ /// </remarks>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter.</exception>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="UnauthorizedAccessException">Incase of Privileges are not defined.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public void Stop(int geofenceId)
+ {
+ GeofenceError ret = (GeofenceError)Interop.GeofenceManager.Stop(Handle, geofenceId);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to stop service for " + geofenceId);
+ }
+ }
+
+ private static readonly Interop.GeofenceManager.StateChangedCallback s_stateChangedCallback = (int fenceId, GeofenceState state, IntPtr data) =>
+ {
+ GeofenceStateEventArgs evenArgs = new GeofenceStateEventArgs(fenceId, state);
+ s_stateChanged?.Invoke(null, evenArgs);
+ return true;
+ };
+
+ private static event EventHandler<GeofenceStateEventArgs> s_stateChanged = null;
+
+ /// <summary>
+ /// Invokes when a device enters or exits the given geofence, If this event is registered.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <remarks>
+ /// Call to Start() will invoke this event.
+ /// </remarks>
+ /// <exception cref="NotSupportedException">Incase of feature Not supported.</exception>
+ public event EventHandler<GeofenceStateEventArgs> StateChanged
+ {
+ add
+ {
+ if(s_stateChanged == null)
+ {
+ GeofenceError ret = (GeofenceError)Interop.GeofenceManager.SetStateChangedCB(Handle, s_stateChangedCallback, IntPtr.Zero);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to register state change callback");
+ }
+ }
+ s_stateChanged += value;
+ }
+ remove
+ {
+ s_stateChanged -= value;
+ if (s_stateChanged == null)
+ {
+ GeofenceError ret = (GeofenceError)Interop.GeofenceManager.UnsetStateChangedCB(Handle);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to unregister state change callback");
+ }
+ }
+ }
+ }
+
+ 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>
+ /// <since_tizen>3</since_tizen>
+ /// <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>
+ /// <since_tizen>3</since_tizen>
+ /// <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>
+ /// <since_tizen>3</since_tizen>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ private void Dispose(bool disposing)
+ {
+ if (_disposed)
+ return;
+
+ if (Handle != IntPtr.Zero)
+ {
+ Interop.GeofenceManager.Destroy(Handle);
+ Handle = IntPtr.Zero;
+ }
+
+ _disposed = true;
+ }
+ }
+}
diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence/NamespaceDoc.cs b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/NamespaceDoc.cs
new file mode 100755
index 0000000..440da97
--- /dev/null
+++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/NamespaceDoc.cs
@@ -0,0 +1,33 @@
+/**
+<summary>
+The Tizen.Location.Geofence namespace provides classes for virtual perimeter.
+</summary>
+
+<remarks>
+<h2>Overview</h2>
+<para>
+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.<p>
+There are two kinds of places and fences:<br/>
+- Public places and fences that are created by MyPlace app can be used by all apps.<br/>
+- Private places and fences that are created by specified app can be used by the same app.<p>
+Notifications can be received about the following events:<br/>
+- Zone in when a device enters a specific area<br/>
+- Zone out when a device exits a specific area<br/>
+- Results and errors for each event requested to geofence module<p>
+The Geofence manager has the following properties:<br/>
+- geofence type<br/>
+- status<br/>
+- 'Service state change' callback
+</para>
+
+<h2>Related Features</h2>
+<para>To guarantee that the Geofence application runs on a device with Geofence profile feature,
+declare the following feature requirements in the config file:<br/>
+http://tizen.org/feature/location<br/>
+http://tizen.org/feature/location.geofence<br/>
+http://tizen.org/feature/location.wps
+</para>
+</remarks>
+*/
+namespace Tizen.Location.Geofence {}
diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence/VirtualPerimeter.cs b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/VirtualPerimeter.cs
new file mode 100755
index 0000000..0d5cffe
--- /dev/null
+++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/VirtualPerimeter.cs
@@ -0,0 +1,269 @@
+/*
+ * 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;
+using System.Collections.Generic;
+
+namespace Tizen.Location.Geofence
+{
+ /// <summary>
+ /// Allows to create a virtual fence as Geofence using GeofenceManager instance.
+ /// User can manage all the geofence/place related data and events.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ public class VirtualPerimeter
+ {
+ private IntPtr Handle;
+
+ /// <summary>
+ /// Creates a VirtualPerimeter which can be used to create virtual fence.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="manager">GeofenceManager instance.</param>
+ /// <exception cref="ArgumentException"> Incase of invlid parameter.</exception>
+ public VirtualPerimeter(GeofenceManager manager)
+ {
+ if (manager == null)
+ {
+ throw GeofenceErrorFactory.CreateException(GeofenceError.InvalidParameter, "Invalid GeofenceManager instance");
+ }
+ else
+ {
+ Handle = manager.Handle;
+ }
+ }
+
+ /// <summary>
+ /// Creates a new place for geofencing service.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="name">A place name to be created.</param>
+ /// <returns>The place id to be newly created on success.</returns>
+ /// <privilege>http://tizen.org/privilege/location</privilege>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter.</exception>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="UnauthorizedAccessException">Incase of Privileges are not defined.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public int AddPlaceName(string name)
+ {
+ int placeId = 0;
+ GeofenceError ret = (GeofenceError)Interop.VirtualPerimeter.AddPlace(Handle, name, out placeId);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to add place to Geofence Manager for " + name);
+ }
+
+ return placeId;
+ }
+
+ /// <summary>
+ /// Updates the place name of a given place id.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="placeId">The specified place id.</param>
+ /// <param name="name">A new place name of the place id.</param>
+ /// <privilege>http://tizen.org/privilege/location</privilege>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter.</exception>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="UnauthorizedAccessException">Incase of Privileges are not defined.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public void UpdatePlace(int placeId, string name)
+ {
+ GeofenceError ret = (GeofenceError)Interop.VirtualPerimeter.UpdatePlace(Handle, placeId, name);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to update place to Geofence Manager for " + placeId);
+ }
+ }
+
+ /// <summary>
+ /// Removes the specific place for geofencing service.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="placeId">The specified place id.</param>
+ /// <privilege>http://tizen.org/privilege/location</privilege>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter.</exception>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="UnauthorizedAccessException">Incase of Privileges are not defined.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public void RemovePlace(int placeId)
+ {
+ GeofenceError ret = (GeofenceError)Interop.VirtualPerimeter.RemovePlace(Handle, placeId);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to remove place from Geofence Manager for " + placeId);
+ }
+ }
+
+ /// <summary>
+ /// Adds a geofence for a given geofence manager.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="fence">The Geofence instance to be added.</param>
+ /// <returns>The geofence id to be newly created on success.</returns>
+ /// <remarks> The retun value will always be a number greater than zero.</remarks>
+ /// <privilege>http://tizen.org/privilege/location</privilege>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter.</exception>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="UnauthorizedAccessException">Incase of Privileges are not defined.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public int AddGeofence(Fence fence)
+ {
+ int fenceId = 0;
+ GeofenceError ret = (GeofenceError)Interop.VirtualPerimeter.AddFence(Handle, fence.Handle, out fenceId);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to add fence to Geofence Manager ");
+ }
+
+ return fenceId;
+ }
+
+ /// <summary>
+ /// Removes a geofence with a given geofence id.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="fenceId">The specified geofence id.</param>
+ /// <privilege>http://tizen.org/privilege/location</privilege>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter.</exception>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="UnauthorizedAccessException">Incase of Privileges are not defined.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public void RemoveGeofence(int fenceId)
+ {
+ GeofenceError ret = (GeofenceError)Interop.VirtualPerimeter.RemoveFence(Handle, fenceId);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to remove geofence from Geofence Manager for " + fenceId);
+ }
+ }
+
+ /// <summary>
+ /// Gets the name of place.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="placeId">The place id.</param>
+ /// <returns>The name of the place.</returns>
+ /// <privilege>http://tizen.org/privilege/location</privilege>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter.</exception>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="UnauthorizedAccessException">Incase of Privileges are not defined.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public string GetPlaceName(int placeId)
+ {
+ string name = "";
+ GeofenceError ret = (GeofenceError)Interop.VirtualPerimeter.GetPlaceName(Handle, placeId, out name);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to get placenamefrom Geofence Manager for " + placeId);
+ }
+
+ return name;
+ }
+
+ /// <summary>
+ /// Retrieves a list of places registered in the specified geofence manager.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <returns>list of places registered as PlaceData instance list.</returns>
+ /// <privilege>http://tizen.org/privilege/location</privilege>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="UnauthorizedAccessException">Incase of Privileges are not defined.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public IEnumerable<PlaceData> GetPlaceDataList()
+ {
+ List<PlaceData> places = new List<PlaceData>();
+ Interop.VirtualPerimeter.ForEachPlaceListCallback placeCallback = (int placeId, string name, int index, int count, IntPtr data) =>
+ {
+ if (count != 0)
+ {
+ PlaceData place = new PlaceData(placeId, name, index, count);
+ places.Add(place);
+ }
+ return true;
+ };
+
+ GeofenceError ret = (GeofenceError)Interop.VirtualPerimeter.GetForEachPlaceList(Handle, placeCallback, IntPtr.Zero);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to get Places list from Geofence Manager ");
+ }
+
+ return places;
+ }
+
+ /// <summary>
+ /// Retrieves a list of fences registered in the specified geofence manager.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <returns>list of FenceData instances registred for each Geofence.</returns>
+ /// <privilege>http://tizen.org/privilege/location</privilege>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="UnauthorizedAccessException">Incase of Privileges are not defined.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public IEnumerable<FenceData> GetFenceDataList()
+ {
+ List<FenceData> fences = new List<FenceData>();
+ Interop.VirtualPerimeter.ForEachFenceListCallback callback = (int fenceId, IntPtr handle, int index, int count, IntPtr data) =>
+ {
+ if (count != 0)
+ {
+ FenceData fence = new FenceData(fenceId, handle, index, count);
+ fences.Add(fence);
+ }
+ return true;
+ };
+
+ GeofenceError ret = (GeofenceError)Interop.VirtualPerimeter.GetForEachFenceList(Handle, callback, IntPtr.Zero);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to get Geofence list from Geofence Manager ");
+ }
+
+ return fences;
+ }
+
+ /// <summary>
+ /// Retrieves a list of fences registered in the specified place.
+ /// </summary>
+ /// <since_tizen>3</since_tizen>
+ /// <param name="placeId"> The place id.</param>
+ /// <returns>list of FenceData instances registred for each Geofence for specified place.</returns>
+ /// <privilege>http://tizen.org/privilege/location</privilege>
+ /// <exception cref="ArgumentException">Incase of Invalid parameter.</exception>
+ /// <exception cref="InvalidOperationException">Incase of any System error.</exception>
+ /// <exception cref="UnauthorizedAccessException">Incase of Privileges are not defined.</exception>
+ /// <exception cref="NotSupportedException">Incase of Geofence is not supported.</exception>
+ public IEnumerable<FenceData> GetGeofenceDataListByPlaceId(int placeId)
+ {
+ List<FenceData> fences = new List<FenceData>();
+ Interop.VirtualPerimeter.ForEachFenceListCallback callback = (int fenceId, IntPtr handle, int index, int count, IntPtr data) =>
+ {
+ FenceData fence = new FenceData(fenceId, handle, index, count);
+ fences.Add(fence);
+ return true;
+ };
+
+ GeofenceError ret = (GeofenceError)Interop.VirtualPerimeter.GetForEachPlaceFenceList(Handle, placeId, callback, IntPtr.Zero);
+ if (ret != GeofenceError.None)
+ {
+ throw GeofenceErrorFactory.CreateException(ret, "Failed to get Geofence list from Geofence Manager for " + placeId);
+ }
+
+ return fences;
+ }
+ }
+}