summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjongmun Woo <jongmun.woo@samsung.com>2015-06-12 11:53:59 (GMT)
committerjongmun Woo <jongmun.woo@samsung.com>2015-06-12 12:00:58 (GMT)
commit12f904740fa3322f9fd472f1f04c3141d55bd29b (patch)
tree5921d0812f89b2fbb1f1766cabdde027dbf9b5d0
parent47368947d9e679e6af929c1eb03e131219d40953 (diff)
downloadgeofence-dbus-12f904740fa3322f9fd472f1f04c3141d55bd29b.zip
geofence-dbus-12f904740fa3322f9fd472f1f04c3141d55bd29b.tar.gz
geofence-dbus-12f904740fa3322f9fd472f1f04c3141d55bd29b.tar.bz2
2.To support 64bit arch Signed-off-by: jongmun Woo <jongmun.woo@samsung.com> Change-Id: I19c500b322f38b7f82ac53d8ba99f42a83506251
-rw-r--r--AUTHORS5
-rw-r--r--CMakeLists.txt47
-rw-r--r--LICENSE204
-rw-r--r--geofence-dbus.pc.in11
-rw-r--r--geofence/CMakeLists.txt16
-rw-r--r--geofence/include/geofence_client.h223
-rw-r--r--geofence/include/geofence_client_priv.h44
-rw-r--r--geofence/src/geofence_client.c799
-rw-r--r--introspection/gen.sh8
-rw-r--r--introspection/geofence.xml80
-rw-r--r--libgeofence-dbus.manifest5
-rw-r--r--packaging/geofence-dbus.spec81
-rw-r--r--server/CMakeLists.txt27
-rw-r--r--server/include/geofence_dbus_server.h149
-rw-r--r--server/include/geofence_dbus_server_priv.h44
-rw-r--r--server/res/geofence-dbus-server.conf128
-rw-r--r--server/src/geofence_dbus_server.c620
17 files changed, 2491 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..0bc9dd3
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,5 @@
+Woo-Young Kim <woo02.kim@samsung.com>
+Bono Koo <mw.koo@samsung.com>
+Ki-Sun SHIN <kisun47.shin@samsung.com>
+bosung kwak <bosung.kwak@samsung.com>
+Areum Choi <arumi.choi@samsung.com> \ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..c465b9d
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,47 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(geofence-dbus C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR ${LIBDIR})
+SET(INCLUDEDIR "\${prefix}/include")
+
+# Set required packages
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED glib-2.0 gio-2.0 gthread-2.0 dlog gobject-2.0 gio-unix-2.0 capi-appfw-app-manager capi-appfw-package-manager pkgmgr-info)
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs -fvisibility=hidden ")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wextra -fvisibility=hidden -fPIC")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter -Wno-missing-field-initializers -Wmissing-declarations -Wcast-align")
+
+ADD_DEFINITIONS("-DFEATURE_DLOG_DEBUG")
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DLIBDIR=\"${LIBDIR}\"")
+ADD_DEFINITIONS(" -DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\" ")
+
+IF ( ENABLE_DOCOMO_LOCATION )
+ ADD_DEFINITIONS("-DDOCOMO_FEATURE")
+ENDIF ( ENABLE_DOCOMO_LOCATION )
+
+MESSAGE(${CMAKE_C_FLAGS})
+MESSAGE(${CMAKE_EXE_LINKER_FLAGS})
+
+# pkgconfig file
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(LIBDIR ${LIBDIR})
+
+CONFIGURE_FILE(geofence-dbus.pc.in geofence-dbus.pc @ONLY)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/geofence-dbus.pc DESTINATION ${LIBDIR}/pkgconfig)
+
+#INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME libgeofence-dbus)
+
+ADD_SUBDIRECTORY(server)
+ADD_SUBDIRECTORY(geofence)
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..a06208b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,204 @@
+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/geofence-dbus.pc.in b/geofence-dbus.pc.in
new file mode 100644
index 0000000..6dd5102
--- /dev/null
+++ b/geofence-dbus.pc.in
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+
+Name: GEOFENCE dbus Library
+Description: GEOFENCE dbus library
+Requires: glib-2.0 gobject-2.0
+Version: 0.1
+Libs: -L${libdir} -lgeofence-dbus-server -lgeofence-dbus-client
+Cflags: -I${includedir}/geofence-dbus
diff --git a/geofence/CMakeLists.txt b/geofence/CMakeLists.txt
new file mode 100644
index 0000000..b450254
--- /dev/null
+++ b/geofence/CMakeLists.txt
@@ -0,0 +1,16 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(geofence-dbus-client C)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+### Build ###
+SET(SRCS
+ src/geofence_client.c
+)
+
+ADD_LIBRARY(geofence-dbus-client SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(geofence-dbus-client ${pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(geofence-dbus-client PROPERTIES VERSION 0.1.0 SOVERSION 0 OUTPUT_NAME geofence-dbus-client)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/geofence_client.h DESTINATION include/geofence-dbus)
+INSTALL(TARGETS geofence-dbus-client DESTINATION ${LIBDIR} COMPONENT Runtime)
diff --git a/geofence/include/geofence_client.h b/geofence/include/geofence_client.h
new file mode 100644
index 0000000..a5f85a5
--- /dev/null
+++ b/geofence/include/geofence_client.h
@@ -0,0 +1,223 @@
+/* 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.
+ */
+
+/**
+ * @file geofence_client.h
+ * @brief This file contains the internal definitions and structures related to geofence client.
+ */
+#ifndef __GEOFENCE_CLIENT_H__
+#define __GEOFENCE_CLIENT_H__
+
+__BEGIN_DECLS
+#include <gio/gio.h>
+typedef enum {
+ GEOFENCE_STATUS_CB = 0x01,
+ GEOFENCE_INOUT_CB = GEOFENCE_STATUS_CB << 0x01,
+} geofence_client_callback_e;
+
+typedef enum {
+ GEOFENCE_CLIENT_ERROR_NONE = 0x0,
+ GEOFENCE_CLIENT_ERROR_UNKNOWN,
+ GEOFENCE_CLIENT_ERROR_PARAMETER,
+ GEOFENCE_CLIENT_ERROR_MEMORY,
+ GEOFENCE_CLIENT_ERROR_CONNECTION,
+ GEOFENCE_CLIENT_ERROR_STATUS,
+ GEOFENCE_CLIENT_ERROR_DBUS_CALL,
+ GEOFENCE_CLIENT_ERROR_NO_RESULT,
+ GEOFENCE_CLIENT_ACCESS_DENIED
+} geofence_client_error_e;
+
+typedef void *geofence_client_dbus_h;
+
+/**
+* @brief Callback registered by the client to get the callback for the geofence in/out status
+*/
+typedef void (*geofence_client_cb) (const char *sig, GVariant *param, void *user_data);
+
+/**
+* @brief Callback registered by the client to get the callback for the geofence event status
+*/
+typedef void (*geofence_client_event_cb) (const char *sig, GVariant *param, void *user_data);
+
+/**
+* @brief API to add the geofence. This will call the server API.
+* @param[in] geofence_client - Client dbus handle
+* @param[in] latitude - latitude value if is a geopoint geofence
+* @param[in] longitude - longitude value if it is a geopint geofence
+* @param[in] radius - radius value if it is a geopoint geofence
+* @param[in] bssid - bssid value if it is a wifi/BT geofence
+* @return int
+* @retval returns the fence-id of the geofence added
+* @see geo_client_delete_geofence
+*/
+int geo_client_add_geofence(geofence_client_dbus_h geofence_client, gint place_id, gint geofence_type, gdouble latitude, gdouble longitude, gint radius, const gchar *address, const gchar *bssid, const gchar *ssid);
+
+/**
+* @brief API to add the place. This will call the server API
+* @param[in] geofence_client - Client dbus handle
+* @param[in] place_name - Name of the place
+* retval returns the place_id of the place added
+* @see geo_client_delete_place
+*/
+int geo_client_add_place(geofence_client_dbus_h geofence_client, const gchar *place_name);
+
+/**
+* @brief API to enable the geofence. This will call the server API
+* @param[in] geofence_client - Client dbus handle
+* @param[in] fence_id - Unique id of the fence
+* @param[in] bEnable - enable flag for geofence
+*/
+int geo_client_enable_service(geofence_client_dbus_h geofence_client, gint geofence_id, gboolean bEnable);
+
+/**
+* @brief API to update the place. This will call the server API
+* @param[in] geofence_client - Client dbus handle
+* @param[in] place_id - Unique id of the place
+* @param[in] place_name - Name of the place[may be a new value]
+* @return int
+* @retval GEOFENCE_CLIENT_ERROR_NONE if success
+ GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure
+* @see geo_client_add_place
+*/
+int geo_client_update_place(geofence_client_dbus_h geofence_client, gint place_id, const gchar *place_name);
+
+/**
+* @brief API to delete the geofence from the server
+* @param[in] geofence_client - Client dbus handle
+* @param[in] fence-id - Fence ID of the fence which needs to be deleted
+* @return int
+* @retval GEOFENCE_CLIENT_ERROR_NONE if success
+ GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure
+* @see geo_client_add_geofence
+*/
+int geo_client_delete_geofence(geofence_client_dbus_h geofence_client, gint fence_id);
+
+/**
+* @brief API to delete the place from the server
+* @param[in] geofence_client - Client dbus handle
+* @param[in] place_id - Place ID of the place which needs to be deleted
+* @return int
+* @retval GEOFENCE_CLIENT_ERROR_NONE if success
+ GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure
+* @see geo_client_add_place
+*/
+int geo_client_delete_place(geofence_client_dbus_h geofence_client, gint place_id);
+
+/**
+* @brief API to get the place name
+* @param[in] geofence_client - Client dbus handle
+* @param[in] place_id - Place ID of the place whose name should be retrieved
+* @param[out] place_name - Name of the place
+* @param[out] error_code - Error that has occured on the server side
+* @return GEOFENCE_CLIENT_ERROR_NONE if success
+ GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure
+*/
+int geo_client_get_place_name(geofence_client_dbus_h geofence_client, gint place_id, char **placeName, int *errorCode);
+
+/**
+* @brief API to get the fence list
+* @param[in] geofence_client - Client dbus handle
+* @param[in] place_id - ID of the place whose list has to be retrived
+* @param[out] iter - iterator for the array of fences
+* @param[out] fenceCnt - total count of the fence
+* @param[out] errorCode - error code for the api
+* @return int
+* @retval GEOFENCE_CLIENT_ERROR_NONE if success
+ GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure
+*/
+int geo_client_get_list(geofence_client_dbus_h geofence_client, int place_id, GVariantIter **iter, gint *fenceCnt, int *errorCode);
+
+/**
+* @brief API to get the place list
+* @param[in] geofence_client - Client dbus handle
+* @param[out] iter - iterator for the array of fences
+* @param[out] placeCnt - total count of the fence
+* @param[out] errorCode - error code for the API
+* @return int
+* @retval GEOFENCE_CLIENT_ERROR_NONE if success
+ GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure
+*/
+int geo_client_get_place_list(geofence_client_dbus_h geofence_client, GVariantIter **iter, gint *fenceCnt, int *errorCode);
+
+/**
+* @brief API to start the geofence service on a particular geofence
+* @param[in] geofence_client - Client dbus handle
+* @param[in] fence-id - Fence ID of the fence for which geofence service should be started
+* @return int
+* @retval GEOFENCE_CLIENT_ERROR_NONE if success
+ GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure
+* @see geo_client_stop_geofence
+*/
+int geo_client_start_geofence(geofence_client_dbus_h geofence_client, gint fence_id);
+
+/**
+* @brief API to stop the geofence service on a particular geofence
+* @param[in] geofence_client - Client dbus handle
+* @param[in] fence-id - Fence ID of the fence for which geofence service should be stopped
+* @return int
+* @retval GEOFENCE_CLIENT_ERROR_NONE if success
+ GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure
+* @see geo_client_start_geofence
+*/
+int geo_client_stop_geofence(geofence_client_dbus_h geofence_client, gint fence_id);
+
+/**
+* @brief API to start the client and make a subscription to the server
+* @param[in] service_name - Name of the service required by the client
+* @param[in] service_path - Path of the service for dbus connection
+* @param[in] geofence_client - Client dbus handle
+* @param[in] callback - callback registered by the client
+* @param[in] user_data - Data that has to come back in the callback
+* @return int
+* @retval GEOFENCE_CLIENT_ERROR_NONE - if success
+ GEOFENCE_CLIENT_ACCESS_DENIED - if failure
+ GEOFENCE_CLIENT_ERROR_DBUS_CALL - if failure
+* @see geo_client_stop
+*/
+int geo_client_start(char *service_name, char *service_path, geofence_client_dbus_h *geofence_client, geofence_client_cb callback, geofence_client_event_cb evt_callback, void *user_data);
+
+/**
+* @brief API to stop the client and remove the subscription to the server
+* @param[in] geofence_client - Client dbus handle
+* @return int
+* @retval GEOFENCE_CLIENT_ERROR_NONE - if success
+ GEOFENCE_CLIENT_ACCESS_DENIED - if failure
+ GEOFENCE_CLIENT_ERROR_DBUS_CALL - if failure
+* @see geo_client_start
+*/
+int geo_client_stop(geofence_client_dbus_h *geofence_client);
+
+/**
+* @brief API to create the connection with the server
+* @param[in] geofence_client - Client dbus handle
+* @return int
+* @retval GEOFENCE_CLIENT_ERROR_NONE - if success
+ GEOFENCE_CLIENT_ERROR_CONNECTION - if failure
+* @see geo_client_destroy
+*/
+int geo_client_create(geofence_client_dbus_h *geofence_client);
+
+/**
+* @brief API to destroy the connection with the server
+* @param[in] geofence_client - Client dbus handle
+* @return int
+* @retval GEOFENCE_CLIENT_ERROR_NONE - if success
+ GEOFENCE_CLIENT_ERROR_CONNECTION - if failure
+* @see geo_client_create
+*/
+int geo_client_destroy(geofence_client_dbus_h geofence_client);
+
+__END_DECLS
+#endif /* __GEOFENCE_CLIENT_H__ */
diff --git a/geofence/include/geofence_client_priv.h b/geofence/include/geofence_client_priv.h
new file mode 100644
index 0000000..ec0b7b2
--- /dev/null
+++ b/geofence/include/geofence_client_priv.h
@@ -0,0 +1,44 @@
+/* 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.
+ */
+
+/**
+ * @file geofence_client_priv.h
+ * @brief This file contains the log tags for the geofence client.
+ */
+
+#ifndef __GEOFENCE_CLIENT_PRIV_H__
+#define __GEOFENCE_CLIENT_PRIV_H__
+
+__BEGIN_DECLS
+#ifdef FEATURE_DLOG_DEBUG
+#include <dlog.h>
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "GEOFENCE_DBUS_CLIENT"
+#endif
+#define GEOFENCE_CLIENT_LOGI(fmt, args...) { LOGI(fmt, ##args); }
+#define GEOFENCE_CLIENT_LOGD(fmt, args...) { LOGD(fmt, ##args); }
+#define GEOFENCE_CLIENT_LOGW(fmt, args...) { LOGW(fmt, ##args); }
+#define GEOFENCE_CLIENT_LOGE(fmt, args...) { LOGE(fmt, ##args); }
+#define GEOFENCE_CLIENT_SECLOG(fmt, args...) SECURE_LOGW(fmt, ##args)
+#else
+#define GEOFENCE_CLIENT_LOGI(fmt, args...)
+#define GEOFENCE_CLIENT_LOGD(fmt, args...)
+#define GEOFENCE_CLIENT_LOGW(fmt, args...)
+#define GEOFENCE_CLIENT_LOGE(fmt, args...)
+#define GEOFENCE_CLIENT_SECLOG(fmt, args...)
+#endif
+ __END_DECLS
+#endif /* __GEOFENCE_CLIENT_PRIV_H__ */
diff --git a/geofence/src/geofence_client.c b/geofence/src/geofence_client.c
new file mode 100644
index 0000000..30f6203
--- /dev/null
+++ b/geofence/src/geofence_client.c
@@ -0,0 +1,799 @@
+/* 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 <app_manager.h>
+#include "geofence_client.h"
+#include "geofence_client_priv.h"
+
+typedef struct _geofence_client_dbus_s {
+ GDBusConnection *conn;
+ gchar *service_name;
+ gchar *service_path;
+ int geofence_evt_id;
+ int geofence_evt_status_id;
+ int geofence_id;
+ geofence_client_cb user_cb;
+ geofence_client_event_cb user_event_cb;
+ void *user_data;
+} geofence_client_dbus_s;
+
+static void __geofence_signal_callback(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data)
+{
+ GEOFENCE_CLIENT_SECLOG("name : %s, path : %s, interface : %s, sig : %s, handle[%p]", name, path, interface, sig, user_data);
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *) user_data;
+ if (handle == NULL) {
+ GEOFENCE_CLIENT_LOGD("Invalid handle");
+ return;
+ }
+ if (handle->user_cb)
+ handle->user_cb(sig, param, handle->user_data);
+}
+
+EXPORT_API int geo_client_add_geofence(geofence_client_dbus_h geofence_client, gint place_id, gint geofence_type, gdouble latitude, gdouble longitude, gint radius, const gchar *address, const gchar *bssid, const gchar *ssid)
+{
+ /* add fence interface between App & geofence-server */
+ GEOFENCE_CLIENT_LOGD("geo_client_add_fence");
+ g_return_val_if_fail(geofence_client, 0);
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;
+
+ GVariant *reg = NULL;
+ GError *error = NULL;
+ GDBusProxy *proxy = NULL;
+ gchar *app_id = NULL;
+ gint fence_id = -1;
+ pid_t pid = 0;
+
+ GEOFENCE_CLIENT_LOGI("Getting the app id in client");
+ pid = getpid();
+ int ret = app_manager_get_app_id(pid, &app_id);
+
+ if (ret != APP_MANAGER_ERROR_NONE)
+ GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret);
+
+ GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id);
+ gchar *signal_path = NULL;
+ signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG");
+ GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path);
+
+ proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error);
+ g_free(signal_path);
+
+ if (proxy) {
+ GEOFENCE_CLIENT_LOGD(" proxy exited !");
+ reg = g_dbus_proxy_call_sync(proxy, "AddGeofence", g_variant_new("(siiddisss)", app_id, place_id, geofence_type, latitude, longitude, radius, address, bssid, ssid), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (reg) {
+ g_variant_get(reg, "(i)", &fence_id);
+ g_variant_unref(reg);
+ reg = NULL;
+ } else {
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to add geofence Error[%s]", error->message);
+ g_error_free(error);
+ }
+ }
+ g_object_unref(proxy);
+ } else {
+ GEOFENCE_CLIENT_LOGD(" proxy NOT exited !");
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message);
+ g_error_free(error);
+ }
+ }
+
+ if (app_id)
+ g_free(app_id);
+
+ return fence_id;
+}
+
+EXPORT_API int geo_client_add_place(geofence_client_dbus_h geofence_client, const gchar *place_name)
+{
+ /* add fence interface between App & geofence-server */
+ GEOFENCE_CLIENT_LOGD("geo_client_add_place");
+ g_return_val_if_fail(geofence_client, 0);
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;
+
+ GVariant *reg = NULL;
+ GError *error = NULL;
+ GDBusProxy *proxy = NULL;
+ gchar *app_id = NULL;
+ int place_id = -1;
+ pid_t pid = 0;
+
+ GEOFENCE_CLIENT_LOGI("Getting the app id in client");
+ pid = getpid();
+ int ret = app_manager_get_app_id(pid, &app_id);
+
+ if (ret != APP_MANAGER_ERROR_NONE)
+ GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret);
+
+ GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id);
+ gchar *signal_path = NULL;
+ signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG");
+ GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path);
+
+ proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error);
+ g_free(signal_path);
+
+ if (proxy) {
+ GEOFENCE_CLIENT_LOGD(" proxy exited !");
+ reg = g_dbus_proxy_call_sync(proxy, "AddPlace", g_variant_new("(ss)", app_id, place_name), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (reg) {
+ g_variant_get(reg, "(i)", &place_id);
+ g_variant_unref(reg);
+ reg = NULL;
+ } else {
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to add place Error[%s]", error->message);
+ g_error_free(error);
+ }
+ }
+ g_object_unref(proxy);
+ } else {
+ GEOFENCE_CLIENT_LOGD(" proxy NOT exited !");
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message);
+ g_error_free(error);
+ }
+ }
+ if (app_id)
+ g_free(app_id);
+
+ return place_id;
+}
+
+EXPORT_API int geo_client_update_place(geofence_client_dbus_h geofence_client, gint place_id, const gchar *place_name)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_update_place");
+ g_return_val_if_fail(geofence_client, 0);
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;
+
+ GError *error = NULL;
+ GDBusProxy *proxy = NULL;
+ gchar *app_id = NULL;
+ pid_t pid = 0;
+
+ GEOFENCE_CLIENT_LOGI("Getting the app id in client");
+ pid = getpid();
+ int ret = app_manager_get_app_id(pid, &app_id);
+ if (ret != APP_MANAGER_ERROR_NONE)
+ GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret);
+ GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id);
+
+ ret = GEOFENCE_CLIENT_ERROR_NONE;
+ gchar *signal_path = NULL;
+ signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG");
+ GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path);
+
+ proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error);
+ g_free(signal_path);
+
+ if (proxy) {
+ GEOFENCE_CLIENT_LOGD(" proxy exited !");
+ g_dbus_proxy_call(proxy, "UpdatePlace", g_variant_new("(iss)", place_id, app_id, place_name), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error);
+ } else {
+ GEOFENCE_CLIENT_LOGD(" proxy NOT exited !");
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message);
+ g_error_free(error);
+ ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL;
+ }
+ }
+ if (app_id)
+ g_free(app_id);
+
+ return ret;
+}
+
+EXPORT_API int geo_client_delete_geofence(geofence_client_dbus_h geofence_client, gint fence_id)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_delete_geofence");
+ g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER);
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *) geofence_client;
+
+ GError *error = NULL;
+ GDBusProxy *proxy = NULL;
+ gchar *app_id = NULL;
+ int ret = GEOFENCE_CLIENT_ERROR_NONE;
+ pid_t pid = 0;
+
+ GEOFENCE_CLIENT_LOGI("Getting the app id in client");
+ pid = getpid();
+ ret = app_manager_get_app_id(pid, &app_id);
+
+ if (ret != APP_MANAGER_ERROR_NONE)
+ GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret);
+
+ GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id);
+
+ gchar *signal_path = NULL;
+ signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG");
+ GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path);
+
+ proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error);
+ g_free(signal_path);
+
+ if (proxy) {
+ g_dbus_proxy_call(proxy, "DeleteGeofence", g_variant_new("(is)", fence_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error);
+ } else {
+ GEOFENCE_CLIENT_LOGD(" proxy NOT exited !");
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message);
+ g_error_free(error);
+ ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL;
+ }
+ }
+ if (app_id)
+ g_free(app_id);
+
+ return ret;
+}
+
+EXPORT_API int geo_client_delete_place(geofence_client_dbus_h geofence_client, gint place_id)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_delete_place");
+ g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER);
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;
+
+ GError *error = NULL;
+ GDBusProxy *proxy = NULL;
+ gchar *app_id = NULL;
+ int ret = GEOFENCE_CLIENT_ERROR_NONE;
+ pid_t pid = 0;
+
+ GEOFENCE_CLIENT_LOGI("Getting the app id in client");
+ pid = getpid();
+ ret = app_manager_get_app_id(pid, &app_id);
+
+ if (ret != APP_MANAGER_ERROR_NONE)
+ GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret);
+
+ GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id);
+
+ gchar *signal_path = NULL;
+ signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG");
+ GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path);
+
+ proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error);
+ g_free(signal_path);
+ if (proxy) {
+ g_dbus_proxy_call(proxy, "DeletePlace", g_variant_new("(is)", place_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error);
+ } else {
+ GEOFENCE_CLIENT_LOGD(" proxy NOT exited !");
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message);
+ g_error_free(error);
+ ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL;
+ }
+ }
+ if (app_id)
+ g_free(app_id);
+
+ return ret;
+}
+
+EXPORT_API int geo_client_enable_service(geofence_client_dbus_h geofence_client, gint geofence_id, gboolean bEnable)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_enable_geofence, id(%d)", geofence_id);
+ g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER);
+
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;
+
+ GError *error = NULL;
+ GDBusProxy *proxy = NULL;
+ gchar *app_id = NULL;
+ int ret = GEOFENCE_CLIENT_ERROR_NONE;
+ gchar *signal_path = NULL;
+ pid_t pid = 0;
+ gboolean enable = bEnable;
+
+ GEOFENCE_CLIENT_LOGI("Getting the app id in client");
+ pid = getpid();
+ ret = app_manager_get_app_id(pid, &app_id);
+
+ if (ret != APP_MANAGER_ERROR_NONE)
+ GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret);
+
+ GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id);
+
+ signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG");
+ GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path);
+
+ GEOFENCE_CLIENT_LOGD("handle->user_cb : %x", handle->user_cb);
+
+ /* Start geofence */
+ proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error);
+ g_free(signal_path);
+
+ if (proxy) {
+ g_dbus_proxy_call(proxy, "EnableGeofence", g_variant_new("(isb)", geofence_id, app_id, enable), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error);
+ } else {
+ GEOFENCE_CLIENT_LOGD(" proxy NOT exited !");
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message);
+ g_error_free(error);
+ ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL;
+ }
+ }
+ if (app_id)
+ g_free(app_id);
+
+ return ret;
+}
+
+EXPORT_API int geo_client_start_geofence(geofence_client_dbus_h geofence_client, int geofence_id)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_start_geofence, id(%d)", geofence_id);
+ g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER);
+
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;
+
+ GError *error = NULL;
+ GDBusProxy *proxy = NULL;
+ gchar *app_id = NULL;
+ int ret = GEOFENCE_CLIENT_ERROR_NONE;
+ gchar *signal_path = NULL;
+ pid_t pid = 0;
+
+ GEOFENCE_CLIENT_LOGI("Getting the app id in client");
+ pid = getpid();
+ ret = app_manager_get_app_id(pid, &app_id);
+
+ if (ret != APP_MANAGER_ERROR_NONE)
+ GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret);
+
+ GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id);
+
+ signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG");
+ GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path);
+
+ GEOFENCE_CLIENT_LOGD("handle->user_cb : %x", handle->user_cb);
+
+ /* Start geofence */
+ proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error);
+ g_free(signal_path);
+
+ if (proxy) {
+ g_dbus_proxy_call(proxy, "StartGeofence", g_variant_new("(is)", geofence_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error);
+ } else {
+ GEOFENCE_CLIENT_LOGD(" proxy NOT exited !");
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message);
+ g_error_free(error);
+ ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL;
+ }
+ }
+ if (app_id)
+ g_free(app_id);
+
+ return ret;
+}
+
+EXPORT_API int geo_client_stop_geofence(geofence_client_dbus_h geofence_client, int geofence_id)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_stop_geofence");
+
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;
+ g_return_val_if_fail(handle, GEOFENCE_CLIENT_ERROR_PARAMETER);
+
+ int ret = GEOFENCE_CLIENT_ERROR_NONE;
+ GError *error = NULL;
+ gchar *app_id = NULL;
+ pid_t pid = 0;
+
+ GEOFENCE_CLIENT_LOGI("Getting the app id in client");
+ pid = getpid();
+ ret = app_manager_get_app_id(pid, &app_id);
+
+ if (ret != APP_MANAGER_ERROR_NONE)
+ GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret);
+
+ GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id);
+ GEOFENCE_CLIENT_LOGD("handle->user_cb : %x", handle->user_cb);
+
+ gchar *signal_path = NULL;
+ signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG");
+ GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path);
+
+ /* Stop*/
+ GDBusProxy *proxy = NULL;
+ GEOFENCE_CLIENT_LOGD("handle->conn: %p", handle->conn);
+ proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error);
+ g_free(signal_path);
+
+ if (proxy) {
+ g_dbus_proxy_call(proxy, "StopGeofence", g_variant_new("(is)", geofence_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error);
+ } else {
+ GEOFENCE_CLIENT_LOGD(" proxy NOT exited !");
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message);
+ g_error_free(error);
+ ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL;
+ }
+ }
+ if (app_id)
+ g_free(app_id);
+
+ return ret;
+}
+
+EXPORT_API int geo_client_get_place_name(geofence_client_dbus_h geofence_client, int place_id, char **placeName, int *errorCode)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_get_place_name");
+ g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER);
+
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;
+
+ GVariant *reg = NULL;
+ GError *error = NULL;
+ GDBusProxy *proxy = NULL;
+ gchar *app_id = NULL;
+ int ret = GEOFENCE_CLIENT_ERROR_NONE;
+ gchar *signal_path = NULL;
+ pid_t pid = 0;
+ char *place_name = NULL;
+ int error_code = -1;
+
+ GEOFENCE_CLIENT_LOGI("Getting the app id in client");
+ pid = getpid();
+ ret = app_manager_get_app_id(pid, &app_id);
+
+ if (ret != APP_MANAGER_ERROR_NONE)
+ GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret);
+
+ GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id);
+
+ signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG");
+ GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path);
+
+ GEOFENCE_CLIENT_LOGD("handle->user_cb : %x", handle->user_cb);
+ /* Start geofence */
+ proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error);
+ g_free(signal_path);
+
+ if (proxy) {
+ reg = g_dbus_proxy_call_sync(proxy, "GetPlaceName", g_variant_new("(is)", place_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (reg) {
+ g_variant_get(reg, "(is)", &error_code, &place_name);
+ *errorCode = error_code;
+ *placeName = strdup(place_name);
+ if (place_name)
+ g_free(place_name);
+ g_variant_unref(reg);
+ } else {
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get the place name Error[%s]", error->message);
+ g_error_free(error);
+ ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL;
+ }
+ }
+ g_object_unref(proxy);
+ } else {
+ GEOFENCE_CLIENT_LOGD(" proxy NOT exited !");
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message);
+ g_error_free(error);
+ ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL;
+ }
+ }
+
+ if (app_id)
+ g_free(app_id);
+
+ return ret;
+}
+
+EXPORT_API int geo_client_get_list(geofence_client_dbus_h geofence_client, int place_id, GVariantIter **iter, int *fenceCnt, int *errorCode)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_get_list");
+ g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER);
+
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;
+
+ GVariant *reg = NULL;
+ GError *error = NULL;
+ GDBusProxy *proxy = NULL;
+ gchar *app_id = NULL;
+ int ret = GEOFENCE_CLIENT_ERROR_NONE;
+ gchar *signal_path = NULL;
+ pid_t pid = 0;
+ GVariantIter *iterator;
+ int error_code = -1;
+ int fence_cnt = 1;
+
+ GEOFENCE_CLIENT_LOGI("Getting the app id in client");
+ pid = getpid();
+ ret = app_manager_get_app_id(pid, &app_id);
+
+ if (ret != APP_MANAGER_ERROR_NONE)
+ GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret);
+
+ GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id);
+
+ signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG");
+ GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path);
+
+ GEOFENCE_CLIENT_LOGD("handle->user_cb : %x", handle->user_cb);
+
+ /* Start geofence */
+ proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error);
+ g_free(signal_path);
+
+ if (proxy) {
+ reg = g_dbus_proxy_call_sync(proxy, "GetList", g_variant_new("(is)", place_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (reg) {
+ g_variant_get(reg, "(iiaa{sv})", &fence_cnt, &error_code, &iterator);
+ *fenceCnt = fence_cnt;
+ *errorCode = error_code;
+ if (iterator == NULL)
+ GEOFENCE_CLIENT_LOGE("Iterator is null");
+ *iter = iterator;
+ g_variant_unref(reg);
+ } else {
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get the list Error[%s]", error->message);
+ g_error_free(error);
+ ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL;
+ }
+ }
+ g_object_unref(proxy);
+ } else {
+ GEOFENCE_CLIENT_LOGD(" proxy NOT exited !");
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message);
+ g_error_free(error);
+ ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL;
+ }
+ }
+ if (app_id)
+ g_free(app_id);
+
+ return ret;
+}
+
+EXPORT_API int geo_client_get_place_list(geofence_client_dbus_h geofence_client, GVariantIter **iter, int *placeCnt, int *errorCode)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_get_place_list");
+ g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER);
+
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;
+
+ GVariant *reg = NULL;
+ GError *error = NULL;
+ GDBusProxy *proxy = NULL;
+ gchar *app_id = NULL;
+ int ret = GEOFENCE_CLIENT_ERROR_NONE;
+ gchar *signal_path = NULL;
+ pid_t pid = 0;
+ GVariantIter *iterator;
+ int error_code = -1;
+ int place_cnt = 0;
+
+ GEOFENCE_CLIENT_LOGI("Getting the app id in client");
+ pid = getpid();
+ ret = app_manager_get_app_id(pid, &app_id);
+ if (ret != APP_MANAGER_ERROR_NONE)
+ GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret);
+
+ GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id);
+
+ signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG");
+ GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path);
+
+ GEOFENCE_CLIENT_LOGD("handle->user_cb : %x", handle->user_cb);
+
+ /* Start geofence */
+ proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error);
+ g_free(signal_path);
+ if (proxy) {
+ reg = g_dbus_proxy_call_sync(proxy, "GetPlaceList", g_variant_new("(s)", app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (reg) {
+ g_variant_get(reg, "(iiaa{sv})", &place_cnt, &error_code, &iterator);
+ *placeCnt = place_cnt;
+ *errorCode = error_code;
+ if (iterator == NULL)
+ GEOFENCE_CLIENT_LOGE("Iterator is null");
+ *iter = iterator;
+ g_variant_unref(reg);
+ } else {
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get the place list Error[%s]", error->message);
+ g_error_free(error);
+ ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL;
+ }
+ }
+ g_object_unref(proxy);
+ } else {
+ GEOFENCE_CLIENT_LOGD(" proxy NOT exited !");
+ if (error) {
+ GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message);
+ g_error_free(error);
+ ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL;
+ }
+ }
+ if (app_id)
+ g_free(app_id);
+
+ return ret;
+}
+
+static void geo_client_signal_unsubcribe(geofence_client_dbus_h geofence_client)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_signal_unsubcribe");
+
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;
+ if (handle == NULL) {
+ GEOFENCE_CLIENT_LOGE("Invalid handle");
+ return;
+ }
+ if (handle->conn == NULL) {
+ GEOFENCE_CLIENT_LOGE("Invalid dbus_connection");
+ return;
+ }
+ if (handle->geofence_evt_id) {
+ g_dbus_connection_signal_unsubscribe(handle->conn, handle->geofence_evt_id);
+ handle->geofence_evt_id = 0;
+ }
+ if (handle->geofence_evt_status_id) {
+ g_dbus_connection_signal_unsubscribe(handle->conn, handle->geofence_evt_status_id);
+ handle->geofence_evt_status_id = 0;
+ }
+}
+
+EXPORT_API int geo_client_start(char *service_name, char *service_path, geofence_client_dbus_h *geofence_client, geofence_client_cb callback, geofence_client_event_cb evt_callback, void *user_data)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_start");
+ g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER);
+
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;
+
+ GVariant *param = NULL;
+ GVariantBuilder *builder = NULL;
+ gchar *signal_path = NULL;
+
+ handle->service_name = g_strdup(service_name);
+ handle->service_path = g_strdup(service_path);
+
+ signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG");
+ GEOFENCE_CLIENT_LOGD("Geofence signal subscribe Object Path [%s]", signal_path);
+
+ if (callback) {
+ handle->user_cb = callback;
+ handle->user_data = user_data;
+ handle->geofence_evt_id = g_dbus_connection_signal_subscribe(handle->conn, handle->service_name, "org.tizen.lbs.Geofence", "GeofenceInout", signal_path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, __geofence_signal_callback, handle, NULL);
+
+ if (handle->geofence_evt_id) {
+ GEOFENCE_CLIENT_LOGD("Listening Geofence Changed");
+ } else {
+ GEOFENCE_CLIENT_LOGD("Fail to listen Geofence Changed");
+ }
+ }
+ if (callback) {
+ handle->user_event_cb = evt_callback;
+ handle->user_data = user_data;
+ handle->geofence_evt_status_id = g_dbus_connection_signal_subscribe(handle->conn, handle->service_name, "org.tizen.lbs.Geofence", "GeofenceEvent", signal_path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, __geofence_signal_callback, handle, NULL);
+
+ if (handle->geofence_evt_status_id) {
+ GEOFENCE_CLIENT_LOGD("Listening Geofence event changed");
+ } else {
+ GEOFENCE_CLIENT_LOGD("Fail to listen Geofence event changed");
+ return GEOFENCE_CLIENT_ERROR_DBUS_CALL;
+ }
+ }
+ g_free(signal_path);
+
+ /* Start */
+ GEOFENCE_CLIENT_LOGD("START: CMD-START");
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "CMD", g_variant_new_string("START"));
+
+ param = g_variant_ref_sink(g_variant_new("(@a{sv})", g_variant_builder_end(builder)));
+
+ g_variant_unref(param);
+
+ return GEOFENCE_CLIENT_ERROR_NONE;
+}
+
+EXPORT_API int geo_client_stop(geofence_client_dbus_h *geofence_client)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_stop");
+
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;;
+ g_return_val_if_fail(handle, GEOFENCE_CLIENT_ERROR_PARAMETER);
+
+ GVariant *param = NULL;
+ GVariantBuilder *builder = NULL;
+ geo_client_signal_unsubcribe(handle);
+ /* Stop*/
+ GEOFENCE_CLIENT_LOGD("STOP: CMD-STOP");
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "CMD", g_variant_new_string("STOP"));
+ param = g_variant_ref_sink(g_variant_new("(@a{sv})", g_variant_builder_end(builder)));
+
+ g_variant_unref(param);
+
+ return GEOFENCE_CLIENT_ERROR_NONE;
+}
+
+static int __geofence_client_create_connection(geofence_client_dbus_s *client)
+{
+ GEOFENCE_CLIENT_LOGD("__geofence_client_create_connection");
+ g_return_val_if_fail(client, GEOFENCE_CLIENT_ERROR_PARAMETER);
+ GError *error = NULL;
+
+ client->conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (!client->conn) {
+ if (error && error->message) {
+ GEOFENCE_CLIENT_LOGD("Fail to get GBus. ErrCode[%d], Msg[%s]", error->code, error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ GEOFENCE_CLIENT_LOGD("Fail to get addr of bus.");
+ return GEOFENCE_CLIENT_ERROR_CONNECTION;
+ }
+ GEOFENCE_CLIENT_LOGD("client->conn: %p", client->conn);
+
+ return GEOFENCE_CLIENT_ERROR_NONE;
+}
+
+static void _glib_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data)
+{
+ geofence_client_dbus_s *client = (geofence_client_dbus_s *)user_data;
+ if (client != NULL) {
+ GEOFENCE_CLIENT_LOGD("client->conn: %p", client->conn);
+ }
+ GEOFENCE_CLIENT_LOGE("GLIB[%d] : %s", log_level, msg);
+}
+
+/* The reason why we seperate this from start is to support IPC for db operation between a server and a client.*/
+EXPORT_API int geo_client_create(geofence_client_dbus_h *geofence_client)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_create");
+
+ int ret = GEOFENCE_CLIENT_ERROR_NONE;
+ geofence_client_dbus_s *client = g_new0(geofence_client_dbus_s, 1);
+ g_return_val_if_fail(client, GEOFENCE_CLIENT_ERROR_MEMORY);
+ g_log_set_default_handler(_glib_log, client);
+
+ ret = __geofence_client_create_connection(client);
+ if (ret != GEOFENCE_CLIENT_ERROR_NONE) {
+ g_free(client);
+ return ret;
+ }
+ *geofence_client = (geofence_client_dbus_s *) client;
+
+ return GEOFENCE_CLIENT_ERROR_NONE;
+}
+
+EXPORT_API int geo_client_destroy(geofence_client_dbus_h geofence_client)
+{
+ GEOFENCE_CLIENT_LOGD("geo_client_destroy");
+ g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER);
+
+ geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;
+
+ if (handle->conn) {
+ g_object_unref(handle->conn);
+ handle->conn = NULL;
+ }
+ if (handle->service_path)
+ g_free(handle->service_path);
+ if (handle->service_name)
+ g_free(handle->service_name);
+ g_free(handle);
+
+ return GEOFENCE_CLIENT_ERROR_NONE;
+}
diff --git a/introspection/gen.sh b/introspection/gen.sh
new file mode 100644
index 0000000..98baaf2
--- /dev/null
+++ b/introspection/gen.sh
@@ -0,0 +1,8 @@
+#!/bin/bash -x
+
+gdbus-codegen --interface-prefix org.tizen.lbs. \
+ --generate-c-code generated-code \
+ --c-generate-object-manager \
+ --c-namespace Geofence \
+ --generate-docbook generated-docs \
+ geofence.xml
diff --git a/introspection/geofence.xml b/introspection/geofence.xml
new file mode 100644
index 0000000..2f61278
--- /dev/null
+++ b/introspection/geofence.xml
@@ -0,0 +1,80 @@
+<node>
+ <interface name="org.tizen.lbs.Geofence">
+ <method name="AddGeofence">
+ <arg direction="in" type="s" name="app_id"/>
+ <arg direction="in" type="i" name="place_id"/>
+ <arg direction="in" type="i" name="geofence_type"/>
+ <arg direction="in" type="d" name="latitude"/>
+ <arg direction="in" type="d" name="longitude"/>
+ <arg direction="in" type="i" name="radius"/>
+ <arg direction="in" type="s" name="address"/>
+ <arg direction="in" type="s" name="bssid"/>
+ <arg direction="in" type="s" name="ssid"/>
+ <arg direction="out" type="i" name="fence_id"/>
+ </method>
+ <method name="AddPlace">
+ <arg direction="in" type="s" name="app_id"/>
+ <arg direction="in" type="s" name="place_name"/>
+ <arg direction="out" type="i" name="place_id"/>
+ </method>
+ <method name="EnableGeofence">
+ <arg direction="in" type="i" name="fence_id"/>
+ <arg direction="in" type="s" name="app_id"/>
+ <arg direction="in" type="b" name="enable"/>
+ </method>
+ <method name="UpdatePlace">
+ <arg direction="in" type="i" name="place_id"/>
+ <arg direction="in" type="s" name="app_id"/>
+ <arg direction="in" type="s" name="place_name"/>
+ </method>
+ <method name="DeleteGeofence">
+ <arg direction="in" type="i" name="fence_id"/>
+ <arg direction="in" type="s" name="app_id"/>
+ </method>
+ <method name="DeletePlace">
+ <arg direction="in" type="i" name="place_id"/>
+ <arg direction="in" type="s" name="app_id"/>
+ </method>
+ <method name="StartGeofence">
+ <arg direction="in" type="i" name="fence_id"/>
+ <arg direction="in" type="s" name="app_id"/>
+ </method>
+ <method name="StopGeofence">
+ <arg direction="in" type="i" name="fence_id"/>
+ <arg direction="in" type="s" name="app_id"/>
+ </method>
+ <method name="GetPlaceName">
+ <arg direction="in" type="i" name="place_id"/>
+ <arg direction="in" type="s" name="app_id"/>
+ <arg direction="out" type="i" name="error_code"/>
+ <arg direction="out" type="s" name="place_name"/>
+ </method>
+ <method name="GetList">
+ <arg direction="in" type="i" name="place_id"/>
+ <arg direction="in" type="s" name="app_id"/>
+ <arg direction="out" type="i" name="fence_count"/>
+ <arg direction="out" type="i" name="error_code"/>
+ <arg direction="out" type="aa{sv}" name="geofence_info"/>
+ </method>
+ <method name="GetPlaceList">
+ <arg direction="in" type="s" name="app_id"/>
+ <arg direction="out" type="i" name="place_count"/>
+ <arg direction="out" type="i" name="error_code"/>
+ <arg direction="out" type="aa{sv}" name="place_info"/>
+ </method>
+ <signal name="GeofenceInout">
+ <arg direction="out" type="s" name="app_id"/>
+ <arg direction="out" type="i" name="fence_id"/>
+ <arg direction="out" type="i" name="access_type"/>
+ <arg direction="out" type="i" name="fence_state"/>
+ </signal>
+ <signal name="GeofenceEvent">
+ <arg direction="out" type="i" name="place_id"/>
+ <arg direction="out" type="i" name="fence_id"/>
+ <arg direction="out" type="i" name="access_type"/>
+ <arg direction="out" type="s" name="app_id"/>
+ <arg direction="out" type="i" name="error"/>
+ <arg direction="out" type="i" name="state"/>
+ </signal>
+ </interface>
+</node>
diff --git a/libgeofence-dbus.manifest b/libgeofence-dbus.manifest
new file mode 100644
index 0000000..97e8c31
--- /dev/null
+++ b/libgeofence-dbus.manifest
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
diff --git a/packaging/geofence-dbus.spec b/packaging/geofence-dbus.spec
new file mode 100644
index 0000000..0a295d8
--- /dev/null
+++ b/packaging/geofence-dbus.spec
@@ -0,0 +1,81 @@
+Name: geofence-dbus
+Summary: Dbus interface for Geofence service
+Version: 0.2.2
+Release: 1
+Group: Location/Libraries
+License: Apache-2.0
+Source0: geofence-dbus-%{version}.tar.gz
+
+%if "%{?tizen_profile_name}" == "tv"
+ExcludeArch: %{arm} %ix86 x86_64
+%endif
+
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+BuildRequires: cmake
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gobject-2.0)
+BuildRequires: pkgconfig(dlog)
+#BuildRequires: pkgconfig(security-server)
+BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(gio-unix-2.0)
+BuildRequires: pkgconfig(capi-appfw-app-manager)
+BuildRequires: pkgconfig(capi-appfw-package-manager)
+BuildRequires: pkgconfig(pkgmgr-info)
+BuildRequires: python
+BuildRequires: python-xml
+
+%description
+Geofence dbus interface
+
+%package -n libgeofence-dbus
+Summary: Geofence dbus library
+Group: Location/Libraries
+Requires(post): sys-assert
+
+%description -n libgeofence-dbus
+Geofence client API library
+
+%package -n libgeofence-dbus-devel
+Summary: Telephony client API (devel)
+Group: Development/Libraries
+Requires: libgeofence-dbus = %{version}-%{release}
+
+%description -n libgeofence-dbus-devel
+Geofence client API library (devel)
+
+
+%prep
+%setup -q
+
+
+%build
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
+export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
+export CFLAGS+=" -Wno-unused-local-typedefs "
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIBDIR=%{_libdir}\
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+
+%files -n libgeofence-dbus
+%manifest libgeofence-dbus.manifest
+%defattr(-,root,root,-)
+#%doc COPYING
+%{_libdir}/*.so.*
+%{_prefix}/etc/dbus-1/system.d/*
+
+%files -n libgeofence-dbus-devel
+%defattr(-,root,root,-)
+%{_includedir}/geofence-dbus/*.h
+%{_libdir}/pkgconfig/*.pc
+%{_libdir}/*.so
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
new file mode 100644
index 0000000..68ecc60
--- /dev/null
+++ b/server/CMakeLists.txt
@@ -0,0 +1,27 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(geofence-dbus-server C)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/cmake_tmp ${CMAKE_BINARY_DIR})
+
+### Build ###
+SET(SRCS_S
+ src/geofence_dbus_server.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/generated-code.c
+)
+MESSAGE(Server_CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR})
+MESSAGE(CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR})
+MESSAGE(CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR})
+
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/generated-code.c
+ COMMAND gdbus-codegen --interface-prefix org.tizen.lbs. --generate-c-code generated-code --c-generate-object-manager --c-namespace SLoc --generate-docbook generated-docs ${CMAKE_SOURCE_DIR}/introspection/geofence.xml
+ COMMENT "Generating GDBus .c/.h")
+
+ADD_LIBRARY(geofence-dbus-server SHARED ${SRCS_S})
+TARGET_LINK_LIBRARIES(geofence-dbus-server ${pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(geofence-dbus-server PROPERTIES VERSION 0.1.0 SOVERSION 0 OUTPUT_NAME geofence-dbus-server)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/geofence-dbus-server.conf DESTINATION ${PREFIX}/etc/dbus-1/system.d)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/geofence_dbus_server.h DESTINATION include/geofence-dbus)
+INSTALL(TARGETS geofence-dbus-server DESTINATION ${LIBDIR} COMPONENT Runtime)
+#ADD_SUBDIRECTORY(test_src)
diff --git a/server/include/geofence_dbus_server.h b/server/include/geofence_dbus_server.h
new file mode 100644
index 0000000..1d532c6
--- /dev/null
+++ b/server/include/geofence_dbus_server.h
@@ -0,0 +1,149 @@
+/* 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.
+ */
+
+/**
+ * @file geofence_dbus_server.h
+ * @brief This file contains the APIs and callback functions for the dbus server.
+ */
+
+#ifndef __GEOFENCE_DBUS_SERVER_H__
+#define __GEOFENCE_DBUS_SERVER_H__
+
+__BEGIN_DECLS
+#include <gio/gio.h>
+
+/**
+* @brief Callback for setting the options
+*/
+typedef void (*GeofenceDbusSetOptionsCB) (GVariant * options, gpointer userdata);
+
+/**
+* @brief Callback for shutting down the Dbus
+*/
+typedef void (*GeofenceDbusShutdownCB) (gpointer userdata, gboolean *shutdown_arr);
+
+/* for geofence callbacks */
+
+/**
+* @brief Callback for adding the fence
+*/
+typedef gint (*GeofenceAddGeofenceCB) (const gchar * app_id, gint place_id, gint geofence_type, gdouble latitude, gdouble longitude, gint radius, const gchar * address, const gchar * bssid, const gchar * ssid, gpointer userdata);
+
+/**
+* @brief Callback for adding the place
+*/
+typedef gint (*GeofenceAddPlaceCB) (const gchar * app_id, const gchar * place_name, gpointer userdata);
+
+/**
+* @brief Callback for enabling the geofence
+*/
+typedef void (*GeofenceEnableGeofenceCB) (gint fence_id, const gchar *app_id, gboolean enable, gpointer userdata);
+
+/**
+* @brief Callback for updating the place
+*/
+typedef void (*GeofenceUpdatePlaceCB) (gint place_id, const gchar *app_id, const gchar *place_name, gpointer userdata);
+/**
+* @brief Callback for deleting the geofence
+*/
+typedef void (*GeofenceDeleteGeofenceCB) (gint fence_id, const gchar *app_id, gpointer userdata);
+
+/**
+* @brief Callback for deleting the place
+*/
+typedef void (*GeofenceDeletePlaceCB) (gint place_id, const gchar *app_id, gpointer userdata);
+
+/**
+* @brief Callback for Starting the Geofence service
+*/
+typedef void (*GeofenceStartGeofenceCB) (gint fence_id, const gchar *app_id, gpointer userdata);
+
+/**
+* @brief Callback for Stopping the Geofence service
+*/
+typedef void (*GeofenceStopGeofenceCB) (gint fence_id, const gchar *app_id, gpointer userdata);
+
+/**
+* @brief Callback for getting the place name
+*/
+typedef void (*GeofenceGetPlaceNameGeofenceCB) (int place_id, const gchar *app_id, char **place_name, int *error_code, gpointer userdata);
+
+/**
+* @brief Callback for getting the fence list
+*/
+typedef GVariant * (*GeofenceGetlistGeofenceCB) (int place_id, const gchar *app_id, int *fenceCnt, int *error_code, gpointer userdata);
+
+/**
+* @brief Callback for getting the place list
+*/
+typedef GVariant * (*GeofenceGetPlaceListGeofenceCB) (const gchar *app_id, int *fenceCnt, int *error_code, gpointer userdata);
+
+typedef enum {
+ GEOFENCE_DBUS_SERVER_ERROR_NONE = 0x0,
+ GEOFENCE_DBUS_SERVER_ERROR_UNKNOWN,
+ GEOFENCE_DBUS_SERVER_ERROR_PARAMETER,
+ GEOFENCE_DBUS_SERVER_ERROR_MEMORY,
+ GEOFENCE_DBUS_SERVER_ERROR_CONNECTION,
+ GEOFENCE_DBUS_SERVER_ERROR_STATUS,
+ GEOFENCE_DBUS_SERVER_ERROR_DBUS_CALL,
+ GEOFENCE_DBUS_SERVER_ERROR_NO_RESULT,
+} geofence_dbus_server_error_e;
+
+typedef void *geofence_dbus_server_h;
+
+/**
+* @brief API to send the geofence status to the application
+* @param[in] geofence_dbus_server - The dbus server
+* @param[in] app_id - The application to which the status needs to be sent
+* @param[in] fence_state - The state of the fence whether in/out
+* @return int
+* @retval GEOFENCE_DBUS_SERVER_ERROR_NONE
+*/
+int geofence_dbus_server_send_geofence_inout_changed(geofence_dbus_server_h geofence_dbus_server, const gchar *app_id, gint fence_id, gint access_type, gint fence_state);
+
+int geofence_dbus_server_send_geofence_event_changed(geofence_dbus_server_h geofence_dbus_server, gint place_id, gint fence_id, gint access_type, const gchar *app_id, gint error, gint state);
+
+
+/**
+* @brief API to create the server
+* @param[in] service_name - Name of the service for which the server has to be created
+* @param[in] service_path - Path for the service
+* @param[in] name - Server name
+* @param[in] description - Description about the server
+* @param[in] geofence_dbus_server - Dbus server pointer
+* @param[in] add_geofence_cb - Callback for add geofence funtionality
+* @param[in] enable_geofence_cb - Callback for enable geofence functionality
+* @param[in] delete_fence_cb - Callback for delete geofence funtionality
+* @param[in] getlist_fence_cb - Callback for getlist functionality
+* @param[in] start_geofence_cb - Callback for start geofence functionality
+* @param[in] stop_geofence_cb - Callback for stopping the geofence functionality
+* @param[in] userdata - Userdata if any which will come back in the callbacks
+* return int
+* retval GEOFENCE_DBUS_SERVER_ERROR_NONE if success
+ GEOFENCE_DBUS_SERVER_ERROR_MEMORY if failure
+*/
+int geofence_dbus_server_create(char *service_name, char *service_path, char *name, char *description, geofence_dbus_server_h *geofence_dbus_server, GeofenceAddGeofenceCB add_geofence_cb, GeofenceAddPlaceCB add_place_cb, GeofenceEnableGeofenceCB enable_geofence_cb, GeofenceUpdatePlaceCB update_place_cb, GeofenceDeleteGeofenceCB delete_fence_cb, GeofenceDeletePlaceCB delete_place_cb, GeofenceGetPlaceNameGeofenceCB getplacename_fence_cb, GeofenceGetlistGeofenceCB getlist_fence_cb, GeofenceGetPlaceListGeofenceCB getplacelist_fence_cb, GeofenceStartGeofenceCB start_geofence_cb, GeofenceStopGeofenceCB stop_geofence_cb, gpointer userdata);
+
+/**
+* @brief API to destroy the dbus server which was created
+* @param[in] geofence_dbus_server - Handle to the dbus server which was created
+* @return int
+* @retval GEOFENCE_DBUS_SERVER_ERROR_NONE if sucess
+ GEOFENCE_DBUS_SERVER_ERROR_PARAMETER if failure
+*/
+int geofence_dbus_server_destroy(geofence_dbus_server_h geofence_dbus_server);
+
+__END_DECLS
+#endif /* __GEOFENCE_DBUS_SERVER_H__ */
diff --git a/server/include/geofence_dbus_server_priv.h b/server/include/geofence_dbus_server_priv.h
new file mode 100644
index 0000000..5623e9f
--- /dev/null
+++ b/server/include/geofence_dbus_server_priv.h
@@ -0,0 +1,44 @@
+/* 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.
+ */
+
+/**
+ * @file geofence_dbus_server_priv.h
+ * @brief This file contains the log tags for the geofence dbus server.
+ */
+
+#ifndef __GEOFENCE_DBUS_SERVER_PRIV_H__
+#define __GEOFENCE_DBUS_SERVER_PRIV_H__
+
+__BEGIN_DECLS
+#ifdef FEATURE_DLOG_DEBUG
+#include <dlog.h>
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "GEOFENCE_DBUS_SERVER"
+#endif
+#define GEOFENCE_DBUS_SERVER_LOGI(fmt, args...) { LOGI(fmt, ##args); }
+#define GEOFENCE_DBUS_SERVER_LOGD(fmt, args...) { LOGD(fmt, ##args); }
+#define GEOFENCE_DBUS_SERVER_LOGW(fmt, args...) { LOGW(fmt, ##args); }
+#define GEOFENCE_DBUS_SERVER_LOGE(fmt, args...) { LOGE(fmt, ##args); }
+#define GEOFENCE_DBUS_SERVER_SECLOG(fmt, args...) { SECURE_LOGD(fmt, ##args); }
+#else
+#define GEOFENCE_DBUS_SERVER_LOGI(fmt, args...)
+#define GEOFENCE_DBUS_SERVER_LOGD(fmt, args...)
+#define GEOFENCE_DBUS_SERVER_LOGW(fmt, args...)
+#define GEOFENCE_DBUS_SERVER_LOGE(fmt, args...)
+#define GEOFENCE_DBUS_SERVER_SECLOG(fmt, args...)
+#endif
+ __END_DECLS
+#endif /*__GEOFENCE_DBUS_SERVER_PRIV_H__*/
diff --git a/server/res/geofence-dbus-server.conf b/server/res/geofence-dbus-server.conf
new file mode 100644
index 0000000..793edee
--- /dev/null
+++ b/server/res/geofence-dbus-server.conf
@@ -0,0 +1,128 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+ <policy user="root">
+ <allow own="org.tizen.lbs"/>
+ <allow own="org.tizen.lbs.Manager"/>
+ <allow own="org.tizen.lbs.Geofence"/>
+ <allow own="org.tizen.lbs.Providers.GpsManager"/>
+ <allow own="org.tizen.lbs.Providers.GeofenceManager"/>
+ <allow own="org.tizen.lbs.Providers.Xps"/>
+ <allow send_destination="org.tizen.lbs"/>
+ <allow send_destination="org.tizen.lbs.Manager"/>
+ <allow send_destination="org.tizen.lbs.Geofence"/>
+ <allow send_destination="org.tizen.lbs.Providers.GpsManager"/>
+ <allow send_destination="org.tizen.lbs.Providers.GeofenceManager"/>
+ <allow send_destination="org.tizen.lbs.Providers.Xps"/>
+ <allow receive_sender="org.tizen.lbs.Manager"/>
+ <allow receive_sender="org.tizen.lbs.Geofence"/>
+ <allow receive_sender="org.tizen.lbs.Providers.GpsManager"/>
+ <allow receive_sender="org.tizen.lbs.Providers.GeofenceManager"/>
+ <allow receive_sender="org.tizen.lbs.Providers.Xps"/>
+ <allow send_interface="org.tizen.lbs"/>
+ <allow send_interface="org.tizen.lbs.Manager"/>
+ <allow send_interface="org.tizen.lbs.Geofence"/>
+ <allow send_interface="org.tizen.lbs.Position"/>
+ <allow send_interface="org.tizen.lbs.Nmea"/>
+ <allow send_interface="org.tizen.lbs.Satellite"/>
+ <allow receive_interface="org.tizen.lbs"/>
+ <allow receive_interface="org.tizen.lbs.Manager"/>
+ <allow receive_interface="org.tizen.lbs.SGeofence"/>
+ <allow receive_interface="org.tizen.lbs.Position"/>
+ <allow receive_interface="org.tizen.lbs.Nmea"/>
+ <allow receive_interface="org.tizen.lbs.Satellite"/>
+ </policy>
+ <policy user="app">
+ <allow own="org.tizen.lbs"/>
+ <allow own="org.tizen.lbs.Manager"/>
+ <allow own="org.tizen.lbs.Geofence"/>
+ <allow own="org.tizen.lbs.Providers.GpsManager"/>
+ <allow own="org.tizen.lbs.Providers.GeofenceManager"/>
+ <allow own="org.tizen.lbs.Providers.Xps"/>
+ <allow send_destination="org.tizen.lbs"/>
+ <allow send_destination="org.tizen.lbs.Manager"/>
+ <allow send_destination="org.tizen.lbs.Geofence"/>
+ <allow send_destination="org.tizen.lbs.Providers.GpsManager"/>
+ <allow send_destination="org.tizen.lbs.Providers.GeofenceManager"/>
+ <allow send_destination="org.tizen.lbs.Providers.Xps"/>
+ <allow receive_sender="org.tizen.lbs.Manager"/>
+ <allow receive_sender="org.tizen.lbs.Geofence"/>
+ <allow receive_sender="org.tizen.lbs.Providers.GpsManager"/>
+ <allow receive_sender="org.tizen.lbs.Providers.GeofenceManager"/>
+ <allow receive_sender="org.tizen.lbs.Providers.Xps"/>
+ <allow send_interface="org.tizen.lbs"/>
+ <allow send_interface="org.tizen.lbs.Manager"/>
+ <allow send_interface="org.tizen.lbs.Geofence"/>
+ <allow send_interface="org.tizen.lbs.Poistion"/>
+ <allow send_interface="org.tizen.lbs.Nmea"/>
+ <allow send_interface="org.tizen.lbs.Satellite"/>
+ <allow receive_interface="org.tizen.lbs"/>
+ <allow receive_interface="org.tizen.lbs.Manager"/>
+ <allow receive_interface="org.tizen.lbs.Geofence"/>
+ <allow receive_interface="org.tizen.lbs.Position"/>
+ <allow receive_interface="org.tizen.lbs.Nmea"/>
+ <allow receive_interface="org.tizen.lbs.Satellite"/>
+ </policy>
+ <policy at_console="true">
+ <allow own="org.tizen.lbs"/>
+ <allow own="org.tizen.lbs.Manager"/>
+ <allow own="org.tizen.lbs.Geofence"/>
+ <allow own="org.tizen.lbs.Providers.GpsManager"/>
+ <allow own="org.tizen.lbs.Providers.GeofenceManager"/>
+ <allow own="org.tizen.lbs.Providers.Xps"/>
+ <allow send_destination="org.tizen.lbs"/>
+ <allow send_destination="org.tizen.lbs.Manager"/>
+ <allow send_destination="org.tizen.lbs.Geofence"/>
+ <allow send_destination="org.tizen.lbs.Providers.GpsManager"/>
+ <allow send_destination="org.tizen.lbs.Providers.GeofenceManager"/>
+ <allow send_destination="org.tizen.lbs.Providers.Xps"/>
+ <allow receive_sender="org.tizen.lbs.Manager"/>
+ <allow receive_sender="org.tizen.lbs.Geofence"/>
+ <allow receive_sender="org.tizen.lbs.Providers.GpsManager"/>
+ <allow receive_sender="org.tizen.lbs.Providers.GeofenceManager"/>
+ <allow receive_sender="org.tizen.lbs.Providers.Xps"/>
+ <allow send_interface="org.tizen.lbs"/>
+ <allow send_interface="org.tizen.lbs.Manager"/>
+ <allow send_interface="org.tizen.lbs.Geofence"/>
+ <allow send_interface="org.tizen.lbs.Poistion"/>
+ <allow send_interface="org.tizen.lbs.Nmea"/>
+ <allow send_interface="org.tizen.lbs.Satellite"/>
+ <allow receive_interface="org.tizen.lbs"/>
+ <allow receive_interface="org.tizen.lbs.Manager"/>
+ <allow receive_interface="org.tizen.lbs.Geofence"/>
+ <allow receive_interface="org.tizen.lbs.Position"/>
+ <allow receive_interface="org.tizen.lbs.Nmea"/>
+ <allow receive_interface="org.tizen.lbs.Satellite"/>
+ </policy>
+ <policy context="default">
+ <deny own="org.tizen.lbs"/>
+ <deny own="org.tizen.lbs.Manager"/>
+ <deny own="org.tizen.lbs.Geofence"/>
+ <deny own="org.tizen.lbs.Providers.GpsManager"/>
+ <deny own="org.tizen.lbs.Providers.GeofenceManager"/>
+ <deny own="org.tizen.lbs.Providers.Xps"/>
+ <deny send_destination="org.tizen.lbs"/>
+ <deny send_destination="org.tizen.lbs.Manager"/>
+ <deny send_destination="org.tizen.lbs.Geofence"/>
+ <deny send_destination="org.tizen.lbs.Providers.GpsManager"/>
+ <deny send_destination="org.tizen.lbs.Providers.GeofenceManager"/>
+ <deny send_destination="org.tizen.lbs.Providers.Xps"/>
+ <deny receive_sender="org.tizen.lbs.Manager"/>
+ <deny receive_sender="org.tizen.lbs.Geofence"/>
+ <deny receive_sender="org.tizen.lbs.Providers.GpsManager"/>
+ <deny receive_sender="org.tizen.lbs.Providers.GeofenceManager"/>
+ <deny receive_sender="org.tizen.lbs.Providers.Xps"/>
+ <deny send_interface="org.tizen.lbs"/>
+ <deny send_interface="org.tizen.lbs.Manager"/>
+ <deny send_interface="org.tizen.lbs.Geofence"/>
+ <deny send_interface="org.tizen.lbs.Poistion"/>
+ <deny send_interface="org.tizen.lbs.Nmea"/>
+ <deny send_interface="org.tizen.lbs.Satellite"/>
+ <deny receive_interface="org.tizen.lbs"/>
+ <deny receive_interface="org.tizen.lbs.Manager"/>
+ <deny receive_interface="org.tizen.lbs.Geofence"/>
+ <deny receive_interface="org.tizen.lbs.Position"/>
+ <deny receive_interface="org.tizen.lbs.Nmea"/>
+ <deny receive_interface="org.tizen.lbs.Satellite"/>
+ </policy>
+</busconfig>
diff --git a/server/src/geofence_dbus_server.c b/server/src/geofence_dbus_server.c
new file mode 100644
index 0000000..3158a61
--- /dev/null
+++ b/server/src/geofence_dbus_server.c
@@ -0,0 +1,620 @@
+/* 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 "generated-code.h"
+#include "geofence_dbus_server.h"
+#include "geofence_dbus_server_priv.h"
+
+typedef struct _geofence_dbus_server_s {
+ /* Geofence Dbus Server info */
+ gchar *service_name;
+ gchar *prev_owner;
+ gchar *service_path;
+ gchar *name;
+ gchar *description;
+ GHashTable *connections;
+ gint status;
+ GDBusObjectManagerServer *manager;
+ SLocObjectSkeleton *obj_skeleton;
+ GeofenceDbusSetOptionsCB set_options_cb;
+ GeofenceDbusShutdownCB shutdown_cb;
+ gpointer userdata; /* used for save GpsManager */
+ guint owner_changed_id;
+ guint owner_id;
+ guint get_providerinfo_h;
+ guint get_status_h;
+ guint set_option_h;
+ guint add_reference_h;
+ guint remove_reference_h;
+
+ /* for geofence */
+ guint add_geofence_h;
+ guint add_place_h;
+ guint enable_geofence_h;
+ guint update_place_h;
+ guint delete_geofence_h;
+ guint delete_place_h;
+ guint start_geofence_h;
+ guint stop_geofence_h;
+ guint getplacename_geofence_h;
+ guint getlist_geofence_h;
+ guint getplacelist_geofence_h;
+
+ gint geofence_status;
+ GeofenceAddGeofenceCB add_geofence_cb;
+ GeofenceAddPlaceCB add_place_cb;
+ GeofenceEnableGeofenceCB enable_geofence_cb;
+ GeofenceUpdatePlaceCB update_place_cb;
+ GeofenceDeleteGeofenceCB delete_geofence_cb;
+ GeofenceDeletePlaceCB delete_place_cb;
+ GeofenceGetPlaceNameGeofenceCB getplacename_geofence_cb;
+ GeofenceGetlistGeofenceCB getlist_geofence_cb;
+ GeofenceGetPlaceListGeofenceCB getplacelist_geofence_cb;
+ GeofenceStartGeofenceCB start_geofence_cb;
+ GeofenceStopGeofenceCB stop_geofence_cb;
+} geofence_dbus_server_s;
+
+typedef enum {
+ GEOFENCE_DBUS_SERVER_METHOD_GPS = 0,
+ GEOFENCE_DBUS_SERVER_METHOD_NPS,
+ GEOFENCE_DBUS_SERVER_METHOD_AGPS,
+ GEOFENCE_DBUS_SERVER_METHOD_GEOFENCE,
+ GEOFENCE_DBUS_SERVER_METHOD_SIZE,
+} geofence_dbus_server_method_e;
+
+static gboolean geofence_dbus_setup_geofence_interface(SLocObjectSkeleton *object, geofence_dbus_server_s *ctx)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("geofence_dbus_setup_geofence_interface");
+ if (!object || !ctx)
+ return FALSE;
+
+ SLocGeofence *geofence = NULL;
+ geofence = sloc_geofence_skeleton_new();
+ sloc_object_skeleton_set_geofence(object, geofence);
+ g_object_unref(geofence);
+
+ return TRUE;
+}
+
+static gboolean geofence_find_method(gpointer key, gpointer value, gpointer user_data)
+{
+ int *ip = (int *)user_data;
+ int *arr = (int *)value;
+ int method = *ip;
+
+ GEOFENCE_DBUS_SERVER_LOGD("[%s] geofence_find_method method:%d, count:%d", (char *)key, method, arr[method]);
+
+ return (arr[method] > 0) ? TRUE : FALSE;
+}
+
+/*
+ * For geofence methods
+ */
+static gboolean on_add_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, const gchar *app_id, gint place_id, gint geofence_type, gdouble latitude, gdouble longitude, gint radius, const gchar *address, const gchar *bssid, const gchar *ssid, gpointer user_data)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("on_add_geofence");
+
+ /* call geofence-server's callback, add_geofence_cb */
+ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data;
+ if (!ctx)
+ return FALSE;
+ gint fence_id = 0;
+ if (ctx->add_geofence_cb) {
+ fence_id = ctx->add_geofence_cb(app_id, place_id, geofence_type, latitude, longitude, radius, address, bssid, ssid, ctx->userdata);
+ GEOFENCE_DBUS_SERVER_LOGD("add_geofence_cb called");
+ }
+ sloc_geofence_complete_add_geofence(geofence, invocation, fence_id);
+ return TRUE;
+}
+
+static gboolean on_add_place(SLocGeofence *geofence, GDBusMethodInvocation *invocation, const gchar *app_id, const gchar *place_name, gpointer user_data)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("on_add_place");
+
+ /* call geofence-server's callback, add_place_cb */
+ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data;
+ if (!ctx)
+ return FALSE;
+ gint place_id = 0;
+ if (ctx->add_geofence_cb) {
+ place_id = ctx->add_place_cb(app_id, place_name, ctx->userdata);
+ GEOFENCE_DBUS_SERVER_LOGD("add_place_cb called");
+ }
+ sloc_geofence_complete_add_place(geofence, invocation, place_id);
+ return TRUE;
+}
+
+static gboolean on_enable_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint fence_id, const gchar *app_id, gboolean enable, gpointer user_data)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("on_enable_geofence");
+
+ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data;
+ if (!ctx)
+ return FALSE;
+
+ /* call geofence-server's callback, enable_geofence_cb */
+ if (ctx->enable_geofence_cb) {
+ ctx->enable_geofence_cb(fence_id, app_id, enable, ctx->userdata);
+ GEOFENCE_DBUS_SERVER_LOGD("enable_geofence_cb called");
+ }
+ sloc_geofence_complete_enable_geofence(geofence, invocation);
+ return TRUE;
+}
+
+static gboolean on_update_place(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint place_id, const gchar *app_id, const gchar *place_name, gpointer user_data)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("on_update_place");
+
+ /* call geofence-server's callback, update_place_cb */
+ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data;
+ if (!ctx)
+ return FALSE;
+ if (ctx->update_place_cb) {
+ ctx->update_place_cb(place_id, app_id, place_name, ctx->userdata);
+ GEOFENCE_DBUS_SERVER_LOGD("update_place_cb called");
+ }
+ sloc_geofence_complete_update_place(geofence, invocation);
+ return TRUE;
+}
+
+static gboolean on_getplacename_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint place_id, const gchar *app_id, gpointer user_data)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("on_getplacename_geofence");
+
+ /* call geofence-server's callback, getplacename_geofence_cb */
+ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data;
+ if (!ctx) {
+ return FALSE;
+ }
+ char *place_name = NULL;
+ gint error_code = -1;
+ if (ctx->getplacename_geofence_cb) {
+ ctx->getplacename_geofence_cb(place_id, app_id, &place_name, &error_code, ctx->userdata);
+ GEOFENCE_DBUS_SERVER_LOGD("getlist_geofence_cb called");
+ }
+ sloc_geofence_complete_get_place_name(geofence, invocation, error_code, place_name);
+ if (place_name)
+ g_free(place_name); /*This has to be freed as it has been allocated by the server DB side*/
+ return TRUE;
+}
+
+static gboolean on_getlist_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint place_id, const gchar *app_id, gpointer user_data)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("on_getlist_geofence");
+
+ /* call geofence-server's callback, getlist_geofence_cb */
+ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data;
+ if (!ctx)
+ return FALSE;
+
+ GVariant *geofence_info = NULL;
+ gint fence_cnt = 0;
+ gint error_code = -1;
+ if (ctx->getlist_geofence_cb) {
+ geofence_info = ctx->getlist_geofence_cb(place_id, app_id, &fence_cnt, &error_code, ctx->userdata);
+ GEOFENCE_DBUS_SERVER_LOGD("getlist_geofence_cb called");
+ }
+ sloc_geofence_complete_get_list(geofence, invocation, fence_cnt, error_code, geofence_info);
+ return TRUE;
+}
+
+static gboolean on_getplacelist_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, const gchar *app_id, gpointer user_data)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("on_getplacelist_geofence");
+
+ /* call geofence-server's callback, getplacelist_geofence_cb */
+ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data;
+ if (!ctx)
+ return FALSE;
+ GVariant *place_info = NULL;
+ gint place_cnt = 0;
+ gint error_code = -1;
+ if (ctx->getplacelist_geofence_cb) {
+ place_info = ctx->getplacelist_geofence_cb(app_id, &place_cnt, &error_code, ctx->userdata);
+ GEOFENCE_DBUS_SERVER_LOGD("getplacelist_geofence_cb called");
+ }
+ sloc_geofence_complete_get_place_list(geofence, invocation, place_cnt, error_code, place_info);
+ return TRUE;
+}
+
+static gboolean on_delete_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint fence_id, const gchar *app_id, gpointer user_data)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("on_delete_geofence");
+
+ /* call geofence-server's callback, delete_geofence_cb */
+ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data;
+ if (!ctx)
+ return FALSE;
+ if (ctx->delete_geofence_cb) {
+ ctx->delete_geofence_cb(fence_id, app_id, ctx->userdata);
+ GEOFENCE_DBUS_SERVER_LOGD("delete_geofence_cb called");
+ }
+ sloc_geofence_complete_delete_geofence(geofence, invocation);
+ return TRUE;
+}
+
+static gboolean on_delete_place(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint place_id, const gchar *app_id, gpointer user_data)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("on_delete_place");
+
+ /* call geofence-server's callback, delete_place_cb */
+ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data;
+ if (!ctx)
+ return FALSE;
+ if (ctx->delete_place_cb) {
+ ctx->delete_place_cb(place_id, app_id, ctx->userdata);
+ GEOFENCE_DBUS_SERVER_LOGD("delete_place_cb called");
+ }
+ sloc_geofence_complete_delete_place(geofence, invocation);
+ return TRUE;
+}
+
+static gboolean on_start_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint fence_id, const gchar *app_id, gpointer user_data)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("on_start_geofence");
+
+ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data;
+ if (!ctx)
+ return FALSE;
+ /* call geofence-server's callback, start_geofence_cb */
+ if (ctx->start_geofence_cb) {
+ ctx->start_geofence_cb(fence_id, app_id, ctx->userdata);
+ GEOFENCE_DBUS_SERVER_LOGD("start_geofence_cb called");
+ }
+ sloc_geofence_complete_start_geofence(geofence, invocation);
+ return TRUE;
+}
+
+static gboolean on_stop_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint fence_id, const gchar *app_id, gpointer user_data)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("on_stop_geofence");
+
+ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data;
+ if (!ctx)
+ return FALSE;
+ /* call geofence-server's callback, stop_geofence_cb */
+ if (ctx->stop_geofence_cb) {
+ ctx->stop_geofence_cb(fence_id, app_id, ctx->userdata);
+ GEOFENCE_DBUS_SERVER_LOGD("stop_geofence_cb called");
+ }
+ sloc_geofence_complete_stop_geofence(geofence, invocation);
+ return TRUE;
+}
+
+static gboolean geofence_remove_client_by_force(const char *client, void *data)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("remove client by force for client [%s]", client);
+
+ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)data;
+
+ int *count_arr = (int *)g_hash_table_lookup(ctx->connections, client);
+ if (!count_arr) {
+ GEOFENCE_DBUS_SERVER_LOGD("Client[%s] is already removed", client);
+ return FALSE;
+ } else {
+ GEOFENCE_DBUS_SERVER_LOGD("[Client: %s]. Remove all clients in hash table", client);
+ if (!g_hash_table_remove(ctx->connections, client))
+ GEOFENCE_DBUS_SERVER_LOGE("g_hash_table_remove is Fail");
+ }
+
+ int index = 0;
+ gboolean *shutdown_arr = (gboolean *)g_malloc0_n(GEOFENCE_DBUS_SERVER_METHOD_SIZE, sizeof(gboolean));
+ if (shutdown_arr == NULL) {
+ GEOFENCE_DBUS_SERVER_LOGD("malloc fail for geofence_remove_client_by_force");
+ return FALSE;
+ }
+
+ if (g_hash_table_size(ctx->connections) == 0) {
+ GEOFENCE_DBUS_SERVER_SECLOG("Hash table size is zero, Now shutdown provider[%s]", ctx->name);
+
+ for (; index < GEOFENCE_DBUS_SERVER_METHOD_SIZE; index++)
+ shutdown_arr[index] = TRUE;
+ } else {
+ GEOFENCE_DBUS_SERVER_SECLOG("Hash table size is not zero");
+
+ for (; index < GEOFENCE_DBUS_SERVER_METHOD_SIZE; index++) {
+ if (g_hash_table_find(ctx->connections, (GHRFunc) geofence_find_method, &index) == NULL) {
+ shutdown_arr[index] = TRUE;
+ continue;
+ }
+ }
+ }
+
+ if (ctx->shutdown_cb) {
+ ctx->shutdown_cb(ctx->userdata, shutdown_arr);
+ GEOFENCE_DBUS_SERVER_LOGD("shutdown_cb called.. gps:%d, nps:%d", shutdown_arr[GEOFENCE_DBUS_SERVER_METHOD_GPS], shutdown_arr[GEOFENCE_DBUS_SERVER_METHOD_NPS]);
+ }
+
+ GEOFENCE_DBUS_SERVER_LOGD("###### A client[%s] is abnormally shut down ########", client);
+
+ g_free(shutdown_arr);
+ return TRUE;
+}
+
+static void geofence_scan_sender(char *key, char *value, gpointer user_data)
+{
+ geofence_dbus_server_s *handle = (geofence_dbus_server_s *)user_data;
+ g_return_if_fail(handle);
+ gchar *prev_owner = handle->prev_owner;
+ g_return_if_fail(prev_owner);
+
+ GEOFENCE_DBUS_SERVER_LOGD("geofence_scan_sender >> key[%s] : prev_owner[%s]\n", key, prev_owner);
+
+ if (g_strcmp0(prev_owner, key) == 0) {
+ GEOFENCE_DBUS_SERVER_LOGD("disconnected sender name matched, remove client by force!");
+ geofence_remove_client_by_force(prev_owner, handle);
+ }
+}
+
+static void on_name_owner_changed(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data)
+{
+ geofence_dbus_server_s *handle = (geofence_dbus_server_s *)user_data;
+ g_return_if_fail(handle);
+
+ gchar *service_name = NULL, *prev_owner = NULL, *new_owner = NULL;
+ g_variant_get(parameters, "(&s&s&s)", &service_name, &prev_owner, &new_owner);
+
+ if (g_strcmp0(object_path, "/org/freedesktop/DBus") != 0 || g_strcmp0(interface_name, "org.freedesktop.DBus") != 0 || g_strcmp0(sender_name, "org.freedesktop.DBus") != 0)
+ return;
+
+ /* if the prev_owner matches the sender name, then remote sender(client) is crashed */
+ if (g_strcmp0(new_owner, "") == 0 && (prev_owner != NULL && strlen(prev_owner) > 0) && handle->connections != NULL) {
+ if (handle->prev_owner) {
+ g_free(handle->prev_owner);
+ handle->prev_owner = NULL;
+ }
+ handle->prev_owner = g_strdup(prev_owner);
+ g_hash_table_foreach(handle->connections, (GHFunc) geofence_scan_sender, handle);
+ }
+}
+
+static void on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data)
+{
+ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data;
+ if (!ctx)
+ return;
+
+ gchar *path = NULL;
+ SLocGeofence *geofence = NULL;
+
+ GEOFENCE_DBUS_SERVER_LOGD("geofence dbus registered");
+
+ /* create object for each interfaces */
+ path = g_strdup_printf("%s/%s", ctx->service_path, "SAMSUNG");
+ ctx->obj_skeleton = sloc_object_skeleton_new(path);
+
+ if (NULL != path) {
+ GEOFENCE_DBUS_SERVER_LOGD("object path [%s], obj_skeleton [%p]", path, ctx->obj_skeleton);
+ g_free(path);
+ path = NULL;
+ }
+
+ /* add geofence interface */
+ geofence_dbus_setup_geofence_interface(ctx->obj_skeleton, ctx);
+
+ if (ctx->obj_skeleton != NULL) {
+ g_dbus_object_manager_server_export(ctx->manager, G_DBUS_OBJECT_SKELETON(ctx->obj_skeleton));
+ /* register callback for each methods for geofence */
+ geofence = sloc_object_get_geofence(SLOC_OBJECT(ctx->obj_skeleton));
+ }
+ g_return_if_fail(geofence);
+
+ if (ctx->add_geofence_cb)
+ ctx->add_geofence_h = g_signal_connect(geofence, "handle-add-geofence", G_CALLBACK(on_add_geofence), ctx); /* user_data */
+ if (ctx->add_place_cb)
+ ctx->add_place_h = g_signal_connect(geofence, "handle-add-place", G_CALLBACK(on_add_place), ctx); /* user_data */
+ if (ctx->enable_geofence_cb)
+ ctx->enable_geofence_h = g_signal_connect(geofence, "handle-enable-geofence", G_CALLBACK(on_enable_geofence), ctx); /* user_data */
+ if (ctx->update_place_cb)
+ ctx->update_place_h = g_signal_connect(geofence, "handle-update-place", G_CALLBACK(on_update_place), ctx); /* user_data */
+ if (ctx->delete_geofence_cb)
+ ctx->delete_geofence_h = g_signal_connect(geofence, "handle-delete-geofence", G_CALLBACK(on_delete_geofence), ctx); /* user_data */
+ if (ctx->delete_place_cb)
+ ctx->delete_place_h = g_signal_connect(geofence, "handle-delete-place", G_CALLBACK(on_delete_place), ctx); /* user_data */
+ if (ctx->start_geofence_cb)
+ ctx->start_geofence_h = g_signal_connect(geofence, "handle-start-geofence", G_CALLBACK(on_start_geofence), ctx); /* user_data */
+ if (ctx->stop_geofence_cb)
+ ctx->stop_geofence_h = g_signal_connect(geofence, "handle-stop-geofence", G_CALLBACK(on_stop_geofence), ctx); /* user_data */
+ if (ctx->getplacename_geofence_cb)
+ ctx->getplacename_geofence_h = g_signal_connect(geofence, "handle-get-place-name", G_CALLBACK(on_getplacename_geofence), ctx);
+ if (ctx->getlist_geofence_cb)
+ ctx->getlist_geofence_h = g_signal_connect(geofence, "handle-get-list", G_CALLBACK(on_getlist_geofence), ctx); /*user_data */
+ if (ctx->getplacelist_geofence_cb)
+ ctx->getplacelist_geofence_h = g_signal_connect(geofence, "handle-get-place-list", G_CALLBACK(on_getplacelist_geofence), ctx);
+ g_object_unref(geofence);
+
+ ctx->owner_changed_id = g_dbus_connection_signal_subscribe(conn, "org.freedesktop.DBus", "org.freedesktop.DBus", "NameOwnerChanged", "/org/freedesktop/DBus", NULL, G_DBUS_SIGNAL_FLAGS_NONE, on_name_owner_changed, ctx, NULL);
+ g_dbus_object_manager_server_set_connection(ctx->manager, conn);
+ GEOFENCE_DBUS_SERVER_LOGD("done to acquire the dbus");
+}
+
+static void on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+ GEOFENCE_DBUS_SERVER_SECLOG("Geofence Server: Acquired the name <%s> on the system bus", name);
+}
+
+static void on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+ GEOFENCE_DBUS_SERVER_SECLOG("Geofence Server: Lost the name <%s> on the system bus", name);
+}
+
+EXPORT_API int geofence_dbus_server_send_geofence_inout_changed(geofence_dbus_server_h geofence_dbus_server, const gchar *app_id, gint fence_id, gint access_type, gint fence_state)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("geofence_dbus_server_send_geofence_inout_changed");
+ g_return_val_if_fail(geofence_dbus_server, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER);
+
+ geofence_dbus_server_s *handle = (geofence_dbus_server_s *)geofence_dbus_server;
+ g_return_val_if_fail(handle->obj_skeleton, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER);
+
+ SLocGeofence *geofence = NULL;
+ geofence = sloc_object_get_geofence(SLOC_OBJECT(handle->obj_skeleton));
+ g_return_val_if_fail(geofence, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER);
+
+ sloc_geofence_emit_geofence_inout(geofence, app_id, fence_id, access_type, fence_state);
+ g_object_unref(geofence);
+
+ return GEOFENCE_DBUS_SERVER_ERROR_NONE;
+}
+
+EXPORT_API int geofence_dbus_server_send_geofence_event_changed(geofence_dbus_server_h geofence_dbus_server, gint place_id, gint fence_id, gint access_type, const gchar *app_id, gint error, gint state)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("geofence_dbus_server_send_geofence_event_changed");
+ g_return_val_if_fail(geofence_dbus_server, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER);
+ geofence_dbus_server_s *handle = (geofence_dbus_server_s *)geofence_dbus_server;
+ g_return_val_if_fail(handle->obj_skeleton, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER);
+
+ SLocGeofence *geofence = NULL;
+ geofence = sloc_object_get_geofence(SLOC_OBJECT(handle->obj_skeleton));
+ g_return_val_if_fail(geofence, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER);
+
+ sloc_geofence_emit_geofence_event(geofence, place_id, fence_id, access_type, app_id, error, state);
+ g_object_unref(geofence);
+
+ return GEOFENCE_DBUS_SERVER_ERROR_NONE;
+}
+
+static void _glib_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data)
+{
+ geofence_dbus_server_s *server = (geofence_dbus_server_s *)user_data;
+ if (server != NULL)
+ GEOFENCE_DBUS_SERVER_LOGD("server->manager (%p)", server->manager);
+ GEOFENCE_DBUS_SERVER_LOGE("GLIB[%d] : %s", log_level, msg);
+}
+
+EXPORT_API int geofence_dbus_server_create(char *service_name, char *service_path, char *name, char *description, geofence_dbus_server_h *geofence_dbus_server, GeofenceAddGeofenceCB add_geofence_cb, GeofenceAddPlaceCB add_place_cb, GeofenceEnableGeofenceCB enable_geofence_cb, GeofenceUpdatePlaceCB update_place_cb, GeofenceDeleteGeofenceCB delete_geofence_cb, GeofenceDeletePlaceCB delete_place_cb, GeofenceGetPlaceNameGeofenceCB getplacename_geofence_cb, GeofenceGetlistGeofenceCB getlist_geofence_cb, GeofenceGetPlaceListGeofenceCB getplacelist_geofence_cb, GeofenceStartGeofenceCB start_geofence_cb, GeofenceStopGeofenceCB stop_geofence_cb, gpointer userdata)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("geofence_dbus_server_create");
+ g_return_val_if_fail(service_name, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER);
+ g_return_val_if_fail(service_path, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER);
+ g_return_val_if_fail(geofence_dbus_server, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER);
+
+ int ret = GEOFENCE_DBUS_SERVER_ERROR_NONE;
+
+ geofence_dbus_server_s *server = g_new0(geofence_dbus_server_s, 1);
+ g_return_val_if_fail(server, GEOFENCE_DBUS_SERVER_ERROR_MEMORY);
+
+ g_log_set_default_handler(_glib_log, server);
+
+ server->service_name = g_strdup(service_name);
+ server->service_path = g_strdup(service_path);
+ server->manager = g_dbus_object_manager_server_new(server->service_path);
+
+ if (name)
+ server->name = g_strdup(name);
+ if (description)
+ server->description = g_strdup(description);
+
+ server->connections = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ server->userdata = userdata;
+
+ /* add gefence callbacks */
+ server->add_geofence_cb = add_geofence_cb;
+ server->add_place_cb = add_place_cb;
+ server->enable_geofence_cb = enable_geofence_cb;
+ server->update_place_cb = update_place_cb;
+ server->delete_geofence_cb = delete_geofence_cb;
+ server->delete_place_cb = delete_place_cb;
+ server->getplacename_geofence_cb = getplacename_geofence_cb;
+ server->getlist_geofence_cb = getlist_geofence_cb;
+ server->getplacelist_geofence_cb = getplacelist_geofence_cb;
+ server->start_geofence_cb = start_geofence_cb;
+ server->stop_geofence_cb = stop_geofence_cb;
+
+ server->owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, service_name, G_BUS_NAME_OWNER_FLAGS_REPLACE, on_bus_acquired, on_name_acquired, on_name_lost, server, NULL);
+ GEOFENCE_DBUS_SERVER_LOGD("g_bus_own_name id=[%d]", server->owner_id);
+ *geofence_dbus_server = (geofence_dbus_server_h *) server;
+
+ return ret;
+}
+
+EXPORT_API int geofence_dbus_server_destroy(geofence_dbus_server_h geofence_dbus_server)
+{
+ GEOFENCE_DBUS_SERVER_LOGD("geofence_dbus_server_destroy");
+ g_return_val_if_fail(geofence_dbus_server, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER);
+
+ geofence_dbus_server_s *handle = (geofence_dbus_server_s *)geofence_dbus_server;
+ int ret = GEOFENCE_DBUS_SERVER_ERROR_NONE;
+ g_bus_unown_name(handle->owner_id);
+ if (handle->prev_owner) {
+ g_free(handle->prev_owner);
+ handle->prev_owner = NULL;
+ }
+ /* disconnect geofence callbacks */
+ SLocGeofence *geofence = NULL;
+ geofence = sloc_object_get_geofence(SLOC_OBJECT(handle->obj_skeleton));
+ g_return_val_if_fail(geofence, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER);
+
+ if (handle->add_geofence_h) {
+ g_signal_handler_disconnect(geofence, handle->add_geofence_h);
+ handle->add_geofence_h = 0;
+ }
+ if (handle->add_place_h) {
+ g_signal_handler_disconnect(geofence, handle->add_place_h);
+ handle->add_place_h = 0;
+ }
+ if (handle->enable_geofence_h) {
+ g_signal_handler_disconnect(geofence, handle->enable_geofence_h);
+ handle->enable_geofence_h = 0;
+ }
+ if (handle->update_place_h) {
+ g_signal_handler_disconnect(geofence, handle->update_place_h);
+ handle->update_place_h = 0;
+ }
+ if (handle->delete_geofence_h) {
+ g_signal_handler_disconnect(geofence, handle->delete_geofence_h);
+ handle->delete_geofence_h = 0;
+ }
+ if (handle->delete_place_h) {
+ g_signal_handler_disconnect(geofence, handle->delete_place_h);
+ handle->delete_place_h = 0;
+ }
+ if (handle->start_geofence_h) {
+ g_signal_handler_disconnect(geofence, handle->start_geofence_h);
+ handle->start_geofence_h = 0;
+ }
+ if (handle->stop_geofence_h) {
+ g_signal_handler_disconnect(geofence, handle->stop_geofence_h);
+ handle->stop_geofence_h = 0;
+ }
+ if (handle->getplacename_geofence_h) {
+ g_signal_handler_disconnect(geofence, handle->getplacename_geofence_h);
+ handle->getplacename_geofence_h = 0;
+ }
+ if (handle->getlist_geofence_h) {
+ g_signal_handler_disconnect(geofence, handle->getlist_geofence_h);
+ handle->getlist_geofence_h = 0;
+ }
+ if (handle->getplacelist_geofence_h) {
+ g_signal_handler_disconnect(geofence, handle->getplacelist_geofence_h);
+ handle->getplacelist_geofence_h = 0;
+ }
+ g_object_unref(geofence);
+
+ if (handle->manager) {
+ if (handle->owner_changed_id) {
+ g_dbus_connection_signal_unsubscribe(g_dbus_object_manager_server_get_connection(handle->manager), handle->owner_changed_id);
+ handle->owner_changed_id = 0;
+ }
+ g_object_unref(handle->manager);
+ handle->manager = NULL;
+ }
+
+ g_hash_table_destroy(handle->connections);
+ g_free(handle);
+
+ return ret;
+}