From 5315689b24705313e6e1748586d95e7fdd29f65e Mon Sep 17 00:00:00 2001 From: "jk7744.park" Date: Sat, 24 Oct 2015 16:43:55 +0900 Subject: [PATCH] tizen 2.4 release --- .gitignore | 2 + AUTHORS | 5 + CMakeLists.txt | 45 +++ LICENSE | 204 ++++++++++ geofence-dbus.pc.in | 11 + geofence/CMakeLists.txt | 16 + geofence/include/geofence_client.h | 232 +++++++++++ geofence/include/geofence_client_priv.h | 44 +++ geofence/src/geofence_client.c | 598 +++++++++++++++++++++++++++++ introspection/gen.sh | 8 + introspection/geofence.xml | 82 ++++ libgeofence-dbus.manifest | 5 + packaging/geofence-dbus.changes | 71 ++++ packaging/geofence-dbus.spec | 76 ++++ server/CMakeLists.txt | 27 ++ server/include/geofence_dbus_server.h | 172 +++++++++ server/include/geofence_dbus_server_priv.h | 44 +++ server/res/geofence-dbus-server.conf | 128 ++++++ server/src/geofence_dbus_server.c | 587 ++++++++++++++++++++++++++++ 19 files changed, 2357 insertions(+) create mode 100644 .gitignore create mode 100755 AUTHORS create mode 100755 CMakeLists.txt create mode 100755 LICENSE create mode 100755 geofence-dbus.pc.in create mode 100644 geofence/CMakeLists.txt create mode 100644 geofence/include/geofence_client.h create mode 100644 geofence/include/geofence_client_priv.h create mode 100755 geofence/src/geofence_client.c create mode 100755 introspection/gen.sh create mode 100644 introspection/geofence.xml create mode 100755 libgeofence-dbus.manifest create mode 100644 packaging/geofence-dbus.changes create mode 100644 packaging/geofence-dbus.spec create mode 100644 server/CMakeLists.txt create mode 100644 server/include/geofence_dbus_server.h create mode 100644 server/include/geofence_dbus_server_priv.h create mode 100644 server/res/geofence-dbus-server.conf create mode 100644 server/src/geofence_dbus_server.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f05287e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.[oa] +*~ diff --git a/AUTHORS b/AUTHORS new file mode 100755 index 0000000..0bc9dd3 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,5 @@ +Woo-Young Kim +Bono Koo +Ki-Sun SHIN +bosung kwak +Areum Choi \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..32b10f7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,45 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(geofence-dbus C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${prefix}/lib") +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) + +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(" -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}) + +CONFIGURE_FILE(geofence-dbus.pc.in geofence-dbus.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/geofence-dbus.pc DESTINATION lib/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 100755 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 100755 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..a21cc66 --- /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 lib COMPONENT Runtime) diff --git a/geofence/include/geofence_client.h b/geofence/include/geofence_client.h new file mode 100644 index 0000000..2d73956 --- /dev/null +++ b/geofence/include/geofence_client.h @@ -0,0 +1,232 @@ +/* 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 +#include + +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_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, + GEOFENCE_CLIENT_ERROR_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, + GEOFENCE_CLIENT_ACCESS_DENIED = TIZEN_ERROR_PERMISSION_DENIED, + GEOFENCE_CLIENT_ERROR_CONNECTION = TIZEN_ERROR_GEOFENCE_MANAGER | 0x01, + GEOFENCE_CLIENT_ERROR_DBUS_CALL = TIZEN_ERROR_GEOFENCE_MANAGER | 0x06, +} 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); + +#if 0 +/** +* @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); +#endif + +/** +* @brief API to add the geofence. This will call the server API. +* @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID +* @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, gchar *app_id, 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] app_id - Caller's application ID +* @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, gchar *appid, const gchar *place_name); + +/** +* @brief API to update the place. This will call the server API +* @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID +* @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, gchar *app_id, 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] app_id - Caller's application ID +* @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, gchar *app_id, gint fence_id); + +/** +* @brief API to delete the place from the server +* @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID +* @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, gchar *app_id, 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, gchar *app_id, gint place_id, gchar **place_name, gint *error_code); + +/** +* @brief API to get the fence list +* @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID +* @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_geofences(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id, GVariantIter **iter, gint *fence_cnt, gint *error_code); + +/** +* @brief API to get the place list +* @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID +* @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_places(geofence_client_dbus_h geofence_client, gchar *app_id, GVariantIter **iter, gint *fence_cnt, int *error_code); + +/** +* @brief API to enable the geofence. This will call the server API +* @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID +* @param[in] fence_id - Unique id of the fence +* @param[in] bEnable - enable flag for geofence +*/ +int geo_client_enable_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint geofence_id, gboolean onoff); + +/** +* @brief API to start the geofence service on a particular geofence +* @param[in] app_id - Caller's application ID +* @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, gchar *app_id, gint fence_id); + +/** +* @brief API to stop the geofence service on a particular geofence +* @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID +* @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, gchar *app_id, gint fence_id); + +/** +* @brief API to start the client and make a subscription to the server +* @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(geofence_client_dbus_h geofence_client, geofence_client_cb 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..9b6eb68 --- /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 +#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 100755 index 0000000..a37ea4f --- /dev/null +++ b/geofence/src/geofence_client.c @@ -0,0 +1,598 @@ +/* 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 +#include "geofence_client.h" +#include "geofence_client_priv.h" + +#define GEOFENCE_SERVICE_NAME "org.tizen.lbs.Providers.GeofenceServer" +#define GEOFENCE_SERVICE_PATH "/org/tizen/lbs/Providers/GeofenceServer" +#define GEOFENCE_INTERFACE_NAME "org.tizen.lbs.Geofence" + + +typedef struct _geofence_client_dbus_s { + GDBusConnection *conn; + gchar *service_name; + gchar *service_path; + gchar *signal_path; + int geofence_evt_id; + int geofence_evt_status_id; + geofence_client_cb user_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, gchar *app_id, gint place_id, gint geofence_type, gdouble latitude, gdouble longitude, gint radius, const gchar *address, const gchar *bssid, const gchar *ssid) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + 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; + int fence_id = -1; + + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); + if (proxy) { + GEOFENCE_CLIENT_LOGD("proxy: %p", proxy); + + 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 { + if (error) { + GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); + g_error_free(error); + } + + } + GEOFENCE_CLIENT_LOGD("fence_id: %d", fence_id); + + return fence_id; +} + +EXPORT_API int geo_client_delete_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint fence_id) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + 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; + int ret = GEOFENCE_CLIENT_ERROR_NONE; + + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); + 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 { + if (error) { + GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); + g_error_free(error); + ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; + } + } + + return ret; +} + +EXPORT_API int geo_client_get_geofences(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id, GVariantIter **iter, gint *fence_cnt, gint *error_code) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + 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; + int ret = GEOFENCE_CLIENT_ERROR_NONE; + GVariantIter *iterator; + int new_error_code = 0; + int new_fence_cnt = 0; + + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); + if (proxy) { + GEOFENCE_CLIENT_LOGD("proxy: %p", proxy); + + reg = g_dbus_proxy_call_sync(proxy, "GetGeofences", g_variant_new("(is)", place_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (reg) { + g_variant_get(reg, "(iiaa{sv})", &new_fence_cnt, &new_error_code, &iterator); + *error_code = new_error_code; + *fence_cnt = new_fence_cnt; + 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 { + if (error) { + GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); + g_error_free(error); + ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; + } + } + + return ret; +} + +EXPORT_API int geo_client_enable_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint geofence_id, gboolean onoff) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + 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; + int ret = GEOFENCE_CLIENT_ERROR_NONE; + + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); + if (proxy) { + g_dbus_proxy_call(proxy, "EnableGeofence", g_variant_new("(isb)", geofence_id, app_id, onoff), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); + } else { + if (error) { + GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); + g_error_free(error); + ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; + } + } + + return ret; +} + +EXPORT_API int geo_client_start_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint geofence_id) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + 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; + int ret = GEOFENCE_CLIENT_ERROR_NONE; + + GEOFENCE_CLIENT_LOGD("handle->conn: %p, geofence_id", handle->conn, geofence_id); + + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); + 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 { + if (error) { + GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); + g_error_free(error); + ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; + } + } + return ret; +} + +EXPORT_API int geo_client_stop_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint geofence_id) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); + + geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; + int ret = GEOFENCE_CLIENT_ERROR_NONE; + GError *error = NULL; + 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, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); + 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 { + if (error) { + GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); + g_error_free(error); + ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; + } + } + + return ret; +} + +EXPORT_API int geo_client_add_place(geofence_client_dbus_h geofence_client, gchar *app_id, const gchar *place_name) +{ + /* add fence interface between App & geofence-server */ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + 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; + int place_id = -1; + + GEOFENCE_CLIENT_LOGI("APP ID: %s", app_id); + + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); + if (proxy) { + GEOFENCE_CLIENT_LOGD("proxy: %p", proxy); + 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 { + if (error) { + GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); + g_error_free(error); + } + } + + GEOFENCE_CLIENT_LOGD("place_id: %d", place_id); + + return place_id; +} + +EXPORT_API int geo_client_update_place(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id, const gchar *place_name) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + 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; + int ret = GEOFENCE_CLIENT_ERROR_NONE; + + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); + if (proxy) { + 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 { + if (error) { + GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); + g_error_free(error); + ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; + } + } + + return ret; +} + +EXPORT_API int geo_client_delete_place(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + 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; + int ret = GEOFENCE_CLIENT_ERROR_NONE; + + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); + 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 { + if (error) { + GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); + g_error_free(error); + ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; + } + } + + return ret; +} + +EXPORT_API int geo_client_get_place_name(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id, gchar **place_name, gint *error_code) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + 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; + int ret = GEOFENCE_CLIENT_ERROR_NONE; + char *new_place_name = NULL; + int new_error_code = 0; + + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); + 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)", &new_error_code, &new_place_name); + *error_code = new_error_code; + *place_name = g_strdup(new_place_name); + g_free(new_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 { + if (error) { + GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); + g_error_free(error); + ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; + } + } + + return ret; +} + +EXPORT_API int geo_client_get_places(geofence_client_dbus_h geofence_client, gchar *app_id, GVariantIter **iter, gint *place_cnt, gint *error_code) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + 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; + + int ret = GEOFENCE_CLIENT_ERROR_NONE; + GVariantIter *iterator; + int new_error_code = 0; + int new_place_cnt = 0; + + GEOFENCE_CLIENT_LOGD("handle->conn: %p", handle->conn); + GEOFENCE_CLIENT_LOGI("APP ID: %s", app_id); + + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); + if (proxy) { + reg = g_dbus_proxy_call_sync(proxy, "GetPlaces", g_variant_new("(s)", app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (reg) { + g_variant_get(reg, "(iiaa{sv})", &new_place_cnt, &new_error_code, &iterator); + *place_cnt = new_place_cnt; + *error_code = new_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 { + if (error) { + GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); + g_error_free(error); + ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; + } + } + + return ret; +} + +EXPORT_API int geo_client_start(geofence_client_dbus_h geofence_client, geofence_client_cb callback, void *user_data) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); + + geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; + gchar *signal_path = NULL; + + handle->service_name = g_strdup(GEOFENCE_SERVICE_NAME); + handle->service_path = g_strdup(GEOFENCE_SERVICE_PATH); + handle->signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); + GEOFENCE_CLIENT_LOGD("Object Path [%s]", handle->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, GEOFENCE_INTERFACE_NAME, "GeofenceInout", handle->signal_path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, __geofence_signal_callback, handle, NULL); + + if (handle->geofence_evt_id) { + GEOFENCE_CLIENT_LOGD("Listening GeofenceInout"); + } else { + GEOFENCE_CLIENT_LOGD("Fail to listen GeofenceInout"); + } + + handle->geofence_evt_status_id = g_dbus_connection_signal_subscribe(handle->conn, handle->service_name, GEOFENCE_INTERFACE_NAME, "GeofenceEvent", handle->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"); + } else { + GEOFENCE_CLIENT_LOGD("Fail to listen Geofence event"); + return GEOFENCE_CLIENT_ERROR_DBUS_CALL; + } + } + g_free(signal_path); + + +#if SUPPORT_MULTI_CLIENT + GVariant *param = NULL; + GVariantBuilder *builder = NULL; + + + 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); +#endif + + return GEOFENCE_CLIENT_ERROR_NONE; +} + +static void __geo_client_signal_unsubcribe(geofence_client_dbus_h geofence_client) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + + 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_stop(geofence_client_dbus_h geofence_client) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + + geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;; + g_return_val_if_fail(handle, GEOFENCE_CLIENT_ERROR_PARAMETER); + + __geo_client_signal_unsubcribe(handle); + +#if SUPPORT_MULTI_CLIENT + GVariant *param = NULL; + GVariantBuilder *builder = NULL; + + /* 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); + +#endif + + return GEOFENCE_CLIENT_ERROR_NONE; +} + +static int __geofence_client_create_connection(geofence_client_dbus_s *client) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + + g_return_val_if_fail(client, GEOFENCE_CLIENT_ERROR_PARAMETER); + GError *error = NULL; + +#if 0 + client->conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); +#endif + + char *bus_addr = NULL; + bus_addr = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!bus_addr) { + GEOFENCE_CLIENT_LOGD("Fail to get addr of bus."); + return GEOFENCE_CLIENT_ERROR_CONNECTION; + } + + GEOFENCE_CLIENT_LOGD("bus_addr: %s", bus_addr); + + client->conn = g_dbus_connection_new_for_address_sync(bus_addr, + G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | + G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION, + NULL, NULL, &error); + g_free(bus_addr); + + 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; + } + 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("ENTER >>>"); + + 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("ENTER >>>"); + 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; + } + g_free(handle->service_path); + g_free(handle->service_name); + g_free(handle->signal_path); + g_free(handle); + + return GEOFENCE_CLIENT_ERROR_NONE; +} diff --git a/introspection/gen.sh b/introspection/gen.sh new file mode 100755 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..391f37e --- /dev/null +++ b/introspection/geofence.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libgeofence-dbus.manifest b/libgeofence-dbus.manifest new file mode 100755 index 0000000..97e8c31 --- /dev/null +++ b/libgeofence-dbus.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/geofence-dbus.changes b/packaging/geofence-dbus.changes new file mode 100644 index 0000000..d79d512 --- /dev/null +++ b/packaging/geofence-dbus.changes @@ -0,0 +1,71 @@ +[Version] geofence-dbus_0.3.0 +[date] 06 Jul 2015 +[Title] Simplied API signature. +[Developer] Young-Ae Kang + +============================================================================== + +[Version] geofence-dbus_0.2.2 +[date] 24 December 2014 +[Title] Fence name has been added in the geofence dbus module +[Issue#] NA +[Problem] NA +[Cause] New feature need to be added to give name to the fence +[Solution] Fence name has been added in all modules +[Developer] Karthik Paulraj + +============================================================================== + +[Version] geofence-dbus_0.2.1 +[date] 29 August 2014 +[Title] remove deprecated code +[Issue#] NA +[Problem] build error +[Cause] change the api for app_manager_get_package +[Solution] remove app_manager_get_package +[Developer] Kisun SHIN + +================================================================================ +[Version] geofence-dbus_0.2.0 +[date] 25 June 2014 +[Title] separate create_client & start_client / destroy_client & stop_client +[Issue#] NA +[Problem] got the error when destroyed +[Cause] missing start / stop client +[Solution] separate start / stop client +[Developer] Kisun SHIN + +================================================================================ + +[Version] geofence-dbus_0.1.3 +[date] 19 June 2014 +[Title] Remove g_dbus_connection_signal_unsubscribe when geofence stop +[Issue#] NA +[Problem] cannot start geofence service after stopped once +[Cause] whenever stopped geofecne, signal is disconnected. +[Solution] do not disconnect the geofence signal. +[Developer] Wooyoung KIM + +================================================================================ +[Version] geofence-dbus_0.1.2 +[date] 27 May 2014 +[Title] Remove cb in start / Add cb in create +[Issue#] NA +[Problem] multi callback when multi geofence +[Cause] Whenever start, callback is registered. +[Solution] register the callback when create once. +[Developer] Kisun SHIN + +================================================================================ + +[Version] geofence-dbus_0.1.1 +[date] 12 May 2014 +[Title] Git update +[Issue#] NA +[Problem] NA +[Cause] NA +[Solution] NA +[Developer] Areum Choi + +================================================================================ + diff --git a/packaging/geofence-dbus.spec b/packaging/geofence-dbus.spec new file mode 100644 index 0000000..4da02dd --- /dev/null +++ b/packaging/geofence-dbus.spec @@ -0,0 +1,76 @@ +Name: geofence-dbus +Summary: Dbus interface for Geofence service +Version: 0.3.0 +Release: 1 +Group: Framework/Location +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(gio-2.0) +BuildRequires: pkgconfig(gio-unix-2.0) +BuildRequires: pkgconfig(capi-base-common) + +%description +Geofence dbus interface + +%package -n libgeofence-dbus +Summary: Geofence dbus library +Group: TO_BE/FILLED_IN +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} \ + +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..c3be0df --- /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 lib 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..7448c2e --- /dev/null +++ b/server/include/geofence_dbus_server.h @@ -0,0 +1,172 @@ +/* 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 + +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; + + +#if SUPPORT_MULTI_CLIENT +/** +* @brief Callback for setting the options +*/ +typedef void (*GeofenceDbusSetOptionsCB)(GVariant *options, gpointer userdata); +#endif + +/** +* @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 deleting the geofence +*/ +typedef void (*GeofenceDeleteGeofenceCB)(gint fence_id, const gchar *app_id, gpointer userdata); + +/** +* @brief Callback for getting the fence list +*/ +typedef GVariant *(*GeofenceGetGeofencesCB)(int place_id, const gchar *app_id, int *fence_cnt, int *error_code, 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 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); + + +/* for place callbacks */ + +/** +* @brief Callback for adding the place +*/ +typedef gint(*GeofenceAddPlaceCB)(const gchar *app_id, const gchar *place_name, gpointer userdata); + +/** +* @brief Callback for deleting the place +*/ +typedef void (*GeofenceDeletePlaceCB)(gint place_id, const gchar *app_id, 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 getting the place name +*/ +typedef void (*GeofenceGetPlaceNameCB)(int place_id, const gchar *app_id, char **place_name, int *error_code, gpointer userdata); + +/** +* @brief Callback for getting the place list +*/ +typedef GVariant *(*GeofenceGetPlacesCB)(const gchar *app_id, int *fence_cnt, int *error_code, gpointer userdata); + +/** +* @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); + +typedef struct { +#if SUPPORT_MULTI_CLIENT + /* size_t size; */ + GeofenceDbusSetOptionsCB set_options_cb; +#endif + GeofenceDbusShutdownCB shutdown_cb; + + GeofenceAddGeofenceCB add_geofence_cb; + GeofenceDeleteGeofenceCB delete_geofence_cb; + GeofenceGetGeofencesCB get_geofences_cb; + GeofenceEnableGeofenceCB enable_geofence_cb; + GeofenceStartGeofenceCB start_geofence_cb; + GeofenceStopGeofenceCB stop_geofence_cb; + + GeofenceAddPlaceCB add_place_cb; + GeofenceUpdatePlaceCB update_place_cb; + GeofenceDeletePlaceCB delete_place_cb; + GeofenceGetPlaceNameCB get_place_name_cb; + GeofenceGetPlacesCB get_places_cb; +} geofence_dbus_callback_s; + + +/** +* @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] geofence_dbus_server - Dbus server pointer +* @param[in] geofence_dbus_callback - Callback for all dbus interface +* @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(geofence_dbus_server_h *geofence_dbus_server, geofence_dbus_callback_s *geofence_dbus_callback, 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..00851cc --- /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 +#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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/src/geofence_dbus_server.c b/server/src/geofence_dbus_server.c new file mode 100644 index 0000000..3e86c03 --- /dev/null +++ b/server/src/geofence_dbus_server.c @@ -0,0 +1,587 @@ +/* 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 +#include + +#include "generated-code.h" +#include "geofence_dbus_server.h" +#include "geofence_dbus_server_priv.h" + + +#define GEOFENCE_SERVICE_NAME "org.tizen.lbs.Providers.GeofenceServer" +#define GEOFENCE_SERVICE_PATH "/org/tizen/lbs/Providers/GeofenceServer" + +typedef struct _geofence_dbus_signal_s { + guint add_geofence_h; + guint delete_geofence_h; + guint get_geofences_h; + guint enable_geofence_h; + guint start_geofence_h; + guint stop_geofence_h; + + guint add_place_h; + guint update_place_h; + guint delete_place_h; + guint get_place_name_h; + guint get_places_h; +} geofence_dbus_signal_s; + +typedef struct _geofence_dbus_server_s { + /* Geofence Dbus Server info */ + gchar *service_name; + gchar *prev_owner; + gchar *service_path; + gint status; + GDBusObjectManagerServer *manager; + SLocObjectSkeleton *obj_skeleton; + GHashTable *connections; + gpointer userdata; + 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; + + geofence_dbus_signal_s *dbus_signal; + geofence_dbus_callback_s *dbus_callback; +} geofence_dbus_server_s; + +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; +} + +/* + * 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("ENTER >>>"); + + /* 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 = -1; + if (ctx->dbus_callback && ctx->dbus_callback->add_geofence_cb) { + fence_id = ctx->dbus_callback->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"); + } + GEOFENCE_DBUS_SERVER_LOGD("fence_id: %d", fence_id); + sloc_geofence_complete_add_geofence(geofence, invocation, fence_id); + 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->dbus_callback && ctx->dbus_callback->delete_geofence_cb) { + ctx->dbus_callback->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_get_geofences(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint place_id, const gchar *app_id, gpointer user_data) +{ + GEOFENCE_DBUS_SERVER_LOGD("ENTER >>>"); + + /* 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->dbus_callback && ctx->dbus_callback->get_geofences_cb) { + geofence_info = ctx->dbus_callback->get_geofences_cb(place_id, app_id, &fence_cnt, &error_code, ctx->userdata); + GEOFENCE_DBUS_SERVER_LOGD("getlist_geofence_cb called"); + } + sloc_geofence_complete_get_geofences(geofence, invocation, fence_cnt, error_code, geofence_info); + 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->dbus_callback && ctx->dbus_callback->enable_geofence_cb) { + ctx->dbus_callback->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_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->dbus_callback && ctx->dbus_callback->start_geofence_cb) { + ctx->dbus_callback->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->dbus_callback && ctx->dbus_callback->stop_geofence_cb) { + ctx->dbus_callback->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 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 = -1; + if (ctx->dbus_callback && ctx->dbus_callback->add_place_cb) { + place_id = ctx->dbus_callback->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_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->dbus_callback && ctx->dbus_callback->update_place_cb) { + ctx->dbus_callback->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_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->dbus_callback && ctx->dbus_callback->delete_place_cb) { + ctx->dbus_callback->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_get_place_name(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->dbus_callback && ctx->dbus_callback->add_place_cb) { + ctx->dbus_callback->get_place_name_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_get_places(SLocGeofence *geofence, GDBusMethodInvocation *invocation, const gchar *app_id, gpointer user_data) +{ + GEOFENCE_DBUS_SERVER_LOGD("ENTER >>>"); + + /* 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->dbus_callback && ctx->dbus_callback->add_place_cb) { + place_info = ctx->dbus_callback->get_places_cb(app_id, &place_cnt, &error_code, ctx->userdata); + GEOFENCE_DBUS_SERVER_LOGD("get_places_cb called"); + } + sloc_geofence_complete_get_places(geofence, invocation, place_cnt, error_code, place_info); + return TRUE; +} + +/*#if SUPPORT_MULTI_CLIENT */ +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"); + } + +#if SUPPORT_MULTI_CLIENT + gboolean shutdown_arr = FALSE; + + if (g_hash_table_size(ctx->connections) == 0) { + GEOFENCE_DBUS_SERVER_SECLOG("Hash table size is zero, Now shutdown provider[%s]", ctx->prev_owner); + shutdown_arr = TRUE; + } else { + GEOFENCE_DBUS_SERVER_SECLOG("Hash table size is not zero"); + } + + if (ctx->shutdown_cb) { + ctx->shutdown_cb(ctx->userdata, shutdown_arr); + GEOFENCE_DBUS_SERVER_LOGD("shutdown_cb called..[%d]", shutdown_arr); + } + +#endif + GEOFENCE_DBUS_SERVER_LOGD("###### A client[%s] is abnormally shut down ########", client); + + + 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); + } +} +/*#endif */ + +static void on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data) +{ + geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data; + g_return_if_fail(ctx); + + 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)); + } + if (geofence == NULL) { + GEOFENCE_DBUS_SERVER_LOGE("Can't create geofence object"); + return; + } + + geofence_dbus_callback_s *dbus_callback = ctx->dbus_callback; + geofence_dbus_signal_s *dbus_signal = g_new0(geofence_dbus_signal_s, 1); + g_return_val_if_fail(dbus_signal, GEOFENCE_DBUS_SERVER_ERROR_MEMORY); + + if (dbus_callback->add_geofence_cb) + dbus_signal->add_geofence_h = g_signal_connect(geofence, "handle-add-geofence", G_CALLBACK(on_add_geofence), ctx); + if (dbus_callback->delete_geofence_cb) + dbus_signal->delete_geofence_h = g_signal_connect(geofence, "handle-delete-geofence", G_CALLBACK(on_delete_geofence), ctx); + if (dbus_callback->get_geofences_cb) + dbus_signal->get_geofences_h = g_signal_connect(geofence, "handle-get-geofences", G_CALLBACK(on_get_geofences), ctx); + if (dbus_callback->enable_geofence_cb) + dbus_signal->enable_geofence_h = g_signal_connect(geofence, "handle-enable-geofence", G_CALLBACK(on_enable_geofence), ctx); + if (dbus_callback->start_geofence_cb) + dbus_signal->start_geofence_h = g_signal_connect(geofence, "handle-start-geofence", G_CALLBACK(on_start_geofence), ctx); + if (dbus_callback->stop_geofence_cb) + dbus_signal->stop_geofence_h = g_signal_connect(geofence, "handle-stop-geofence", G_CALLBACK(on_stop_geofence), ctx); + + if (dbus_callback->add_place_cb) + dbus_signal->add_place_h = g_signal_connect(geofence, "handle-add-place", G_CALLBACK(on_add_place), ctx); + if (dbus_callback->update_place_cb) + dbus_signal->update_place_h = g_signal_connect(geofence, "handle-update-place", G_CALLBACK(on_update_place), ctx); + if (dbus_callback->delete_place_cb) + dbus_signal->delete_place_h = g_signal_connect(geofence, "handle-delete-place", G_CALLBACK(on_delete_place), ctx); + if (dbus_callback->get_place_name_cb) + dbus_signal->get_place_name_h = g_signal_connect(geofence, "handle-get-place-name", G_CALLBACK(on_get_place_name), ctx); + if (dbus_callback->get_places_cb) + dbus_signal->get_places_h = g_signal_connect(geofence, "handle-get-places", G_CALLBACK(on_get_places), ctx); + + ctx->dbus_signal = dbus_signal; + + g_object_unref(geofence); + + /*#if SUPPORT_MULTI_CLIENT //TODO: We need it? */ + 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); + /*#endif */ + + 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("ENTER >>>"); + 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("ENTER >>>"); + 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; +} + +/* Because of this, geofence-server's handler doesn't work. */ +#if 0 +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); +} +#endif + +EXPORT_API int geofence_dbus_server_create(geofence_dbus_server_h *geofence_dbus_server, geofence_dbus_callback_s *geofence_dbus_callback, gpointer userdata) +{ + GEOFENCE_DBUS_SERVER_LOGD("geofence_dbus_server_create"); + g_return_val_if_fail(geofence_dbus_server, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER); + g_return_val_if_fail(geofence_dbus_callback, 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(GEOFENCE_SERVICE_NAME); + server->service_path = g_strdup(GEOFENCE_SERVICE_PATH); + server->manager = g_dbus_object_manager_server_new(server->service_path); + server->connections = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + server->userdata = userdata; + + /* set gefence callbacks */ + server->dbus_callback = geofence_dbus_callback; + + server->owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, server->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_s *) 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 *server = (geofence_dbus_server_s *)geofence_dbus_server; + int ret = GEOFENCE_DBUS_SERVER_ERROR_NONE; + g_bus_unown_name(server->owner_id); + if (server->prev_owner) { + g_free(server->prev_owner); + server->prev_owner = NULL; + } + /* disconnect geofence callbacks */ + SLocGeofence *geofence = NULL; + geofence = sloc_object_get_geofence(SLOC_OBJECT(server->obj_skeleton)); + g_return_val_if_fail(geofence, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER); + + geofence_dbus_signal_s *handle = server->dbus_signal; + g_return_val_if_fail(handle, 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->delete_geofence_h) { + g_signal_handler_disconnect(geofence, handle->delete_geofence_h); + handle->delete_geofence_h = 0; + } + if (handle->get_geofences_h) { + g_signal_handler_disconnect(geofence, handle->get_geofences_h); + handle->get_geofences_h = 0; + } + if (handle->enable_geofence_h) { + g_signal_handler_disconnect(geofence, handle->enable_geofence_h); + handle->enable_geofence_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->add_place_h) { + g_signal_handler_disconnect(geofence, handle->add_place_h); + handle->add_place_h = 0; + } + if (handle->update_place_h) { + g_signal_handler_disconnect(geofence, handle->update_place_h); + handle->update_place_h = 0; + } + if (handle->delete_place_h) { + g_signal_handler_disconnect(geofence, handle->delete_place_h); + handle->delete_place_h = 0; + } + if (handle->get_place_name_h) { + g_signal_handler_disconnect(geofence, handle->get_place_name_h); + handle->get_place_name_h = 0; + } + if (handle->get_places_h) { + g_signal_handler_disconnect(geofence, handle->get_places_h); + handle->get_places_h = 0; + } + g_free(handle); + g_object_unref(geofence); + + if (server->manager) { + if (server->owner_changed_id) { + g_dbus_connection_signal_unsubscribe(g_dbus_object_manager_server_get_connection(server->manager), server->owner_changed_id); + server->owner_changed_id = 0; + } + g_object_unref(server->manager); + server->manager = NULL; + } + + g_hash_table_destroy(server->connections); + + g_free(server->service_name); + g_free(server->service_path); + + g_free(server); + + return ret; +} -- 2.7.4