From 53bd6efb032fc400a81f96b590a8ed5989f5402c Mon Sep 17 00:00:00 2001 From: Kibum Kim Date: Mon, 27 Feb 2012 21:16:25 +0900 Subject: [PATCH] tizen beta release --- AUTHORS | 4 + LICENSE | 204 +++++++++++ Makefile.am | 3 + autogen.sh | 21 ++ configure.ac | 83 +++++ debian/changelog | 191 +++++++++++ debian/compat | 1 + debian/control | 18 + debian/location-geoclue-gpsd.install.in | 1 + debian/location-geoclue-gpsd.postinst | 8 + debian/location-geoclue-nominatim.install.in | 1 + debian/rules | 115 +++++++ modules/Makefile.am | 10 + modules/geoclue-gpsd.c | 402 ++++++++++++++++++++++ modules/geoclue-nominatim.c | 490 +++++++++++++++++++++++++++ modules/log.h | 46 +++ packaging/location-module.spec | 42 +++ 17 files changed, 1640 insertions(+) create mode 100644 AUTHORS create mode 100644 LICENSE create mode 100644 Makefile.am create mode 100755 autogen.sh create mode 100755 configure.ac create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100755 debian/control create mode 100755 debian/location-geoclue-gpsd.install.in create mode 100644 debian/location-geoclue-gpsd.postinst create mode 100644 debian/location-geoclue-nominatim.install.in create mode 100755 debian/rules create mode 100755 modules/Makefile.am create mode 100755 modules/geoclue-gpsd.c create mode 100644 modules/geoclue-nominatim.c create mode 100644 modules/log.h create mode 100755 packaging/location-module.spec diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..19ef850 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,4 @@ +Youngae Kang +Yunhan Kim +Genie Kim +Minjune Kim diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9c13a9b --- /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/Makefile.am b/Makefile.am new file mode 100644 index 0000000..19fa930 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,3 @@ +ACLOCAL_AMFLAGS=-I m4 + +SUBDIRS= modules diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..e6f3a78 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,21 @@ +#!/bin/sh +rm -f config.cache +rm -f acconfig.h + +echo "- libtoolize..." +libtoolize --force || exit $? + +echo "- aclocal..." +aclocal --force -I m4 || exit $? + +echo "- autoheader..." +autoheader --force || exit $? + +echo "- automake..." +automake --add-missing --force-missing || exit $? + +echo "- autoconf..." +autoconf --force || exit $? + +echo "- ready!" +exit diff --git a/configure.ac b/configure.ac new file mode 100755 index 0000000..4aef127 --- /dev/null +++ b/configure.ac @@ -0,0 +1,83 @@ +# Initialize +AC_PREREQ(2.61) +AC_INIT([location-module], 0.1) +AC_CONFIG_AUX_DIR([build-aux]) +AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_HEADER([config.h]) +AC_CONFIG_SRCDIR([modules/geoclue-nominatim.c]) +AM_INIT_AUTOMAKE([1.10.2 foreign -Wall -Werror]) + +# Check programs for making executable +AC_PROG_CC +AM_PROG_CC_C_O +AC_PROG_INSTALL + +# Check programs for making libraries. +AM_PROG_LIBTOOL + +# Add default build options to CFLAGS, LDFLAGS +if test "x$GCC" = "xyes"; then + CFLAGS="$CFLAGS -Wall -Werror" + LDFLAGS="$LDFLAGS -Wl,-z,defs -Wl,--as-needed -Wl,--hash-style=both" +fi + +# Add -g option to CFLAGS +AC_ARG_ENABLE([debug], + [AC_HELP_STRING([--enable-debug],[turn on debugging [default=no]])], + [case "${enableval}" in + yes) enable_dbg=yes ;; + no) enable_dbg=no ;; + *) AC_MSG_ERROR([Bad value ${enableval} for --enable-debug]) ;; + esac],[enable_dbg=no]) +if ([test "x$enable_dbg" = xyes]); then + CFLAGS="$CFLAGS -g" +fi + +# Check GCC EFL visibility +AC_MSG_CHECKING(for ELF visibility) +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ + __attribute__((visibility("default"))) + int var=10; + ]])], + [has_visibility=yes + AC_DEFINE([EXPORT_API], [__attribute__((visibility("default")))], [Symbol visibility prefix]) + CFLAGS="$CFLAGS -fvisibility=hidden"], + [has_visibility=no + AC_DEFINE([EXPORT_API], [], [Symbol visibility prefix]) ] +) +AC_MSG_RESULT($has_visibility) + +# Checks libraries +PKG_CHECK_MODULES(MODULE, [glib-2.0 gmodule-2.0 geoclue location]) +AC_SUBST(MODULE_LIBS) +AC_SUBST(MODULE_CFLAGS) + +# Check dlog libraris +AC_ARG_ENABLE([dlog], + [AC_HELP_STRING([--enable-dlog],[show dlog message [default=no]])], + [case "${enableval}" in + yes) enable_dlog=yes ;; + no) enable_dlog=no ;; + *) AC_MSG_ERROR([Bad value ${enableval} for --enable-dlog]) ;; + esac],[enable_dlog=no]) +if ([test "x$enable_dlog" = xyes]); then + PKG_CHECK_MODULES(DLOG, [dlog], have_dlog="yes", have_dlog="no") + if test "x$have_dlog" = "xyes"; then + MODULE_CFLAGS="$MODULE_CFLAGS $DLOG_CFLAGS -DMOD_DLOG_DEBUG" + MODULE_LIBS="$MODULE_LIBS $DLOG_LIBS" + fi +fi + +# Check D-Bus service path +DBUS_SERVICES_DIR="${datadir}/dbus-1/services" +AC_SUBST(DBUS_SERVICES_DIR) +AC_DEFINE_UNQUOTED(DBUS_SERVICES_DIR, "$DBUS_SERVICES_DIR", [Where services dir for D-Bus is]) + +# Generate files +AC_CONFIG_FILES([ +Makefile +modules/Makefile +]) + +AC_OUTPUT diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..b37c2ed --- /dev/null +++ b/debian/changelog @@ -0,0 +1,191 @@ +location-module (0.1.18-2) unstable; urgency=low + + * rollback + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.18-2 + + -- Minjune Kim Thu, 23 Feb 2012 14:25:43 +0900 + +location-module (0.1.18-1) unstable; urgency=low + + * remove location-geoclue-gpsd + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.18-1 + + -- Genie Kim Fri, 10 Feb 2012 16:18:30 +0900 + +location-module (0.1.17-1) unstable; urgency=low + + * Support multiple result of geocode but it is workaround. + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.17-1 + + -- Minjune Kim Thu, 09 Feb 2012 11:46:50 +0900 + +location-module (0.1.16-4) unstable; urgency=low + + * Modify lib path on postinst + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.16-4 + + -- Minjune Kim Wed, 01 Feb 2012 14:26:56 +0900 + +location-module (0.1.16-3) unstable; urgency=low + + * Fix bug while using WPS module. + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.16-3 + + -- Minjune Kim Mon, 19 Dec 2011 18:59:35 +0900 + +location-module (0.1.16-2) unstable; urgency=low + + * generate link file to support wps method on SDK. + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.16-2 + + -- Minjune Kim Fri, 09 Dec 2011 20:15:04 +0900 + +location-module (0.1.16-1) unstable; urgency=low + + * add geoclue gpsd module + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.16-1 + + -- Genie Kim Wed, 07 Dec 2011 16:50:31 +0900 + +location-module (0.1.15-1) unstable; urgency=low + + * remove not using packages(hostip/opencellid) + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.15-1 + + -- Genie Kim Tue, 06 Dec 2011 22:40:14 +0900 + +location-module (0.1.14-1) unstable; urgency=low + + * move gpsd module to geoclue-providers for last knonw position + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.14-1 + + -- Genie Kim Sat, 26 Nov 2011 12:17:29 +0900 + +location-module (0.1.13-1) unstable; urgency=low + + * use time_t for timestamp + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.13-1 + + -- Genie Kim Mon, 17 Oct 2011 13:36:42 +0900 + +location-module (0.1.12-1) unstable; urgency=low + + * fixed BS about gmtime_r() + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.12-1 + + -- Genie Kim Thu, 01 Sep 2011 14:04:33 +0900 + +location-module (0.1.11-1) unstable; urgency=low + + * fixed prevent defect + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.11-1 + + -- Genie Kim Fri, 26 Aug 2011 13:38:29 +0900 + +location-module (0.1.10-2) unstable; urgency=low + + * change boilerplate + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.10-2 + + -- Genie Kim Wed, 20 Jul 2011 17:52:15 +0900 + +location-module (0.1.10-1) unstable; urgency=low + + * Package: Release new location-geoclue-nominatim package + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.10-1 + + -- Tae-Hwan Kim Wed, 01 Jun 2011 21:14:33 +0900 + +location-module (0.1.9-1) unstable; urgency=low + + * Remove callbacks when location stops + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.9-1 + + -- Tae-Hwan Kim Fri, 13 May 2011 19:28:42 +0900 + +location-module (0.1.8-2) unstable; urgency=low + + * Apply New Location APIs + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.8-2 + + -- Tae-Hwan Kim Wed, 20 Apr 2011 11:16:12 +0900 + +location-module (0.1.7-1) unstable; urgency=low + + * Fix depends & timestamp + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.7-1 + + -- Tae-Hwan Kim Wed, 16 Feb 2011 21:02:21 +0900 + +location-module (0.1.6-1) unstable; urgency=low + + * Add geoclue-hostip module & geoclue-opencellid & geoclue-opencellid module + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.6-1 + + -- Tae-Hwan Kim Wed, 19 Jan 2011 13:32:18 +0900 + +location-module (0.1.5-1) unstable; urgency=low + + * Adapt to plug change again + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.5-1 + + -- Tae-Hwan Kim Tue, 21 Dec 2010 17:31:07 +0900 + +location-module (0.1.4-0) unstable; urgency=low + + * Adapt to plugin change + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.4-0 + + -- Tae-Hwan Kim Mon, 13 Dec 2010 10:32:35 +0900 + +location-module (0.1.3-0) unstable; urgency=low + + * Initialize is_started to FALSE + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.3-0 + + -- Tae-Hwan Kim Thu, 02 Dec 2010 13:36:02 +0900 + +location-module (0.1.2-0) unstable; urgency=low + + * Prevent duplicate start + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.2-0 + + -- Tae-Hwan Kim Mon, 29 Nov 2010 11:17:46 +0900 + +location-module (0.1.1-0) unstable; urgency=low + + * Add debug pkg & disable geoclue-skyhook + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.1-0 + + -- Tae-Hwan Kim Wed, 24 Nov 2010 22:21:17 +0900 + +location-module (0.1.0-1) unstable; urgency=low + + * Initial release + * Git: slp/pkgs/l/location-module + * Tag: location-module_0.1.0-1 + + -- Tae-Hwan Kim Tue, 02 Nov 2010 20:10:07 +0900 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100755 index 0000000..7db09a1 --- /dev/null +++ b/debian/control @@ -0,0 +1,18 @@ +Source: location-module +Section: libs +Priority: extra +Maintainer: Youngae Kang , Yunhan Kim , Genie Kim , Minjune Kim +Build-Depends: debhelper (>= 5), libglib2.0-dev, libslp-location-dev, libgeoclue-dev, libvconf-dev +Standards-Version: 3.7.2 + +Package: location-geoclue-nominatim +Section: utils +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: geoclue-nominatim geocode module for location + +Package: location-module-dbg +Section: libs +Architecture: any +Depends: ${misc:Depends}, location-geoclue-nominatim (=${binary:Version}) +Description: debug package for location-geoclue-nominatim diff --git a/debian/location-geoclue-gpsd.install.in b/debian/location-geoclue-gpsd.install.in new file mode 100755 index 0000000..212ab82 --- /dev/null +++ b/debian/location-geoclue-gpsd.install.in @@ -0,0 +1 @@ +@PREFIX@/lib/location/module/libgps0.so* diff --git a/debian/location-geoclue-gpsd.postinst b/debian/location-geoclue-gpsd.postinst new file mode 100644 index 0000000..6ab6d36 --- /dev/null +++ b/debian/location-geoclue-gpsd.postinst @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ ! -e /usr/lib/location/module/libwps0.so ] ; then + cp -f /usr/lib/location/module/libgps0.so /usr/lib/location/module/libwps0.so +fi + +sync + diff --git a/debian/location-geoclue-nominatim.install.in b/debian/location-geoclue-nominatim.install.in new file mode 100644 index 0000000..2ede3ae --- /dev/null +++ b/debian/location-geoclue-nominatim.install.in @@ -0,0 +1 @@ +@PREFIX@/lib/location/module/libgeocode0.so* diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..4298e5d --- /dev/null +++ b/debian/rules @@ -0,0 +1,115 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +LDFLAGS ?= +PREFIX ?= /usr +DATADIR ?= /opt + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 + CXXFLAGS += -O0 +else + CFLAGS += -O2 + CXXFLAGS += -O2 +endif + +configure: configure-stamp +configure-stamp: + dh_testdir + ./autogen.sh + # Add here commands to configure the package. + ./configure --prefix=$(PREFIX) --enable-dlog --enable-debug + + touch configure-stamp + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + $(MAKE) + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + cat $$f > $${f%.in}; \ + sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \ + sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \ + done + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + - $(MAKE) clean + + rm -rf CMakeCache.txt + rm -rf CMakeFiles + rm -rf cmake_install.cmake + rm -rf Makefile + rm -rf install_manifest.txt + rm -rf *.so + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + rm -f $${f%.in}; \ + done + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/wavplayer. + $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs +# dh_installdocs + dh_installexamples + dh_install --sourcedir=debian/tmp +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + dh_strip --dbg-package=location-module-dbg + dh_compress + dh_fixperms +# dh_perl + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/modules/Makefile.am b/modules/Makefile.am new file mode 100755 index 0000000..51beb47 --- /dev/null +++ b/modules/Makefile.am @@ -0,0 +1,10 @@ +pkgdir = $(libdir)/location/module +pkg_LTLIBRARIES = libgeocode0.la + +# geoclue nominatim plugin +libgeocode0_la_SOURCES = geoclue-nominatim.c $(utility) +libgeocode0_la_CFLAGS = \ + -fPIC\ + $(MODULE_CFLAGS) +libgeocode0_la_LIBADD = \ + $(MODULE_LIBS) diff --git a/modules/geoclue-gpsd.c b/modules/geoclue-gpsd.c new file mode 100755 index 0000000..fda27e2 --- /dev/null +++ b/modules/geoclue-gpsd.c @@ -0,0 +1,402 @@ +/* + * location-geoclue-gpsd + * + * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Yunhan Kim , + * Genie Kim , Minjune Kim + * + * 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 +#include +#include +#include + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "log.h" + +typedef struct{ + char devname[256]; + GeocluePosition *pos; + GeoclueVelocity *vel; + LocModStatusCB status_cb; + LocModPositionCB pos_cb; + LocModVelocityCB vel_cb; + gpointer userdata; + gboolean is_started; +} GeoclueGpsdData; + +static void +status_callback (GeoclueProvider *provider, + gint status, + gpointer userdata) +{ + GeoclueGpsdData* gpsd = (GeoclueGpsdData*)userdata; + g_return_if_fail(gpsd->status_cb); + + switch(status){ + case GEOCLUE_STATUS_ERROR: + case GEOCLUE_STATUS_UNAVAILABLE: + case GEOCLUE_STATUS_ACQUIRING: + MOD_LOGD("Status callback>> GEOCLUE_STATUS_ACQUIRING/ERROR/UNAVAILABLE"); + gpsd->status_cb(FALSE, LOCATION_STATUS_NO_FIX, gpsd->userdata); + break; + case GEOCLUE_STATUS_AVAILABLE: + MOD_LOGD("Status callback>> GEOCLUE_STATUS_AVAILABLE"); + gpsd->status_cb(TRUE, LOCATION_STATUS_3D_FIX, gpsd->userdata); + break; + default: + break; + } +} + +static void +position_callback (GeocluePosition *position, + GeocluePositionFields fields, + int timestamp, + double latitude, + double longitude, + double altitude, + GeoclueAccuracy *accuracy, + gpointer userdata) +{ + GeoclueGpsdData* gpsd = (GeoclueGpsdData*)userdata; + g_return_if_fail(gpsd->pos_cb); + + GeoclueAccuracyLevel level; + double horiz_acc; + double vert_acc; + geoclue_accuracy_get_details (accuracy, &level, &horiz_acc, &vert_acc); + + LocationPosition *pos = NULL; + LocationAccuracy *acc = NULL; + + if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE && + fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) { + if(fields & GEOCLUE_POSITION_FIELDS_ALTITUDE) + pos = location_position_new (timestamp, latitude, longitude, altitude, LOCATION_STATUS_3D_FIX); + else pos = location_position_new (timestamp, latitude, longitude, 0, LOCATION_STATUS_2D_FIX); + } else pos = location_position_new (0, 0, 0, 0, LOCATION_STATUS_NO_FIX); + + if (accuracy) { + GeoclueAccuracyLevel level; + double horiz_acc; + double vert_acc; + geoclue_accuracy_get_details (accuracy, &level, &horiz_acc, &vert_acc); + acc = location_accuracy_new (LOCATION_ACCURACY_LEVEL_DETAILED, horiz_acc, vert_acc); + } else acc = location_accuracy_new (LOCATION_ACCURACY_LEVEL_NONE, horiz_acc, vert_acc); + + MOD_LOGD("Position callback>> time(%d) lat(%f) long(%f) alt(%f) status(%d) acc_level(%d) hoz_acc(%f) vert_acc(%f)", + pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status, + acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + gpsd->pos_cb(TRUE, pos, acc, gpsd->userdata); + location_position_free (pos); + location_accuracy_free (acc); +} + +static void +velocity_callback (GeoclueVelocity *velocity, + GeoclueVelocityFields fields, + int timestamp, + double speed, + double direction, + double climb, + gpointer userdata) +{ + GeoclueGpsdData* gpsd = (GeoclueGpsdData*)userdata; + g_return_if_fail(gpsd->vel_cb); + + LocationVelocity *vel = NULL; + LocationAccuracy *acc = NULL; + + if (fields & GEOCLUE_VELOCITY_FIELDS_SPEED && + fields & GEOCLUE_VELOCITY_FIELDS_DIRECTION) { + if (fields & GEOCLUE_VELOCITY_FIELDS_CLIMB) vel = location_velocity_new (timestamp, speed, direction, climb); + else vel = location_velocity_new (timestamp, speed, direction, 0); + acc = location_accuracy_new (LOCATION_ACCURACY_LEVEL_DETAILED, 0, 0); + } else { + vel = location_velocity_new (0, 0, 0, 0); + acc = location_accuracy_new (LOCATION_ACCURACY_LEVEL_NONE, 0, 0); + } + MOD_LOGD("Velocity callback>> timestamp(%d) speed(%f) direction(%f) climb(%f) acc_level(%d) hoz_acc(%f) vert_acc(%f)", + vel->timestamp, vel->speed, vel->direction, vel->climb, + acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + + gpsd->vel_cb(TRUE, vel, acc, gpsd->userdata); + location_velocity_free (vel); + location_accuracy_free (acc); +} + +static void +_unref_geoclue(GeoclueGpsdData* gpsd) +{ + if(gpsd->pos) { + g_signal_handlers_disconnect_by_func(G_OBJECT (GEOCLUE_PROVIDER(gpsd->pos)), G_CALLBACK (status_callback), gpsd); + g_signal_handlers_disconnect_by_func(G_OBJECT (GEOCLUE_PROVIDER(gpsd->pos)), G_CALLBACK (position_callback), gpsd); + g_object_unref (gpsd->pos); + gpsd->pos = NULL; + } + + if( gpsd->vel != NULL){ + g_signal_handlers_disconnect_by_func(G_OBJECT (GEOCLUE_PROVIDER(gpsd->vel)), G_CALLBACK (velocity_callback), gpsd); + g_object_unref (gpsd->vel); + gpsd->vel = NULL; + } + gpsd->is_started = FALSE; +} + +static gboolean +_ref_geoclue(GeoclueGpsdData* gpsd) +{ + if(gpsd->is_started == TRUE){ + MOD_LOGW ("geoclue-gpsd is alredy started"); + return TRUE; + } + + gchar *service, *path; + service = g_strdup_printf ("org.freedesktop.Geoclue.Providers.Gpsd"); + path = g_strdup_printf ("/org/freedesktop/Geoclue/Providers/Gpsd"); + + if(!gpsd->pos){ + gpsd->pos = geoclue_position_new (service, path); + } + if(!gpsd->vel){ + gpsd->vel = geoclue_velocity_new (service, path); + } + g_free (service); + g_free (path); + if(!gpsd->pos || !gpsd->vel){ + MOD_LOGW ("Error while creating Geoclue object."); + _unref_geoclue(gpsd); + return FALSE; + } + + gpsd->is_started = TRUE; + g_signal_connect (G_OBJECT (GEOCLUE_PROVIDER(gpsd->pos)), "status-changed", G_CALLBACK (status_callback), gpsd); + g_signal_connect (G_OBJECT (GEOCLUE_PROVIDER(gpsd->pos)), "position-changed", G_CALLBACK (position_callback), gpsd); + g_signal_connect (G_OBJECT (GEOCLUE_PROVIDER(gpsd->vel)), "velocity-changed", G_CALLBACK (velocity_callback), gpsd); + + return TRUE; +} + +static int +start(gpointer handle, LocModStatusCB status_cb, LocModPositionCB pos_cb, LocModVelocityCB vel_cb, gpointer userdata) +{ + MOD_LOGD("start"); + GeoclueGpsdData* gpsd = (GeoclueGpsdData*)handle; + g_return_val_if_fail(gpsd, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(status_cb, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(pos_cb, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(vel_cb, LOCATION_ERROR_NOT_AVAILABLE); + + gpsd->status_cb = status_cb; + gpsd->pos_cb = pos_cb; + gpsd->vel_cb = vel_cb; + gpsd->userdata = userdata; + if (!_ref_geoclue(gpsd)) return LOCATION_ERROR_NOT_AVAILABLE; + return LOCATION_ERROR_NONE; +} + +static int +stop(gpointer handle) +{ + MOD_LOGD("stop"); + GeoclueGpsdData* gpsd = (GeoclueGpsdData*)handle; + g_return_val_if_fail(gpsd, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(gpsd->status_cb, LOCATION_ERROR_NOT_AVAILABLE); + _unref_geoclue(gpsd); + gpsd->status_cb(FALSE, LOCATION_STATUS_NO_FIX, gpsd->userdata); + return LOCATION_ERROR_NONE; +} + +static int +get_position( + gpointer handle, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + GeoclueGpsdData* gpsd = (GeoclueGpsdData*)handle; + g_return_val_if_fail(gpsd, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(gpsd->pos, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER); + + GeocluePositionFields fields; + int timestamp; + double lat, lon, alt; + GeoclueAccuracy *_accuracy = NULL; + GError *error = NULL; + + fields = geoclue_position_get_position (gpsd->pos, ×tamp, + &lat, &lon, &alt, + &_accuracy, &error); + if (error) { + MOD_LOGD ("Error getting position: %s", error->message); + g_error_free (error); + return LOCATION_ERROR_NOT_AVAILABLE; + } + + if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE && + fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) { + if(fields & GEOCLUE_POSITION_FIELDS_ALTITUDE) *position = location_position_new (timestamp, lat, lon, alt, LOCATION_STATUS_3D_FIX); + else *position = location_position_new (timestamp, lat, lon, 0, LOCATION_STATUS_2D_FIX); + } else *position = location_position_new (0, 0, 0, 0, LOCATION_STATUS_NO_FIX); + + if (_accuracy) { + GeoclueAccuracyLevel level; + double horiz_acc; + double vert_acc; + geoclue_accuracy_get_details (_accuracy, &level, &horiz_acc, &vert_acc); + *accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_DETAILED, horiz_acc, vert_acc); + geoclue_accuracy_free (_accuracy); + } else *accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_NONE, 0, 0); + + return LOCATION_ERROR_NONE; +} + +static int +get_velocity( + gpointer handle, + LocationVelocity **velocity, + LocationAccuracy **accuracy) +{ + GeoclueGpsdData* gpsd = (GeoclueGpsdData*)handle; + g_return_val_if_fail(gpsd, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(gpsd->vel, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER); + + GeoclueVelocityFields fields; + int timestamp; + double spd, dir, climb; + GError *error = NULL; + + fields = geoclue_velocity_get_velocity (gpsd->vel, ×tamp, + &spd, &dir, &climb, + &error); + if (error) { + MOD_LOGD ("Error getting velocity: %s", error->message); + g_error_free (error); + return LOCATION_ERROR_NOT_AVAILABLE; + } + + if (fields & GEOCLUE_VELOCITY_FIELDS_SPEED && + fields & GEOCLUE_VELOCITY_FIELDS_DIRECTION) { + if (fields & GEOCLUE_VELOCITY_FIELDS_CLIMB) *velocity = location_velocity_new (timestamp, spd, dir, climb); + else *velocity = location_velocity_new (timestamp, spd, dir, 0); + *accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_DETAILED, 0, 0); + } else { + *velocity = location_velocity_new (0, 0, 0, 0); + *accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_NONE, 0, 0); + } + return LOCATION_ERROR_NONE; +} + +static int +get_nmea(gpointer handle, + char **nmea_data) +{ + MOD_LOGD("get_nmea: not available"); + return LOCATION_ERROR_NOT_AVAILABLE; +} + +static int +get_satellite(gpointer handle, + LocationSatellite **satellite) +{ + MOD_LOGD("get_satellite: not available"); + return LOCATION_ERROR_NOT_AVAILABLE; +} + +static int +set_devname(gpointer handle, + const char *devname) +{ + GeoclueGpsdData* gpsd = (GeoclueGpsdData*)handle; + g_return_val_if_fail(gpsd, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(gpsd->devname, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(devname, LOCATION_ERROR_PARAMETER); + MOD_LOGD("set_devname: %s --> %s", gpsd->devname, devname); + g_stpcpy(gpsd->devname, devname); + + return LOCATION_ERROR_NONE; +} + + +static int +get_devname(gpointer handle, + char **devname) +{ + GeoclueGpsdData* gpsd = (GeoclueGpsdData*)handle; + g_return_val_if_fail(gpsd, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(gpsd->devname, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(devname, LOCATION_ERROR_PARAMETER); + + *devname = g_strdup(gpsd->devname); + MOD_LOGD("get_devname: %s", *devname); + + return LOCATION_ERROR_NONE; +} + +LOCATION_MODULE_API gpointer +init(LocModGpsOps* ops) +{ + MOD_LOGD("init"); + g_return_val_if_fail(ops, NULL); + ops->start = start; + ops->stop = stop ; + ops->get_position = get_position; + ops->get_velocity = get_velocity; + Dl_info info; + if (dladdr(&get_position, &info) == 0) { + MOD_LOGD("failed to get module name"); + } else if (g_str_has_prefix(info.dli_fname, "gps")) { + ops->get_nmea = get_nmea; + ops->get_satellite = get_satellite; + ops->set_devname = set_devname; + ops->get_devname = get_devname; + } + + GeoclueGpsdData* gpsd = g_new0(GeoclueGpsdData, 1); + g_return_val_if_fail(gpsd, NULL); + + g_stpcpy(gpsd->devname, "/dev/rfcomm0"); + gpsd->pos = NULL; + gpsd->vel = NULL; + gpsd->status_cb= NULL; + gpsd->pos_cb = NULL; + gpsd->vel_cb = NULL; + gpsd->userdata = NULL; + gpsd->is_started = FALSE; + + return (gpointer)gpsd; +} + +LOCATION_MODULE_API void +shutdown(gpointer handle) +{ + MOD_LOGD("shutdown"); + GeoclueGpsdData* gpsd = (GeoclueGpsdData*)handle; + g_return_if_fail(gpsd); + _unref_geoclue(gpsd); + if(gpsd->status_cb) gpsd->status_cb(FALSE, LOCATION_STATUS_NO_FIX, gpsd->userdata); + g_free(gpsd); +} diff --git a/modules/geoclue-nominatim.c b/modules/geoclue-nominatim.c new file mode 100644 index 0000000..2a10156 --- /dev/null +++ b/modules/geoclue-nominatim.c @@ -0,0 +1,490 @@ +/* + * location-geoclue-nominatim + * + * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Yunhan Kim , + * Genie Kim , Minjune Kim + * + * 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 +#include +#include + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "log.h" + +typedef struct { + char* service_name; + GeoclueGeocode* geocoder; + GeoclueReverseGeocode* rev_geocoder; +} NominatimHandle; + +typedef struct { + LocationPositionCB pos_cb; + LocationAddressCB addr_cb; + gpointer userdata; +} NominatimData; + +static GHashTable* +get_geoclue_addr_from_location_addr (const LocationAddress *address) +{ + if (!address) return NULL; + + GHashTable *geoclue_addr = geoclue_address_details_new(); + if (address->street) { + if (address->building_number) { + char *street_addr = g_strdup_printf ("%s %s", address->building_number, address->street); + geoclue_address_details_insert (geoclue_addr, GEOCLUE_ADDRESS_KEY_STREET, street_addr); + g_free (street_addr); + } else geoclue_address_details_insert (geoclue_addr, GEOCLUE_ADDRESS_KEY_STREET, address->street); + } + if (address->district) geoclue_address_details_insert (geoclue_addr, GEOCLUE_ADDRESS_KEY_AREA, address->district); + if (address->city) geoclue_address_details_insert (geoclue_addr, GEOCLUE_ADDRESS_KEY_LOCALITY, address->city); + if (address->state) geoclue_address_details_insert (geoclue_addr, GEOCLUE_ADDRESS_KEY_REGION, address->state); + if (address->country_code) geoclue_address_details_insert (geoclue_addr, GEOCLUE_ADDRESS_KEY_COUNTRY, address->country_code); + if (address->postal_code) geoclue_address_details_insert (geoclue_addr, GEOCLUE_ADDRESS_KEY_POSTALCODE, address->postal_code); + + return geoclue_addr; +} + +static LocationAddress* +get_location_addr_from_geoclue_addr (GHashTable *geoclue_addr) +{ + if (!geoclue_addr) return NULL; + + LocationAddress *addr = NULL; + + gchar *country, *region, *locality, *postalcode, *area, *street; + + country = g_hash_table_lookup (geoclue_addr, GEOCLUE_ADDRESS_KEY_COUNTRY); + region = g_hash_table_lookup (geoclue_addr, GEOCLUE_ADDRESS_KEY_REGION); + locality = g_hash_table_lookup (geoclue_addr, GEOCLUE_ADDRESS_KEY_LOCALITY); + area = g_hash_table_lookup (geoclue_addr, GEOCLUE_ADDRESS_KEY_AREA); + postalcode = g_hash_table_lookup (geoclue_addr, GEOCLUE_ADDRESS_KEY_POSTALCODE); + street = g_hash_table_lookup (geoclue_addr, GEOCLUE_ADDRESS_KEY_STREET); + + addr = location_address_new (NULL, street, area, locality, region, country, postalcode); + return addr; +} + +static LocationAccuracy * +get_location_acc_from_geoclue_acc (GeoclueAccuracy *acc) +{ + if (!acc) return NULL; + + LocationAccuracy *accuracy = NULL; + GeoclueAccuracyLevel level; + double horiz_acc; + double vert_acc; + geoclue_accuracy_get_details (acc, &level, &horiz_acc, &vert_acc); + + if (level == GEOCLUE_ACCURACY_LEVEL_DETAILED) accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_DETAILED, horiz_acc, vert_acc); + else if (level == GEOCLUE_ACCURACY_LEVEL_STREET) accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_STREET, horiz_acc, vert_acc); + else if (level == GEOCLUE_ACCURACY_LEVEL_POSTALCODE) accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_POSTALCODE, horiz_acc, vert_acc); + else if (level == GEOCLUE_ACCURACY_LEVEL_LOCALITY) accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_LOCALITY, horiz_acc, vert_acc); + else if (level == GEOCLUE_ACCURACY_LEVEL_REGION) accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_REGION, horiz_acc, vert_acc); + else if (level == GEOCLUE_ACCURACY_LEVEL_COUNTRY) accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_COUNTRY, horiz_acc, vert_acc); + else accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_NONE, 0, 0); + + return accuracy; +} + +static void +_unref_geoclue(NominatimHandle* handle) +{ + if (handle->geocoder) { + g_object_unref (handle->geocoder); + handle->geocoder = NULL; + } + if (handle->rev_geocoder) { + g_object_unref (handle->rev_geocoder); + handle->rev_geocoder = NULL; + } +} + +static gboolean +_ref_geoclue(NominatimHandle* handle) +{ + gchar *service, *path; + service = g_strdup_printf ("org.freedesktop.Geoclue.Providers.Nominatim"); + path = g_strdup_printf ("/org/freedesktop/Geoclue/Providers/Nominatim"); + + if (!handle->geocoder) handle->geocoder = geoclue_geocode_new (service, path); + if (!handle->rev_geocoder) handle->rev_geocoder = geoclue_reverse_geocode_new (service, path); + + if(!handle->geocoder || !handle->rev_geocoder){ + MOD_LOGW ("Error while creating Geoclue object."); + _unref_geoclue(handle); + return FALSE; + } + return TRUE; +} + +static void +address_cb (GeoclueReverseGeocode *revgeocode, + GHashTable *details, + GeoclueAccuracy *accuracy, + GError *error, + gpointer userdata) +{ + NominatimData* data = (NominatimData*)userdata; + g_return_if_fail(data->addr_cb); + + LocationAddress *addr = NULL; + LocationAccuracy *acc = NULL; + LocationError err = LOCATION_ERROR_NONE; + + if (error) { + MOD_LOGW ("Error getting reverse geocode: %s", error->message); + err = LOCATION_ERROR_NOT_AVAILABLE; + } else { + if (accuracy) acc = get_location_acc_from_geoclue_acc (accuracy); + else acc = location_accuracy_new (LOCATION_ACCURACY_LEVEL_NONE, 0, 0); + + if (details) addr = get_location_addr_from_geoclue_addr (details); + } + + data->addr_cb (err, addr, acc, data->userdata); + if (addr) location_address_free (addr); + if (acc) location_accuracy_free (acc); + g_free (data); +} + +static void _free_pos_list_item(gpointer data) +{ + g_return_if_fail(data); + + LocationPosition *position = (LocationPosition *)data; + location_position_free(position); +} + +static void _free_acc_list_item(gpointer data) +{ + g_return_if_fail(data); + + LocationAccuracy *accuracy = (LocationAccuracy *)data; + location_accuracy_free(accuracy); +} + +static void position_cb (GeoclueGeocode *geocode, + GeocluePositionFields fields, + double latitude, + double longitude, + double altitude, + GeoclueAccuracy *accuracy, + GError *error, + gpointer userdata) +{ + NominatimData* data = (NominatimData*)userdata; + GList *pos_list = NULL; + GList *acc_list = NULL; + + g_return_if_fail(data->pos_cb); + + LocationPosition *pos = NULL; + LocationAccuracy *acc = NULL; + LocationError err = LOCATION_ERROR_NONE; + + if (error) { + MOD_LOGW ("Error getting geocode: %s", error->message); + err = LOCATION_ERROR_NOT_AVAILABLE; + } else { + if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE && + fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) { + if(fields & GEOCLUE_POSITION_FIELDS_ALTITUDE) pos = location_position_new (0, latitude, longitude, altitude, LOCATION_STATUS_3D_FIX); + else pos = location_position_new (0, latitude, longitude, 0, LOCATION_STATUS_2D_FIX); + + pos_list = g_list_append(pos_list, pos); + } else { + err = LOCATION_ERROR_NOT_FOUND; + } + + if (accuracy) { + acc = get_location_acc_from_geoclue_acc (accuracy); + acc_list = g_list_append(acc_list, acc); + } + } + data->pos_cb (err, pos_list, acc_list, data->userdata); + + if (pos_list) g_list_free_full(pos_list, _free_pos_list_item); + if (acc_list) g_list_free_full(pos_list, _free_acc_list_item); + g_free (data); + +} + + +static int +get_geocode (gpointer handle, + const LocationAddress *addr, + GList **pos_list, + GList **acc_list) +{ + NominatimHandle *nominatim = (NominatimHandle *)handle; + g_return_val_if_fail(nominatim, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(addr, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(pos_list, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(acc_list, LOCATION_ERROR_PARAMETER); + + double lat, lon, alt; + GeoclueAccuracy *geoclue_acc = NULL; + GError *error = NULL; + LocationPosition *pos = NULL; + LocationAccuracy *acc = NULL; + LocationError err = LOCATION_ERROR_NONE; + + GHashTable* geoclue_addr = get_geoclue_addr_from_location_addr (addr); + GeocluePositionFields fields = geoclue_geocode_address_to_position (nominatim->geocoder, geoclue_addr, + &lat, &lon, &alt, + &geoclue_acc, &error); + g_hash_table_destroy (geoclue_addr); + + if (error) { + MOD_LOGW ("Error getting geocode: %s", error->message); + g_error_free (error); + return LOCATION_ERROR_NOT_AVAILABLE; + } + + if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE && + fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) { + if(fields & GEOCLUE_POSITION_FIELDS_ALTITUDE) pos = location_position_new (0, lat, lon, alt, LOCATION_STATUS_3D_FIX); + else pos = location_position_new (0, lat, lon, 0, LOCATION_STATUS_2D_FIX); + + *pos_list = g_list_append(*pos_list, pos); + } + else { + err = LOCATION_ERROR_NOT_FOUND; + } + + if (geoclue_acc) { + acc = get_location_acc_from_geoclue_acc (geoclue_acc); + geoclue_accuracy_free (geoclue_acc); + + *acc_list = g_list_append(*acc_list, acc); + } + + if (pos) location_position_free (pos); + if (acc) location_accuracy_free (acc); + + return err; +} + + +static int +get_geocode_async (gpointer handle, + const LocationAddress * addr, + LocationPositionCB callback, + gpointer userdata) +{ + NominatimHandle *nominatim = (NominatimHandle *)handle; + g_return_val_if_fail(nominatim, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(addr, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(callback, LOCATION_ERROR_PARAMETER); + + GHashTable* geoclue_addr = get_geoclue_addr_from_location_addr (addr); + NominatimData *data = g_new0 (NominatimData, 1); + data->pos_cb = callback; + data->userdata = userdata; + geoclue_geocode_address_to_position_async (nominatim->geocoder, geoclue_addr, position_cb, data); + g_hash_table_destroy (geoclue_addr); + + return LOCATION_ERROR_NONE; +} + +static int +get_geocode_freetext(gpointer handle, + const const gchar* addr, + GList **pos_list, + GList **acc_list) +{ + NominatimHandle *nominatim = (NominatimHandle *)handle; + g_return_val_if_fail(nominatim, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(addr, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(pos_list, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(acc_list, LOCATION_ERROR_PARAMETER); + + double lat, lon, alt; + GeoclueAccuracy *geoclue_acc = NULL; + GError *error = NULL; + LocationPosition *pos = NULL; + LocationAccuracy *acc = NULL; + LocationError err = LOCATION_ERROR_NONE; + + GeocluePositionFields fields = geoclue_geocode_freeform_address_to_position (nominatim->geocoder, addr, + &lat, &lon, &alt, + &geoclue_acc, &error); + if (error) { + MOD_LOGW ("Error getting geocode: %s", error->message); + g_error_free (error); + return LOCATION_ERROR_NOT_AVAILABLE; + } + + if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE && + fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) { + if(fields & GEOCLUE_POSITION_FIELDS_ALTITUDE) pos = location_position_new (0, lat, lon, alt, LOCATION_STATUS_3D_FIX); + else pos = location_position_new (0, lat, lon, 0, LOCATION_STATUS_2D_FIX); + *pos_list = g_list_append(*pos_list, pos); + } + else { + err = LOCATION_ERROR_NOT_FOUND; + } + + if (geoclue_acc) { + acc = get_location_acc_from_geoclue_acc (geoclue_acc); + geoclue_accuracy_free (geoclue_acc); + *acc_list = g_list_append(*acc_list, acc); + } + + if (pos) location_position_free (pos); + if (acc) location_accuracy_free (acc); + return err; +} + + +static int +get_geocode_freetext_async (gpointer handle, + const gchar* addr, + LocationPositionCB callback, + gpointer userdata) +{ + NominatimHandle *nominatim = (NominatimHandle *)handle; + g_return_val_if_fail(nominatim, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(addr, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(callback, LOCATION_ERROR_PARAMETER); + + NominatimData *data = g_new0 (NominatimData, 1); + data->pos_cb = callback; + data->userdata = userdata; + geoclue_geocode_freeform_address_to_position_async (nominatim->geocoder, addr, position_cb, data); + + return LOCATION_ERROR_NONE; +} + +static int +get_reverse_geocode(gpointer handle, + const LocationPosition *pos, + LocationAddress **addr, + LocationAccuracy **acc) +{ + NominatimHandle *nominatim = (NominatimHandle *)handle; + g_return_val_if_fail(nominatim, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(pos, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(addr, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(acc, LOCATION_ERROR_PARAMETER); + + GeoclueAccuracy *addr_acc = NULL; + GError *error = NULL; + GHashTable* geoclue_addr = NULL; + + double lat = pos->latitude; + double lon = pos->longitude; + GeoclueAccuracy *pos_acc = geoclue_accuracy_new (GEOCLUE_ACCURACY_LEVEL_DETAILED, 0.0, 0.0); + + gboolean success = geoclue_reverse_geocode_position_to_address (nominatim->rev_geocoder, lat, lon, + pos_acc, &geoclue_addr, + &addr_acc, &error); + geoclue_accuracy_free (pos_acc); + + if (!success || error) { + MOD_LOGW ("Error getting reverse geocode: %s", error->message); + g_error_free (error); + return LOCATION_ERROR_NOT_AVAILABLE; + } + + if (addr_acc) { + *acc = get_location_acc_from_geoclue_acc (addr_acc); + geoclue_accuracy_free (addr_acc); + } else *acc = location_accuracy_new (LOCATION_ACCURACY_LEVEL_NONE, 0, 0); + if (geoclue_addr) { + *addr = get_location_addr_from_geoclue_addr (geoclue_addr); + g_hash_table_destroy (geoclue_addr); + } + + return LOCATION_ERROR_NONE; +} + +static int +get_reverse_geocode_async (gpointer handle, + const LocationPosition *pos, + LocationAddressCB callback, + gpointer userdata) +{ + NominatimHandle *nominatim = (NominatimHandle *)handle; + g_return_val_if_fail(nominatim, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(pos, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(callback, LOCATION_ERROR_PARAMETER); + + double lat = pos->latitude; + double lon = pos->longitude; + GeoclueAccuracy *pos_acc = geoclue_accuracy_new (GEOCLUE_ACCURACY_LEVEL_DETAILED, 0.0, 0.0);; + NominatimData *data = g_new0 (NominatimData, 1); + data->addr_cb = callback; + data->userdata = userdata; + geoclue_reverse_geocode_position_to_address_async (nominatim->rev_geocoder, + lat, lon, pos_acc, + address_cb, data); + geoclue_accuracy_free (pos_acc); + + return LOCATION_ERROR_NONE; +} + +static int +get_service_name (gpointer handle, + gchar **service_name) +{ + NominatimHandle *nominatim = (NominatimHandle *)handle; + g_return_val_if_fail(nominatim, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (service_name, LOCATION_ERROR_PARAMETER); + *service_name = g_strdup (nominatim->service_name); + return LOCATION_ERROR_NONE; +} + +LOCATION_MODULE_API gpointer +init (LocModGeoOps* ops) +{ + MOD_LOGD("init"); + g_return_val_if_fail(ops, NULL); + NominatimHandle *handle = g_new0 (NominatimHandle, 1); + if (!_ref_geoclue(handle)) { + g_free (handle); + return NULL; + } + handle->service_name = g_strdup ("Nominatim"); + ops->get_service_name = get_service_name; + ops->get_geocode = get_geocode; + ops->get_geocode_freetext = get_geocode_freetext; + ops->get_reverse_geocode = get_reverse_geocode; + ops->get_geocode_async = get_geocode_async; + ops->get_geocode_freetext_async = get_geocode_freetext_async; + ops->get_reverse_geocode_async = get_reverse_geocode_async; + return (gpointer)handle; +} + +LOCATION_MODULE_API void +shutdown (gpointer handle) +{ + MOD_LOGD("shutdown"); + g_return_if_fail(handle); + NominatimHandle *nominatim = (NominatimHandle *)handle; + g_free (nominatim->service_name); + _unref_geoclue(nominatim); + g_free (nominatim); +} diff --git a/modules/log.h b/modules/log.h new file mode 100644 index 0000000..8548bc5 --- /dev/null +++ b/modules/log.h @@ -0,0 +1,46 @@ +/* + * location-module + * + * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Youngae Kang , Yunhan Kim , + * Genie Kim , Minjune Kim + * + * 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 __LOCATION_LOG_H__ +#define __LOCATION_LOG_H__ + +#define TAG_LOCATION "location_mod" + +#ifdef MOD_DLOG_DEBUG // if debug mode, show filename & line number +#include +#define MOD_LOGD(fmt,args...) SLOG(LOG_DEBUG, TAG_LOCATION, "[%-15s:%-4d:%-27s][Mod]"fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##args) +#define MOD_LOGW(fmt,args...) SLOG(LOG_WARN, TAG_LOCATION, "[%-15s:%-4d:%-27s][Mod]"fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##args) +#define MOD_LOGI(fmt,args...) SLOG(LOG_INFO, TAG_LOCATION, "[%-15s:%-4d:%-27s][Mod]"fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##args) +#define MOD_LOGE(fmt,args...) SLOG(LOG_ERROR, TAG_LOCATION, "[%-15s:%-4d:%-27s][Mod]"fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##args) +#elif MOD_DLOG_RELEASE // if release mode, do not show filename & line number +#include +#define MOD_LOGD(fmt,args...) SLOG(LOG_DEBUG, TAG_LOCATION, "[Mod]"fmt"\n", ##args) +#define MOD_LOGW(fmt,args...) SLOG(LOG_WARN, TAG_LOCATION, "[Mod]"fmt"\n", ##args) +#define MOD_LOGI(fmt,args...) SLOG(LOG_INFO, TAG_LOCATION, "[Mod]"fmt"\n", ##args) +#define MOD_LOGE(fmt,args...) SLOG(LOG_ERROR, TAG_LOCATION, "[Mod]:"fmt"\n", ##args) +#else // if do not use dlog +#define MOD_LOGD(...) g_debug(__VA_ARGS__); +#define MOD_LOGW(...) g_warning(__VA_ARGS__); +#define MOD_LOGI(...) g_message(__VA_ARGS__); +#define MOD_LOGE(...) g_error(__VA_ARGS__); +#endif + +#endif diff --git a/packaging/location-module.spec b/packaging/location-module.spec new file mode 100755 index 0000000..dfe2975 --- /dev/null +++ b/packaging/location-module.spec @@ -0,0 +1,42 @@ +Name: location-module +Summary: Location module +Version: 0.1.12 +Release: 5 +Group: TO_BE/FILLED_IN +License: TO_BE/FILLED_IN +Source0: %{name}-%{version}.tar.gz +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(location) +BuildRequires: pkgconfig(geoclue) +BuildRequires: pkgconfig(vconf) + + +%description +Location module + + +%package -n location-geoclue-nominatim +Summary: geoclue-nominatim geocode module for location +Group: TO_BE/FILLED_IN + +%description -n location-geoclue-nominatim +geoclue-nominatim geocode module for location + +%prep +%setup -q + +%build +./autogen.sh +%configure --prefix=$(PREFIX) --enable-dlog --enable-debug + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +%files -n location-geoclue-nominatim +%defattr(-,root,root,-) +%{_libdir}/location/module/libgeocode0.so +%{_libdir}/location/module/libgeocode0.so.* + -- 2.7.4