From 60c68dc86a4b648a0f3a323fad447af5258bba42 Mon Sep 17 00:00:00 2001 From: chanywa Date: Tue, 27 Dec 2016 16:40:28 +0900 Subject: [PATCH] Tizen.Location.Geofence Setup Change-Id: I11f1136d736cfb7c3cefa50240b8dc6a81df16b1 --- LICENSE | 202 ++++++++++++ packaging/csapi-geofence.manifest | 5 + packaging/csapi-geofence.spec | 76 +++++ .../Interop/Interop.Libraries.cs | 24 ++ .../Interop/Interop.Location.cs | 151 +++++++++ .../Properties/AssemblyInfo.cs | 36 +++ .../Tizen.Location.Geofence.Net45.csproj | 68 ++++ .../Tizen.Location.Geofence.Net45.project.json | 11 + .../Tizen.Location.Geofence.csproj | 113 +++++++ .../Tizen.Location.Geofence.nuspec | 16 + .../Tizen.Location.Geofence.project.json | 17 + .../Tizen.Location.Geofence.snk | Bin 0 -> 596 bytes .../Tizen.Location.Geofence/Fence.cs | 324 +++++++++++++++++++ .../Tizen.Location.Geofence/FenceData.cs | 119 +++++++ .../Tizen.Location.Geofence/GeofenceEnum.cs | 168 ++++++++++ .../GeofenceErrorFactory.cs | 159 ++++++++++ .../Tizen.Location.Geofence/GeofenceEventArgs.cs | 149 +++++++++ .../Tizen.Location.Geofence/GeofenceManager.cs | 194 ++++++++++++ .../Tizen.Location.Geofence/VirtualPerimeter.cs | 348 +++++++++++++++++++++ 19 files changed, 2180 insertions(+) create mode 100644 LICENSE create mode 100644 packaging/csapi-geofence.manifest create mode 100755 packaging/csapi-geofence.spec create mode 100755 src/Tizen.Location.Geofence/Interop/Interop.Libraries.cs create mode 100755 src/Tizen.Location.Geofence/Interop/Interop.Location.cs create mode 100644 src/Tizen.Location.Geofence/Properties/AssemblyInfo.cs create mode 100644 src/Tizen.Location.Geofence/Tizen.Location.Geofence.Net45.csproj create mode 100644 src/Tizen.Location.Geofence/Tizen.Location.Geofence.Net45.project.json create mode 100644 src/Tizen.Location.Geofence/Tizen.Location.Geofence.csproj create mode 100644 src/Tizen.Location.Geofence/Tizen.Location.Geofence.nuspec create mode 100644 src/Tizen.Location.Geofence/Tizen.Location.Geofence.project.json create mode 100644 src/Tizen.Location.Geofence/Tizen.Location.Geofence.snk create mode 100755 src/Tizen.Location.Geofence/Tizen.Location.Geofence/Fence.cs create mode 100755 src/Tizen.Location.Geofence/Tizen.Location.Geofence/FenceData.cs create mode 100755 src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceEnum.cs create mode 100755 src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceErrorFactory.cs create mode 100755 src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceEventArgs.cs create mode 100755 src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceManager.cs create mode 100755 src/Tizen.Location.Geofence/Tizen.Location.Geofence/VirtualPerimeter.cs diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/packaging/csapi-geofence.manifest b/packaging/csapi-geofence.manifest new file mode 100644 index 0000000..75b0fa5 --- /dev/null +++ b/packaging/csapi-geofence.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/csapi-geofence.spec b/packaging/csapi-geofence.spec new file mode 100755 index 0000000..0611b61 --- /dev/null +++ b/packaging/csapi-geofence.spec @@ -0,0 +1,76 @@ +%{!?dotnet_assembly_path: %define dotnet_assembly_path /opt/usr/share/dotnet.tizen/framework} + +%if 0%{?tizen_build_devel_mode} +%define BUILDCONF Debug +%else +%define BUILDCONF Release +%endif + +Name: csapi-geofence +Summary: Tizen location geofence API for C# +Version: 1.0.0 +Release: 1 +Group: Development/Libraries +License: Apache-2.0 +URL: https://www.tizen.org +Source0: %{name}-%{version}.tar.gz +Source1: %{name}.manifest + +AutoReqProv: no + +BuildRequires: mono-compiler +BuildRequires: mono-devel + +BuildRequires: dotnet-build-tools + +# NuGet for Dependencies +BuildRequires: csapi-tizen-nuget + + +%description +geofence C# API for Tizen + +%prep +%setup -q +cp %{SOURCE1} . + +%define Assemblies Tizen.Location.Geofence + +%build +for ASM in %{Assemblies}; do +# NuGet Restore +find $ASM/*.project.json -exec nuget restore {} \; +# Build +find $ASM/*.csproj -exec xbuild {} /p:Configuration=%{BUILDCONF} \; +# NuGet Pack +nuget pack $ASM/$ASM.nuspec -Version %{version} -Properties Configuration=%{BUILDCONF} +done + +%install +# Runtime Binary +mkdir -p %{buildroot}%{dotnet_assembly_path} +for ASM in %{Assemblies}; do +%if 0%{?_with_corefx} + install -p -m 644 $ASM/bin/%{BUILDCONF}/$ASM.dll %{buildroot}%{dotnet_assembly_path} +%else + install -p -m 644 $ASM/bin/%{BUILDCONF}/Net45/$ASM.dll %{buildroot}%{dotnet_assembly_path} +%endif +done +# NuGet +mkdir -p %{buildroot}/nuget +install -p -m 644 *.nupkg %{buildroot}/nuget + +%files +%manifest %{name}.manifest +%license LICENSE +%attr(644,root,root) %{dotnet_assembly_path}/*.dll + +%package nuget +Summary: NuGet package for %{name} +Group: Development/Libraries + +%description nuget +NuGet package for %{name} + +%files nuget +/nuget/*.nupkg 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..9993ad4 --- /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 + { + public const string Geofence = "libcapi-geofence-manager.so.0"; + public 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..026da11 --- /dev/null +++ b/src/Tizen.Location.Geofence/Interop/Interop.Location.cs @@ -0,0 +1,151 @@ +/* + * 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")] + public 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); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_create_wifi")] + public 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); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_get_type")] + public 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); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_get_latitude")] + public 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); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_get_radius")] + public 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); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_get_bssid")] + public 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); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_status_get_state")] + public static extern int FenceState(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 partial class GeofenceManager + { + public delegate bool StateChangedCallback(int fenceId,GeofenceState state,IntPtr userData); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_is_supported")] + public static extern int IsSupported(out bool supported); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_create")] + public static extern int Create(out IntPtr handle); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_destroy")] + public static extern int Destroy(IntPtr handle); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_start")] + public static extern int Start(IntPtr handle, int fenceId); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_stop")] + public 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); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_unset_geofence_state_changed_cb")] + public static extern int UnsetStateChangedCB(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); + + 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); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_add_place")] + public 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); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_remove_place")] + public 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); + + [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); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_foreach_geofence_list")] + public 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); + + [DllImport(Libraries.Geofence, EntryPoint = "geofence_manager_foreach_place_list")] + public 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); + + } +} diff --git a/src/Tizen.Location.Geofence/Properties/AssemblyInfo.cs b/src/Tizen.Location.Geofence/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..43a6d0c --- /dev/null +++ b/src/Tizen.Location.Geofence/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tizen.Location")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tizen.Location")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a5d934e0-284a-42b9-8395-34b92fb32e63")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence.Net45.csproj b/src/Tizen.Location.Geofence/Tizen.Location.Geofence.Net45.csproj new file mode 100644 index 0000000..32ac5af --- /dev/null +++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence.Net45.csproj @@ -0,0 +1,68 @@ + + + + + Debug + AnyCPU + {47F9D980-5C53-495D-973A-E996ECDBE744} + Library + Properties + Tizen.Location + Tizen.Location.Geofence + v4.5 + 512 + + + true + full + false + bin\Debug\Net45\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\Net45\ + TRACE + prompt + 4 + + + true + + + Tizen.Location.Geofence.snk + + + + + + ..\..\..\..\system\tct-system-device-tizen-tests\lib\Tizen.dll + + + + + + + + + + + + + + + + + + + + diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence.Net45.project.json b/src/Tizen.Location.Geofence/Tizen.Location.Geofence.Net45.project.json new file mode 100644 index 0000000..5787764 --- /dev/null +++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence.Net45.project.json @@ -0,0 +1,11 @@ +{ + "dependencies": { + "Tizen": "1.0.0" + }, + "frameworks": { + "net45": {} + }, + "runtimes": { + "win": {} + } +} 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..8cb67cb --- /dev/null +++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence.csproj @@ -0,0 +1,113 @@ + + + + 14.0 + Debug + AnyCPU + 8.0.30703 + 2.0 + {A5D934E0-284A-42B9-8395-34B92FB32E63} + Library + Properties + Tizen.Location + Tizen.Location.Geofence + 512 + en-US + + + .NETStandard + v1.6 + .NETStandard,Version=v1.6 + .NETStandard,Version=v1.6 + false + true + $(NoWarn);1701 + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + + + Tizen.Location.Geofence.snk + + + + + + + + + + + + + + + + + + + + + + + + + <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory) + <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) + true + + + + $(MSBuildExtensionsPath)\Tizen + $(TizenBuildPath)\bin + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence.nuspec b/src/Tizen.Location.Geofence/Tizen.Location.Geofence.nuspec new file mode 100644 index 0000000..e72255c --- /dev/null +++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence.nuspec @@ -0,0 +1,16 @@ + + + + Tizen.Location.Geofence + $version$ + Tizen Developers + Geofence management APIs for Tizen.Location + + + + + + + + + diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence.project.json b/src/Tizen.Location.Geofence/Tizen.Location.Geofence.project.json new file mode 100644 index 0000000..27943bf --- /dev/null +++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence.project.json @@ -0,0 +1,17 @@ +{ + "buildOptions": { + "debugType": "portable", + "platform": "AnyCPU", + "preserveCompilationContext": true + }, + "dependencies": { + "NETStandard.Library": "1.6.0", + "Tizen": "1.0.0" + }, + "runtimes": { + "win": {} + }, + "frameworks": { + "netstandard1.6": {} + } +} diff --git a/src/Tizen.Location.Geofence/Tizen.Location.Geofence.snk b/src/Tizen.Location.Geofence/Tizen.Location.Geofence.snk new file mode 100644 index 0000000000000000000000000000000000000000..cd1b1ad166e9391c65567559c91269087641f48e GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50098|uaKGkKC-FW%08|^jo1*D{j!-q9K+mx zFiYPqqtM5RUwUEDuiLksaU(JV!}ys~cha>N@5js3Hg(9h=sjn^y?)x`h%tD{bb%`ZeFbuT=J0ouga7n2k7eI2GmuIozx0?PM?zT zFu&!gtX_~A&obfD%WT}WOeseU^i0h9_L4JK_Rr*ODGh1`cxu8*uS?=@ZXEOK%+YyD zm1s7*az2Jt-L}fB@5*K{Yq`Mnd&c7DIbe1i>-NcdDg9?Lp98X40vV z6_b5M&F0}lvBa`?KqUinCF#l3-zmA_WgP5+Ij2AD%6bgLgmE(1zrXXGgfN_?R8|r8 zTR8b48K2b&TFs3#f37~%Kz1_-FT*A2FT#m)bIta~a8C&hue4Irk54)Dq5mkK%IOik zI@->oG)gTRne09NU4Qma3QNS|=1KO|0Kxvx{l>x*3gCu>Nf6#Vc37`qe$-)X zC5If6{1X+wDtMEb^xXDGV$0O22pim2u_X}wx#L1x5gkt&tWYwG*T1-r0u=w)a9Q#m z%>y^+ww1M^(@)Pyv(_R#UuYC#6z7H9S9PfRmQ<}lKQHrq{3 iz=wOwotBnTzZ%Bc`Qg&+W3=K;e4z8eW33sg*AiF|JTyE2 literal 0 HcmV?d00001 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..d2e1ed6 --- /dev/null +++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/Fence.cs @@ -0,0 +1,324 @@ +/* + * 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 +{ + /// + /// 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. + /// + /// Geopoint: Geofence is specified by coordinates (Latitude and Longitude) and Radius + /// WIFI: Geofence is specified by BSSID of Wi-Fi access point + /// BT: Geofence is specified by Bluetooth address + /// + /// 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. + /// + public class Fence : IDisposable + { + internal IntPtr Handle + { + get; + set; + } + + + internal Fence(IntPtr handle) + { + Handle = handle; + } + + ~Fence() + { + Dispose(false); + } + /// + /// Gets the type of geofence + /// + 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; + } + } + + /// + /// Gets the id of place. + /// + 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; + } + } + + /// + ///Gets the longitude of geofence. + /// + 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; + + } + } + + /// + ///Gets the latitude of geofence. + /// + 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; + } + } + + /// + /// Gets the radius of geofence. + /// + 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; + } + } + + /// + /// Gets the state of geofence. + /// + 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; + } + } + + /// + /// Gets the amount of seconds geofence is in the current state. + /// + 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; + } + } + + /// + /// Gets the address of geofence. + /// + 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; + } + } + + /// + /// Gets the bssid of geofence. + /// + 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; + } + } + + /// + ///Gets the ssid of geofence. + /// + 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; + } + } + + /// + /// Creates a geopoint type of new geofence. + /// + /// The current place id + /// Specifies the value of latitude of geofence [-90.0 ~ 90.0] (degrees) + /// Specifies the value of longitude of geofence [-180.0 ~ 180.0] (degrees) + /// Specifies the value of radius of geofence [100 ~ 500](meter) + /// Specifies the value of address + /// Newly created geofence instance + /// Incase of Invalid parameter + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + 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); + } + + /// + /// Creates a Wi-Fi type of new geofence. + /// + /// The current place id + /// Specifies the value of BSSID of Wi-Fi MAC address + /// Specifies the value of SSID of Wi-Fi Device + /// Newly created geofence instance + /// Incase of Invalid parameter + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + 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); + } + + /// + /// Creates a bluetooth type of new geofence. + /// + /// The current place id + /// Specifies the value of BSSID of BT MAC address + /// Specifies the value of SSID of BT Device + /// Newly created geofence instance + /// Incase of Invalid parameter + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + 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); + } + + /// + /// Overloaded Dispose API for destroying the fence Handle. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (!disposing) + { + if (Handle != IntPtr.Zero) + { + Interop.Geofence.Destroy(Handle); + Handle = IntPtr.Zero; + } + } + } + } +} 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..1fd8395 --- /dev/null +++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/FenceData.cs @@ -0,0 +1,119 @@ +/* + * 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 +{ + /// + /// Represents the Geofence list Item data. + /// + public class FenceData + { + internal FenceData(int fenceId, IntPtr handle, int index, int count) + { + GeofenceId = fenceId; + Fence = new Fence(handle); + Index = index; + Count = count; + } + /// + /// Geofence instance + /// + public Fence Fence + { + get; + internal set; + } + + /// + /// The geofence id + /// + public int GeofenceId + { + get; + internal set; + } + + /// + /// The index number of the fences in the list. + /// Index value starts from 1. + /// + public int Index + { + get; + internal set; + } + + /// + /// The total number of fences that exists for the requester + /// + public int Count + { + get; + internal set; + } + }; + + /// + /// Represents the Place list Item data. + /// + public class PlaceData + { + internal PlaceData(int id, string name, int index, int count) + { + PlaceId = id; + Name = name; + Index = index; + Count = count; + } + /// + /// The current place id + /// + public int PlaceId + { + get; + internal set; + } + + /// + /// The current place name + /// + public string Name + { + get; + internal set; + } + + /// + /// The index number of the places in the list. + /// Index value starts from 1. + /// + public int Index + { + get; + internal set; + } + + /// + /// The total number of places that exists for the requester + /// + public int Count + { + get; + internal set; + } + }; +} 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..7e7c250 --- /dev/null +++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceEnum.cs @@ -0,0 +1,168 @@ +/* + * 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 +{ + /// + /// Enumeration for geofence type + /// + public enum FenceType + { + /// + /// Geofence is specified by geospatial coordinate + /// + GeoPoint = 1, + + /// + /// Geofence is specified by Wi-Fi access point + /// + Wifi, + + /// + /// Geofence is specified by Bluetooth device + /// + Bluetooth + }; + + /// + /// Enumerations for the state of geofence manager. + /// + public enum GeofenceState + { + /// + /// Uncertain state of geofence + /// + Uncertain = 0, + + /// + /// Geofence In state + /// + In, + + /// + /// Geofence Out state + /// + Out + }; + + /// + /// Enumerations for geofence management events. + /// + public enum GeoFenceEventType + { + /// + ///Geofence is added + /// + FenceAdded = 0, + + /// + /// Geofence is removed + /// + FenceRemoved, + + /// + ///Geofencing is started + /// + FenceStarted, + + /// + /// Geofencing is stopped + /// + FenceStopped, + + /// + ///Place is added + /// + PlaceAdded = 0x10, + + /// + /// Place is removed + /// + PlaceRemoved, + + /// + ///Place is updated + /// + PlaceUpdated, + + /// + /// Setting for geofencing is enabled + /// + SettingEnabled = 0x20, + + /// + /// Setting for geofencing is disabled + /// + SettingDisabled + }; + + /// + /// Enumeration for the provider of proximity + /// + public enum ProximityProvider + { + /// + /// Proximity is specified by geospatial coordinate + /// + Location, + + /// + /// Proximity is specified by Wi-Fi access point + /// + WiFi, + + /// + /// Proximity is specified by Bluetooth device + /// + Bluetooth, + + /// + ///Proximity is specified by Bluetooth low energy device + /// + BLE, + + /// + /// Proximity is specified by Sensor + /// + Sensor + } + + /// + /// Enumeration for the state of proximity. + /// + public enum ProximityState + { + /// + /// Uncertain state of proximity + /// + Uncertain, + + /// + /// Far state of proximity + /// + Far, + + /// + /// Far state of proximity + /// + Near, + + /// + /// Immediate state of proximity + /// + 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..3bfe774 --- /dev/null +++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceErrorFactory.cs @@ -0,0 +1,159 @@ +/* + * 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 +{ + /// + /// Enum to give the type of error occured, if any. + /// + public enum GeofenceError + { + /// + /// Successful. + /// + None = Tizen.Internals.Errors.ErrorCode.None, + + /// + /// Out of memory. + /// + OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, + + /// + /// Invalid parameter. + /// + InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, + + /// + /// Permission denied. + /// + PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, + + /// + /// Not Supported + /// + NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported, + + /// + ///Geofence Manager is not initialized + /// + NotInitialized = -0x02C00000 | 0x100 | 0x01, + + /// + ///Invalid geofence ID + /// + InvalidID = -0x02C00000 | 0x100 | 0x02, + + /// + /// Exception occurs + /// + Exception = -0x02C00000 | 0x100 | 0x03, + + /// + ///Geofencing is already started + /// + AlreadyStarted = -0x02C00000 | 0x100 | 0x04, + + /// + ///Too many geofence + /// + TooManyGeofence = -0x02C00000 | 0x100 | 0x05, + + /// + ///Error in GPS, Wi-Fi, or BT + /// + IPC = -0x02C00000 | 0x100 | 0x06, + + /// + ///DB error in the server side + /// + DBFailed = -0x02C00000 | 0x100 | 0x07, + + /// + ///Access to specified place is denied + /// + PlaceAccessDenied = -0x02C00000 | 0x100 | 0x08, + + /// + /// Access to specified geofence is denied + /// + 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..bffb98b --- /dev/null +++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceEventArgs.cs @@ -0,0 +1,149 @@ +/* + * 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 +{ + /// + /// Event arguments passed when Event is triggered to notify proximity state change. + /// + public class ProximityStateEventArgs: EventArgs + { + /// + /// Internal constructor + /// + /// The geofence id + /// The proximity state + /// The proximity provider + internal ProximityStateEventArgs(int id, ProximityState state, ProximityProvider provider) + { + GeofenceId = id; + State = state; + Provider = provider; + } + + /// + /// The geofence id + /// + public int GeofenceId + { + get; + } + + /// + /// The proximity state + /// + public ProximityState State + { + get; + } + + /// + /// The proximity provider + /// + public ProximityProvider Provider + { + get; + } + }; + + /// + /// Event arguments passed when Event is triggered to notify Geofence state change. + /// + public class GeofenceStateEventArgs :EventArgs + { + /// + /// Internal constructor + /// + /// The specified geofence id + /// The geofence state + internal GeofenceStateEventArgs(int fenceId, GeofenceState state) + { + GeofenceId = fenceId; + State = state; + } + + /// + /// The specified geofence id + /// + public int GeofenceId + { + get; + } + + /// + /// The geofence state + /// + public GeofenceState State + { + get; + } + } + + /// + /// Event arguments passed when Event occurs in geofence and place such as add, update, etc.. + /// + public class GeofenceResponseEventArgs : EventArgs + { + /// + /// Internal constructor + /// + /// The place id + /// The specified geofence id + /// The error code for the particular action + /// The result code for the particular place and geofence management + internal GeofenceResponseEventArgs(int placeId, int fenceId, GeofenceError error, GeoFenceEventType eventType) + { + PlaceId = placeId; + FenceId = fenceId; + ErrorCode = error; + EventType = eventType; + } + + /// + /// The place id + /// + public int PlaceId + { + get; + } + + /// + /// The specified geofence id + /// + public int FenceId + { + get; + } + + /// + /// The error code for the particular action + /// + public GeofenceError ErrorCode + { + get; + } + + /// + /// The result code for the particular place and geofence management + /// + 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..1c5ff19 --- /dev/null +++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/GeofenceManager.cs @@ -0,0 +1,194 @@ +/* + * 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 +{ + /// + /// 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. + /// + /// Public places and fences that are created by MyPlace app can be used by all apps. + /// Private places and fences that are created by specified app can be used by the same app. + /// + /// Notifications can be received about the following events: + /// Zone in when a device enters a specific area + /// Zone out when a device exits a specific area + /// Results and errors for each event requested to geofence module + /// + /// + public class GeofenceManager : IDisposable + { + internal IntPtr Handle + { + get; + set; + } + + /// + /// Creates a new geofence manager. + /// + /// Incase of OutOfMemory condition + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + 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); + } + + /// + /// Checks whether the geofence manager is available or not. + /// + 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; + } + } + + /// + /// Starts the geofencing service. + /// + /// The specified geofence id + /// http://tizen.org/privilege/location + /// + /// When the location service is enabled, the StateChanged event is invoked and the service starts + /// + /// Incase of Invalid parameter + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + 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); + } + } + + /// + /// Stops the geofenceing service. + /// + /// The specified geofence id + /// http://tizen.org/privilege/location + /// + ///This function initiates the process of stopping the service. + ///You can stop and start the geofence manager as needed. + /// + /// Incase of Invalid parameter + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + 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 s_stateChanged = null; + + /// + /// Invokes when a device enters or exits the given geofence, If this event is registered. + /// + /// + /// Call to Start() will invoke this event. + /// + /// Incase of feature Not supported + public event EventHandler 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"); + } + } + } + } + + /// + /// Overloaded Dispose API for destroying the GeofenceManager Handle. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (!disposing) + { + if (Handle != IntPtr.Zero) + { + Interop.GeofenceManager.Destroy(Handle); + Handle = IntPtr.Zero; + } + } + } + } +} 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..9cf128d --- /dev/null +++ b/src/Tizen.Location.Geofence/Tizen.Location.Geofence/VirtualPerimeter.cs @@ -0,0 +1,348 @@ +/* + * 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 +{ + /// + /// Allows to create a virtual fence as Geofence using GeofenceManager instance. + /// User can manage all the geofence/place related data and events. + /// + public class VirtualPerimeter + { + private IntPtr Handle; + + /// + /// Creates a VirtualPerimeter which can be used to create virtual fence. + /// + /// GeofenceManager instance + /// Incase of invlid parameter + public VirtualPerimeter(GeofenceManager manager) + { + if (manager == null) + { + throw GeofenceErrorFactory.CreateException(GeofenceError.InvalidParameter, "Invalid GeofenceManager instance"); + } + else + { + Handle = manager.Handle; + } + } + + /// + /// Creates a new place for geofencing service. + /// + /// A place name to be created + /// The place id to be newly created on success + /// http://tizen.org/privilege/location + /// Incase of Invalid parameter + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + 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; + } + + /// + /// Updates the place name of a given place id. + /// + /// The specified place id + /// A new place name of the place id + /// http://tizen.org/privilege/location + /// Incase of Invalid parameter + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + 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); + } + } + + /// + /// Removes the specific place for geofencing service. + /// + /// The specified place id + /// http://tizen.org/privilege/location + /// Incase of Invalid parameter + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + 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); + } + } + + /// + /// Adds a geofence for a given geofence manager. + /// + /// The Geofence instance to be added. + /// The geofence id to be newly created on success + /// The retun value will always be a number greater than zero + /// http://tizen.org/privilege/location + /// Incase of Invalid parameter + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + 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; + } + + /// + /// Removes a geofence with a given geofence id. + /// + /// The specified geofence id + /// http://tizen.org/privilege/location + /// Incase of Invalid parameter + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + 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); + } + } + + /// + /// Gets the name of place. + /// + /// The place id + /// The name of the place + /// http://tizen.org/privilege/location + /// Incase of Invalid parameter + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + 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; + } + + /// + /// Retrieves a list of places registered in the specified geofence manager. + /// + /// list of places registered as PlaceData instance list. + /// http://tizen.org/privilege/location + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + public IEnumerable GetPlaceDataList() + { + List places = new List(); + 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; + } + + /// + /// Retrieves a list of fences registered in the specified geofence manager. + /// + /// list of FenceData instances registred for each Geofence + /// http://tizen.org/privilege/location + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + public IEnumerable GetFenceDataList() + { + List fences = new List(); + 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; + } + + /// + /// Retrieves a list of fences registered in the specified place. + /// + /// The place id + /// list of FenceData instances registred for each Geofence for specified place + /// http://tizen.org/privilege/location + /// Incase of Invalid parameter + /// Incase of any System error + /// Incase of Pvivileges are not defined + /// Incase of Geofence is not supported + public IEnumerable GetGeoFenceDataListByPlaceId(int placeId) + { + List fences = new List(); + 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; + } + + 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 s_proximityChanged; + + /// + /// Called when a proximity state of device is changed. + /// + /// + /// Call to Start() will invoke this event. + /// + /// Incase of feature Not supported + public event EventHandler 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 s_geofenceEventChanged; + + /// + /// 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. + /// + /// + /// 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. + /// + /// Incase of feature Not supported + public event EventHandler 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"); + } + } + } + } + } +} -- 2.7.4