From 87d87fa02f1b24872d7ce586cae08953a0d4541a Mon Sep 17 00:00:00 2001 From: Minjune Kim Date: Tue, 21 Aug 2012 18:21:08 +0900 Subject: [PATCH] Release Tizen2.0 beta --- AUTHORS | 1 - configure.ac | 4 +- debian/changelog | 61 ++-- debian/control | 4 +- modules/Makefile.am | 16 +- modules/{ => gpsd}/geoclue-gpsd.c | 0 modules/log.h | 2 +- .../location-osm-geocode.c} | 305 +++-------------- modules/osm/location-osm-geocode.h | 42 +++ modules/osm/location-osm-poi.c | 251 ++++++++++++++ modules/osm/location-osm-poi.h | 46 +++ modules/osm/location-osm-route.c | 239 +++++++++++++ modules/osm/location-osm-route.h | 41 +++ modules/osm/location-osm.c | 325 ++++++++++++++++++ modules/osm/location-osm.h | 46 +++ modules/osm/osm-http.c | 381 +++++++++++++++++++++ modules/osm/osm-http.h | 46 +++ modules/osm/osm-route-yours.c | 98 ++++++ modules/osm/osm-route-yours.h | 27 ++ packaging/location-module.manifest | 5 - packaging/location-module.spec | 18 +- 21 files changed, 1646 insertions(+), 312 deletions(-) rename modules/{ => gpsd}/geoclue-gpsd.c (100%) rename modules/{geoclue-nominatim.c => osm/location-osm-geocode.c} (54%) create mode 100644 modules/osm/location-osm-geocode.h create mode 100644 modules/osm/location-osm-poi.c create mode 100644 modules/osm/location-osm-poi.h create mode 100644 modules/osm/location-osm-route.c create mode 100644 modules/osm/location-osm-route.h create mode 100644 modules/osm/location-osm.c create mode 100644 modules/osm/location-osm.h create mode 100644 modules/osm/osm-http.c create mode 100644 modules/osm/osm-http.h create mode 100644 modules/osm/osm-route-yours.c create mode 100644 modules/osm/osm-route-yours.h delete mode 100644 packaging/location-module.manifest mode change 100644 => 100755 packaging/location-module.spec diff --git a/AUTHORS b/AUTHORS index 19ef850..cc7be1c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,4 +1,3 @@ Youngae Kang Yunhan Kim Genie Kim -Minjune Kim diff --git a/configure.ac b/configure.ac index 4aef127..b011442 100755 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ 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]) +AC_CONFIG_SRCDIR([modules]) AM_INIT_AUTOMAKE([1.10.2 foreign -Wall -Werror]) # Check programs for making executable @@ -49,7 +49,7 @@ AC_COMPILE_IFELSE( AC_MSG_RESULT($has_visibility) # Checks libraries -PKG_CHECK_MODULES(MODULE, [glib-2.0 gmodule-2.0 geoclue location]) +PKG_CHECK_MODULES(MODULE, [glib-2.0 gmodule-2.0 geoclue location libcurl json-glib-1.0 dlog]) AC_SUBST(MODULE_LIBS) AC_SUBST(MODULE_CFLAGS) diff --git a/debian/changelog b/debian/changelog index 211d97e..7f350fd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,41 @@ +location-module (0.1.20-4) unstable; urgency=low + + * Add LocationMapPref in geocode + * Tag: location-module_0.1.20-4 + + -- Minjune Kim Mon, 20 Aug 2012 11:28:25 +0900 + +location-module (0.1.20-3) unstable; urgency=low + + * Change lib name from libmap-service.so to libmap-service-osm + * Tag: location-module_0.1.20-3 + + -- Minjune Kim Tue, 07 Aug 2012 21:30:04 +0900 + +location-module (0.1.20-2) unstable; urgency=low + + * Seperate map service from location service + * Tag: location-module_0.1.20-2 + + -- Minjune Kim Mon, 23 Jul 2012 17:45:00 +0900 + +location-module (0.1.20-1) unstable; urgency=low + + * Add POI + * Tag: location-module_0.1.20-1 + + -- Minjune Kim Mon, 02 Jul 2012 23:30:51 +0900 + +location-module (0.1.19-1) unstable; urgency=low + + * Add route. + * Tag: location-module_0.1.19-1 + + -- Genie Kim Wed, 30 May 2012 19:56:33 +0900 + location-module (0.1.18-4) unstable; urgency=low * Define Capability API proto. - * Git: pkgs/l/location-module * Tag: location-module_0.1.18-4 -- Minjune Kim Wed, 14 Mar 2012 20:49:29 +0900 @@ -9,7 +43,6 @@ location-module (0.1.18-4) unstable; urgency=low location-module (0.1.18-3) unstable; urgency=low * fix bug : pos -> acc list - * Git: pkgs/l/location-module * Tag: location-module_0.1.18-3 -- Genie Kim Fri, 02 Mar 2012 15:06:50 +0900 @@ -17,7 +50,6 @@ location-module (0.1.18-3) unstable; urgency=low location-module (0.1.18-2) unstable; urgency=low * Change lib name to libmap-service - * Git: pkgs/l/location-module * Tag: location-module_0.1.18-2 -- Genie Kim Fri, 17 Feb 2012 21:36:20 +0900 @@ -25,7 +57,6 @@ location-module (0.1.18-2) unstable; urgency=low location-module (0.1.18-1) unstable; urgency=low * remove location-geoclue-gpsd - * Git: pkgs/l/location-module * Tag: location-module_0.1.18-1 -- Genie Kim Fri, 10 Feb 2012 16:18:30 +0900 @@ -33,7 +64,6 @@ location-module (0.1.18-1) unstable; urgency=low location-module (0.1.17-1) unstable; urgency=low * Support multiple result of geocode but it is workaround. - * Git: pkgs/l/location-module * Tag: location-module_0.1.17-1 -- Minjune Kim Thu, 09 Feb 2012 11:46:50 +0900 @@ -41,7 +71,6 @@ location-module (0.1.17-1) unstable; urgency=low location-module (0.1.16-4) unstable; urgency=low * Modify lib path on postinst - * Git: pkgs/l/location-module * Tag: location-module_0.1.16-4 -- Minjune Kim Wed, 01 Feb 2012 14:26:56 +0900 @@ -49,7 +78,6 @@ location-module (0.1.16-4) unstable; urgency=low location-module (0.1.16-3) unstable; urgency=low * Fix bug while using WPS module. - * Git: pkgs/l/location-module * Tag: location-module_0.1.16-3 -- Minjune Kim Mon, 19 Dec 2011 18:59:35 +0900 @@ -57,7 +85,6 @@ location-module (0.1.16-3) unstable; urgency=low location-module (0.1.16-2) unstable; urgency=low * generate link file to support wps method on SDK. - * Git: pkgs/l/location-module * Tag: location-module_0.1.16-2 -- Minjune Kim Fri, 09 Dec 2011 20:15:04 +0900 @@ -65,7 +92,6 @@ location-module (0.1.16-2) unstable; urgency=low location-module (0.1.16-1) unstable; urgency=low * add geoclue gpsd module - * Git: pkgs/l/location-module * Tag: location-module_0.1.16-1 -- Genie Kim Wed, 07 Dec 2011 16:50:31 +0900 @@ -73,7 +99,6 @@ location-module (0.1.16-1) unstable; urgency=low location-module (0.1.15-1) unstable; urgency=low * remove not using packages(hostip/opencellid) - * Git: pkgs/l/location-module * Tag: location-module_0.1.15-1 -- Genie Kim Tue, 06 Dec 2011 22:40:14 +0900 @@ -81,7 +106,6 @@ location-module (0.1.15-1) unstable; urgency=low location-module (0.1.14-1) unstable; urgency=low * move gpsd module to geoclue-providers for last knonw position - * Git: pkgs/l/location-module * Tag: location-module_0.1.14-1 -- Genie Kim Sat, 26 Nov 2011 12:17:29 +0900 @@ -89,7 +113,6 @@ location-module (0.1.14-1) unstable; urgency=low location-module (0.1.13-1) unstable; urgency=low * use time_t for timestamp - * Git: pkgs/l/location-module * Tag: location-module_0.1.13-1 -- Genie Kim Mon, 17 Oct 2011 13:36:42 +0900 @@ -97,7 +120,6 @@ location-module (0.1.13-1) unstable; urgency=low location-module (0.1.12-1) unstable; urgency=low * fixed BS about gmtime_r() - * Git: pkgs/l/location-module * Tag: location-module_0.1.12-1 -- Genie Kim Thu, 01 Sep 2011 14:04:33 +0900 @@ -105,7 +127,6 @@ location-module (0.1.12-1) unstable; urgency=low location-module (0.1.11-1) unstable; urgency=low * fixed prevent defect - * Git: pkgs/l/location-module * Tag: location-module_0.1.11-1 -- Genie Kim Fri, 26 Aug 2011 13:38:29 +0900 @@ -113,7 +134,6 @@ location-module (0.1.11-1) unstable; urgency=low location-module (0.1.10-2) unstable; urgency=low * change boilerplate - * Git: pkgs/l/location-module * Tag: location-module_0.1.10-2 -- Genie Kim Wed, 20 Jul 2011 17:52:15 +0900 @@ -121,7 +141,6 @@ location-module (0.1.10-2) unstable; urgency=low location-module (0.1.10-1) unstable; urgency=low * Package: Release new location-geoclue-nominatim package - * Git: pkgs/l/location-module * Tag: location-module_0.1.10-1 -- Tae-Hwan Kim Wed, 01 Jun 2011 21:14:33 +0900 @@ -129,7 +148,6 @@ location-module (0.1.10-1) unstable; urgency=low location-module (0.1.9-1) unstable; urgency=low * Remove callbacks when location stops - * Git: pkgs/l/location-module * Tag: location-module_0.1.9-1 -- Tae-Hwan Kim Fri, 13 May 2011 19:28:42 +0900 @@ -137,7 +155,6 @@ location-module (0.1.9-1) unstable; urgency=low location-module (0.1.8-2) unstable; urgency=low * Apply New Location APIs - * Git: pkgs/l/location-module * Tag: location-module_0.1.8-2 -- Tae-Hwan Kim Wed, 20 Apr 2011 11:16:12 +0900 @@ -145,7 +162,6 @@ location-module (0.1.8-2) unstable; urgency=low location-module (0.1.7-1) unstable; urgency=low * Fix depends & timestamp - * Git: pkgs/l/location-module * Tag: location-module_0.1.7-1 -- Tae-Hwan Kim Wed, 16 Feb 2011 21:02:21 +0900 @@ -153,7 +169,6 @@ location-module (0.1.7-1) unstable; urgency=low location-module (0.1.6-1) unstable; urgency=low * Add geoclue-hostip module & geoclue-opencellid & geoclue-opencellid module - * Git: pkgs/l/location-module * Tag: location-module_0.1.6-1 -- Tae-Hwan Kim Wed, 19 Jan 2011 13:32:18 +0900 @@ -161,7 +176,6 @@ location-module (0.1.6-1) unstable; urgency=low location-module (0.1.5-1) unstable; urgency=low * Adapt to plug change again - * Git: pkgs/l/location-module * Tag: location-module_0.1.5-1 -- Tae-Hwan Kim Tue, 21 Dec 2010 17:31:07 +0900 @@ -169,7 +183,6 @@ location-module (0.1.5-1) unstable; urgency=low location-module (0.1.4-0) unstable; urgency=low * Adapt to plugin change - * Git: pkgs/l/location-module * Tag: location-module_0.1.4-0 -- Tae-Hwan Kim Mon, 13 Dec 2010 10:32:35 +0900 @@ -177,7 +190,6 @@ location-module (0.1.4-0) unstable; urgency=low location-module (0.1.3-0) unstable; urgency=low * Initialize is_started to FALSE - * Git: pkgs/l/location-module * Tag: location-module_0.1.3-0 -- Tae-Hwan Kim Thu, 02 Dec 2010 13:36:02 +0900 @@ -185,7 +197,6 @@ location-module (0.1.3-0) unstable; urgency=low location-module (0.1.2-0) unstable; urgency=low * Prevent duplicate start - * Git: pkgs/l/location-module * Tag: location-module_0.1.2-0 -- Tae-Hwan Kim Mon, 29 Nov 2010 11:17:46 +0900 @@ -193,7 +204,6 @@ location-module (0.1.2-0) unstable; urgency=low location-module (0.1.1-0) unstable; urgency=low * Add debug pkg & disable geoclue-skyhook - * Git: pkgs/l/location-module * Tag: location-module_0.1.1-0 -- Tae-Hwan Kim Wed, 24 Nov 2010 22:21:17 +0900 @@ -201,7 +211,6 @@ location-module (0.1.1-0) unstable; urgency=low location-module (0.1.0-1) unstable; urgency=low * Initial release - * Git: 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/control b/debian/control index 7db09a1..027b3c7 100755 --- a/debian/control +++ b/debian/control @@ -2,13 +2,13 @@ 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 +Build-Depends: debhelper (>= 5), libglib2.0-dev, libslp-location-dev, libgeoclue-dev, libvconf-dev, libcurl-dev, libjson-glib-dev Standards-Version: 3.7.2 Package: location-geoclue-nominatim Section: utils Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} +Depends: ${shlibs:Depends}, ${misc:Depends} libcurl3 Description: geoclue-nominatim geocode module for location Package: location-module-dbg diff --git a/modules/Makefile.am b/modules/Makefile.am index 6cd1d91..ce51114 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -1,10 +1,16 @@ pkgdir = $(libdir)/location/module -pkg_LTLIBRARIES = libmap-service0.la +pkg_LTLIBRARIES = libmap-service-osm.la -# map-serivce nominatim plugin -libmap_service0_la_SOURCES = geoclue-nominatim.c $(utility) -libmap_service0_la_CFLAGS = \ +# map-serivce OpenStreetMap plugin +libmap_service_osm_la_SOURCES = osm/location-osm.c \ + osm/location-osm-route.c \ + osm/location-osm-poi.c \ + osm/location-osm-geocode.c \ + osm/osm-http.c \ + osm/osm-route-yours.c \ + $(utility) +libmap_service_osm_la_CFLAGS = \ -fPIC\ $(MODULE_CFLAGS) -libmap_service0_la_LIBADD = \ +libmap_service_osm_la_LIBADD = \ $(MODULE_LIBS) diff --git a/modules/geoclue-gpsd.c b/modules/gpsd/geoclue-gpsd.c similarity index 100% rename from modules/geoclue-gpsd.c rename to modules/gpsd/geoclue-gpsd.c diff --git a/modules/log.h b/modules/log.h index 8548bc5..5016669 100644 --- a/modules/log.h +++ b/modules/log.h @@ -22,7 +22,7 @@ #ifndef __LOCATION_LOG_H__ #define __LOCATION_LOG_H__ -#define TAG_LOCATION "location_mod" +#define TAG_LOCATION "location_osm" #ifdef MOD_DLOG_DEBUG // if debug mode, show filename & line number #include diff --git a/modules/geoclue-nominatim.c b/modules/osm/location-osm-geocode.c similarity index 54% rename from modules/geoclue-nominatim.c rename to modules/osm/location-osm-geocode.c index dafc6ee..7803637 100644 --- a/modules/geoclue-nominatim.c +++ b/modules/osm/location-osm-geocode.c @@ -1,5 +1,5 @@ /* - * location-geoclue-nominatim + * location-module * * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved. * @@ -19,33 +19,11 @@ * 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; +#include "location-osm.h" static GHashTable* -get_geoclue_addr_from_location_addr (const LocationAddress *address) +_get_geoclue_addr_from_location_addr (const LocationAddress *address) { if (!address) return NULL; @@ -67,7 +45,7 @@ get_geoclue_addr_from_location_addr (const LocationAddress *address) } static LocationAddress* -get_location_addr_from_geoclue_addr (GHashTable *geoclue_addr) +_get_location_addr_from_geoclue_addr (GHashTable *geoclue_addr) { if (!geoclue_addr) return NULL; @@ -86,8 +64,9 @@ get_location_addr_from_geoclue_addr (GHashTable *geoclue_addr) return addr; } + static LocationAccuracy * -get_location_acc_from_geoclue_acc (GeoclueAccuracy *acc) +_get_location_acc_from_geoclue_acc (GeoclueAccuracy *acc) { if (!acc) return NULL; @@ -109,44 +88,13 @@ get_location_acc_from_geoclue_acc (GeoclueAccuracy *acc) } 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; + OsmHandleData* data = (OsmHandleData*)userdata; g_return_if_fail(data->addr_cb); LocationAddress *addr = NULL; @@ -157,10 +105,10 @@ address_cb (GeoclueReverseGeocode *revgeocode, 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); + 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); + if (details) addr = _get_location_addr_from_geoclue_addr (details); } data->addr_cb (err, addr, acc, data->userdata); @@ -169,7 +117,8 @@ address_cb (GeoclueReverseGeocode *revgeocode, g_free (data); } -static void _free_pos_list_item(gpointer data) +static void +_free_pos_list_item(gpointer data) { g_return_if_fail(data); @@ -177,7 +126,8 @@ static void _free_pos_list_item(gpointer data) location_position_free(position); } -static void _free_acc_list_item(gpointer data) +static void +_free_acc_list_item(gpointer data) { g_return_if_fail(data); @@ -185,7 +135,8 @@ static void _free_acc_list_item(gpointer data) location_accuracy_free(accuracy); } -static void position_cb (GeoclueGeocode *geocode, +static void +position_cb (GeoclueGeocode *geocode, GeocluePositionFields fields, double latitude, double longitude, @@ -194,7 +145,7 @@ static void position_cb (GeoclueGeocode *geocode, GError *error, gpointer userdata) { - NominatimData* data = (NominatimData*)userdata; + OsmHandleData* data = (OsmHandleData*)userdata; GList *pos_list = NULL; GList *acc_list = NULL; @@ -219,7 +170,7 @@ static void position_cb (GeoclueGeocode *geocode, } if (accuracy) { - acc = get_location_acc_from_geoclue_acc (accuracy); + acc = _get_location_acc_from_geoclue_acc (accuracy); acc_list = g_list_append(acc_list, acc); } } @@ -232,18 +183,12 @@ static void position_cb (GeoclueGeocode *geocode, } -static int -get_geocode (gpointer handle, +int +osm_get_geocode (OsmHandle *osm, 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; @@ -251,8 +196,8 @@ get_geocode (gpointer handle, 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, + GHashTable* geoclue_addr = _get_geoclue_addr_from_location_addr (addr); + GeocluePositionFields fields = geoclue_geocode_address_to_position (osm->geocoder, geoclue_addr, &lat, &lon, &alt, &geoclue_acc, &error); g_hash_table_destroy (geoclue_addr); @@ -275,7 +220,7 @@ get_geocode (gpointer handle, } if (geoclue_acc) { - acc = get_location_acc_from_geoclue_acc (geoclue_acc); + acc = _get_location_acc_from_geoclue_acc (geoclue_acc); geoclue_accuracy_free (geoclue_acc); *acc_list = g_list_append(*acc_list, acc); @@ -287,40 +232,28 @@ get_geocode (gpointer handle, return err; } - -static int -get_geocode_async (gpointer handle, +int +osm_get_geocode_async (OsmHandle *osm, 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); + GHashTable* geoclue_addr = _get_geoclue_addr_from_location_addr (addr); + OsmHandleData *data = g_new0 (OsmHandleData, 1); data->pos_cb = callback; data->userdata = userdata; - geoclue_geocode_address_to_position_async (nominatim->geocoder, geoclue_addr, position_cb, data); + geoclue_geocode_address_to_position_async (osm->geocoder, geoclue_addr, position_cb, data); g_hash_table_destroy (geoclue_addr); return LOCATION_ERROR_NONE; } -static int -get_geocode_freetext(gpointer handle, +int +osm_get_geocode_freetext(OsmHandle *osm, 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; @@ -328,7 +261,7 @@ get_geocode_freetext(gpointer handle, LocationAccuracy *acc = NULL; LocationError err = LOCATION_ERROR_NONE; - GeocluePositionFields fields = geoclue_geocode_freeform_address_to_position (nominatim->geocoder, addr, + GeocluePositionFields fields = geoclue_geocode_freeform_address_to_position (osm->geocoder, addr, &lat, &lon, &alt, &geoclue_acc, &error); if (error) { @@ -348,7 +281,7 @@ get_geocode_freetext(gpointer handle, } if (geoclue_acc) { - acc = get_location_acc_from_geoclue_acc (geoclue_acc); + acc = _get_location_acc_from_geoclue_acc (geoclue_acc); geoclue_accuracy_free (geoclue_acc); *acc_list = g_list_append(*acc_list, acc); } @@ -358,38 +291,26 @@ get_geocode_freetext(gpointer handle, return err; } - -static int -get_geocode_freetext_async (gpointer handle, +int +osm_get_geocode_freetext_async (OsmHandle *osm, 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); + OsmHandleData *data = g_new0 (OsmHandleData, 1); data->pos_cb = callback; data->userdata = userdata; - geoclue_geocode_freeform_address_to_position_async (nominatim->geocoder, addr, position_cb, data); + geoclue_geocode_freeform_address_to_position_async (osm->geocoder, addr, position_cb, data); return LOCATION_ERROR_NONE; } -static int -get_reverse_geocode(gpointer handle, +int +osm_get_reverse_geocode(OsmHandle *osm, 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; @@ -398,7 +319,7 @@ get_reverse_geocode(gpointer handle, 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, + gboolean success = geoclue_reverse_geocode_position_to_address (osm->rev_geocoder, lat, lon, pos_acc, &geoclue_addr, &addr_acc, &error); geoclue_accuracy_free (pos_acc); @@ -410,35 +331,30 @@ get_reverse_geocode(gpointer handle, } if (addr_acc) { - *acc = get_location_acc_from_geoclue_acc (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); + *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, +int +osm_get_reverse_geocode_async (OsmHandle *osm, 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); + OsmHandleData *data = g_new0 (OsmHandleData, 1); data->addr_cb = callback; data->userdata = userdata; - geoclue_reverse_geocode_position_to_address_async (nominatim->rev_geocoder, + geoclue_reverse_geocode_position_to_address_async (osm->rev_geocoder, lat, lon, pos_acc, address_cb, data); geoclue_accuracy_free (pos_acc); @@ -446,139 +362,6 @@ get_reverse_geocode_async (gpointer handle, return LOCATION_ERROR_NONE; } -static int -search_poi (gpointer handle, - const LocationPOIFilter *filter, - const LocationPosition *position, - const LocationPreference *svc_pref, - const LocationPOIPreference *pref, - LocationPOICB cb, const gpointer user_data, guint * req_id) -{ - return LOCATION_ERROR_NOT_SUPPORTED; -} -static int -search_poi_by_area (gpointer handle, - const LocationPOIFilter *filter, - const LocationBoundary *boundary, - const LocationPreference *svc_pref, - const LocationPOIPreference *pref, - LocationPOICB cb, const gpointer user_data, guint * req_id) -{ - return LOCATION_ERROR_NOT_SUPPORTED; -} - -static int -search_poi_by_address (gpointer handle, - const LocationPOIFilter *filter, - const LocationAddress *address, - const LocationPreference *svc_pref, - const LocationPOIPreference *pref, - LocationPOICB cb, const gpointer user_data, guint * req_id) -{ - return LOCATION_ERROR_NOT_SUPPORTED; -} - -static int -search_poi_by_freeform (gpointer handle, - const LocationPOIFilter * filter, - const gchar *freeform, - const LocationPreference *svc_pref, - const LocationPOIPreference *pref, - LocationPOICB cb, const gpointer user_data, guint *req_id) -{ - return LOCATION_ERROR_NOT_SUPPORTED; -} - -static int -cancel_poi_request (gpointer handle, guint req_id) -{ - return LOCATION_ERROR_NOT_SUPPORTED; -} - -static int -request_route (gpointer handle, - const LocationPosition *origin, - const LocationPosition *destination, - GList *waypoint, - const LocationPreference *svc_pref, - const LocationRoutePreference *pref, - LocationRouteCB cb, const gpointer user_data, guint * req_id) -{ - return LOCATION_ERROR_NOT_SUPPORTED; -} -static int -cancel_route_request (gpointer handle, guint req_id) -{ - return LOCATION_ERROR_NOT_SUPPORTED; -} -static gboolean -is_supported_map_provider_capability (gpointer handle, - LocationMapServiceType type) -{ - return FALSE; -} - -static int -get_map_provider_capability_key (gpointer handle, - LocationMapServiceType type, GList **key) -{ - g_return_val_if_fail (key, LOCATION_ERROR_PARAMETER); - *key = NULL; - return LOCATION_ERROR_NOT_SUPPORTED; -} - -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 (LocModServiceOps* 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; - ops->search_poi = search_poi; - ops->search_poi_by_area = search_poi_by_area; - ops->search_poi_by_address = search_poi_by_address; - ops->search_poi_by_freeform = search_poi_by_freeform; - ops->cancel_poi_request = cancel_poi_request; - ops->request_route = request_route; - ops->cancel_route_request = cancel_route_request; - ops->is_supported_map_provider_capability = is_supported_map_provider_capability; - ops->get_map_provider_capability_key = get_map_provider_capability_key; - - 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/osm/location-osm-geocode.h b/modules/osm/location-osm-geocode.h new file mode 100644 index 0000000..8d384bf --- /dev/null +++ b/modules/osm/location-osm-geocode.h @@ -0,0 +1,42 @@ +/* + * 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_OSM_GEOCODE_H__ +#define __LOCATION_OSM_GEOCODE_H__ + + + +#include "location-osm.h" + +int osm_get_geocode (OsmHandle *osm, const LocationAddress *addr, GList **pos_list, GList **acc_list); + +int osm_get_geocode_async (OsmHandle *osm, const LocationAddress * addr, LocationPositionCB callback, gpointer userdata); + +int osm_get_geocode_freetext(OsmHandle *osm, const const gchar* addr, GList **pos_list, GList **acc_list); + +int osm_get_geocode_freetext_async (OsmHandle *osm, const gchar* addr, LocationPositionCB callback, gpointer userdata); + +int osm_get_reverse_geocode(OsmHandle *osm, const LocationPosition *pos, LocationAddress **addr, LocationAccuracy **acc); + +int osm_get_reverse_geocode_async (OsmHandle *osm, const LocationPosition *pos, LocationAddressCB callback, gpointer userdata); + + +#endif /* __LOCATION_OSM_GEOCODE_H__ */ diff --git a/modules/osm/location-osm-poi.c b/modules/osm/location-osm-poi.c new file mode 100644 index 0000000..a3cf4a3 --- /dev/null +++ b/modules/osm/location-osm-poi.c @@ -0,0 +1,251 @@ +/* + * 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. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include "log.h" +#include "location-osm.h" +#include "location-osm-poi.h" + +static int g_req_id = 0; + +static void +_get_lang (gchar country_code[3], gchar lang_code[3]) +{ + if (!country_code || !lang_code) return; + gchar* langset = vconf_get_str(VCONFKEY_LANGSET); + MOD_LOGW("getenv: %s", langset); + + if(langset == NULL){ + lang_code[0] = 'E'; + lang_code[1] = 'N'; + lang_code[2] = '\0'; + country_code[0] = 'U'; + country_code[1] = 'S'; + country_code[2] = '\0'; + }else{ + gchar* langset_upper = g_ascii_strup(langset, -1); + lang_code[0] = langset_upper[0]; + lang_code[1] = langset_upper[1]; + lang_code[2] = '\0'; + country_code[0] = langset_upper[3]; + country_code[1] = langset_upper[4]; + country_code[2] = '\0'; + g_free(langset_upper); + } + MOD_LOGW("Language: %s, Country: %s", lang_code, country_code); +} + +static void +_free_landmark(gpointer data) +{ + g_return_if_fail (data); + + LocationLandmark *landmark = (LocationLandmark *)data; + location_landmark_free(landmark); +} + + +static void +_poi_callback(GeocluePoi *poi, int count, GPtrArray *landmark, GError *error, gpointer userdata) +{ + OsmHandleData *data = (OsmHandleData *)userdata; + + g_return_if_fail(data); + g_return_if_fail(data->poi_cb); + + int req_id = data->req_id; + int err = LOCATION_ERROR_NONE; + GValueArray *vals = NULL; + GList *landmark_list = NULL; + LocationLandmark *land = NULL; + GeoclueLandmark landmark_data = {0, }; + LocationBoundary *bounding_box = NULL; + LocationPosition *left_top = NULL; + LocationPosition *right_bottom = NULL; + + int idx = 0; + if (!landmark || error) { + MOD_LOGE("Landmark[%p] is NULL or Error occurs", landmark); + err = LOCATION_ERROR_UNKNOWN; + } + else { + MOD_LOGE("Count [%d]", count); + for (; idx < count; idx++) { + vals = (GValueArray *) g_ptr_array_index(landmark, idx); + if (!vals) { + break; + } + + landmark_data.id = g_value_get_int (g_value_array_get_nth(vals, 0)); + landmark_data.rank = g_value_get_int (g_value_array_get_nth(vals, 1)); + landmark_data.lat = g_value_get_double (g_value_array_get_nth(vals, 2)); + landmark_data.lon = g_value_get_double (g_value_array_get_nth(vals, 3)); + landmark_data.boundary_left = g_value_get_double (g_value_array_get_nth(vals, 4)); + landmark_data.boundary_top = g_value_get_double (g_value_array_get_nth(vals, 5)); + landmark_data.boundary_right = g_value_get_double (g_value_array_get_nth(vals, 6)); + landmark_data.boundary_bottom = g_value_get_double (g_value_array_get_nth(vals, 7)); + landmark_data.name = g_value_dup_string (g_value_array_get_nth(vals, 8)); + landmark_data.icon = g_value_dup_string (g_value_array_get_nth(vals, 9)); + landmark_data.house = g_value_dup_string (g_value_array_get_nth(vals, 10)); + landmark_data.road = g_value_dup_string (g_value_array_get_nth(vals, 11)); + landmark_data.village = g_value_dup_string (g_value_array_get_nth(vals, 12)); + landmark_data.suburb = g_value_dup_string (g_value_array_get_nth(vals, 13)); + landmark_data.postcode = g_value_dup_string (g_value_array_get_nth(vals, 14)); + landmark_data.city = g_value_dup_string (g_value_array_get_nth(vals, 15)); + landmark_data.county = g_value_dup_string (g_value_array_get_nth(vals, 16)); + landmark_data.country = g_value_dup_string (g_value_array_get_nth(vals, 17)); + landmark_data.country_code = g_value_dup_string (g_value_array_get_nth(vals, 18)); + + land = location_landmark_new(); + + location_landmark_set_id (land, (guint)landmark_data.id); + location_landmark_set_priority(land, (guint)landmark_data.rank); + location_landmark_set_position (land, location_position_new (0, landmark_data.lat, landmark_data.lon, 0.0, LOCATION_STATUS_2D_FIX)); + + location_landmark_set_name (land, landmark_data.name); + location_landmark_set_address (land, location_address_new (NULL, landmark_data.house, landmark_data.village, landmark_data.city, landmark_data.county, landmark_data.country_code, landmark_data.postcode)); + location_landmark_set_property (land, "ICON", landmark_data.icon); + + if (!landmark_data.boundary_left || landmark_data.boundary_top || landmark_data.boundary_right || landmark_data.boundary_bottom) { + left_top = location_position_new (0, landmark_data.boundary_left, landmark_data.boundary_top, 0.0, LOCATION_STATUS_2D_FIX); + right_bottom = location_position_new (0, landmark_data.boundary_right, landmark_data.boundary_bottom, 0.0, LOCATION_STATUS_2D_FIX); + bounding_box = location_boundary_new_for_rect (left_top, right_bottom); + if (bounding_box) { + location_landmark_set_bounding_box (land, bounding_box); + location_boundary_free(bounding_box); + } + + if (left_top) location_position_free (left_top); + if (right_bottom) location_position_free (right_bottom); + + left_top = NULL; + right_bottom = NULL; + bounding_box = NULL; + } + + + landmark_list = g_list_append (landmark_list, land); + } + } + + MOD_LOGW ("Calling LocationPOICB"); + data->poi_cb (err, req_id, landmark_list, NULL, NULL, data->userdata); + + g_list_free_full (landmark_list, _free_landmark); +} + +int +osm_search_poi_by_position(OsmHandle *osm, + const LocationPOIFilter *filter, + const LocationPosition *position, + const LocationMapPref *svc_pref, + const LocationPOIPreference *pref, + LocationPOICB cb, + const gpointer user_data, + guint *req_id) +{ + int left = 0.0, top = 0.0, right = 0.0, bottom = 0.0; + *req_id = ++g_req_id; + + OsmHandleData *data = g_new0 (OsmHandleData, 1); + data->req_id = *req_id; + data->poi_cb = cb; + data->userdata = user_data; + + gchar *keyword = NULL, *lang = NULL, *country_code = NULL; + int max_result = 0; + + keyword = location_poi_filter_get(filter, "KEYWORD"); + if (!keyword) { + MOD_LOGW("OSM supports only keyword filter."); + return LOCATION_ERROR_PARAMETER; + + } + + lang = location_map_pref_get_language (svc_pref); + country_code = location_map_pref_get_country(svc_pref); + max_result = location_poi_pref_get_max_result(pref); + + geoclue_poi_search_by_position_async (osm->poi, keyword, lang, country_code, max_result, left, top, right, bottom, _poi_callback, data); + + return LOCATION_ERROR_NONE; +} + +int +osm_search_poi_by_area(OsmHandle *osm, + const LocationPOIFilter *filter, + const LocationBoundary *boundary, + const LocationMapPref *svc_pref, + const LocationPOIPreference *pref, + LocationPOICB cb, + const gpointer user_data, + guint *req_id) +{ + *req_id = ++g_req_id; + + OsmHandleData *data = g_new0 (OsmHandleData, 1); + + gchar sys_country[3] = {0, }, sys_lang[3] = {0, }; + gchar *keyword = NULL, *lang = NULL, *country_code = NULL; + int max_result = 0; + gdouble left = 0.0, top = 0.0, right = 0.0, bottom = 0.0; + + data->req_id = *req_id; + data->poi_cb = cb; + data->userdata = user_data; + + _get_lang (sys_country, sys_lang); + keyword = location_poi_filter_get(filter, "KEYWORD"); + if (!keyword) { + MOD_LOGW("OSM supports only keyword filter."); + return LOCATION_ERROR_PARAMETER; + + } + + lang = location_map_pref_get_language (svc_pref); +// if (!lang) lang = sys_lang; + + country_code = location_map_pref_get_country(svc_pref); +// if (!country_code) country_code = sys_country; + + max_result = location_poi_pref_get_max_result(pref); + + LocationPosition *left_top = boundary->rect.left_top; + LocationPosition *right_bottom = boundary->rect.right_bottom; + + left = left_top->latitude; + top = left_top->longitude; + right = right_bottom->latitude; + bottom = right_bottom->longitude; + + geoclue_poi_search_by_position_async (osm->poi, keyword, lang, country_code, max_result, left, top, right, bottom, _poi_callback, data); + + return LOCATION_ERROR_NONE; +} diff --git a/modules/osm/location-osm-poi.h b/modules/osm/location-osm-poi.h new file mode 100644 index 0000000..27dfddc --- /dev/null +++ b/modules/osm/location-osm-poi.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_OSM_POI_H__ +#define __LOCATION_OSM_POI_H__ + +#include +#include + +int osm_search_poi_by_position(OsmHandle *osm, + const LocationPOIFilter *filter, + const LocationPosition *position, + const LocationMapPref *svc_pref, + const LocationPOIPreference *pref, + LocationPOICB cb, + const gpointer user_data, + guint *req_id); + +int osm_search_poi_by_area(OsmHandle *osm, + const LocationPOIFilter *filter, + const LocationBoundary *boundary, + const LocationMapPref *svc_pref, + const LocationPOIPreference *pref, + LocationPOICB cb, + const gpointer user_data, + guint *req_id); + +#endif /* __LOCATION_OSM_ROUTE_H__ */ diff --git a/modules/osm/location-osm-route.c b/modules/osm/location-osm-route.c new file mode 100644 index 0000000..ca93126 --- /dev/null +++ b/modules/osm/location-osm-route.c @@ -0,0 +1,239 @@ +/* + * 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. + */ + +#include +#include +#include + +#include +#include +#include +#include "log.h" +#include "osm-route-yours.h" +#include "location-osm-route.h" +#include "osm-http.h" + +static char * +_create_route_url (const LocationPosition *origin, const LocationPosition *destination, const GList *waypoint, const LocationMapPref *svc_pref, const LocationRoutePreference *pref) +{ + gdouble flon = 0.0, flat = 0.0, tlon = 0.0, tlat = 0.0; + GList *ways = NULL; + char *mode = "motorcar"; + + + flon = origin->longitude; + flat = origin->latitude; + tlon = destination->longitude; + tlat = destination->latitude; + +#if 0 + if (waypoint) +#endif + + return yournavi_create_url (flat, flon, tlat, tlon, ways, 1, mode, 1); + //yournavi_create_url (gdouble flon, gdouble flat, gdouble tlon, gdouble tlat, const GList *ways, int type, char *mode, int instruction); + +} + +static void +_position_foreach_cb (gpointer data, gpointer user_data) +{ + if (!data) return ; + + osm_data_t *ndata = (osm_data_t *)user_data; + + LocationPosition *pos = (LocationPosition*) data; + LocationPosition *duplicated = location_position_copy (pos); + + ndata->waypoint = g_list_append(ndata->waypoint, duplicated); + +} + +#if 0 +static void +_position_destory_cb (gpointer data) +{ + if (!data) return; + + LocationPosition *pos = (LocationPosition *)data; + + location_position_free (pos); +} +#endif + +static void +_get_position_from_coordinates (JsonArray *_array, guint index, JsonNode *element, gpointer user_data) +{ + GList **pos_list = (GList **)user_data; + gdouble lat = 0.0, lon = 0.0; + + JsonArray *array = json_node_get_array(element); + if (array) { + lon = json_array_get_double_element (array, 0); + lat = json_array_get_double_element (array, 1); + *pos_list = g_list_append(*pos_list, location_position_new(0, lat, lon, 0.0, LOCATION_STATUS_2D_FIX)); + } + +} + +int +convert_data_to_location_service (const char *result, int result_len, LocationPosition *origin, LocationPosition *dest, GList **route_list) +{ + gboolean ret = FALSE; + GError *err = NULL; + JsonParser* parser = json_parser_new (); + JsonNode* node = NULL; + JsonObject *obj = NULL; + JsonObject *properties = NULL; + JsonArray *positions = NULL; +// gchar *instructions = NULL; + + GList *pos_list = NULL; + LocationRoute *route = NULL; + gchar *str_distance = NULL, *str_duration = NULL; + gdouble distance = 0.0; + glong duration = 0; + + if (!result) return -1; + + ret = json_parser_load_from_data(parser, result, result_len, &err); + if (ret == FALSE) { + MOD_LOGW("Fail to parser data"); + return -1; + } + + node = json_parser_get_root(parser); + if (!node) { + MOD_LOGW("Fail to parser data"); + return -1; + } + + obj = json_node_get_object(node); + if (!obj) { + MOD_LOGW("Fail to parser data"); + return -1; + } + + positions = json_object_get_array_member(obj, "coordinates"); + if (positions) { + json_array_foreach_element (positions, _get_position_from_coordinates, &pos_list); + MOD_LOGW("foreach"); + } + + properties = json_object_get_object_member(obj, "properties"); + if (properties) { + str_distance = (gchar *)json_object_get_string_member(properties, "distance"); + MOD_LOGW("distance [%s]", str_distance); + // instructions = json_object_get_string_member (properties, "description"); + str_duration = (gchar *)json_object_get_string_member (properties, "traveltime"); + MOD_LOGW("time [%s]", str_duration); + + if (str_distance) { + distance = atof (str_distance); + MOD_LOGW("converted distance [%f]", distance); + g_free(str_distance); + } + + if (str_duration) { + duration = atol (str_duration); + MOD_LOGW("converted duration [%ld]", duration); + g_free( str_duration); + } + } + else { + MOD_LOGW("property NULL"); + } + + LocationRouteStep *step = location_route_step_new (); + + location_route_step_set_start_point (step, location_position_copy (origin)); + location_route_step_set_end_point (step, location_position_copy (dest)); + + + if (pos_list) { + location_route_step_set_geometry (step, pos_list); + } + GList *step_list = NULL; + step_list = g_list_append (step_list, step); + + + // Route == RouteSegment + LocationRouteSegment *segment = location_route_segment_new(); + location_route_segment_set_start_point (segment, location_position_copy (origin)); + location_route_segment_set_end_point (segment, location_position_copy (dest)); + location_route_segment_set_distance (segment, distance); + location_route_segment_set_duration (segment, duration); + location_route_segment_set_route_step (segment, step_list); + + GList *seg_list = NULL; + seg_list = g_list_append (seg_list, segment); + + + route = location_route_new (); + location_route_set_origin(route, origin); + location_route_set_destination(route, dest); + location_route_set_total_distance(route, distance); + location_route_set_distance_unit(route, "M"); + location_route_set_total_duration(route, duration); + location_route_set_route_segment(route, seg_list); + + *route_list = g_list_append(*route_list, route); + + return 0; +} + +int +osm_request_route (const LocationPosition *origin, + const LocationPosition *destination, + GList *waypoint, + const LocationMapPref *svc_pref, + const LocationRoutePreference *pref, + LocationRouteCB cb, + const gpointer user_data, + guint *req_id) +{ + osm_data_t *ndata = g_new0(osm_data_t, 1); + + ndata->route_cb = cb; + ndata->user_data = (gpointer)user_data; + ndata->origin = location_position_copy(origin); + ndata->dest = location_position_copy(destination); + if (waypoint) g_list_foreach(waypoint, _position_foreach_cb, ndata); + + char *url = _create_route_url (origin, destination, waypoint, svc_pref, pref); + if (!url) return LOCATION_ERROR_UNKNOWN; + + int ret = curl_request_route_async(url, ndata, req_id); + if (ret != 0) { + if (ndata) g_free(ndata); + if (url) g_free(url); + return LOCATION_ERROR_UNKNOWN; + } + + if (url) g_free(url); + return LOCATION_ERROR_NONE; +} + +int +osm_cancel_route_request (guint req_id) +{ + return curl_cancel_route_request (req_id); +} diff --git a/modules/osm/location-osm-route.h b/modules/osm/location-osm-route.h new file mode 100644 index 0000000..944af90 --- /dev/null +++ b/modules/osm/location-osm-route.h @@ -0,0 +1,41 @@ +/* + * 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_OSM_ROUTE_H__ +#define __LOCATION_OSM_ROUTE_H__ + +#include +#include + +int osm_request_route (const LocationPosition *origin, + const LocationPosition *destination, + GList *waypoint, + const LocationMapPref *svc_pref, + const LocationRoutePreference *pref, + LocationRouteCB cb, + const gpointer user_data, + guint *req_id); + +int osm_cancel_route_request (guint req_id); + +int convert_data_to_location_service (const char *result, int result_len, LocationPosition *origin, LocationPosition *dest, GList **route); + +#endif /* __LOCATION_OSM_ROUTE_H__ */ diff --git a/modules/osm/location-osm.c b/modules/osm/location-osm.c new file mode 100644 index 0000000..19dac0d --- /dev/null +++ b/modules/osm/location-osm.c @@ -0,0 +1,325 @@ +/* + * 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. + */ + +#include + +#include +#include +#include "location-osm-geocode.h" +#include "location-osm-route.h" +#include "location-osm-poi.h" + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "log.h" + +static void +_unref_geoclue(OsmHandle* 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; + } + if (handle->poi) { + g_object_unref (handle->poi); + handle->poi = NULL; + } +} + +static gboolean +_ref_geoclue(OsmHandle* 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->poi) handle->poi = geoclue_poi_new (service, path); + + if(!handle->geocoder || !handle->rev_geocoder || !handle->poi){ + MOD_LOGW ("Error while creating Geoclue object."); + _unref_geoclue(handle); + return FALSE; + } + return TRUE; +} + +static int +get_geocode (gpointer handle, + const LocationAddress *addr, + const LocationMapPref *svc_pref, + GList **pos_list, + GList **acc_list) +{ + OsmHandle *osm = (OsmHandle *)handle; + g_return_val_if_fail(osm, 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); + + return osm_get_geocode(osm, addr, pos_list, acc_list); +} + + +static int +get_geocode_async (gpointer handle, + const LocationAddress *addr, + const LocationMapPref *svc_pref, + LocationPositionCB callback, + gpointer userdata) +{ + OsmHandle *osm = (OsmHandle *)handle; + g_return_val_if_fail(osm, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(addr, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(callback, LOCATION_ERROR_PARAMETER); + + return osm_get_geocode_async(osm, addr, callback, userdata); +} + +static int +get_geocode_freetext(gpointer handle, + const gchar *addr, + const LocationMapPref *svc_pref, + GList **pos_list, + GList **acc_list) +{ + OsmHandle *osm = (OsmHandle *)handle; + g_return_val_if_fail(osm, 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); + + return osm_get_geocode_freetext(osm, addr, pos_list, acc_list); +} + + +static int +get_geocode_freetext_async (gpointer handle, + const gchar* addr, + const LocationMapPref *svc_pref, + LocationPositionCB callback, + gpointer userdata) +{ + OsmHandle *osm = (OsmHandle *)handle; + g_return_val_if_fail(osm, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(addr, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(callback, LOCATION_ERROR_PARAMETER); + + return osm_get_geocode_freetext_async(osm, addr, callback, userdata); +} + +static int +get_reverse_geocode(gpointer handle, + const LocationPosition *pos, + const LocationMapPref *svc_pref, + LocationAddress **addr, + LocationAccuracy **acc) +{ + OsmHandle *osm = (OsmHandle *)handle; + g_return_val_if_fail(osm, 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); + + return osm_get_reverse_geocode(osm, pos, addr, acc); +} + +static int +get_reverse_geocode_async (gpointer handle, + const LocationPosition *pos, + const LocationMapPref *svc_pref, + LocationAddressCB callback, + gpointer userdata) +{ + OsmHandle *osm = (OsmHandle *)handle; + g_return_val_if_fail(osm, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(pos, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(callback, LOCATION_ERROR_PARAMETER); + + return osm_get_reverse_geocode_async(osm, pos, callback, userdata); +} + +static int +search_poi (gpointer handle, + const LocationPOIFilter *filter, + const LocationPosition *position, + const LocationMapPref *svc_pref, + const LocationPOIPreference *pref, + LocationPOICB cb, const gpointer user_data, guint * req_id) +{ + OsmHandle *osm = (OsmHandle *)handle; + g_return_val_if_fail(osm, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(filter, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(pref, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(cb, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(req_id, LOCATION_ERROR_PARAMETER); + + + return osm_search_poi_by_position(osm, filter, position, svc_pref, pref, cb, user_data, req_id); +} + +static int +search_poi_by_area (gpointer handle, + const LocationPOIFilter *filter, + const LocationBoundary *boundary, + const LocationMapPref *svc_pref, + const LocationPOIPreference *pref, + LocationPOICB cb, const gpointer user_data, guint * req_id) +{ + OsmHandle *osm = (OsmHandle *)handle; + g_return_val_if_fail(osm, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(filter, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(boundary, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(pref, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(cb, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(req_id, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(boundary->type == LOCATION_BOUNDARY_RECT, LOCATION_ERROR_NOT_SUPPORTED); + + return osm_search_poi_by_area(osm, filter, boundary, svc_pref, pref, cb, user_data, req_id);; +} + +static int +search_poi_by_address (gpointer handle, + const LocationPOIFilter *filter, + const LocationAddress *address, + const LocationMapPref *svc_pref, + const LocationPOIPreference *pref, + LocationPOICB cb, const gpointer user_data, guint * req_id) +{ + return LOCATION_ERROR_NOT_SUPPORTED; +} + +static int +search_poi_by_freeform (gpointer handle, + const LocationPOIFilter * filter, + const gchar *freeform, + const LocationMapPref *svc_pref, + const LocationPOIPreference *pref, + LocationPOICB cb, const gpointer user_data, guint *req_id) +{ + return LOCATION_ERROR_NOT_SUPPORTED; +} + +static int +cancel_poi_request (gpointer handle, guint req_id) +{ + return LOCATION_ERROR_NOT_SUPPORTED; +} + +static int +request_route (gpointer handle, + const LocationPosition *origin, + const LocationPosition *destination, + GList *waypoint, + const LocationMapPref *svc_pref, + const LocationRoutePreference *pref, + LocationRouteCB cb, const gpointer user_data, guint * req_id) +{ + OsmHandle *osm = (OsmHandle *)handle; + g_return_val_if_fail(osm, LOCATION_ERROR_NOT_AVAILABLE); + + return osm_request_route(origin, destination, waypoint, svc_pref, pref, cb, user_data, req_id); +} + +static int +cancel_route_request (gpointer handle, guint req_id) +{ + OsmHandle *osm = (OsmHandle *) handle; + g_return_val_if_fail (osm, LOCATION_ERROR_NOT_AVAILABLE); + + return osm_cancel_route_request (req_id); +} + +static gboolean +is_supported_provider_capability (gpointer handle, + LocationMapServiceType type) +{ + return FALSE; +} + +static int +get_provider_capability_key (gpointer handle, + LocationMapServiceType type, GList **key) +{ + g_return_val_if_fail (key, LOCATION_ERROR_PARAMETER); + *key = NULL; + return LOCATION_ERROR_NOT_SUPPORTED; +} + +static int +get_service_name (gpointer handle, + gchar **service_name) +{ + OsmHandle *osm = (OsmHandle *)handle; + g_return_val_if_fail(osm, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (service_name, LOCATION_ERROR_PARAMETER); + *service_name = g_strdup (osm->service_name); + return LOCATION_ERROR_NONE; +} + +LOCATION_MODULE_API gpointer +init (LocModServiceOps* ops) +{ + MOD_LOGD("init"); + g_return_val_if_fail(ops, NULL); + OsmHandle *handle = g_new0 (OsmHandle, 1); + if (!_ref_geoclue(handle)) { + g_free (handle); + return NULL; + } + handle->service_name = g_strdup ("osm"); + 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; + ops->search_poi = search_poi; + ops->search_poi_by_area = search_poi_by_area; + ops->search_poi_by_address = search_poi_by_address; + ops->search_poi_by_freeform = search_poi_by_freeform; + ops->cancel_poi_request = cancel_poi_request; + ops->request_route = request_route; + ops->cancel_route_request = cancel_route_request; + ops->is_supported_provider_capability = is_supported_provider_capability; + ops->get_provider_capability_key = get_provider_capability_key; + + return (gpointer)handle; +} + +LOCATION_MODULE_API void +shutdown (gpointer handle) +{ + MOD_LOGD("shutdown"); + g_return_if_fail(handle); + OsmHandle *osm = (OsmHandle *)handle; + g_free (osm->service_name); + _unref_geoclue(osm); + g_free (osm); +} diff --git a/modules/osm/location-osm.h b/modules/osm/location-osm.h new file mode 100644 index 0000000..9f66af4 --- /dev/null +++ b/modules/osm/location-osm.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_OSM_H__ +#define __LOCATION_OSM_H__ + +#include +#include +#include +#include +#include + +typedef struct { + char* service_name; + GeoclueGeocode* geocoder; + GeoclueReverseGeocode* rev_geocoder; + GeocluePoi *poi; +} OsmHandle; + +typedef struct { + int req_id; + LocationPositionCB pos_cb; + LocationAddressCB addr_cb; + LocationPOICB poi_cb; + gpointer userdata; +} OsmHandleData; + +#endif /* __LOCATION_OSM_H__ */ diff --git a/modules/osm/osm-http.c b/modules/osm/osm-http.c new file mode 100644 index 0000000..40a8c30 --- /dev/null +++ b/modules/osm/osm-http.c @@ -0,0 +1,381 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include "log.h" +#include "location-osm-route.h" +#include "osm-http.h" + +//http://www.yournavigation.org/api/1.0/gosmore.php?format=geojson&flat=52.215676&flon=5.963946&tlat=52.2573&tlon=6.1799&v=motorcar&fast=1&layer=mapnik + + +#define YOUR_NAVIGATION_SERVER "http://www.yournavigation.org/api/1.0/gosmore.php?" +#define YOUR_NAVIGATION_FORMAT "format=" + +#define KML_FORMAT "kml" +#define GEOJSON_FORMAT "geojson" + +static CURLM *g_multi_handle; +static pthread_t g_http_thread; +static GHashTable *g_req_table; + +pthread_mutex_t curl_mutex = PTHREAD_MUTEX_INITIALIZER; + +typedef int (*curl_async_cb) (int req_id, int error, const char *result, int result_len, void *user_data); + +typedef struct { + guint req_id; + CURL *ctx; + curl_async_cb cb; + void *user_data; + + int result_len; + char *result; +} curl_item_t; + +CURL* +curl_create_session (guint *req_id) +{ + static guint session_id = 0; + + CURL_MUTEX_LOCK(&curl_mutex); + if (!g_multi_handle) + g_multi_handle = curl_multi_init(); + CURL_MUTEX_UNLOCK(&curl_mutex); + + CURL* ctx = curl_easy_init(); + if (!ctx) { + MOD_LOGW("Unable to initialize cURL interface\n"); + return NULL; + } + + *req_id = ++session_id; + + MOD_LOGW ("req_id [%d]", *req_id); + + return ctx; +} + +int +curl_destroy_session (CURL* ctx) +{ + if (!ctx) return -1; + + curl_easy_cleanup(ctx); + + return 0; +} + +static gboolean +_compare_ctx (gpointer key, gpointer value, gpointer userdata) +{ + if (!key || !value || !userdata) return FALSE; + + curl_item_t * item = (curl_item_t*) value; + CURL *ctx = (CURL*) userdata; + + if (item->ctx == ctx) { + return TRUE; + } + + return FALSE; +} + +static int +_send_resp (curl_item_t *item) +{ + MOD_LOGW ("Send response [%p]", item); + if (!item) return -1; + MOD_LOGW("Result [%s]", item->result); + + if (item->cb) + item->cb (item->req_id, 0, item->result, item->result_len, item->user_data); + + if (item->user_data) { + g_free(item->user_data); + item->user_data = NULL; + } + + if (item->result) { + g_free(item->result); + item->result = NULL; + } + + return 0; +} + +static void * +_create_http_thread(void *data) +{ + MOD_LOGW ("Create Thread"); + CURLMsg *msg = NULL; + int msgs_left = 0; + int still_running = 1; + int rc = 0; + int ret = 0; + struct timeval timeout; + + timeout.tv_sec = 10; + timeout.tv_usec = 0; + + while(still_running) { + fd_set fdread; + fd_set fdwrite; + fd_set fdexecp; + int maxfd = -1; + + FD_ZERO(&fdread); + FD_ZERO(&fdwrite); + FD_ZERO(&fdexecp); + + if (g_req_table) + curl_multi_fdset (g_multi_handle, &fdread, &fdwrite, &fdexecp, &maxfd); + else { + MOD_LOGW ("Hash table is NULL"); + break; + } + + rc = select(maxfd+1, &fdread, &fdwrite, &fdexecp, &timeout); + MOD_LOGW ("run loop [%d]", still_running); + switch (rc) { + case -1: + break; + case 0: + default: + /* Timeout or readable / writable sockets */ + curl_multi_perform(g_multi_handle, &still_running); + if (ret != CURLM_OK) { + MOD_LOGW ("curl_multi_perform error [%d]", ret); + break; + } + + msg = curl_multi_info_read(g_multi_handle, &msgs_left); + if (msg && msg->msg == CURLMSG_DONE) { + curl_item_t *item = g_hash_table_find (g_req_table, _compare_ctx, msg->easy_handle); + if (item) { + MOD_LOGW ("Found Item ID[%d]", item->req_id); + int ret = _send_resp(item); + if (ret) { + MOD_LOGW ("Fail to send response [%d]", ret); + g_http_thread = 0; + return NULL; + } + + g_hash_table_remove (g_req_table, (gpointer) &item->req_id); + + curl_destroy_session(item->ctx); + if (item) { + g_free(item); + item = NULL; + } + + } + } + else { + sleep(1); + } + break; + } + } + + CURL_MUTEX_LOCK (&curl_mutex); + if (g_multi_handle) { + curl_multi_cleanup(g_multi_handle); + g_multi_handle = NULL; + } + CURL_MUTEX_UNLOCK (&curl_mutex); + + MOD_LOGW("End Thread"); + g_http_thread = 0; + + return NULL; +} + +static size_t +_osm_route_cb (char *ptr, size_t size, size_t nmemb, void *userdata) +{ + curl_item_t *item = (curl_item_t*)userdata; + + MOD_LOGW("size[%d], nmemb [%d]", size, nmemb); + int reallo_len = size * nmemb; + + item->result = realloc (item->result, item->result_len + reallo_len + 1); + if (item->result == NULL) { + /* out of memory! */ + MOD_LOGW("not enough memory (realloc returned NULL)\n"); + return 0; + } + + memcpy(&(item->result[item->result_len]), ptr, reallo_len); + item->result_len += reallo_len; + item->result[item->result_len] = 0; + + return reallo_len; +} + +static int +_route_cb (int req_id, int error, const char *result, int result_len, void *user_data) +{ + GList *route = NULL; + char *error_code = NULL; + char *error_msg = NULL; + + osm_data_t *ndata = (osm_data_t *) user_data; + if (result && result_len > 0) { + // parsing + } + + convert_data_to_location_service (result, result_len, ndata->origin, ndata->dest, &route); + + + ndata->route_cb(error, req_id, route, error_code, error_msg, ndata->user_data); + + return 0; +} + +int +curl_request_route_async(const char *url, osm_data_t *data, guint *req_id) +{ + curl_item_t *item = g_new0(curl_item_t, 1); + if (!item) return -999; + + int stillrunning = 0; + + + CURL *ctx = curl_create_session (req_id); + if (!ctx) { + *req_id = -1; + return -1; + } + + + CURLMcode err = 0; + int ret = 0; + + item->req_id = *req_id; + item->user_data = data; + item->ctx = ctx; + item->cb = _route_cb; + + curl_easy_setopt (ctx, CURLOPT_URL, url); +// curl_easy_setopt (ctx, CURLOPT_NOPROGRESS , 0L); +// curl_easy_setopt( ctx , CURLOPT_WRITEHEADER , stderr); + curl_easy_setopt( ctx, CURLOPT_WRITEFUNCTION, _osm_route_cb); + curl_easy_setopt( ctx , CURLOPT_WRITEDATA, item); + + CURL_MUTEX_LOCK (&curl_mutex); + curl_multi_add_handle(g_multi_handle, ctx); + + if (!g_req_table) { + g_req_table = g_hash_table_new (g_int_hash, g_int_equal); + } + + g_hash_table_insert(g_req_table, req_id, item); + + MOD_LOGW ("ReqID: %u", *req_id); + + err = curl_multi_perform(g_multi_handle, &stillrunning); + CURL_MUTEX_UNLOCK (&curl_mutex); + if (CURLM_OK != err) { + MOD_LOGW ("curl_multi_perform error[%d]", err); + if (item) { + g_free(item); + item = NULL; + } + + curl_destroy_session(ctx); + return -1; + } + + if (!g_http_thread) { //TODO + ret = pthread_create(&g_http_thread, NULL, _create_http_thread, NULL); + + if (ret) { + // return error + MOD_LOGW ("Fail to create thread [%d", ret); + if (item) { + g_free(item); + item = NULL; + } + + curl_destroy_session(ctx); + return -1; + } + MOD_LOGW ("End loop"); + pthread_detach(g_http_thread); + } + else { + MOD_LOGW ("Thread is alive"); + } + + return 0; +} + +int +curl_cancel_route_request (guint req_id) +{ + curl_item_t* item = NULL; + + if (!g_req_table) { + return LOCATION_ERROR_NOT_FOUND; + } + + item = (curl_item_t *)g_hash_table_lookup (g_req_table, (void* )&req_id); + if (!item) { + return LOCATION_ERROR_NOT_FOUND; + } + + + if (g_multi_handle) { + curl_multi_remove_handle (g_multi_handle, item->ctx); + } + + if( item->user_data) { + g_free (item->user_data); + item->user_data = NULL; + } + + if (item->result) { + g_free (item->result); + item->result = NULL; + } + if (item) { + g_free (item); + item = NULL; + } + + gboolean ret = g_hash_table_remove(g_req_table, (void *)&req_id); + if (!ret) { + return LOCATION_ERROR_NOT_FOUND; + } + if (g_hash_table_size(g_req_table) == 0) { + MOD_LOGW ("Hash table is NULL"); + g_hash_table_destroy(g_req_table); + g_req_table = NULL; + } + + return LOCATION_ERROR_NONE; +} diff --git a/modules/osm/osm-http.h b/modules/osm/osm-http.h new file mode 100644 index 0000000..6621497 --- /dev/null +++ b/modules/osm/osm-http.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 __OSM_HTTP_H__ +#define __OSM_HTTP_H__ + +#include + +typedef struct { + gpointer handle; + LocationPosition *origin; + LocationPosition *dest; + GList *waypoint; + LocationRouteCB route_cb; + gpointer user_data; +} osm_data_t; + +#define CURL_MUTEX_LOCK(x) MOD_LOGW ("Try to lock mutex[%p]", x); \ + pthread_mutex_lock (x); + +#define CURL_MUTEX_UNLOCK(x) MOD_LOGW ("Try to unlock mutex[%p]", x); \ + pthread_mutex_unlock (x); + +int curl_request_route_async(const char *url, osm_data_t *data, guint *req_id); + +int curl_cancel_route_request (guint req_id); + +#endif /* __OSM_HTTP_H__ */ diff --git a/modules/osm/osm-route-yours.c b/modules/osm/osm-route-yours.c new file mode 100644 index 0000000..13560f6 --- /dev/null +++ b/modules/osm/osm-route-yours.c @@ -0,0 +1,98 @@ +/* + * 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. + */ + +//http://www.yournavigation.org/api/1.0/gosmore.php?format=geojson&flat=52.215676&flon=5.963946&tlat=52.2573&tlon=6.1799&v=motorcar&fast=1&layer=mapnik +//http://www.yournavigation.org/api/1.0/gosmore.php?formats=geojson/&flat=52.215676&flot=5.963946&tlat=52.257300&tlon=6.179900&v=carmotor&fast=1&instructions=1&layer=mapnik +//http://www.yournavigation.org/api/1.0/gosmore.php?format=geojson&flat=52.215676&flon=5.963946&tlat=52.2573&tlon=6.179900&v=motorcar&fast=1&instructions=1&layer=mapnik + +#include +#include +#include +#include "log.h" + +const char *YOURS_SERVER = "http://www.yournavigation.org/api/1.0/gosmore.php?"; +const char *YOURS_FORMAT = "format="; +const char *YOURS_INSTRUCTIONS = "instructions="; +const char *YOURS_TYPE = "v="; +const char *YOURS_FAST = "fast="; +const char *YOURS_END = "layer=mapnik"; + +const char *YOURS_FORMAT_KML = "kml"; +const char *YOURS_FORMAT_GEOJSON = "geojson"; + +const char *YOURS_SET_ON = "1"; +const char *YOURS_SET_OFF = "0"; + +const char delimeter = '&'; + +static int _add_option (char *buf, const char *key, const char *option) +{ + if (!buf || !option) return -1; + + if (strlen(buf) == 0) { //create + strncpy(buf, YOURS_SERVER, strlen (YOURS_SERVER)); + + if (key) strncat(buf, key, strlen (key)); + strncat(buf, option, strlen (option)); + + } else { + strncat(buf, &delimeter, 1); + if (key) strncat(buf, key, strlen (key)); + strncat(buf, option, strlen (option)); + } + + return 0; +} + +char* yournavi_create_url (gdouble flat, gdouble flon, gdouble tlat, gdouble tlon, GList *way, int type, char *mode ,int instruction) +{ + char url[1024] = {0, }; + char pos_str[64] = {0, }; + + //TODO WAYPOINT : Not supported + + +#if 0 // kml + _add_option(url, YOURS_FORMAT, YOURS_FORMAT_KML); +#else + _add_option(url, YOURS_FORMAT, YOURS_FORMAT_GEOJSON); +#endif + + snprintf(pos_str, 64, "flat=%f&flot=%f&tlat=%f&tlon=%f", flat, flon, tlat, tlon); + _add_option (url, NULL, pos_str); + + _add_option (url, YOURS_TYPE, mode); + + if (type) + _add_option (url, YOURS_FAST, YOURS_SET_ON); + else + _add_option (url, YOURS_FAST, YOURS_SET_OFF); + + if (instruction) + _add_option (url, YOURS_INSTRUCTIONS, YOURS_SET_ON); + + _add_option (url, NULL, YOURS_END); + + MOD_LOGW ("URL[%s]", url); + + return g_strdup(url); +} + diff --git a/modules/osm/osm-route-yours.h b/modules/osm/osm-route-yours.h new file mode 100644 index 0000000..11c4f69 --- /dev/null +++ b/modules/osm/osm-route-yours.h @@ -0,0 +1,27 @@ +/* + * 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 __OSM_ROUTE_YOURS_H__ +#define __OSM_ROUTE_YOURS_H__ + +char* yournavi_create_url (gdouble flat, gdouble flon, gdouble tlat, gdouble tlon, GList *way, int type, char *mode ,int instruction); + +#endif /* __OSM_ROUTE_YOURS_H__ */ diff --git a/packaging/location-module.manifest b/packaging/location-module.manifest deleted file mode 100644 index 017d22d..0000000 --- a/packaging/location-module.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/packaging/location-module.spec b/packaging/location-module.spec old mode 100644 new mode 100755 index e35821d..e694d76 --- a/packaging/location-module.spec +++ b/packaging/location-module.spec @@ -1,16 +1,19 @@ Name: location-module Summary: Location module -Version: 0.1.18 -Release: 4 -Group: Libraries -License: Apache-2.0 +Version: 0.1.20 +Release: 1 +Group: TO_BE/FILLED_IN +License: TO_BE/FILLED_IN Source0: %{name}-%{version}.tar.gz -Source1001: packaging/location-module.manifest BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gmodule-2.0) BuildRequires: pkgconfig(location) BuildRequires: pkgconfig(geoclue) BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(libcurl) +BuildRequires: pkgconfig(json-glib-1.0) + %description @@ -28,7 +31,6 @@ geoclue-nominatim map-service module for location %setup -q %build -cp %{SOURCE1001} . ./autogen.sh %configure --prefix=%{_prefix} --enable-dlog --enable-debug @@ -39,8 +41,6 @@ rm -rf %{buildroot} %make_install %files -n location-geoclue-nominatim -%manifest location-module.manifest %defattr(-,root,root,-) -%{_libdir}/location/module/libmap-service0.so -%{_libdir}/location/module/libmap-service0.so.* +%{_libdir}/location/module/libmap-service-osm* -- 2.7.4