tizen 2.4 release accepted/tizen/2.4/mobile/20151029.032950 submit/tizen_2.4/20151028.064231 tizen_2.4_mobile_release
authorjk7744.park <jk7744.park@samsung.com>
Sat, 24 Oct 2015 07:44:01 +0000 (16:44 +0900)
committerjk7744.park <jk7744.park@samsung.com>
Sat, 24 Oct 2015 07:44:01 +0000 (16:44 +0900)
31 files changed:
.gitignore [new file with mode: 0644]
AUTHORS [new file with mode: 0755]
CMakeLists.txt [new file with mode: 0755]
LICENSE [new file with mode: 0755]
capi-geofence-manager.manifest [new file with mode: 0755]
capi-geofence-manager.pc.in [new file with mode: 0755]
doc/geofence-manager-doc.h [new file with mode: 0644]
include/geofence_manager.h [new file with mode: 0644]
include/geofence_type.h [new file with mode: 0644]
packaging/capi-geofence-manager.changes [new file with mode: 0644]
packaging/capi-geofence-manager.spec [new file with mode: 0644]
src/geofence_manager.c [new file with mode: 0644]
src/geofence_settings.h [new file with mode: 0644]
src/manager/geofence-ielement.c [new file with mode: 0755]
src/manager/geofence-ielement.h [new file with mode: 0644]
src/manager/geofence-internal.c [new file with mode: 0644]
src/manager/geofence-internal.h [new file with mode: 0644]
src/manager/geofence-log.c [new file with mode: 0644]
src/manager/geofence-log.h [new file with mode: 0644]
src/manager/geofence-marshal.list [new file with mode: 0644]
src/manager/geofence-param.c [new file with mode: 0644]
src/manager/geofence-param.h [new file with mode: 0644]
src/manager/geofence-privacy.c [new file with mode: 0644]
src/manager/geofence-privacy.h [new file with mode: 0644]
src/manager/geofence-type-private.h [new file with mode: 0644]
src/manager/geofence.c [new file with mode: 0644]
src/manager/geofence.h [new file with mode: 0644]
src/manager/include/geofence_data_type.h [new file with mode: 0644]
src/manager/include/geofence_module.h [new file with mode: 0644]
src/manager/module-internal.c [new file with mode: 0644]
src/manager/module-internal.h [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..f05287e
--- /dev/null
@@ -0,0 +1,2 @@
+*.[oa]
+*~
diff --git a/AUTHORS b/AUTHORS
new file mode 100755 (executable)
index 0000000..a8e91db
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,8 @@
+Young-Ae Kang <youngae.kang@samsung.com>\r
+JongMun Woo <jongmun.woo@samsung.com>\r
+Kyoungjun Sung <kj7.sung@samsung.com>\r
+Woo-Young Kim <woo02.kim@samsung.com>\r
+Bono Koo <mw.koo@samsung.com>\r
+Ki-Sun SHIN <kisun47.shin@samsung.com>\r
+bosung kwak <bosung.kwak@samsung.com>\r
+Areum Choi <arumi.choi@samsung.com>\r
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..2cea97f
--- /dev/null
@@ -0,0 +1,130 @@
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-geofence-manager")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR
+    include
+    src
+    src/manager
+    src/manager/include
+    )
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+SET(dependents "dlog vconf glib-2.0 gmodule-2.0 capi-appfw-app-manager capi-appfw-package-manager pkgmgr-info privacy-manager-client capi-system-info")
+SET(pc_dependents "capi-base-common")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${dependents})
+FOREACH(flag ${${fw_name}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fvisibility=hidden -fPIC -Werror")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+IF("${ARCH}" STREQUAL "arm")
+    ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DEXPORT_API=__attribute__((visibility(\"default\")))")
+ADD_DEFINITIONS("-DTIZEN_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib")
+
+# Source Lists
+SET(API_SRCS
+    src/geofence_manager.c
+)
+
+aux_source_directory(src/manager MANAGER_SRCS)
+
+ADD_LIBRARY(${fw_name} SHARED ${API_SRCS} ${MANAGER_SRCS})
+
+IF (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/manager/geofence-marshal.c)
+    MESSAGE ("")
+    MESSAGE ("<<< Generating geofence-marshal.c >>>")
+
+    EXECUTE_PROCESS(
+        COMMAND glib-genmarshal --header --prefix=geofence ${CMAKE_CURRENT_SOURCE_DIR}/src/manager/geofence-marshal.list
+        OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/manager/geofence-marshal.h
+    )
+
+    EXECUTE_PROCESS(
+        COMMAND glib-genmarshal --body --prefix=geofence ${CMAKE_CURRENT_SOURCE_DIR}/src/manager/geofence-marshal.list
+        OUTPUT_VARIABLE marshal_var
+    )
+
+    EXECUTE_PROCESS(
+        COMMAND echo "#include \"geofence-marshal.h\" ${marshal_var}"
+        OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/manager/geofence-marshal.c
+    )
+
+ENDIF (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/manager/geofence-marshal.c)
+
+SET_TARGET_PROPERTIES(${fw_name}
+     PROPERTIES
+     VERSION ${FULLVER}
+     SOVERSION ${MAJORVER}
+     CLEAN_DIRECT_OUTPUT 1
+)
+
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
+
+INSTALL(TARGETS ${fw_name} DESTINATION lib)
+INSTALL(DIRECTORY include/ DESTINATION include/geofence PATTERN "*.h")
+INSTALL(DIRECTORY src/manager/include/ DESTINATION include/geofence PATTERN "*.h")
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${pc_dependents})
+SET(PC_LDFLAGS -l${fw_name})
+SET(PC_CFLAGS -I\${includedir}/geofence)
+
+CONFIGURE_FILE(
+    ${fw_name}.pc.in
+    ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc
+    @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig)
+
+# Test Suite
+#IF("${BINTYPE}" STREQUAL "eng")
+#      ADD_SUBDIRECTORY(test)
+#ENDIF("${BINTYPE}" STREQUAL "eng")
+
+IF(UNIX)
+
+ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
+ADD_CUSTOM_COMMAND(
+        DEPENDS clean
+        COMMENT "distribution clean"
+        COMMAND find
+        ARGS    .
+        -not -name config.cmake -and \(
+        -name tester.c -or
+        -name Testing -or
+        -name CMakeFiles -or
+        -name cmake.depends -or
+        -name cmake.check_depends -or
+        -name CMakeCache.txt -or
+        -name cmake.check_cache -or
+        -name *.cmake -or
+        -name Makefile -or
+        -name core -or
+        -name core.* -or
+        -name gmon.out -or
+        -name install_manifest.txt -or
+        -name *.pc -or
+        -name *~ \)
+        | grep -v TC | xargs rm -rf
+        TARGET  distclean
+        VERBATIM
+)
+
+ENDIF(UNIX)
+
diff --git a/LICENSE b/LICENSE
new file mode 100755 (executable)
index 0000000..f94008a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,206 @@
+Copyright (c) 2000 - 2011 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 [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/capi-geofence-manager.manifest b/capi-geofence-manager.manifest
new file mode 100755 (executable)
index 0000000..97e8c31
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_"/>
+       </request>
+</manifest>
diff --git a/capi-geofence-manager.pc.in b/capi-geofence-manager.pc.in
new file mode 100755 (executable)
index 0000000..5cf130c
--- /dev/null
@@ -0,0 +1,15 @@
+
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=/usr/lib
+includedir=/usr/include/geofence
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@ 
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
+
diff --git a/doc/geofence-manager-doc.h b/doc/geofence-manager-doc.h
new file mode 100644 (file)
index 0000000..280863a
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2011-2014 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.
+ */
+
+
+#ifndef __TIZEN_LOCATION_GEOFENCE_MANAGER_DOC_H__
+#define __TIZEN_LOCATION_GEOFENCE_MANAGER_DOC_H__
+
+/**
+ * @ingroup CAPI_LOCATION_FRAMEWORK
+ * @defgroup CAPI_GEOFENCE_MANAGER_MODULE Geofence Manager
+ * @brief This Geofence Manager API provides service related to geofence(geo-fence).
+ *
+ * @section CAPI_GEOFENCE_MANAGER_MODULE_HEADER Required Header
+ *   \#include <geofence_manager.h>
+ *
+ * @section CAPI_GEOFENCE_MANAGER_MODULE_OVERVIEW Overview
+ * This Geofence Manager API provides service related to geofence(geo-fence). A geofence is a virtual perimeter for a real-world geographic area.
+ * This API provides functions to set geofence with geopoint, MAC address of Wi-Fi and Bluetooth address. And, notifications on events like changing in service status are provided.
+ *
+ * There are two kinds of places and fences:
+ * - 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
+ *
+ * The Geofence manager has the following properties:
+ * - geofence type
+ * - status
+ * - 'Service state change' callback
+ *
+ * The geofence type property of geofence manager (#geofence_type_e) specified the type of virtual perimeter.
+ *
+ * The status property describes the current state and duration of a geofence.
+ * state (#geofence_state_e) can be uncertain, in, or out.
+ *
+ * @section CAPI_GEOFENCE_MANAGER_MODULE_FEATURE Related Features
+ * This API is related with the following features:\n
+ *  - http://tizen.org/feature/location\n
+ *  - http://tizen.org/feature/location.geofence\n
+ *
+ * It is recommended to design feature related codes in your application for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ */
+
+/**
+ * @ingroup CAPI_GEOFENCE_MANAGER_MODULE
+ * @defgroup CAPI_GEOFENCE_MODULE Geofence
+ * @brief The Geofence defines a virtual perimeter.
+ *
+ *
+ * @section CAPI_GEOFENCE_MODULE_HEADER Required Header
+ *   \#include <geofence_manager.h>
+ *
+ * @section CAPI_GEOFENCE_MODULE_OVERVIEW Overview
+ *
+ * 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, WiFi, or BT.
+ *
+ * 1. Geopoint: Gefence is specified by cooridinates (Latitude and Longitude) and Radius\n
+ * 2. WIFI: Geofence is specified by BSSID of Wi-Fi access point\n
+ * 3. BT: Geofence is specified by Bluetooth address\n
+ *
+ * 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.
+ *
+ *
+ * @section CAPI_GEOFENCE_MODULE_FEATURE Related Features
+ * This API is related with the following features:\n
+ *  - http://tizen.org/feature/location\n
+ *  - http://tizen.org/feature/location.geofence\n
+ *
+ * It is recommended to design feature related codes in your application for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ */
+
+
+#endif  /* __TIZEN_LOCATION_GEOFENCE_MANAGER_DOC_H__ */
diff --git a/include/geofence_manager.h b/include/geofence_manager.h
new file mode 100644 (file)
index 0000000..8ca12fb
--- /dev/null
@@ -0,0 +1,696 @@
+/* Copyright 2014 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.
+ */
+
+#ifndef __TIZEN_GEOFENCE_MANAGER_H__
+#define __TIZEN_GEOFENCE_MANAGER_H__
+
+#include <geofence_type.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @addtogroup CAPI_GEOFENCE_MANAGER_MODULE
+ * @{
+ */
+
+/**
+ * @brief Called when a device enters or exits the given geofence.
+ * @since_tizen 2.4
+ * @param[in] geofence_id  The specified geofence id
+ * @param[in] state  The geofence state
+ * @param[in] user_data  The user data passed from callback registration function
+ * @pre geofence_manager_start() will invoke this callback if you register this callback using geofence_manager_set_geofence_state_changed_cb().
+ * @see geofence_state_e
+ * @see geofence_manager_start()
+ * @see geofence_manager_set_geofence_state_changed_cb()
+ */
+typedef void(*geofence_state_changed_cb)(int geofence_id, geofence_state_e state, void *user_data);
+
+/**
+ * @brief Called when the some event occurs in geofence and place such as add, update, etc..
+ * @details The events of public geofence is also received if there are public geofences.
+ *
+ * @since_tizen 2.4
+ * @remarks The value of place_id or geofence_id is -1 when the place id or geofence id is not assigned.
+ * @param[in] place_id The place id
+ * @param[in] geofence_id The specified geofence id
+ * @param[in] error The error code for the particular action
+ * @param[in] manage The result code for the particular place and geofence management
+ * @param[in] user_data The user data passed from callback registration function
+ * @pre geofence_manager_start() will invoke this callback if you register this callback using geofence_manager_set_geofence_state_changed_cb()
+ * @see geofence_manage_e
+ * @see geofence_manager_start()
+ * @see geofence_manager_set_geofence_state_changed_cb()
+ */
+typedef void(*geofence_event_cb)(int place_id, int geofence_id, geofence_manager_error_e error, geofence_manage_e manage, void *user_data);
+
+/**
+ * @brief Called when the fence list is requested.
+ * @since_tizen 2.4
+ * @param[in] geofence_id The geofence id
+ * @param[in] fence The fence handle
+ * @param[in] fence_index The index number of the fences in the list
+ * @param[in] fence_cnt The total number of fences that exists for the requester
+ * @param[in] user_data The user data passed from callback registration function
+ * @return true to continue iterating, otherwise false
+ * @pre geofence_manager_foreach_geofence_list() and geofence_manager_foreach_place_geofence_list() will invoke this callback if you specify this callback using geofence_manager_foreach_geofence_list().
+ * @see geofence_manager_foreach_geofence_list()
+ * @see geofence_manager_foreach_place_geofence_list()
+ * @see geofence_manager_add()
+ */
+typedef bool(*geofence_manager_fence_cb)(int geofence_id, geofence_h fence, int fence_index, int fence_cnt, void *user_data);
+
+/**
+ * @brief Called when the place list is requested.
+ * @since_tizen 2.4
+ * @param[in] place_id The current place id
+ * @param[in] place_name The current place name
+ * @param[in] place_index The index number of the places in the list
+ * @param[in] place_cnt The total number of places that exists for the requester
+ * @param[in] user_data The user data passed from callback registration function
+ * @return true to continue iterating, otherwise false
+ * @pre geofence_manager_foreach_place_list() will invoke this callback if you specify this callback using geofence_manager_foreach_place_list().
+ * @see geofence_manager_foreach_place_list()
+ * @see geofence_manager_add_place()
+ */
+typedef bool(*geofence_manager_place_cb)(int place_id, const char *place_name, int place_index, int place_cnt, void *user_data);
+
+
+/**
+ * @brief Checks whether the geofence manager is available or not.
+ * @since_tizen 2.4
+ * @param[out] supported  @c true if geofence service is supported, otherwise @c false
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @see        geofence_manager_create()
+ */
+int geofence_manager_is_supported(bool *supported);
+
+/**
+ * @brief Creates a new geofence manager.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @remarks The manager must be released using geofence_manager_destroy().
+ * @param[out] manager  A geofence manager handle to be newly created on success
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_OUT_OF_MEMORY    Out of memory
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #GEOFENCE_MANAGER_ERROR_EXCEPTION   Exception occurred
+ * @see geofence_manager_destroy()
+ */
+int geofence_manager_create(geofence_manager_h *manager);
+
+/**
+ * @brief Releases the geofence manager.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @param[in] manager The geofence manager handle
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_EXCEPTION    Exception occurred
+ * @pre geofence_manager_stop() is called before.
+ * @see geofence_manager_create()
+ * @see geofence_manager_stop()
+*/
+int geofence_manager_destroy(geofence_manager_h manager);
+
+/**
+ * @brief Starts the geofencing service.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ *
+ * @remarks There is no limit on number of geofence managers for which this function called
+ *
+ * Calling this function invokes a location service event. When the location service is enabled, the service state change callback
+ * (set using #geofence_manager_set_geofence_state_changed_cb()) notifies the user with geofence id as the 1st argument,
+ * geofence zone state(#GEOFENCE_STATE_IN and #GEOFENCE_STATE_OUT) as the 2nd argument, and the service starts \n
+ *
+ * @param[in]   manager The geofence manager handle
+ * @param[in]   geofence_id The specified geofence id
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_EXCEPTION Exception occurred
+ * @retval #GEOFENCE_MANAGER_ERROR_GEOFENCE_ACCESS_DENIED Access to specified geofence is denied
+ * @see geofence_manager_stop()
+ * @see geofence_manager_add_fence()
+ * @see geofence_manager_set_geofence_state_changed_cb()
+ */
+int geofence_manager_start(geofence_manager_h manager, int geofence_id);
+
+/**
+ * @brief Stops the geofenceing service.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @remarks    This function initiates the process of stopping the service.
+ *
+ * You can stop and start the geofence manager as needed.
+ *
+ * @param[in]   manager The geofence manager handle
+ * @param[in]   geofence_id The specified geofence id
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #GEOFENCE_MANAGER_ERROR_EXCEPTION Exception occurred
+ * @retval #GEOFENCE_MANAGER_ERROR_GEOFENCE_ACCESS_DENIED Access to specified geofence is denied
+ * @see   geofence_manager_start()
+ */
+int geofence_manager_stop(geofence_manager_h manager, int geofence_id);
+
+/**
+ * @brief Creates a new place for geofencing service.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @param[in] manager The geofence manager handle
+ * @param[in] place_name A place name to be created
+ * @param[out] place_id The place id to be newly created on success
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #GEOFENCE_MANAGER_ERROR_EXCEPTION Exception occurred
+ * @see   geofence_manager_update_place()
+ * @see   geofence_manager_remove_place()
+ */
+int geofence_manager_add_place(geofence_manager_h manager, const char *place_name, int *place_id);
+
+/**
+ * @brief Updates the place name of a given place id.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @param[in] manager The geofence manager handle
+ * @param[in] place_id The specified place id
+ * @param[in] place_name A new place name of the place id
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #GEOFENCE_MANAGER_ERROR_EXCEPTION Exception occurred
+ * @retval #GEOFENCE_MANAGER_ERROR_PLACE_ACCESS_DENIED Access to specified place is denied
+ * @see   geofence_manager_add_place()
+ * @see   geofence_manager_remove_place()
+ */
+int geofence_manager_update_place(geofence_manager_h manager, int place_id, const char *place_name);
+
+/**
+ * @brief Removes the specific place for geofencing service.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @remarks    The place must have no geofences.
+ * @param[in] manager The geofence manager handle
+ * @param[in] place_id The specified place id
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #GEOFENCE_MANAGER_ERROR_EXCEPTION Exception occurred
+ * @retval #GEOFENCE_MANAGER_ERROR_PLACE_ACCESS_DENIED Access to specified place is denied
+ * @pre geofence_manager_remove_fence() in all geofence is called before.
+ * @see   geofence_manager_add_place()
+ * @see   geofence_manager_update_place()
+ */
+int geofence_manager_remove_place(geofence_manager_h manager, int place_id);
+
+/**
+ * @brief Adds a geofence for a given geofence manager.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @param[in] manager The geofence manager handle
+ * @param[in] fence The geofence handle
+ * @param[out] geofence_id The geofence id handle to be newly created on success
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #GEOFENCE_MANAGER_ERROR_EXCEPTION Exception occurred
+ * @see geofence_manager_remove_fence()
+ * @see geofence_create_geopoint()
+ * @see geofence_create_bluetooth()
+ * @see geofence_create_wifi()
+ * @see geofence_manager_start()
+ */
+int geofence_manager_add_fence(geofence_manager_h manager, const geofence_h fence, int *geofence_id);
+
+/**
+ * @brief Removes a geofence with a given geofence id
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @param[in] manager The geofence manager handle
+ * @param[in] geofence_id The specified geofence id
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #GEOFENCE_MANAGER_ERROR_EXCEPTION Exception occurred
+ * @retval #GEOFENCE_MANAGER_ERROR_GEOFENCE_ACCESS_DENIED Access to specified geofence is denied
+ * @pre geofence_manager_stop() is called before.
+ * @see geofence_manager_add_fence()
+ */
+int geofence_manager_remove_fence(geofence_manager_h manager, int geofence_id);
+
+/**
+ * @brief Registers a callback function to be invoked when a device enters or exits the specific geofence.
+ * @since_tizen 2.4
+ * @param[in] manager The geofence manager handle
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @post This function invokes geofence_state_changed_cb().
+ * @see geofence_manager_unset_geofence_state_changed_cb()
+ * @see geofence_state_changed_cb()
+ */
+int geofence_manager_set_geofence_state_changed_cb(geofence_manager_h manager, geofence_state_changed_cb callback, void *user_data);
+
+/**
+ * @brief Unregisters the callback function.
+ * @since_tizen 2.4
+ * @param[in] manager The geofence manager handle
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @see geofence_state_changed_cb()
+ */
+int geofence_manager_unset_geofence_state_changed_cb(geofence_manager_h manager);
+
+/**
+ * @brief Registers a callback function to be invoked when a response comes.
+ * @since_tizen 2.4
+ * @param[in] manager The geofence manager handle
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @post This function invokes geofence_event_cb().
+ * @see geofence_manager_unset_geofence_event_cb()
+ */
+int geofence_manager_set_geofence_event_cb(geofence_manager_h manager, geofence_event_cb callback, void *user_data);
+
+/**
+ * @brief Unregisters the callback function.
+ * @since_tizen 2.4
+ * @param[in] manager The geofence manager handle
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @see geofence_event_cb()
+ */
+int geofence_manager_unset_geofence_event_cb(geofence_manager_h manager);
+
+/**
+ * @brief Retrieves a list of fences registered in the specified geofence manager.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @param[in] manager The geofence manager handle
+ * @param[in] callback The callback function to deliver each fence
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_DATABASE Database error
+ * @post This function invokes geofence_manager_fence_cb().
+ * @see geofence_manager_fence_cb()
+ * @see geofence_manager_add()
+ */
+int geofence_manager_foreach_geofence_list(geofence_manager_h manager, geofence_manager_fence_cb callback, void *user_data);
+
+/**
+ * @brief Retrieves a list of fences registered in the specified place.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @param[in] place_id The place id
+ * @param[in] callback The callback function to deliver each fence of the specified place
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_DATABASE Database error
+ * @retval #GEOFENCE_MANAGER_ERROR_PLACE_ACCESS_DENIED Access to specified place is denied
+ * @post This function invokes geofence_manager_fence_cb().
+ * @see geofence_manager_fence_at_place_cb()
+ * @see geofence_manager_add_place()
+ */
+int geofence_manager_foreach_place_geofence_list(geofence_manager_h manager, int place_id, geofence_manager_fence_cb callback, void *user_data);
+
+/**
+ * @brief Retrieves a list of place registered in the specified geofence manager.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @param[in] manager The geofence manager handle
+ * @param[in] callback The callback function to deliver each place of the specified geofence manager
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_DATABASE Database error
+ * @post This function invokes geofence_manager_place_cb().
+ * @see geofence_manager_place_cb()
+ * @see geofence_manager_add_place()
+ */
+int geofence_manager_foreach_place_list(geofence_manager_h manager, geofence_manager_place_cb callback, void *user_data);
+
+/**
+ * @brief Gets the name of place.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @remarks The place_name must be released using free().
+ * @param[in] manager The geofence manager handle
+ * @param[in] place_id The place id
+ * @param[out] place_name The name of the place
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALI_ID
+ * @retval #GEOFENCE_MANAGER_ERROR_DATABASE Database error
+ * @retval #GEOFENCE_MANAGER_ERROR_PLACE_ACCESS_DENIED Access to specified place is denied
+ * @see geofence_manager_add_place()
+ * @see geofence_manager_update_place()
+ */
+int geofence_manager_get_place_name(geofence_manager_h manager, int place_id, char **place_name);
+
+/**
+ * @}
+ */
+
+
+/**
+ * @addtogroup CAPI_GEOFENCE_MODULE
+ * @{
+ */
+
+/**
+ * @brief Creates a geopoint type of new geofence.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @remarks    The fence must be released using geofence_destroy().
+ * @param[in] place_id The current place id
+ * @param[in] latitude Specifies the value of latitude of geofence [-90.0 ~ 90.0] (degrees)
+ * @param[in] longitude Specifies the value of longitude of geofence [-180.0 ~ 180.0] (degrees)
+ * @param[in] radius Specifies the value of radius of geofence [100 ~ 500](meter)
+ * @param[in] address Specifies the value of address
+ * @param[out] fence A geofence handle to be newly created on success
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_EXCEPTION Exception occurred
+ * @retval #GEOFENCE_MANAGER_ERROR_PLACE_ACCESS_DENIED Access to specified place is denied
+ * @see geofence_create_bluetooth()
+ * @see geofence_create_wifi()
+ * @see geofence_destroy()
+ */
+int geofence_create_geopoint(int place_id, double latitude, double longitude, int radius, const char *address, geofence_h *fence);
+
+/**
+ * @brief Creates a bluetooth type of new geofence.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @remarks    The fence must be released using geofence_destroy().
+ * @param[in] place_id The current place id
+ * @param[in] bssid Specifies the value of BSSID of BT MAC address
+ * @param[in] ssid Specifies the value of SSID of BT Device
+ * @param[out] fence A geofence handle to be newly created on success
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_EXCEPTION Exception occurred
+ * @retval #GEOFENCE_MANAGER_ERROR_PLACE_ACCESS_DENIED Access to specified place is denied
+ * @see geofence_create_geopoint()
+ * @see geofence_create_wifi()
+ * @see geofence_destroy()
+ */
+int geofence_create_bluetooth(int place_id, const char *bssid, const char *ssid, geofence_h *fence);
+
+/**
+ * @brief Creates a Wi-Fi type of new geofence.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @remarks    The fence must be released using geofence_destroy().
+ * @param[in] place_id The current place id
+ * @param[in] bssid Specifies the value of BSSID of Wi-Fi MAC address
+ * @param[in] ssid Specifies the value of SSID of Wi-Fi Device
+ * @param[out] fence A geofence handle to be newly created on success
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_EXCEPTION Exception occurred
+ * @retval #GEOFENCE_MANAGER_ERROR_PLACE_ACCESS_DENIED Access to specified place is denied
+ * @see geofence_create_geopoint()
+ * @see geofence_create_bluetooth()
+ * @see geofence_destroy()
+ */
+int geofence_create_wifi(int place_id, const char *bssid, const char *ssid, geofence_h *fence);
+
+/**
+ * @brief Releases the geofence.
+ * @since_tizen 2.4
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/location
+ * @param[in] fence The geofence handle
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @see geofence_create_geopoint()
+ * @see geofence_create_bluetooth()
+ * @see geofence_create_wifi()
+ */
+int geofence_destroy(geofence_h fence);
+
+/**
+ * @brief Gets the type of geofence.
+ * @since_tizen 2.4
+ * @param[in] fence The geofence handle
+ * @param[out] type The type of geofence
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @see geofence_get_geopoint()
+ * @see geofence_get_radius()
+ * @see geofence_get_bssid()
+ */
+int geofence_get_type(geofence_h fence, geofence_type_e *type);
+
+/**
+ * @brief Gets the id of place.
+ * @since_tizen 2.4
+ * @param[in] fence The geofence handle
+ * @param[out] place_id The id of the place
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @see geofence_create_geopoint()
+ * @see geofence_create_bluetooth()
+ * @see geofence_create_wifi()
+ */
+int geofence_get_place_id(geofence_h fence, int *place_id);
+
+/**
+ * @brief Gets the latitude of geofence.
+ * @since_tizen 2.4
+ * @remarks The geofence has latitude only when geofence_type_e is GEOFENCE_TYPE_GEOPOINT.
+ * @param[in] fence The geofence handle
+ * @param[out] latitude The latitude of geofence
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument.
+ * @see geofence_get_longitude()
+ * @see geofence_get_radius()
+ * @see geofence_get_address()
+ * @see geofence_get_type()
+ * @see geofence_create_geopoint()
+ */
+int geofence_get_latitude(geofence_h fence, double *latitude);
+
+/**
+ * @brief Gets the longitude of geofence.
+ * @since_tizen 2.4
+ * @remarks The geofence has longitude only when geofence_type_e is GEOFENCE_TYPE_GEOPOINT.
+ * @param[in] fence The geofence handle
+ * @param[out] longitude The longitude of geofence
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @see geofence_get_latitude()
+ * @see geofence_get_radius()
+ * @see geofence_get_address()
+ * @see geofence_get_type()
+ * @see geofence_create_geopoint()
+ */
+int geofence_get_longitude(geofence_h fence, double *longitude);
+
+
+/**
+ * @brief Gets the radius of geofence.
+ * @since_tizen 2.4
+ * @remarks The geofence has radius only when geofence_type_e is GEOFENCE_TYPE_GEOPOINT.
+ * @param[in] fence The geofence handle
+ * @param[out] radius The radius of geofence
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @see geofence_get_latitude()
+ * @see geofence_get_longitude()
+ * @see geofence_get_address()
+ * @see geofence_get_type()
+ * @see geofence_create_geopoint()
+ */
+int geofence_get_radius(geofence_h fence, int *radius);
+
+/**
+ * @brief Gets the address of geofence
+ * @since_tizen 2.4
+ * @remarks The geofence has address only when geofence_type_e is GEOFENCE_TYPE_GEOPOINT. The address must be released using free().
+ * @param[in] fence The geofence handle
+ * @param[out] address Specifies the value of address
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @see geofence_get_latitude()
+ * @see geofence_get_longitude()
+ * @see geofence_get_radius()
+ * @see geofence_get_type()
+ * @see geofence_create_geopoint()
+ */
+int geofence_get_address(geofence_h fence, char **address);
+
+/**
+ * @brief Gets the bssid of geofence
+ * @since_tizen 2.4
+ * @remarks The geofence has bssid only when geofence_type_e is GEOFENCE_TYPE_BLUETOOTH or GEOFENCE_TYPE_WIFI. The bssid must be released using free().
+ * @param[in] fence The geofence handle
+ * @param[out] bssid The bssid of geofence
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @see geofence_get_type()
+ * @see geofence_create_bluetooth()
+ * @see geofence_create_wifi()
+ * @see geofence_get_ssid()
+ */
+int geofence_get_bssid(geofence_h fence, char **bssid);
+
+/**
+ * @brief Gets the ssid of geofence
+ * @since_tizen 2.4
+ * @remarks The geofence has ssid only when geofence_type_e is GEOFENCE_TYPE_BLUETOOTH or GEOFENCE_TYPE_WIFI. The ssid must be released using free().
+ * @param[in] fence The geofence handle
+ * @param[out] ssid The ssid of geofence
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @see geofence_get_type()
+ * @see geofence_create_bluetooth()
+ * @see geofence_create_wifi()
+ * @see geofence_get_bssid()
+ */
+int geofence_get_ssid(geofence_h fence, char **ssid);
+
+/**
+ * @brief Returns The geofence status of specified geofence.
+ * @since_tizen 2.4
+ * @remarks A status must be released using geofence_status_destroy()
+ * @param[in] geofence_id The geofence id
+ * @param[out] status The status handle of a specified geofence
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @retval #GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function
+ * @retval #GEOFENCE_MANAGER_ERROR_GEOFENCE_ACCESS_DENIED Access to specified geofence is denied
+ * @see geofence_status_destroy()
+ * @see geofence_manager_start()
+ * @see geofence_manager_stop()
+ */
+int geofence_status_create(int geofence_id, geofence_status_h *status);
+
+/**
+ * @brief Releases the memory, used by the status data.
+ * @since_tizen 2.4
+ * @param[in] status The status handle of a specified geofence
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @see geofence_status_create()
+ * @see geofence_status_get_state()
+ * @see geofence_status_get_duration()
+ */
+int geofence_status_destroy(geofence_status_h status);
+
+/**
+ * @brief Gets the state of geofence.
+ * @since_tizen 2.4
+ * @param[in] status The geofence status handle
+ * @param[out] state The state of geofence
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @see geofence_status_get_duration()
+ */
+int geofence_status_get_state(geofence_status_h status, geofence_state_e *state);
+
+/**
+ * @brief Gets the amount of seconds geofence is in the current state.
+ * @since_tizen 2.4
+ * @param[in] status The geofence status handle
+ * @param[out] seconds The amount of seconds geofence is in the current state
+ * @return 0 on success, otherwise a negative error value
+ * @retval #GEOFENCE_MANAGER_ERROR_NONE Successful
+ * @retval #GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER Illegal argument
+ * @see geofence_status_get_state()
+ */
+int geofence_status_get_duration(geofence_status_h status, int *seconds);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_GEOFENCE_MANAGER_H__ */
diff --git a/include/geofence_type.h b/include/geofence_type.h
new file mode 100644 (file)
index 0000000..a3b0394
--- /dev/null
@@ -0,0 +1,123 @@
+/* Copyright 2014 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.
+ */
+
+#ifndef __TIZEN_GEOFENCE_MANAGER_TYPES_H__
+#define __TIZEN_GEOFENCE_MANAGER_TYPES_H__
+
+
+#include <tizen_type.h>
+#include <tizen_error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_GEOFENCE_MANAGER_MODULE
+ * @since_tizen 2.4
+ * @{
+ */
+
+/**
+ * @brief Enumerations of error code for Geofence manager.
+ * @since_tizen 2.4
+ */
+typedef enum {
+       GEOFENCE_MANAGER_ERROR_NONE = TIZEN_ERROR_NONE,                                                                       /**< Success */
+       GEOFENCE_MANAGER_ERROR_OUT_OF_MEMORY           = TIZEN_ERROR_OUT_OF_MEMORY,           /**< Out of memory */
+       GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER       = TIZEN_ERROR_INVALID_PARAMETER,       /**< Invalid parameter */
+       GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED       = TIZEN_ERROR_PERMISSION_DENIED,       /**< Permission denied */
+       GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED           = TIZEN_ERROR_NOT_SUPPORTED,           /**< Not supported */
+       GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED         = TIZEN_ERROR_GEOFENCE_MANAGER | 0x01, /**< Geofence Manager is not initialized */
+       GEOFENCE_MANAGER_ERROR_INVALID_ID              = TIZEN_ERROR_GEOFENCE_MANAGER | 0x02, /**< Invalid geofence ID */
+       GEOFENCE_MANAGER_ERROR_EXCEPTION               = TIZEN_ERROR_GEOFENCE_MANAGER | 0x03, /**< Exception occurs */
+       GEOFENCE_MANAGER_ERROR_ALREADY_STARTED         = TIZEN_ERROR_GEOFENCE_MANAGER | 0x04, /**< Geofencing is already started */
+       GEOFENCE_MANAGER_ERROR_TOO_MANY_GEOFENCE       = TIZEN_ERROR_GEOFENCE_MANAGER | 0x05, /**< Too many geofence */
+       GEOFENCE_MANAGER_ERROR_IPC                     = TIZEN_ERROR_GEOFENCE_MANAGER | 0x06, /**< Error in GPS, Wi-Fi, or BT */
+       GEOFENCE_MANAGER_ERROR_DATABASE                = TIZEN_ERROR_GEOFENCE_MANAGER | 0x07, /**< DB error in the server side */
+       GEOFENCE_MANAGER_ERROR_PLACE_ACCESS_DENIED     = TIZEN_ERROR_GEOFENCE_MANAGER | 0x08, /**< Access to specified place is denied */
+       GEOFENCE_MANAGER_ERROR_GEOFENCE_ACCESS_DENIED  = TIZEN_ERROR_GEOFENCE_MANAGER | 0x09, /**< Access to specified geofence is denied */
+}
+geofence_manager_error_e;
+
+/**
+ * @brief Enumerations for the state of geofence manager.
+ * @since_tizen 2.4
+ */
+typedef enum {
+    GEOFENCE_STATE_UNCERTAIN = 0,      /**< Uncertain state of geofence */
+    GEOFENCE_STATE_IN,                         /**< Geofence In state */
+    GEOFENCE_STATE_OUT,                                /**< Geofence Out state */
+} geofence_state_e;
+
+
+/**
+ * @brief Enumeration for geofence type.
+ * @since_tizen 2.4
+ */
+typedef enum {
+    GEOFENCE_TYPE_GEOPOINT = 1,                /**< Geofence is specified by geospatial coordinate */
+    GEOFENCE_TYPE_WIFI,                                /**< Geofence is specified by Wi-Fi access point */
+    GEOFENCE_TYPE_BT,                          /**< Geofence is specified by Blutetooth device */
+} geofence_type_e;
+
+/**
+  * @brief Enumerations for geofence management events.
+  * @since_tizen 2.4
+  */
+typedef enum {
+    GEOFENCE_MANAGE_FENCE_ADDED = 0x00,         /**< Geofence is added*/
+    GEOFENCE_MANAGE_FENCE_REMOVED,              /**< Geofence is removed */
+    GEOFENCE_MANAGE_FENCE_STARTED,              /**< Geofencing is started*/
+    GEOFENCE_MANAGE_FENCE_STOPPED,              /**< Geofencing is stopped*/
+
+    GEOFENCE_MANAGE_PLACE_ADDED = 0x10,         /**< Place is added*/
+    GEOFENCE_MANAGE_PLACE_REMOVED,              /**< Place is removed*/
+    GEOFENCE_MANAGE_PLACE_UPDATED,              /**< Place is updated*/
+
+    GEOFENCE_MANAGE_SETTING_ENABLED = 0x20,     /**< Setting for geofencing is enabled */
+    GEOFENCE_MANAGE_SETTING_DISABLED,           /**< Setting for geofencing is disabled */
+} geofence_manage_e;
+
+/**
+ * @brief The geofence manager handle.
+ * @since_tizen 2.4
+ */
+typedef struct geofence_manager_s *geofence_manager_h;
+
+/**
+ * @brief The geofence handle.
+ * @since_tizen 2.4
+ */
+typedef struct geofence_s *geofence_h;
+
+/**
+ * @brief The geofence status handle.
+ * @since_tizen 2.4
+ */
+typedef struct geofence_status_s *geofence_status_h;
+
+
+/**
+ * @}
+ */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __TIZEN_GEOFENCE_MANAGER_TYPES_H__ */
diff --git a/packaging/capi-geofence-manager.changes b/packaging/capi-geofence-manager.changes
new file mode 100644 (file)
index 0000000..1ce7383
--- /dev/null
@@ -0,0 +1,91 @@
+[Version] geofence-manager_0.3.0
+[date] 03 Sep 2015
+[Description] To use model-config for checking geofence enabled instead of build-feature 
+[Developer] Jongmun Woo <jongmun.woo@samsung.com>
+
+===============================================================================
+
+[Version] geofence-manager_0.3.0
+[date] 06 Jul 2015
+[Description] 1.To use new geofence-dbus interface. 
+              2.Created new plugin package having module interface for location-geofence-server.
+[Developer] Young-Ae Kang <youngae.kang@samsung.com>
+
+===============================================================================
+
+[Version] geofence-manager_0.2.2
+[date] 24 Dec 2014
+[Title] Fence name added for Geofence Manager module
+[Issue#] NA
+[Problem] NA
+[Cause] New feature need to be added
+[Solution] fence_name has been added as the parameter in all the levels
+[Developer] Karthik Paulraj <p.karthik@samsung.com>
+
+===============================================================================
+
+[Version] geofence-manager_0.2.0
+[date] 25 June 2014
+[Title] 
+[Issue#] NA
+[Problem] missing create geofence
+[Cause] create geofence is in geofence library
+[Solution] separate create / destroy and start / stop, add create in geofence manager
+[Developer] Kisun SHIN <kisun47.shin@samsung.com>
+
+================================================================================
+[Version] geofence-manager_0.1.5
+[date] 21 June 2014
+[Title] when the apps destroy the geofence service, error is occurred.
+[Issue#] NA
+[Problem] when geofence service is destroyed, object is null.
+[Cause] geofence object is already freed 
+[Solution] disconnect the signal before free the object
+[Developer] Kisun SHIN <kisun47.shin@samsung.com>
+
+================================================================================
+
+[Version] geofence-manager_0.1.4
+[date] 19 June 2014
+[Title] change cb register
+[Issue#] NA
+[Problem] change cb register position
+[Cause] change cb register position
+[Solution] change cb register position (start -> create)
+[Developer] Wooyoung KIM <woo02.kim@samsung.com>
+
+================================================================================
+
+[Version] geofence-manager_0.1.3
+[date] 29 May 2014
+[Title] Add geofence-dbus dependancy
+[Issue#] NA
+[Problem] NA
+[Cause] it is not included geofence-dbus on device.
+[Solution] add geofence-dbus dependancy
+[Developer] Kisun SHIN <kisun47.shin@samsung.com>
+
+================================================================================
+
+[Version] geofence-manager_0.1.2
+[date] 27 May 2014
+[Title] remove geofence id
+[Issue#] NA
+[Problem] NA
+[Cause] change structure for geofence cb
+[Solution] do not need geofence id for callback
+[Developer] Kisun SHIN <kisun47.shin@samsung.com>
+
+================================================================================
+
+[Version] geofence-manager_0.1.1
+[date] 12 May 2014
+[Title] Git update
+[Issue#] NA
+[Problem] NA
+[Cause] NA
+[Solution] NA 
+[Developer] Areum Choi <arumi.choi@samsung.com>
+
+================================================================================
+
diff --git a/packaging/capi-geofence-manager.spec b/packaging/capi-geofence-manager.spec
new file mode 100644 (file)
index 0000000..f5c2c99
--- /dev/null
@@ -0,0 +1,87 @@
+Name:       capi-geofence-manager
+Summary:    A Geofence Manager library in Tizen Native API
+Version:    0.3.1
+Release:    1
+Group:      Location/Libraries
+License:    Apache-2.0
+Source0:    %{name}-%{version}.tar.gz
+
+%if "%{?tizen_profile_name}" == "tv"
+ExcludeArch: %{arm} %ix86 x86_64
+%endif
+
+BuildRequires:  cmake
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(capi-base-common)
+BuildRequires:  pkgconfig(vconf)
+BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(gmodule-2.0)
+BuildRequires:  pkgconfig(capi-appfw-app-manager)
+BuildRequires:  pkgconfig(capi-appfw-package-manager)
+BuildRequires:  pkgconfig(pkgmgr-info)
+BuildRequires:  pkgconfig(privacy-manager-client)
+BuildRequires:  pkgconfig(capi-system-info)
+
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+Provides: capi-geofence-manager-plugin-devel
+
+%description
+
+
+%prep
+%setup -q
+
+
+%build
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
+export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
+
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+%manifest capi-geofence-manager.manifest
+%{_libdir}/libcapi-geofence-manager.so.*
+
+%package devel
+Summary: A Geofence Manager library in Tizen Native API (Development)
+Group:   Location/Libraries
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+
+%files devel
+%{_includedir}/geofence/*.h
+%{_libdir}/pkgconfig/*.pc
+%{_libdir}/libcapi-geofence-manager.so
+%exclude %{_includedir}/geofence/geofence_module.h
+%exclude %{_includedir}/geofence/geofence_data_type.h
+
+%package plugin-devel
+Summary:    Geofence Manager Plug-in (Development)
+Group:      Location/Libraries
+Requires:  %{name} = %{version}-%{release}
+
+%description plugin-devel
+This provides interfaces for Geofence Manager plugin. 
+
+%post plugin-devel
+
+%postun plugin-devel
+
+%files plugin-devel
+%defattr(-,root,root,-)
+%{_includedir}/geofence/geofence_module.h
+%{_includedir}/geofence/geofence_data_type.h
diff --git a/src/geofence_manager.c b/src/geofence_manager.c
new file mode 100644 (file)
index 0000000..df28874
--- /dev/null
@@ -0,0 +1,1024 @@
+/* Copyright 2014 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.
+ */
+
+
+#ifndef GEOFENCE_DUMMY_API
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <system_info.h>
+
+#include "geofence-log.h"
+#include "geofence.h"
+#include "geofence-ielement.h"
+#include "geofence-privacy.h"
+#include "geofence-param.h"
+#include "geofence_manager.h"
+
+static GHashTable *fence_map = NULL;
+static GList *tracking_list = NULL;
+static geofence_manager_s *handle = NULL;
+static int gIsMgrCreated = 0;
+
+bool __is_geofence_feature_enabled()
+{
+       const char *geofence_feature = "http://tizen.org/feature/location.geofence";
+       bool geofence_enabled = false;
+
+       system_info_get_platform_bool(geofence_feature, &geofence_enabled);
+
+       return geofence_enabled;
+}
+
+static void __cb_zone_in(GObject *self, guint geofence_id, gpointer userdata)
+{
+       GEOFENCE_LOGD("__cb_zone_in : geofence_id = %d", geofence_id);
+
+       geofence_manager_s *handle = (geofence_manager_s *) userdata;
+       GList *fence_list = g_list_first(tracking_list);
+
+       while (fence_list) {
+               if ((int)fence_list->data == geofence_id) {
+                       geofence_info_s *info = (geofence_info_s *)g_hash_table_lookup(fence_map, (gpointer)geofence_id);
+                       if (info != NULL) {
+                               GEOFENCE_LOGD("Info exists");
+                               info->info = NULL;
+                               info->state = GEOFENCE_STATE_IN;
+                               info->last_updated_time = (g_get_real_time() / 1000000); /* microsecs->millisecs->secs */
+                               g_hash_table_replace(fence_map, (gpointer)geofence_id, (gpointer)info);
+                       }
+                       if (handle->user_cb) {
+                               ((geofence_state_changed_cb) handle->user_cb)(geofence_id, GEOFENCE_STATE_IN, handle->user_data);
+                               break;
+                       }
+               }
+               fence_list = g_list_next(fence_list);
+       }
+}
+
+static void __cb_zone_out(GObject *self, guint geofence_id, gpointer userdata)
+{
+       GEOFENCE_LOGD("__cb_zone_out : geofence_id = %d", geofence_id);
+
+       geofence_manager_s *handle = (geofence_manager_s *) userdata;
+       GList *fence_list = g_list_first(tracking_list);
+
+       while (fence_list) {
+               if ((int)fence_list->data == geofence_id) {
+                       geofence_info_s *info = (geofence_info_s *)g_hash_table_lookup(fence_map, (gpointer)geofence_id);
+                       if (info != NULL) {
+                               GEOFENCE_LOGD("Info exists");
+                               info->info = NULL;
+                               info->state = GEOFENCE_STATE_OUT;
+                               info->last_updated_time = (g_get_real_time() / 1000000); /* microsecs->millisecs->secs */
+                               g_hash_table_replace(fence_map, (gpointer)geofence_id, (gpointer)info);
+                       }
+                       if (handle->user_cb) {
+                               ((geofence_state_changed_cb) handle->user_cb)(geofence_id, GEOFENCE_STATE_OUT, handle->user_data);
+                               break;
+                       }
+               }
+               fence_list = g_list_next(fence_list);
+       }
+}
+
+void __handle_action(int place_id, int geofence_id, geofence_manager_error_e error, geofence_manage_e action)
+{
+       if (error != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGD("__handle_action: error=%d", error);
+               return;
+       }
+
+       switch (action) {
+               case GEOFENCE_MANAGE_FENCE_STARTED: {
+                               geofence_info_s *fence_info = (geofence_info_s *)malloc(sizeof(geofence_info_s));
+                               if (fence_info == NULL)
+                                       break;
+                               fence_info->info = NULL;
+                               fence_info->state = GEOFENCE_STATE_UNCERTAIN;
+                               fence_info->last_updated_time = (g_get_real_time() / 1000000);
+                               g_hash_table_insert(fence_map, (gpointer)geofence_id, (gpointer)fence_info);
+                               /* Inserting the fence in the tracking list */
+                               tracking_list = g_list_append(tracking_list, (gpointer)geofence_id);
+                       }
+                       break;
+               case GEOFENCE_MANAGE_FENCE_STOPPED: {
+                               geofence_info_s *info = (geofence_info_s *)g_hash_table_lookup(fence_map, (gpointer)geofence_id);
+                               if (info != NULL) {
+                                       g_hash_table_remove(fence_map, (gpointer)geofence_id);
+                                       free(info);
+                               }
+                               /* Removing the fence in the tracking list */
+                               tracking_list = g_list_remove(tracking_list, (gpointer)geofence_id);
+                       }
+                       break;
+               default:
+                       break;
+       }
+}
+
+static void __cb_fence_evt(GObject *self, guint place_id, guint geofence_id, guint error, guint action, gpointer userdata)
+{
+       GEOFENCE_LOGD("place_id: %d, geofence_id: %d, error: %d, action: %d", place_id, geofence_id, error, action);
+       geofence_manager_s *handle = (geofence_manager_s *) userdata;
+
+       /* This will take care of actions in the manager side for successful execution on the server side */
+       __handle_action(place_id, geofence_id, error, action);
+
+       if (handle->user_event_cb)
+               ((geofence_event_cb) handle->user_event_cb)(place_id, geofence_id, error, action, handle->user_data);
+}
+
+static int __set_callback(geofence_manager_h manager, void *callback, void *user_data)
+{
+       GEOFENCE_LOGD("__set_callback");
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_NULL_ARG_CHECK(callback);
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       handle->user_cb = callback;
+       handle->user_data = user_data;
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+static int __unset_callback(geofence_manager_h manager)
+{
+       GEOFENCE_LOGD("__unset_callback");
+       GEOFENCE_NULL_ARG_CHECK(manager);
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       handle->user_cb = NULL;
+       handle->user_data = NULL;
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+static int __set_event_callback(geofence_manager_h manager, void *callback, void *user_data)
+{
+       GEOFENCE_LOGD("__set_event_callback");
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_NULL_ARG_CHECK(callback);
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       handle->user_event_cb = callback;
+       handle->user_data = user_data;
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+static int __unset_event_callback(geofence_manager_h manager)
+{
+       GEOFENCE_LOGD("__unset_event_callback");
+       GEOFENCE_NULL_ARG_CHECK(manager);
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       handle->user_event_cb = NULL;
+       handle->user_data = NULL;
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+static bool __is_fence_started(int fence_id)
+{
+       GEOFENCE_LOGD("__is_fence_started");
+       GList *fence_list = g_list_first(tracking_list);
+
+       while (fence_list) {
+               if ((int)fence_list->data == fence_id)
+                       return true;
+               fence_list = g_list_next(fence_list);
+       }
+       return false;
+}
+
+/*
+* Geofence Manager
+*/
+
+/*
+* Public Implementation
+*/
+
+EXPORT_API int geofence_manager_is_supported(bool *supported)
+{
+       GEOFENCE_LOGD("geofence_manager_is_supported");
+
+       if (__is_geofence_feature_enabled() == false)
+               return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(supported);
+
+       *supported = geofence_is_supported();
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_manager_create(geofence_manager_h *manager)
+{
+       GEOFENCE_LOGD("geofence_manager_create");
+
+       if (__is_geofence_feature_enabled() == false)
+               return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+       geofence_privacy_initialize();
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Cannot use geofence service for privacy[%d]", ret);
+               return __print_error_code(GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED);
+       }
+
+       ret = geofence_init();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE)
+               return __print_error_code(GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED);
+
+       if (gIsMgrCreated == 0) {
+               handle = (geofence_manager_s *) malloc(sizeof(geofence_manager_s));
+               if (handle == NULL)
+                       return __print_error_code(GEOFENCE_MANAGER_ERROR_OUT_OF_MEMORY);
+
+               memset(handle, 0, sizeof(geofence_manager_s));
+
+               handle->object = geofence_new();
+               if (handle->object == NULL) {
+                       free(handle);
+                       return __print_error_code(GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED);
+               }
+               if (!handle->sig_id[_GEOFENCE_SIGNAL_ZONE_IN])
+                       handle->sig_id[_GEOFENCE_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
+               if (!handle->sig_id[_GEOFENCE_SIGNAL_ZONE_OUT])
+                       handle->sig_id[_GEOFENCE_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
+               if (!handle->sig_id[_GEOFENCE_SIGNAL_EVENT])
+                       handle->sig_id[_GEOFENCE_SIGNAL_EVENT] = g_signal_connect(handle->object, "geofence-event", G_CALLBACK(__cb_fence_evt), handle);
+
+               ret = geofence_ielement_create(GEOFENCE_IELEMENT(handle->object));
+               if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+                       return __print_error_code(GEOFENCE_MANAGER_ERROR_EXCEPTION);
+               }
+               /* Initialize the hashmaps to store the fence and place info */
+               fence_map = g_hash_table_new(g_direct_hash, g_direct_equal);
+               if (fence_map == NULL)
+                       GEOFENCE_LOGD("Fence Map is NULL");
+               gIsMgrCreated = 1; /* Setting the create flag */
+       } else {
+               GEOFENCE_LOGE("Geofence Manager is already created. Returning the same handle");
+       }
+
+       *manager = (geofence_manager_h) handle;
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_manager_destroy(geofence_manager_h manager)
+{
+       GEOFENCE_LOGD("geofence_manager_destroy");
+
+       if (__is_geofence_feature_enabled() == false)
+               return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Cannot use geofence service for privacy[%d]", ret);
+               return __print_error_code(GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED);
+       }
+       geofence_manager_unset_geofence_event_cb(manager);
+       geofence_manager_unset_geofence_state_changed_cb(manager);
+
+       GList *fence_list = g_list_first(tracking_list);
+
+       /* Stopping the already started fences by this application */
+       while (fence_list) {
+               if (GEOFENCE_MANAGER_ERROR_NONE != geofence_manager_stop(manager, (int)fence_list->data)) {
+                       GEOFENCE_LOGD("Stopping the geofence_list failed. Unable to destroy the manager.");
+                       return __print_error_code(GEOFENCE_MANAGER_ERROR_EXCEPTION);
+               }
+               fence_list = g_list_next(fence_list);
+       }
+
+       if (handle->sig_id[_GEOFENCE_SIGNAL_ZONE_IN]) {
+               g_signal_handler_disconnect(handle->object, handle->sig_id[_GEOFENCE_SIGNAL_ZONE_IN]);
+               handle->sig_id[_GEOFENCE_SIGNAL_ZONE_IN] = 0;
+       }
+       if (handle->sig_id[_GEOFENCE_SIGNAL_ZONE_OUT]) {
+               g_signal_handler_disconnect(handle->object, handle->sig_id[_GEOFENCE_SIGNAL_ZONE_OUT]);
+               handle->sig_id[_GEOFENCE_SIGNAL_ZONE_OUT] = 0;
+       }
+
+       ret = geofence_ielement_destroy(GEOFENCE_IELEMENT(handle->object));
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       }
+
+       /* destroy the hashtables */
+       g_hash_table_destroy(fence_map);
+       fence_map = NULL;
+       geofence_privacy_finalize();
+       g_list_free(tracking_list);
+       geofence_free(handle->object);
+       free(handle);
+       tracking_list = NULL;
+       handle = NULL;
+       gIsMgrCreated = 0; /* Resetting the create flag */
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+/*EXPORT_API int geofence_manager_enable_fence(geofence_manager_h manager, int geofence_id, bool enable)
+{
+       GEOFENCE_LOGD("geofence_manager_enable_service");
+
+       if (__is_geofence_feature_enabled() == false)
+               return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_CHECK_CONDITION(geofence_id > 0, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+        int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Cannot use geofence service for privacy[%d]", ret);
+               return __print_error_code(ret);
+
+       }
+       ret = geofence_ielement_enable_service(GEOFENCE_IELEMENT(handle->object), geofence_id, enable);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE)
+               return __print_error_code(ret);
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}*/
+
+EXPORT_API int geofence_manager_start(geofence_manager_h manager, int geofence_id)
+{
+       GEOFENCE_LOGD("geofence_manager_start : Geofence ID[%d]", geofence_id);
+
+       if (__is_geofence_feature_enabled() == false)
+               return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_CHECK_CONDITION(geofence_id > 0, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Cannot use geofence service for privacy[%d]", ret);
+               return __print_error_code(ret);
+
+       }
+       if (__is_fence_started(geofence_id) == true) {
+               return __print_error_code(GEOFENCE_MANAGER_ERROR_ALREADY_STARTED);
+       }
+       ret = geofence_ielement_start(GEOFENCE_IELEMENT(handle->object), geofence_id);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE)
+               return __print_error_code(ret);
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_manager_stop(geofence_manager_h manager, int geofence_id)
+{
+       GEOFENCE_LOGD("geofence_manager_stop");
+
+       if (__is_geofence_feature_enabled() == false)
+               return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_CHECK_CONDITION(geofence_id > 0, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Cannot use geofence service for privacy[%d]", ret);
+               return __print_error_code(GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED);
+       }
+       if (__is_fence_started(geofence_id) == false) {
+               GEOFENCE_LOGE("Fence is not currently running.");
+               return __print_error_code(GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       }
+       ret = geofence_ielement_stop(GEOFENCE_IELEMENT(handle->object), geofence_id);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) GEOFENCE_LOGD("Fail to stop. Error [%d]", ret);
+
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_manager_add_fence(geofence_manager_h manager, geofence_h params, int *geofence_id)
+{
+       GEOFENCE_LOGD("ENTER >>>");
+
+       if (__is_geofence_feature_enabled() == false)
+               return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_NULL_ARG_CHECK(params);
+       GEOFENCE_NULL_ARG_CHECK(geofence_id);
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+
+       ret = geofence_ielement_add(GEOFENCE_IELEMENT(handle->object), (geofence_s *) params, geofence_id);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_manager_add_place(geofence_manager_h manager, const char *place_name, int *place_id)
+{
+       GEOFENCE_LOGD("ENTER >>>");
+
+       if (__is_geofence_feature_enabled() == false)
+               return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_NULL_ARG_CHECK(place_id);
+       GEOFENCE_NULL_ARG_CHECK(place_name);
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+
+       ret = geofence_ielement_add_place(GEOFENCE_IELEMENT(handle->object), place_name, place_id);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_manager_update_place(geofence_manager_h manager, int place_id, const char *place_name)
+{
+       if (__is_geofence_feature_enabled() == false)
+               return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_NULL_ARG_CHECK(place_name);
+       GEOFENCE_CHECK_CONDITION(place_id > 0, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+
+       GEOFENCE_LOGD("place_id[%d]", place_id);
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+
+       ret = geofence_ielement_update_place(GEOFENCE_IELEMENT(handle->object), place_name, place_id);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_manager_remove_fence(geofence_manager_h manager, int geofence_id)
+{
+       GEOFENCE_LOGD("geofence_manager_remove_geofence");
+
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_CHECK_CONDITION(geofence_id > 0, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+
+       ret = geofence_ielement_remove(GEOFENCE_IELEMENT(handle->object), geofence_id);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_manager_remove_place(geofence_manager_h manager, int place_id)
+{
+       GEOFENCE_LOGD("geofence_manager_remove_place");
+
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_CHECK_CONDITION(place_id > 0, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+
+       ret = geofence_ielement_remove_place(GEOFENCE_IELEMENT(handle->object), place_id);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_manager_get_place_name(geofence_manager_h manager, int place_id, char **place_name)
+{
+       GEOFENCE_LOGD("geofence_manager_remove_place");
+
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_NULL_ARG_CHECK(place_name);
+       GEOFENCE_CHECK_CONDITION(place_id > 0, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+
+       ret = geofence_ielement_get_place_name(GEOFENCE_IELEMENT(handle->object), place_id, place_name);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+
+EXPORT_API int geofence_manager_set_geofence_state_changed_cb(geofence_manager_h manager, geofence_state_changed_cb callback, void *user_data)
+{
+       GEOFENCE_LOGD("geofence_manager_set_geofence_state_changed_cb");
+
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+
+       return __set_callback(manager, callback, user_data);
+}
+
+EXPORT_API int geofence_manager_set_geofence_event_cb(geofence_manager_h manager, geofence_event_cb callback, void *user_data)
+{
+       GEOFENCE_LOGD("geofence_manager_set_geofence_event_cb");
+
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+
+       return __set_event_callback(manager, callback, user_data);
+}
+
+EXPORT_API int geofence_manager_unset_geofence_state_changed_cb(geofence_manager_h manager)
+{
+       GEOFENCE_LOGD("geofence_manager_unset_geofence_state_changed_cb");
+
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+
+       return __unset_callback(manager);
+}
+
+EXPORT_API int geofence_manager_unset_geofence_event_cb(geofence_manager_h manager)
+{
+       GEOFENCE_LOGD("geofence_manager_unset_geofence_event_cb");
+
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+
+       return __unset_event_callback(manager);
+}
+
+EXPORT_API int geofence_manager_foreach_geofence_list(geofence_manager_h manager, geofence_manager_fence_cb callback, void *user_data)
+{
+       GEOFENCE_LOGD(">>> Start");
+
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_NULL_ARG_CHECK(callback);
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Cannot use geofence service for privacy[%d]", ret);
+               return __print_error_code(GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED);
+       }
+
+       int fence_amount = 0;
+       int *fence_ids = NULL;
+       geofence_s *params = NULL;
+
+       ret = geofence_ielement_get_fence_list(GEOFENCE_IELEMENT(handle->object), -1, &fence_amount, &fence_ids, &params);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+
+       if (fence_amount == 0) {
+               if (callback)
+                       callback(-1, NULL, 0, 0, user_data);
+               return GEOFENCE_MANAGER_ERROR_NONE;
+       }
+       int i = 0;
+       for (i = 0; i < fence_amount; i++) {
+               if (!callback(fence_ids[i], (geofence_h)geofence_parameter_copy((const geofence_s *)(params + i)), (i + 1), fence_amount, user_data))
+                       break;
+               GEOFENCE_LOGD("Printing the details:");
+               GEOFENCE_LOGD("Fence id: %d, lat: %lf, lon: %lf, rad: %d, bssid: %s", fence_ids[i], params[i].latitude, params[i].longitude, params[i].radius, params[i].bssid);
+       }
+
+       int iterations = fence_amount;
+       while (iterations-- > 0) {
+               geofence_parameter_free((geofence_s *)(params++));
+       }
+
+       g_slice_free1(sizeof(int)*fence_amount, fence_ids);
+
+       GEOFENCE_LOGD("<<< End");
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_manager_foreach_place_geofence_list(geofence_manager_h manager, int place_id, geofence_manager_fence_cb callback, void *user_data)
+{
+       GEOFENCE_LOGD(">>> Start");
+
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_NULL_ARG_CHECK(callback);
+       GEOFENCE_CHECK_CONDITION(place_id > 0, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Cannot use geofence service for privacy[%d]", ret);
+               return __print_error_code(GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED);
+       }
+
+       int fence_amount = 0;
+       int *fence_ids = NULL;
+       geofence_s *params = NULL;
+
+       GEOFENCE_LOGD("place_id: %d", place_id);
+       ret = geofence_ielement_get_fence_list(GEOFENCE_IELEMENT(handle->object), place_id, &fence_amount, &fence_ids, &params);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+
+       if (fence_amount == 0) {
+               callback(0, NULL, 0, 0, user_data);
+               return GEOFENCE_MANAGER_ERROR_NONE;
+       }
+       int i = 0;
+       for (i = 0; i < fence_amount; i++)      {
+               callback(fence_ids[i], (geofence_h)geofence_parameter_copy((const geofence_s *)(params + i)), (i + 1), fence_amount, user_data);
+               GEOFENCE_LOGD("Fence id: %d, lat: %lf, lon: %lf, rad: %d, address: %s, bssid: %s, ssid: %s", fence_ids[i], params[i].latitude, params[i].longitude, params[i].radius, params[i].address, params[i].bssid, params[i].ssid);
+       }
+       int iterations = fence_amount;
+       while (iterations-- > 0) {
+               geofence_parameter_free((geofence_s *)(params++));
+       }
+
+       g_slice_free1(sizeof(int)*fence_amount, fence_ids);
+
+       GEOFENCE_LOGD("<<< End");
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_manager_foreach_place_list(geofence_manager_h manager, geofence_manager_place_cb callback, void *user_data)
+{
+       GEOFENCE_LOGD(">>> Start");
+
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(manager);
+       GEOFENCE_NULL_ARG_CHECK(callback);
+
+       geofence_manager_s *handle = (geofence_manager_s *) manager;
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = geofence_get_privacy();
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Cannot use geofence service for privacy[%d]", ret);
+               return __print_error_code(GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED);
+       }
+
+       int place_amount = 0;
+       int *place_ids = NULL;
+       place_s *params = NULL;
+
+       ret = geofence_ielement_get_place_list(GEOFENCE_IELEMENT(handle->object), &place_amount, &place_ids, &params);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               return __print_error_code(ret);
+       }
+       if (place_amount == 0) {
+               callback(0, NULL, 0, 0, user_data);
+               return GEOFENCE_MANAGER_ERROR_NONE;
+       }
+
+       int i = 0;
+       for (i = 0; i < place_amount; i++) {
+               callback(place_ids[i], ((const place_s *)(params + i))->place_name, (i + 1), place_amount, user_data);
+       }
+
+       int iterations = place_amount;
+       while (iterations-- > 0) {
+               g_slice_free(place_s, (params++));
+       }
+
+       g_slice_free1(sizeof(int)*place_amount, place_ids);
+
+       GEOFENCE_LOGD("<<< End");
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_create_geopoint(int place_id, double latitude, double longitude, int radius, const char *address, geofence_h *fence)
+{
+       GEOFENCE_LOGD("geofence_manager_create_geopoint");
+
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(fence);
+       GEOFENCE_NULL_ARG_CHECK(address);
+       GEOFENCE_CHECK_CONDITION(place_id > 0, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+       GEOFENCE_CHECK_CONDITION(latitude >= -90 && latitude <= 90, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+       GEOFENCE_CHECK_CONDITION(longitude >= -180 && longitude <= 180, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+       GEOFENCE_CHECK_CONDITION(radius >= 100 && radius <= 500, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+
+       *fence = (geofence_h)geofence_parameter_new(place_id, GEOFENCE_TYPE_GEOPOINT, latitude, longitude, radius, address, NULL, NULL);
+       return (*fence) ? GEOFENCE_MANAGER_ERROR_NONE : __print_error_code(GEOFENCE_MANAGER_ERROR_EXCEPTION);
+}
+
+EXPORT_API int geofence_create_bluetooth(int place_id, const char *bssid, const char *ssid, geofence_h *fence)
+{
+       GEOFENCE_LOGD("geofence_create_bluetooth");
+
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(fence);
+       GEOFENCE_NULL_ARG_CHECK(bssid);
+       GEOFENCE_NULL_ARG_CHECK(ssid);
+       GEOFENCE_CHECK_CONDITION(place_id > 0, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+
+       *fence = (geofence_h)geofence_parameter_new(place_id, GEOFENCE_TYPE_BT, .0, .0, 0, NULL, bssid, ssid);
+       return (*fence) ? GEOFENCE_MANAGER_ERROR_NONE : __print_error_code(GEOFENCE_MANAGER_ERROR_EXCEPTION);
+}
+
+EXPORT_API int geofence_create_wifi(int place_id, const char *bssid, const char *ssid, geofence_h *fence)
+{
+       GEOFENCE_LOGD("geofence_create_wifi");
+
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(fence);
+       GEOFENCE_NULL_ARG_CHECK(bssid);
+       GEOFENCE_NULL_ARG_CHECK(ssid);
+       GEOFENCE_CHECK_CONDITION(place_id > 0, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+
+       *fence = (geofence_h)geofence_parameter_new(place_id, GEOFENCE_TYPE_WIFI, .0, .0, 0, NULL, bssid, ssid);
+       return (*fence) ? GEOFENCE_MANAGER_ERROR_NONE : __print_error_code(GEOFENCE_MANAGER_ERROR_EXCEPTION);
+}
+
+EXPORT_API int geofence_destroy(geofence_h fence)
+{
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(fence);
+       geofence_parameter_free((geofence_s *)fence);
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_get_type(geofence_h fence, geofence_type_e *type)
+{
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(fence);
+       GEOFENCE_NULL_ARG_CHECK(type);
+
+       geofence_s *p = (geofence_s *)fence;
+       *type = p->type;
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_get_place_id(geofence_h fence, int *place_id)
+{
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(fence);
+       GEOFENCE_NULL_ARG_CHECK(place_id);
+
+       geofence_s *p = (geofence_s *)fence;
+       *place_id = p->place_id;
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_get_latitude(geofence_h fence, double *latitude)
+{
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(fence);
+       GEOFENCE_NULL_ARG_CHECK(latitude);
+
+       geofence_s *p = (geofence_s *)fence;
+       *latitude = p->latitude;
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_get_longitude(geofence_h fence, double *longitude)
+{
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(fence);
+       GEOFENCE_NULL_ARG_CHECK(longitude);
+
+       geofence_s *p = (geofence_s *)fence;
+       *longitude = p->longitude;
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_get_radius(geofence_h fence, int *radius)
+{
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(fence);
+       GEOFENCE_NULL_ARG_CHECK(radius);
+
+       geofence_s *p = (geofence_s *)fence;
+       *radius = p->radius;
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_get_address(geofence_h fence, char **address)
+{
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(fence);
+       GEOFENCE_NULL_ARG_CHECK(address);
+
+       geofence_s *p = (geofence_s *)fence;
+       *address = strdup(p->address);
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_get_bssid(geofence_h fence, char **bssid)
+{
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(fence);
+       GEOFENCE_NULL_ARG_CHECK(bssid);
+
+       geofence_s *p = (geofence_s *)fence;
+       *bssid = strdup(p->bssid);
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_get_ssid(geofence_h fence, char **ssid)
+{
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(fence);
+       GEOFENCE_NULL_ARG_CHECK(ssid);
+
+       geofence_s *p = (geofence_s *)fence;
+       *ssid = strdup(p->ssid);
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_status_create(int geofence_id, geofence_status_h *status)
+{
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(status);
+       GEOFENCE_CHECK_CONDITION(geofence_id > 0, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER, "GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER");
+       GEOFENCE_LOGD("Allocating memory for new status");
+
+       geofence_status_s *new_status = g_slice_new0(geofence_status_s);
+       GEOFENCE_CHECK_CONDITION(new_status != NULL, GEOFENCE_MANAGER_ERROR_OUT_OF_MEMORY, "GEOFENCE_MANAGER_ERROR_OUT_OF_MEMORY");
+
+       new_status->fence_id = geofence_id;
+       new_status->state = GEOFENCE_STATE_UNCERTAIN;
+       new_status->seconds = 0;
+       *status = (geofence_status_h)new_status;
+       GEOFENCE_LOGD("Status created for fence: %d", geofence_id);
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_status_destroy(geofence_status_h status)
+{
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(status);
+
+       g_slice_free(geofence_status_s, ((geofence_status_s *)status));
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_status_get_state(geofence_status_h status, geofence_state_e *state)
+{
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(status);
+       GEOFENCE_NULL_ARG_CHECK(state);
+
+       geofence_status_s *p = (geofence_status_s *)status;
+       GEOFENCE_LOGD("Looking up for state in hashmap");
+       geofence_info_s *info = (geofence_info_s *)g_hash_table_lookup(fence_map, (gpointer)p->fence_id);
+       if (info != NULL)
+               *state = info->state;
+       else
+               *state = GEOFENCE_STATE_UNCERTAIN;
+       GEOFENCE_LOGD("state value being assigned: %d", *state);
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_status_get_duration(geofence_status_h status, int *seconds)
+{
+       if (__is_geofence_feature_enabled() == false)
+                       return GEOFENCE_MANAGER_ERROR_NOT_SUPPORTED;
+
+       GEOFENCE_NULL_ARG_CHECK(status);
+       GEOFENCE_NULL_ARG_CHECK(seconds);
+
+       geofence_status_s *p = (geofence_status_s *)status;
+       geofence_info_s *info = (geofence_info_s *)g_hash_table_lookup(fence_map, (gpointer)p->fence_id);
+       if (info != NULL) {
+               gint64 time_in_secs = (g_get_real_time() / 1000000);
+               GEOFENCE_LOGD("Current time: %d, last updated: %d", time_in_secs, info->last_updated_time);
+               *seconds = (time_in_secs - info->last_updated_time); /* difference of time */
+       } else
+               *seconds = 0;
+       GEOFENCE_LOGD("Duration value assigned: %d", *seconds);
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+#endif /* GEOFENCE_DUMMY_API */
diff --git a/src/geofence_settings.h b/src/geofence_settings.h
new file mode 100644 (file)
index 0000000..0551173
--- /dev/null
@@ -0,0 +1,36 @@
+/* Copyright 2014 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.
+ */
+
+#ifndef __TIZEN_GEOFENCE_SETTINGS_H__
+#define __TIZEN_GEOFENCE_SETTINGS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ *@brief This API should be called when a fence needs to be enabled/disabled
+ *@param[in] manager Geofence manager instance
+ *@param[in] geofence_id ID of the fence which need to be enabled or disabled
+ *@param[in] enable boolean value should be set to true for enable and set to false for diable
+**/
+int geofence_manager_enable_fence(geofence_manager_h manager, int geofence_id, bool enable);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_GEOFENCE_SETTINGS_H__ */
+
diff --git a/src/manager/geofence-ielement.c b/src/manager/geofence-ielement.c
new file mode 100755 (executable)
index 0000000..0ef83be
--- /dev/null
@@ -0,0 +1,184 @@
+/* Copyright 2014 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.
+ */
+
+#include "geofence-log.h"
+#include "geofence-ielement.h"
+
+static void _glib_log(const gchar *log_domain, GLogLevelFlags log_level,
+                      const gchar *msg, gpointer user_data)
+{
+
+       GEOFENCE_LOGD("GLIB[%d] : %s", log_level, msg);
+}
+
+
+GType geofence_ielement_get_type(void)
+{
+       g_log_set_default_handler(_glib_log, NULL);
+
+       static GType iface_type = 0;
+
+       if (!iface_type) {
+               static const GTypeInfo info = {
+                       sizeof(GeofenceIElementInterface),      /* class_size */
+                       NULL,                           /* base_init */
+                       NULL                            /* base_finalize */
+               };
+
+               iface_type = g_type_register_static(G_TYPE_INTERFACE,   /* parent-type */
+                                                   "GeofenceIElement", /* type name */
+                                                   &info,                              /* info */
+                                                   0);                                 /* flags */
+       }
+
+       return iface_type;
+}
+
+int geofence_ielement_create(GeofenceIElement *self)
+{
+       g_return_val_if_fail(GEOFENCE_IS_IELEMENT(self), GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self), GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self)->create, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       return GEOFENCE_IELEMENT_GET_INTERFACE(self)->create(self);
+}
+
+int geofence_ielement_destroy(GeofenceIElement *self)
+{
+       g_return_val_if_fail(GEOFENCE_IS_IELEMENT(self), GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self), GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self)->destroy, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       return GEOFENCE_IELEMENT_GET_INTERFACE(self)->destroy(self);
+}
+
+int geofence_ielement_enable_service(GeofenceIElement *self, int geofence_id, bool enable)
+{
+       g_return_val_if_fail(GEOFENCE_IS_IELEMENT(self), GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(geofence_id, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self), GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self)->enable, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       return GEOFENCE_IELEMENT_GET_INTERFACE(self)->enable(self, geofence_id, enable);
+}
+
+int geofence_ielement_start(GeofenceIElement *self, int geofence_id)
+{
+       g_return_val_if_fail(GEOFENCE_IS_IELEMENT(self), GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(geofence_id, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self), GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self)->start, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       return GEOFENCE_IELEMENT_GET_INTERFACE(self)->start(self, geofence_id);
+}
+
+int geofence_ielement_stop(GeofenceIElement *self, int geofence_id)
+{
+       g_return_val_if_fail(GEOFENCE_IS_IELEMENT(self), GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(geofence_id, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self), GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self)->stop, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       return GEOFENCE_IELEMENT_GET_INTERFACE(self)->stop(self, geofence_id);
+}
+
+int geofence_ielement_add(GeofenceIElement *self, geofence_s *params, int *geofence_id)
+{
+       g_return_val_if_fail(GEOFENCE_IS_IELEMENT(self), GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(params, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(geofence_id, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self), GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self)->add, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       return GEOFENCE_IELEMENT_GET_INTERFACE(self)->add(self, params, geofence_id);
+}
+
+int geofence_ielement_add_place(GeofenceIElement *self, const char *place_name, int *place_id)
+{
+       g_return_val_if_fail(GEOFENCE_IS_IELEMENT(self), GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(place_name, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(place_id, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self), GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self)->add_place, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       return GEOFENCE_IELEMENT_GET_INTERFACE(self)->add_place(self, place_name, place_id);
+}
+
+int geofence_ielement_update_place(GeofenceIElement *self, const char *place_name, int place_id)
+{
+       g_return_val_if_fail(GEOFENCE_IS_IELEMENT(self), GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(place_name, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(place_id, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self), GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self)->update_place, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       return GEOFENCE_IELEMENT_GET_INTERFACE(self)->update_place(self, place_name, place_id);
+}
+
+int geofence_ielement_remove(GeofenceIElement *self, int geofence_id)
+{
+       g_return_val_if_fail(GEOFENCE_IS_IELEMENT(self), GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(geofence_id, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self), GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self)->remove, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       return GEOFENCE_IELEMENT_GET_INTERFACE(self)->remove(self, geofence_id);
+}
+
+int geofence_ielement_remove_place(GeofenceIElement *self, int place_id)
+{
+       g_return_val_if_fail(GEOFENCE_IS_IELEMENT(self), GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(place_id, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self), GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self)->remove_place, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       return GEOFENCE_IELEMENT_GET_INTERFACE(self)->remove_place(self, place_id);
+}
+
+int geofence_ielement_get_place_name(GeofenceIElement *self, int place_id, char **place_name)
+{
+       g_return_val_if_fail(GEOFENCE_IS_IELEMENT(self), GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(place_id, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(place_name, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self), GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self)->get_place_name, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       return GEOFENCE_IELEMENT_GET_INTERFACE(self)->get_place_name(self, place_id, place_name);
+}
+
+int geofence_ielement_get_fence_list(GeofenceIElement *self, int place_id, int *fence_amount, int **fence_ids, geofence_s **params)
+{
+       g_return_val_if_fail(GEOFENCE_IS_IELEMENT(self), GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(fence_amount, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(fence_ids, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(params, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self), GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self)->get_list, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       return GEOFENCE_IELEMENT_GET_INTERFACE(self)->get_list(self, place_id, fence_amount, fence_ids, params);
+}
+
+int geofence_ielement_get_place_list(GeofenceIElement *self, int *place_amount, int **place_ids, place_s **params)
+{
+       g_return_val_if_fail(GEOFENCE_IS_IELEMENT(self), GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(place_amount, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(place_ids, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(params, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self), GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(GEOFENCE_IELEMENT_GET_INTERFACE(self)->get_place_list, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       return GEOFENCE_IELEMENT_GET_INTERFACE(self)->get_place_list(self, place_amount, place_ids, params);
+}
+
diff --git a/src/manager/geofence-ielement.h b/src/manager/geofence-ielement.h
new file mode 100644 (file)
index 0000000..549753a
--- /dev/null
@@ -0,0 +1,95 @@
+/* Copyright 2014 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.
+ */
+
+#ifndef __GEOFENCE_IELEMENT_H__
+#define __GEOFENCE_IELEMENT_H__
+
+#include <glib-object.h>
+#include "geofence-type-private.h"
+
+/**
+ * @file geofence-ielement.h
+ * @brief This file contains the internal definitions and structures related to geofence interface.
+ */
+
+G_BEGIN_DECLS
+
+enum {
+    ZONE_IN,
+    ZONE_OUT,
+    GEOFENCE_EVENT,
+    LAST_SIGNAL
+};
+
+#define GEOFENCE_TYPE_IELEMENT                  (geofence_ielement_get_type ())
+#define GEOFENCE_IELEMENT(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEOFENCE_TYPE_IELEMENT, GeofenceIElement))
+#define GEOFENCE_IS_IELEMENT(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEOFENCE_TYPE_IELEMENT))
+#define GEOFENCE_IELEMENT_GET_INTERFACE(obj)    (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEOFENCE_TYPE_IELEMENT, GeofenceIElementInterface))
+
+typedef struct _GeofenceIElement          GeofenceIElement;
+typedef struct _GeofenceIElementInterface GeofenceIElementInterface;
+
+typedef int (*TYPE_GEOFENCE_CREATE)(GeofenceIElement *self);
+typedef int (*TYPE_GEOFENCE_DESTROY)(GeofenceIElement *self);
+typedef int (*TYPE_GEOFENCE_ENABLE)(GeofenceIElement *self, int geofence_id, bool enable);
+typedef int (*TYPE_GEOFENCE_START)(GeofenceIElement *self, int geofence_id);
+typedef int (*TYPE_GEOFENCE_STOP)(GeofenceIElement *self, int geofence_id);
+typedef int (*TYPE_GEOFENCE_ADD)(GeofenceIElement *self, geofence_s *params, int *geofence_id);
+typedef int (*TYPE_GEOFENCE_ADD_PLACE)(GeofenceIElement *self, const char *place_name, int *place_id);
+typedef int (*TYPE_GEOFENCE_UPDATE_PLACE)(GeofenceIElement *self, const char *place_name, int place_id);
+typedef int (*TYPE_GEOFENCE_REMOVE)(GeofenceIElement *self, int geofence_id);
+typedef int (*TYPE_GEOFENCE_REMOVE_PLACE)(GeofenceIElement *self, int place_id);
+typedef int (*TYPE_GEOFENCE_GET_PLACE_NAME)(GeofenceIElement *self, int place_id, char **place_name);
+typedef int (*TYPE_GEOFENCE_GET_LIST)(GeofenceIElement *self, int place_id, int *fence_amount, int **fence_ids, geofence_s **params);
+typedef int (*TYPE_GEOFENCE_GET_PLACE_LIST)(GeofenceIElement *self, int *place_amount, int **place_ids, place_s **params);
+
+struct _GeofenceIElementInterface {
+       GTypeInterface parent_iface;
+
+       TYPE_GEOFENCE_CREATE            create;
+       TYPE_GEOFENCE_DESTROY           destroy;
+       TYPE_GEOFENCE_ENABLE            enable;
+       TYPE_GEOFENCE_START             start;
+       TYPE_GEOFENCE_STOP              stop;
+       TYPE_GEOFENCE_ADD               add;
+       TYPE_GEOFENCE_ADD_PLACE         add_place;
+       TYPE_GEOFENCE_UPDATE_PLACE      update_place;
+       TYPE_GEOFENCE_REMOVE            remove;
+       TYPE_GEOFENCE_REMOVE_PLACE      remove_place;
+       TYPE_GEOFENCE_GET_PLACE_NAME    get_place_name;
+       TYPE_GEOFENCE_GET_LIST          get_list;
+       TYPE_GEOFENCE_GET_PLACE_LIST    get_place_list;
+};
+
+GType geofence_ielement_get_type(void);
+
+int geofence_ielement_create(GeofenceIElement *self);
+int geofence_ielement_destroy(GeofenceIElement *self);
+int geofence_ielement_enable_service(GeofenceIElement *self, int geofence_id, bool enable);
+int geofence_ielement_start(GeofenceIElement *self, int geofence_id);
+int geofence_ielement_stop(GeofenceIElement *self, int geofence_id);
+int geofence_ielement_add(GeofenceIElement *self, geofence_s *params, int *geofence_id);
+int geofence_ielement_add_place(GeofenceIElement *self, const char *place_name, int *place_id);
+int geofence_ielement_update_place(GeofenceIElement *self, const char *place_name, int place_id);
+int geofence_ielement_remove(GeofenceIElement *self, int geofence_id);
+int geofence_ielement_remove_place(GeofenceIElement *self, int place_id);
+int geofence_ielement_get_place_name(GeofenceIElement *self, int place_id, char **place_name);
+int geofence_ielement_get_fence_list(GeofenceIElement *self, int place_id, int *fence_amount, int **fence_ids, geofence_s **params);
+int geofence_ielement_get_place_list(GeofenceIElement *self, int *place_amount, int **place_ids, place_s **params);
+
+G_END_DECLS
+
+#endif
+
diff --git a/src/manager/geofence-internal.c b/src/manager/geofence-internal.c
new file mode 100644 (file)
index 0000000..96c7b87
--- /dev/null
@@ -0,0 +1,544 @@
+/* Copyright 2014 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "geofence-log.h"
+#include "module-internal.h"
+#include "geofence-internal.h"
+#include "geofence-marshal.h"
+#include "geofence-ielement.h"
+#include "geofence-param.h"
+#include "geofence-internal.h"
+#include "geofence_module.h"
+
+
+typedef struct _GeofenceInternalPrivate {
+       GeofenceInternalMod             *mod;
+       GMutex                  mutex;
+       geofence_s              *params;
+} GeofenceInternalPrivate;
+
+enum {
+    PROP_0,
+    PROP_GEOFENCE_PARAMS,
+    PROP_MAX
+};
+
+static guint32 signals[LAST_SIGNAL] = { 0, };
+static GParamSpec *properties[PROP_MAX] = {NULL, };
+static int gIsCreated = 0;
+
+#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), GEOFENCE_TYPE_INTERNAL, GeofenceInternalPrivate))
+
+static void geofence_ielement_interface_init(GeofenceIElementInterface *iface);
+
+
+G_DEFINE_TYPE_WITH_CODE(GeofenceInternal, geofence_internal, G_TYPE_OBJECT,
+                        G_IMPLEMENT_INTERFACE(GEOFENCE_TYPE_IELEMENT,
+                                              geofence_ielement_interface_init));
+
+/*
+static void geofence_parameter_set_property (GObject *object,
+       guint property_id,
+       const GValue *value,
+       GParamSpec *pspec)
+{
+       GeofenceInternalPrivate* priv = GET_PRIVATE(object);
+       g_return_if_fail (priv);
+       g_return_if_fail (priv->mod);
+       g_return_if_fail (priv->mod->handler);
+
+       int ret = 0;
+       switch (property_id){
+               case PROP_GEOFENCE_PARAMS:
+                       break;
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                       break;
+       }
+}
+*/
+
+static void geofence_internal_dispose(GObject *gobject)
+{
+       GEOFENCE_LOGD("geofence_internal_dispose");
+
+       GeofenceInternalPrivate *priv = GET_PRIVATE(gobject);
+       g_return_if_fail(priv);
+
+       g_mutex_clear(&priv->mutex);
+
+       G_OBJECT_CLASS(geofence_internal_parent_class)->dispose(gobject);
+}
+
+static void geofence_internal_finalize(GObject *gobject)
+{
+       GEOFENCE_LOGD("geofence_internal_finalize");
+
+       GeofenceInternalPrivate *priv = GET_PRIVATE(gobject);
+       g_return_if_fail(priv);
+
+       module_free(priv->mod, "geofence");
+       priv->mod = NULL;
+
+       if (priv->params) {
+               geofence_parameter_free(priv->params);
+               priv->params = NULL;
+       }
+
+       G_OBJECT_CLASS(geofence_internal_parent_class)->finalize(gobject);
+}
+
+static void geofence_internal_get_property(GObject *object,
+                                           guint property_id,
+                                           GValue *value,
+                                           GParamSpec *pspec)
+{
+       GEOFENCE_LOGD("geofence_internal_get_property");
+       GeofenceInternalPrivate *priv = GET_PRIVATE(object);
+       g_return_if_fail(priv);
+       g_return_if_fail(priv->mod);
+       g_return_if_fail(priv->mod->handler);
+
+       switch (property_id) {
+               case PROP_GEOFENCE_PARAMS:
+                       g_value_set_boxed(value, priv->params);
+                       break;
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+                       break;
+       }
+}
+
+void geofence_signaling(GeofenceObject *obj,
+                        guint32 signals[LAST_SIGNAL],
+                        guint geofence_id,
+                        guint state)
+{
+       GEOFENCE_LOGD("geofence_signaling");
+
+       g_return_if_fail(obj);
+       g_return_if_fail(signals);
+       g_return_if_fail(state);
+
+       if (state == GEOFENCE_STATE_IN) {
+               GEOFENCE_LOGD("Signal emit: ZONE IN");
+               g_signal_emit(obj, signals[ZONE_IN], 0, geofence_id, NULL);
+       } else if (state == GEOFENCE_STATE_OUT) {
+               GEOFENCE_LOGD("Signal emit : ZONE_OUT");
+               g_signal_emit(obj, signals[ZONE_OUT], 0, geofence_id, NULL);
+       }
+}
+
+void geofence_event_signaling(GeofenceObject *obj,
+                              guint32 signals[LAST_SIGNAL],
+                              guint place_id,
+                              guint fence_id,
+                              guint error,
+                              guint state)
+{
+       GEOFENCE_LOGD("geofence_event_signaling");
+       g_return_if_fail(obj);
+       g_return_if_fail(signals);
+
+       /* Signal has to be emitted here */
+       g_signal_emit(obj, signals[GEOFENCE_EVENT], 0, place_id, fence_id, error, state, NULL);
+}
+
+static void _state_cb(int geofence_id, int state, gpointer userdata)
+{
+       GEOFENCE_LOGD("_state_cb");
+       g_return_if_fail(userdata);
+       GeofenceInternalPrivate *priv = GET_PRIVATE(userdata);
+       g_return_if_fail(priv);
+       GEOFENCE_LOGD("geofence id [%d] state [%d]", geofence_id, state);
+       geofence_signaling(userdata, signals, geofence_id, state);
+}
+
+static void _geofence_event_cb(int place_id, int geofence_id, int error, int state, gpointer userdata)
+{
+       GEOFENCE_LOGD("_geofence_event_cb");
+       g_return_if_fail(userdata);
+       GeofenceInternalPrivate *priv = GET_PRIVATE(userdata);
+       g_return_if_fail(priv);
+       geofence_event_signaling(userdata, signals, place_id, geofence_id, error, state);
+}
+
+static int geofence_internal_create(GeofenceInternal *self)
+{
+       GEOFENCE_LOGD("geofence_internal_create");
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+       g_return_val_if_fail(priv, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->handler, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->ops.create, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       if (gIsCreated == 0) {
+               ret = priv->mod->ops.create(priv->mod->handler, _state_cb, _geofence_event_cb, self);
+               if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+                       GEOFENCE_LOGE("Fail to create. Error[%d]", ret);
+               }
+               gIsCreated = 1;
+       }
+
+       return ret;
+}
+
+static int geofence_internal_destroy(GeofenceInternal *self)
+{
+       GEOFENCE_LOGD("geofence_internal_destroy");
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+       g_return_val_if_fail(priv, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->handler, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->ops.destroy, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = priv->mod->ops.destroy(priv->mod->handler);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Fail to destroy. Error[%d]", ret);
+       }
+
+       if (gIsCreated == 1) {
+               gIsCreated = 0;
+       }
+
+       return ret;
+}
+
+static int geofence_internal_enable_service(GeofenceInternal *self, int geofence_id, bool enable)
+{
+       GEOFENCE_LOGD("geofence_internal_enable_service");
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+       g_return_val_if_fail(priv, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->handler, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->ops.enable_service, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+       ret = priv->mod->ops.enable_service(priv->mod->handler, geofence_id, enable);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Fail to enable the geofence. Error[%d]", ret);
+       }
+       return ret;
+}
+
+static int geofence_internal_start(GeofenceInternal *self, int geofence_id)
+{
+       GEOFENCE_LOGD("geofence_internal_start");
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+       g_return_val_if_fail(priv, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->handler, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->ops.start_geofence, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = priv->mod->ops.start_geofence(priv->mod->handler, geofence_id);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Fail to start geofence. Error[%d]", ret);
+       }
+       return ret;
+}
+
+static int geofence_internal_stop(GeofenceInternal *self, int geofence_id)
+{
+       GEOFENCE_LOGD("geofence_internal_stop");
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+       g_return_val_if_fail(priv, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->handler, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->ops.stop_geofence, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = priv->mod->ops.stop_geofence(priv->mod->handler, geofence_id);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Failed to stop. Error[%d]", ret);
+       }
+       return ret;
+}
+
+static int geofence_internal_add(GeofenceInternal *self, geofence_s *params, int *geofence_id)
+{
+       GEOFENCE_LOGD("geofence_internal_add");
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+
+       g_return_val_if_fail(priv, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->handler, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       g_return_val_if_fail(priv->mod->ops.add_geopoint, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->ops.add_bssid, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       if (priv->params) geofence_parameter_free(priv->params);
+       priv->params = geofence_parameter_copy(params);
+
+       g_return_val_if_fail(priv->params, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       if (priv->params->type == GEOFENCE_TYPE_GEOPOINT) {
+               ret = priv->mod->ops.add_geopoint(priv->mod->handler, priv->params->place_id, priv->params->latitude, priv->params->longitude, priv->params->radius, priv->params->address, geofence_id);
+               if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+                       GEOFENCE_LOGE("Fail to add geofence. Error[%d]", ret);
+               } else {
+                       GEOFENCE_LOGE("Success to add geofence. Error[%d]", ret);
+               }
+       } else {
+               ret = priv->mod->ops.add_bssid(priv->mod->handler, priv->params->place_id, priv->params->bssid, priv->params->ssid, priv->params->type, geofence_id);
+               if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+                       GEOFENCE_LOGE("Fail to add geofence. Error[%d]", ret);
+               } else {
+                       GEOFENCE_LOGE("Success to add geofence. Error[%d]", ret);
+               }
+       }
+
+       return ret;
+}
+
+static int geofence_internal_remove(GeofenceInternal *self, int geofence_id)
+{
+       GEOFENCE_LOGD("geofence_internal_remove");
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+       g_return_val_if_fail(priv, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->handler, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->ops.remove_geofence, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = priv->mod->ops.remove_geofence(priv->mod->handler, geofence_id);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Failed to remove geofence. Error[%d]", ret);
+       }
+       return ret;
+}
+
+static int geofence_internal_get_list(GeofenceInternal *self, int place_id, int *fence_amount, int **fence_ids, geofence_s **params)
+{
+       GEOFENCE_LOGD("geofence_internal_get_list");
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+       g_return_val_if_fail(priv, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->handler, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->ops.get_geofences, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = priv->mod->ops.get_geofences(priv->mod->handler, place_id, fence_amount, fence_ids, params);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Failed to get list. Error[%d]", ret);
+       }
+       return ret;
+}
+
+static int geofence_internal_add_place(GeofenceInternal *self, const char *place_name, int *place_id)
+{
+       GEOFENCE_LOGD("geofence_internal_add_place");
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+       g_return_val_if_fail(priv, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->handler, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->ops.add_place, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = priv->mod->ops.add_place(priv->mod->handler, place_name, place_id);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Failed to add place. Error[%d]", ret);
+       } else {
+               GEOFENCE_LOGE("Success to add place. Error[%d]", ret);
+       }
+
+       return ret;
+}
+
+static int geofence_internal_update_place(GeofenceInternal *self, const char *place_name, int place_id)
+{
+       GEOFENCE_LOGD("geofence_internal_update_place");
+
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+
+       g_return_val_if_fail(priv, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->handler, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->ops.update_place, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = priv->mod->ops.update_place(priv->mod->handler, place_id, place_name);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Fail to update place. Error[%d]", ret);
+       } else {
+               GEOFENCE_LOGE("Success to update place. Error[%d]", ret);
+       }
+
+       return ret;
+}
+
+static int geofence_internal_remove_place(GeofenceInternal *self, int place_id)
+{
+
+       GEOFENCE_LOGD("geofence_internal_remove_place");
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+       g_return_val_if_fail(priv, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->handler, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->ops.remove_place, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = priv->mod->ops.remove_place(priv->mod->handler, place_id);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Failed to remove place. Error[%d]", ret);
+       } else {
+               GEOFENCE_LOGE("Success to remove place. Error[%d]", ret);
+       }
+       return ret;
+}
+
+static int geofence_internal_get_place_name(GeofenceInternal *self, int place_id, char **place_name)
+{
+       GEOFENCE_LOGD("geofence_internal_get_place_name");
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+       g_return_val_if_fail(priv, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->handler, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->ops.get_place_name, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = priv->mod->ops.get_place_name(priv->mod->handler, place_id, place_name);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Failed to get the place name. Error[%d]", ret);
+       } else {
+               GEOFENCE_LOGE("Success to get the place name. Error[%d]", ret);
+       }
+       return ret;
+}
+
+static int geofence_internal_get_place_list(GeofenceInternal *self, int *place_amount, int **place_ids, place_s **params)
+{
+
+       GEOFENCE_LOGD("geofence_internal_get_place_list");
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+       g_return_val_if_fail(priv, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->handler, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+       g_return_val_if_fail(priv->mod->ops.get_places, GEOFENCE_MANAGER_ERROR_EXCEPTION);
+
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+
+       ret = priv->mod->ops.get_places(priv->mod->handler, place_amount, place_ids, params);
+       if (ret != GEOFENCE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Failed to get place list. Error[%d]", ret);
+       }
+       return ret;
+}
+
+static void geofence_ielement_interface_init(GeofenceIElementInterface *iface)
+{
+       iface->create = (TYPE_GEOFENCE_CREATE) geofence_internal_create;
+       iface->destroy = (TYPE_GEOFENCE_DESTROY) geofence_internal_destroy;
+       iface->enable = (TYPE_GEOFENCE_ENABLE) geofence_internal_enable_service;
+       iface->start = (TYPE_GEOFENCE_START) geofence_internal_start;
+       iface->stop = (TYPE_GEOFENCE_STOP) geofence_internal_stop;
+       iface->add = (TYPE_GEOFENCE_ADD) geofence_internal_add;
+       iface->remove = (TYPE_GEOFENCE_REMOVE) geofence_internal_remove;
+       iface->get_list = (TYPE_GEOFENCE_GET_LIST) geofence_internal_get_list;
+
+       iface->add_place = (TYPE_GEOFENCE_ADD_PLACE) geofence_internal_add_place;
+       iface->update_place = (TYPE_GEOFENCE_UPDATE_PLACE) geofence_internal_update_place;
+       iface->remove_place = (TYPE_GEOFENCE_REMOVE_PLACE) geofence_internal_remove_place;
+       iface->get_place_name = (TYPE_GEOFENCE_GET_PLACE_NAME) geofence_internal_get_place_name;
+       iface->get_place_list = (TYPE_GEOFENCE_GET_PLACE_LIST) geofence_internal_get_place_list;
+}
+
+static void geofence_internal_init(GeofenceInternal *self)
+{
+       GEOFENCE_LOGD("geofence_internal_init");
+
+       GeofenceInternalPrivate *priv = GET_PRIVATE(self);
+       g_return_if_fail(priv);
+
+       priv->mod = (GeofenceInternalMod *)module_new("geofence");
+       if (!priv->mod) GEOFENCE_LOGW("geofence module loading failed");
+
+       g_mutex_init(&priv->mutex);
+}
+
+static void geofence_internal_class_init(GeofenceInternalClass *klass)
+{
+       GEOFENCE_LOGD("geofence_internal_class_init");
+       GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+       /*      gobject_class->set_property = geofence_parameter_set_property; */
+       gobject_class->get_property = geofence_internal_get_property;
+
+       gobject_class->dispose = geofence_internal_dispose;
+       gobject_class->finalize = geofence_internal_finalize;
+
+       g_type_class_add_private(klass, sizeof(GeofenceInternalPrivate));
+
+       signals[ZONE_IN] = g_signal_new("zone-in",
+                                       G_TYPE_FROM_CLASS(klass),
+                                       G_SIGNAL_RUN_FIRST |
+                                       G_SIGNAL_NO_RECURSE,
+                                       G_STRUCT_OFFSET(GeofenceInternalClass, zone_in),
+                                       NULL, NULL,
+                                       geofence_VOID__UINT,
+                                       G_TYPE_NONE, 1,
+                                       G_TYPE_UINT);
+
+       signals[ZONE_OUT] = g_signal_new("zone-out",
+                                        G_TYPE_FROM_CLASS(klass),
+                                        G_SIGNAL_RUN_FIRST |
+                                        G_SIGNAL_NO_RECURSE,
+                                        G_STRUCT_OFFSET(GeofenceInternalClass, zone_out),
+                                        NULL, NULL,
+                                        geofence_VOID__UINT,
+                                        G_TYPE_NONE, 1,
+                                        G_TYPE_UINT);
+
+       signals[GEOFENCE_EVENT] = g_signal_new("geofence-event",
+                                              G_TYPE_FROM_CLASS(klass),
+                                              G_SIGNAL_RUN_FIRST |
+                                              G_SIGNAL_NO_RECURSE,
+                                              G_STRUCT_OFFSET(GeofenceInternalClass, geofence_event),
+                                              NULL, NULL,
+                                              g_cclosure_marshal_generic,
+                                              G_TYPE_NONE, 4,
+                                              G_TYPE_UINT,
+                                              G_TYPE_UINT,
+                                              G_TYPE_UINT,
+                                              G_TYPE_UINT);
+
+       properties[PROP_GEOFENCE_PARAMS] = g_param_spec_boxed("geofence-parameter",
+                                                             "geofence parameter prop",
+                                                             "geofence parameter data",
+                                                             GEOFENCE_PRAMETER,
+                                                             G_PARAM_READABLE);
+
+       g_object_class_install_properties(gobject_class,
+                                         PROP_MAX,
+                                         properties);
+
+}
diff --git a/src/manager/geofence-internal.h b/src/manager/geofence-internal.h
new file mode 100644 (file)
index 0000000..c3f5cde
--- /dev/null
@@ -0,0 +1,56 @@
+/* Copyright 2014 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.
+ */
+
+#ifndef __GEOFENCE_INTERNAL_H__
+#define __GEOFENCE_INTERNAL_H__
+
+#include "geofence-ielement.h"
+
+/**
+ * @file geofence-internal.h
+ * @brief This file contains the internal definitions and structures related to Geofence method.
+ */
+
+G_BEGIN_DECLS
+
+#define GEOFENCE_TYPE_INTERNAL                                 (geofence_internal_get_type ())
+#define GEOFENCE_INTERNAL(obj)                                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEOFENCE_TYPE_INTERNAL, GeofenceInternal))
+#define GEOFENCE_IS_INTERNAL(obj)                              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEOFENCE_TYPE_INTERNAL))
+#define GEOFENCE_INTERNAL_CLASS(klass)                 (G_TYPE_CHECK_CLASS_CAST ((klass), GEOFENCE_TYPE_INTERNAL, GeofenceInternalClass))
+#define GEOFENCE_IS_INTERNAL_CLASS(klass)              (G_TYPE_CHECK_CLASS_TYPE ((klass), GEOFENCE_TYPE_INTERNAL))
+#define GEOFENCE_INTERNAL_GET_CLASS(obj)               (G_TYPE_INSTANCE_GET_CLASS ((obj), GEOFENCE_TYPE_INTERNAL, GeofenceInternalClass))
+
+typedef struct _GeofenceInternal       GeofenceInternal;
+typedef struct _GeofenceInternalClass  GeofenceInternalClass;
+
+struct _GeofenceInternal {
+       GObject parent_instance;
+};
+
+struct _GeofenceInternalClass {
+       GObjectClass parent_class;
+
+       void (* zone_in)(guint geofence_id);
+       void (* zone_out)(guint geofence_id);
+       void (* geofence_event)(guint place_id, guint geofence_id, guint error, guint state);
+};
+
+/*typedef void (*service_status_cb) (int status, void *user_data); */
+
+GType geofence_internal_get_type(void);
+
+G_END_DECLS
+
+#endif
diff --git a/src/manager/geofence-log.c b/src/manager/geofence-log.c
new file mode 100644 (file)
index 0000000..4041c0a
--- /dev/null
@@ -0,0 +1,78 @@
+/* Copyright 2014 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.
+ */
+
+#include "geofence_type.h"
+#include "geofence-log.h"
+
+/*
+* Internal Implementation
+*/
+
+int __print_error_code(int code)
+{
+       int ret = GEOFENCE_MANAGER_ERROR_NONE;
+       char *msg = "GEOFENCE_MANAGER_ERROR_NONE";
+       switch (code) {
+               case GEOFENCE_MANAGER_ERROR_NONE:
+                       ret = GEOFENCE_MANAGER_ERROR_NONE;
+                       msg = "GEOFENCE_MANAGER_ERROR_NONE";
+                       break;
+               case GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED:
+                       ret = GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED;
+                       msg = "GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED";
+                       break;
+               case GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED:
+                       ret = GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED;
+                       msg = "GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED";
+                       break;
+               case GEOFENCE_MANAGER_ERROR_INVALID_ID:
+                       ret = GEOFENCE_MANAGER_ERROR_INVALID_ID;
+                       msg = "GEOFENCE_MANAGER_ERROR_INVALID_ID";
+                       break;
+               case GEOFENCE_MANAGER_ERROR_EXCEPTION:
+                       ret = GEOFENCE_MANAGER_ERROR_EXCEPTION;
+                       msg = "GEOFENCE_MANAGER_ERROR_EXCEPTION";
+                       break;
+               case GEOFENCE_MANAGER_ERROR_ALREADY_STARTED:
+                       ret = GEOFENCE_MANAGER_ERROR_ALREADY_STARTED;
+                       msg = "GEOFENCE_MANAGER_ERROR_ALREADY_STARTED";
+                       break;
+               case GEOFENCE_MANAGER_ERROR_TOO_MANY_GEOFENCE:
+                       ret = GEOFENCE_MANAGER_ERROR_TOO_MANY_GEOFENCE;
+                       msg = "GEOFENCE_MANAGER_ERROR_TOO_MANY_GEOFENCE";
+                       break;
+               case GEOFENCE_MANAGER_ERROR_IPC:
+                       ret = GEOFENCE_MANAGER_ERROR_IPC;
+                       msg = "GEOFENCE_MANAGER_ERROR_IPC";
+                       break;
+               case GEOFENCE_MANAGER_ERROR_DATABASE:
+                       ret = GEOFENCE_MANAGER_ERROR_DATABASE;
+                       msg = "GEOFENCE_MANAGER_ERROR_DATABASE";
+                       break;
+               case GEOFENCE_MANAGER_ERROR_PLACE_ACCESS_DENIED:
+                       ret = GEOFENCE_MANAGER_ERROR_PLACE_ACCESS_DENIED;
+                       msg = "GEOFENCE_MANAGER_ERROR_PLACE_ACCESS_DENIED";
+                       break;
+               case GEOFENCE_MANAGER_ERROR_GEOFENCE_ACCESS_DENIED:
+                       ret = GEOFENCE_MANAGER_ERROR_GEOFENCE_ACCESS_DENIED;
+                       msg = "GEOFENCE_MANAGER_ERROR_GEOFENCE_ACCESS_DENIED";
+                       break;
+               default:
+                       msg = "GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED";
+                       ret = GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED;
+       }
+       GEOFENCE_LOGE("ERROR : %s(0x%08x)", msg, ret);
+       return ret;
+}
diff --git a/src/manager/geofence-log.h b/src/manager/geofence-log.h
new file mode 100644 (file)
index 0000000..f43bb67
--- /dev/null
@@ -0,0 +1,67 @@
+/* Copyright 2014 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.
+ */
+
+#ifndef __GEOFENCE_LOG_H__
+#define __GEOFENCE_LOG_H__
+
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "CAPI_GEOFENCE_MANAGER"
+
+/*
+* Internal Macros
+*/
+
+#define GEOFENCE_LOGD(fmt,args...) LOGD(fmt, ##args)
+#define GEOFENCE_LOGW(fmt,args...) LOGW(fmt, ##args)
+#define GEOFENCE_LOGI(fmt,args...) LOGI(fmt, ##args)
+#define GEOFENCE_LOGE(fmt,args...) LOGE(fmt, ##args)
+
+#define GEOFENCE_CHECK_CONDITION(condition, error, msg)        \
+       do { \
+               if (condition) { \
+               } else { \
+                       GEOFENCE_LOGE("%s(0x%08x)", msg, error); \
+                       return error; \
+               } \
+       } while (0)
+
+
+#define GEOFENCE_PRINT_ERROR_CODE(error, msg)  \
+       do { \
+               GEOFENCE_LOGE("%s(0x%08x)", msg, error); \
+               return error; \
+       } while (0)
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#define GEOFENCE_NULL_ARG_CHECK(arg)   \
+       GEOFENCE_CHECK_CONDITION((arg != NULL),GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER,"GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER") \
+        
+int __print_error_code(int code);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*__GEOFENCE_LOG_H__ */
diff --git a/src/manager/geofence-marshal.list b/src/manager/geofence-marshal.list
new file mode 100644 (file)
index 0000000..db5fc2c
--- /dev/null
@@ -0,0 +1,4 @@
+VOID:POINTER,POINTER,POINTER
+VOID:UINT,POINTER,POINTER
+VOID:UINT
+VOID:UINT,UINT,UINT
diff --git a/src/manager/geofence-param.c b/src/manager/geofence-param.c
new file mode 100644 (file)
index 0000000..a6eb293
--- /dev/null
@@ -0,0 +1,86 @@
+/* Copyright 2014 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.
+ */
+
+#include "geofence-log.h"
+#include "geofence-param.h"
+
+
+GType geofence_parameter_get_type(void)
+{
+       static volatile gsize type_volatile = 0;
+       if (g_once_init_enter(&type_volatile)) {
+               GType type = g_boxed_type_register_static(g_intern_static_string("geofence_s"), (GBoxedCopyFunc) geofence_parameter_copy, (GBoxedFreeFunc) geofence_parameter_free);
+               g_once_init_leave(&type_volatile, type);
+       }
+       return type_volatile;
+}
+
+geofence_s *geofence_parameter_new(gint place_id, guint type, gdouble latitude, gdouble longitude, guint radius, const gchar *address, const gchar *bssid, const gchar *ssid)
+{
+       GEOFENCE_LOGD("geofence_parameter_new");
+
+       if (place_id < 0) return NULL;
+       if (type == GEOFENCE_TYPE_GEOPOINT && (latitude < -90 || latitude > 90)) return NULL;
+       if (type == GEOFENCE_TYPE_GEOPOINT && (longitude < -180 || longitude > 180)) return NULL;
+       if (type == GEOFENCE_TYPE_GEOPOINT && (radius < 100 || radius > 500)) return NULL;
+       if (type == GEOFENCE_TYPE_GEOPOINT && address == NULL) return NULL;
+       if (type != GEOFENCE_TYPE_GEOPOINT && (bssid == NULL) && (ssid == NULL)) return NULL;
+
+       geofence_s *param = g_slice_new0(geofence_s);
+       g_return_val_if_fail(param, NULL);
+
+       param->place_id = place_id;
+       param->type = type;
+       param->latitude = latitude;
+       param->longitude = longitude;
+       param->radius = radius;
+       if (type != GEOFENCE_TYPE_GEOPOINT) {
+               g_strlcpy(param->bssid, bssid, WLAN_BSSID_LEN);
+               g_strlcpy(param->ssid, ssid, WLAN_BSSID_LEN);
+       } else
+               g_strlcpy(param->address, address, ADDRESS_LEN);
+
+       GEOFENCE_LOGD("geofence_parameter_new : type[%d], place_id[%d], latitude[%f], longitude[%f], radius[%d]", param->type, param->place_id, param->latitude, param->longitude, param->radius);
+
+       return param;
+}
+
+geofence_s *geofence_parameter_copy(const geofence_s *params)
+{
+       g_return_val_if_fail(params, NULL);
+
+       geofence_s *new_param = NULL;
+
+       new_param = geofence_parameter_new(params->place_id, params->type, params->latitude, params->longitude, params->radius, params->address, params->bssid, params->ssid);
+       if (new_param == NULL) {
+               GEOFENCE_LOGD("fail to create new param");
+               return NULL;
+       }
+
+       if (params->type != GEOFENCE_TYPE_GEOPOINT) {
+               GEOFENCE_LOGD("bssid : %s", new_param->bssid);
+               GEOFENCE_LOGD("ssid : %s", new_param->ssid);
+       } else {
+               GEOFENCE_LOGD("Address: %s", new_param->address);
+       }
+
+       return new_param;
+}
+
+void geofence_parameter_free(geofence_s *params)
+{
+       g_return_if_fail(params);
+       g_slice_free(geofence_s, params);
+}
diff --git a/src/manager/geofence-param.h b/src/manager/geofence-param.h
new file mode 100644 (file)
index 0000000..3899d85
--- /dev/null
@@ -0,0 +1,32 @@
+/* Copyright 2014 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.
+ */
+
+#ifndef __GEOFENCE_PARAM_H__
+#define __GEOFENCE_PARAM_H__
+
+#include "geofence-type-private.h"
+
+G_BEGIN_DECLS
+
+GType geofence_parameter_get_type(void);
+#define GEOFENCE_PRAMETER (geofence_parameter_get_type ())
+
+geofence_s *geofence_parameter_new(gint place_id, guint type, gdouble latitude, gdouble longitude, guint radius, const gchar *address, const gchar *bssid, const gchar *ssid);
+geofence_s *geofence_parameter_copy(const geofence_s *params);
+void geofence_parameter_free(geofence_s *params);
+
+G_END_DECLS
+
+#endif
diff --git a/src/manager/geofence-privacy.c b/src/manager/geofence-privacy.c
new file mode 100644 (file)
index 0000000..79eb33e
--- /dev/null
@@ -0,0 +1,187 @@
+/* Copyright 2014 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.
+ */
+
+#include <glib.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <app_manager.h>
+#include <package_manager.h>
+#include <pkgmgr-info.h>
+#include <privacy_checker_client.h>
+
+#include "geofence-log.h"
+#include "geofence-type-private.h"
+
+#define CAPP    1
+#define WEBAPP  2
+#define CPPAPP  3
+#define LOCATION_PRIVILEGE     "http://tizen.org/privilege/location"
+
+int location_get_app_type(char *target_app_id)
+{
+       int ret = 0;
+       pid_t pid = 0;
+       char *app_id = NULL;
+       app_info_h app_info;
+       char *type = NULL;
+
+       if (target_app_id == NULL) {
+               pid = getpid();
+               ret = app_manager_get_app_id(pid, &app_id);
+               if (ret != APP_MANAGER_ERROR_NONE) {
+                       GEOFENCE_LOGE("Fail to get app_id. Err[%d]", ret);
+                       return GEOFENCE_MANAGER_ERROR_NONE;
+               }
+       } else {
+               app_id = g_strdup(target_app_id);
+       }
+
+       ret = app_info_create(app_id, &app_info);
+       if (ret != APP_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Fail to get app_id. Err[%d]", ret);
+               g_free(app_id);
+               return 0;
+       }
+
+       ret = app_info_get_type(app_info, &type);
+       if (ret != APP_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Fail to get type. Err[%d]", ret);
+               g_free(app_id);
+               app_info_destroy(app_info);
+               return 0;
+       }
+
+       if (strcmp(type, "c++app") == 0)
+               ret = CPPAPP;
+       else if (strcmp(type, "webapp") == 0)
+               ret = WEBAPP;
+       else
+               ret = CAPP;
+
+       g_free(type);
+       g_free(app_id);
+       app_info_destroy(app_info);
+
+       return ret;
+}
+
+void geofence_privacy_initialize(void)
+{
+       int ret = 0;
+       pid_t pid = 0;
+       char *app_id = NULL;
+       char *package_id = NULL;
+       pkgmgrinfo_appinfo_h pkgmgrinfo_appinfo;
+
+       pid = getpid();
+       ret = app_manager_get_app_id(pid, &app_id);
+       if (ret != APP_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Fail to get app_id. Err[%d]", ret);
+               return;
+       }
+
+       ret = pkgmgrinfo_appinfo_get_appinfo(app_id, &pkgmgrinfo_appinfo);
+       if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Fail to get appinfo for [%s]. Err[%d]", app_id, ret);
+               g_free(app_id);
+               return;
+       }
+       ret = pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo, &package_id);
+       if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Fail to get package_id for [%s]. Err[%d]", app_id, ret);
+               pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo);
+               g_free(app_id);
+               return;
+       }
+
+       ret = privacy_checker_initialize(package_id);
+       if (ret != PRIV_MGR_ERROR_SUCCESS) {
+               GEOFENCE_LOGE("Fail to initialize privacy checker. err[%d]", ret);
+               pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo);
+               g_free(app_id);
+               return;
+       }
+
+       GEOFENCE_LOGD("Success to initialize privacy checker");
+
+       g_free(app_id);
+       pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo);
+}
+
+void geofence_privacy_finalize(void)
+{
+       int ret = 0;
+       ret = privacy_checker_finalize();
+       if (ret != PRIV_MGR_ERROR_SUCCESS) {
+               GEOFENCE_LOGE("Fail to finalize privacy_cehecker. Err[%d]", ret);
+               return;
+       }
+
+       GEOFENCE_LOGD("Success to finalize privacy checker");
+}
+
+int geofence_get_privacy(void)
+{
+       int ret = 0;
+       pid_t pid = 0;
+       char *app_id = NULL;
+       char *package_id = NULL;
+       int app_type = 0;
+       pkgmgrinfo_appinfo_h pkgmgrinfo_appinfo;
+
+       pid = getpid();
+       ret = app_manager_get_app_id(pid, &app_id);
+       if (ret != APP_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Fail to get app_id. Err[%d]", ret);
+               return GEOFENCE_MANAGER_ERROR_NONE;
+       }
+
+       app_type = location_get_app_type(app_id);
+       if (app_type == CPPAPP) {
+               GEOFENCE_LOGE("CPPAPP use location");
+               g_free(app_id);
+               return GEOFENCE_MANAGER_ERROR_NONE;
+       }
+
+       ret = pkgmgrinfo_appinfo_get_appinfo(app_id, &pkgmgrinfo_appinfo);
+       if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Fail to get appinfo of [%s]. Err[%d]", app_id, ret);
+               g_free(app_id);
+               return GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED;
+       }
+
+       ret = pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo, &package_id);
+       if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+               GEOFENCE_LOGE("Fail to get package_id of [%s]. Err[%d]", app_id, ret);
+               g_free(app_id);
+               pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo);
+               return GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED;
+       }
+
+       ret = privacy_checker_check_package_by_privilege(package_id, LOCATION_PRIVILEGE);
+       if (ret != PRIV_MGR_ERROR_SUCCESS) {
+               GEOFENCE_LOGE("Fail to get privilege of [%s] package. Err[%d]", package_id, ret);
+               pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo);
+               g_free(app_id);
+               return GEOFENCE_MANAGER_ERROR_PERMISSION_DENIED;
+       }
+
+       pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo);
+       g_free(app_id);
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
diff --git a/src/manager/geofence-privacy.h b/src/manager/geofence-privacy.h
new file mode 100644 (file)
index 0000000..664d6b8
--- /dev/null
@@ -0,0 +1,25 @@
+/* Copyright 2014 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.
+ */
+
+#ifndef __GEOFENCE_PRIVACY_H__
+#define __GEOFENCE_PRIVACY_H__
+
+int geofence_get_app_type(void);
+int geofence_get_privacy(void);
+
+void geofence_privacy_initialize(void);
+void geofence_privacy_finalize(void);
+
+#endif
diff --git a/src/manager/geofence-type-private.h b/src/manager/geofence-type-private.h
new file mode 100644 (file)
index 0000000..6cb2252
--- /dev/null
@@ -0,0 +1,77 @@
+/* Copyright 2014 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.
+ */
+
+#ifndef __GEOFENCE_TYPE_PRIAVE_H__
+#define __GEOFENCE_TYPE_PRIAVE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include "geofence_type.h"
+#include "geofence_data_type.h"
+
+G_BEGIN_DECLS
+
+#define _GEOFENCE_CALLBACK_MAX         100
+
+/**
+ * @brief Geofence object redefined by GObject.
+ */
+typedef GObject GeofenceObject;
+
+
+/**
+ * @brief The geofence signal types
+ */
+typedef enum {
+    _GEOFENCE_SIGNAL_ZONE_IN,
+    _GEOFENCE_SIGNAL_ZONE_OUT,
+    _GEOFENCE_SIGNAL_EVENT,
+    _GEOFENCE_SIGNAL_NUM
+} _geofence_signal_e;
+
+/**
+ * @brief The geofence manager structure
+ */
+typedef struct _geofence_manager_s {
+       GeofenceObject *object;
+       const void *user_cb;
+       const void *user_event_cb;
+       void *user_data;
+       gulong sig_id[_GEOFENCE_SIGNAL_NUM];
+       GList *app_fence_list;
+} geofence_manager_s;
+
+/**
+* @brief The geofence complete information structure
+*/
+typedef struct _geofence_info_s {
+       geofence_s *info;
+       geofence_state_e state;
+       int last_updated_time;
+} geofence_info_s;
+
+/**
+ * @brief The geofence status structure
+ */
+typedef struct _geofence_status_s {
+       int fence_id;
+       geofence_state_e state;
+       int seconds;
+} geofence_status_s;
+
+
+G_END_DECLS
+
+#endif /* __GEOFENCE_TYPE_PRIAVE_H__ */
diff --git a/src/manager/geofence.c b/src/manager/geofence.c
new file mode 100644 (file)
index 0000000..01b2399
--- /dev/null
@@ -0,0 +1,75 @@
+/* Copyright 2014 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.
+ */
+
+#include <glib.h>
+#include <stdio.h>
+#include <pthread.h>
+
+#include "geofence-internal.h"
+#include "module-internal.h"
+#include "geofence-log.h"
+#include "geofence.h"
+
+int geofence_init(void)
+{
+       GEOFENCE_LOGD("geofence_init");
+
+#if !GLIB_CHECK_VERSION(2, 35, 0)
+       g_type_init();
+#endif
+
+#if !GLIB_CHECK_VERSION(2, 31, 0)
+       if (!g_thread_supported()) g_thread_init(NULL);
+#endif
+       if (FALSE == module_init())
+               return GEOFENCE_MANAGER_ERROR_NOT_INITIALIZED;
+
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+GeofenceObject *geofence_new(void)
+{
+       GEOFENCE_LOGD("geofence_new");
+
+       GeofenceObject *self = NULL;
+
+       self = g_object_new(GEOFENCE_TYPE_INTERNAL, NULL);
+
+       if (!self) GEOFENCE_LOGD("Fail to create geofence object. [%d]");
+       return self;
+}
+
+int geofence_free(GeofenceObject *obj)
+{
+       GEOFENCE_LOGD("geofence_free");
+
+       g_return_val_if_fail(obj, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER);
+       g_object_unref(obj);
+       return GEOFENCE_MANAGER_ERROR_NONE;
+}
+
+gboolean geofence_is_supported(void)
+{
+       GEOFENCE_LOGD("geofence_is_supported");
+
+       gboolean supported = FALSE;
+
+       if (module_is_supported("geofence")) {
+               supported = TRUE;
+       }
+
+       return supported;
+}
+
diff --git a/src/manager/geofence.h b/src/manager/geofence.h
new file mode 100644 (file)
index 0000000..de244fa
--- /dev/null
@@ -0,0 +1,111 @@
+/* Copyright 2014 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.
+ */
+
+
+#ifndef __GEOFENCE_H__
+#define __GEOFENCE_H__
+
+
+#include <glib.h>
+#include "geofence-type-private.h"
+
+G_BEGIN_DECLS
+
+/**
+ * @file geofence.h
+ * @brief This file contains the Geofence API and related structure and enumeration.
+ */
+/**
+ * @defgroup GeofenceFW GeofenceFW
+ * @brief This is a Geofence Framework for providing geofence services.
+ * @addtogroup GeofenceFW
+ * @{
+ * @defgroup GeofenceAPI Geofence API
+ * @brief This sub module provides the Geofence API.
+ * @addtogroup GeofenceAPI
+ * @{
+ */
+
+/**
+ * @brief
+ * Initialize geofence sub module.
+ * @remarks None.
+ * This API should be called before any other Geofence APIs.
+ * @pre None.
+ * @post None.
+ * @return int
+ * @retval 0                              Success
+ *
+ * @see None.
+ */
+int geofence_init(void);
+
+/**
+ * @brief
+ * Create a new #GeofenceObject.
+ * @remarks
+ * Returned object is necessary for other APIs.
+ * @pre
+ * #geofence_init should be called before.
+ * @post None.
+ * @param [in]
+ * method - Geofence method to be used.
+ * @return a new #GeofenceObject
+ * @retval NULL              if error occured
+ * @see geofence_free
+ */
+GeofenceObject *geofence_new(void);
+
+/**
+ * @brief
+ * Free memory of given #GeofenceObject.
+ * @remarks None.
+ * @pre
+ * #geofence_init should be called before.
+ * @post None.
+ * @param [in]
+ * obj - a #GeofenceObject created by #geofence_new.
+ * @return int
+ * @retval 0                              Success.
+ *
+ * @see geofence_new
+ * @par Example
+ * @code
+
+ * @endcode
+ */
+int geofence_free(GeofenceObject *obj);
+
+/**
+ * @brief
+ * Check wheither a method is available.
+ * @remarks
+ * @pre
+ * #geofence_init should be called before.\n
+ * @post None.
+ * @param [in] method - a #GeofenceObject
+ * @return int
+ * @retval True                Supported
+ *        False        Not supported
+ * @par Example
+ * @code
+ * @endcode
+ */
+gboolean geofence_is_supported(void);
+
+G_END_DECLS
+
+#endif /* __GEOFENCE_H__ */
+
diff --git a/src/manager/include/geofence_data_type.h b/src/manager/include/geofence_data_type.h
new file mode 100644 (file)
index 0000000..d94042b
--- /dev/null
@@ -0,0 +1,55 @@
+/* Copyright 2014 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.
+ */
+
+#ifndef __GEOFENCE_DATA_TYPE_H__
+#define __GEOFENCE_DATA_TYPE_H__
+
+#include <geofence_type.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ADDRESS_LEN            64
+#define WLAN_BSSID_LEN         18
+#define WLAN_SSID_LEN  18
+#define PLACE_NAME_LEN 64
+
+/**
+ * @brief The geofence parameter structure
+ */
+typedef struct _geofence_s {
+       geofence_type_e type;
+       double latitude;
+       double longitude;
+       int radius;
+       char address[ADDRESS_LEN];
+       char bssid[WLAN_BSSID_LEN];
+       char ssid[WLAN_SSID_LEN];
+       int place_id;
+} geofence_s;
+
+/**
+ * @brief The geofence place structure
+ */
+typedef struct _place_s {
+       char place_name[PLACE_NAME_LEN];
+} place_s;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __GEOFENCE_DATA_TYPE_H__ */
diff --git a/src/manager/include/geofence_module.h b/src/manager/include/geofence_module.h
new file mode 100644 (file)
index 0000000..0d2512d
--- /dev/null
@@ -0,0 +1,84 @@
+/* Copyright 2014 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.
+ */
+
+#ifndef __GEOFENCE_MODULE_H__
+#define __GEOFENCE_MODULE_H__
+
+#include <geofence_data_type.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @brief This represents a geofence callback function for geofence plug-in.
+ */
+/*typedef void (*GeofenceModGeofenceStatusCB) (gboolean enabled, gpointer userdata); */
+
+/**
+ * @brief This represents a geofence callback function for geofence plug-in.
+ */
+typedef void (*GeofenceModCB)(int fence_id, int state, gpointer userdata);
+
+typedef void (*GeofenceModEventCB)(int place_id, int fence_id, int error, int state, gpointer userdata);
+
+/**
+ * @brief This represents APIs declared in a Geofence plug-in for Geofence modules.
+ */
+typedef struct {
+       int (*create)(void *handle, GeofenceModCB geofence_cb, GeofenceModEventCB geofence_event_cb, void *userdata);
+       int (*destroy)(void *handle);
+       int (*enable_service)(void *handle, int fence_id, bool enable);
+       int (*start_geofence)(void *handle, int fence_id);
+       int (*stop_geofence)(void *handle, int fence_id);
+       int (*add_geopoint)(void *handle, int place_id, double latitude, double longitude, int radius, const char *address, int *fence_id);
+       int (*add_bssid)(void *handle, int place_id, const char *bssid, const char *ssid, geofence_type_e type, int *fence_id);
+       int (*remove_geofence)(void *handle, int fence_id);
+       int (*get_geofences)(void *handle, int place_id, int *fence_amount, int **fence_ids, geofence_s **params);
+
+       int (*add_place)(void *handle, const char *place_name, int *place_id);
+       int (*update_place)(void *handle, int place_id, const char *place_name);
+       int (*remove_place)(void *handle, int place_id);
+       int (*get_place_name)(void *handle, int place_id, char **place_name);
+       int (*get_places)(void *handle, int *place_amount, int **place_ids, place_s **params);
+} GeofenceModOps;
+
+/**
+ * @brief This represents APIs declared in a HW Geofence plug-in for Geofence modules.
+ */
+
+/*
+typedef struct {
+       int (*add_fence)(void *handle, int fence_id, double latitude, double longitude, int radius, int last_state, int monitor_states, int notification_responsiveness, int unknown_timer);
+       int (*delete_fence)(void *handle, int fence_id);
+       int (*pause_fence)(void *handle, int fence_id);
+       int (*resume_fence)(void *handle, int fence_id);
+       int (*set_callback)(void *handle, LocModGeofenceStatusCB status_cb, LocModGeofenceCB geofence_cb, void *userdata);
+       int (*unset_callback)(void *handle);
+} LocModGpsGeofenceOps;
+*/
+
+/**
+ * @brief This is used for exported APIs in a plug-in for a geofence framework.
+ */
+#define GEOFENCE_MODULE_API __attribute__((visibility("default"))) G_MODULE_EXPORT
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/manager/module-internal.c b/src/manager/module-internal.c
new file mode 100644 (file)
index 0000000..8dd8238
--- /dev/null
@@ -0,0 +1,242 @@
+/* Copyright 2014 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.
+ */
+
+#include <glib.h>
+#include <stdio.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include "geofence-log.h"
+#include "module-internal.h"
+
+#define MAX_MODULE_INDEX 4
+const char *MODULE_PATH_PREFIX = "/usr/lib/geofence/module";
+
+static GMod *gmod_new(const char *module_name, gboolean is_resident)
+{
+       if (!module_name)
+               return NULL;
+
+       GMod *gmod = g_new0(GMod, 1);
+       gmod->name = g_strdup(module_name);
+       if (!gmod->name) {
+               g_free(gmod);
+               return NULL;
+       }
+       gmod->path = g_module_build_path(MODULE_PATH_PREFIX, gmod->name);
+
+       if (!gmod->path) {
+               g_free(gmod->name);
+               g_free(gmod);
+               return NULL;
+       }
+       gmod->module = g_module_open(gmod->path, G_MODULE_BIND_LAZY);
+       if (!gmod->module) {
+               g_free(gmod->name);
+               g_free(gmod->path);
+               g_free(gmod);
+               return NULL;
+       }
+       if (is_resident)
+               g_module_make_resident(gmod->module);
+
+       return gmod;
+}
+
+static void gmod_free(GMod *gmod)
+{
+       if (gmod->name)
+               g_free(gmod->name);
+       if (gmod->path)
+               g_free(gmod->path);
+       if (gmod->module)
+               g_module_close(gmod->module);
+       g_free(gmod);
+}
+
+static gboolean gmod_find_sym(GMod *gmod, gpointer *init_func, gpointer *shutdown_func)
+{
+       char sym[256];
+       g_stpcpy(sym, "init");
+       if (!g_module_symbol(gmod->module, sym, init_func)) {
+               GEOFENCE_LOGW("symbol not found: %s", sym);
+               return FALSE;
+       }
+       g_stpcpy(sym, "shutdown");
+       if (!g_module_symbol(gmod->module, sym, shutdown_func)) {
+               GEOFENCE_LOGW("symbol not found: %s", sym);
+               return FALSE;
+       }
+       return TRUE;
+}
+
+static gpointer mod_new(const char *module_name)
+{
+       gpointer ret_mod = NULL;
+       if (!module_name)
+               return NULL;
+
+       GMod *gmod = NULL;
+       gpointer init = NULL;
+       gpointer shutdown = NULL;
+       gmod = gmod_new(module_name, TRUE);
+       if (!gmod) {
+               GEOFENCE_LOGW("module(%s) new failed", module_name);
+               return NULL;
+       }
+       if (!gmod_find_sym(gmod, &init, &shutdown)) {
+               GEOFENCE_LOGW("symbol (init, shutdown) finding failed");
+               gmod_free(gmod);
+               return NULL;
+       }
+       if (!init || !shutdown) {
+               GEOFENCE_LOGW("init, shutdown symbol is NULL");
+               gmod_free(gmod);
+               return NULL;
+       }
+       if (g_str_has_prefix(module_name, "geofence")) {
+               GeofenceInternalMod *_mod = g_new0(GeofenceInternalMod, 1);
+               _mod->gmod = gmod;
+               _mod->init = init;
+               _mod->shutdown = shutdown;
+               _mod->handler = _mod->init(&(_mod->ops));
+               if (!_mod->handler) {
+                       GEOFENCE_LOGW("module init failed");
+                       gmod_free(_mod->gmod);
+                       ret_mod = NULL;
+               } else
+                       ret_mod = (gpointer) _mod;
+       } else {
+               GEOFENCE_LOGW("module name (%s) is wrong", module_name);
+               ret_mod = NULL;
+       }
+       return ret_mod;
+}
+
+static void mod_free(gpointer mod, const char *module_name)
+{
+       if (!mod || !module_name)
+               return;
+
+       if (0 == g_strcmp0(module_name, "geofence")) {
+               GeofenceInternalMod *_mod = (GeofenceInternalMod *) mod;
+               if (_mod->shutdown && _mod->handler) {
+                       _mod->shutdown(_mod->handler);
+               }
+               _mod->handler = NULL;
+               _mod->init = NULL;
+               _mod->shutdown = NULL;
+               gmod_free(_mod->gmod);
+               _mod->gmod = NULL;
+       } else
+               GEOFENCE_LOGW("module name (%s) is wrong", module_name);
+
+       g_free(mod);
+}
+
+static gboolean mod_is_supported(const char *module_name)
+{
+       GMod *gmod = NULL;
+       gmod = gmod_new(module_name, FALSE);
+       if (!gmod) {
+               return FALSE;
+       }
+       gmod_free(gmod);
+
+       return TRUE;
+}
+
+gboolean module_init(void)
+{
+       if (!g_module_supported()) {
+               GEOFENCE_LOGW("module is not supported");
+               return FALSE;
+       }
+       return TRUE;
+}
+
+void module_free(gpointer mod, const char *module_name)
+{
+       if (!mod || !module_name)
+               return;
+       mod_free(mod, module_name);
+}
+
+GeofenceInternalMod *module_new(const char *module_name)
+{
+       if (!module_name)
+               return NULL;
+
+       char name[256];
+
+       gpointer mod = NULL;
+       if (0 >= g_snprintf(name, 256, "%s", module_name)) {
+               GEOFENCE_LOGW("module name(%s) is wrong", name);
+       }
+       mod = mod_new(name);
+       if (mod) {
+               GEOFENCE_LOGW("module (%s) open success", name);
+       } else {
+               GEOFENCE_LOGW("module (%s) open failed", name);
+       }
+       return mod;
+}
+
+gboolean module_is_supported(const char *module_name)
+{
+       if (!module_name)
+               return FALSE;
+
+       int index = 0;
+       gboolean ret = FALSE;
+       gboolean found = FALSE;
+
+       char name[256] = { 0, };
+
+       for (index = -1; index < MAX_MODULE_INDEX; index++) {
+               if (index >= 0) {
+                       g_snprintf(name, 256, "%s%d", module_name, index);
+               } else {
+                       g_snprintf(name, 256, "%s", module_name);
+               }
+
+               ret = mod_is_supported(name);
+               if (ret == TRUE) {
+                       found = TRUE;
+                       GEOFENCE_LOGW("module name(%s) is found", name);
+                       break;
+               }
+       }
+
+       return found;
+}
+
+gchar *mod_get_realpath(const gchar *module_name)
+{
+       gchar link_path[PATH_MAX] = { 0, };
+       gchar *path = NULL;
+
+       snprintf(link_path, PATH_MAX, "%s/lib%s.so", MODULE_PATH_PREFIX, module_name);
+       if (strlen(link_path) == 0) {
+               GEOFENCE_LOGE("Fail to get real path of [%s]", module_name);
+               return NULL;
+       }
+
+       path = strrchr(link_path, '/');
+       if (!path)
+               return NULL;
+
+       return g_strdup(path);
+}
diff --git a/src/manager/module-internal.h b/src/manager/module-internal.h
new file mode 100644 (file)
index 0000000..2a502a9
--- /dev/null
@@ -0,0 +1,51 @@
+/* Copyright 2014 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.
+ */
+
+#ifndef __MODULE_INTERNAL_H__
+#define __MODULE_INTERNAL_H__
+
+#include <gmodule.h>
+#include "geofence_module.h"
+
+/**
+ * @file module-internal.h
+ * @brief This file contains the internal definitions and structures related to module.
+ */
+
+G_BEGIN_DECLS
+
+typedef struct {
+       GModule *module;
+       char *name;
+       char *path;
+} GMod;
+
+typedef struct {
+       GMod *gmod;
+       gpointer handler;
+       gpointer(*init)(GeofenceModOps *ops);
+       void (*shutdown)(gpointer handle);
+       GeofenceModOps ops;
+} GeofenceInternalMod;
+
+gboolean module_init(void);
+GeofenceInternalMod *module_new(const char *module_name);
+void module_free(gpointer mod, const char *module_name);
+gboolean module_is_supported(const char *module_name);
+gchar *mod_get_realpath(const gchar *module_name);
+
+G_END_DECLS
+
+#endif