tizen 2.4 release accepted/tizen_2.4_mobile tizen_2.4 accepted/tizen/2.4/mobile/20151029.033338 submit/tizen_2.4/20151028.064107 tizen_2.4_mobile_release
authorjk7744.park <jk7744.park@samsung.com>
Sat, 24 Oct 2015 07:39:21 +0000 (16:39 +0900)
committerjk7744.park <jk7744.park@samsung.com>
Sat, 24 Oct 2015 07:39:21 +0000 (16:39 +0900)
14 files changed:
.gitignore [new file with mode: 0644]
AUTHORS [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0644]
LICENSE [new file with mode: 0644]
include/place_context_provider.h [new file with mode: 0644]
packaging/place-context-provider.manifest [new file with mode: 0644]
packaging/place-context-provider.spec [new file with mode: 0644]
place-context-provider.pc.in [new file with mode: 0644]
src/geofence/myplace_handle.cpp [new file with mode: 0644]
src/geofence/myplace_handle.h [new file with mode: 0644]
src/geofence/place_geofence.cpp [new file with mode: 0644]
src/geofence/place_geofence.h [new file with mode: 0644]
src/geofence/place_geofence_types.h [new file with mode: 0644]
src/place_context_provider.cpp [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..a01ee28
--- /dev/null
@@ -0,0 +1 @@
+.*.swp
diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..a86e881
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,2 @@
+Andrei Glushkov <a.glushkov@samsung.com>
+Mu-Woong Lee    <muwoong.lee@samsung.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e5efb63
--- /dev/null
@@ -0,0 +1,72 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(place-context-provider)
+INCLUDE(GNUInstallDirs)
+
+# Targets
+SET(target_provider "ctx-place-provider")
+
+# Source Lists
+FILE(GLOB SRCS src/*.cpp)
+
+# Dependencies
+SET(provider_deps "context-common")
+
+# Dependencies regarding profiles
+IF("${PROFILE}" STREQUAL "mobile")
+       ADD_DEFINITIONS("-D_MOBILE_")
+       FILE(GLOB SRCS ${SRCS} src/geofence/*.cpp)
+       SET(provider_deps "${provider_deps} capi-geofence-manager")
+ENDIF("${PROFILE}" STREQUAL "mobile")
+
+IF("${PROFILE}" STREQUAL "wearable")
+       ADD_DEFINITIONS("-D_WEARABLE_")
+ENDIF("${PROFILE}" STREQUAL "wearable")
+
+MESSAGE("Sources: ${SRCS}")
+
+# Common Options
+INCLUDE(FindPkgConfig)
+INCLUDE_DIRECTORIES(
+       ${CMAKE_CURRENT_SOURCE_DIR}/include
+       ${CMAKE_CURRENT_SOURCE_DIR}/src/shared
+)
+ADD_DEFINITIONS(-g -O2 -Wall -fPIC -fvisibility=hidden -Wl,--as-needed)
+
+# Build
+pkg_check_modules(provider_pkg REQUIRED ${provider_deps})
+
+FOREACH(flag ${provider_pkg_CFLAGS})
+       SET(PROVIDER_EXTRA_CFLAGS "${PROVIDER_EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+ADD_LIBRARY(${target_provider} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${target_provider} ${provider_pkg_LDFLAGS})
+SET_TARGET_PROPERTIES(${target_provider} PROPERTIES COMPILE_FLAGS ${PROVIDER_EXTRA_CFLAGS})
+SET_TARGET_PROPERTIES(${target_provider} PROPERTIES COMPILE_DEFINITIONS "LOG_TAG=\"CONTEXT-PLACE\"")
+SET_TARGET_PROPERTIES(${target_provider} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${target_provider} PROPERTIES VERSION ${FULLVER})
+
+
+# Installing
+INSTALL(TARGETS ${target_provider} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries)
+INSTALL(
+       DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/context-service/internal
+       FILES_MATCHING PATTERN "*.h"
+)
+
+SET(VERSION ${FULLVER})
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(PC_NAME ${PROJECT_NAME})
+SET(PC_INCLUDE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/context-service")
+SET(PC_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
+SET(PC_DESCRIPTION "Tizen Place Context Provider")
+SET(PC_REQUIRED ${provider_deps})
+SET(PC_LDFLAGS -l${target_provider})
+SET(PC_CFLAGS -I\${includedir}/context-service)
+
+CONFIGURE_FILE(
+       ${PROJECT_NAME}.pc.in
+       ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc
+       @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..1b01074
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,204 @@
+Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 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 (c) 2015 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.
+
diff --git a/include/place_context_provider.h b/include/place_context_provider.h
new file mode 100644 (file)
index 0000000..407838b
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __CONTEXT_PLACE_CONTEXT_PROVIDER_H__
+#define __CONTEXT_PLACE_CONTEXT_PROVIDER_H__
+
+namespace ctx {
+       bool init_place_context_provider();
+}
+
+#endif /* __CONTEXT_PLACE_CONTEXT_PROVIDER_H__ */
diff --git a/packaging/place-context-provider.manifest b/packaging/place-context-provider.manifest
new file mode 100644 (file)
index 0000000..a76fdba
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
diff --git a/packaging/place-context-provider.spec b/packaging/place-context-provider.spec
new file mode 100644 (file)
index 0000000..4849a71
--- /dev/null
@@ -0,0 +1,74 @@
+Name:       place-context-provider
+Summary:    Place Context Provider
+Version:    0.6.0
+Release:    1
+Group:      System/Libraries
+License:    Apache-2.0
+Source0:    %{name}-%{version}.tar.gz
+
+%define BUILD_PROFILE %{?profile}%{!?profile:%{?tizen_profile_name}}
+
+BuildRequires: cmake
+BuildRequires: pkgconfig(context-common)
+
+%if "%{?BUILD_PROFILE}" == "mobile"
+BuildRequires: pkgconfig(capi-geofence-manager)
+%endif
+
+%description
+Place Context Provider
+
+%prep
+%setup -q
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+
+export   CFLAGS+=" -Wextra -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wswitch-default"
+export CXXFLAGS+=" -Wextra -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wswitch-default -Wnon-virtual-dtor -Wno-c++0x-compat"
+
+export   CFLAGS+=" -Wno-unused-parameter -Wno-empty-body"
+export CXXFLAGS+=" -Wno-unused-parameter -Wno-empty-body"
+#export CXXFLAGS+=" -std=c++0x"
+
+export   CFLAGS+=" -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow -fno-common"
+export CXXFLAGS+=" -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow"
+
+export   CFLAGS+=" -DTIZEN_ENGINEER_MODE"
+export CXXFLAGS+=" -DTIZEN_ENGINEER_MODE"
+export   FFLAGS+=" -DTIZEN_ENGINEER_MODE"
+
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DPROFILE=%{?BUILD_PROFILE}
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE %{buildroot}/usr/share/license/%{name}
+
+%post
+/sbin/ldconfig
+
+%postun
+/sbin/ldconfig
+
+%files
+%manifest packaging/%{name}.manifest
+%defattr(-,root,root,-)
+%{_libdir}/*.so*
+/usr/share/license/%{name}
+
+%package devel
+Summary:    Place Context Provider (Development)
+Group:      System/Libraries
+Requires:      %{name} = %{version}-%{release}
+
+%description devel
+Place Context Provider (Development)
+
+%files devel
+%defattr(-,root,root,-)
+%{_includedir}/context-service/internal/*.h
+%{_libdir}/pkgconfig/%{name}.pc
diff --git a/place-context-provider.pc.in b/place-context-provider.pc.in
new file mode 100644 (file)
index 0000000..378b991
--- /dev/null
@@ -0,0 +1,13 @@
+#Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=@PREFIX@
+libdir=@PC_LIBDIR@
+includedir=@PC_INCLUDE@
+
+Name: @PC_NAME@
+Description: @PC_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
diff --git a/src/geofence/myplace_handle.cpp b/src/geofence/myplace_handle.cpp
new file mode 100644 (file)
index 0000000..cb830ff
--- /dev/null
@@ -0,0 +1,218 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include <types_internal.h>
+#include <json.h>
+#include <context_mgr.h>
+#include "place_geofence_types.h"
+#include "myplace_handle.h"
+
+ctx::myplace_handle::myplace_handle()
+       : _place_id(-1)
+       , prev_state(GEOFENCE_STATE_UNCERTAIN)
+       , geo_handle(NULL)
+{
+}
+
+ctx::myplace_handle::~myplace_handle()
+{
+       stop_monitor();
+}
+
+bool ctx::myplace_handle::start_monitor(int place_id)
+{
+       _D("Starts to monitor Place-%d", place_id);
+
+       IF_FAIL_RETURN(place_id >= 0, false);
+       IF_FAIL_RETURN_TAG(geo_handle == NULL, false, _E, "Re-starting MyPlace monitor");
+
+       geofence_manager_create(&geo_handle);
+       IF_FAIL_RETURN_TAG(geo_handle, false, _E, "Geofence initialization failed");
+
+       int ret;
+
+       ret = geofence_manager_set_geofence_state_changed_cb(geo_handle, fence_state_cb, this);
+       IF_FAIL_CATCH_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, _E, "Setting state callback failed");
+
+       ret = geofence_manager_set_geofence_event_cb(geo_handle, fence_event_cb, this);
+       IF_FAIL_CATCH_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, _E, "Setting event callback failed");
+
+       ret = geofence_manager_foreach_place_geofence_list(geo_handle, place_id, fence_list_cb, this);
+       IF_FAIL_CATCH_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, _E, "Getting fence list failed");
+
+       _place_id = place_id;
+       return true;
+
+CATCH:
+       stop_monitor();
+       return false;
+}
+
+int ctx::myplace_handle::get_place_id()
+{
+       return _place_id;
+}
+
+void ctx::myplace_handle::stop_monitor()
+{
+       _D("Stops monitoring Place-%d", _place_id);
+
+       //TODO: Do we need to stop all geofences explicitly?
+       if (geo_handle) {
+               geofence_manager_destroy(geo_handle);
+               geo_handle = NULL;
+       }
+
+       geo_state_map.clear();
+       _place_id = -1;
+       prev_state = GEOFENCE_STATE_UNCERTAIN;
+}
+
+bool ctx::myplace_handle::start_fence(int fence_id)
+{
+       int ret;
+
+       ret = geofence_manager_start(geo_handle, fence_id);
+       IF_FAIL_RETURN_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, true, _W, "Starting failed");
+
+       geofence_status_h status;
+       ret = geofence_status_create(fence_id, &status);
+       IF_FAIL_RETURN_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, true, _W, "Getting status failed");
+
+       geofence_state_e state = GEOFENCE_STATE_UNCERTAIN;
+       geofence_status_get_state(status, &state);
+       geofence_status_destroy(status);
+
+       geo_state_map[fence_id] = state;
+
+       return true;
+}
+
+void ctx::myplace_handle::remove_fence(int fence_id)
+{
+       geofence_manager_stop(geo_handle, fence_id);
+       geo_state_map.erase(fence_id);
+}
+
+void ctx::myplace_handle::update_fence(int fence_id, geofence_manage_e manage)
+{
+       switch (manage) {
+               case GEOFENCE_MANAGE_PLACE_REMOVED:
+                       _W("[Place-%d] Removed", _place_id);
+                       stop_monitor();
+                       break;
+               case GEOFENCE_MANAGE_FENCE_ADDED:
+                       _I("[Place %d] Fence-%d added", _place_id, fence_id);
+                       start_fence(fence_id);
+                       emit_state_change();
+                       break;
+               case GEOFENCE_MANAGE_FENCE_REMOVED:
+                       _I("[Place-%d] Fence-%d removed", _place_id, fence_id);
+                       remove_fence(fence_id);
+                       emit_state_change();
+                       break;
+               case GEOFENCE_MANAGE_FENCE_STARTED:
+                       _D("[Place-%d] Fence-%d started", _place_id, fence_id);
+                       break;
+               case GEOFENCE_MANAGE_FENCE_STOPPED:
+                       _D("[Place-%d] Fence-%d stopped", _place_id, fence_id);
+                       //TODO: Do we need to restart this?
+                       break;
+               default:
+                       _D("[Place-%d] Ignoring the manage event %d", _place_id, manage);
+                       break;
+       }
+}
+
+void ctx::myplace_handle::update_state(int fence_id, geofence_state_e state)
+{
+       geo_state_map[fence_id] = state;
+}
+
+static const char* get_state_string(geofence_state_e state)
+{
+       switch (state) {
+               case GEOFENCE_STATE_IN:
+                       return MYPLACE_EVENT_IN;
+               case GEOFENCE_STATE_OUT:
+                       return MYPLACE_EVENT_OUT;
+               case GEOFENCE_STATE_UNCERTAIN:
+                       return MYPLACE_EVENT_UNCERTAIN;
+               default:
+                       return MYPLACE_EVENT_UNCERTAIN;
+       }
+}
+
+void ctx::myplace_handle::emit_state_change()
+{
+       geofence_state_e current_state = GEOFENCE_STATE_UNCERTAIN;
+       int out_count = 0;
+
+       for (geo_state_map_t::iterator it = geo_state_map.begin(); it != geo_state_map.end(); ++it) {
+               if (it->second == GEOFENCE_STATE_IN) {
+                       current_state = GEOFENCE_STATE_IN;
+                       break;
+               } else if (it->second == GEOFENCE_STATE_OUT) {
+                       ++ out_count;
+               }
+       }
+
+       if (current_state != GEOFENCE_STATE_IN && out_count > 0) {
+               current_state = GEOFENCE_STATE_OUT;
+       }
+
+       if (current_state == prev_state) {
+               return;
+       }
+
+       prev_state = current_state;
+
+       json option;
+       option.set(NULL, PLACE_STATUS_DATA_MYPLACE_ID, _place_id);
+
+       json data;
+       data.set(NULL, PLACE_STATUS_DATA_MYPLACE_ID, _place_id);
+       data.set(NULL, PLACE_STATUS_DATA_MYPLACE_EVENT, get_state_string(current_state));
+
+       context_manager::publish(PLACE_SUBJ_GEOFENCE, option, ERR_NONE, data);
+}
+
+bool ctx::myplace_handle::fence_list_cb(int geofence_id, geofence_h fence, int fence_index, int fence_cnt, void* user_data)
+{
+       _D("FenceID: %d, Index: %d, Count: %d", geofence_id, fence_index, fence_cnt);
+       IF_FAIL_RETURN(fence_cnt > 0, false);
+
+       myplace_handle *handle = reinterpret_cast<myplace_handle*>(user_data);
+       return handle->start_fence(geofence_id);
+}
+
+void ctx::myplace_handle::fence_event_cb(int place_id, int geofence_id, geofence_manager_error_e error, geofence_manage_e manage, void* user_data)
+{
+       IF_FAIL_VOID_TAG(error == GEOFENCE_MANAGER_ERROR_NONE, _W, "Geofence error: %d", error);
+
+       myplace_handle *handle = reinterpret_cast<myplace_handle*>(user_data);
+
+       IF_FAIL_VOID_TAG(place_id == handle->get_place_id(), _W, "Mismatched Place ID");
+
+       handle->update_fence(geofence_id, manage);
+}
+
+void ctx::myplace_handle::fence_state_cb(int geofence_id, geofence_state_e state, void* user_data)
+{
+       myplace_handle *handle = reinterpret_cast<myplace_handle*>(user_data);
+       handle->update_state(geofence_id, state);
+       handle->emit_state_change();
+}
diff --git a/src/geofence/myplace_handle.h b/src/geofence/myplace_handle.h
new file mode 100644 (file)
index 0000000..c8b4913
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __CONTEXT_PLACE_MYPLACE_HANDLE_H__
+#define __CONTEXT_PLACE_MYPLACE_HANDLE_H__
+
+#include <set>
+#include <string>
+#include <map>
+#include <geofence_manager.h>
+
+namespace ctx {
+
+       class myplace_handle {
+
+               typedef std::map<int, geofence_state_e> geo_state_map_t;
+               typedef std::set<std::string> string_set_t;
+
+               public:
+                       myplace_handle();
+                       ~myplace_handle();
+
+                       bool start_monitor(int place_id);
+                       int get_place_id();
+
+               private:
+                       int _place_id;
+                       geofence_state_e prev_state;
+                       geofence_manager_h geo_handle;
+                       geo_state_map_t geo_state_map;
+
+                       void emit_state_change();
+                       void stop_monitor();
+                       bool start_fence(int fence_id);
+                       void remove_fence(int fence_id);
+                       void update_fence(int fence_id, geofence_manage_e manage);
+                       void update_state(int fence_id, geofence_state_e state);
+
+                       static bool fence_list_cb(int geofence_id, geofence_h fence, int fence_index, int fence_cnt, void* user_data);
+                       static void fence_event_cb(int place_id, int geofence_id, geofence_manager_error_e error, geofence_manage_e manage, void* user_data);
+                       static void fence_state_cb(int geofence_id, geofence_state_e state, void* user_data);
+       };
+
+}      /* namespace ctx */
+
+#endif /* __CONTEXT_PLACE_MYPLACE_HANDLE_H__ */
diff --git a/src/geofence/place_geofence.cpp b/src/geofence/place_geofence.cpp
new file mode 100644 (file)
index 0000000..53fb40b
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include <geofence_manager.h>
+
+#include <types_internal.h>
+#include <json.h>
+#include <context_mgr.h>
+#include "place_geofence.h"
+
+ctx::place_geofence_provider *ctx::place_geofence_provider::__instance = NULL;
+
+ctx::place_geofence_provider::place_geofence_provider()
+{
+}
+
+ctx::place_geofence_provider::~place_geofence_provider()
+{
+       for (handle_map_t::iterator it = __handle_map.begin(); it != __handle_map.end(); ++it) {
+               delete it->second;
+       }
+
+       __handle_map.clear();
+}
+
+ctx::context_provider_iface *ctx::place_geofence_provider::create(void *data)
+{
+       IF_FAIL_RETURN(!__instance, __instance);
+       __instance = new(std::nothrow) place_geofence_provider();
+       IF_FAIL_RETURN_TAG(__instance, NULL, _E, "Memory allocation failed");
+       _I(BLUE("Created"));
+       return __instance;
+}
+
+void ctx::place_geofence_provider::destroy(void *data)
+{
+       IF_FAIL_VOID(__instance);
+       delete __instance;
+       __instance = NULL;
+       _I(BLUE("Destroyed"));
+}
+
+bool ctx::place_geofence_provider::is_supported()
+{
+       bool supported = false;
+       int ret = geofence_manager_is_supported(&supported);
+       IF_FAIL_RETURN_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, false, _E, "geofence_manager_is_supported() failed");
+       return supported;
+}
+
+void ctx::place_geofence_provider::submit_trigger_item()
+{
+       context_manager::register_trigger_item(PLACE_SUBJ_GEOFENCE, OPS_SUBSCRIBE,
+                       "{"
+                               "\"Event\":{\"type\":\"string\",\"values\":[\"In\",\"Out\"]}"
+                       "}",
+                       "{"
+                               "\"PlaceId\":{\"type\":\"integer\",\"min\":1}"
+                       "}");
+}
+
+void ctx::place_geofence_provider::__destroy_if_unused()
+{
+       IF_FAIL_VOID(__handle_map.empty());
+       destroy(NULL);
+}
+
+
+int ctx::place_geofence_provider::subscribe(const char *subject, ctx::json option, ctx::json *request_result)
+{
+       int ret = __subscribe(option);
+       __destroy_if_unused();
+       return ret;
+}
+
+int ctx::place_geofence_provider::unsubscribe(const char *subject, ctx::json option)
+{
+       int ret = __unsubscribe(option);
+       __destroy_if_unused();
+       return ret;
+}
+
+int ctx::place_geofence_provider::read(const char *subject, ctx::json option, ctx::json *request_result)
+{
+       __destroy_if_unused();
+       return ERR_NOT_SUPPORTED;
+}
+
+int ctx::place_geofence_provider::write(const char *subject, ctx::json data, ctx::json *request_result)
+{
+       __destroy_if_unused();
+       return ERR_NOT_SUPPORTED;
+}
+
+int ctx::place_geofence_provider::__subscribe(ctx::json option)
+{
+       int pid = -1;
+       option.get(NULL, PLACE_STATUS_OPT_MYPLACE_ID, &pid);
+       IF_FAIL_RETURN_TAG(pid != -1, ERR_INVALID_PARAMETER, _E, "Getting PlaceID failed");
+
+       handle_map_t::iterator it = __handle_map.find(pid);
+       if (it != __handle_map.end()) {
+               _D("Place ID %d is being monitored already", pid);
+               return ERR_NONE;
+       }
+
+       myplace_handle *handle = new(std::nothrow) myplace_handle();
+       ASSERT_ALLOC(handle);
+
+       bool ret = handle->start_monitor(pid);
+       if (!ret) {
+               _E("Monitoring Place ID %d failed", pid);
+               delete handle;
+               return ERR_OPERATION_FAILED;
+       }
+
+       __handle_map[pid] = handle;
+
+       return ERR_NONE;
+}
+
+int ctx::place_geofence_provider::__unsubscribe(ctx::json option)
+{
+       int pid = -1;
+       option.get(NULL, PLACE_STATUS_OPT_MYPLACE_ID, &pid);
+       IF_FAIL_RETURN_TAG(pid != -1, ERR_INVALID_PARAMETER, _E, "Getting PlaceID failed");
+
+       handle_map_t::iterator it = __handle_map.find(pid);
+       if (it == __handle_map.end()) {
+               _D("Place ID %d is not being monitored", pid);
+               return ERR_NONE;
+       }
+
+       delete it->second;
+       __handle_map.erase(it);
+
+       return ERR_NONE;
+}
diff --git a/src/geofence/place_geofence.h b/src/geofence/place_geofence.h
new file mode 100644 (file)
index 0000000..9fb8ae8
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __CONTEXT_PLACE_GEOFENCE_H__
+#define __CONTEXT_PLACE_GEOFENCE_H__
+
+#include <map>
+#include <provider_iface.h>
+#include "myplace_handle.h"
+#include "place_geofence_types.h"
+
+namespace ctx {
+
+       class place_geofence_provider : public context_provider_iface {
+               typedef std::map<int, ctx::myplace_handle*> handle_map_t;
+
+       public:
+               static context_provider_iface *create(void *data);
+               static void destroy(void *data);
+               static bool is_supported();
+               static void submit_trigger_item();
+
+               int subscribe(const char *subject, ctx::json option, ctx::json *request_result);
+               int unsubscribe(const char *subject, ctx::json option);
+               int read(const char *subject, ctx::json option, ctx::json *request_result);
+               int write(const char *subject, ctx::json data, ctx::json *request_result);
+
+       private:
+               static place_geofence_provider *__instance;
+               handle_map_t __handle_map;
+
+               place_geofence_provider();
+               ~place_geofence_provider();
+
+               int __subscribe(ctx::json option);
+               int __unsubscribe(ctx::json option);
+               void __destroy_if_unused();
+       };
+
+}      /* namespace ctx */
+
+#endif /* __CONTEXT_PLACE_GEOFENCE_H__ */
diff --git a/src/geofence/place_geofence_types.h b/src/geofence/place_geofence_types.h
new file mode 100644 (file)
index 0000000..b9aa61a
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __CONTEXT_PLACE_GEOFENCE_TYPES__
+#define __CONTEXT_PLACE_GEOFENCE_TYPES__
+
+// Context Items
+#define PLACE_SUBJ_GEOFENCE            "place/geofence"
+
+#define PLACE_PRIV_GEOFENCE            "location"
+
+// Option Keys
+#define PLACE_STATUS_OPT_MYPLACE_ID            "PlaceId"
+
+// Data Keys
+#define PLACE_STATUS_DATA_MYPLACE_ID   "PlaceId"
+#define PLACE_STATUS_DATA_MYPLACE_EVENT        "Event"
+
+// Data Values
+#define        MYPLACE_EVENT_UNCERTAIN "Uncertain"
+#define        MYPLACE_EVENT_IN                "In"
+#define        MYPLACE_EVENT_OUT               "Out"
+
+#endif
diff --git a/src/place_context_provider.cpp b/src/place_context_provider.cpp
new file mode 100644 (file)
index 0000000..a0205b6
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include <types_internal.h>
+#include <context_mgr.h>
+#include <provider_iface.h>
+#include <place_context_provider.h>
+
+#ifdef _MOBILE_
+#include "geofence/place_geofence.h"
+#endif
+
+template<typename provider>
+void register_provider(const char *subject, const char *privilege)
+{
+       if (!provider::is_supported())
+               return;
+
+       ctx::context_provider_info provider_info(provider::create, provider::destroy, NULL, privilege);
+       ctx::context_manager::register_provider(subject, provider_info);
+       provider::submit_trigger_item();
+}
+
+EXTAPI bool ctx::init_place_context_provider()
+{
+#ifdef _MOBILE_
+       register_provider<place_geofence_provider>(PLACE_SUBJ_GEOFENCE, PLACE_PRIV_GEOFENCE);
+#endif
+       return true;
+}