diff options
author | Genie Kim <daejins.kim@samsung.com> | 2013-05-09 13:57:46 +0900 |
---|---|---|
committer | Genie Kim <daejins.kim@samsung.com> | 2013-05-09 14:00:32 +0900 |
commit | 56bc9cf8b06f8227e9c50c04e571290e8b4301fd (patch) | |
tree | c784fd14a7a1e28a72d32f94057f9d97cb385f6a | |
parent | 8e6db0b71d17ff4f343b3b2c81632973367ac718 (diff) | |
download | lbs-dbus-tizen_2.1.tar.gz lbs-dbus-tizen_2.1.tar.bz2 lbs-dbus-tizen_2.1.zip |
initialize lbs-dbus in RSAsubmit/tizen_2.1/20130514.071558submit/tizen/20130517.044934accepted/tizen/20130520.101057tizen_2.1
Change-Id: I438a6e5dca706947b7e36e6bef011b921e0016ce
-rw-r--r-- | AUTHORS | 4 | ||||
-rw-r--r-- | CMakeLists.txt | 40 | ||||
-rw-r--r-- | LICENSE | 204 | ||||
-rw-r--r-- | client/CMakeLists.txt | 17 | ||||
-rw-r--r-- | client/include/lbs_dbus_client.h | 61 | ||||
-rw-r--r-- | client/include/lbs_dbus_client_priv.h | 51 | ||||
-rw-r--r-- | client/src/lbs_dbus_client.c | 382 | ||||
-rw-r--r-- | introspection/gen.sh | 6 | ||||
-rw-r--r-- | introspection/lbs.xml | 23 | ||||
-rw-r--r-- | introspection/lbs_nmea.xml | 8 | ||||
-rw-r--r-- | introspection/lbs_position.xml | 15 | ||||
-rw-r--r-- | introspection/lbs_satellite.xml | 11 | ||||
-rw-r--r-- | lbs-dbus.pc.in | 11 | ||||
-rw-r--r-- | liblbs-dbus.manifest | 5 | ||||
-rw-r--r-- | packaging/lbs-dbus.spec | 73 | ||||
-rw-r--r-- | server/CMakeLists.txt | 27 | ||||
-rw-r--r-- | server/include/lbs_dbus_server.h | 92 | ||||
-rw-r--r-- | server/include/lbs_dbus_server_priv.h | 52 | ||||
-rw-r--r-- | server/res/lbs-dbus-server.conf | 96 | ||||
-rw-r--r-- | server/src/lbs_dbus_server.c | 625 |
20 files changed, 1803 insertions, 0 deletions
@@ -0,0 +1,4 @@ +Youngae Kang <youngae.kang@samsung.com> +Minjune Kim <sena06.kim@samsung.com> +Genie Kim <daejins.kim@samsung.com> +Ming Zhu <mingwu.zhu@samsung.com> diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0a7b659 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,40 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(lbs-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\\\")))\" ") + +MESSAGE(${CMAKE_C_FLAGS}) +MESSAGE(${CMAKE_EXE_LINKER_FLAGS}) + +# pkgconfig file +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +CONFIGURE_FILE(lbs-dbus.pc.in lbs-dbus.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lbs-dbus.pc DESTINATION lib/pkgconfig) + +INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME liblbs-dbus) + +ADD_SUBDIRECTORY(client) +ADD_SUBDIRECTORY(server) @@ -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/client/CMakeLists.txt b/client/CMakeLists.txt new file mode 100644 index 0000000..160c80d --- /dev/null +++ b/client/CMakeLists.txt @@ -0,0 +1,17 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(lbs-dbus-client C) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) + +### Build ### +SET(SRCS + src/lbs_dbus_client.c +) + +ADD_LIBRARY(lbs-dbus SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(lbs-dbus ${pkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(lbs-dbus PROPERTIES VERSION 0.1.0 SOVERSION 0 OUTPUT_NAME lbs-dbus) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/lbs_dbus_client.h DESTINATION include/lbs-dbus) +INSTALL(TARGETS lbs-dbus DESTINATION lib COMPONENT Runtime) +#ADD_SUBDIRECTORY(test_src) diff --git a/client/include/lbs_dbus_client.h b/client/include/lbs_dbus_client.h new file mode 100644 index 0000000..29de5d1 --- /dev/null +++ b/client/include/lbs_dbus_client.h @@ -0,0 +1,61 @@ +/* + * lbs-dbus + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com> + * Genie Kim <daejins.kim@samsung.com>, Ming Zhu <mingwu.zhu@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LBS_DBUS_CLIENT_H__ +#define __LBS_DBUS_CLIENT_H__ + +__BEGIN_DECLS + +#include <gio/gio.h> + +typedef enum { + LBS_CLIENT_LOCATION_CB = 0x01, + LBS_CLIENT_LOCATION_STATUS_CB = LBS_CLIENT_LOCATION_CB << 0x01, + LBS_CLIENT_SATELLITE_CB = LBS_CLIENT_LOCATION_CB << 0x02, + LBS_CLIENT_NMEA_CB = LBS_CLIENT_LOCATION_CB << 0x03, +} lbs_client_callback_e; + +typedef enum { + LBS_CLIENT_ERROR_NONE = 0x0, + LBS_CLIENT_ERROR_UNKNOWN, + LBS_CLIENT_ERROR_PARAMETER, + LBS_CLIENT_ERROR_MEMORY, + LBS_CLIENT_ERROR_CONNECTION, + LBS_CLIENT_ERROR_STATUS, + LBS_CLIENT_ERROR_DBUS_CALL, + LBS_CLIENT_ERROR_NO_RESULT, +} lbs_client_error_e; + +typedef void *lbs_client_dbus_h; + +int lbs_client_create(char *service_name, char *service_path, lbs_client_dbus_h *lbs_client); +int lbs_client_destroy(lbs_client_dbus_h lbs_client); + +int lbs_client_start(lbs_client_dbus_h lbs_client, lbs_client_callback_e callback_type, GDBusSignalCallback callback, void *user_data); +int lbs_client_stop(lbs_client_dbus_h lbs_client); + +int lbs_client_get_nmea(lbs_client_dbus_h lbs_client, int *timestamp, char **nmea); + +__END_DECLS + +#endif /* __LBS_DBUS_CLIENT_H__ */ + + diff --git a/client/include/lbs_dbus_client_priv.h b/client/include/lbs_dbus_client_priv.h new file mode 100644 index 0000000..945b14b --- /dev/null +++ b/client/include/lbs_dbus_client_priv.h @@ -0,0 +1,51 @@ +/* + * lbs-dbus + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com> + * Genies Kim <daejins.kim@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LBS_DBUS_CLIENT_PRIV_H__ +#define __LBS_DBUS_CLIENT_PRIV_H__ + +__BEGIN_DECLS + +#ifdef FEATURE_DLOG_DEBUG +#include <dlog.h> + +#ifdef LOG_TAG +#undef LOG_TAG +#define LOG_TAG "LBS_DBUS_CLIENT" +#endif + +#define LBS_CLIENT_LOGI(fmt,args...) { LOGI(fmt, ##args); } +#define LBS_CLIENT_LOGD(fmt,args...) { LOGD(fmt, ##args); } +#define LBS_CLIENT_LOGW(fmt,args...) { LOGW(fmt, ##args); } +#define LBS_CLIENT_LOGE(fmt,args...) { LOGE(fmt, ##args); } + +#else + +#define LBS_CLIENT_LOGI(fmt,args...) +#define LBS_CLIENT_LOGD(fmt,args...) +#define LBS_CLIENT_LOGW(fmt,args...) +#define LBS_CLIENT_LOGE(fmt,args...) + +#endif + +__END_DECLS + +#endif diff --git a/client/src/lbs_dbus_client.c b/client/src/lbs_dbus_client.c new file mode 100644 index 0000000..b8e48bb --- /dev/null +++ b/client/src/lbs_dbus_client.c @@ -0,0 +1,382 @@ +/* + * lbs-dbus + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com> + * Genie Kim <daejins.kim@samsung.com>, Ming Zhu <mingwu.zhu@samsung.com> + * + * 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 "lbs_dbus_client.h" +#include "lbs_dbus_client_priv.h" + +typedef struct _lbs_client_dbus_s { + int is_started; + gchar *addr; + GDBusConnection *conn; + gchar *service_name; + gchar *service_path; + int loc_evt_id; + int loc_status_evt_id; + int sat_evt_id; + int nmea_evt_id; + void *user_data; +} lbs_client_dbus_s; + +EXPORT_API int +lbs_client_start(lbs_client_dbus_h lbs_client, lbs_client_callback_e callback_type, GDBusSignalCallback callback, void *user_data) +{ + LBS_CLIENT_LOGD("lbs_client_start"); + + g_return_val_if_fail (lbs_client, LBS_CLIENT_ERROR_PARAMETER); + g_return_val_if_fail (callback_type, LBS_CLIENT_ERROR_PARAMETER); + + lbs_client_dbus_s *handle = (lbs_client_dbus_s *)lbs_client; + g_return_val_if_fail (handle->is_started == FALSE, LBS_CLIENT_ERROR_STATUS); + + GVariant *reg = NULL; + GVariant *param = NULL; + GError *error = NULL; + GVariantBuilder *builder = NULL; + GDBusProxy *proxy = NULL; + gchar *signal_path = NULL; + + signal_path = g_strdup_printf ("%s/%s", handle->service_path, "SAMSUNG"); + LBS_CLIENT_LOGD("LBS signal subscribe Object Path [%s]", signal_path); + + if (callback) { + if (callback_type & LBS_CLIENT_LOCATION_CB) { + handle->loc_evt_id = g_dbus_connection_signal_subscribe(handle->conn, + handle->service_name, //GPS_MANAGER_SERVICE_NAME, /* Sender */ + "org.tizen.lbs.Position", /* Interface */ + "PositionChanged", /* Member */ + signal_path, //GPS_MANAGER_SERVICE_PATH, /* Object */ + NULL, /* arg0 */ + G_DBUS_SIGNAL_FLAGS_NONE, + callback, user_data, + NULL); + + if (handle->loc_evt_id) { + LBS_CLIENT_LOGD("Listening Position info"); + } + else { + LBS_CLIENT_LOGD("Fail to listen Position info"); + } + } + + if (callback_type & LBS_CLIENT_LOCATION_STATUS_CB) { + handle->loc_status_evt_id = g_dbus_connection_signal_subscribe(handle->conn, + handle->service_name, //GPS_MANAGER_SERVICE_NAME, /* Sender */ + "org.tizen.lbs.Manager", /* Interface */ + "StatusChanged", /* Member */ + handle->service_path, //GPS_MANAGER_SERVICE_PATH, /* Object */ + NULL, /* arg0 */ + G_DBUS_SIGNAL_FLAGS_NONE, + callback, user_data, + NULL); + + if (handle->loc_status_evt_id) { + LBS_CLIENT_LOGD("Listening location Status"); + } + else { + LBS_CLIENT_LOGD("Fail to listen location Status"); + } + } + + if (callback_type & LBS_CLIENT_SATELLITE_CB) { + handle->sat_evt_id= g_dbus_connection_signal_subscribe(handle->conn, + handle->service_name, //GPS_MANAGER_SERVICE_NAME, /* Sender */ + "org.tizen.lbs.Satellite", /* Interface */ + "SatelliteChanged", /* Member */ + signal_path, //GPS_MANAGER_SERVICE_PATH, /* Object */ + NULL, /* arg0 */ + G_DBUS_SIGNAL_FLAGS_NONE, + callback, user_data, + NULL); + + if (handle->sat_evt_id) { + LBS_CLIENT_LOGD("Listening satellite info"); + } + else { + LBS_CLIENT_LOGD("Fail to listen satellite info"); + } + } + + if (callback_type & LBS_CLIENT_NMEA_CB) { + handle->nmea_evt_id = g_dbus_connection_signal_subscribe(handle->conn, + handle->service_name, /* Sender */ + "org.tizen.lbs.Nmea", /* Interface */ + "NmeaChanged", /* Member */ + signal_path, //GPS_MANAGER_SERVICE_PATH, /* Object */ + NULL, /* arg0 */ + G_DBUS_SIGNAL_FLAGS_NONE, + callback, user_data, + NULL); + + if (handle->nmea_evt_id) { + LBS_CLIENT_LOGD("Listening nmea info"); + } + else { + LBS_CLIENT_LOGD("Fail to listen nmea info"); + } + } + } + g_free(signal_path); + + // Start + LBS_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))); + + proxy = g_dbus_proxy_new_sync (handle->conn, // GDBusConnection + G_DBUS_PROXY_FLAGS_NONE, //GDbusProxyFlags + NULL, + handle->service_name, + handle->service_path, + "org.tizen.lbs.Manager", + NULL, + &error); + + reg = g_dbus_proxy_call_sync(proxy, + "AddReference", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + + reg = g_dbus_proxy_call_sync(proxy, + "SetOptions", + param, + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, + NULL, + &error); + + g_object_unref(proxy); + g_variant_builder_unref (builder); + g_variant_unref(param); + + handle->is_started = TRUE; + + return LBS_CLIENT_ERROR_NONE; +} + +EXPORT_API int +lbs_client_stop(lbs_client_dbus_h lbs_client) +{ + LBS_CLIENT_LOGD("lbs_client_stop"); + + lbs_client_dbus_s *handle = (lbs_client_dbus_s *)lbs_client; + g_return_val_if_fail (handle, LBS_CLIENT_ERROR_PARAMETER); + g_return_val_if_fail (handle->is_started == TRUE, LBS_CLIENT_ERROR_STATUS); + + int ret = LBS_CLIENT_ERROR_NONE; + GVariant *param = NULL; + GVariant *reg = NULL; + GError *error = NULL; + GVariantBuilder *builder = NULL; + + //TODO: Unsubscribe + if (handle->loc_evt_id) { + g_dbus_connection_signal_unsubscribe(handle->conn, handle->loc_evt_id); + handle->loc_evt_id = 0; + } + + if (handle->sat_evt_id) { + g_dbus_connection_signal_unsubscribe(handle->conn, handle->sat_evt_id); + handle->sat_evt_id = 0; + } + + if (handle->loc_status_evt_id) { + g_dbus_connection_signal_unsubscribe(handle->conn, handle->loc_status_evt_id); + handle->loc_status_evt_id = 0; + } + + if (handle->nmea_evt_id) { + g_dbus_connection_signal_unsubscribe(handle->conn, handle->nmea_evt_id); + handle->nmea_evt_id = 0; + } + + // Stop + LBS_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))); + + GDBusProxy *proxy = NULL; + proxy = g_dbus_proxy_new_sync (handle->conn, // GDBusConnection + G_DBUS_PROXY_FLAGS_NONE, //GDbusProxyFlags + NULL, + handle->service_name, + handle->service_path, + "org.tizen.lbs.Manager", + NULL, + &error); + reg = g_dbus_proxy_call_sync(proxy, + "SetOptions", + param, + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, + NULL, + &error); + + reg = g_dbus_proxy_call_sync(proxy, + "RemoveReference", + NULL, + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, + NULL, + &error); + + g_object_unref(proxy); + g_variant_builder_unref (builder); + g_variant_unref(param); + handle->is_started = FALSE; + + return ret; +} + +EXPORT_API int +lbs_client_get_nmea(lbs_client_dbus_h lbs_client, int *timestamp, char **nmea) +{ + LBS_CLIENT_LOGD("lbs_client_nmea"); + g_return_val_if_fail (lbs_client, LBS_CLIENT_ERROR_PARAMETER); + g_return_val_if_fail (timestamp, LBS_CLIENT_ERROR_PARAMETER); + g_return_val_if_fail (nmea, LBS_CLIENT_ERROR_PARAMETER); + + GVariant *reg = NULL; + GError *error = NULL; + lbs_client_dbus_s *handle = (lbs_client_dbus_s *)lbs_client; + + *timestamp = 0; + *nmea = NULL; + + reg = g_dbus_connection_call_sync(handle->conn, + handle->service_name, //GPS_MANAGER_SERVICE_NAME, /* Bus Name */ + handle->service_path, //GPS_MANAGER_SERVICE_PATH, /* Object path */ + "org.tizen.lbs.Nmea", /* Interface*/ + "GetNmea", /* Method name */ + NULL, /* Param */ + NULL, /* Ret */ + G_DBUS_CALL_FLAGS_NONE, /* GDBusCallFlags (G_DBUS_CALL_FLAGS_NONE/G_DBUS_CALL_FLAGS_NO_AUTO_START) */ + -1, /* timeout msec */ + NULL, /* cancellable */ + &error); + + if (error) { + LBS_CLIENT_LOGE("Fail to get nmea. Error[%s]", error->message); + g_error_free (error); + return LBS_CLIENT_ERROR_DBUS_CALL; + } + + /* Get Ret */ + if (!reg) { + LBS_CLIENT_LOGD("There is no result"); + return LBS_CLIENT_ERROR_NO_RESULT; + } + + LBS_CLIENT_LOGD("type : %s", g_variant_get_type(reg)); + g_variant_get (reg, "(is)", timestamp, nmea); + LBS_CLIENT_LOGD("Get NMEA. Timestamp[%d], NMEA[%s]", *timestamp, *nmea); + + return LBS_CLIENT_ERROR_NONE; +} + +static int +_client_create_connection (lbs_client_dbus_s *client) +{ + LBS_CLIENT_LOGD("create connection"); + g_return_val_if_fail (client, LBS_CLIENT_ERROR_PARAMETER); + GError *error = NULL; + + client->addr = g_dbus_address_get_for_bus_sync (G_BUS_TYPE_SYSTEM, NULL, &error); + if (!client->addr) { + LBS_CLIENT_LOGD("Fail to get addr of bus."); + return LBS_CLIENT_ERROR_CONNECTION; + } + + client->conn = g_dbus_connection_new_for_address_sync (client->addr, + G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | + G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION, + NULL, NULL, &error); + if (!client->conn) { + LBS_CLIENT_LOGD("Fail to get addr of bus."); + g_free(client->addr); + return LBS_CLIENT_ERROR_CONNECTION; + } + + return LBS_CLIENT_ERROR_NONE; +} + +// The reason why we seperate this from start is to support IPC for db operation between a server and a client. +EXPORT_API int +lbs_client_create(char *service_name, char *service_path, lbs_client_dbus_h *lbs_client) +{ + LBS_CLIENT_LOGD("lbs_client_create"); + g_return_val_if_fail (service_name, LBS_CLIENT_ERROR_PARAMETER); + g_return_val_if_fail (service_path, LBS_CLIENT_ERROR_PARAMETER); + g_return_val_if_fail (lbs_client, LBS_CLIENT_ERROR_PARAMETER); + + int ret = LBS_CLIENT_ERROR_NONE; + + lbs_client_dbus_s *client = g_new0(lbs_client_dbus_s, 1); + g_return_val_if_fail (client, LBS_CLIENT_ERROR_MEMORY); + + ret = _client_create_connection (client); + if (ret != LBS_CLIENT_ERROR_NONE) { + g_free(client); + return ret; + } + + client->service_name = g_strdup(service_name); + client->service_path = g_strdup(service_path); + + *lbs_client = (lbs_client_dbus_h *)client; + + return LBS_CLIENT_ERROR_NONE; +} + +EXPORT_API int +lbs_client_destroy (lbs_client_dbus_h lbs_client) +{ + LBS_CLIENT_LOGD("lbs_client_destroy"); + g_return_val_if_fail(lbs_client, LBS_CLIENT_ERROR_PARAMETER); + + lbs_client_dbus_s *handle = (lbs_client_dbus_s *)lbs_client; + g_return_val_if_fail(handle->is_started == FALSE, LBS_CLIENT_ERROR_STATUS); + + int ret = LBS_CLIENT_ERROR_NONE; + GError *error = NULL; + + //TODO : disconnect + if (handle->conn) { + ret = g_dbus_connection_close_sync(handle->conn, NULL, &error); + if (ret != TRUE) { + LBS_CLIENT_LOGD("Fail to disconnection Dbus"); + } + handle->conn = NULL; + } + + if (handle->addr) g_free(handle->addr); + if (handle->service_path) g_free(handle->service_path); + if (handle->service_name) g_free(handle->service_name); + g_free(handle); + + return LBS_CLIENT_ERROR_NONE; +} diff --git a/introspection/gen.sh b/introspection/gen.sh new file mode 100644 index 0000000..3617331 --- /dev/null +++ b/introspection/gen.sh @@ -0,0 +1,6 @@ +gdbus-codegen --interface-prefix org.tizen.lbs. \ + --generate-c-code generated-code \ + --c-generate-object-manager \ + --c-namespace Lbs \ + --generate-docbook generated-docs \ + lbs.xml lbs_position.xml lbs_satellite.xml lbs_nmea.xml diff --git a/introspection/lbs.xml b/introspection/lbs.xml new file mode 100644 index 0000000..eaf89e7 --- /dev/null +++ b/introspection/lbs.xml @@ -0,0 +1,23 @@ +<node> + <interface name="org.tizen.lbs.Manager"> + <method name="GetProviderInfo"> + <arg direction="out" type="s" name="Name"/> + <arg direction="out" type="s" name="Description"/> + </method> + <method name="GetStatus"> + <arg direction="out" type="i" name="status"/> + </method> + <signal name="StatusChanged"> + <arg direction="out" type="i" name="status"/> + </signal> + <method name="SetOptions"> + <arg direction="in" type="a{sv}" name="options"/> + </method> + <method name="AddReference"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + </method> + <method name="RemoveReference"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + </method> + </interface> +</node> diff --git a/introspection/lbs_nmea.xml b/introspection/lbs_nmea.xml new file mode 100644 index 0000000..16ca309 --- /dev/null +++ b/introspection/lbs_nmea.xml @@ -0,0 +1,8 @@ +<node> + <interface name="org.tizen.lbs.Nmea"> + <signal name="NmeaChanged"> + <arg type="i" name="timestamp"/> + <arg type="s" name="nmea_data"/> + </signal> + </interface> +</node> diff --git a/introspection/lbs_position.xml b/introspection/lbs_position.xml new file mode 100644 index 0000000..9978ceb --- /dev/null +++ b/introspection/lbs_position.xml @@ -0,0 +1,15 @@ +<node> + <interface name="org.tizen.lbs.Position"> + <signal name="PositionChanged"> + <arg type="i" name="fields" /> + <arg type="i" name="timestamp" /> + <arg type="d" name="latitude" /> + <arg type="d" name="longitude" /> + <arg type="d" name="altitude" /> + <arg type="d" name="speed" /> + <arg type="d" name="direction" /> + <arg type="d" name="climb" /> + <arg type="(idd)" name="accuracy" /> + </signal> + </interface> +</node> diff --git a/introspection/lbs_satellite.xml b/introspection/lbs_satellite.xml new file mode 100644 index 0000000..2160ffa --- /dev/null +++ b/introspection/lbs_satellite.xml @@ -0,0 +1,11 @@ +<node> + <interface name="org.tizen.lbs.Satellite"> + <signal name="SatelliteChanged"> + <arg type="i" name="timestamp" /> + <arg type="i" name="satellite_used" /> + <arg type="i" name="satellite_visible" /> + <arg type="ai" name="used_prn" /> + <arg type="a(iiii)" name="sat_info" /> + </signal> + </interface> +</node> diff --git a/lbs-dbus.pc.in b/lbs-dbus.pc.in new file mode 100644 index 0000000..29b91a7 --- /dev/null +++ b/lbs-dbus.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: LBS dbus Library +Description: LBS dbus library +Requires: glib-2.0 gobject-2.0 +Version: 0.1 +Libs: -L${libdir} -llbs-dbus -llbs-dbus-server +Cflags: -I${includedir}/lbs-dbus diff --git a/liblbs-dbus.manifest b/liblbs-dbus.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/liblbs-dbus.manifest @@ -0,0 +1,5 @@ +<manifest> + <request> + <domain name="_"/> + </request> +</manifest> diff --git a/packaging/lbs-dbus.spec b/packaging/lbs-dbus.spec new file mode 100644 index 0000000..fa73040 --- /dev/null +++ b/packaging/lbs-dbus.spec @@ -0,0 +1,73 @@ +Name: lbs-dbus +Summary: Dbus interface for Location based service +Version: 0.1.6 +Release: 1 +Group: System/Libraries +License: Apache +Source0: lbs-dbus-%{version}.tar.gz +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: python +BuildRequires: python-xml +#BuildRequires: sec-product-features + +%description +LBS dbus interface + +%package -n liblbs-dbus +Summary: LBS dbus library +Group: TO_BE/FILLED_IN +Requires(post): sys-assert + +%description -n liblbs-dbus +LBS client API library + +%package -n liblbs-dbus-devel +Summary: Telephony client API (devel) +Group: Development/Libraries +Requires: liblbs-dbus = %{version}-%{release} + +%description -n liblbs-dbus-devel +LBS client API library (devel) + + +%prep +%setup -q + + +%build +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} + + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install +mkdir -p %{buildroot}/usr/share/license + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + +%files -n liblbs-dbus +%manifest liblbs-dbus.manifest +%defattr(-,root,root,-) +#%doc COPYING +%{_libdir}/*.so.* +%{_prefix}/etc/dbus-1/system.d/* +/usr/share/license/liblbs-dbus + +%files -n liblbs-dbus-devel +%defattr(-,root,root,-) +%{_includedir}/lbs-dbus/*.h +%{_libdir}/pkgconfig/*.pc +%{_libdir}/*.so diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt new file mode 100644 index 0000000..2abd6ca --- /dev/null +++ b/server/CMakeLists.txt @@ -0,0 +1,27 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(lbs-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/lbs_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 Lbs --generate-docbook generated-docs ${CMAKE_SOURCE_DIR}/introspection/lbs.xml ${CMAKE_SOURCE_DIR}/introspection/lbs_position.xml ${CMAKE_SOURCE_DIR}/introspection/lbs_satellite.xml ${CMAKE_SOURCE_DIR}/introspection/lbs_nmea.xml + COMMENT "Generating GDBus .c/.h") + +ADD_LIBRARY(lbs-dbus-server SHARED ${SRCS_S}) +TARGET_LINK_LIBRARIES(lbs-dbus-server ${pkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(lbs-dbus-server PROPERTIES VERSION 0.1.0 SOVERSION 0 OUTPUT_NAME lbs-dbus-server) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/lbs-dbus-server.conf DESTINATION ${PREFIX}/etc/dbus-1/system.d) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/lbs_dbus_server.h DESTINATION include/lbs-dbus) +INSTALL(TARGETS lbs-dbus-server DESTINATION lib COMPONENT Runtime) +#ADD_SUBDIRECTORY(test_src) diff --git a/server/include/lbs_dbus_server.h b/server/include/lbs_dbus_server.h new file mode 100644 index 0000000..5522776 --- /dev/null +++ b/server/include/lbs_dbus_server.h @@ -0,0 +1,92 @@ +/* + * lbs-dbus + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com> + * Genie Kim <daejins.kim@samsung.com>, Ming Zhu <mingwu.zhu@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LBS_DBUS_SERVER_H__ +#define __LBS_DBUS_SERVER_H__ + +__BEGIN_DECLS + +#include <gio/gio.h> + +typedef void (*LbsDbusSetOptionsCB)(GVariant *options, gpointer userdata); +typedef void (*LbsDbusShutdownCB)(gpointer userdata); + + +typedef enum { + LBS_SERVER_ERROR_NONE = 0x0, + LBS_SERVER_ERROR_UNKNOWN, + LBS_SERVER_ERROR_PARAMETER, + LBS_SERVER_ERROR_MEMORY, + LBS_SERVER_ERROR_CONNECTION, + LBS_SERVER_ERROR_STATUS, + LBS_SERVER_ERROR_DBUS_CALL, + LBS_SERVER_ERROR_NO_RESULT, +} lbs_server_error_e; + +typedef void *lbs_server_dbus_h; + +int +lbs_server_emit_position_changed(lbs_server_dbus_h lbs_server, + gint arg_fields, + gint arg_timestamp, + gdouble arg_latitude, + gdouble arg_longitude, + gdouble arg_altitude, + gdouble arg_speed, + gdouble arg_direction, + gdouble arg_climb, + GVariant *arg_accuracy); + +int +lbs_server_emit_satellite_changed(lbs_server_dbus_h lbs_server, + gint arg_timestamp, + gint arg_satellite_used, + gint arg_satellite_visible, + GVariant *arg_used_prn, + GVariant *arg_sat_info); + +int +lbs_server_emit_nmea_changed(lbs_server_dbus_h lbs_server, + gint arg_timestamp, + const gchar *arg_nmea_data); + +int +lbs_server_emit_status_changed(lbs_server_dbus_h lbs_server, gint status); + +int +lbs_server_create(char *service_name, + char *service_path, + char *name, + char *description, + lbs_server_dbus_h *lbs_server, + LbsDbusSetOptionsCB set_options_cb, + LbsDbusShutdownCB shutdown_cb, + gpointer userdata); + + +int +lbs_server_destroy (lbs_server_dbus_h lbs_server); + + +__END_DECLS + +#endif /* __LBS_DBUS_SERVER_H__ */ + diff --git a/server/include/lbs_dbus_server_priv.h b/server/include/lbs_dbus_server_priv.h new file mode 100644 index 0000000..452f9e6 --- /dev/null +++ b/server/include/lbs_dbus_server_priv.h @@ -0,0 +1,52 @@ +/* + * lbs-dbus + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com> + * Genie Kim <daejins.kim@samsung.com>, Ming Zhu <mingwu.zhu@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LBS_DBUS_SERVER_PRIV_H__ +#define __LBS_DBUS_SERVER_PRIV_H__ + +__BEGIN_DECLS + +#ifdef FEATURE_DLOG_DEBUG +#include <dlog.h> + +#ifdef LOG_TAG +#undef LOG_TAG +#define LOG_TAG "LBS_DBUS_SERVER" +#endif + +#define LBS_SERVER_LOGI(fmt,args...) { LOGI(fmt, ##args); } +#define LBS_SERVER_LOGD(fmt,args...) { LOGD(fmt, ##args); } +#define LBS_SERVER_LOGW(fmt,args...) { LOGW(fmt, ##args); } +#define LBS_SERVER_LOGE(fmt,args...) { LOGE(fmt, ##args); } + +#else + +#define LBS_SERVER_LOGI(fmt,args...) +#define LBS_SERVER_LOGD(fmt,args...) +#define LBS_SERVER_LOGW(fmt,args...) +#define LBS_SERVER_LOGE(fmt,args...) + +#endif + +__END_DECLS + + +#endif diff --git a/server/res/lbs-dbus-server.conf b/server/res/lbs-dbus-server.conf new file mode 100644 index 0000000..83f6ff1 --- /dev/null +++ b/server/res/lbs-dbus-server.conf @@ -0,0 +1,96 @@ +<!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.Providers.GpsManager"/> + <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.Providers.GpsManager"/> + <allow send_destination="org.tizen.lbs.Providers.Xps"/> + <allow receive_sender="org.tizen.lbs.Manager"/> + <allow receive_sender="org.tizen.lbs.Providers.GpsManager"/> + <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.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.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.Providers.GpsManager"/> + <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.Providers.GpsManager"/> + <allow send_destination="org.tizen.lbs.Providers.Xps"/> + <allow receive_sender="org.tizen.lbs.Manager"/> + <allow receive_sender="org.tizen.lbs.Providers.GpsManager"/> + <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.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.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.Providers.GpsManager"/> + <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.Providers.GpsManager"/> + <allow send_destination="org.tizen.lbs.Providers.Xps"/> + <allow receive_sender="org.tizen.lbs.Manager"/> + <allow receive_sender="org.tizen.lbs.Providers.GpsManager"/> + <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.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.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.Providers.GpsManager"/> + <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.Providers.GpsManager"/> + <deny send_destination="org.tizen.lbs.Providers.Xps"/> + <deny receive_sender="org.tizen.lbs.Manager"/> + <deny receive_sender="org.tizen.lbs.Providers.GpsManager"/> + <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.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.Position"/> + <deny receive_interface="org.tizen.lbs.Nmea"/> + <deny receive_interface="org.tizen.lbs.Satellite"/> + </policy> +</busconfig> diff --git a/server/src/lbs_dbus_server.c b/server/src/lbs_dbus_server.c new file mode 100644 index 0000000..9f75c02 --- /dev/null +++ b/server/src/lbs_dbus_server.c @@ -0,0 +1,625 @@ +/* + * lbs-dbus + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com> + * Genie Kim <daejins.kim@samsung.com>, Ming Zhu <mingwu.zhu@samsung.com> + * + * 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 "lbs_dbus_server.h" +#include "lbs_dbus_server_priv.h" + + +typedef struct _lbs_server_dbus_s { + /* LBS server dbus info */ + gchar *service_name; + gchar *prev_owner; + gchar *service_path; + gchar *name; + gchar *description; + GHashTable *connections; + gint status; + GDBusObjectManagerServer *manager; + LbsObjectSkeleton *obj_skeleton; + + LbsDbusSetOptionsCB set_options_cb; + LbsDbusShutdownCB shutdown_cb; + gpointer userdata; /* used for save GeoclueGpsManager */ + + guint owner_changed_id; + LbsManager *lbs_mgr; + LbsPosition *lbs_pos; + guint owner_id; + guint get_providerinfo_h; + guint get_status_h; + guint set_option_h; + guint add_reference_h; + guint remove_reference_h; +} lbs_server_dbus_s; + +static gboolean lbs_dbus_setup_position_interface(LbsObjectSkeleton *object, lbs_server_dbus_s *ctx) +{ + LBS_SERVER_LOGD("lbs_dbus_setup_position_interface"); + if (!object || !ctx) { + return FALSE; + } + + LbsPosition *position = NULL; + position = lbs_position_skeleton_new(); + ctx->lbs_pos = position; + lbs_object_skeleton_set_position(object, position); + g_object_unref(position); + + LBS_SERVER_LOGD("position = %p", position); + + return TRUE; +} + +static gboolean lbs_dbus_setup_satellite_interface(LbsObjectSkeleton *object, lbs_server_dbus_s *ctx) +{ + LBS_SERVER_LOGD("lbs_dbus_setup_satellite_interface"); + if (!object || !ctx) { + return FALSE; + } + + LbsSatellite *sat = NULL; + sat = lbs_satellite_skeleton_new(); + lbs_object_skeleton_set_satellite(object, sat); + g_object_unref(sat); + + LBS_SERVER_LOGD("sat = %p", sat); + + return TRUE; +} + +static gboolean lbs_dbus_setup_nmea_interface(LbsObjectSkeleton *object, lbs_server_dbus_s *ctx) +{ + LBS_SERVER_LOGD("lbs_dbus_setup_nmea_interface"); + if (!object || !ctx) { + return FALSE; + } + + LbsNmea *nmea = NULL; + nmea = lbs_nmea_skeleton_new(); + lbs_object_skeleton_set_nmea(object, nmea); + g_object_unref(nmea); + + LBS_SERVER_LOGD("nmea = %p", nmea); + + return TRUE; +} + + + +static gboolean +on_manager_getproviderinfo (LbsManager *mgr, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + LBS_SERVER_LOGD("on_manager_getproviderinfo"); + lbs_server_dbus_s *ctx = (lbs_server_dbus_s *)user_data; + if (!ctx) { + return FALSE; + } + + if (ctx->name && ctx->description) { + lbs_manager_complete_get_provider_info(mgr, invocation, ctx->name, ctx->description); + } else { + lbs_manager_complete_get_provider_info(mgr, invocation, NULL, NULL); + } + + return TRUE; +} + +static gboolean +on_manager_getstatus (LbsManager *mgr, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + LBS_SERVER_LOGD("on_manager_getstatus"); + lbs_server_dbus_s *ctx = (lbs_server_dbus_s *)user_data; + if (!ctx) { + return FALSE; + } + + lbs_manager_complete_get_status(mgr, invocation, ctx->status); + + return TRUE; +} + +static gboolean +on_manager_setoptions (LbsManager *mgr, + GDBusMethodInvocation *invocation, + GVariant *options, + gpointer user_data) +{ + LBS_SERVER_LOGD("on_manager_setoptions"); + lbs_server_dbus_s *ctx = (lbs_server_dbus_s *)user_data; + if (!ctx) { + return FALSE; + } + + if (ctx->set_options_cb) { + ctx->set_options_cb(options, ctx->userdata); + LBS_SERVER_LOGD("set_options_cb called"); + } + + lbs_manager_complete_set_options(mgr, invocation); + + return TRUE; +} + +static gboolean +on_manager_addreference (LbsManager *mgr, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + LBS_SERVER_LOGD("on_manager_addreference"); + lbs_server_dbus_s *ctx = (lbs_server_dbus_s *)user_data; + if (!ctx) { + return FALSE; + } + + const gchar *sender = NULL; + gchar *sender_cp = NULL; + int *pcount = NULL; + + /* Update the hash of open connections */ + sender = g_dbus_method_invocation_get_sender(invocation); + sender_cp = g_strdup(sender); + pcount = g_hash_table_lookup(ctx->connections, sender); + if (!pcount) { + pcount = g_malloc0(sizeof(int)); + } + (*pcount)++; + g_hash_table_insert(ctx->connections, (gpointer)sender_cp, pcount); + LBS_SERVER_LOGD("sender [%s], pcount [%d] insert into hash table", sender_cp, *pcount); + + lbs_manager_complete_add_reference(mgr, invocation); + + return TRUE; +} + +static gboolean +lbs_server_remove_client (lbs_server_dbus_s *ctx, const char *client) +{ + if (!ctx || !client) { + return FALSE; + } + + int *pcount = NULL; + + pcount = g_hash_table_lookup(ctx->connections, client); + if (!pcount) { + LBS_SERVER_LOGD("Client[%s] is already removed", client); + return FALSE; + } + (*pcount)--; + LBS_SERVER_LOGD("Client[%s] has reference count[%d]", client, *pcount); + if (*pcount == 0) { + LBS_SERVER_LOGD("Reference count is zero, Now remove client[%s] in hash table", client); + g_hash_table_remove(ctx->connections, client); + } + if (g_hash_table_size(ctx->connections) == 0) { + LBS_SERVER_LOGD("Hash table size is zero, Now we shutdown provider[%s]", ctx->name); + if (ctx->shutdown_cb) { + LBS_SERVER_LOGD("shutdown_cb to be called..."); + ctx->shutdown_cb(ctx->userdata); + LBS_SERVER_LOGD("shutdown_cb called..."); + } + } + return TRUE; +} + +static gboolean +on_manager_removereference (LbsManager *mgr, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + LBS_SERVER_LOGD("on_manager_removereference"); + lbs_server_dbus_s *ctx = (lbs_server_dbus_s *)user_data; + if (!ctx) { + return FALSE; + } + + const gchar *sender = NULL; + sender = g_dbus_method_invocation_get_sender(invocation); + if (!lbs_server_remove_client(ctx, sender)) { + LBS_SERVER_LOGD("Unreffed by client that has not been referenced"); + } + + lbs_manager_complete_remove_reference(mgr, invocation); + + return TRUE; +} + +static gboolean +lbs_remove_client_by_force(const char *client, void *data) +{ + LBS_SERVER_LOGD("remove client by force"); + lbs_server_dbus_s *ctx = (lbs_server_dbus_s *)data; + if (lbs_server_remove_client (ctx, client)) { + LBS_SERVER_LOGD("###### A clinet[%s] is abnormally shut down ########", client); + } + + return TRUE; +} + +static void +lbs_scan_sender(char *key, char *value, gpointer user_data) +{ + lbs_server_dbus_s *handle = (lbs_server_dbus_s *)user_data; + g_return_if_fail(handle); + gchar *prev_owner = handle->prev_owner; + g_return_if_fail(prev_owner); + + LBS_SERVER_LOGD("lbs_scan_sender >> key[%s] : prev_owner[%s]\n", key, prev_owner); + if (g_strcmp0(prev_owner, key) == 0) { + LBS_SERVER_LOGD("disconnected sender name matched, remove client by force!"); + lbs_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, /* 1. service name 2. prev_owner 3. new_owner */ + gpointer user_data) +{ + lbs_server_dbus_s *handle = (lbs_server_dbus_s *)user_data; + g_return_if_fail(handle); + + LBS_SERVER_LOGD("on_name_owner_changed: sender_name[%s], object_path[%s], interface_name[%s]", + sender_name, object_path, interface_name); + + gchar *service_name = NULL, *prev_owner = NULL, *new_owner = NULL; + g_variant_get (parameters, "(&s&s&s)", &service_name, &prev_owner, &new_owner); + LBS_SERVER_LOGD("service_name %s, prev_owner %s, new_owner %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) { + goto out; + } + + /* 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)lbs_scan_sender, handle); + } + +out: + ; +} + +static void on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data) +{ + lbs_server_dbus_s *ctx = (lbs_server_dbus_s *)user_data; + if (!ctx) { + return; + } + + LbsManager *mgr = NULL; + LbsObjectSkeleton *object = NULL; + gchar *path = NULL; + + LBS_SERVER_LOGD("dbus registered"); + + /* create object for each interfaces*/ + path = g_strdup_printf ("%s/%s", ctx->service_path, "SAMSUNG"); + object = lbs_object_skeleton_new(path); + ctx->obj_skeleton = object; + + LBS_SERVER_LOGD("object path [%s], obj_skeleton [%p]", path, ctx->obj_skeleton); + + lbs_dbus_setup_position_interface(object, ctx); + lbs_dbus_setup_satellite_interface(object, ctx); + lbs_dbus_setup_nmea_interface(object, ctx); + g_dbus_object_manager_server_export(ctx->manager, G_DBUS_OBJECT_SKELETON(object)); + + /* Add interface to default object path */ + mgr = lbs_manager_skeleton_new(); + ctx->lbs_mgr = mgr; + LBS_SERVER_LOGD("mgr = %p", mgr); + + ctx->get_providerinfo_h = g_signal_connect (mgr, + "handle-get-provider-info", + G_CALLBACK (on_manager_getproviderinfo), + ctx); /* user_data */ + ctx->get_status_h = g_signal_connect (mgr, + "handle-get-status", + G_CALLBACK (on_manager_getstatus), + ctx); /* user_data */ + ctx->set_option_h = g_signal_connect (mgr, + "handle-set-options", + G_CALLBACK (on_manager_setoptions), + ctx); /* user_data */ + ctx->add_reference_h = g_signal_connect (mgr, + "handle-add-reference", + G_CALLBACK (on_manager_addreference), + ctx); /* user_data */ + ctx->remove_reference_h = g_signal_connect (mgr, + "handle-remove-reference", + G_CALLBACK (on_manager_removereference), + ctx); /* user_data */ + + 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_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(mgr), conn, ctx->service_path, NULL); + + g_dbus_object_manager_server_set_connection (ctx->manager, conn); + + LBS_SERVER_LOGD("done to acquire the dbus"); +} + +static void on_name_acquired(GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + LBS_SERVER_LOGD("LBS Server: Acquired the name <%s> on the system bus", name); +} + +static void on_name_lost(GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + LBS_SERVER_LOGD("LBS Server: Lost the name <%s> on the system bus", name); +} + +EXPORT_API int +lbs_server_emit_position_changed(lbs_server_dbus_h lbs_server, + gint arg_fields, + gint arg_timestamp, + gdouble arg_latitude, + gdouble arg_longitude, + gdouble arg_altitude, + gdouble arg_speed, + gdouble arg_direction, + gdouble arg_climb, + GVariant *arg_accuracy) +{ + LBS_SERVER_LOGD("lbs_server_emit_position_changed"); + g_return_val_if_fail(lbs_server, LBS_SERVER_ERROR_PARAMETER); + + lbs_server_dbus_s *handle = (lbs_server_dbus_s *)lbs_server; + g_return_val_if_fail(handle->obj_skeleton, LBS_SERVER_ERROR_PARAMETER); + g_return_val_if_fail(handle->lbs_pos, LBS_SERVER_ERROR_PARAMETER); + + LBS_SERVER_LOGD("lbs_pos = %p", handle->lbs_pos); + + lbs_position_emit_position_changed(handle->lbs_pos, + arg_fields, + arg_timestamp, + arg_latitude, + arg_longitude, + arg_altitude, + arg_speed, + arg_direction, + arg_climb, + arg_accuracy); + + return LBS_SERVER_ERROR_NONE; + +} + +EXPORT_API int +lbs_server_emit_satellite_changed(lbs_server_dbus_h lbs_server, + gint arg_timestamp, + gint arg_satellite_used, + gint arg_satellite_visible, + GVariant *arg_used_prn, + GVariant *arg_sat_info) +{ + LBS_SERVER_LOGD("lbs_server_emit_satellite_changed"); + g_return_val_if_fail(lbs_server, LBS_SERVER_ERROR_PARAMETER); + + lbs_server_dbus_s *handle = (lbs_server_dbus_s *)lbs_server; + g_return_val_if_fail(handle->obj_skeleton, LBS_SERVER_ERROR_PARAMETER); + + LbsSatellite *sat = NULL; + sat = lbs_object_peek_satellite(LBS_OBJECT(handle->obj_skeleton)); + LBS_SERVER_LOGD("sat = %p", sat); + + lbs_satellite_emit_satellite_changed (sat, + arg_timestamp, + arg_satellite_used, + arg_satellite_visible, + arg_used_prn, + arg_sat_info); + + return LBS_SERVER_ERROR_NONE; +} + +EXPORT_API int +lbs_server_emit_nmea_changed(lbs_server_dbus_h lbs_server, + gint arg_timestamp, + const gchar *arg_nmea_data) +{ + LBS_SERVER_LOGD("lbs_server_emit_nmea_changed"); + g_return_val_if_fail(lbs_server, LBS_SERVER_ERROR_PARAMETER); + + lbs_server_dbus_s *handle = (lbs_server_dbus_s *)lbs_server; + g_return_val_if_fail(handle->obj_skeleton, LBS_SERVER_ERROR_PARAMETER); + + LbsNmea *nmea = NULL; + nmea = lbs_object_peek_nmea(LBS_OBJECT(handle->obj_skeleton)); + LBS_SERVER_LOGD("nmea = %p", nmea); + + lbs_nmea_emit_nmea_changed(nmea, arg_timestamp, arg_nmea_data); + + return LBS_SERVER_ERROR_NONE; + +} + + + +EXPORT_API int +lbs_server_emit_status_changed(lbs_server_dbus_h lbs_server, gint status) +{ + LBS_SERVER_LOGD("lbs_server_emit_status_changed"); + g_return_val_if_fail(lbs_server, LBS_SERVER_ERROR_PARAMETER); + + lbs_server_dbus_s *handle = (lbs_server_dbus_s *)lbs_server; + g_return_val_if_fail(handle->obj_skeleton, LBS_SERVER_ERROR_PARAMETER); + g_return_val_if_fail(handle->lbs_mgr, LBS_SERVER_ERROR_PARAMETER); + + LBS_SERVER_LOGD("lbs_mgr = %p", handle->lbs_mgr); + + handle->status = status; + lbs_manager_emit_status_changed(handle->lbs_mgr, status); + + return LBS_SERVER_ERROR_NONE; +} + +EXPORT_API int +lbs_server_create(char *service_name, + char *service_path, + char *name, + char *description, + lbs_server_dbus_h *lbs_server, + LbsDbusSetOptionsCB set_options_cb, + LbsDbusShutdownCB shutdown_cb, + gpointer userdata) +{ + LBS_SERVER_LOGD("lbs_server_create"); + g_return_val_if_fail (service_name, LBS_SERVER_ERROR_PARAMETER); + g_return_val_if_fail (service_path, LBS_SERVER_ERROR_PARAMETER); + g_return_val_if_fail (lbs_server, LBS_SERVER_ERROR_PARAMETER); + + int ret = LBS_SERVER_ERROR_NONE; + + lbs_server_dbus_s *server = g_new0(lbs_server_dbus_s, 1); + g_return_val_if_fail (server, LBS_SERVER_ERROR_MEMORY); + + 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); + LBS_SERVER_LOGD("server->manager (%p)", server->manager); + + 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; + server->set_options_cb = set_options_cb; + server->shutdown_cb = shutdown_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); + + LBS_SERVER_LOGD("g_bus_own_name id=[%d]", server->owner_id); + + *lbs_server = (lbs_server_dbus_h *)server; + + return ret; +} + +EXPORT_API int +lbs_server_destroy (lbs_server_dbus_h lbs_server) +{ + LBS_SERVER_LOGD("lbs_server_destroy"); + g_return_val_if_fail(lbs_server, LBS_SERVER_ERROR_PARAMETER); + + lbs_server_dbus_s *handle = (lbs_server_dbus_s *)lbs_server; + + int ret = LBS_SERVER_ERROR_NONE; + + g_bus_unown_name(handle->owner_id); + + if (handle->prev_owner) { + g_free(handle->prev_owner); + handle->prev_owner = NULL; + } + if (handle->service_path) { + g_free(handle->service_path); + handle->service_path = NULL; + } + if (handle->service_name) { + g_free(handle->service_name); + handle->service_name = NULL; + } + + if (handle->get_providerinfo_h) { + g_signal_handler_disconnect (handle->lbs_mgr, handle->get_providerinfo_h); + handle->get_providerinfo_h = 0; + } + + if (handle->get_status_h) { + g_signal_handler_disconnect (handle->lbs_mgr, handle->get_status_h); + handle->get_status_h = 0; + } + + if (handle->set_option_h) { + g_signal_handler_disconnect (handle->lbs_mgr, handle->set_option_h); + handle->set_option_h = 0; + } + + if (handle->add_reference_h) { + g_signal_handler_disconnect (handle->lbs_mgr, handle->add_reference_h); + handle->add_reference_h = 0; + } + + if (handle->remove_reference_h) { + g_signal_handler_disconnect (handle->lbs_mgr, handle->remove_reference_h); + handle->remove_reference_h = 0; + } + + 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; +} + |