From b2e57232c0c834bb25e051530553b0490963abeb Mon Sep 17 00:00:00 2001 From: Kim Kibum Date: Sun, 29 Apr 2012 17:01:25 +0900 Subject: upload tizen1.0 source --- TC/_export_env.sh | 14 +- TC/_export_target_env.sh | 15 +- TC/build.sh | 17 +- TC/config | 2 + TC/tet_scen | 1 + TC/unit/Makefile | 3 +- TC/unit/tslist | 1 + TC/unit/utc_location_search_poi.c | 400 +++++++ TC/unit/utc_properties_last_position.c | 87 -- configure.ac | 7 +- debian/changelog | 80 +- debian/control | 2 +- debian/libslp-location-dev.install | 3 +- debian/libslp-location.install | 2 +- debian/libslp-location.postinst | 64 +- debian/rules | 4 + location/Makefile.am | 98 +- location/include/location-log.h | 51 + location/include/location-types.h | 243 ++++ location/location-accuracy.c | 105 -- location/location-accuracy.h | 132 --- location/location-address.c | 90 -- location/location-address.h | 97 -- location/location-boundary.c | 354 ------ location/location-boundary.h | 299 ----- location/location-common-util.c | 226 ---- location/location-common-util.h | 45 - location/location-cps.c | 171 --- location/location-cps.h | 61 - location/location-geocode.c | 227 ---- location/location-geocode.h | 61 - location/location-gps.c | 532 --------- location/location-gps.h | 69 -- location/location-hybrid.c | 576 --------- location/location-hybrid.h | 67 -- location/location-ielement.c | 261 ---- location/location-ielement.h | 122 -- location/location-ips.c | 171 --- location/location-ips.h | 61 - location/location-log.h | 54 - location/location-marshal.list | 2 - location/location-module-internal.c | 388 ------ location/location-module-internal.h | 108 -- location/location-module.h | 150 --- location/location-poi-info.c | 193 --- location/location-poi-info.h | 187 --- location/location-poi.c | 234 ---- location/location-poi.h | 61 - location/location-position.c | 200 ---- location/location-position.h | 170 --- location/location-satellite.c | 138 --- location/location-satellite.h | 137 --- location/location-setting.c | 101 -- location/location-setting.h | 96 -- location/location-signaling-util.c | 167 --- location/location-signaling-util.h | 52 - location/location-sps.c | 560 --------- location/location-sps.h | 67 -- location/location-types.h | 153 --- location/location-velocity.c | 92 -- location/location-velocity.h | 106 -- location/location-wps.c | 476 -------- location/location-wps.h | 67 -- location/location.c | 473 -------- location/location.h | 1442 ----------------------- location/manager/Makefile.am | 41 + location/manager/location-accuracy.c | 105 ++ location/manager/location-accuracy.h | 139 +++ location/manager/location-boundary.c | 373 ++++++ location/manager/location-boundary.h | 317 +++++ location/manager/location-common-util.c | 171 +++ location/manager/location-common-util.h | 40 + location/manager/location-cps.c | 171 +++ location/manager/location-cps.h | 58 + location/manager/location-gps.c | 617 ++++++++++ location/manager/location-gps.h | 65 + location/manager/location-hybrid.c | 711 +++++++++++ location/manager/location-hybrid.h | 64 + location/manager/location-ielement.c | 346 ++++++ location/manager/location-ielement.h | 138 +++ location/manager/location-ips.c | 171 +++ location/manager/location-ips.h | 58 + location/manager/location-marshal.list | 2 + location/manager/location-position.c | 203 ++++ location/manager/location-position.h | 177 +++ location/manager/location-satellite.c | 139 +++ location/manager/location-satellite.h | 143 +++ location/manager/location-setting.c | 101 ++ location/manager/location-setting.h | 67 ++ location/manager/location-signaling-util.c | 199 ++++ location/manager/location-signaling-util.h | 52 + location/manager/location-sps.c | 598 ++++++++++ location/manager/location-sps.h | 64 + location/manager/location-velocity.c | 92 ++ location/manager/location-velocity.h | 112 ++ location/manager/location-wps.c | 535 +++++++++ location/manager/location-wps.h | 64 + location/manager/location.c | 230 ++++ location/manager/location.h | 738 ++++++++++++ location/map-service/Makefile.am | 27 + location/map-service/location-address.c | 90 ++ location/map-service/location-address.h | 101 ++ location/map-service/location-geocode.c | 27 + location/map-service/location-geocode.h | 39 + location/map-service/location-landmark-ext.h | 117 ++ location/map-service/location-landmark.c | 528 +++++++++ location/map-service/location-landmark.h | 147 +++ location/map-service/location-map-service-ext.h | 40 + location/map-service/location-map-service.c | 327 +++++ location/map-service/location-map-service.h | 1389 ++++++++++++++++++++++ location/map-service/location-poi.c | 289 +++++ location/map-service/location-poi.h | 282 +++++ location/map-service/location-pref.c | 222 ++++ location/map-service/location-pref.h | 121 ++ location/map-service/location-route-ext.h | 362 ++++++ location/map-service/location-route.c | 1372 +++++++++++++++++++++ location/map-service/location-route.h | 873 ++++++++++++++ location/map-service/map-internal.c | 235 ++++ location/map-service/map-internal.h | 82 ++ location/map-service/map-service.c | 209 ++++ location/map-service/map-service.h | 73 ++ location/module/Makefile.am | 20 + location/module/location-module.h | 171 +++ location/module/module-internal.c | 366 ++++++ location/module/module-internal.h | 96 ++ packaging/libslp-location.spec | 59 +- tests/Makefile.am | 5 +- tests/address-sample.c | 7 +- tests/cps-test.c | 2 +- tests/gps-test.c | 2 +- tests/hybrid-test.c | 2 +- tests/ips-test.c | 2 +- tests/location-api-test-util.c | 372 +++--- tests/location-api-test-util.h | 2 +- tests/location-api-test.c | 518 +++++++- tests/nmea-sample.c | 2 +- tests/position-sample-gps.c | 2 +- tests/property-sample.c | 2 +- tests/satellite-sample.c | 2 +- tests/sps-test.c | 2 +- tests/velocity-sample.c | 2 +- tests/wps-test.c | 2 +- tests/zone-sample.c | 2 +- 143 files changed, 16304 insertions(+), 10084 deletions(-) mode change 100644 => 100755 TC/_export_env.sh create mode 100644 TC/config create mode 100644 TC/unit/utc_location_search_poi.c delete mode 100644 TC/unit/utc_properties_last_position.c mode change 100644 => 100755 configure.ac mode change 100644 => 100755 location/Makefile.am create mode 100644 location/include/location-log.h create mode 100644 location/include/location-types.h delete mode 100644 location/location-accuracy.c delete mode 100644 location/location-accuracy.h delete mode 100644 location/location-address.c delete mode 100644 location/location-address.h delete mode 100644 location/location-boundary.c delete mode 100644 location/location-boundary.h delete mode 100644 location/location-common-util.c delete mode 100644 location/location-common-util.h delete mode 100644 location/location-cps.c delete mode 100644 location/location-cps.h delete mode 100644 location/location-geocode.c delete mode 100644 location/location-geocode.h delete mode 100644 location/location-gps.c delete mode 100644 location/location-gps.h delete mode 100644 location/location-hybrid.c delete mode 100644 location/location-hybrid.h delete mode 100644 location/location-ielement.c delete mode 100644 location/location-ielement.h delete mode 100644 location/location-ips.c delete mode 100644 location/location-ips.h delete mode 100644 location/location-log.h delete mode 100644 location/location-marshal.list delete mode 100644 location/location-module-internal.c delete mode 100644 location/location-module-internal.h delete mode 100644 location/location-module.h delete mode 100644 location/location-poi-info.c delete mode 100644 location/location-poi-info.h delete mode 100644 location/location-poi.c delete mode 100644 location/location-poi.h delete mode 100644 location/location-position.c delete mode 100644 location/location-position.h delete mode 100644 location/location-satellite.c delete mode 100644 location/location-satellite.h delete mode 100644 location/location-setting.c delete mode 100644 location/location-setting.h delete mode 100644 location/location-signaling-util.c delete mode 100644 location/location-signaling-util.h delete mode 100644 location/location-sps.c delete mode 100644 location/location-sps.h delete mode 100644 location/location-types.h delete mode 100644 location/location-velocity.c delete mode 100644 location/location-velocity.h delete mode 100644 location/location-wps.c delete mode 100644 location/location-wps.h delete mode 100644 location/location.c delete mode 100644 location/location.h create mode 100644 location/manager/Makefile.am create mode 100644 location/manager/location-accuracy.c create mode 100644 location/manager/location-accuracy.h create mode 100644 location/manager/location-boundary.c create mode 100644 location/manager/location-boundary.h create mode 100644 location/manager/location-common-util.c create mode 100644 location/manager/location-common-util.h create mode 100644 location/manager/location-cps.c create mode 100644 location/manager/location-cps.h create mode 100644 location/manager/location-gps.c create mode 100644 location/manager/location-gps.h create mode 100644 location/manager/location-hybrid.c create mode 100644 location/manager/location-hybrid.h create mode 100644 location/manager/location-ielement.c create mode 100644 location/manager/location-ielement.h create mode 100644 location/manager/location-ips.c create mode 100644 location/manager/location-ips.h create mode 100644 location/manager/location-marshal.list create mode 100644 location/manager/location-position.c create mode 100644 location/manager/location-position.h create mode 100644 location/manager/location-satellite.c create mode 100644 location/manager/location-satellite.h create mode 100644 location/manager/location-setting.c create mode 100644 location/manager/location-setting.h create mode 100644 location/manager/location-signaling-util.c create mode 100644 location/manager/location-signaling-util.h create mode 100644 location/manager/location-sps.c create mode 100644 location/manager/location-sps.h create mode 100644 location/manager/location-velocity.c create mode 100644 location/manager/location-velocity.h create mode 100644 location/manager/location-wps.c create mode 100644 location/manager/location-wps.h create mode 100644 location/manager/location.c create mode 100644 location/manager/location.h create mode 100644 location/map-service/Makefile.am create mode 100644 location/map-service/location-address.c create mode 100644 location/map-service/location-address.h create mode 100644 location/map-service/location-geocode.c create mode 100644 location/map-service/location-geocode.h create mode 100644 location/map-service/location-landmark-ext.h create mode 100644 location/map-service/location-landmark.c create mode 100644 location/map-service/location-landmark.h create mode 100644 location/map-service/location-map-service-ext.h create mode 100644 location/map-service/location-map-service.c create mode 100644 location/map-service/location-map-service.h create mode 100644 location/map-service/location-poi.c create mode 100644 location/map-service/location-poi.h create mode 100644 location/map-service/location-pref.c create mode 100644 location/map-service/location-pref.h create mode 100644 location/map-service/location-route-ext.h create mode 100644 location/map-service/location-route.c create mode 100644 location/map-service/location-route.h create mode 100644 location/map-service/map-internal.c create mode 100644 location/map-service/map-internal.h create mode 100644 location/map-service/map-service.c create mode 100644 location/map-service/map-service.h create mode 100644 location/module/Makefile.am create mode 100644 location/module/location-module.h create mode 100644 location/module/module-internal.c create mode 100644 location/module/module-internal.h diff --git a/TC/_export_env.sh b/TC/_export_env.sh old mode 100644 new mode 100755 index 7a7b2ae..72a11ec --- a/TC/_export_env.sh +++ b/TC/_export_env.sh @@ -1,14 +1,8 @@ -export ARCH=target +#!/bin/sh -export TET_INSTALL_PATH=~/opensrc/tet3.7 # tetware root path -export TET_TARGET_PATH=$TET_INSTALL_PATH # tetware target path +. ./config +export TET_INSTALL_PATH=$TET_INSTALL_HOST_PATH # tetware root path +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target # tetware target path export PATH=$TET_TARGET_PATH/bin:$PATH export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH - export TET_ROOT=$TET_TARGET_PATH - -set $(pwd) -export TET_SUITE_ROOT=$1 - -set $(date +%s) -FILE_NAME_EXTENSION=$1 diff --git a/TC/_export_target_env.sh b/TC/_export_target_env.sh index 323bb38..5ddaa53 100644 --- a/TC/_export_target_env.sh +++ b/TC/_export_target_env.sh @@ -1,14 +1,7 @@ -export ARCH=target - -export TET_INSTALL_PATH=/opt/home/root/TETware # path to mount -export TET_TARGET_PATH=$TET_INSTALL_PATH +#!/bin/sh +. ./config +export TET_INSTALL_PATH=$TET_INSTALL_TARGET_PATH # path to path +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target export PATH=$TET_TARGET_PATH/bin:$PATH export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH - export TET_ROOT=$TET_TARGET_PATH - -set $(pwd) -export TET_SUITE_ROOT=$1 - -set $(date +%s) -FILE_NAME_EXTENSION=$1 diff --git a/TC/build.sh b/TC/build.sh index b6c54b9..72aad6c 100755 --- a/TC/build.sh +++ b/TC/build.sh @@ -1,17 +1,16 @@ +#!/bin/sh + . ./_export_env.sh # setting environment variables -echo PATH=$PATH -echo LD_LIBRARY_PATH=$LD_LIBRARY_PATH -echo TET_ROOT=$TET_ROOT -echo TET_SUITE_ROOT=$TET_SUITE_ROOT -echo ARCH=$ARCH +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` -RESULT_DIR=results-$ARCH +RESULT_DIR=results HTML_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.html JOURNAL_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.journal mkdir -p $RESULT_DIR -tcc -c -p ./ # executing tcc, with clean option (-c) -tcc -b -j $JOURNAL_RESULT -p ./ # executing tcc to build test cases (-b) -grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT # reporting the result +tcc -c -p ./ +tcc -b -j $JOURNAL_RESULT -p ./ +grw -c 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/config b/TC/config new file mode 100644 index 0000000..ba387c7 --- /dev/null +++ b/TC/config @@ -0,0 +1,2 @@ +TET_INSTALL_HOST_PATH=/home/june/SBS2/work/tetware/TETware +TET_INSTALL_TARGET_PATH=/mnt/nfs/SBS2/work/tetware/TETware diff --git a/TC/tet_scen b/TC/tet_scen index f036f23..bf662fc 100644 --- a/TC/tet_scen +++ b/TC/tet_scen @@ -18,6 +18,7 @@ all /unit/utc_location_get_last_velocity /unit/utc_location_get_satellite /unit/utc_location_get_last_satellite + /unit/utc_location_search_poi /unit/utc_location_init /unit/utc_location_new /unit/utc_location_start diff --git a/TC/unit/Makefile b/TC/unit/Makefile index 2a33f95..62fc0c8 100644 --- a/TC/unit/Makefile +++ b/TC/unit/Makefile @@ -31,6 +31,7 @@ TC24 = utc_location_get_address TC25 = utc_location_get_address_from_position TC26 = utc_location_get_position_from_address TC27 = utc_location_get_position_from_freeformed_address +TC28 = utc_location_search_poi # # add your Package Config Info Here @@ -61,7 +62,7 @@ CFLAGS += $(INCS) # # e.g., # -TCLIST = $(TC1) $(TC2) $(TC3) $(TC4) $(TC5) $(TC6) $(TC7) $(TC8) $(TC9) $(TC10) $(TC11) $(TC12) $(TC13) $(TC14) $(TC16) $(TC17) $(TC18) $(TC19) $(TC20) $(TC21) $(TC22) $(TC23) $(TC24) $(TC25) $(TC26) $(TC27) +TCLIST = $(TC1) $(TC2) $(TC3) $(TC4) $(TC5) $(TC6) $(TC7) $(TC8) $(TC9) $(TC10) $(TC11) $(TC12) $(TC13) $(TC14) $(TC16) $(TC17) $(TC18) $(TC19) $(TC20) $(TC21) $(TC22) $(TC23) $(TC24) $(TC25) $(TC26) $(TC27) $(TC28) all: $(TCLIST) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< diff --git a/TC/unit/tslist b/TC/unit/tslist index e4a997f..6cf5690 100644 --- a/TC/unit/tslist +++ b/TC/unit/tslist @@ -15,6 +15,7 @@ utc_location_get_velocity utc_location_get_last_velocity utc_location_get_satellite utc_location_get_last_satellite +utc_location_search_poi utc_location_init utc_location_new utc_location_start diff --git a/TC/unit/utc_location_search_poi.c b/TC/unit/utc_location_search_poi.c new file mode 100644 index 0000000..ce84a31 --- /dev/null +++ b/TC/unit/utc_location_search_poi.c @@ -0,0 +1,400 @@ +/* + * libslp-location + * + * 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 + +static void startup(), cleanup(); +void (*tet_startup) () = startup; +void (*tet_cleanup) () = cleanup; + +static void utc_location_search_poi_01(); +static void utc_location_search_poi_02(); +static void utc_location_search_poi_03(); +static void utc_location_search_poi_04(); +static void utc_location_search_poi_05(); +static void utc_location_search_poi_06(); +static void utc_location_search_poi_07(); +static void utc_location_search_poi_08(); +static void utc_location_search_poi_09(); +static void utc_location_search_poi_10(); + +struct tet_testlist tet_testlist[] = { + {utc_location_search_poi_01,1}, + {utc_location_search_poi_02,2}, + {utc_location_search_poi_03,3}, + {utc_location_search_poi_04,4}, + {utc_location_search_poi_05,5}, + {utc_location_search_poi_06,6}, + {utc_location_search_poi_07,7}, + {utc_location_search_poi_08,8}, + {utc_location_search_poi_09,9}, + {utc_location_search_poi_10,10}, + {NULL,0}, +}; + +static GMainLoop *loop = NULL; +LocationObject* loc; +int ret; +int isNetStarted = 0; + +static gboolean +exit_loop (gpointer data) +{ + g_main_loop_quit (loop); + return FALSE; +} + +static gboolean +exit_loop_fail (gpointer data) +{ + g_main_loop_quit (loop); + tet_result(TET_FAIL); + return FALSE; +} + +static void startup() +{ + location_init(); + loc = location_new(LOCATION_METHOD_GPS); + + loop = g_main_loop_new(NULL,FALSE); + g_main_loop_run (loop); + + tet_printf("\n TC startup"); +} + +static void cleanup() +{ + location_free(loc); + tet_printf("\n TC End"); +} + +static void __location_POI_cb(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata) +{ + tet_printf("\n===== __location_POI_cb ======\n"); + if (error != LOCATION_ERROR_NONE) { + tet_result(TET_FAIL); + tet_printf("Failed :%d\n", error); + } + + if (landmark_list) tet_result(TET_PASS); + g_main_loop_quit (loop); +} + + +static void +utc_location_search_poi_01() +{ + guint req_id = 0; + int ret = 0; + tet_printf("Keyword-cafe, Max - 10 and sort by Distance"); + LocationPOIFilter *filter = location_poi_filter_new(); + gchar *key = g_strdup("KEYWORD"); + gchar *value = g_strdup("cafe"); + location_poi_filter_set(filter, key, value); + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 10); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_DESC); + + LocationPosition *position = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX); + + ret = location_search_poi(loc, filter, position, pref, __location_POI_cb, NULL, &req_id); + if(ret != LOCATION_ERROR_NONE) { + tet_result(TET_FAIL); + tet_printf("Fail to search POI. Error[%d]\n", ret); + } else { + g_timeout_add_seconds(60, exit_loop_fail, NULL); + tet_printf("Seach POI sucess, req_id %d\n", req_id); + } + location_poi_filter_free(filter); + location_poi_pref_free(pref); + location_position_free(position); +} + +static void +utc_location_search_poi_02() +{ + guint req_id = 0; + int ret = 0; + tet_printf("Category-restaurant, Max - 10 and sort by Distance"); + LocationPOIFilter *filter = location_poi_filter_new(); + gchar *key = g_strdup("CATEGORY"); + gchar *value = g_strdup("restaurant"); + location_poi_filter_set(filter, key, value); + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 10); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_DESC); + + LocationPosition *position = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX); + + ret = location_search_poi(loc, filter, position, pref, __location_POI_cb, NULL, &req_id); + if(ret != LOCATION_ERROR_NONE) { + tet_result(TET_FAIL); + tet_printf("Fail to search POI. Error[%d]\n", ret); + } else { + g_timeout_add_seconds(60, exit_loop_fail, NULL); + tet_printf("Seach POI sucess, req_id %d\n", req_id); + } + location_poi_filter_free(filter); + location_poi_pref_free(pref); + location_position_free(position); +} + +static void +utc_location_search_poi_03() +{ + guint req_id = 0; + int ret = 0; + tet_printf("POIName-cafe, Max - 20 and sort by Distance"); + LocationPOIFilter *filter = location_poi_filter_new(); + gchar *key = g_strdup("POIName"); + gchar *value = g_strdup("cafe"); + location_poi_filter_set(filter, key, value); + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 20); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); + + LocationPosition *position = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX); + + ret = location_search_poi(loc, filter, position, pref, __location_POI_cb, NULL, &req_id); + if(ret != LOCATION_ERROR_NONE) { + tet_result(TET_FAIL); + tet_printf("Fail to search POI. Error[%d]\n", ret); + } else { + g_timeout_add_seconds(60, exit_loop_fail, NULL); + tet_printf("Seach POI sucess, req_id %d\n", req_id); + } + location_poi_filter_free(filter); + location_poi_pref_free(pref); + location_position_free(position); +} + +static void +utc_location_search_poi_04() +{ + guint req_id = 0; + int ret = 0; + tet_printf("POIName-restaurant, Max - 50 and sort by Distance"); + LocationPOIFilter *filter = location_poi_filter_new(); + gchar *key = g_strdup("POIName"); + gchar *value = g_strdup("restaurant"); + location_poi_filter_set(filter, key, value); + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 50); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); + + LocationPosition *position = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX); + + ret = location_search_poi(loc, filter, position, pref, __location_POI_cb, NULL, &req_id); + if(ret != LOCATION_ERROR_NONE) { + tet_result(TET_FAIL); + tet_printf("Fail to search POI. Error[%d]\n", ret); + } else { + g_timeout_add_seconds(60, exit_loop_fail, NULL); + tet_printf("Seach POI sucess, req_id %d\n", req_id); + } + location_poi_filter_free(filter); + location_poi_pref_free(pref); + location_position_free(position); +} + +static void +utc_location_search_poi_05() +{ + guint req_id = 0; + int ret = 0; + tet_printf("POIName-restaurant, Max - 50 and sort by Distance"); + LocationPOIFilter *filter = location_poi_filter_new(); + gchar *key = g_strdup("POIName"); + gchar *value = g_strdup("restaurant"); + location_poi_filter_set(filter, key, value); + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 50); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); + + LocationPosition *position = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX); + + ret = location_search_poi(NULL, filter, position, pref, __location_POI_cb, NULL, &req_id); + if(ret == LOCATION_ERROR_PARAMETER) { + tet_result(TET_PASS); + } else { + tet_result(TET_FAIL); + } + location_poi_filter_free(filter); + location_poi_pref_free(pref); + location_position_free(position); +} + +static void +utc_location_search_poi_06() +{ + guint req_id = 0; + int ret = 0; + tet_printf("POIName-restaurant, Max - 50 and sort by Distance"); + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 50); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); + + LocationPosition *position = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX); + + ret = location_search_poi(loc, NULL, position, pref, __location_POI_cb, NULL, &req_id); + if(ret == LOCATION_ERROR_PARAMETER) { + tet_result(TET_PASS); + } else { + tet_result(TET_FAIL); + } + location_poi_pref_free(pref); + location_position_free(position); +} + +static void +utc_location_search_poi_07() +{ + guint req_id = 0; + int ret = 0; + tet_printf("POIName-restaurant, Max - 50 and sort by Distance"); + LocationPOIFilter *filter = location_poi_filter_new(); + gchar *key = g_strdup("POIName"); + gchar *value = g_strdup("restaurant"); + location_poi_filter_set(filter, key, value); + + LocationPosition *position = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX); + + ret = location_search_poi(loc, filter, position, NULL, __location_POI_cb, NULL, &req_id); + if(ret == LOCATION_ERROR_PARAMETER) { + tet_result(TET_PASS); + } else { + tet_result(TET_FAIL); + } + location_poi_filter_free(filter); + location_position_free(position); +} + +static void +utc_location_search_poi_08() +{ + guint req_id = 0; + int ret = 0; + tet_printf("POIName-restaurant, Max - 50 and sort by Distance"); + LocationPOIFilter *filter = location_poi_filter_new(); + gchar *key = g_strdup("POIName"); + gchar *value = g_strdup("restaurant"); + location_poi_filter_set(filter, key, value); + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 50); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); + + ret = location_search_poi(loc, filter, NULL, pref, __location_POI_cb, NULL, &req_id); + if(ret == LOCATION_ERROR_PARAMETER) { + tet_result(TET_PASS); + } else { + tet_result(TET_FAIL); + } + + location_poi_filter_free(filter); + location_poi_pref_free(pref); +} + +static void +utc_location_search_poi_09() +{ + guint req_id = 0; + int ret = 0; + tet_printf("POIName-restaurant, Max - 50 and sort by Distance"); + LocationPOIFilter *filter = location_poi_filter_new(); + gchar *key = g_strdup("POIName"); + gchar *value = g_strdup("restaurant"); + location_poi_filter_set(filter, key, value); + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 50); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); + + LocationPosition *position = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX); + + ret = location_search_poi(loc, filter, position, pref, NULL, NULL, &req_id); + if(ret == LOCATION_ERROR_PARAMETER) { + tet_result(TET_PASS); + } else { + tet_result(TET_FAIL); + } + + location_poi_filter_free(filter); + location_poi_pref_free(pref); + location_position_free(position); +} + +static void +utc_location_search_poi_10() +{ + int ret = 0; + tet_printf("POIName-restaurant, Max - 50 and sort by Distance"); + LocationPOIFilter *filter = location_poi_filter_new(); + gchar *key = g_strdup("POIName"); + gchar *value = g_strdup("restaurant"); + location_poi_filter_set(filter, key, value); + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 50); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); + + LocationPosition *position = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX); + + ret = location_search_poi(loc, filter, position, pref, __location_POI_cb, NULL, NULL); + if(ret == LOCATION_ERROR_PARAMETER) { + tet_result(TET_PASS); + } else { + tet_result(TET_FAIL); + } + + location_poi_filter_free(filter); + location_poi_pref_free(pref); + location_position_free(position); +} diff --git a/TC/unit/utc_properties_last_position.c b/TC/unit/utc_properties_last_position.c deleted file mode 100644 index 03c08cf..0000000 --- a/TC/unit/utc_properties_last_position.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * libslp-location - * - * 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 - -static void startup(), cleanup(); -void (*tet_startup) () = startup; -void (*tet_cleanup) () = cleanup; - -static void utc_get_lastpostion(); - -struct tet_testlist tet_testlist[] = { - {utc_get_lastpostion,1}, - {NULL,0}, -}; - - -static GMainLoop *loop = NULL; -int ret; -LocationObject* loc; - -static gboolean -exit_loop (gpointer data) -{ - g_main_loop_quit (loop); - tet_result(TET_FAIL); - return FALSE; -} - -static void startup() -{ - location_init(); - loc = location_new(LOCATION_METHOD_GPS); - location_start(loc); - loop = g_main_loop_new(NULL,FALSE); - tet_printf("\n TC startup"); -} - -static void cleanup() -{ - location_stop(loc); - location_free(loc); - tet_printf("\n TC End"); -} - -static void -cb_updated (GObject *self, - guint type, - gpointer data, - gpointer accuracy, - gpointer userdata) -{ - LocationPosition *pos = NULL; - g_object_get(loc, "last-position", &pos, NULL); - if (pos) { - location_position_free (pos); - tet_result(TET_PASS); - } else tet_result(TET_FAIL); - g_main_loop_quit (loop); -} - -static void -utc_get_lastpostion() -{ - g_signal_connect (loc, "service-updated", G_CALLBACK(cb_updated), loc); - g_timeout_add_seconds (60, exit_loop, NULL); - g_main_loop_run (loop); -} diff --git a/configure.ac b/configure.ac old mode 100644 new mode 100755 index f574b41..a646f28 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_INIT(Location, 0.1, [sena06.kim@samsung.com]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADER([config.h]) -AC_CONFIG_SRCDIR([location/location.c]) +AC_CONFIG_SRCDIR([location]) AM_INIT_AUTOMAKE([1.10.2 foreign -Wall -Werror]) # Check programs for making executable @@ -50,7 +50,7 @@ AC_COMPILE_IFELSE( AC_MSG_RESULT($has_visibility) # Check dependencies -PKG_CHECK_MODULES(LOCATION, [glib-2.0 gobject-2.0 gmodule-2.0 vconf]) +PKG_CHECK_MODULES(LOCATION, [glib-2.0 gobject-2.0 dbus-glib-1 gmodule-2.0 vconf]) AC_SUBST(LOCATION_LIBS) AC_SUBST(LOCATION_CFLAGS) @@ -81,6 +81,9 @@ AC_CONFIG_FILES([ location.pc Makefile location/Makefile +location/manager/Makefile +location/map-service/Makefile +location/module/Makefile tests/Makefile ]) diff --git a/debian/changelog b/debian/changelog index f9d2e33..370e857 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,18 +1,92 @@ +libslp-location (0.3.34-13) unstable; urgency=low + + * The result was wrong when location_boundary_if_inside was called + * Git: pkgs/l/libslp-location + * Tag: libslp-location_0.3.34-13 + + -- Minjune Kim Mon, 02 Apr 2012 16:59:08 +0900 + +libslp-location (0.3.34-12) unstable; urgency=low + + * Fix the bug that get_last_position of WPS was failed on emulator. + * Move the fuctionality to location module + * Git: pkgs/l/libslp-location + * Tag: libslp-location_0.3.34-12 + + -- Minjune Kim Tue, 27 Mar 2012 11:09:07 +0900 + +libslp-location (0.3.34-11) unstable; urgency=low + + * Add location_route_step_set_transport_mode / location_route_step_get_transport_mode + * Git: pkgs/l/libslp-location + * Tag: libslp-location_0.3.34-11 + + -- Minjune Kim Mon, 26 Mar 2012 17:00:48 +0900 + +libslp-location (0.3.34-10) unstable; urgency=low + + * Check param's range in funcs. + * Git: pkgs/l/libslp-location + * Tag: libslp-location_0.3.34-10 + + -- Minjune Kim Thu, 22 Mar 2012 13:18:42 +0900 + +libslp-location (0.3.34-9) unstable; urgency=low + + * Fix the bug that location_get_map_service_pref returned fail + * Git: pkgs/l/libslp-location + * Tag: libslp-location_0.3.34-9 + + -- Minjune Kim Tue, 20 Mar 2012 22:15:17 +0900 + +libslp-location (0.3.34-8) unstable; urgency=low + + * modity TC script and copy satellite info with timestamp + * Git: pkgs/l/libslp-location + * Tag: libslp-location_0.3.34-8 + + -- Minjune Kim Mon, 19 Mar 2012 20:49:24 +0900 + +libslp-location (0.3.34-7) unstable; urgency=low + + * add libgconf-dbus-dev in control + * Git: pkgs/l/libslp-location + * Tag: libslp-location_0.3.34-7 + + -- Genie Kim Fri, 16 Mar 2012 11:33:54 +0900 + +libslp-location (0.3.34-6) unstable; urgency=low + + * Support Capability APIs + * Git: pkgs/l/libslp-location + * Tag: libslp-location_0.3.34-6 + + -- Minjune Kim Wed, 14 Mar 2012 20:35:31 +0900 + +libslp-location (0.3.34-5) unstable; urgency=low + + * Add dbus_g_thread_init & g_thread_init to location_init + * Git: pkgs/l/libslp-location + * Tag: libslp-location_0.3.34-5 + + -- Minjune Kim Fri, 09 Mar 2012 16:29:07 +0900 + libslp-location (0.3.34-4) unstable; urgency=low - * Rollback + * Change a wps_start to support an emulator. * Git: pkgs/l/libslp-location * Tag: libslp-location_0.3.34-4 - -- Minjune Kim Thu, 23 Feb 2012 14:30:58 +0900 + -- Minjune Kim Wed, 07 Mar 2012 10:59:54 +0900 libslp-location (0.3.34-3) unstable; urgency=low * Add POI func & Route prototype + * Implement get_last_xxx & Update satellite info * Git: pkgs/l/libslp-location * Tag: libslp-location_0.3.34-3 - -- root Thu, 23 Feb 2012 14:29:51 +0900 + -- Minjune Kim Thu, 23 Feb 2012 14:29:51 +0900 libslp-location (0.3.34-2) unstable; urgency=low diff --git a/debian/control b/debian/control index 89f9108..9527507 100755 --- a/debian/control +++ b/debian/control @@ -3,7 +3,7 @@ Section: libs Priority: extra Maintainer: Youngae Kang , Yunhan Kim , Genie kim , Minjune Kim Uploaders: Genie Kim -Build-Depends: debhelper (>= 5), libglib2.0-dev, dlog-dev, libvconf-dev, libvconf-keys-dev, libjson-glib-dev +Build-Depends: debhelper (>= 5), libglib2.0-dev, libdbus-glib-1-dev, dlog-dev, libvconf-dev, libvconf-keys-dev, libjson-glib-dev, libgconf-dbus-dev Standards-Version: 3.7.2 Homepage: N/A diff --git a/debian/libslp-location-dev.install b/debian/libslp-location-dev.install index a2f6b8c..f31bdab 100644 --- a/debian/libslp-location-dev.install +++ b/debian/libslp-location-dev.install @@ -1,4 +1,3 @@ usr/include/* usr/lib/pkgconfig/* -usr/lib/*.{la,a} -usr/lib/*.so +usr/lib/*.la diff --git a/debian/libslp-location.install b/debian/libslp-location.install index 093956b..d34bd90 100644 --- a/debian/libslp-location.install +++ b/debian/libslp-location.install @@ -1 +1 @@ -usr/lib/*.so.* +usr/lib/*.so* diff --git a/debian/libslp-location.postinst b/debian/libslp-location.postinst index ee6360c..872b534 100755 --- a/debian/libslp-location.postinst +++ b/debian/libslp-location.postinst @@ -3,46 +3,42 @@ #setting if [ "${USER}" = "root" ] then -vconftool set -t int db/location/lastposition/gps/Timestamp "0" -f -vconftool set -t double db/location/lastposition/gps/Latitude "0.0" -f -vconftool set -t double db/location/lastposition/gps/Longitude "0.0" -f -vconftool set -t double db/location/lastposition/gps/Altitude "0.0" -f -vconftool set -t double db/location/lastposition/gps/HorAccuracy "0.0" -f -vconftool set -t double db/location/lastposition/gps/VerAccuracy "0.0" -f -vconftool set -t int db/location/lastposition/wps/Timestamp "0" -f -vconftool set -t double db/location/lastposition/wps/Latitude "0.0" -f -vconftool set -t double db/location/lastposition/wps/Longitude "0.0" -f -vconftool set -t double db/location/lastposition/wps/Altitude "0.0" -f -vconftool set -t double db/location/lastposition/wps/HorAccuracy "0.0" -f -vconftool set -t int db/location/lastposition/sps/Timestamp "0" -f -vconftool set -t double db/location/lastposition/sps/Latitude "0.0" -f -vconftool set -t double db/location/lastposition/sps/Longitude "0.0" -f -vconftool set -t double db/location/lastposition/sps/Altitude "0.0" -f -vconftool set -t double db/location/lastposition/sps/HorAccuracy "0.0" -f -vconftool set -t double db/location/lastposition/sps/VerAccuracy "0.0" -f +vconftool set -t int db/location/last/gps/Timestamp "0" -f +vconftool set -t double db/location/last/gps/Latitude "0.0" -f +vconftool set -t double db/location/last/gps/Longitude "0.0" -f +vconftool set -t double db/location/last/gps/Altitude "0.0" -f +vconftool set -t double db/location/last/gps/HorAccuracy "0.0" -f +vconftool set -t double db/location/last/gps/VerAccuracy "0.0" -f +vconftool set -t double db/location/last/gps/Speed "0.0" -f +vconftool set -t double db/location/last/gps/Direction "0.0" -f +vconftool set -t int db/location/last/wps/Timestamp "0" -f +vconftool set -t double db/location/last/wps/Latitude "0.0" -f +vconftool set -t double db/location/last/wps/Longitude "0.0" -f +vconftool set -t double db/location/last/wps/Altitude "0.0" -f +vconftool set -t double db/location/last/wps/HorAccuracy "0.0" -f +vconftool set -t double db/location/last/wps/Speed "0.0" -f +vconftool set -t double db/location/last/wps/Direction "0.0" -f vconftool set -t int db/location/setting/GpsEnabled "0" -g 6514 -f vconftool set -t int db/location/setting/AgpsEnabled "0" -g 6514 -f vconftool set -t int db/location/setting/NetworkEnabled "0" -g 6514 -f vconftool set -t int db/location/setting/SensorEnabled "0" -g 6514 -f else -vconftool set -t int db/location/lastposition/gps/Timestamp "0" -f -vconftool set -t double db/location/lastposition/gps/Latitude "0.0" -f -vconftool set -t double db/location/lastposition/gps/Longitude "0.0" -f -vconftool set -t double db/location/lastposition/gps/Altitude "0.0" -f -vconftool set -t double db/location/lastposition/gps/HorAccuracy "0.0" -f -vconftool set -t double db/location/lastposition/gps/VerAccuracy "0.0" -f -vconftool set -t int db/location/lastposition/wps/Timestamp "0" -f -vconftool set -t double db/location/lastposition/wps/Latitude "0.0" -f -vconftool set -t double db/location/lastposition/wps/Longitude "0.0" -f -vconftool set -t double db/location/lastposition/wps/Altitude "0.0" -f -vconftool set -t double db/location/lastposition/wps/HorAccuracy "0.0" -f -vconftool set -t int db/location/lastposition/sps/Timestamp "0" -f -vconftool set -t double db/location/lastposition/sps/Latitude "0.0" -f -vconftool set -t double db/location/lastposition/sps/Longitude "0.0" -f -vconftool set -t double db/location/lastposition/sps/Altitude "0.0" -f -vconftool set -t double db/location/lastposition/sps/HorAccuracy "0.0" -f -vconftool set -t double db/location/lastposition/sps/VerAccuracy "0.0" -f +vconftool set -t int db/location/last/gps/Timestamp "0" -f +vconftool set -t double db/location/last/gps/Latitude "0.0" -f +vconftool set -t double db/location/last/gps/Longitude "0.0" -f +vconftool set -t double db/location/last/gps/Altitude "0.0" -f +vconftool set -t double db/location/last/gps/HorAccuracy "0.0" -f +vconftool set -t double db/location/last/gps/VerAccuracy "0.0" -f +vconftool set -t double db/location/last/gps/Speed "0.0" -f +vconftool set -t double db/location/last/gps/Direction "0.0" -f +vconftool set -t int db/location/last/wps/Timestamp "0" -f +vconftool set -t double db/location/last/wps/Latitude "0.0" -f +vconftool set -t double db/location/last/wps/Longitude "0.0" -f +vconftool set -t double db/location/last/wps/Altitude "0.0" -f +vconftool set -t double db/location/last/wps/HorAccuracy "0.0" -f +vconftool set -t double db/location/last/wps/Speed "0.0" -f +vconftool set -t double db/location/last/wps/Direction "0.0" -f vconftool set -t int db/location/setting/GpsEnabled "0" -g -f vconftool set -t int db/location/setting/AgpsEnabled "0" -f vconftool set -t int db/location/setting/NetworkEnabled "0" -f diff --git a/debian/rules b/debian/rules index 4f12d83..c997f77 100755 --- a/debian/rules +++ b/debian/rules @@ -61,6 +61,10 @@ clean: rm -rf install_manifest.txt rm -rf *.so rm -f pkgconfig/lbs-location.pc + rm -rf location/*.o + rm -rf location/*.lo + rm -rf location/*.la + rm -rf tests/.lib for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ rm -f $${f%.in}; \ diff --git a/location/Makefile.am b/location/Makefile.am old mode 100644 new mode 100755 index 799e4c8..a5dd525 --- a/location/Makefile.am +++ b/location/Makefile.am @@ -1,77 +1,49 @@ +SUBDIRS = manager map-service module lib_LTLIBRARIES = libSLP-location.la +COMMON_HEADER_DIR = include +MANAGER_DIR = manager +MAP_SERVICE_DIR = map-service +MODULE_DIR = module + libSLP_location_la_SOURCES = \ - location-marshal.c \ - location-marshal.h \ - location-ielement.c \ - location-ielement.h \ - location-setting.c \ - location-setting.h \ - location-module.h \ - location-module-internal.c\ - location-module-internal.h\ - location.c \ - location.h \ - location-position.c \ - location-position.h \ - location-velocity.c \ - location-velocity.h \ - location-accuracy.c \ - location-accuracy.h \ - location-address.c \ - location-address.h \ - location-boundary.c \ - location-boundary.h \ - location-satellite.c \ - location-satellite.h \ - location-poi-info.c \ - location-poi-info.h \ - location-signaling-util.c \ - location-signaling-util.h \ - location-common-util.c \ - location-common-util.h \ - location-gps.c \ - location-gps.h \ - location-wps.c \ - location-wps.h \ - location-ips.c \ - location-ips.h \ - location-cps.c \ - location-cps.h \ - location-sps.c \ - location-sps.h \ - location-hybrid.c \ - location-hybrid.h \ - location-geocode.c \ - location-geocode.h \ - location-poi.c \ - location-poi.h + ${MANAGER_DIR}/location.c\ + ${MAP_SERVICE_DIR}/location-map-service.c + libSLP_location_la_CFLAGS = \ -fPIC\ + -I${srcdir} \ + -I${srcdir}/include \ + -I${srcdir}/${MANAGER_DIR} \ + -I${srcdir}/${MODULE_DIR} \ + -I${srcdir}/${MAP_SERVICE_DIR} \ $(LOCATION_CFLAGS) libSLP_location_la_LIBADD = \ + ${MANAGER_DIR}/liblocation-manager.la \ + ${MAP_SERVICE_DIR}/liblocation-map-service.la \ + ${MODULE_DIR}/liblocation-module.la \ -lm\ $(LOCATION_LIBS) -EXTRA_DIST = \ - location-marshal.list - -location-marshal.h: location-marshal.list $(GLIB_GENMARSHAL) - $(GLIB_GENMARSHAL) $< --header --prefix=location > $@ -location-marshal.c: location-marshal.list location-marshal.h $(GLIB_GENMARSHAL) - echo "#include \"location-marshal.h\"" > $@ && $(GLIB_GENMARSHAL) location-marshal.list --body --prefix=location >> $@ - libSLP_location_includedir = $(includedir)/location libSLP_location_include_HEADERS = \ - location.h \ - location-types.h \ - location-position.h \ - location-velocity.h \ - location-accuracy.h \ - location-address.h \ - location-boundary.h \ - location-satellite.h \ - location-poi-info.h \ - location-module.h + ${COMMON_HEADER_DIR}/location-types.h \ + ${MANAGER_DIR}/location.h \ + ${MANAGER_DIR}/location-position.h \ + ${MANAGER_DIR}/location-velocity.h \ + ${MANAGER_DIR}/location-accuracy.h \ + ${MANAGER_DIR}/location-boundary.h \ + ${MANAGER_DIR}/location-satellite.h \ + ${MAP_SERVICE_DIR}/location-address.h \ + ${MAP_SERVICE_DIR}/location-map-service.h \ + ${MAP_SERVICE_DIR}/location-map-service-ext.h \ + ${MAP_SERVICE_DIR}/location-poi.h \ + ${MAP_SERVICE_DIR}/location-route.h \ + ${MAP_SERVICE_DIR}/location-route-ext.h \ + ${MAP_SERVICE_DIR}/location-geocode.h \ + ${MAP_SERVICE_DIR}/location-pref.h \ + ${MAP_SERVICE_DIR}/location-landmark.h \ + ${MAP_SERVICE_DIR}/location-landmark-ext.h \ + ${MODULE_DIR}/location-module.h diff --git a/location/include/location-log.h b/location/include/location-log.h new file mode 100644 index 0000000..ebc2448 --- /dev/null +++ b/location/include/location-log.h @@ -0,0 +1,51 @@ +/* + * libslp-location + * + * 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__ + +/** + * @file location-log.h + * @brief This file contains macro functions for logging. + */ + +#define TAG_LOCATION "location" + +#ifdef LOCATION_DLOG_DEBUG // if debug mode, show filename & line number +#include +#define LOCATION_LOGD(fmt,args...) SLOG(LOG_DEBUG, TAG_LOCATION, "[%-15s:%-4d:%-27s]"fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##args) +#define LOCATION_LOGW(fmt,args...) SLOG(LOG_WARN, TAG_LOCATION, "[%-15s:%-4d:%-27s]"fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##args) +#define LOCATION_LOGI(fmt,args...) SLOG(LOG_INFO, TAG_LOCATION, "[%-15s:%-4d:%-27s]"fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##args) +#define LOCATION_LOGE(fmt,args...) SLOG(LOG_ERROR, TAG_LOCATION, "[%-15s:%-4d:%-27s]"fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##args) +#elif LOCATION_DLOG_RELEASE // if release mode, do not show filename & line number +#include +#define LOCATION_LOGD(fmt,args...) SLOG(LOG_DEBUG, TAG_LOCATION, fmt"\n", ##args) +#define LOCATION_LOGW(fmt,args...) SLOG(LOG_WARN, TAG_LOCATION, fmt"\n", ##args) +#define LOCATION_LOGI(fmt,args...) SLOG(LOG_INFO, TAG_LOCATION, fmt"\n", ##args) +#define LOCATION_LOGE(fmt,args...) SLOG(LOG_ERROR, TAG_LOCATION, fmt"\n", ##args) +#else // if do not use dlog +#define LOCATION_LOGD(...) g_debug(__VA_ARGS__); +#define LOCATION_LOGW(...) g_warning(__VA_ARGS__); +#define LOCATION_LOGI(...) g_message(__VA_ARGS__); +#define LOCATION_LOGE(...) g_error(__VA_ARGS__); +#endif + +#endif diff --git a/location/include/location-types.h b/location/include/location-types.h new file mode 100644 index 0000000..c1d150d --- /dev/null +++ b/location/include/location-types.h @@ -0,0 +1,243 @@ +/* + * libslp-location + * + * 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_TYPE_H__ +#define __LOCATION_TYPE_H__ + +#include +#include + +G_BEGIN_DECLS + +#ifndef LOCATION_DEPRECATED_API +#define LOCATION_DEPRECATED_API __attribute__ ((deprecated)) +#endif + +/** + * @file location-types.h + * @brief This file contains the Location related structure, enumeration, and asynchronous function definitions. + * @addtogroup LocationFW + * @{ + * @defgroup LocationTypes Location Types + * @brief This sub module provides structure, enumeration, and asynchronous function definitions. + * @addtogroup LocationTypes + * @{ + */ + +/** + * @brief This represents the returned error code of used functions. + */ +typedef enum { + LOCATION_ERROR_NONE = 0, ///< Success. + LOCATION_ERROR_NOT_ALLOWED, ///< Location servie is not allowed. + LOCATION_ERROR_NOT_AVAILABLE, ///< Location service is not available. + LOCATION_ERROR_NETWORK_FAILED, ///< Network is not available. + LOCATION_ERROR_NETWORK_NOT_CONNECTED, ///< Network is not connected. + LOCATION_ERROR_CONFIGURATION, ///< Configuration setting is not correct. + LOCATION_ERROR_PARAMETER, ///< Input parameter is not correct. + LOCATION_ERROR_NOT_FOUND, ///< Output is not found. + LOCATION_ERROR_NOT_SUPPORTED, ///< Not supported. + LOCATION_ERROR_UNKNOWN, ///< Unknown error. +} LocationError; + +/** + * @brief This represents location method to be used. + */ +typedef enum +{ + LOCATION_METHOD_NONE = -1, ///< Undefined method. + LOCATION_METHOD_HYBRID = 0, ///< This method selects best method. + LOCATION_METHOD_GPS, ///< This method uses Global Positioning System. + LOCATION_METHOD_WPS, ///< This method uses Wifi Positioning System. + LOCATION_METHOD_CPS, ///< This method uses cell ID of base station. + LOCATION_METHOD_IPS, ///< This method uses IP address. + LOCATION_METHOD_SPS ///< This method uses sensor. +} LocationMethod; + +/** + * @brief This represents the update type given by signal callback. + */ +typedef enum { + UPDATE_TYPE_NONE = -1, ///< Undefined update type. + POSITION_UPDATED = 0, ///< This type is used when position information is updated. + VELOCITY_UPDATED, ///< This type is used when velocity information is updated. + SATELLITE_UPDATED, ///< This type is used when satellite information is updated. + ADDRESS_UPDATED, ///< This type is used when address information is updated. This is not implemented yet. + GEOCODE_UPDATED, ///< This type is used when geocode information is updated. This is not implemented yet. + REVERSEGEOCODE_UPDATED ///< This type is used when reverse geocode information is updated. This is not implemented yet. +} LocationUpdateType; + +typedef enum { + MAP_SERVICE_PREF_LANGUAGE, + MAP_SERVICE_PREF_DISTANCE_UNIT, + + MAP_SERVICE_PREF_PROPERTY, + + MAP_SERVICE_GEOCODE_TYPE, + MAP_SERVICE_REVERSE_GEOCODE_TYPE, + + MAP_SERVICE_POI_TYPE, + MAP_SERVICE_POI_SEARCH_BY_ADDRESS, + MAP_SERVICE_POI_SEARCH_BY_FREEFORM_ADDRESS, + MAP_SERVICE_POI_SEARCH_BY_CIRCLE_BOUNDARY, + MAP_SERVICE_POI_SEARCH_BY_RECT_BOUNDARY, + MAP_SERVICE_POI_SEARCH_BY_POLYGON_BOUNDARY, + MAP_SERVICE_POI_PREF_SORT_BY, + MAP_SERVICE_POI_PREF_PROPERTY, + MAP_SERVICE_POI_FILTER, + MAP_SERVICE_POI_FILTER_CATEGORY, + + MAP_SERVICE_ROUTE_REQUEST_FREEFORM_ADDR_TO_AVOID, + MAP_SERVICE_ROUTE_REQUEST_STRUCTED_ADDR_TO_AVOID, + MAP_SERVICE_ROUTE_REQUEST_CIRCLE_AREA_TO_AVOID, + MAP_SERVICE_ROUTE_REQUEST_RECT_AREA_TO_AVOID, + MAP_SERVICE_ROUTE_REQUEST_POLYGON_AREA_TO_AVOID, + MAP_SERVICE_ROUTE_REQUEST_FEATURE_TO_AVOID, + MAP_SERVICE_ROUTE_PREF_TYPE, + MAP_SERVICE_ROUTE_PREF_TRANSPORT_MODE, + MAP_SERVICE_ROUTE_PREF_GEOMETRY_BOUNDING_BOX, + MAP_SERVICE_ROUTE_PREF_GEOMETRY_RETRIEVAL, + MAP_SERVICE_ROUTE_PREF_INSTRUCTION_GEOMETRY, + MAP_SERVICE_ROUTE_PREF_INSTRUCTION_BOUNDING_BOX, + MAP_SERVICE_ROUTE_PREF_INSTRUCTION_RETRIEVAL, + MAP_SERVICE_ROUTE_PREF_REALTIME_TRAFFIC, + MAP_SERVICE_ROUTE_PREF_PROPERTY, + MAP_SERVICE_ROUTE_DISTANCE_UNIT, + MAP_SERVICE_ROUTE_PROPERTY, + MAP_SERVICE_ROUTE_SEGMENT_PROPERTY, + MAP_SERVICE_ROUTE_STEP_PROPERTY, + MAP_SERVICE_TYPE_MAX + +} LocationMapServiceType; + +/** + * @brief Location object redefined by GObject. + */ +typedef GObject LocationObject; + +/** + * @brief This represents position information such as latitude-longitude-altitude values and timestamp. + */ +typedef struct _LocationPosition LocationPosition; + +/** + * @brief This represents last known position information such as latitude-longitude values and accuracy. \n + * This would be deprecated soon. + */ +typedef struct _LocationLastPosition LocationLastPosition; + +/** + * @brief This represents position information such as number of satellites in used or in view. + */ +typedef struct _LocationSatellite LocationSatellite; + +/** + * @brief This represents velocity information such as as speed, direction, climb. + */ +typedef struct _LocationVelocity LocationVelocity; + +/** + * @brief This represents location accuracy information such as accuracy level, horizontal and vertical accuracy. + */ +typedef struct _LocationAccuracy LocationAccuracy; + +/** + * @brief This represents boundary information such as rectangular or circle area. + */ +typedef struct _LocationBoundary LocationBoundary; + +/** + * @brief This represents address information such as building number, street name, etc. + */ +typedef struct _LocationAddress LocationAddress; + +/** + * @brief This represents a structure of Location preference. + */ +typedef struct _LocationPreference LocationPreference; + +/** + * @brief This represents a structure of Location POI filter. + */ +typedef struct _LocationPOIFilter LocationPOIFilter; + +/** + * @brief This represents a structure of Location POI preference. + */ +typedef struct _LocationPOIPreference LocationPOIPreference; + +/** + * @brief This represents a structure of Landmark information. + */ +typedef struct _LocationLandmark LocationLandmark; + +/** + * @brief This represents a structure of Landmark Url. + */ +typedef struct _LocationLandmarkUrl LocationLandmarkUrl; + +/** + * @brief This represents a structure of Location route preference. + */ +typedef struct _LocationRoutePreference LocationRoutePreference; + +/** + * @brief This represents a structure of Location route. + */ +typedef struct _LocationRoute LocationRoute; + +/** + * @brief This represents a structure of Location route segment. + */ +typedef struct _LocationRouteSegment LocationRouteSegment; + +/** + * @brief This represents a structure of Location route step. + */ +typedef struct _LocationRouteStep LocationRouteStep; + +/** + * @brief This represents callback function which will be called to give position information. + */ +typedef void (*LocationPositionCB)(LocationError error, GList *position_list, GList *accuracy_list, gpointer userdata); + +/** + * @brief This represents callback function which will be called to give address information. + */ +typedef void (*LocationAddressCB)(LocationError error, LocationAddress *address, LocationAccuracy *acc, gpointer userdata); + +/** + * @brief This represents callback function which will be called to give POI information. + */ +typedef void (*LocationPOICB)(LocationError error, guint req_id, GList *landmark_list, gchar *error_code, gchar *error_msg, gpointer userdata); + +/** + * @brief This represents callback function which will be called to give Route information. + */ +typedef void (*LocationRouteCB)(LocationError error, guint req_id, GList *route_list, gchar *error_code, gchar *error_msg, gpointer userdata); + +/** + * @}@} + */ + +G_END_DECLS + +#endif /* __LOCATION_TYPE_H__ */ diff --git a/location/location-accuracy.c b/location/location-accuracy.c deleted file mode 100644 index 4681e37..0000000 --- a/location/location-accuracy.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-accuracy.h" -#include "location/location-log.h" - -GType -location_accuracy_get_type (void) -{ - static volatile gsize type_volatile = 0; - if(g_once_init_enter(&type_volatile)) { - GType type = g_boxed_type_register_static ( - g_intern_static_string ("LocationAccuracy"), - (GBoxedCopyFunc) location_accuracy_copy, - (GBoxedFreeFunc) location_accuracy_free); - g_once_init_leave(&type_volatile, type); - } - return type_volatile; -} - -EXPORT_API LocationAccuracy* -location_accuracy_new (LocationAccuracyLevel level, - gdouble horizontal_accuracy, - gdouble vertical_accuracy) -{ - LocationAccuracy* accuracy = g_slice_new0 (LocationAccuracy); - accuracy->level = level; - accuracy->horizontal_accuracy = horizontal_accuracy; - accuracy->vertical_accuracy = vertical_accuracy; - - return accuracy; -} - -EXPORT_API void -location_accuracy_free (LocationAccuracy* accuracy) -{ - g_return_if_fail (accuracy); - g_slice_free (LocationAccuracy, accuracy); -} - -static int -comp_int(int a, int b){ - if (a < b) return -1; - if (a == b) return 0; - return 1; -} - -static int -comp_double_reverse(double a, double b) { - if (a > b) return -1; - else if (a == b) return 0; - return 1; -} - -int -location_accuracy_level_compare(const LocationAccuracy *accuracy1, const LocationAccuracy *accuracy2) -{ - g_return_val_if_fail(accuracy1, -1); - g_return_val_if_fail(accuracy2, 1); - - return comp_int(accuracy1->level, accuracy2->level); -} - -EXPORT_API int -location_accuracy_compare (const LocationAccuracy *accuracy1, const LocationAccuracy *accuracy2) -{ - int ret = 0; - ret = location_accuracy_level_compare(accuracy1, accuracy2); - if(!ret){ - ret = comp_double_reverse(accuracy1->horizontal_accuracy, accuracy2->horizontal_accuracy); - if(!ret) return comp_double_reverse(accuracy1->vertical_accuracy, accuracy2->vertical_accuracy); - } - return ret; -} - -EXPORT_API LocationAccuracy* -location_accuracy_copy (const LocationAccuracy *accuracy) -{ - g_return_val_if_fail(accuracy, NULL); - return location_accuracy_new(accuracy->level, - accuracy->horizontal_accuracy, - accuracy->vertical_accuracy); -} diff --git a/location/location-accuracy.h b/location/location-accuracy.h deleted file mode 100644 index e006798..0000000 --- a/location/location-accuracy.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * libslp-location - * - * 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_ACCURACY_H_ -#define __LOCATION_ACCURACY_H_ - -#include - -G_BEGIN_DECLS - -/** - * @file location-accuracy.h - * @brief This file contains the definitions, structures, and functions related to accuracy information. - * @addtogroup LocationTypes - * @{ - */ - -/** - * @brief This represents the approximate accuracy level of given information. - */ -typedef enum { - LOCATION_ACCURACY_LEVEL_NONE = 0, ///< Invalid data. - LOCATION_ACCURACY_LEVEL_COUNTRY, ///< Country accuracy level-> - LOCATION_ACCURACY_LEVEL_REGION, ///< Regional accuracy level-> - LOCATION_ACCURACY_LEVEL_LOCALITY, ///< Local accuracy level-> - LOCATION_ACCURACY_LEVEL_POSTALCODE, ///< Postal accuracy level-> - LOCATION_ACCURACY_LEVEL_STREET, ///< Street accuracy level-> - LOCATION_ACCURACY_LEVEL_DETAILED, ///< Detailed accuracy level-> -} LocationAccuracyLevel; - -/** - * @brief This represents location accuracy information such as accuracy level, horizontal and vertical accuracy. - */ -struct _LocationAccuracy -{ - LocationAccuracyLevel level; ///< The accuracy level of the location information. - gdouble horizontal_accuracy; ///< The horizontal position uncertainty of the location in meters. - gdouble vertical_accuracy; ///< The vertical position uncertainty of the location in meters. -}; - -GType location_accuracy_get_type(void); -#define LOCATION_TYPE_ACCURACY (location_accuracy_get_type()) - -/** - * @brief Create a new #LocationAccuracy with given information. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] level - The accuracy level of the location information. - * @param [in] horizontal_accuracy - The horizontal position uncertainty of the location in meters. - * @param [in] vertical_accuracy - The vertical position uncertainty of the location in meters. - * @return a new #LocationAccuracy - * @retval NULL if error occured - */ -LocationAccuracy *location_accuracy_new (LocationAccuracyLevel level, gdouble horizontal_accuracy, gdouble vertical_accuracy); - -/** - * @brief Free a #LocationAccuracy. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] accuracy - a #LocationAccuracy. - * @return None. - */ -void location_accuracy_free (LocationAccuracy *accuracy); - -/** - * @brief Compare for two accuracys. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] accuracy1 - a #LocationAccuracy - * @param [in] accuracy2 - another #LocationAccuracy - * @return integer - * @retval\n - * 0 - if the accuracy match\n - * positive value - if accuracy of accuracy1 is better than accuracy of accuracy2\n - * negative value - if accuracy of accuracy1 is worse than accuracy of accuracy2 - */ -int location_accuracy_compare (const LocationAccuracy *accuracy1, const LocationAccuracy *accuracy2); - -/** - * @brief Compare for two accuracys' level. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] accuracy1 - a #LocationAccuracy - * @param [in] accuracy2 - another #LocationAccuracy - * @return integer - * @retval\n - * 0 - if the accuracy match\n - * positive value - if accuracy1's level is better than accuracy2's level\n - * negative value - if accuracy1's level is worse than accuracy2's level - */ -int location_accuracy_level_compare(const LocationAccuracy *accuracy1, const LocationAccuracy *accuracy2); - -/** - * @brief Makes a copy of #LocationAccuracy - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] accuracy - a #LocationAccuracy - * @return a new #LocationAccuracy - * @retval NULL if error occured - */ -LocationAccuracy *location_accuracy_copy (const LocationAccuracy *accuracy); - -/** - * @} - */ - -G_END_DECLS - -#endif diff --git a/location/location-address.c b/location/location-address.c deleted file mode 100644 index 61bf429..0000000 --- a/location/location-address.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-address.h" -#include "location/location-log.h" - -GType -location_address_get_type (void) -{ - static volatile gsize type_volatile = 0; - if(g_once_init_enter(&type_volatile)) { - GType type = g_boxed_type_register_static ( - g_intern_static_string ("LocationAddress"), - (GBoxedCopyFunc) location_address_copy, - (GBoxedFreeFunc) location_address_free); - g_once_init_leave(&type_volatile, type); - } - return type_volatile; -} - -EXPORT_API LocationAddress* -location_address_new (const gchar *building_number, - const gchar *street, - const gchar *district, - const gchar *city, - const gchar *state, - const gchar *country_code, - const gchar *postal_code) -{ - LocationAddress* address = g_slice_new0(LocationAddress); - - address->building_number = g_strdup(building_number); - address->street = g_strdup(street); - address->district = g_strdup(district); - address->city = g_strdup(city); - address->state = g_strdup(state); - address->country_code = g_strdup(country_code); - address->postal_code = g_strdup(postal_code); - - return address; -} - -EXPORT_API void -location_address_free (LocationAddress* address) -{ - g_return_if_fail(address); - g_free(address->building_number); - g_free(address->street); - g_free(address->district); - g_free(address->city); - g_free(address->state); - g_free(address->country_code); - g_free(address->postal_code); - g_slice_free(LocationAddress, address); -} - -EXPORT_API LocationAddress* -location_address_copy (const LocationAddress *address) -{ - g_return_val_if_fail(address, NULL); - return location_address_new(address->building_number, - address->street, - address->district, - address->city, - address->state, - address->country_code, - address->postal_code); -} diff --git a/location/location-address.h b/location/location-address.h deleted file mode 100644 index eb450a5..0000000 --- a/location/location-address.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * libslp-location - * - * 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_ADDRESS_H_ -#define __LOCATION_ADDRESS_H_ - -#include - -G_BEGIN_DECLS - -/** - * @file location-address.h - * @brief This file contains the definitions, structures, and functions related to address information. - * @addtogroup LocationTypes - * @{ - */ - -/** - * @brief This represents address information such as building number, street name, etc. - */ -struct _LocationAddress -{ - gchar *building_number; ///< Building number. - gchar *street; ///< Full street name. - gchar *district; ///< Municipal district name. - gchar *city; ///< City name. - gchar *state; ///< State or province region of a nation. - gchar *country_code; ///< Country name. - gchar *postal_code; ///< Postal delivery code. -}; - -GType location_address_get_type(void); -#define LOCATION_TYPE_ADDRESS (location_address_get_type()) - -/** - * @brief Create a new #LocationAddress with given information. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] building_number - Building number - * @param [in] street - Full street name. - * @param [in] district - Municipal district name. - * @param [in] city - City name. - * @param [in] state - State or province region of a nation. - * @param [in] country_code - Country name. - * @param [in] postal_code - Postal delivery code. - * @return a new #LocationAddress - * @retval NULL if error occured - */ -LocationAddress *location_address_new (const gchar *building_number, const gchar *street, const gchar *district, const gchar *city, const gchar *state, const gchar *country_code, const gchar *postal_code); - -/** - * @brief Free a #LocationAddress. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] address - a #LocationAddress. - * @return None. - */ -void location_address_free (LocationAddress *address); - -/** - * @brief Makes a copy of #LocationAddress - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] address - a #LocationAddress - * @return a new #LocationAddress - * @retval NULL if error occured - */ -LocationAddress *location_address_copy (const LocationAddress *address); - -/** - * @} - */ - -G_END_DECLS - -#endif diff --git a/location/location-boundary.c b/location/location-boundary.c deleted file mode 100644 index 5c06a17..0000000 --- a/location/location-boundary.c +++ /dev/null @@ -1,354 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -/* - * location_boundary_if_inside(LocationBoundary* boundary, - * LocationPosition* position) - * code from - * - * Copyright (c) 1970-2003, Wm. Randolph Franklin - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * 1.Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimers. - * 2.Redistributions in binary form must reproduce the above copyright notice - * in the documentation and/or other materials provided with the distribution. - * 3.The name of W. Randolph Franklin may not be used to endorse or promote - * products derived from this Software without specific prior written permission. - * - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include "location/location-boundary.h" -#include "location/location-log.h" - -GType -location_boundary_get_type (void) -{ - static volatile gsize type_volatile = 0; - if(g_once_init_enter(&type_volatile)) { - GType type = g_boxed_type_register_static ( - g_intern_static_string ("LocationBoundary"), - (GBoxedCopyFunc) location_boundary_copy, - (GBoxedFreeFunc) location_boundary_free); - g_once_init_leave(&type_volatile, type); - } - return type_volatile; -} - -static void _append_polygon_position(gpointer data, gpointer user_data) -{ - g_return_if_fail(data); - g_return_if_fail(user_data); - - LocationBoundary* boundary = (LocationBoundary*)user_data; - LocationPosition* position = (LocationPosition *)data; - LocationPosition* new_position = location_position_copy(position); - - boundary->polygon.position_list = g_list_append(boundary->polygon.position_list, new_position); -} - -static void _free_polygon_position(gpointer data) -{ - g_return_if_fail(data); - - LocationPosition* position = (LocationPosition *)data; - location_position_free(position); -} - - -EXPORT_API LocationBoundary * -location_boundary_new_for_rect (LocationPosition* left_top, - LocationPosition* right_bottom) -{ - g_return_val_if_fail(left_top, NULL); - g_return_val_if_fail(right_bottom, NULL); - - gdouble lon_interval = right_bottom->longitude - left_top->longitude; - - if(lon_interval < 180 && lon_interval > -180) { - if(right_bottom->longitude <= left_top->longitude || right_bottom->latitude >= left_top->latitude) - return NULL; - } - else { - if(right_bottom->longitude >= left_top->longitude || right_bottom->latitude >= left_top->latitude) - return NULL; - } - - LocationBoundary* boundary = g_slice_new0 (LocationBoundary); - boundary->type = LOCATION_BOUNDARY_RECT; - boundary->rect.left_top = location_position_copy(left_top); - boundary->rect.right_bottom = location_position_copy(right_bottom); - return boundary; -} - -EXPORT_API LocationBoundary * -location_boundary_new_for_circle (LocationPosition* center, - gdouble radius) -{ - g_return_val_if_fail(center, NULL); - g_return_val_if_fail(radius > 0, NULL); - LocationBoundary* boundary = g_slice_new0 (LocationBoundary); - boundary->type = LOCATION_BOUNDARY_CIRCLE; - boundary->circle.center = location_position_copy(center); - boundary->circle.radius = radius; - return boundary; -} - -EXPORT_API LocationBoundary * -location_boundary_new_for_polygon(GList *position_list) -{ - g_return_val_if_fail(position_list, NULL); - g_return_val_if_fail(g_list_length(position_list) > 2, NULL); - - LocationBoundary *boundary = g_slice_new0 (LocationBoundary); - - g_list_foreach(position_list, (GFunc)_append_polygon_position, boundary); - boundary->type = LOCATION_BOUNDARY_POLYGON; - boundary->polygon.position_list = g_list_first(boundary->polygon.position_list); - - return boundary; -} - -EXPORT_API void -location_boundary_free (LocationBoundary* boundary) -{ - g_return_if_fail(boundary); - - if (boundary->type == LOCATION_BOUNDARY_RECT) { - location_position_free(boundary->rect.left_top); - location_position_free(boundary->rect.right_bottom); - } else if (boundary->type == LOCATION_BOUNDARY_CIRCLE) { - location_position_free(boundary->circle.center); - } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) { - g_list_free_full(boundary->polygon.position_list, (GDestroyNotify)_free_polygon_position); - } - g_slice_free(LocationBoundary, boundary); -} - -EXPORT_API LocationBoundary* -location_boundary_copy (const LocationBoundary* boundary) -{ - g_return_val_if_fail(boundary, NULL); - if (boundary->type == LOCATION_BOUNDARY_RECT) { - return location_boundary_new_for_rect(boundary->rect.left_top, boundary->rect.right_bottom); - } else if (boundary->type == LOCATION_BOUNDARY_CIRCLE) { - return location_boundary_new_for_circle(boundary->circle.center, boundary->circle.radius); - } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) { - return location_boundary_new_for_polygon(boundary->polygon.position_list); - } - return NULL; -} - - -EXPORT_API gboolean -location_boundary_if_inside (LocationBoundary* boundary, - LocationPosition* position) -{ - g_return_val_if_fail(boundary, FALSE); - g_return_val_if_fail(position, FALSE); - - gboolean is_inside = FALSE; - - switch(boundary->type) { - - case LOCATION_BOUNDARY_RECT: { - gdouble y = position->latitude; - gdouble x = position->longitude; - - gdouble lt_y = boundary->rect.left_top->latitude; - gdouble lt_x = boundary->rect.left_top->longitude; - gdouble rb_y = boundary->rect.right_bottom->latitude; - gdouble rb_x = boundary->rect.right_bottom->longitude; - - if (lt_x - rb_x < 180 && lt_x - rb_x > -180) { - if ((rb_y < y && y < lt_y) && ( lt_x < x && x < rb_x)) { - LOCATION_LOGD("\tInside of Rectangular boundary"); - is_inside = TRUE; - } - } - else { - if ((rb_y < y && y < lt_y) && ( lt_x < x || x < rb_x)) { - LOCATION_LOGD("\tInside of Rectangular boundary near 180th meridian"); - is_inside = TRUE; - } - } - break; - } - case LOCATION_BOUNDARY_CIRCLE: { - - LocationPosition center; - gulong distance = 0; - - center.latitude = boundary->circle.center->latitude; - center.longitude = boundary->circle.center->longitude; - - location_get_distance(¢er, position, &distance); - if (distance < boundary->circle.radius){ - LOCATION_LOGD("\tInside Circle boundary"); - is_inside = TRUE; - } - break; - } - case LOCATION_BOUNDARY_POLYGON: { - - int i, j; - double interval_x = 0.0, interval_y = 0.0; - double x0, y0; - gboolean edge_area; - int crossing_num = 0; - GList *position_list = boundary->polygon.position_list; - int count = g_list_length(position_list); - GList *pos1_list = NULL; - GList *pos2_list = NULL; - LocationPosition* pos1 = NULL; - LocationPosition* pos2 = NULL; - - i = 0; - j = count - 1; - pos1_list = g_list_first(position_list); - pos2_list = g_list_last(position_list); - while(pos1_list = g_list_next(pos1_list)) { - edge_area = FALSE; - pos1 = pos1_list->data; - pos2 = pos2_list->data; - interval_y = pos1->longitude - pos2->longitude; - interval_x = pos1->latitude - pos2->latitude; - /** - * Case 1. -180 < longitude2 - longitude1 < 180 : normal case - * Case 2. longitude2 - longitude1 < -180 : interval_y = longitude2 - longitude1 + 360 - * Case 3. longitude2 - longitude1 > 180 : intreval_y = longitude2 - longitude1 - 360 - */ - if (interval_y > 180) { - interval_y = interval_y - 360; - edge_area = TRUE; - } - else if (interval_y < -180) { - interval_y = interval_y + 360; - edge_area = TRUE; - } - - if (edge_area && (pos1->longitude > position->longitude) == (pos2->longitude > position->longitude)){ - if (pos2->longitude * position->longitude > 0) { - x0 = pos2->latitude; - y0 = pos2->longitude; - } - else { - x0 = pos1->latitude; - y0 = pos1->longitude; - } - - if (position->latitude < ((interval_x/interval_y)*(position->longitude - y0) + x0)) { - - LOCATION_LOGD("Reverse"); - crossing_num++; - } - } - else if (!edge_area && (pos1->longitude > position->longitude) != (pos2->longitude > position->longitude)) { - x0 = pos2->latitude; - y0 = pos2->longitude; - if (position->latitude < ((interval_x/interval_y)*(position->longitude - y0) + x0)) { - LOCATION_LOGD("Common"); - crossing_num++; - } - } - else LOCATION_LOGD("It is not crossed."); - - pos2_list = pos1_list; - } - LOCATION_LOGW("num[%d]", crossing_num); - is_inside = crossing_num & 1; // Odd : inside, Even : outside - - break; - } - default: { - LOCATION_LOGW("\tboundary type is undefined.[%d]", boundary->type); - break; - } - } - - return is_inside; -} - -EXPORT_API int -location_boundary_add(const LocationObject *obj, const LocationBoundary *boundary) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (boundary, LOCATION_ERROR_PARAMETER); - - GList *boundary_list = NULL; - - boundary_list = g_list_append(boundary_list, (gpointer) boundary); - - g_object_set(G_OBJECT(obj), "boundary", boundary_list, NULL); - - - return LOCATION_ERROR_NONE; -} - -EXPORT_API int -location_boundary_remove(const LocationObject *obj, const LocationBoundary *boundary) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (boundary, LOCATION_ERROR_PARAMETER); - - g_object_set(G_OBJECT(obj), "removal-boundary", boundary, NULL); - - return LOCATION_ERROR_NONE; -} - -EXPORT_API int -location_boundary_foreach(const LocationObject *obj, LocationBoundaryFunc func, gpointer user_data) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (func, LOCATION_ERROR_PARAMETER); - - GList * boundary_list = NULL; - - g_object_get(G_OBJECT(obj), "boundary", &boundary_list, NULL); - - if (boundary_list == NULL) { - LOCATION_LOGD("There is no boundary."); - return LOCATION_ERROR_UNKNOWN; - } - g_list_foreach(boundary_list, (GFunc)func, user_data); - - return LOCATION_ERROR_NONE; -} diff --git a/location/location-boundary.h b/location/location-boundary.h deleted file mode 100644 index 9fe0d6e..0000000 --- a/location/location-boundary.h +++ /dev/null @@ -1,299 +0,0 @@ -/* - * libslp-location - * - * 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_BOUNDARY_H_ -#define __LOCATION_BOUNDARY_H_ - -#include -#include - -/** - * @file location-boundary.h - * @brief This file contains the definitions, structures, and functions related to boundary information. - * @addtogroup LocationTypes - * @{ - */ - -G_BEGIN_DECLS - -/** - * @brief - * The type of the @location_boundary_foreach function of #LocationObject - */ -typedef void (*LocationBoundaryFunc) (LocationBoundary *boundary, gpointer user_data); - -/** - * @brief This represents used geographical type, and supports rectangle or circle area. - */ -typedef enum { - LOCATION_BOUNDARY_NONE = 0, ///< Undefined geographical area type. - LOCATION_BOUNDARY_RECT, ///< Rectangular geographical area type. - LOCATION_BOUNDARY_CIRCLE, ///< Circle geographical area type. - LOCATION_BOUNDARY_POLYGON ///< Polygon geographical area type. -} LocationBoundaryType; - -/** - * @brief This represents a rectangular geographical area. - */ -typedef struct { - LocationPosition* left_top; ///< The left top position of rectangle. - LocationPosition* right_bottom; ///< The right bottom position of rectangle. -} LocationRect; - -/** - * @brief This represents a circle geographical area with center geographic position and radius. - */ -typedef struct { - LocationPosition* center; ///< The center position of a circle. - gdouble radius; ///< The radius of a circle. -} LocationCircle; - -/** - * @brief This represents a polygon geographical area. - */ -typedef struct { - GList *position_list; ///< The collection of positions -} LocationPolygon; - -/** - * @brief This represents boundary information such as rectangular or circle area. - */ -struct _LocationBoundary{ - LocationBoundaryType type; ///< The boundary type of this information. - union { - LocationRect rect; ///< The geographical information of a rectangle. - LocationCircle circle; ///< The geographical information of a circle. - LocationPolygon polygon; ///< The geographical information of a polygon. - }; -}; - -GType location_boundary_get_type (void); -#define LOCATION_TYPE_BOUNDARY (location_boundary_get_type ()) - -/** - * @brief Create a rectangular type of new #LocationBoundary with given information. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] left_top - left top position. - * @param [in] right_bottom - right bottom position. - * @return a new #LocationBoundary - * @retval NULL if error occured - */ -LocationBoundary *location_boundary_new_for_rect (LocationPosition *left_top, LocationPosition *right_bottom); - -/** - * @brief Create a circle type of new #LocationBoundary with given information. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] center - center position. - * @param [in] radius - radius. - * @return a new #LocationBoundary - * @retval NULL if error occured - */ -LocationBoundary *location_boundary_new_for_circle (LocationPosition *center, gdouble radius); - -/** - * @brief Create a polygon type of new #LocationBoundary with given information. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] position_list - the list of positions. - * @return a new #LocationBoundary - * @retval NULL if error occured - */ -LocationBoundary *location_boundary_new_for_polygon(GList *position_list); - -/** - * @brief Free a #LocationBoundary. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] boundary - a #LocationBoundary. - * @return None. - */ -void location_boundary_free (LocationBoundary *boundary); - -/** - * @brief Makes a copy of #LocationBoundary - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] boundary - a #LocationBoundary - * @return a new #LocationBoundary - * @retval NULL if error occured - */ -LocationBoundary *location_boundary_copy (const LocationBoundary* boundary); - -/** - * @brief - * Add Boundary on LocationFW. - * You should call this fuction when you want to receive a crossing signal(zone-in/zone-out) from #LocationBoundary. - * @remarks It supports multi-boundaries. \n - However a duplicated boundary would not be allowed. - * @pre - * #location_new should be called before.\n - * @post None. - * @param [in] obj - a #LocationObject - * @param [in] boundary - a #LocationBoundary - * @return int - * @retval 0 Success - * Please refer #LocationError for more information. - * @par Example - * @code -#include - -static void cb_zone_in (GObject *self, guint type, gpointer position, gpointer accuracy) -{ - g_printf ("[zone-in] position - lat: %f, long: %f", position->latitude, position->longitude); -} - -static void cb_zone_out (GObject *self, guint type, gpointer position, gpointer accuracy) -{ - g_printf ("[zone-out] position - lat: %f, long: %f", position->latitude, position->longitude); -} - -void location_test_boundary_add(LocationObject *loc) -{ - LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX); - LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX); - - LoationBoundary *boundary = location_boundary_new_for_rect (lt, rb); - - ret = location_boundary_add(loc, boundary); - - g_signal_connect(loc, "zone-in", G_CALLBACK(cb_zone_in), NULL); - g_siganl_connect(loc, "zone-out", G_CALLBACK(cb_zone_out), NULL); - - location_position_free(rb); - location_position_free(lt); -} - * @endcode - */ -int location_boundary_add(const LocationObject *obj, const LocationBoundary *boundary); - -/** - * @brief - * Remove Boundary on LocationFW. - * You should call this function when you don't want to receive a crossing signal(zone-in/zone-out) from #LocationBoundary any more. - * @remarks It supports multi-boundaries. - * @pre - * #location_init should be called before.\n - * @post None. - * @param [in] obj - a #LocationObject - * @param [in] boundary - a #LocationBoundary - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @par Example - * @code -#include - -void location_test_boundary_remove(LocationObject *loc) -{ - int ret = 0; - LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX); - LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX); - - LoationBoundary *boundary = location_boundary_new_for_rect (lt, rb); - - ret = location_boundary_remove(loc, boundary); - - location_position_free(rb); - location_position_free(lt); - -} - * @endcode - */ -int location_boundary_remove(const LocationObject *obj, const LocationBoundary *boundary); - -/** - * @brief - * Call a function for each element of a Boundary list. - * @remarks None. - * @pre - * #location_init should be called before.\n - * @post None. - * @param [in] obj - a #LocationObject - * @param [in] func - a #LocationBoundaryFunc - * @param [in] user_data - a #void - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @par Example - * @code -#include - -static void remove_boundary(LocationBoundary *boundary, void *user_data) -{ - LocationBoundary *loc = (LocationBoundary *) user_data; - if (loc == NULL || boundary == NULL) return; - - location_boundary_remove(loc, boundary); -} - -void location_test_boundary_foreach(LocationObject *loc) -{ - int ret = location_boundary_foreach(loc, remove_boundary, loc); -} - * @endcode - */ -int location_boundary_foreach(const LocationObject *obj, LocationBoundaryFunc func, gpointer user_data); - - -/** - * @brief Check if #LocationPosition is inside #LocationBoundary. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None.* @param [in] boundary - a #LocationBoundary - * @param [in] position - a #LocationPosition - * @return gboolean - * @retval\n - * TRUE - if inside\n - * FALSE - if outside\n - * @par Example - * @code -#include - -void location_test_boundary_if_inside(LocationObject *loc, LocationBoundary *boundary) -{ - gboolean is_inside = FALSE; - LocationPosition* position = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX); - is_inside = location_boundary_if_inside(boundary, position); - if (is_inside == TRUE) g_printf("The position is inside of the boundary\n"); - else g_printf("The position is outside of the boundary\n"); - -} - * @endcode - - */ -gboolean location_boundary_if_inside (LocationBoundary *boundary, LocationPosition *position); - -/** - * @} - */ - -G_END_DECLS - -#endif diff --git a/location/location-common-util.c b/location/location-common-util.c deleted file mode 100644 index 231dc41..0000000 --- a/location/location-common-util.c +++ /dev/null @@ -1,226 +0,0 @@ -/* - * libslp-location - * - * 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 "location.h" -#include "location-common-util.h" -#include "location-setting.h" -#include "location-log.h" - -static gint compare_position (gconstpointer a, gconstpointer b) -{ - g_return_val_if_fail(a, 1); - g_return_val_if_fail(b, -1); - - if(location_position_equal((LocationPosition*) a, (LocationPosition *)b) == TRUE) { - return 0; - } - - return -1; -} - -static int -boundary_compare (gconstpointer comp1, gconstpointer comp2) -{ - g_return_val_if_fail(comp1, 1); - g_return_val_if_fail(comp2, -1); - - int ret = -1; - - LocationBoundary *boundary1 = (LocationBoundary *)comp1; - LocationBoundary *boundary2 = (LocationBoundary *)comp2; - - if (boundary1->type == boundary2->type) { - switch (boundary1->type) { - case LOCATION_BOUNDARY_CIRCLE: { - if (location_position_equal(boundary1->circle.center, boundary2->circle.center) - && boundary1->circle.radius == boundary2->circle.radius) { - ret = 0; - } - break; - } - case LOCATION_BOUNDARY_RECT: { - if (location_position_equal(boundary1->rect.left_top, boundary2->rect.left_top) - && location_position_equal(boundary1->rect.right_bottom, boundary2->rect.right_bottom)) { - ret = 0; - } - break; - } - case LOCATION_BOUNDARY_POLYGON: { - - GList *boundary1_next = NULL; - GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL; - if (g_list_length(boundary1->polygon.position_list) != g_list_length(boundary2->polygon.position_list)) { - return -1; - } - - // Find a matching index of Boundary2 with Boundary1's 1st postion. - boundary2_start = g_list_find_custom(boundary2->polygon.position_list, g_list_nth_data(boundary1->polygon.position_list, 0), (GCompareFunc) compare_position); - if (boundary2_start == NULL) return -1; - - boundary2_prev = g_list_previous(boundary2_start); - boundary2_next = g_list_next(boundary2_start); - if (boundary2_prev == NULL) boundary2_prev = g_list_last(boundary2->polygon.position_list); - if (boundary2_next == NULL) boundary2_next = g_list_first(boundary2->polygon.position_list); - - boundary1_next = g_list_next(boundary1->polygon.position_list); - if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_prev->data) == TRUE){ - boundary1_next = g_list_next(boundary1_next); - while (boundary1_next) { - boundary2_prev = g_list_previous(boundary2_prev); - if (boundary2_prev == NULL) boundary2_prev = g_list_last(boundary2->polygon.position_list); - if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*) boundary2_prev->data) == FALSE){ - return -1; - } - boundary1_next = g_list_next(boundary1_next); - } - ret = 0; - } - else if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_next->data) == TRUE) { - boundary1_next = g_list_next(boundary1_next); - while(boundary1_next) { - boundary2_next = g_list_next(boundary2_next); - if (boundary2_next == NULL) boundary2_next = g_list_first(boundary2->polygon.position_list); - if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*) boundary2_next->data) == FALSE){ - return -1; - } - boundary1_next = g_list_next(boundary1_next); - } - ret = 0; - } - else { - return -1; - } - break; - } - default:{ - ret = -1; - break; - } - - } - } - - return ret; -} - -int set_prop_boundary(GList **prev_boundary_list, GList *new_boundary_list) -{ - g_return_val_if_fail(new_boundary_list, LOCATION_ERROR_PARAMETER); - - int index; - GList *check_list = NULL; - - LocationBoundary *new_boundary = NULL; - LocationBoundary *copy_boundary = NULL; - - index = 0; - while((new_boundary = (LocationBoundary*) g_list_nth_data(new_boundary_list, index)) != NULL) { - - check_list = g_list_find_custom(*prev_boundary_list, new_boundary, (GCompareFunc)boundary_compare); - if (check_list == NULL) { - LOCATION_LOGD("Set Prop >> boundary type: [%d]", new_boundary->type); - copy_boundary = location_boundary_copy(new_boundary); - *prev_boundary_list = g_list_append(*prev_boundary_list, copy_boundary); - } - index++; - } - *prev_boundary_list = g_list_first(*prev_boundary_list); - - return LOCATION_ERROR_NONE; -} - - - -int set_prop_removal_boundary(GList **prev_boundary_list, LocationBoundary* boundary) -{ - g_return_val_if_fail(*prev_boundary_list, LOCATION_ERROR_PARAMETER); - - GList *check_list = NULL; - - check_list = g_list_find_custom (*prev_boundary_list, boundary, (GCompareFunc) boundary_compare); - if (check_list) { - LOCATION_LOGD("Found"); - *prev_boundary_list = g_list_delete_link(*prev_boundary_list, check_list); - } - - if (g_list_length(*prev_boundary_list) == 0 ) { - LOCATION_LOGD("Boundary List is empty"); - g_list_free(*prev_boundary_list); - *prev_boundary_list = NULL; - } - - return LOCATION_ERROR_NONE; -} - -int get_last_known_position (LocationMethod method, LocationLastPosition *last_pos) -{ - int timestamp = 0; - double longitude = 0.0, latitude = 0.0, altitude = 0.0; - double hor_accuracy = 0.0, ver_accuracy = 0.0; - LOCATION_LOGD("Method [%d]", method); - switch (method) { - case LOCATION_METHOD_SPS: - if (vconf_get_int(SPS_LAST_TIMESTAMP, ×tamp) || - vconf_get_dbl(SPS_LAST_LATITUDE, &latitude) || - vconf_get_dbl(SPS_LAST_LONGITUDE, &longitude) || - vconf_get_dbl(SPS_LAST_ALTITUDE, &altitude) || - vconf_get_dbl(SPS_LAST_HORACCURACY, &hor_accuracy) || - vconf_get_dbl(SPS_LAST_VERACCURACY, &ver_accuracy)) { - return -1; - } - break; - case LOCATION_METHOD_WPS: - if (vconf_get_int(WPS_LAST_TIMESTAMP, ×tamp) || - vconf_get_dbl(WPS_LAST_LATITUDE, &latitude) || - vconf_get_dbl(WPS_LAST_LONGITUDE, &longitude) || - vconf_get_dbl(WPS_LAST_ALTITUDE, &altitude) || - vconf_get_dbl(WPS_LAST_HORACCURACY, &hor_accuracy)) { - return -1; - } - break; - case LOCATION_METHOD_GPS: - if (vconf_get_int(GPS_LAST_TIMESTAMP, ×tamp) || - vconf_get_dbl(GPS_LAST_LATITUDE, &latitude) || - vconf_get_dbl(GPS_LAST_LONGITUDE, &longitude) || - vconf_get_dbl(GPS_LAST_ALTITUDE, &altitude) || - vconf_get_dbl(GPS_LAST_HORACCURACY, &hor_accuracy) || - vconf_get_dbl(GPS_LAST_VERACCURACY, &ver_accuracy)) { - return -1; - } - break; - case LOCATION_METHOD_HYBRID: - default: - return -1; - - } - - last_pos->method = method; - last_pos->timestamp = (guint) timestamp; - last_pos->longitude = (gdouble) longitude; - last_pos->latitude = (gdouble) latitude; - last_pos->altitude = (gdouble) altitude; - last_pos->horizontal_accuracy = (gdouble) hor_accuracy; - last_pos->vertical_accuracy = (gdouble) ver_accuracy; - - return 0; -} - - diff --git a/location/location-common-util.h b/location/location-common-util.h deleted file mode 100644 index 99d9654..0000000 --- a/location/location-common-util.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * libslp-location - * - * 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_COMMON_UTIL_H__ -#define __LOCATION_COMMON_UTIL_H__ - -#include -#include - -/** - * @file location-common-util.h - * @brief This file contains the common utils for LocationObject. - * @addtogroup LocationInternal - * @{ - * @} - */ - -G_BEGIN_DECLS - -int set_prop_boundary(GList **prev_boundary_list, GList *new_boundary_list); -int set_prop_removal_boundary(GList **prev_boundary_list, LocationBoundary *boundary); - -int get_last_known_position (LocationMethod method, LocationLastPosition *last_pos); - -G_END_DECLS - -#endif diff --git a/location/location-cps.c b/location/location-cps.c deleted file mode 100644 index c0c404a..0000000 --- a/location/location-cps.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-setting.h" -#include "location/location-log.h" - -#include "location/location-module-internal.h" - -#include "location/location-cps.h" -#include "location/location-marshal.h" -#include "location/location-ielement.h" - -typedef struct _LocationCpsPrivate { - LocationCpsMod *mod; - LocationPosition *pos; - LocationAccuracy *acc; -} LocationCpsPrivate; - -enum { - PROP_0, - PROP_METHOD_TYPE, - PROP_LAST_POSITION -}; - -#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_CPS, LocationCpsPrivate)) - -static void location_ielement_interface_init (LocationIElementInterface *iface); - -G_DEFINE_TYPE_WITH_CODE (LocationCps, location_cps, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, - location_ielement_interface_init)); - -static void -location_cps_dispose (GObject *gobject) -{ - LOCATION_LOGD("location_cps_dispose"); - G_OBJECT_CLASS (location_cps_parent_class)->dispose (gobject); -} - -static void -location_cps_finalize (GObject *gobject) -{ - LOCATION_LOGD("location_cps_finalize"); - LocationCpsPrivate* priv = GET_PRIVATE(gobject); - module_free(priv->mod, "cps"); - priv->mod = NULL; - - G_OBJECT_CLASS (location_cps_parent_class)->finalize (gobject); -} - -static void -location_cps_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - LocationCpsPrivate *priv = GET_PRIVATE (object); - - switch (property_id){ - case PROP_METHOD_TYPE: - g_value_set_int(value, LOCATION_METHOD_CPS); - break; - case PROP_LAST_POSITION:{ - g_value_set_boxed (value, priv->pos); - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static int -location_cps_get_position (LocationCps *self, - LocationPosition **position, - LocationAccuracy **accuracy) -{ - LOCATION_LOGD("location_cps_get_position"); - - LocationCpsPrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - setting_retval_if_fail(GPS_ENABLED); - setting_retval_if_fail(NETWORK_ENABLED); - - LocModCpsOps ops = priv->mod->ops; - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (ops.get_position, LOCATION_ERROR_NOT_AVAILABLE); - int ret = ops.get_position(priv->mod->handler, position, accuracy); - if(priv->pos) location_position_free(priv->pos); - if(priv->acc) location_accuracy_free(priv->acc); - priv->pos = location_position_copy(*position); - priv->acc = location_accuracy_copy(*accuracy); - return ret; -} - -static void -location_ielement_interface_init (LocationIElementInterface *iface) -{ - iface->get_position = (TYPE_GET_POSITION)location_cps_get_position; -} - -static void -location_cps_init (LocationCps *self) -{ - LOCATION_LOGD("location_cps_init"); - LocationCpsPrivate* priv = GET_PRIVATE(self); - - priv->mod = (LocationCpsMod*)module_new("cps"); - if(!priv->mod) LOCATION_LOGW("module loading failed"); - - priv->pos = NULL; - priv->acc = NULL; -} - -static void -location_cps_class_init (LocationCpsClass *klass) -{ - LOCATION_LOGD("location_cps_class_init"); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GParamSpec *pspec; - - gobject_class->get_property = location_cps_get_property; - - gobject_class->dispose = location_cps_dispose; - gobject_class->finalize = location_cps_finalize; - - g_type_class_add_private (klass, sizeof (LocationCpsPrivate)); - - pspec = g_param_spec_int ("method", - "method type", - "location method type name", - LOCATION_METHOD_CPS, - LOCATION_METHOD_CPS, - LOCATION_METHOD_CPS, - G_PARAM_READABLE); - g_object_class_install_property (gobject_class, - PROP_METHOD_TYPE, - pspec); - - pspec = g_param_spec_boxed ("last-position", - "cps last position prop", - "cps last position data", - LOCATION_TYPE_POSITION, - G_PARAM_READABLE); - g_object_class_install_property (gobject_class, - PROP_LAST_POSITION, - pspec); -} - diff --git a/location/location-cps.h b/location/location-cps.h deleted file mode 100644 index 5effdf4..0000000 --- a/location/location-cps.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * libslp-location - * - * 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_CPS_H__ -#define __LOCATION_CPS_H__ - -#include - -/** - * @file location-cps.h - * @brief This file contains the internal definitions and structures related to CPS. - * @addtogroup LocationInternal - * @{ - * @} - */ - -G_BEGIN_DECLS - -#define LOCATION_TYPE_CPS (location_cps_get_type ()) -#define LOCATION_CPS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_CPS, LocationCps)) -#define LOCATION_IS_CPS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_CPS)) -#define LOCATION_CPS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_CPS, LocationCpsClass)) -#define LOCATION_IS_CPS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_CPS)) -#define LOCATION_CPS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_CPS, LocationCpsClass)) - -typedef struct _LocationCps LocationCps; -typedef struct _LocationCpsClass LocationCpsClass; - -struct _LocationCps -{ - GObject parent_instance; -}; - -struct _LocationCpsClass -{ - GObjectClass parent_class; -}; - -GType location_cps_get_type (void); - -G_END_DECLS - -#endif diff --git a/location/location-geocode.c b/location/location-geocode.c deleted file mode 100644 index ce15850..0000000 --- a/location/location-geocode.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-log.h" - -#include "location/location-module-internal.h" - -#include "location/location-geocode.h" -#include "location/location-marshal.h" -#include "location/location-ielement.h" - -typedef struct _LocationGeocodePrivate { - LocationGeoMod* mod; -} LocationGeocodePrivate; - -enum { - PROP_0, - PROP_SERVICE_NAME -}; - -#define DEFAULT_SERVICE "decarta" - -#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_GEOCODE, LocationGeocodePrivate)) - -static void location_ielement_interface_init (LocationIElementInterface *iface); - -G_DEFINE_TYPE_WITH_CODE (LocationGeocode, location_geocode, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, location_ielement_interface_init)); - - -static void -location_geocode_dispose (GObject *gobject) -{ - LOCATION_LOGD("location_geocode_dispose"); - - G_OBJECT_CLASS (location_geocode_parent_class)->dispose (gobject); -} - -static void -location_geocode_finalize (GObject *gobject) -{ - LOCATION_LOGD("location_geocode_finalize"); - LocationGeocodePrivate* priv = GET_PRIVATE(gobject); - module_free(priv->mod, "geocode"); - priv->mod = NULL; - G_OBJECT_CLASS (location_geocode_parent_class)->finalize (gobject); -} - -static void -location_geocode_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - LocationGeocodePrivate *priv = GET_PRIVATE (object); - - g_return_if_fail(priv->mod); - g_return_if_fail(priv->mod->handler); - switch (property_id){ - case PROP_SERVICE_NAME:{ - char* service_name = NULL; - if(priv->mod->ops.get_service_name){ - if( LOCATION_ERROR_NONE != priv->mod->ops.get_service_name(priv->mod->handler, &service_name) ){ - service_name = NULL; - } - } - LOCATION_LOGD("Get prop>> Service name: %s", service_name); - g_value_set_string(value, service_name); - g_free(service_name); - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static int -location_geocode_get_geocode (LocationGeocode *self, - const LocationAddress *address, - GList **position_list, - GList **accuracy_list) -{ - LOCATION_LOGD("location_geocode_get_geocode"); - LocationGeocodePrivate* priv = GET_PRIVATE(self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.get_geocode, LOCATION_ERROR_NOT_AVAILABLE); - return (priv->mod->ops.get_geocode)(priv->mod->handler, address, position_list, accuracy_list); -} - -static int -location_geocode_get_geocode_freeform (LocationGeocode *self, - const gchar *address, - GList **position_list, - GList **accuracy_list) -{ - LOCATION_LOGD("location_geocode_get_geocode_freeform"); - LocationGeocodePrivate* priv = GET_PRIVATE(self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.get_geocode_freetext, LOCATION_ERROR_NOT_AVAILABLE); - return (priv->mod->ops.get_geocode_freetext)(priv->mod->handler, address, position_list, accuracy_list); -} - -static int -location_geocode_get_reversegeocode (LocationGeocode *self, - const LocationPosition *position, - LocationAddress **address, - LocationAccuracy **accuracy) -{ - LOCATION_LOGD("location_geocode_get_reversegeocode"); - LocationGeocodePrivate* priv = GET_PRIVATE(self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.get_reverse_geocode, LOCATION_ERROR_NOT_AVAILABLE); - return (priv->mod->ops.get_reverse_geocode)(priv->mod->handler, position, address, accuracy); -} - -static int -location_geocode_get_geocode_async (LocationGeocode *self, - LocationAddress *address, - LocationPositionCB callback, - gpointer userdata) -{ - LOCATION_LOGD("location_geocode_get_geocode_async"); - LocationGeocodePrivate* priv = GET_PRIVATE(self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.get_geocode_async, LOCATION_ERROR_NOT_AVAILABLE); - return (priv->mod->ops.get_geocode_async)(priv->mod->handler, address, callback, userdata); -} - -static int -location_geocode_get_geocode_freeform_async (LocationGeocode *self, - const gchar *address, - LocationPositionCB callback, - gpointer userdata) -{ - LOCATION_LOGD("location_geocode_get_geocode_freeform_async"); - LocationGeocodePrivate* priv = GET_PRIVATE(self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.get_geocode_freetext_async, LOCATION_ERROR_NOT_AVAILABLE); - return (priv->mod->ops.get_geocode_freetext_async)(priv->mod->handler, address, callback, userdata); -} - -static int -location_geocode_get_reversegeocode_async (LocationGeocode *self, - const LocationPosition *position, - LocationAddressCB callback, - gpointer userdata) -{ - LOCATION_LOGD("location_geocode_get_reversegeocode_async"); - LocationGeocodePrivate* priv = GET_PRIVATE(self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.get_reverse_geocode_async, LOCATION_ERROR_NOT_AVAILABLE); - return (priv->mod->ops.get_reverse_geocode_async)(priv->mod->handler, position, callback, userdata); -} - -static void -location_ielement_interface_init (LocationIElementInterface *iface) -{ - iface->get_geocode = (TYPE_GET_GEOCODE)location_geocode_get_geocode; - iface->get_geocode_freeform = (TYPE_GET_GEOCODE_FREEFORM)location_geocode_get_geocode_freeform; - iface->get_reversegeocode = (TYPE_GET_REVERSEGEOCODE)location_geocode_get_reversegeocode; - iface->get_geocode_async = (TYPE_GET_GEOCODE_ASYNC)location_geocode_get_geocode_async; - iface->get_geocode_freeform_async = (TYPE_GET_GEOCODE_FREEFORM_ASYNC)location_geocode_get_geocode_freeform_async; - iface->get_reversegeocode_async = (TYPE_GET_REVERSEGEOCODE_ASYNC)location_geocode_get_reversegeocode_async; -} - -static void -location_geocode_init (LocationGeocode *self) -{ - LOCATION_LOGD("location_geocode_init"); - LocationGeocodePrivate* priv = GET_PRIVATE(self); - - priv->mod = (LocationGeoMod*)module_new("geocode"); - if(!priv->mod) LOCATION_LOGW("module loading failed"); -} - -static void -location_geocode_class_init (LocationGeocodeClass *klass) -{ - LOCATION_LOGD("location_geocode_class_init"); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GParamSpec *pspec; - - gobject_class->get_property = location_geocode_get_property; - - gobject_class->dispose = location_geocode_dispose; - gobject_class->finalize = location_geocode_finalize; - - g_type_class_add_private (klass, sizeof (LocationGeocodePrivate)); - - pspec = g_param_spec_string ("service provider", - "geocode service provider name prop", - "geocode service provider name", - DEFAULT_SERVICE, - G_PARAM_READABLE); - g_object_class_install_property (gobject_class, - PROP_SERVICE_NAME, - pspec); -} diff --git a/location/location-geocode.h b/location/location-geocode.h deleted file mode 100644 index efb4ac1..0000000 --- a/location/location-geocode.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * libslp-location - * - * 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_GEOCODE_H__ -#define __LOCATION_GEOCODE_H__ - -#include - -/** - * @file location-geocode.h - * @brief This file contains the internal definitions and structures related to geocode. - * @addtogroup LocationInternal - * @{ - * @} - */ - -G_BEGIN_DECLS - -#define LOCATION_TYPE_GEOCODE (location_geocode_get_type ()) -#define LOCATION_GEOCODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_GEOCODE, LocationGeocode)) -#define LOCATION_IS_GEOCODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_GEOCODE)) -#define LOCATION_GEOCODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_GEOCODE, LocationGeocodeClass)) -#define LOCATION_IS_GEOCODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_GEOCODE)) -#define LOCATION_GEOCODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_GEOCODE, LocationGeocodeClass)) - -typedef struct _LocationGeocode LocationGeocode; -typedef struct _LocationGeocodeClass LocationGeocodeClass; - -struct _LocationGeocode -{ - GObject parent_instance; -}; - -struct _LocationGeocodeClass -{ - GObjectClass parent_class; -}; - -GType location_geocode_get_type (void); - -G_END_DECLS - -#endif diff --git a/location/location-gps.c b/location/location-gps.c deleted file mode 100644 index 3c3588f..0000000 --- a/location/location-gps.c +++ /dev/null @@ -1,532 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-setting.h" -#include "location/location-log.h" - -#include "location/location-module-internal.h" - -#include "location/location-gps.h" -#include "location/location-marshal.h" -#include "location/location-ielement.h" -#include "location/location-signaling-util.h" -#include "location/location-common-util.h" - - -typedef struct _LocationGpsPrivate { - LocationGpsMod* mod; - gboolean is_started; - gboolean set_noti; - gboolean enabled; - guint interval; - LocationPosition* pos; - LocationVelocity* vel; - LocationAccuracy* acc; - GList* boundary_list; - ZoneStatus zone_status; -} LocationGpsPrivate; - -enum { - PROP_0, - PROP_DEV_NAME, - PROP_METHOD_TYPE, - PROP_LAST_POSITION, - PROP_UPDATE_INTERVAL, - PROP_BOUNDARY, - PROP_REMOVAL_BOUNDARY, - PROP_NMEA, - PROP_SATELLITE, - PROP_MAX -}; - -static guint32 signals[LAST_SIGNAL] = {0, }; -static GParamSpec *properties[PROP_MAX] = {NULL, }; - -#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_GPS, LocationGpsPrivate)) - -static void location_ielement_interface_init (LocationIElementInterface *iface); - -G_DEFINE_TYPE_WITH_CODE (LocationGps, location_gps, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, - location_ielement_interface_init)); - -static void -gps_status_cb (gboolean enabled, - LocationStatus status, - gpointer self) -{ - LOCATION_LOGD("gps_status_cb"); - g_return_if_fail(self); - LocationGpsPrivate* priv = GET_PRIVATE(self); - enable_signaling(self, signals, &(priv->enabled), enabled, status); -} - -static void -gps_position_cb (gboolean enabled, - LocationPosition *pos, - LocationAccuracy *acc, - gpointer self) -{ - LOCATION_LOGD("gps_position_cb"); - g_return_if_fail(self); - g_return_if_fail(pos); - g_return_if_fail(acc); - LocationGpsPrivate* priv = GET_PRIVATE(self); - enable_signaling(self, signals, &(priv->enabled), enabled, pos->status); - position_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->pos), &(priv->acc), priv->boundary_list, &(priv->zone_status), enabled, pos, acc); -} - -static void -gps_velocity_cb (gboolean enabled, - LocationVelocity *vel, - LocationAccuracy *acc, - gpointer self) -{ - LOCATION_LOGD("gps_velocity_cb"); - g_return_if_fail(self); - LocationGpsPrivate* priv = GET_PRIVATE(self); - velocity_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->vel), enabled, vel, acc); -} - -static void -location_setting_gps_cb (keynode_t *key, - gpointer self) -{ - LOCATION_LOGD("location_setting_gps_cb"); - g_return_if_fail(key); - g_return_if_fail(self); - LocationGpsPrivate* priv = GET_PRIVATE(self); - g_return_if_fail (priv->mod); - g_return_if_fail (priv->mod->handler); - - int ret = LOCATION_ERROR_NONE; - - if (0 == location_setting_get_key_val(key) && priv->mod->ops.stop && priv->is_started) { - LOCATION_LOGD("location stopped by setting"); - ret = priv->mod->ops.stop(priv->mod->handler); - if (ret == LOCATION_ERROR_NONE) priv->is_started = FALSE; - } - else if (1 == location_setting_get_key_val(key) && priv->mod->ops.start && !priv->is_started) { - LOCATION_LOGD("location resumed by setting"); - ret = priv->mod->ops.start (priv->mod->handler, gps_status_cb, gps_position_cb, gps_velocity_cb, self); - if (ret == LOCATION_ERROR_NONE) priv->is_started = TRUE; - } -} - -static int -location_gps_start (LocationGps *self) -{ - LOCATION_LOGD("location_gps_start"); - LocationGpsPrivate* priv = GET_PRIVATE(self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.start, LOCATION_ERROR_NOT_AVAILABLE); - - if (priv->is_started == TRUE) return LOCATION_ERROR_NONE; - - int ret = LOCATION_ERROR_NONE; - int noti_err = 0; - - if (!location_setting_get_int(GPS_ENABLED)) { - ret = LOCATION_ERROR_NOT_ALLOWED; - } - else { - ret = priv->mod->ops.start (priv->mod->handler, gps_status_cb, gps_position_cb, gps_velocity_cb, self); - if (ret == LOCATION_ERROR_NONE) { - priv->is_started = TRUE; - } - else { - return ret; - } - } - - if(priv->set_noti == FALSE) { - noti_err = location_setting_add_notify (GPS_ENABLED, location_setting_gps_cb, self); - if (noti_err != 0) { - return LOCATION_ERROR_UNKNOWN; - } - priv->set_noti = TRUE; - } - - return ret; -} - -static int -location_gps_stop (LocationGps *self) -{ - LOCATION_LOGD("location_gps_stop"); - LocationGpsPrivate* priv = GET_PRIVATE(self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.stop, LOCATION_ERROR_NOT_AVAILABLE); - - int ret = LOCATION_ERROR_NONE; - int noti_err = 0; - - if ( priv->is_started == TRUE) { - ret = priv->mod->ops.stop (priv->mod->handler); - if (ret == LOCATION_ERROR_NONE) { - priv->is_started = FALSE; - } - else { - return ret; - } - } - - if(priv->set_noti == TRUE) { - noti_err = location_setting_ignore_notify (GPS_ENABLED, location_setting_gps_cb); - if (noti_err != 0) { - return LOCATION_ERROR_UNKNOWN; - } - priv->set_noti = FALSE; - } - - return ret; -} - -static void -location_gps_dispose (GObject *gobject) -{ - LOCATION_LOGD("location_gps_dispose"); - G_OBJECT_CLASS (location_gps_parent_class)->dispose (gobject); -} - -static void -location_gps_finalize (GObject *gobject) -{ - LOCATION_LOGD("location_gps_finalize"); - LocationGpsPrivate* priv = GET_PRIVATE(gobject); - module_free(priv->mod, "gps"); - priv->mod = NULL; - G_OBJECT_CLASS (location_gps_parent_class)->finalize (gobject); -} - -static void -location_gps_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - LocationGpsPrivate* priv = GET_PRIVATE(object); - - g_return_if_fail (priv->mod); - g_return_if_fail (priv->mod->handler); - LocModGpsOps ops = priv->mod->ops; - - int ret = 0; - switch (property_id){ - case PROP_DEV_NAME: { - char* devname = g_value_dup_string(value); - LOCATION_LOGD("Set prop>> device_name: %s", devname); - if(ops.set_devname) - ops.set_devname(priv->mod->handler, devname); - g_free(devname); - break; - } - case PROP_BOUNDARY: { - GList *boundary_list = g_list_copy(g_value_get_pointer(value)); - ret = set_prop_boundary(&priv->boundary_list, boundary_list); - if(ret != 0) LOCATION_LOGD("Set boundary. Error[%d]", ret); - break; - } - case PROP_REMOVAL_BOUNDARY: { - LocationBoundary *req_boundary = (LocationBoundary*) g_value_dup_boxed(value); - ret = set_prop_removal_boundary(&priv->boundary_list, req_boundary); - if(ret != 0) LOCATION_LOGD("Removal boundary. Error[%d]", ret); - break; - } - case PROP_UPDATE_INTERVAL: { - guint interval = g_value_get_uint(value); - LOCATION_LOGD("Set prop>> update-interval: %u", interval); - if(interval > 0) { - if(interval < LOCATION_UPDATE_INTERVAL_MAX) - priv->interval = interval; - else - priv->interval = (guint)LOCATION_UPDATE_INTERVAL_MAX; - } - else - priv->interval = (guint)LOCATION_UPDATE_INTERVAL_DEFAULT; - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -location_gps_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - LocationGpsPrivate *priv = GET_PRIVATE (object); - - g_return_if_fail (priv->mod); - g_return_if_fail (priv->mod->handler); - LocModGpsOps ops = priv->mod->ops; - switch (property_id) { - case PROP_DEV_NAME: { - char* devname = NULL; - if(ops.get_devname) - ops.get_devname(priv->mod->handler, &devname); - LOCATION_LOGD ("Get prop>> device_name: %s", devname); - g_value_set_string (value, devname); - g_free(devname); - break; - } - case PROP_METHOD_TYPE: - g_value_set_int(value, LOCATION_METHOD_GPS); - break; - case PROP_LAST_POSITION: - g_value_set_boxed (value, priv->pos); - break; - case PROP_UPDATE_INTERVAL: - g_value_set_uint(value, priv->interval); - break; - case PROP_BOUNDARY: - g_value_set_pointer(value, g_list_first(priv->boundary_list)); - break; - case PROP_NMEA: { - char *nmea_data = NULL; - if (ops.get_nmea && LOCATION_ERROR_NONE == ops.get_nmea(priv->mod->handler, &nmea_data) && nmea_data) { - LOCATION_LOGD("Get prop>> Lastest nmea: \n%s", nmea_data); - g_value_set_string(value, nmea_data); - g_free(nmea_data); - } else { - LOCATION_LOGW("Get prop>> Lastest nmea: failed"); - g_value_set_string(value, NULL); - } - break; - } - case PROP_SATELLITE: { - LocationSatellite *satellite = NULL; - if (ops.get_satellite && priv->mod->handler && LOCATION_ERROR_NONE == ops.get_satellite(priv->mod->handler, &satellite) && satellite){ - LOCATION_LOGD("Get prop>> Last sat: num_used(%d) num_view(%d)", satellite->num_of_sat_used, satellite->num_of_sat_inview); - g_value_set_boxed (value, satellite); - location_satellite_free(satellite); - } else { - LOCATION_LOGW("Get prop>> Last sat: failed"); - g_value_set_boxed (value, NULL); - } - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static int -location_gps_get_position (LocationGps *self, - LocationPosition **position, - LocationAccuracy **accuracy) -{ - LOCATION_LOGD("location_gps_get_position"); - - LocationGpsPrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - setting_retval_if_fail(GPS_ENABLED); - - LocModGpsOps ops = priv->mod->ops; - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (ops.get_position, LOCATION_ERROR_NOT_AVAILABLE); - return ops.get_position(priv->mod->handler, position, accuracy); -} - -static int -location_gps_get_velocity (LocationGps *self, - LocationVelocity **velocity, - LocationAccuracy **accuracy) -{ - LOCATION_LOGD("location_gps_get_velocity"); - - LocationGpsPrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - setting_retval_if_fail(GPS_ENABLED); - - LocModGpsOps ops = priv->mod->ops; - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (ops.get_velocity, LOCATION_ERROR_NOT_AVAILABLE); - return ops.get_velocity(priv->mod->handler, velocity, accuracy); -} - -static void -location_ielement_interface_init (LocationIElementInterface *iface) -{ - iface->start = (TYPE_START_FUNC)location_gps_start; - iface->stop = (TYPE_STOP_FUNC)location_gps_stop; - iface->get_position = (TYPE_GET_POSITION)location_gps_get_position; - iface->get_velocity = (TYPE_GET_VELOCITY)location_gps_get_velocity; -} - -static void -location_gps_init (LocationGps *self) -{ - LOCATION_LOGD("location_gps_init"); - LocationGpsPrivate* priv = GET_PRIVATE(self); - - priv->mod = (LocationGpsMod*)module_new("gps"); - if(!priv->mod) LOCATION_LOGW("module loading failed"); - - priv->is_started = FALSE; - priv->set_noti = FALSE; - priv->enabled= FALSE; - priv->interval = LOCATION_UPDATE_INTERVAL_DEFAULT; - - priv->pos = NULL; - priv->vel = NULL; - priv->acc = NULL; - priv->zone_status = ZONE_STATUS_NONE; - priv->boundary_list = NULL; -} - -static void -location_gps_class_init (LocationGpsClass *klass) -{ - LOCATION_LOGD("location_gps_class_init"); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->set_property = location_gps_set_property; - gobject_class->get_property = location_gps_get_property; - - gobject_class->dispose = location_gps_dispose; - gobject_class->finalize = location_gps_finalize; - - g_type_class_add_private (klass, sizeof (LocationGpsPrivate)); - - signals[SERVICE_ENABLED] = g_signal_new ("service-enabled", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationGpsClass, enabled), - NULL, NULL, - location_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - signals[SERVICE_DISABLED] = g_signal_new ("service-disabled", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationGpsClass, disabled), - NULL, NULL, - location_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - signals[SERVICE_UPDATED] = g_signal_new ("service-updated", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationGpsClass, updated), - NULL, NULL, - location_VOID__UINT_POINTER_POINTER, - G_TYPE_NONE, 3, - G_TYPE_UINT, - G_TYPE_POINTER, - G_TYPE_POINTER); - - signals[ZONE_IN] = g_signal_new ("zone-in", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationGpsClass, zone_in), - NULL, NULL, - location_VOID__UINT_POINTER_POINTER, - G_TYPE_NONE, 3, - G_TYPE_UINT, - G_TYPE_POINTER, - G_TYPE_POINTER); - - signals[ZONE_OUT] = g_signal_new ("zone-out", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationGpsClass, zone_out), - NULL, NULL, - location_VOID__UINT_POINTER_POINTER, - G_TYPE_NONE, 3, - G_TYPE_UINT, - G_TYPE_POINTER, - G_TYPE_POINTER); - - properties[PROP_DEV_NAME] = g_param_spec_string ("dev-name", - "gps device name prop", - "gps device name", - "/dev/rfcomm0", - G_PARAM_READWRITE); - - properties[PROP_METHOD_TYPE] = g_param_spec_int ("method", - "method type", - "location method type name", - LOCATION_METHOD_GPS, - LOCATION_METHOD_GPS, - LOCATION_METHOD_GPS, - G_PARAM_READABLE); - - properties[PROP_LAST_POSITION] = g_param_spec_boxed ("last-position", - "gps last position prop", - "gps last position data", - LOCATION_TYPE_POSITION, - G_PARAM_READABLE); - - properties[PROP_UPDATE_INTERVAL] = g_param_spec_uint ("update-interval", - "gps update interval prop", - "gps update interval data", - LOCATION_UPDATE_INTERVAL_MIN, - LOCATION_UPDATE_INTERVAL_MAX, - LOCATION_UPDATE_INTERVAL_DEFAULT, - G_PARAM_READWRITE); - - properties[PROP_BOUNDARY] = g_param_spec_pointer ("boundary", - "gps boundary prop", - "gps boundary data", - G_PARAM_READWRITE); - - properties[PROP_REMOVAL_BOUNDARY] = g_param_spec_boxed("removal-boundary", - "gps removal boundary prop", - "gps removal boundary data", - LOCATION_TYPE_BOUNDARY, - G_PARAM_READWRITE); - - - properties[PROP_NMEA] = g_param_spec_string ("nmea", - "gps NMEA name prop", - "gps NMEA", - NULL, - G_PARAM_READABLE); - - properties[PROP_SATELLITE] = g_param_spec_boxed ("satellite", - "gps satellite prop", - "gps satellite data", - LOCATION_TYPE_SATELLITE, - G_PARAM_READABLE); - - g_object_class_install_properties (gobject_class, - PROP_MAX, - properties); - -} diff --git a/location/location-gps.h b/location/location-gps.h deleted file mode 100644 index 418bcf1..0000000 --- a/location/location-gps.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * libslp-location - * - * 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_GPS_H__ -#define __LOCATION_GPS_H__ - -#include - - -/** - * @file location-gps.h - * @brief This file contains the internal definitions and structures related to GPS. - * @defgroup LocationInternal Location Internal - * @addtogroup LocationInternal - * @{ - * @} - */ - -G_BEGIN_DECLS - -#define LOCATION_TYPE_GPS (location_gps_get_type ()) -#define LOCATION_GPS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_GPS, LocationGps)) -#define LOCATION_IS_GPS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_GPS)) -#define LOCATION_GPS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_GPS, LocationGpsClass)) -#define LOCATION_IS_GPS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_GPS)) -#define LOCATION_GPS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_GPS, LocationGpsClass)) - -typedef struct _LocationGps LocationGps; -typedef struct _LocationGpsClass LocationGpsClass; - -struct _LocationGps -{ - GObject parent_instance; -}; - -struct _LocationGpsClass -{ - GObjectClass parent_class; - - void (* enabled) (guint type); - void (* disabled) (guint type); - void (* updated) (guint type, gpointer data, gpointer accuracy); - void (* zone_in) (guint type, gpointer position, gpointer boundary); - void (* zone_out) (guint type, gpointer position, gpointer boundary); -}; - -GType location_gps_get_type (void); - -G_END_DECLS - -#endif diff --git a/location/location-hybrid.c b/location/location-hybrid.c deleted file mode 100644 index 6e82d86..0000000 --- a/location/location-hybrid.c +++ /dev/null @@ -1,576 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-setting.h" -#include "location/location-log.h" - -#include "location/location-module-internal.h" - -#include "location/location-hybrid.h" -#include "location/location-marshal.h" -#include "location/location-ielement.h" -#include "location/location-signaling-util.h" -#include "location/location-common-util.h" - -#include "location/location-gps.h" -#include "location/location-wps.h" -#include "location/location-sps.h" - -typedef struct _LocationHybridPrivate { - gboolean is_started; - gboolean gps_enabled; - gboolean wps_enabled; - gboolean sps_enabled; - guint interval; - LocationObject *gps; - LocationObject *wps; - LocationObject *sps; - gboolean enabled; - LocationMethod current_method; - LocationPosition *pos; - LocationVelocity *vel; - LocationAccuracy *acc; - GList* boundary_list; - ZoneStatus zone_status; - -} LocationHybridPrivate; - -enum { - PROP_0, - PROP_METHOD_TYPE, - PROP_LAST_POSITION, - PROP_UPDATE_INTERVAL, - PROP_BOUNDARY, - PROP_REMOVAL_BOUNDARY, - PROP_MAX -}; - -static guint32 signals[LAST_SIGNAL] = {0, }; -static GParamSpec *properties[PROP_MAX] = {NULL, }; - -#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_HYBRID, LocationHybridPrivate)) - -static void location_ielement_interface_init (LocationIElementInterface *iface); - -G_DEFINE_TYPE_WITH_CODE (LocationHybrid, location_hybrid, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, - location_ielement_interface_init)); - - -static LocationObject* -hybrid_get_update_method_obj (LocationHybridPrivate* priv) -{ - if(!priv->sps && !priv->gps && !priv->wps) return NULL; - - LocationObject* obj = NULL; - if (priv->sps_enabled) { - LOCATION_LOGW("Current method is SPS"); - priv->current_method = LOCATION_METHOD_SPS; - obj = priv->sps; - } else if (priv->gps_enabled) { - LOCATION_LOGW("Current method is GPS"); - priv->current_method = LOCATION_METHOD_GPS; - obj = priv->gps; - } else if (priv->wps_enabled) { - LOCATION_LOGW("Current method is WPS"); - priv->current_method = LOCATION_METHOD_WPS; - obj = priv->wps; - } else { - LOCATION_LOGW("No current method available"); - priv->current_method = LOCATION_METHOD_HYBRID; - obj = NULL; - } - return obj; -} - -static gboolean -hyrid_is_equal_g_type_method(GType g_type, LocationMethod method) -{ - if (g_type == LOCATION_TYPE_SPS && method == LOCATION_METHOD_SPS) return TRUE; - if (g_type == LOCATION_TYPE_GPS && method == LOCATION_METHOD_GPS) return TRUE; - if (g_type == LOCATION_TYPE_WPS && method == LOCATION_METHOD_WPS) return TRUE; - return FALSE; -} - -static void -hybrid_update_sps(LocationHybrid* self, - guint type, - gpointer data, - gpointer accuracy) -{ - LocationHybridPrivate* priv = GET_PRIVATE(self); - if (!priv->sps) return; - LOCATION_LOGD ("hybrid_update_sps"); - - switch (type) { - case POSITION_UPDATED: { - if (data) g_object_set(priv->sps, "position-base", data, NULL); - if (priv->gps) { - LocationSatellite* sat = NULL; - g_object_get(priv->gps, "satellite", &sat, NULL); - if (sat) { - g_object_set(priv->sps, "satellite-info", sat, NULL); - location_satellite_free (sat); - } - } - if (accuracy) g_object_set(priv->sps, "accuracy-info", accuracy, NULL); - break; - } - case VELOCITY_UPDATED: - if (data) g_object_set(priv->sps, "velocity-base", data, NULL); - if (accuracy) g_object_set(priv->sps, "accuracy-info", accuracy, NULL); - break; - } -} - -static void -hybrid_service_updated (GObject *obj, - guint type, - gpointer data, - gpointer accuracy, - gpointer self) -{ - LOCATION_LOGD ("hybrid_service_updated"); - LocationHybridPrivate* priv = GET_PRIVATE((LocationHybrid*)self); - GType g_type = G_TYPE_FROM_INSTANCE(obj); - if (g_type == LOCATION_TYPE_GPS) hybrid_update_sps((LocationHybrid*)self, type, data, accuracy); - if (hyrid_is_equal_g_type_method(g_type, priv->current_method)) { - LocationAccuracy *acc = (LocationAccuracy*)accuracy; - if (type == POSITION_UPDATED) { - LocationPosition *pos = (LocationPosition*)data; - position_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->pos), &(priv->acc), priv->boundary_list, &(priv->zone_status), TRUE, pos, acc); - } else if (type == VELOCITY_UPDATED) { - LocationVelocity *vel = (LocationVelocity*) data; - velocity_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->vel), TRUE, vel, acc); - } else LOCATION_LOGW ("Undefined GType updated"); - } - -} - -static void -hybrid_service_enabled (GObject *obj, - guint status, - gpointer self) -{ - LOCATION_LOGD ("hybrid_service_enabled"); - LocationHybridPrivate* priv = GET_PRIVATE((LocationHybrid*)self); - GType g_type = G_TYPE_FROM_INSTANCE(obj); - if (g_type == LOCATION_TYPE_SPS) priv->sps_enabled = TRUE; - else if(g_type == LOCATION_TYPE_GPS) priv->gps_enabled = TRUE; - else if(g_type == LOCATION_TYPE_WPS) priv->wps_enabled = TRUE; - else { - LOCATION_LOGW("Undefined GType enabled"); - return; - } - hybrid_get_update_method_obj(priv); - if(priv->sps_enabled || priv->gps_enabled || priv->wps_enabled) - enable_signaling(self, signals, &(priv->enabled), TRUE, status); -} - -static void -hybrid_service_disabled (GObject *obj, - guint status, - gpointer self) -{ - LOCATION_LOGD ("hybrid_service_disabled"); - LocationHybridPrivate* priv = GET_PRIVATE((LocationHybrid*)self); - GType g_type = G_TYPE_FROM_INSTANCE(obj); - if (g_type == LOCATION_TYPE_SPS) priv->sps_enabled = FALSE; - else if(g_type == LOCATION_TYPE_GPS) priv->gps_enabled = FALSE; - else if(g_type == LOCATION_TYPE_WPS) priv->wps_enabled = FALSE; - else { - LOCATION_LOGW("Undefined GType disabled"); - return; - } - hybrid_get_update_method_obj(priv); - if(!priv->sps_enabled && !priv->gps_enabled && !priv->wps_enabled) - enable_signaling(self, signals, &(priv->enabled), FALSE, status); -} - -static int -location_hybrid_start (LocationHybrid *self) -{ - LOCATION_LOGD("location_hybrid_start"); - - int ret_gps = LOCATION_ERROR_NONE; - int ret_wps = LOCATION_ERROR_NONE; - int ret_sps = LOCATION_ERROR_NONE; - - LocationHybridPrivate* priv = GET_PRIVATE(self); - if (priv->is_started == TRUE) - return LOCATION_ERROR_NONE; - - if(priv->gps) ret_gps = location_start(priv->gps); - if(priv->wps) ret_wps = location_start(priv->wps); - if(priv->sps) ret_sps = location_start(priv->sps); - - if (ret_gps != LOCATION_ERROR_NONE && - ret_wps != LOCATION_ERROR_NONE && - ret_sps != LOCATION_ERROR_NONE) { - if (ret_gps == LOCATION_ERROR_NOT_ALLOWED || - ret_wps == LOCATION_ERROR_NOT_ALLOWED || - ret_sps == LOCATION_ERROR_NOT_ALLOWED) { - priv->is_started = TRUE; - return LOCATION_ERROR_NOT_ALLOWED; - } - else { - return LOCATION_ERROR_NOT_AVAILABLE; - } - } - - priv->is_started = TRUE; - return LOCATION_ERROR_NONE; -} - -static int -location_hybrid_stop (LocationHybrid *self) -{ - LOCATION_LOGD("location_hybrid_stop"); - - LocationHybridPrivate* priv = GET_PRIVATE(self); - if( priv->is_started == FALSE) - return LOCATION_ERROR_NONE; - - int ret_gps = LOCATION_ERROR_NONE; - int ret_wps = LOCATION_ERROR_NONE; - int ret_sps = LOCATION_ERROR_NONE; - - if(priv->gps) ret_gps = location_stop(priv->gps); - if(priv->wps) ret_wps = location_stop(priv->wps); - if(priv->sps) ret_sps = location_stop(priv->sps); - - priv->is_started = FALSE; - - if (ret_gps != LOCATION_ERROR_NONE && - ret_wps != LOCATION_ERROR_NONE && - ret_sps != LOCATION_ERROR_NONE) - return LOCATION_ERROR_NOT_AVAILABLE; - - return LOCATION_ERROR_NONE; -} - -static void -location_hybrid_dispose (GObject *gobject) -{ - LOCATION_LOGD("location_hybrid_dispose"); - G_OBJECT_CLASS (location_hybrid_parent_class)->dispose (gobject); -} - -static void -location_hybrid_finalize (GObject *gobject) -{ - LOCATION_LOGD("location_hybrid_finalize"); - LocationHybridPrivate* priv = GET_PRIVATE(gobject); - - if (priv->gps) { - g_signal_handlers_disconnect_by_func(priv->gps, G_CALLBACK (hybrid_service_enabled), gobject); - g_signal_handlers_disconnect_by_func(priv->gps, G_CALLBACK (hybrid_service_disabled), gobject); - g_signal_handlers_disconnect_by_func(priv->gps, G_CALLBACK (hybrid_service_updated), gobject); - location_free(priv->gps); - } - if (priv->wps) { - g_signal_handlers_disconnect_by_func(priv->wps, G_CALLBACK (hybrid_service_enabled), gobject); - g_signal_handlers_disconnect_by_func(priv->wps, G_CALLBACK (hybrid_service_disabled), gobject); - g_signal_handlers_disconnect_by_func(priv->wps, G_CALLBACK (hybrid_service_updated), gobject); - location_free(priv->wps); - } - if (priv->sps) { - g_signal_handlers_disconnect_by_func(priv->sps, G_CALLBACK (hybrid_service_enabled), gobject); - g_signal_handlers_disconnect_by_func(priv->sps, G_CALLBACK (hybrid_service_disabled), gobject); - g_signal_handlers_disconnect_by_func(priv->sps, G_CALLBACK (hybrid_service_updated), gobject); - location_free(priv->sps); - } - - G_OBJECT_CLASS (location_hybrid_parent_class)->finalize (gobject); -} - -static void -location_hybrid_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - LocationHybridPrivate* priv = GET_PRIVATE(object); - if (!priv->gps && !priv->wps && !priv->sps) { - LOCATION_LOGW("Set property is not available now"); - return; - } - - int ret = 0; - switch (property_id){ - case PROP_BOUNDARY:{ - GList *boundary_list = (GList *)g_list_copy(g_value_get_pointer(value)); - ret = set_prop_boundary(&priv->boundary_list, boundary_list); - if(ret != 0) LOCATION_LOGD("Set boundary. Error[%d]", ret); - break; - } - case PROP_REMOVAL_BOUNDARY: { - LocationBoundary *req_boundary = (LocationBoundary*) g_value_dup_boxed(value); - ret = set_prop_removal_boundary(&priv->boundary_list, req_boundary); - if(ret != 0) LOCATION_LOGD("Removal boundary. Error[%d]", ret); - break; - } - case PROP_UPDATE_INTERVAL: { - guint interval = g_value_get_uint(value); - if(interval > 0) { - if(interval < LOCATION_UPDATE_INTERVAL_MAX) - priv->interval = interval; - else - priv->interval = (guint) LOCATION_UPDATE_INTERVAL_MAX; - - } - else - priv->interval = LOCATION_UPDATE_INTERVAL_DEFAULT; - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -location_hybrid_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - LocationHybridPrivate *priv = GET_PRIVATE (object); - if(!priv->gps && !priv->wps && !priv->sps){ - LOCATION_LOGW("Get property is not available now"); - return; - } - - LOCATION_LOGW("Get Propery ID[%d]", property_id); - - switch (property_id){ - case PROP_METHOD_TYPE: - g_value_set_int(value, priv->current_method); - break; - case PROP_LAST_POSITION: - g_value_set_boxed(value, priv->pos); - break; - case PROP_BOUNDARY: - g_value_set_pointer(value, g_list_first(priv->boundary_list)); - break; - case PROP_UPDATE_INTERVAL: - g_value_set_uint(value, priv->interval); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static int -location_hybrid_get_position (LocationHybrid *self, - LocationPosition **position, - LocationAccuracy **accuracy) -{ - LOCATION_LOGD("location_hybrid_get_position"); - setting_retval_if_fail(GPS_ENABLED); - - LocationHybridPrivate *priv = GET_PRIVATE (self); - LocationObject *obj = hybrid_get_update_method_obj(priv); - if(!obj) return LOCATION_ERROR_NOT_AVAILABLE; - return location_get_position (obj, position, accuracy); -} - -static int -location_hybrid_get_velocity (LocationHybrid *self, - LocationVelocity **velocity, - LocationAccuracy **accuracy) -{ - LOCATION_LOGD("location_hybrid_get_velocity"); - setting_retval_if_fail(GPS_ENABLED); - - LocationHybridPrivate *priv = GET_PRIVATE (self); - LocationObject *obj = hybrid_get_update_method_obj(priv); - if(!obj) return LOCATION_ERROR_NOT_AVAILABLE; - return location_get_velocity (obj, velocity, accuracy); -} - -static void -location_ielement_interface_init (LocationIElementInterface *iface) -{ - iface->start = (TYPE_START_FUNC)location_hybrid_start; - iface->stop = (TYPE_STOP_FUNC)location_hybrid_stop; - iface->get_position = (TYPE_GET_POSITION)location_hybrid_get_position; - iface->get_velocity = (TYPE_GET_VELOCITY)location_hybrid_get_velocity; -} - -static void -location_hybrid_init (LocationHybrid *self) -{ - LOCATION_LOGD("location_hybrid_init"); - LocationHybridPrivate* priv = GET_PRIVATE(self); - - priv->is_started = FALSE; - priv->interval = LOCATION_UPDATE_INTERVAL_DEFAULT; - priv->gps_enabled = FALSE; - priv->wps_enabled = FALSE; - priv->sps_enabled = FALSE; - priv->gps = NULL; - priv->wps = NULL; - priv->sps = NULL; - - if(location_is_supported_method(LOCATION_METHOD_GPS)) priv->gps = location_new (LOCATION_METHOD_GPS); - if(location_is_supported_method(LOCATION_METHOD_WPS)) priv->wps = location_new (LOCATION_METHOD_WPS); - if(location_is_supported_method(LOCATION_METHOD_SPS)) priv->sps = location_new (LOCATION_METHOD_SPS); - - if(priv->gps){ - g_signal_connect (priv->gps, "service-enabled", G_CALLBACK(hybrid_service_enabled), self); - g_signal_connect (priv->gps, "service-disabled", G_CALLBACK(hybrid_service_disabled), self); - g_signal_connect (priv->gps, "service-updated", G_CALLBACK(hybrid_service_updated), self); - } - if(priv->wps){ - g_signal_connect (priv->wps, "service-enabled", G_CALLBACK(hybrid_service_enabled), self); - g_signal_connect (priv->wps, "service-disabled", G_CALLBACK(hybrid_service_disabled), self); - g_signal_connect (priv->wps, "service-updated", G_CALLBACK(hybrid_service_updated), self); - } - if(priv->sps){ - g_signal_connect (priv->sps, "service-enabled", G_CALLBACK(hybrid_service_enabled), self); - g_signal_connect (priv->sps, "service-disabled", G_CALLBACK(hybrid_service_disabled), self); - g_signal_connect (priv->sps, "service-updated", G_CALLBACK(hybrid_service_updated), self); - } - - priv->current_method = LOCATION_METHOD_HYBRID; - priv->enabled= FALSE; - - priv->pos = NULL; - priv->vel = NULL; - priv->acc = NULL; - priv->zone_status = ZONE_STATUS_NONE; - priv->boundary_list = NULL; -} - -static void -location_hybrid_class_init (LocationHybridClass *klass) -{ - LOCATION_LOGD("location_hybrid_class_init"); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->set_property = location_hybrid_set_property; - gobject_class->get_property = location_hybrid_get_property; - - gobject_class->dispose = location_hybrid_dispose; - gobject_class->finalize = location_hybrid_finalize; - - g_type_class_add_private (klass, sizeof (LocationHybridPrivate)); - - signals[SERVICE_ENABLED] = g_signal_new ("service-enabled", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationHybridClass, enabled), - NULL, NULL, - location_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - signals[SERVICE_DISABLED] = g_signal_new ("service-disabled", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationHybridClass, disabled), - NULL, NULL, - location_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - signals[SERVICE_UPDATED] = g_signal_new ("service-updated", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationHybridClass, updated), - NULL, NULL, - location_VOID__UINT_POINTER_POINTER, - G_TYPE_NONE, 3, - G_TYPE_UINT, - G_TYPE_POINTER, - G_TYPE_POINTER); - - signals[ZONE_IN] = g_signal_new ("zone-in", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationHybridClass, zone_in), - NULL, NULL, - location_VOID__UINT_POINTER_POINTER, - G_TYPE_NONE, 3, - G_TYPE_UINT, - G_TYPE_POINTER, - G_TYPE_POINTER); - - signals[ZONE_OUT] = g_signal_new ("zone-out", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationHybridClass, zone_out), - NULL, NULL, - location_VOID__UINT_POINTER_POINTER, - G_TYPE_NONE, 3, - G_TYPE_UINT, - G_TYPE_POINTER, - G_TYPE_POINTER); - - properties[PROP_METHOD_TYPE] = g_param_spec_int ("method", - "method type", - "location method type name", - LOCATION_METHOD_HYBRID, - LOCATION_METHOD_HYBRID, - LOCATION_METHOD_HYBRID, - G_PARAM_READABLE); - - properties[PROP_LAST_POSITION] = g_param_spec_boxed ("last-position", - "hybrid last position prop", - "hybrid last position data", - LOCATION_TYPE_POSITION, - G_PARAM_READABLE); - - properties[PROP_UPDATE_INTERVAL] = g_param_spec_uint ("update-interval", - "update interval prop", - "update interval data", - LOCATION_UPDATE_INTERVAL_MIN, - LOCATION_UPDATE_INTERVAL_MAX, - LOCATION_UPDATE_INTERVAL_DEFAULT, - G_PARAM_READWRITE); - - properties[PROP_BOUNDARY] = g_param_spec_pointer ("boundary", - "hybrid boundary prop", - "hybrid boundary data", - G_PARAM_READWRITE); - - properties[PROP_REMOVAL_BOUNDARY] = g_param_spec_boxed("removal-boundary", - "hybrid removal boundary prop", - "hybrid removal boundary data", - LOCATION_TYPE_BOUNDARY, - G_PARAM_READWRITE); - - g_object_class_install_properties (gobject_class, - PROP_MAX, - properties); - -} diff --git a/location/location-hybrid.h b/location/location-hybrid.h deleted file mode 100644 index b7434c3..0000000 --- a/location/location-hybrid.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * libslp-location - * - * 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_HYBRID_H__ -#define __LOCATION_HYBRID_H__ - -#include - -/** - * @file location-hybrid.h - * @brief This file contains the internal definitions and structures related to Hybrid method. - * @addtogroup LocationInternal - * @{ - *@} - */ - -G_BEGIN_DECLS - -typedef struct _LocationHybrid LocationHybrid; -typedef struct _LocationHybridClass LocationHybridClass; - -#define LOCATION_TYPE_HYBRID (location_hybrid_get_type ()) -#define LOCATION_HYBRID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_HYBRID, LocationHybrid)) -#define LOCATION_IS_HYBRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_HYBRID)) -#define LOCATION_HYBRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_HYBRID, LocationHybridClass)) -#define LOCATION_IS_HYBRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_HYBRID)) -#define LOCATION_HYBRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_HYBRID, LocationHybridClass)) - -struct _LocationHybrid -{ - GObject parent_instance; -}; - -struct _LocationHybridClass -{ - GObjectClass parent_class; - - void (* enabled) (guint type); - void (* disabled) (guint type); - void (* updated) (guint type, gpointer data, gpointer accuracy); - void (* zone_in) (guint type, gpointer position, gpointer boundary); - void (* zone_out) (guint type, gpointer position, gpointer boundary); -}; - -GType location_hybrid_get_type (void); - -G_END_DECLS - -#endif diff --git a/location/location-ielement.c b/location/location-ielement.c deleted file mode 100644 index 3b17b01..0000000 --- a/location/location-ielement.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-log.h" -#include "location/location-ielement.h" - -static void -location_ielement_base_init (gpointer g_class) -{ - static gboolean is_initialized = FALSE; - - if (is_initialized){ - /* add properties and signals to the interface here */ - - is_initialized = TRUE; - } -} - -GType -location_ielement_get_type (void) -{ - static GType iface_type = 0; - - if (iface_type == 0) { - static const GTypeInfo info = { - sizeof (LocationIElementInterface), - location_ielement_base_init, /* base_init */ - NULL /* base_finalize */ - }; - - iface_type = g_type_register_static (G_TYPE_INTERFACE, "LocationIElement", - &info, 0); - } - - return iface_type; -} - -int -location_ielement_start (LocationIElement *self) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->start, LOCATION_ERROR_NOT_AVAILABLE); - return LOCATION_IELEMENT_GET_INTERFACE (self)->start (self); -} - -int -location_ielement_stop (LocationIElement *self) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->stop, LOCATION_ERROR_NOT_AVAILABLE); - return LOCATION_IELEMENT_GET_INTERFACE (self)->stop (self); -} - -int -location_ielement_get_position (LocationIElement *self, - LocationPosition **position, - LocationAccuracy **accuracy) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_position, LOCATION_ERROR_NOT_AVAILABLE); - - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_position (self, position, accuracy); -} - -int -location_ielement_get_velocity (LocationIElement *self, - LocationVelocity **velocity, - LocationAccuracy **accuracy) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_velocity, LOCATION_ERROR_NOT_AVAILABLE); - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_velocity (self, velocity, accuracy); -} - -int -location_ielement_get_geocode (LocationIElement *self, - const LocationAddress *address, - GList **position_list, - GList **accuracy_list) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (address, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode, LOCATION_ERROR_NOT_AVAILABLE); - - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode (self, address, position_list, accuracy_list); -} - -int -location_ielement_get_geocode_freeform (LocationIElement *self, - const gchar *address, - GList **position_list, - GList **accuracy_list) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (address, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode_freeform, LOCATION_ERROR_NOT_AVAILABLE); - - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode_freeform (self, address, position_list, accuracy_list); -} - -int -location_ielement_get_reversegeocode (LocationIElement *self, - const LocationPosition *position, - LocationAddress **address, - LocationAccuracy **accuracy) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (address, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_reversegeocode, LOCATION_ERROR_NOT_AVAILABLE); - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_reversegeocode (self, position, address, accuracy); -} - -int -location_ielement_get_geocode_async (LocationIElement *self, - const LocationAddress *address, - LocationPositionCB callback, - gpointer userdata) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (address, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (callback, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode_async, LOCATION_ERROR_NOT_AVAILABLE); - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode_async (self, address, callback, userdata); -} - -int -location_ielement_get_geocode_freeform_async (LocationIElement *self, - const gchar *address, - LocationPositionCB callback, - gpointer userdata) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (address, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (callback, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode_freeform_async, LOCATION_ERROR_NOT_AVAILABLE); - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode_freeform_async (self, address, callback, userdata); -} - -int -location_ielement_get_reversegeocode_async (LocationIElement *self, - const LocationPosition *position, - LocationAddressCB callback, - gpointer userdata) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (callback, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_reversegeocode_async, LOCATION_ERROR_NOT_AVAILABLE); - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_reversegeocode_async (self, position, callback, userdata); -} - -int -location_ielement_get_poi (LocationIElement *self, - gdouble radius, - const gchar* keyword, - LocationPOIInfo **poi_info) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (poi_info, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_poi, LOCATION_ERROR_NOT_AVAILABLE); - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_poi(self, radius, keyword, poi_info); -} - -int -location_ielement_get_poi_from_address (LocationIElement *self, - const LocationAddress* address, - gdouble radius, - const gchar *keyword, - LocationPOIInfo **poi_info) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (address, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (poi_info, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_poi_from_address, LOCATION_ERROR_NOT_AVAILABLE); - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_poi_from_address(self, address, radius, keyword, poi_info); -} - -int -location_ielement_get_poi_from_position (LocationIElement *self, - const LocationPosition *position, - gdouble radius, - const gchar *keyword, - LocationPOIInfo **poi_info) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (poi_info, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_poi_from_position, LOCATION_ERROR_NOT_AVAILABLE); - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_poi_from_position(self, position, radius, keyword, poi_info); -} - -int -location_ielement_get_poi_async (LocationIElement *self, - gdouble radius, - const gchar *keyword, - LocationPOICB callback, - gpointer userdata) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (callback, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_poi_async, LOCATION_ERROR_NOT_AVAILABLE); - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_poi_async (self, radius, keyword, callback, userdata); -} - -int -location_ielement_get_poi_from_address_async (LocationIElement *self, - const LocationAddress *address, - gdouble radius, - const gchar* keyword, - LocationPOICB callback, - gpointer userdata) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (address, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (callback, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_poi_from_address_async, LOCATION_ERROR_NOT_AVAILABLE); - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_poi_from_address_async (self, address, radius, keyword, callback, userdata); -} - - - -int location_ielement_get_poi_from_position_async (LocationIElement *self, - const LocationPosition* position, - gdouble radius, - const gchar* keyword, - LocationPOICB callback, - gpointer userdata) -{ - g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (callback, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_poi_from_position_async, LOCATION_ERROR_NOT_AVAILABLE); - return LOCATION_IELEMENT_GET_INTERFACE (self)->get_poi_from_position_async (self, position, radius, keyword, callback, userdata); -} diff --git a/location/location-ielement.h b/location/location-ielement.h deleted file mode 100644 index a283321..0000000 --- a/location/location-ielement.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * libslp-location - * - * 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_IELEMENT_H__ -#define __LOCATION_IELEMENT_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/** - * @file location-ielement.h - * @brief This file contains the internal definitions and structures related to location interface. - * @addtogroup LocationInternal - * @{ - *@} - */ - -G_BEGIN_DECLS - -enum { - SERVICE_ENABLED, - SERVICE_DISABLED, - SERVICE_UPDATED, - ZONE_IN, - ZONE_OUT, - LAST_SIGNAL -}; - -#define LOCATION_TYPE_IELEMENT (location_ielement_get_type ()) -#define LOCATION_IELEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_IELEMENT, LocationIElement)) -#define LOCATION_IS_IELEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_IELEMENT)) -#define LOCATION_IELEMENT_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), LOCATION_TYPE_IELEMENT, LocationIElementInterface)) - -typedef struct _LocationIElement LocationIElement; -typedef struct _LocationIElementInterface LocationIElementInterface; - -typedef int (*TYPE_START_FUNC)(LocationIElement *self); -typedef int (*TYPE_STOP_FUNC) (LocationIElement *self); -typedef int (*TYPE_GET_POSITION)(LocationIElement *self, LocationPosition **position, LocationAccuracy **accuracy); -typedef int (*TYPE_GET_VELOCITY)(LocationIElement *self, LocationVelocity **velocity, LocationAccuracy **accuracy); -typedef int (*TYPE_GET_GEOCODE)(LocationIElement *self, const LocationAddress *address, GList **position_list, GList **accuracy_list); -typedef int (*TYPE_GET_GEOCODE_FREEFORM)(LocationIElement *self, const gchar *address, GList **position_list, GList **accuracy_list); -typedef int (*TYPE_GET_REVERSEGEOCODE)(LocationIElement *self, const LocationPosition *position, LocationAddress **address, LocationAccuracy **accuracy); -typedef int (*TYPE_GET_GEOCODE_ASYNC)(LocationIElement *self, const LocationAddress *address, LocationPositionCB callback, gpointer userdata); -typedef int (*TYPE_GET_GEOCODE_FREEFORM_ASYNC)(LocationIElement *self, const gchar *address, LocationPositionCB callback, gpointer userdata); -typedef int (*TYPE_GET_REVERSEGEOCODE_ASYNC)(LocationIElement *self, const LocationPosition *position, LocationAddressCB callback, gpointer userdata); -typedef int (*TYPE_GET_POI)(LocationIElement *self, gdouble radius, const gchar* keyword, LocationPOIInfo** poi); -typedef int (*TYPE_GET_POI_ASYNC)(LocationIElement *self, gdouble radius, const gchar* keyword, LocationPOICB callback, gpointer userdata); -typedef int (*TYPE_GET_POI_FROM_ADDRESS)(LocationIElement *self, const LocationAddress* address, gdouble radius, const gchar* keyword, LocationPOIInfo** poi); -typedef int (*TYPE_GET_POI_FROM_POSITION)(LocationIElement *self, const LocationPosition* position, gdouble radius, const gchar* keyword, LocationPOIInfo** poi); -typedef int (*TYPE_GET_POI_FROM_ADDRESS_ASYNC)(LocationIElement *self, const LocationAddress* address, gdouble radius, const gchar* keyword, LocationPOICB callback, gpointer userdata); -typedef int (*TYPE_GET_POI_FROM_POSITION_ASYNC)(LocationIElement *self, const LocationPosition* position, gdouble radius, const gchar* keyword, LocationPOICB callback, gpointer userdata); - -struct _LocationIElementInterface -{ - GTypeInterface parent_iface; - - TYPE_START_FUNC start; - TYPE_STOP_FUNC stop; - TYPE_GET_POSITION get_position; - TYPE_GET_VELOCITY get_velocity; - TYPE_GET_GEOCODE get_geocode; - TYPE_GET_GEOCODE_FREEFORM get_geocode_freeform; - TYPE_GET_REVERSEGEOCODE get_reversegeocode; - TYPE_GET_GEOCODE_ASYNC get_geocode_async; - TYPE_GET_GEOCODE_FREEFORM_ASYNC get_geocode_freeform_async; - TYPE_GET_REVERSEGEOCODE_ASYNC get_reversegeocode_async; - TYPE_GET_POI get_poi; - TYPE_GET_POI_FROM_ADDRESS get_poi_from_address; - TYPE_GET_POI_FROM_POSITION get_poi_from_position; - TYPE_GET_POI_ASYNC get_poi_async; - TYPE_GET_POI_FROM_ADDRESS_ASYNC get_poi_from_address_async; - TYPE_GET_POI_FROM_POSITION_ASYNC get_poi_from_position_async; -}; - -GType location_ielement_get_type (void); - -int location_ielement_start (LocationIElement *self); -int location_ielement_stop(LocationIElement *self); -int location_ielement_get_position (LocationIElement *self, LocationPosition **position, LocationAccuracy **accuracy); -int location_ielement_get_velocity (LocationIElement *self, LocationVelocity **velocity, LocationAccuracy **accuracy); -int location_ielement_get_geocode (LocationIElement *self, const LocationAddress *address, GList **position_list, GList **accuracy_list); -int location_ielement_get_geocode_freeform (LocationIElement *self, const gchar *address, GList **position_list, GList **accuracy_list); -int location_ielement_get_reversegeocode (LocationIElement *self, const LocationPosition *position, LocationAddress **address, LocationAccuracy **accuracy); -int location_ielement_get_geocode_async (LocationIElement *self, const LocationAddress *address, LocationPositionCB callback, gpointer userdata); -int location_ielement_get_geocode_freeform_async (LocationIElement *self, const gchar *address, LocationPositionCB callback, gpointer userdata); -int location_ielement_get_reversegeocode_async (LocationIElement *self, const LocationPosition *position, LocationAddressCB callback, gpointer userdata); -int location_ielement_get_poi(LocationIElement *self, gdouble radius, const gchar *keyword, LocationPOIInfo **poi); -int location_ielement_get_poi_from_address(LocationIElement *self, const LocationAddress *address, gdouble radius, const gchar *keyword, LocationPOIInfo **poi); -int location_ielement_get_poi_from_position (LocationIElement *self, const LocationPosition *position, gdouble radius, const gchar *keyword, LocationPOIInfo **poi); -int location_ielement_get_poi_async(LocationIElement *self, gdouble radius, const gchar *keyword, LocationPOICB callback, gpointer userdata); -int location_ielement_get_poi_from_address_async(LocationIElement *self, const LocationAddress *address, gdouble radius, const gchar *keyword, LocationPOICB callback, gpointer userdata); -int location_ielement_get_poi_from_position_async (LocationIElement *self, const LocationPosition *position, gdouble radius, const gchar *keyword, LocationPOICB callback, gpointer userdata); - -G_END_DECLS - -#endif diff --git a/location/location-ips.c b/location/location-ips.c deleted file mode 100644 index 0412c01..0000000 --- a/location/location-ips.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-setting.h" -#include "location/location-log.h" - -#include "location/location-module-internal.h" - -#include "location/location-ips.h" -#include "location/location-marshal.h" -#include "location/location-ielement.h" - -typedef struct _LocationIpsPrivate { - LocationIpsMod *mod; - LocationPosition *pos; - LocationAccuracy *acc; -} LocationIpsPrivate; - -enum { - PROP_0, - PROP_METHOD_TYPE, - PROP_LAST_POSITION -}; - -#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_IPS, LocationIpsPrivate)) - -static void location_ielement_interface_init (LocationIElementInterface *iface); - -G_DEFINE_TYPE_WITH_CODE (LocationIps, location_ips, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, - location_ielement_interface_init)); - -static void -location_ips_dispose (GObject *gobject) -{ - LOCATION_LOGD("location_ips_dispose"); - G_OBJECT_CLASS (location_ips_parent_class)->dispose (gobject); -} - -static void -location_ips_finalize (GObject *gobject) -{ - LOCATION_LOGD("location_ips_finalize"); - LocationIpsPrivate* priv = GET_PRIVATE(gobject); - module_free(priv->mod, "ips"); - priv->mod = NULL; - - G_OBJECT_CLASS (location_ips_parent_class)->finalize (gobject); -} - -static void -location_ips_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - LocationIpsPrivate *priv = GET_PRIVATE (object); - - switch (property_id){ - case PROP_METHOD_TYPE: - g_value_set_int(value, LOCATION_METHOD_IPS); - break; - case PROP_LAST_POSITION:{ - g_value_set_boxed (value, priv->pos); - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static int -location_ips_get_position (LocationIps *self, - LocationPosition **position, - LocationAccuracy **accuracy) -{ - LOCATION_LOGD("location_ips_get_position"); - - LocationIpsPrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - setting_retval_if_fail(GPS_ENABLED); - setting_retval_if_fail(NETWORK_ENABLED); - - LocModIpsOps ops = priv->mod->ops; - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (ops.get_position, LOCATION_ERROR_NOT_AVAILABLE); - int ret = ops.get_position(priv->mod->handler, position, accuracy); - if (priv->pos) location_position_free(priv->pos); - if (priv->acc) location_accuracy_free(priv->acc); - priv->pos = location_position_copy(*position); - priv->acc = location_accuracy_copy(*accuracy); - return ret; -} - -static void -location_ielement_interface_init (LocationIElementInterface *iface) -{ - iface->get_position = (TYPE_GET_POSITION)location_ips_get_position; -} - -static void -location_ips_init (LocationIps *self) -{ - LOCATION_LOGD("location_ips_init"); - LocationIpsPrivate* priv = GET_PRIVATE(self); - - priv->mod = (LocationIpsMod*)module_new("ips"); - if(!priv->mod) LOCATION_LOGW("module loading failed"); - - priv->pos = NULL; - priv->acc = NULL; -} - -static void -location_ips_class_init (LocationIpsClass *klass) -{ - LOCATION_LOGD("location_ips_class_init"); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GParamSpec *pspec; - - gobject_class->get_property = location_ips_get_property; - - gobject_class->dispose = location_ips_dispose; - gobject_class->finalize = location_ips_finalize; - - g_type_class_add_private (klass, sizeof (LocationIpsPrivate)); - - pspec = g_param_spec_int ("method", - "method type", - "location method type name", - LOCATION_METHOD_IPS, - LOCATION_METHOD_IPS, - LOCATION_METHOD_IPS, - G_PARAM_READABLE); - g_object_class_install_property (gobject_class, - PROP_METHOD_TYPE, - pspec); - - pspec = g_param_spec_boxed ("last-position", - "ips last position prop", - "ips last position data", - LOCATION_TYPE_POSITION, - G_PARAM_READABLE); - g_object_class_install_property (gobject_class, - PROP_LAST_POSITION, - pspec); -} - diff --git a/location/location-ips.h b/location/location-ips.h deleted file mode 100644 index b2523b6..0000000 --- a/location/location-ips.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * libslp-location - * - * 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_IPS_H__ -#define __LOCATION_IPS_H__ - -#include - -/** - * @file location-ips.h - * @brief This file contains the internal definitions and structures related to IPS. - * @addtogroup LocationInternal - * @{ - * @} - */ - -G_BEGIN_DECLS - -#define LOCATION_TYPE_IPS (location_ips_get_type ()) -#define LOCATION_IPS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_IPS, LocationIps)) -#define LOCATION_IS_IPS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_IPS)) -#define LOCATION_IPS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_IPS, LocationIpsClass)) -#define LOCATION_IS_IPS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_IPS)) -#define LOCATION_IPS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_IPS, LocationIpsClass)) - -typedef struct _LocationIps LocationIps; -typedef struct _LocationIpsClass LocationIpsClass; - -struct _LocationIps -{ - GObject parent_instance; -}; - -struct _LocationIpsClass -{ - GObjectClass parent_class; -}; - -GType location_ips_get_type (void); - -G_END_DECLS - -#endif diff --git a/location/location-log.h b/location/location-log.h deleted file mode 100644 index 0f9f58a..0000000 --- a/location/location-log.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * libslp-location - * - * 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__ - -/** - * @file location-log.h - * @brief This file contains macro functions for logging. - * @addtogroup LocationInternal - * @{ - * @} - */ - -#define TAG_LOCATION "location" - -#ifdef LOCATION_DLOG_DEBUG // if debug mode, show filename & line number -#include -#define LOCATION_LOGD(fmt,args...) SLOG(LOG_DEBUG, TAG_LOCATION, "[%-15s:%-4d:%-27s]"fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##args) -#define LOCATION_LOGW(fmt,args...) SLOG(LOG_WARN, TAG_LOCATION, "[%-15s:%-4d:%-27s]"fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##args) -#define LOCATION_LOGI(fmt,args...) SLOG(LOG_INFO, TAG_LOCATION, "[%-15s:%-4d:%-27s]"fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##args) -#define LOCATION_LOGE(fmt,args...) SLOG(LOG_ERROR, TAG_LOCATION, "[%-15s:%-4d:%-27s]"fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##args) -#elif LOCATION_DLOG_RELEASE // if release mode, do not show filename & line number -#include -#define LOCATION_LOGD(fmt,args...) SLOG(LOG_DEBUG, TAG_LOCATION, fmt"\n", ##args) -#define LOCATION_LOGW(fmt,args...) SLOG(LOG_WARN, TAG_LOCATION, fmt"\n", ##args) -#define LOCATION_LOGI(fmt,args...) SLOG(LOG_INFO, TAG_LOCATION, fmt"\n", ##args) -#define LOCATION_LOGE(fmt,args...) SLOG(LOG_ERROR, TAG_LOCATION, fmt"\n", ##args) -#else // if do not use dlog -#define LOCATION_LOGD(...) g_debug(__VA_ARGS__); -#define LOCATION_LOGW(...) g_warning(__VA_ARGS__); -#define LOCATION_LOGI(...) g_message(__VA_ARGS__); -#define LOCATION_LOGE(...) g_error(__VA_ARGS__); -#endif - -#endif diff --git a/location/location-marshal.list b/location/location-marshal.list deleted file mode 100644 index 069387a..0000000 --- a/location/location-marshal.list +++ /dev/null @@ -1,2 +0,0 @@ -VOID:UINT,POINTER,POINTER -VOID:UINT diff --git a/location/location-module-internal.c b/location/location-module-internal.c deleted file mode 100644 index 1c9a19b..0000000 --- a/location/location-module-internal.c +++ /dev/null @@ -1,388 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "location/location-module-internal.h" -#include "location/location-log.h" - -#define MAX_MODULE_INDEX 10 -const char* MODULE_PATH_PREFIX = "/usr/lib/location/module"; - -static GMod* -gmod_new (const char* module_name, gboolean is_resident) -{ - if(!module_name) - return NULL; - - GMod* gmod = g_new0(GMod, 1); - gmod->name = g_strdup(module_name); - if(!gmod->name) { - g_free(gmod); - return NULL; - } - gmod->path = g_module_build_path (MODULE_PATH_PREFIX, gmod->name); - if(!gmod->path){ - g_free(gmod->name); - g_free(gmod); - gmod->name = NULL; - return NULL; - } - gmod->module = g_module_open(gmod->path, G_MODULE_BIND_LAZY); - if(!gmod->module){ - g_free(gmod->name); - g_free(gmod->path); - g_free(gmod); - gmod->name = NULL; - gmod->path = NULL; - - return NULL; - } - if(is_resident) - g_module_make_resident(gmod->module); - - return gmod; -} - -static void -gmod_free (GMod* gmod) -{ - if(gmod->name) - g_free(gmod->name); - if(gmod->path) - g_free(gmod->path); - if(gmod->module) - g_module_close(gmod->module); - g_free(gmod); -} - -static gboolean -gmod_find_sym (GMod* gmod, - gpointer* init_func, gpointer* shutdown_func) -{ - char sym[256]; - g_stpcpy(sym, "init"); - if ( !g_module_symbol (gmod->module, sym, init_func) ){ - LOCATION_LOGW("symbol not found: %s", sym); - return FALSE; - } - g_stpcpy(sym, "shutdown"); - if ( !g_module_symbol (gmod->module, sym, shutdown_func) ){ - LOCATION_LOGW("symbol not found: %s", sym); - return FALSE; - } - return TRUE; -} - -static gpointer -mod_new (const char* module_name) -{ - gpointer ret_mod = NULL; - if(!module_name) - return NULL; - - GMod* gmod = NULL; - gpointer init = NULL; - gpointer shutdown = NULL; - gmod = gmod_new(module_name, TRUE); - if(!gmod){ - LOCATION_LOGW("module(%s) new failed", module_name); - return NULL; - } - if( !gmod_find_sym(gmod, &init, &shutdown) ){ - LOCATION_LOGW("symbol (init, shutdown) finding failed"); - gmod_free(gmod); - return NULL; - } - if(!init || !shutdown){ - LOCATION_LOGW("init, shutdown symbol is NULL"); - gmod_free(gmod); - return NULL; - } - if(g_str_has_prefix(module_name, "geocode")){ - LocationGeoMod* _mod = g_new0(LocationGeoMod, 1); - _mod->gmod = gmod; - _mod->init = init; - _mod->shutdown= shutdown; - _mod->handler= _mod->init(&(_mod->ops)); - if(!_mod->handler){ - LOCATION_LOGW("module init failed"); - gmod_free(_mod->gmod); - ret_mod = NULL; - }else - ret_mod = (gpointer)_mod; - }else if(g_str_has_prefix(module_name, "gps")){ - LocationGpsMod* _mod = g_new0(LocationGpsMod, 1); - _mod->gmod = gmod; - _mod->init = init; - _mod->shutdown= shutdown; - _mod->handler= _mod->init(&(_mod->ops)); - if(!_mod->handler){ - LOCATION_LOGW("module init failed"); - gmod_free(_mod->gmod); - ret_mod = NULL; - }else - ret_mod = (gpointer)_mod; - }else if(g_str_has_prefix(module_name, "wps")){ - LocationWpsMod* _mod = g_new0(LocationWpsMod, 1); - _mod->gmod = gmod; - _mod->init = init; - _mod->shutdown= shutdown; - _mod->handler= _mod->init(&(_mod->ops)); - if(!_mod->handler){ - LOCATION_LOGW("module init failed"); - gmod_free(_mod->gmod); - ret_mod = NULL; - }else - ret_mod = (gpointer)_mod; - }else if(g_str_has_prefix(module_name, "cps")){ - LocationCpsMod* _mod = g_new0(LocationCpsMod, 1); - _mod->gmod = gmod; - _mod->init = init; - _mod->shutdown= shutdown; - _mod->handler= _mod->init(&(_mod->ops)); - if(!_mod->handler){ - LOCATION_LOGW("module init failed"); - gmod_free(_mod->gmod); - ret_mod = NULL; - }else - ret_mod = (gpointer)_mod; - }else if(g_str_has_prefix(module_name, "ips")){ - LocationIpsMod* _mod = g_new0(LocationIpsMod, 1); - _mod->gmod = gmod; - _mod->init = init; - _mod->shutdown= shutdown; - _mod->handler= _mod->init(&(_mod->ops)); - if(!_mod->handler){ - LOCATION_LOGW("module init failed"); - gmod_free(_mod->gmod); - ret_mod = NULL; - }else - ret_mod = (gpointer)_mod; - }else if(g_str_has_prefix(module_name, "sps")){ - LocationSpsMod* _mod = g_new0(LocationSpsMod, 1); - _mod->gmod = gmod; - _mod->init = init; - _mod->shutdown= shutdown; - _mod->handler= _mod->init(&(_mod->ops)); - if(!_mod->handler){ - LOCATION_LOGW("module init failed"); - gmod_free(_mod->gmod); - ret_mod = NULL; - }else - ret_mod = (gpointer)_mod; - }else if(g_str_has_prefix(module_name, "poi")){ - LocationPoiMod* _mod = g_new0(LocationPoiMod, 1); - _mod->gmod = gmod; - _mod->init = init; - _mod->shutdown= shutdown; - _mod->handler= _mod->init(&(_mod->ops)); - if(!_mod->handler){ - LOCATION_LOGW("module init failed"); - gmod_free(_mod->gmod); - ret_mod = NULL; - }else - ret_mod = (gpointer)_mod; - }else{ - LOCATION_LOGW("module name (%s) is wrong", module_name); - ret_mod = NULL; - } - return ret_mod; -} - - -static void -mod_free (gpointer mod, - const char* module_name) -{ - if(!mod || !module_name) - return; - - if(0 == g_strcmp0(module_name, "geocode")){ - LocationGeoMod* _mod = (LocationGeoMod*)mod; - if(_mod->shutdown && _mod->handler){ - _mod->shutdown(_mod->handler); - } - _mod->handler = NULL; - _mod->init = NULL; - _mod->shutdown= NULL; - gmod_free(_mod->gmod); - _mod->gmod = NULL; - }else if(0 == g_strcmp0(module_name, "gps")){ - LocationGpsMod* _mod = (LocationGpsMod*)mod; - if(_mod->shutdown && _mod->handler){ - _mod->shutdown(_mod->handler); - } - _mod->handler = NULL; - _mod->init = NULL; - _mod->shutdown= NULL; - gmod_free(_mod->gmod); - _mod->gmod = NULL; - }else if(0 == g_strcmp0(module_name, "wps")){ - LocationWpsMod* _mod = (LocationWpsMod*)mod; - if(_mod->shutdown && _mod->handler){ - _mod->shutdown(_mod->handler); - } - _mod->handler = NULL; - _mod->init = NULL; - _mod->shutdown= NULL; - gmod_free(_mod->gmod); - _mod->gmod = NULL; - }else if(0 == g_strcmp0(module_name, "cps")){ - LocationCpsMod* _mod = (LocationCpsMod*)mod; - if(_mod->shutdown && _mod->handler){ - _mod->shutdown(_mod->handler); - } - _mod->handler = NULL; - _mod->init = NULL; - _mod->shutdown= NULL; - gmod_free(_mod->gmod); - _mod->gmod = NULL; - }else if(0 == g_strcmp0(module_name, "ips")){ - LocationIpsMod* _mod = (LocationIpsMod*)mod; - if(_mod->shutdown && _mod->handler){ - _mod->shutdown(_mod->handler); - } - _mod->handler = NULL; - _mod->init = NULL; - _mod->shutdown= NULL; - gmod_free(_mod->gmod); - _mod->gmod = NULL; - }else if(0 == g_strcmp0(module_name, "sps")){ - LocationSpsMod* _mod = (LocationSpsMod*)mod; - if(_mod->shutdown && _mod->handler){ - _mod->shutdown(_mod->handler); - } - _mod->handler = NULL; - _mod->init = NULL; - _mod->shutdown= NULL; - gmod_free(_mod->gmod); - _mod->gmod = NULL; - }else if(0 == g_strcmp0(module_name, "poi")){ - LocationPoiMod* _mod = (LocationPoiMod*)mod; - if(_mod->shutdown && _mod->handler){ - _mod->shutdown(_mod->handler); - } - _mod->handler = NULL; - _mod->init = NULL; - _mod->shutdown= NULL; - gmod_free(_mod->gmod); - _mod->gmod = NULL; - }else - LOCATION_LOGW("module name (%s) is wrong", module_name); - - g_free(mod); -} - -static gboolean -mod_is_supported(const char *module_name) -{ - GMod * gmod = NULL; - gmod = gmod_new(module_name, FALSE); - if(!gmod) { - return FALSE; - } - gmod_free(gmod); - - return TRUE; -} - -gboolean module_init (void) -{ - if (!g_module_supported()) { - LOCATION_LOGW("module is not supported"); - return FALSE; - } - return TRUE; -} - -void -module_free (gpointer mod, - const char* module_name) -{ - if(!mod || !module_name) - return; - mod_free(mod, module_name); -} - -gpointer -module_new (const char* module_name) -{ - if(!module_name) - return NULL; - int index = 0; - char name[256]; - - gpointer mod = NULL; - for(index = -1 ; index < MAX_MODULE_INDEX ; index++){ - if(index >= 0){ - if( 0 >= g_snprintf(name, 256, "%s%d", module_name, index)){ - LOCATION_LOGW("module name(%s) is wrong", name); - continue; - } - }else{ - if( 0 >= g_snprintf(name, 256, "%s", module_name)){ - LOCATION_LOGW("module name(%s) is wrong", name); - continue; - } - } - mod = mod_new(name); - if(mod){ - LOCATION_LOGW("module (%s) open success", name); - break; - } - LOCATION_LOGW("module (%s) open failed", name); - } - return mod; -} - -gboolean -module_is_supported(const char *module_name) -{ - if(!module_name) - return FALSE; - - int index = 0; - gboolean ret = FALSE; - gboolean found = FALSE; - - char name[256] = {0, }; - - for(index = -1 ; index < MAX_MODULE_INDEX ; index++){ - if(index >= 0){ - g_snprintf(name, 256, "%s%d", module_name, index); - }else{ - g_snprintf(name, 256, "%s", module_name); - } - - ret = mod_is_supported(name); - if(ret == TRUE) { - found = TRUE; - LOCATION_LOGW("module name(%s) is found", name); - break; - } - } - - return found; -} diff --git a/location/location-module-internal.h b/location/location-module-internal.h deleted file mode 100644 index 868e743..0000000 --- a/location/location-module-internal.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * libslp-location - * - * 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_MODULE_INTERNAL_H__ -#define __LOCATION_MODULE_INTERNAL_H__ - -#include -#include "location/location-module.h" - -/** - * @file location-module-internal.h - * @brief This file contains the internal definitions and structures related to module. - * @addtogroup LocationInternal - * @{ - * @} - */ - -typedef struct{ - GModule* module; - char* name; - char* path; -} GMod; - -typedef struct{ - GMod* gmod; - gpointer handler; - gpointer (*init)(LocModGeoOps* ops); - void (*shutdown)(gpointer handle); - LocModGeoOps ops; -} LocationGeoMod; - -typedef struct{ - GMod* gmod; - gpointer handler; - gpointer (*init)(LocModPoiOps* ops); - void (*shutdown)(gpointer handle); - LocModPoiOps ops; -} LocationPoiMod; - -typedef struct{ - GMod* gmod; - gpointer handler; - gpointer (*init)(LocModGpsOps* ops); - void (*shutdown)(gpointer handle); - LocModGpsOps ops; -} LocationGpsMod; - -typedef struct{ - GMod* gmod; - gpointer handler; - gpointer (*init)(LocModWpsOps* ops); - void (*shutdown)(gpointer handle); - LocModWpsOps ops; -} LocationWpsMod; - -typedef struct{ - GMod* gmod; - gpointer handler; - gpointer (*init)(LocModCpsOps* ops); - void (*shutdown)(gpointer handle); - LocModCpsOps ops; -} LocationCpsMod; - -typedef struct{ - GMod* gmod; - gpointer handler; - gpointer (*init)(LocModIpsOps* ops); - void (*shutdown)(gpointer handle); - LocModIpsOps ops; -} LocationIpsMod; - -typedef struct{ - GMod* gmod; - gpointer handler; - gpointer (*init)(LocModSpsOps* ops); - void (*shutdown)(gpointer handle); - LocModSpsOps ops; -} LocationSpsMod; - -G_BEGIN_DECLS - -gboolean module_init(void); -gpointer module_new(const char* module_name); -void module_free(gpointer mod, const char* module_name); - -gboolean module_is_supported(const char *module_name); - -G_END_DECLS - -#endif diff --git a/location/location-module.h b/location/location-module.h deleted file mode 100644 index a4469af..0000000 --- a/location/location-module.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * libslp-location - * - * 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_MODULE_H__ -#define __LOCATION_MODULE_H__ - -#include -#include -#include -#include -#include -#include -#include -#include - -G_BEGIN_DECLS - -/** - * @file location-module.h - * @brief This file contains the structure and enumeration for location plug-in development. - */ - -/** - * @addtogroup LocationFW - * @{ - * @defgroup LocationModules Location Moduels - * @brief This sub module provides the definitions and structrues for 3rd party plugin modules. - * @addtogroup LocationModules - * @{ - */ - -/** - * @brief This represents APIs declared in a geocode plug-in for location geocode modules. - */ -typedef struct{ - int (*get_service_name)(gpointer handle, gchar **servicename); ///< This is used for getting a service name from a plug-in. - int (*get_geocode)(gpointer handle, const LocationAddress *address, GList **position_list, GList **accuracy_list); ///< This is used for getting a geocode from a plug-in. - int (*get_geocode_freetext)(gpointer handle, const gchar *address, GList **position_list, GList **accuracy_list); ///< This is used for getting a geocode by using a free-fromed address from a plug-in. - int (*get_reverse_geocode)(gpointer handle, const LocationPosition *position, LocationAddress **address, LocationAccuracy **accuracy); ///< This is used for getting a reverse geocode from a plug-in. - int (*get_geocode_async)(gpointer handle, const LocationAddress *address, LocationPositionCB callback, gpointer userdata); ///< This is used for getting a geocode from a plug-in asynchronously. - int (*get_geocode_freetext_async)(gpointer handle, const gchar *address, LocationPositionCB callback, gpointer userdata); ///< This is used for getting a geocode by using a free-fromed address from a plug-in asynchronously. - int (*get_reverse_geocode_async)(gpointer handle, const LocationPosition *position, LocationAddressCB callback, gpointer userdata); ///< This is used for getting a reverse geocode from a plug-in asynchronously. -} LocModGeoOps; - -/** - * @brief This represents APIs declared in a POI plug-in for location POI modules. - */ -typedef struct{ - int (*get_service_name)(gpointer handle, gchar** servicename); ///< This is used for getting a service name from a plug-in. - int (*get_poi)(gpointer handle, gdouble radius, const gchar* keyword, LocationPOIInfo **poi); ///< This is used for getting a POI from a plug-in. - int (*get_poi_from_address)(gpointer handle, const LocationAddress *address, gdouble radius, const gchar* keyword, LocationPOIInfo **poi); ///< This is used for getting a POI by using a address from a plug-in. - int (*get_poi_from_position)(gpointer handle, const LocationPosition *position, gdouble radius, const gchar* keyword, LocationPOIInfo **poi); ///< This is used for getting a POI by using a position from a plug-in. - int (*get_poi_async)(gpointer handle, gdouble radius, const gchar* keyword, LocationPOICB callback, gpointer userdata); ///< This is used for getting a POI from a plug-in asynchronously. - int (*get_poi_from_address_async)(gpointer handle, const LocationAddress *address, gdouble radius, const gchar* keyword, LocationPOICB callback, gpointer userdata); ///< This is used for getting a POI by using a address from a plug-in asynchronously. - int (*get_poi_from_position_async)(gpointer handle, const LocationPosition *position, gdouble radius, const gchar* keyword, LocationPOICB callback, gpointer userdata); ///< This is used for getting a POI by using a position from a plug-in asynchronously. -} LocModPoiOps; - -/** -* @brief This represents a enabled/disabled callback function for a plug-in. -*/ -typedef void (*LocModStatusCB)(gboolean enabled, LocationStatus status, gpointer userdata); - -/** - * @brief This represents a position callback function for a plug-in. - */ -typedef void (*LocModPositionCB) (gboolean enabled, LocationPosition *position, LocationAccuracy *accuracy, gpointer userdata); - -/** - * @brief This represents a velocity callback function for a plug-in. - */ -typedef void (*LocModVelocityCB) (gboolean enabled, LocationVelocity *velocity, LocationAccuracy *accuracy, gpointer userdata); - -/** - * @brief This represents APIs declared in a GPS plug-in for location GPS modules. - */ -typedef struct{ - int (*start)(gpointer handle, LocModStatusCB status_cb, LocModPositionCB pos_cb, LocModVelocityCB vel_cb, gpointer userdata); ///< This is used for starting a GPS device from a plug-in. #LocModStatusCB, #LocModPositionCB, and #LocModVelocityCB are given from a location framework to a plug-in for asynchronous signaling. - int (*stop)(gpointer handle); ///< This is used for stopping a GPS device name from a plug-in. - int (*get_position)(gpointer handle, LocationPosition **position, LocationAccuracy **accuracy); ///< This is used for getting a position from a plug-in. - int (*get_velocity)(gpointer handle, LocationVelocity **velocity, LocationAccuracy **accuracy); ///< This is used for getting a velocity from a plug-in. - int (*get_nmea)(gpointer handle, gchar** nmea_data); ///< This is used for getting a nmea string from a plug-in. - int (*get_satellite)(gpointer handle, LocationSatellite **satellite); ///< This is used for getting a satellite information from a plug-in. - int (*set_devname)(gpointer handle, const gchar *devname); ///< This is used for setting a device name from a plug-in. - int (*get_devname)(gpointer handle, gchar **devname); ///< This is used for getting a device name from a plug-in. -} LocModGpsOps; - -/** - * @brief This represents APIs declared in a WPS plug-in for location WPS modules. - */ -typedef struct{ - int (*start)(gpointer handle, LocModStatusCB status_cb, LocModPositionCB pos_cb, LocModVelocityCB vel_cb, gpointer userdata); ///< This is used for starting a WPS service from a plug-in. #LocModStatusCB, #LocModPositionCB, and #LocModVelocityCB are given from a location framework to a plug-in for asynchronous signaling. - int (*stop)(gpointer handle); ///< This is used for stopping a WPS service from a plug-in. - int (*get_position)(gpointer handle, LocationPosition **position, LocationAccuracy **accuracy); ///< This is used for getting a position from a plug-in. - int (*get_velocity)(gpointer handle, LocationVelocity **velocity, LocationAccuracy **accuracy); ///< This is used for getting a velocity from a plug-in. -} LocModWpsOps; - -/** - * @brief This represents APIs declared in a SPS plug-in for location SPS modules. - */ -typedef struct{ - int (*start)(gpointer handle, LocModStatusCB status_cb, LocModPositionCB pos_cb, LocModVelocityCB vel_cb, gpointer userdata); ///< This is used for starting a SPS service from a plug-in. #LocModStatusCB, #LocModPositionCB and #LocModVelocityCB are given from a location framework to a plug-in for asynchronous signaling. - int (*stop)(gpointer handle); ///< This is used for stopping a SPS service from a plug-in. - int (*get_position)(gpointer handle, LocationPosition **position, LocationAccuracy **accuracy); ///< This is used for getting a position from a plug-in. - int (*get_velocity)(gpointer handle, LocationVelocity **velocity, LocationAccuracy **accuracy); ///< This is used for getting a velocity from a plug-in. - int (*update_data)(gpointer handle, const LocationPosition *position, const LocationVelocity *velocity, const LocationAccuracy *accuracy, const LocationSatellite *satellite); ///< This is used for updating compensated position/velocity data for a plug-in. -} LocModSpsOps; - -/** - * @brief This represents APIs declared in a IPS plug-in for location IPS modules. - */ -typedef struct{ - int (*get_position)(gpointer handle, LocationPosition **position, LocationAccuracy **accuracy); ///< This is used for getting a position from a plug-in. -} LocModIpsOps; - -/** - * @brief This represents APIs declared in a CPS plug-in for location CPS modules. - */ -typedef struct{ - int (*get_position)(gpointer handle, LocationPosition **position, LocationAccuracy **accuracy); ///< This is used for getting a position from a plug-in. -} LocModCpsOps; - -/** - * @brief This is used for exported APIs in a plug-in for a location framework. - */ -#define LOCATION_MODULE_API __attribute__((visibility("default"))) G_MODULE_EXPORT - -/** - * @} @} - */ -G_END_DECLS - -#endif diff --git a/location/location-poi-info.c b/location/location-poi-info.c deleted file mode 100644 index 9429f5f..0000000 --- a/location/location-poi-info.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-poi-info.h" -#include "location/location-log.h" - -GType -location_poiinfo_get_type (void) -{ - static volatile gsize type_volatile = 0; - if(g_once_init_enter(&type_volatile)) { - GType type = g_boxed_type_register_static ( - g_intern_static_string ("LocationPOIInfo"), - (GBoxedCopyFunc) location_poiinfo_copy, - (GBoxedFreeFunc) location_poiinfo_free); - g_once_init_leave(&type_volatile, type); - } - return type_volatile; -} - -GHashTable* -location_poiinfo_detail_properties_new (void) -{ - return g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); -} - -void -location_poiinfo_detail_properties_free (GHashTable* properties) -{ - g_return_if_fail(properties); - g_hash_table_destroy(properties); -} - -gboolean -location_poiinfo_detail_properties_insert (GHashTable* properties, - const gchar* key, - const gchar* value) -{ - g_return_val_if_fail(properties, FALSE); - g_hash_table_insert (properties, g_strdup(key), g_strdup(value)); - return TRUE; -} - -static void -copy_poiinfo_detail_properties (gchar *key, - gchar *value, - GHashTable *properties) -{ - location_poiinfo_detail_properties_insert(properties, key, value); -} - -GHashTable * -location_poiinfo_detail_properties_copy (const GHashTable *properties) -{ - g_return_val_if_fail(properties, NULL); - - GHashTable *dup = location_poiinfo_detail_properties_new (); - g_hash_table_foreach (properties, - (GHFunc)copy_poiinfo_detail_properties, - dup); - return dup; -} - -LocationPOIInfo * -location_poiinfo_new (int num_of_poi) -{ - LocationPOIInfo* poi_info = g_slice_new0(LocationPOIInfo); - poi_info->num_of_poi = num_of_poi; - poi_info->poi_detail = g_new0(LocationPOIDetail, poi_info->num_of_poi); - return poi_info; -} - -void -location_poiinfo_free (LocationPOIInfo* poi_info) -{ - g_return_if_fail(poi_info); - if(poi_info->poi_detail){ - int i = 0; - for (i = 0 ; i < poi_info->num_of_poi ; i++) { - g_free(poi_info->poi_detail[i].name); - g_free(poi_info->poi_detail[i].type); - location_address_free(poi_info->poi_detail[i].address); - location_position_free(poi_info->poi_detail[i].position); - g_free(poi_info->poi_detail[i].phone_number); - location_poiinfo_detail_properties_free(poi_info->poi_detail[i].properties); - } - } - g_free(poi_info->poi_detail); - g_slice_free(LocationPOIInfo, poi_info); -} - -LocationPOIInfo * -location_poiinfo_copy (const LocationPOIInfo* poi_info) -{ - LocationPOIInfo* poi_info_dup = location_poiinfo_new(poi_info->num_of_poi); - int i = 0; - for (i = 0 ; i < poi_info_dup->num_of_poi ; i++) - location_poiinfo_set_poi_detail (poi_info_dup, i, - poi_info->poi_detail[i].name, - poi_info->poi_detail[i].type, - poi_info->poi_detail[i].address, - poi_info->poi_detail[i].position, - poi_info->poi_detail[i].phone_number, - poi_info->poi_detail[i].properties); - - return poi_info_dup; -} - -gboolean -location_poiinfo_get_poi_detail (LocationPOIInfo *poi_info, - guint index, - gchar** name, - gchar** type, - LocationAddress** address, - LocationPosition** position, - gchar** phone_number, - GHashTable** properties) -{ - LOCATION_LOGD("location_poiinfo_get_poi_detail"); - g_return_val_if_fail(name, FALSE); - g_return_val_if_fail(type, FALSE); - g_return_val_if_fail(address, FALSE); - g_return_val_if_fail(position, FALSE); - g_return_val_if_fail(phone_number, FALSE); - g_return_val_if_fail(properties, FALSE); - g_return_val_if_fail(index < poi_info->num_of_poi, FALSE); - - *name = g_strdup(poi_info->poi_detail[index].name); - *type = g_strdup(poi_info->poi_detail[index].type); - *address = location_address_copy(poi_info->poi_detail[index].address); - *position = location_position_copy(poi_info->poi_detail[index].position); - *phone_number = g_strdup(poi_info->poi_detail[index].phone_number); - *properties = location_poiinfo_detail_properties_copy(poi_info->poi_detail[index].properties); - - return TRUE; -} - -gboolean -location_poiinfo_set_poi_detail (LocationPOIInfo *poi_info, - guint index, - const gchar* name, - const gchar* type, - const LocationAddress* address, - const LocationPosition* position, - const gchar* phone_number, - const GHashTable* properties) -{ - LOCATION_LOGD("location_poiinfo_set_poi_detail"); - g_return_val_if_fail(name, FALSE); - g_return_val_if_fail(type, FALSE); - g_return_val_if_fail(address, FALSE); - g_return_val_if_fail(position, FALSE); - g_return_val_if_fail(phone_number, FALSE); - g_return_val_if_fail( index < poi_info->num_of_poi, FALSE); - - g_free(poi_info->poi_detail[index].name); - g_free(poi_info->poi_detail[index].type); - location_address_free(poi_info->poi_detail[index].address); - location_position_free(poi_info->poi_detail[index].position); - g_free(poi_info->poi_detail[index].phone_number); - location_poiinfo_detail_properties_free(poi_info->poi_detail[index].properties); - - poi_info->poi_detail[index].name = g_strdup(name); - poi_info->poi_detail[index].type = g_strdup(type); - poi_info->poi_detail[index].address = location_address_copy(address); - poi_info->poi_detail[index].position = location_position_copy(position); - poi_info->poi_detail[index].phone_number = g_strdup(phone_number); - poi_info->poi_detail[index].properties = location_poiinfo_detail_properties_copy(properties); - - return TRUE; -} diff --git a/location/location-poi-info.h b/location/location-poi-info.h deleted file mode 100644 index 6488907..0000000 --- a/location/location-poi-info.h +++ /dev/null @@ -1,187 +0,0 @@ -/* - * libslp-location - * - * 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_POI_INFO_H__ -#define __LOCATION_POI_INFO_H__ - -#include -#include -#include - -/** - * @file location-poi-info.h - * @brief This file contains the internal definitions and structures related to POI information. - * @addtogroup LocationTypes - * @{ - */ - -G_BEGIN_DECLS - -/** - * @brief This represents one POI information such as name, type of POI, etc. - */ -typedef struct _LocationPOIDetail { - gchar *name; // Name of a POI - gchar *type; // Type of a POI (e.g. cafe) - LocationAddress *address; // Address of a POI - LocationPosition *position; // Position of a POI - gchar *phone_number; // Phone number of a POI - GHashTable *properties; // GHashTable with detailed characteristics of a POI. -} LocationPOIDetail; - -/** - * @brief This represents a number of POI informations. - */ -struct _LocationPOIInfo -{ - guint num_of_poi; - LocationPOIDetail *poi_detail; -}; - -GType location_poiinfo_get_type (void); -#define LOCATION_TYPE_POIINFO (location_poiinfo_get_type ()) - -/** - * @brief Create a new GHashTable for properties in a #LocationPOIDetail. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param None. - * @return a new GHashTable. - * @retval NULL if error occured - */ -GHashTable *location_poiinfo_detail_properties_new (void); - -/** - * @brief Free a GHashTable for properties in a #LocationPOIDetail. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] properties - a #GHashTable. - * @return None. - */ -void location_poiinfo_detail_properties_free (GHashTable* properties); - -/** - * @brief Insert a new key and value into a GHashTable for properties in a #LocationPOIDetail. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] properties - a #GHashTable in a #LocationPOIDetail. - * @param [in] key - a key to insert (e.g. URL) - * @param [in] value - the value to associate with the key. (e.g. http://www.samsung.com) - * @return gboolean - * @retval\n - * TRUE - if success\n - * FALSE - if error occured\n - */ -gboolean location_poiinfo_detail_properties_insert (GHashTable* properties, const gchar* key, const gchar* value); - -/** - * @brief Makes a copy of GHashTable for properties in a #LocationPOIDetail. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] properties - a #GHashTable - * @return a new #GHashTable - * @retval NULL if error occured - */ -GHashTable *location_poiinfo_detail_properties_copy (const GHashTable *properties); - -/** - * @brief Create a new #LocationPOIInfo with given number of #LocationPOIDetail. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] num_of_poi - number of #LocationPOIDetail. - * @return a new #LocationPOIInfo - * @retval NULL if error occured - */ -LocationPOIInfo* location_poiinfo_new (int num_of_poi); - -/** - * @brief Free a #LocationPOIInfo. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] poi_info - a #LocationPOIInfo. - * @return None. - */ -void location_poiinfo_free(LocationPOIInfo* poi_info); - -/** - * @brief Makes a copy of #LocationPOIInfo - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] poi_info - a #LocationPOIInfo - * @return a new #LocationPOIInfo - * @retval NULL if error occured - */ -LocationPOIInfo *location_poiinfo_copy (const LocationPOIInfo* poi_info); - -/** - * @brief Get elements of #LocationPOIDetail with given index in #LocationPOIInfo. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] poi_info - a #LocationPOIInfo - * @param [in] index - index of #LocationPOIDetail in #LocationPOIInfo - * @param [out] name - a name of a #LocationPOIDetail - * @param [out] type - a type of a #LocationPOIDetail - * @param [out] address - a address of a #LocationPOIDetail - * @param [out] position - a position of a#LocationPOIDetail - * @param [out] phone_number - a phone number of #LocationPOIDetail - * @param [out] properties - a GHashTable with properties of #LocationPOIDetail - * @return gboolean - * @retval\n - * TRUE - if success\n - * FALSE - if error occured\n - */ -gboolean location_poiinfo_get_poi_detail(LocationPOIInfo *poi_info, guint index, gchar** name, gchar** type, LocationAddress** address, LocationPosition** position, gchar** phone_number, GHashTable** properties); - -/** - * @brief Set elements of #LocationPOIDetail with given index in #LocationPOIInfo. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] poi_info - a #LocationPOIInfo - * @param [in] index - index of #LocationPOIDetail in #LocationPOIInfo - * @param [in] name - a name of a #LocationPOIDetail - * @param [in] type - a type of a #LocationPOIDetail - * @param [in] address - a address of a #LocationPOIDetail - * @param [in] position - a position of a #LocationPOIDetail - * @param [in] phone_number - a phone number of a #LocationPOIDetail - * @param [in] properties - a GHashTable with properties of a #LocationPOIDetail, can be NULL if a POI have no additional properties - * @return gboolean - * @retval\n - * TRUE - if success\n - * FALSE - if error occured\n - */ -gboolean location_poiinfo_set_poi_detail(LocationPOIInfo *poi_info, guint index, const gchar* name, const gchar* type, const LocationAddress* address, const LocationPosition* position, const gchar* phone_number, const GHashTable* properties); - -/** - * @} - */ - -G_END_DECLS - -#endif diff --git a/location/location-poi.c b/location/location-poi.c deleted file mode 100644 index 20084bb..0000000 --- a/location/location-poi.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-log.h" - -#include "location/location-module-internal.h" - -#include "location/location-poi.h" -#include "location/location-marshal.h" -#include "location/location-ielement.h" - -typedef struct _LocationPoiPrivate { - LocationPoiMod* mod; -} LocationPoiPrivate; - -enum { - PROP_0, - PROP_SERVICE_NAME -}; - -#define DEFAULT_SERVICE "decarta" - -#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_POI, LocationPoiPrivate)) - -static void location_ielement_interface_init (LocationIElementInterface *iface); - -G_DEFINE_TYPE_WITH_CODE (LocationPoi, location_poi, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, location_ielement_interface_init)); - - -static void -location_poi_dispose (GObject *gobject) -{ - LOCATION_LOGD("location_poi_dispose"); - - G_OBJECT_CLASS (location_poi_parent_class)->dispose (gobject); -} - -static void -location_poi_finalize (GObject *gobject) -{ - LOCATION_LOGD("location_poi_finalize"); - LocationPoiPrivate* priv = GET_PRIVATE(gobject); - module_free(priv->mod, "poi"); - priv->mod = NULL; - G_OBJECT_CLASS (location_poi_parent_class)->finalize (gobject); -} - -static void -location_poi_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - LocationPoiPrivate *priv = GET_PRIVATE (object); - - g_return_if_fail(priv->mod); - g_return_if_fail(priv->mod->handler); - switch (property_id){ - case PROP_SERVICE_NAME:{ - char* service_name = NULL; - if(priv->mod->ops.get_service_name){ - if( LOCATION_ERROR_NONE != priv->mod->ops.get_service_name(priv->mod->handler, &service_name) ){ - service_name = NULL; - } - } - LOCATION_LOGD("Get prop>> Service name: %s", service_name); - g_value_set_string(value, service_name); - g_free(service_name); - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static int -location_poi_get_poi (LocationPoi *poi, - gdouble radius, - const gchar *keyword, - LocationPOIInfo **poi_info) -{ - LOCATION_LOGD("location_poi_get_poi"); - LocationPoiPrivate* priv = GET_PRIVATE(poi); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.get_poi, LOCATION_ERROR_NOT_AVAILABLE); - return (priv->mod->ops.get_poi)(priv->mod->handler, radius, keyword, poi_info); -} - -static int -location_poi_get_poi_from_address (LocationPoi *poi, - const LocationAddress *address, - gdouble radius, - const gchar *keyword, - LocationPOIInfo **poi_info) -{ - LOCATION_LOGD("location_poi_get_poi_from_address"); - LocationPoiPrivate* priv = GET_PRIVATE(poi); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.get_poi_from_address, LOCATION_ERROR_NOT_AVAILABLE); - return (priv->mod->ops.get_poi_from_address)(priv->mod->handler, address, radius, keyword, poi_info); -} - -static int -location_poi_get_poi_from_position (LocationPoi *poi, - const LocationPosition *position, - gdouble radius, - const gchar *keyword, - LocationPOIInfo **poi_info) -{ - LOCATION_LOGD("location_poi_get_poi_from_position"); - LocationPoiPrivate* priv = GET_PRIVATE(poi); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.get_poi_from_position, LOCATION_ERROR_NOT_AVAILABLE); - return (priv->mod->ops.get_poi_from_position)(priv->mod->handler, position, radius, keyword, poi_info); -} - -static int -location_poi_get_poi_async (LocationPoi *poi, - gdouble radius, - const gchar *keyword, - LocationPOICB callback, - gpointer userdata) -{ - LOCATION_LOGD("location_poi_get_poi_async"); - LocationPoiPrivate* priv = GET_PRIVATE(poi); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.get_poi_async, LOCATION_ERROR_NOT_AVAILABLE); - return (priv->mod->ops.get_poi_async)(priv->mod->handler, radius, keyword, callback, userdata); -} - -static int -location_poi_get_poi_from_address_async (LocationPoi *poi, - const LocationAddress *address, - gdouble radius, - const gchar *keyword, - LocationPOICB callback, - gpointer userdata) -{ - LOCATION_LOGD("location_poi_get_poi_from_address_async"); - LocationPoiPrivate* priv = GET_PRIVATE(poi); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.get_poi_from_address_async, LOCATION_ERROR_NOT_AVAILABLE); - return (priv->mod->ops.get_poi_from_address_async)(priv->mod->handler, address, radius, keyword, callback, userdata); -} - -static int -location_poi_get_poi_from_position_async (LocationPoi *poi, - const LocationPosition *position, - gdouble radius, - const gchar* keyword, - LocationPOICB callback, - gpointer userdata) -{ - LOCATION_LOGD("location_poi_get_poi_from_position_async"); - LocationPoiPrivate* priv = GET_PRIVATE(poi); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.get_poi_from_position_async, LOCATION_ERROR_NOT_AVAILABLE); - return (priv->mod->ops.get_poi_from_position_async)(priv->mod->handler, position, radius, keyword, callback, userdata); -} - -static void -location_ielement_interface_init (LocationIElementInterface *iface) -{ - iface->get_poi = (TYPE_GET_POI)location_poi_get_poi; - iface->get_poi_from_address = (TYPE_GET_POI_FROM_ADDRESS)location_poi_get_poi_from_address; - iface->get_poi_from_position = (TYPE_GET_POI_FROM_POSITION)location_poi_get_poi_from_position; - iface->get_poi_async = (TYPE_GET_POI_ASYNC)location_poi_get_poi_async; - iface->get_poi_from_address_async = (TYPE_GET_POI_FROM_ADDRESS_ASYNC)location_poi_get_poi_from_address_async; - iface->get_poi_from_position_async = (TYPE_GET_POI_FROM_POSITION_ASYNC)location_poi_get_poi_from_position_async; -} - -static void -location_poi_init (LocationPoi *poi) -{ - LOCATION_LOGD("location_poi_init"); - LocationPoiPrivate* priv = GET_PRIVATE(poi); - - priv->mod = (LocationPoiMod*)module_new("poi"); - if(!priv->mod) LOCATION_LOGW("module loading failed"); -} - -static void -location_poi_class_init (LocationPoiClass *klass) -{ - LOCATION_LOGD("location_poi_class_init"); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GParamSpec *pspec; - - gobject_class->get_property = location_poi_get_property; - - gobject_class->dispose = location_poi_dispose; - gobject_class->finalize = location_poi_finalize; - - g_type_class_add_private (klass, sizeof (LocationPoiPrivate)); - - pspec = g_param_spec_string ("service provider", - "poi service provider name prop", - "poi service provider name", - DEFAULT_SERVICE, - G_PARAM_READABLE); - g_object_class_install_property (gobject_class, - PROP_SERVICE_NAME, - pspec); -} diff --git a/location/location-poi.h b/location/location-poi.h deleted file mode 100644 index 03dbf55..0000000 --- a/location/location-poi.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * libslp-location - * - * 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_POI_H__ -#define __LOCATION_POI_H__ - -#include - -/** - * @addtogroup Location - * @{ - * @file location-poi.h - * @brief This file contains the internal definitions and structures related to POI. - *@} - */ - -G_BEGIN_DECLS - -#define LOCATION_TYPE_POI (location_poi_get_type ()) -#define LOCATION_POI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_POI, LocationPoi)) -#define LOCATION_IS_POI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_POI)) -#define LOCATION_POI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_POI, LocationPoiClass)) -#define LOCATION_IS_POI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_POI)) -#define LOCATION_POI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_POI, LocationPoiClass)) - -typedef struct _LocationPoi LocationPoi; -typedef struct _LocationPoiClass LocationPoiClass; - -struct _LocationPoi -{ - GObject parent_instance; -}; - -struct _LocationPoiClass -{ - GObjectClass parent_class; -}; - -GType location_poi_get_type (void); - -G_END_DECLS - -#endif diff --git a/location/location-position.c b/location/location-position.c deleted file mode 100644 index dd3b387..0000000 --- a/location/location-position.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#include "location/location-position.h" -#include "location/location-setting.h" -#include "location/location-log.h" - -#define DEG2RAD(x) ((x) * M_PI / 180) - -GType -location_position_get_type (void) -{ - static volatile gsize type_volatile = 0; - if(g_once_init_enter(&type_volatile)) { - GType type = g_boxed_type_register_static ( - g_intern_static_string ("LocationPosition"), - (GBoxedCopyFunc) location_position_copy, - (GBoxedFreeFunc) location_position_free); - g_once_init_leave(&type_volatile, type); - } - return type_volatile; -} - -EXPORT_API LocationPosition * -location_position_new (guint timestamp, - gdouble latitude, - gdouble longitude, - gdouble altitude, - LocationStatus status) -{ - LocationPosition* position = g_slice_new0(LocationPosition); - position->timestamp = timestamp; - position->latitude = latitude; - position->longitude = longitude; - position->altitude = altitude; - position->status = status; - return position; -} - -EXPORT_API void -location_position_free (LocationPosition* position) -{ - g_return_if_fail(position); - g_slice_free(LocationPosition, position); -} - -EXPORT_API gboolean -location_position_equal (const LocationPosition *position1, const LocationPosition *position2) -{ - g_return_val_if_fail(position1, FALSE); - g_return_val_if_fail(position2, FALSE); - - if (position1->latitude == position2->latitude && - position1->longitude == position2->longitude && - position1->altitude == position2->altitude) - return TRUE; - return FALSE; -} - -EXPORT_API LocationPosition* -location_position_copy (const LocationPosition *position) -{ - g_return_val_if_fail(position, NULL); - - LocationPosition *new_position = NULL; - - new_position = location_position_new (position->timestamp, - position->latitude, - position->longitude, - position->altitude, - position->status); - - if(new_position) new_position->updated_timestamp = position->updated_timestamp; - - return new_position; - -} - -/* Vincenty formula. WGS-84 */ -EXPORT_API int -location_get_distance(const LocationPosition *pos1, const LocationPosition *pos2, gulong *distance) -{ - g_return_val_if_fail(pos1, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail(pos2, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail(distance, LOCATION_ERROR_PARAMETER); - - *distance = 0; - - const double a = 6378137.0, b = 6356752.314245, f = 1/298.257223563; - double delta_lon = DEG2RAD(pos2->longitude-pos1->longitude); - double u_1 = atan((1-f) * tan(DEG2RAD(pos1->latitude))); - double u_2 = atan((1-f) * tan(DEG2RAD(pos2->latitude))); - - double lambdaP, iter_limit = 100.0; - double lambda = delta_lon; - - double sin_sigma, sin_alpha, cos_sigma, sigma, sq_cos_alpha, cos_2sigma, C; - double sq_u, cal1, cal2, delta_sigma, cal_dist; - double sin_lambda, cos_lambda; - - double sin_u1 = sin(u_1); - double cos_u1 = cos(u_1); - double sin_u2 = sin(u_2); - double cos_u2 = cos(u_2); - - do { - sin_lambda = sin(lambda); - cos_lambda = cos(lambda); - - sin_sigma = sqrt((cos_u2*sin_lambda)*(cos_u2*sin_lambda) + \ - (cos_u1*sin_u2-sin_u1*cos_u2*cos_lambda) * \ - (cos_u1*sin_u2-sin_u1*cos_u2*cos_lambda)); - - if (sin_sigma ==0) - return LOCATION_ERROR_NONE; // co-incident points - - cos_sigma = sin_u1*sin_u2 + cos_u1*cos_u2*cos_lambda; - sigma = atan2(sin_sigma, cos_sigma); - - sin_alpha = cos_u1 * cos_u2 * sin_lambda / sin_sigma; - sq_cos_alpha = 1.0 - sin_alpha*sin_alpha; - cos_2sigma = cos_sigma - 2.0*sin_u1*sin_u2/sq_cos_alpha; - - if (isnan(cos_2sigma)) - cos_2sigma = 0; - - C = f/16.0*sq_cos_alpha*(4.0+f*(4.0-3.0*sq_cos_alpha)); - - lambdaP = lambda; - lambda = delta_lon + (1.0-C) * f * sin_alpha * \ - (sigma + C*sin_sigma*(cos_2sigma+C*cos_sigma*(-1.0+2.0*cos_2sigma*cos_2sigma))); - - } while (abs(lambda-lambdaP) > 1e-12 && --iter_limit>0); - - if (iter_limit==0) return LOCATION_ERROR_UNKNOWN; - - sq_u = sq_cos_alpha * (a*a - b*b) / (b*b); - - cal1 = 1.0 + sq_u/16384.0*(4096.0+sq_u*(-768.0+sq_u*(320.0-175.0*sq_u))); - cal2 = sq_u/1024.0 * (256.0+sq_u*(-128.0+sq_u*(74.0-47.0*sq_u))); - - delta_sigma = cal2*sin_sigma*(cos_2sigma+cal2/4.0*(cos_sigma*(-1.0+2.0*cos_2sigma*cos_2sigma)- \ - cal2/6.0*cos_2sigma*(-3.0+4.0*sin_sigma*sin_sigma)*(-3.0+4.0*cos_2sigma*cos_2sigma))); - cal_dist = b*cal1*(sigma-delta_sigma); - - *distance = (gulong) cal_dist; - - return LOCATION_ERROR_NONE; - -} - -EXPORT_API void -location_last_position_a2i(char *position, int *lat, int *lon) -{ - char *d_lat, *d_lon; - char latitude[HALF_KEY_LENGTH]; - char longitude[HALF_KEY_LENGTH]; - - memcpy(latitude, position + 1, HALF_KEY_LENGTH - 1); - memcpy(longitude, position + HALF_KEY_LENGTH + 1, HALF_KEY_LENGTH - 1); - latitude[HALF_KEY_LENGTH - 1] = '\0'; - longitude[HALF_KEY_LENGTH - 1] = '\0'; - d_lat = position; - d_lon = position + HALF_KEY_LENGTH; - - *lat = atoi(latitude); - *lon = atoi(longitude); - - if (*d_lat == 'S') { - *lat = *lat * -1; - } - if (*d_lon == 'W') { - *lon = *lon * -1; - } -} diff --git a/location/location-position.h b/location/location-position.h deleted file mode 100644 index 4ef257b..0000000 --- a/location/location-position.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * libslp-location - * - * 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_POSITION_H_ -#define __LOCATION_POSITION_H_ - -#include - -#define MAX_KEY_LENGTH 16 -#define HALF_KEY_LENGTH 8 - -/** - * @file location-position.h - * @brief This file contains the internal definitions and structures related to position information. - * @addtogroup LocationTypes - * @{ - */ - -G_BEGIN_DECLS - -/** - * @brief This represents the various fix states. - */ -typedef enum -{ - LOCATION_STATUS_NO_FIX = 0, ///< No fix status. - LOCATION_STATUS_2D_FIX, ///< 2D fix status (latitude/longitude/speed/direction). - LOCATION_STATUS_3D_FIX ///< 3D fix status (altitude/climb as well). -} LocationStatus; - -/** - * @brief This represents position information such as latitude-longitude-altitude values and timestamp. - */ -struct _LocationPosition -{ - guint timestamp; ///< Time stamp. - guint updated_timestamp; ///< latest updated time stamp. - gdouble latitude; ///< Latitude data. - gdouble longitude; ///< Longitude data. - gdouble altitude; ///< Altitude data. - LocationStatus status; ///< Fix states. -}; - -/** - * @brief This represents last known position information such as latitude-longitude values and accuracy. - */ -struct _LocationLastPosition -{ - LocationMethod method; ///< Location Method. - guint timestamp; ///< Time stamp. - gdouble latitude; ///< Latitude data. - gdouble longitude; ///< Longitude data. - gdouble altitude; ///< Altitude data. - gdouble horizontal_accuracy; ///< Horizontal accuracy data. - gdouble vertical_accuracy; ///< Vertical accuracy data. -}; - -GType location_position_get_type (void); -#define LOCATION_TYPE_POSITION (location_position_get_type ()) - -/** - * @brief Create a new #LocationPosition with given information. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] timestamp - Time stamp. - * @param [in] latitude - Latitude data. - * @param [in] longitude - Longitude data. - * @param [in] altitude - Altitude data. - * @param [in] status - a #LocationStatus. - * @return a new #LocationPosition - * @retval NULL if error occured - */ -LocationPosition *location_position_new (guint timestamp, gdouble latitude, gdouble longitude, gdouble altitude, LocationStatus status); - -/** - * @brief Free a #LocationPosition. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] position - a #LocationPosition. - * @return None. - */ -void location_position_free (LocationPosition *position); - -/** - * @brief Compares two positions for equality, returning TRUE if they are equal. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] position1 - a #LocationPosition - * @param [in] position2 - a #LocationPosition - * @return gboolean - * @retval\n - * TRUE - if equal\n - * FALSE - if not equal\n - */ -gboolean location_position_equal (const LocationPosition *position1, const LocationPosition *position2); - -/** - * @brief Makes a copy of #LocationPosition - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] position - a #LocationPosition - * @return a new #LocationPosition - * @retval NULL if error occured - */ -LocationPosition *location_position_copy (const LocationPosition *position); - -/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -/* Vincenty Inverse Solution of Geodesics on the Ellipsoid (c) Chris Veness 2002-2010 */ -/* */ -/* from: Vincenty inverse formula - T Vincenty, "Direct and Inverse Solutions of Geodesics on the */ -/* Ellipsoid with application of nested equations", Survey Review, vol XXII no 176, 1975 */ -/* http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf */ -/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -/** - * @brief Gets the approximate distance between two points. A distance is defined using the WGS84 ellipsoid. - * @remarks Uses meters as a unit of measurement for a distance. - * @pre None. - * @post None. - * @param [in] pos1 - a #LocationPosition (decimal degree) - * @param [in] pos2 - a #LocationPosition (decimal degree) - * @param [out] distance - a #gulong (meters) - * @return int - * @retval 0 Success. - * - * Please refer #LocationError for more information. - */ -int location_get_distance(const LocationPosition *pos1, const LocationPosition *pos2, gulong *distance); - -/** - * @brief Change position string to latitude and longitude integer. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] position - string of last position. - * @param [in] lat - latitude. - * @param [in] lon - longitude. - * @return None. - */ -void location_last_position_a2i(char *position, int *lat, int *lon); - -/** - * @} - */ - -G_END_DECLS - -#endif diff --git a/location/location-satellite.c b/location/location-satellite.c deleted file mode 100644 index 6c19ed4..0000000 --- a/location/location-satellite.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-satellite.h" -#include "location/location-log.h" - -GType -location_satellite_get_type (void) -{ - static volatile gsize type_volatile = 0; - if(g_once_init_enter(&type_volatile)) { - GType type = g_boxed_type_register_static ( - g_intern_static_string ("LocationSatellite"), - (GBoxedCopyFunc) location_satellite_copy, - (GBoxedFreeFunc) location_satellite_free); - g_once_init_leave(&type_volatile, type); - } - return type_volatile; -} - -static void -update_num_of_used (LocationSatellite *satellite) -{ - g_return_if_fail(satellite); - satellite->num_of_sat_used = 0; - if (satellite->num_of_sat_inview > 0 && satellite->sat_inview) { - int i = 0; - for (i = 0 ; i < satellite->num_of_sat_inview ; i++) - if(satellite->sat_inview[i].used) (satellite->num_of_sat_used)++; - } -} - -EXPORT_API LocationSatellite* -location_satellite_new (int num_of_sat_inview) -{ - LocationSatellite* satellite = g_slice_new0(LocationSatellite); - satellite->num_of_sat_inview = num_of_sat_inview; - satellite->num_of_sat_used = 0; - satellite->sat_inview = g_new0(LocationSatelliteDetail, satellite->num_of_sat_inview); - return satellite; -} - -EXPORT_API void -location_satellite_free (LocationSatellite* satellite) -{ - g_return_if_fail(satellite); - g_free(satellite->sat_inview); - g_slice_free(LocationSatellite, satellite); -} - -EXPORT_API LocationSatellite* -location_satellite_copy (const LocationSatellite *satellite) -{ - g_return_val_if_fail(satellite, NULL); - LocationSatellite* satellite_dup = location_satellite_new(satellite->num_of_sat_inview); - satellite_dup->num_of_sat_used = satellite->num_of_sat_used; - int i = 0; - for (i = 0 ; i < satellite_dup->num_of_sat_inview ; i++) - location_satellite_set_satellite_details(satellite_dup, i, - satellite->sat_inview[i].prn, - satellite->sat_inview[i].used, - satellite->sat_inview[i].elevation, - satellite->sat_inview[i].azimuth, - satellite->sat_inview[i].snr); - return satellite_dup; -} - -EXPORT_API gboolean -location_satellite_get_satellite_details (const LocationSatellite *satellite, - guint index, - guint* prn, - gboolean* used, - guint* elevation, - guint* azimuth, - gint* snr) -{ - g_return_val_if_fail(satellite, FALSE); - g_return_val_if_fail(prn, FALSE); - g_return_val_if_fail(used, FALSE); - g_return_val_if_fail(elevation, FALSE); - g_return_val_if_fail(azimuth, FALSE); - g_return_val_if_fail(snr, FALSE); - g_return_val_if_fail(satellite->sat_inview, FALSE); - g_return_val_if_fail(index < satellite->num_of_sat_inview, FALSE); - - *prn = satellite->sat_inview[index].prn; - *used = satellite->sat_inview[index].used; - *elevation = satellite->sat_inview[index].elevation; - *azimuth = satellite->sat_inview[index].azimuth; - *snr = satellite->sat_inview[index].snr; - - return TRUE; -} - -EXPORT_API gboolean -location_satellite_set_satellite_details (LocationSatellite *satellite, - guint index, - guint prn, - gboolean used, - guint elevation, - guint azimuth, - gint snr) -{ - g_return_val_if_fail(satellite, FALSE); - g_return_val_if_fail(satellite->sat_inview, FALSE); - g_return_val_if_fail(index < satellite->num_of_sat_inview, FALSE); - - satellite->sat_inview[index].prn= prn; - satellite->sat_inview[index].used= used; - satellite->sat_inview[index].elevation= elevation; - satellite->sat_inview[index].azimuth= azimuth; - satellite->sat_inview[index].snr= snr; - update_num_of_used (satellite); - - return TRUE; -} diff --git a/location/location-satellite.h b/location/location-satellite.h deleted file mode 100644 index f91f98f..0000000 --- a/location/location-satellite.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * libslp-location - * - * 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_SATELLITE_H_ -#define __LOCATION_SATELLITE_H_ - -#include - -/** - * @file location-satellite.h - * @brief This file contains the internal definitions and structures related to satellite information. - * @addtogroup LocationTypes - * @{ - */ - -G_BEGIN_DECLS - -/** - * @brief This represents one satellite information in view. - */ -typedef struct { - guint prn; ///< The PRNs(Pseudo-Random Noise code) of a satellite. - gboolean used; ///< TRUE if currently used satellite. - guint elevation; ///< The elevation of a satellite. - guint azimuth; ///< The degree from true north 000 to 359 of a satellite. - gint snr; ///< The signal-to-noise ratio, dB of a satellite. -} LocationSatelliteDetail; - -/** - * @brief This represents position information such as number of satellites in used or in view. - */ -struct _LocationSatellite -{ - guint timestamp; ///< Time stamp. - guint num_of_sat_inview; ///< The number of satellites in view. - guint num_of_sat_used; ///< The number of satellites in used. - LocationSatelliteDetail* sat_inview; ///< The information of satellites in view . -}; - -GType location_satellite_get_type (void); -#define LOCATION_TYPE_SATELLITE (location_satellite_get_type ()) - -/** - * @brief Create a new #LocationSatellite with given number of #LocationSatelliteDetail. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] num_of_sat_inview - number of #LocationSatelliteDetail. - * @return a new #LocationSatellite - * @retval NULL if error occured - */ -LocationSatellite *location_satellite_new (int num_of_sat_inview); - -/** - * @brief Free a #LocationSatellite. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] satellite - a #LocationSatellite. - * @return None. - */ -void location_satellite_free (LocationSatellite *satellite); - -/** - * @brief Makes a copy of #LocationSatellite - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] satellite - a #LocationSatellite - * @return a new #LocationSatellite - * @retval NULL if error occured - */ -LocationSatellite *location_satellite_copy (const LocationSatellite *satellite); - -/** - * @brief Get elements of #LocationSatelliteDetail with given index in #LocationSatellite. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] satellite - a #LocationSatellite - * @param [in] index - index of #LocationSatelliteDetail in #LocationSatellite - * @param [out] prn - The PRNs(Pseudo-Random Noise code) of a #LocationSatellite - * @param [out] used - TRUE if a #LocationSatellite in used. - * @param [out] elevation - The elevation of a #LocationSatellite - * @param [out] azimuth - The degree from true north 000 to 359 of a#LocationSatellite - * @param [out] snr - The signal-to-noise ratio, dB of #LocationSatellite - * @return gboolean - * @retval\n - * TRUE - if success\n - * FALSE - if error occured\n - */ -gboolean location_satellite_get_satellite_details (const LocationSatellite *satellite, guint index, guint *prn, gboolean *used, guint *elevation, guint *azimuth, gint *snr); - -/** - * @brief Set elements of #LocationSatelliteDetail with given index in #LocationSatellite. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] satellite - a #LocationSatellite - * @param [in] index - index of #LocationSatelliteDetail in #LocationSatellite - * @param [in] prn - The PRNs(Pseudo-Random Noise code) of a #LocationSatellite - * @param [in] used - TRUE if a #LocationSatellite in used. - * @param [in] elevation - The elevation of a #LocationSatellite - * @param [in] azimuth - The degree from true north 000 to 359 of a#LocationSatellite - * @param [in] snr - The signal-to-noise ratio, dB of #LocationSatellite - * @return gboolean - * @retval\n - * TRUE - if success\n - * FALSE - if error occured\n - */ -gboolean location_satellite_set_satellite_details( LocationSatellite *satellite, guint index, guint prn, gboolean used, guint elevation, guint azimuth, gint snr); - -/** - * @} - */ - -G_END_DECLS - -#endif diff --git a/location/location-setting.c b/location/location-setting.c deleted file mode 100644 index 9f7e73a..0000000 --- a/location/location-setting.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "location/location-log.h" -#include "location/location-setting.h" - - -gint location_setting_get_key_val(keynode_t *key) -{ - g_return_val_if_fail(key, -1); - int val = -1; - switch(vconf_keynode_get_type(key)) - { - case VCONF_TYPE_INT: - val = vconf_keynode_get_int(key); - LOCATION_LOGD("Setting changed [%s]:[%d]", vconf_keynode_get_name(key), val); - break; - default: - LOCATION_LOGW("Unused type(%d)", vconf_keynode_get_type(key)); - break; - } - return val; -} - -gint location_setting_get_int(const gchar* path) -{ - g_return_val_if_fail(path, -1); - int val = -1; - if( vconf_get_int(path, &val)){ - LOCATION_LOGW("vconf_get_int: failed [%s]", path); - val = -1; - } else if (val == 0) - LOCATION_LOGD("vconf_get_int: [%s]:[%d]", path, val); - return val; -} - -gboolean location_setting_get_bool(const gchar* path) -{ - g_return_val_if_fail(path, -1); - gboolean val = FALSE; - if( vconf_get_bool(path, &val)){ - LOCATION_LOGW("vconf_get_int: failed [%s]", path); - val = FALSE; - } - return val; -} - -gchar *location_setting_get_string(const gchar* path) -{ - g_return_val_if_fail(path, -1); - return vconf_get_str(path); -} - -gint location_setting_add_notify(const gchar* path, SettingCB setting_cb, gpointer self) -{ - g_return_val_if_fail(path, -1); - g_return_val_if_fail(self, -1); - - if( vconf_notify_key_changed(path, setting_cb, self)){ - LOCATION_LOGW("vconf notify add failed [%s]", path); - return -1; - } - LOCATION_LOGD("vconf notify added [%s]", path); - return 0; -} - -gint location_setting_ignore_notify(const gchar* path, SettingCB setting_cb) -{ - g_return_val_if_fail(path, -1); - g_return_val_if_fail(setting_cb, -1); - - if( vconf_ignore_key_changed(path, setting_cb)){ - LOCATION_LOGW("vconf notify remove failed [%s]", path); - return -1; - } - LOCATION_LOGD("vconf notify removed [%s]", path); - return 0; -} diff --git a/location/location-setting.h b/location/location-setting.h deleted file mode 100644 index 705f778..0000000 --- a/location/location-setting.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * libslp-location - * - * 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_SETTING_H__ -#define __LOCATION_SETTING_H__ - -#include -#include -#include - -/** - * @file location-setting.h - * @brief This file contains the definitions and functions for setting. - * @addtogroup LocationInternal - * @{ - * @} - */ - -#define VCONF_LOCATION_PATH "db/location" - -#define LOCATION_LAST_POSITION_PATH VCONF_LOCATION_PATH"/lastposition" -#define GPS_LAST_POSITION_PATH LOCATION_LAST_POSITION_PATH"/gps" -#define WPS_LAST_POSITION_PATH LOCATION_LAST_POSITION_PATH"/wps" -#define SPS_LAST_POSITION_PATH LOCATION_LAST_POSITION_PATH"/sps" - -#define GPS_LAST_TIMESTAMP GPS_LAST_POSITION_PATH"/Timestamp" -#define GPS_LAST_LATITUDE GPS_LAST_POSITION_PATH"/Latitude" -#define GPS_LAST_LONGITUDE GPS_LAST_POSITION_PATH"/Longitude" -#define GPS_LAST_ALTITUDE GPS_LAST_POSITION_PATH"/Altitude" -#define GPS_LAST_HORACCURACY GPS_LAST_POSITION_PATH"/HorAccuracy" -#define GPS_LAST_VERACCURACY GPS_LAST_POSITION_PATH"/VerAccuracy" - -#define WPS_LAST_TIMESTAMP WPS_LAST_POSITION_PATH"/Timestamp" -#define WPS_LAST_LATITUDE WPS_LAST_POSITION_PATH"/Latitude" -#define WPS_LAST_LONGITUDE WPS_LAST_POSITION_PATH"/Longitude" -#define WPS_LAST_ALTITUDE WPS_LAST_POSITION_PATH"/Altitude" -#define WPS_LAST_HORACCURACY WPS_LAST_POSITION_PATH"/HorAccuracy" -#define WPS_LAST_VERACCURACY WPS_LAST_POSITION_PATH"/VerAccuracy" - -#define SPS_LAST_TIMESTAMP SPS_LAST_POSITION_PATH"/Timestamp" -#define SPS_LAST_LATITUDE SPS_LAST_POSITION_PATH"/Latitude" -#define SPS_LAST_LONGITUDE SPS_LAST_POSITION_PATH"/Longitude" -#define SPS_LAST_ALTITUDE SPS_LAST_POSITION_PATH"/Altitude" -#define SPS_LAST_HORACCURACY SPS_LAST_POSITION_PATH"/HorAccuracy" -#define SPS_LAST_VERACCURACY SPS_LAST_POSITION_PATH"/VerAccuracy" - -#define GPS_ENABLED VCONFKEY_LOCATION_ENABLED -#define LOCATION_SETTING_PATH VCONF_LOCATION_PATH"/setting" -#define AGPS_ENABLED LOCATION_SETTING_PATH"/AgpsEnabled" -#define NETWORK_ENABLED LOCATION_SETTING_PATH"/NetworkEnabled" -#define SENSOR_ENABLED LOCATION_SETTING_PATH"/SensorEnabled" - -#define LOCATION_UPDATE_INTERVAL_MIN 1 -#define LOCATION_UPDATE_INTERVAL_MAX 120 -#define LOCATION_UPDATE_INTERVAL_DEFAULT LOCATION_UPDATE_INTERVAL_MIN - -typedef void (*SettingCB)(keynode_t *key, gpointer data); - -gint location_setting_get_key_val(keynode_t *key); -gint location_setting_get_int(const gchar* path); -gchar *location_setting_get_string(const gchar* path); -gint location_setting_add_notify(const gchar* path, SettingCB setting_cb, gpointer self); -gint location_setting_ignore_notify(const gchar* path, SettingCB setting_cb); - -#define setting_retval_if_fail(path) {\ - if(!location_setting_get_int(path)){\ - return LOCATION_ERROR_NOT_ALLOWED;\ - }\ -} - -#define setting_ret_if_fail(path) {\ - if(!location_setting_get_int(path)){\ - return;\ - }\ -} - - -#endif diff --git a/location/location-signaling-util.c b/location/location-signaling-util.c deleted file mode 100644 index 263dc2f..0000000 --- a/location/location-signaling-util.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-signaling-util.h" -#include "location/location-log.h" - -#define POS_EXPIRATION_TIME 9 /* sec */ - -void -enable_signaling (LocationObject *obj, - guint32 signals[LAST_SIGNAL], - gboolean *prev_enabled, - gboolean enabled, - LocationStatus status) -{ - g_return_if_fail(obj); - g_return_if_fail(signals); - g_return_if_fail(prev_enabled); - if (*prev_enabled == TRUE && enabled == FALSE) { - *prev_enabled = FALSE; - LOCATION_LOGD("Signal emit: SERVICE_DISABLED"); - g_signal_emit (obj, signals[SERVICE_DISABLED], 0, LOCATION_STATUS_NO_FIX); - } else if (*prev_enabled == FALSE && enabled == TRUE){ - *prev_enabled = TRUE; - LOCATION_LOGD("Signal emit: SERVICE_ENABLED"); - g_signal_emit (obj, signals[SERVICE_ENABLED], 0, status); - } -} - -void -position_signaling (LocationObject *obj, - guint32 signals[LAST_SIGNAL], - gboolean *prev_enabled, - guint interval, - LocationPosition **prev_pos, - LocationAccuracy **prev_acc, - GList *prev_bound, - ZoneStatus *zone_status, - gboolean enabled, - const LocationPosition *pos, - const LocationAccuracy *acc) -{ - g_return_if_fail(zone_status); - g_return_if_fail(pos); - g_return_if_fail(acc); - g_return_if_fail(obj); - g_return_if_fail(signals); - - int index = 0; - gboolean is_inside = FALSE; - guint updated_timestamp = 0; - GList *boundary_list = prev_bound; - LocationBoundary *boundary = NULL; - - if(!*prev_pos || !*prev_acc || location_accuracy_level_compare(*prev_acc, acc) != -1 || - (pos->timestamp - (*prev_pos)->timestamp) > POS_EXPIRATION_TIME) { - - if(*prev_pos) { - updated_timestamp = (*prev_pos)->updated_timestamp; - location_position_free(*prev_pos); - } - if(*prev_acc) location_accuracy_free(*prev_acc); - - if(!updated_timestamp || pos->timestamp - updated_timestamp >= interval) { - LOCATION_LOGD("Signal emit: POSITION SERVICE_UPDATED"); - g_signal_emit(obj, signals[SERVICE_UPDATED], 0, POSITION_UPDATED, pos, acc); - updated_timestamp = pos->timestamp; - } - - if(boundary_list) { - while((boundary = (LocationBoundary *)g_list_nth_data(boundary_list, index))!= NULL) { - - is_inside = location_boundary_if_inside(boundary, pos); - if(is_inside) { - break; - } - index++; - } - - if(is_inside) { - if(*zone_status != ZONE_STATUS_IN) { - LOCATION_LOGD("Signal emit: ZONE IN"); - g_signal_emit(obj, signals[ZONE_IN], 0, NULL, pos, acc); - *zone_status = ZONE_STATUS_IN; - } - } - else { - if (*zone_status != ZONE_STATUS_OUT) { - LOCATION_LOGD("Signal emit : ZONE_OUT"); - g_signal_emit(obj, signals[ZONE_OUT], 0, NULL, pos, acc); - *zone_status = ZONE_STATUS_OUT; - } - } - - } - } - - *prev_pos = location_position_copy(pos); - *prev_acc = location_accuracy_copy(acc); - (*prev_pos)->updated_timestamp = updated_timestamp; -} - -void -velocity_signaling (LocationObject *obj, - guint32 signals[LAST_SIGNAL], - gboolean *prev_enabled, - guint interval, - LocationVelocity **prev_vel, - gboolean enabled, - const LocationVelocity *vel, - const LocationAccuracy *acc) -{ - g_return_if_fail(obj); - g_return_if_fail(signals); - g_return_if_fail(vel); - - guint updated_timestamp = 0; - - if(*prev_vel) { - updated_timestamp = (*prev_vel)->updated_timestamp; - if(!location_velocity_equal(*prev_vel, vel)) { - location_velocity_free (*prev_vel); - } - } - - *prev_vel = location_velocity_copy (vel); - - if(!updated_timestamp || vel->timestamp - updated_timestamp >= interval) { - - LOCATION_LOGD ("Signal emit: VELOCITY SERVICE_UPDATED"); - LocationVelocity *temp_vel = location_velocity_copy (*prev_vel); - LocationAccuracy *temp_acc = location_accuracy_copy(acc); - - g_signal_emit (obj, signals[SERVICE_UPDATED], 0, VELOCITY_UPDATED, temp_vel, temp_acc); - - (*prev_vel)->updated_timestamp = vel->timestamp; - - location_velocity_free(temp_vel); - location_accuracy_free(temp_acc); - } - else { - (*prev_vel)->updated_timestamp = updated_timestamp; - } - -} diff --git a/location/location-signaling-util.h b/location/location-signaling-util.h deleted file mode 100644 index c2474bf..0000000 --- a/location/location-signaling-util.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * libslp-location - * - * 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_SIGNALING_UTIL_H__ -#define __LOCATION_SIGNALING_UTIL_H__ - -#include -#include - -/** - * @file location-signaling.h - * @brief This file contains the signaling utils for LocationObject. - * @addtogroup LocationInternal - * @{ - * @} - */ - -G_BEGIN_DECLS - -typedef enum { - ZONE_STATUS_NONE = 0, - ZONE_STATUS_IN, - ZONE_STATUS_OUT, -} ZoneStatus; - -void enable_signaling (LocationObject *obj, guint32 signals[LAST_SIGNAL], gboolean *prev_enabled, gboolean enabled, LocationStatus status); - -void position_signaling (LocationObject *obj, guint32 signals[LAST_SIGNAL], gboolean *prev_enabled, guint interval, LocationPosition **prev_pos, LocationAccuracy **prev_acc, GList *prev_bound, ZoneStatus *zone_status, gboolean enabled, const LocationPosition *pos, const LocationAccuracy *acc); - -void velocity_signaling (LocationObject* obj, guint32 signals[LAST_SIGNAL], gboolean *prev_enabled, guint interval, LocationVelocity **prev_vel, gboolean enabled, const LocationVelocity *vel, const LocationAccuracy *acc); - -G_END_DECLS - -#endif diff --git a/location/location-sps.c b/location/location-sps.c deleted file mode 100644 index 4f54fed..0000000 --- a/location/location-sps.c +++ /dev/null @@ -1,560 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-setting.h" -#include "location/location-log.h" - -#include "location/location-module-internal.h" - -#include "location/location-sps.h" -#include "location/location-marshal.h" -#include "location/location-ielement.h" -#include "location/location-signaling-util.h" -#include "location/location-common-util.h" - -typedef struct _LocationSpsPrivate { - LocationSpsMod* mod; - gboolean is_started; - gboolean set_noti; - gboolean enabled; - guint interval; - LocationPosition *pos; - LocationVelocity *vel; - LocationAccuracy *acc; - GList *boundary_list; - ZoneStatus zone_status; - LocationPosition *pos_base; - LocationVelocity *vel_base; - LocationAccuracy *acc_info; - LocationSatellite *sat_info; -} LocationSpsPrivate; - -enum { - PROP_0, - PROP_METHOD_TYPE, - PROP_LAST_POSITION, - PROP_UPDATE_INTERVAL, - PROP_BOUNDARY, - PROP_REMOVAL_BOUNDARY, - PROP_POSITION_BASE, - PROP_VELOCITY_BASE, - PROP_ACCURACY_INFO, - PROP_SATELLITE_INFO, - PROP_MAX -}; - -static guint32 signals[LAST_SIGNAL] = {0, }; -static GParamSpec *properties[PROP_MAX] = {NULL, }; - -#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_SPS, LocationSpsPrivate)) - -static void location_ielement_interface_init (LocationIElementInterface *iface); - -G_DEFINE_TYPE_WITH_CODE (LocationSps, location_sps, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, - location_ielement_interface_init)); - -static void -sps_status_cb (gboolean enabled, - LocationStatus status, - gpointer self) -{ - LOCATION_LOGD("sps_status_cb"); - g_return_if_fail(self); - LocationSpsPrivate* priv = GET_PRIVATE(self); - enable_signaling(self, signals, &(priv->enabled), enabled, status); -} - -static void -sps_position_cb (gboolean enabled, - LocationPosition *pos, - LocationAccuracy *acc, - gpointer self) -{ - LOCATION_LOGD("sps_position_cb"); - g_return_if_fail(self); - g_return_if_fail(pos); - g_return_if_fail(acc); - LocationSpsPrivate* priv = GET_PRIVATE(self); - enable_signaling(self, signals, &(priv->enabled), enabled, pos->status); - - position_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->pos), &(priv->acc), priv->boundary_list, &(priv->zone_status), enabled, pos, acc); -} - -static void -sps_velocity_cb (gboolean enabled, - LocationVelocity *vel, - LocationAccuracy *acc, - gpointer self) -{ - LOCATION_LOGD("sps_velocity_cb"); - g_return_if_fail(self); - LocationSpsPrivate* priv = GET_PRIVATE(self); - velocity_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->vel), enabled, vel, acc); -} - -static void -location_setting_sps_cb(keynode_t *key, - gpointer self) -{ - LOCATION_LOGD("location_setting_sps_cb"); - g_return_if_fail(key); - g_return_if_fail(self); - LocationSpsPrivate* priv = GET_PRIVATE(self); - g_return_if_fail (priv->mod); - g_return_if_fail (priv->mod->handler); - - int ret = LOCATION_ERROR_NONE; - - if (location_setting_get_key_val(key) == 0) { - if (priv->mod->ops.stop && priv->is_started) { - ret = priv->mod->ops.stop(priv->mod->handler); - if (ret == LOCATION_ERROR_NONE) priv->is_started = FALSE; - } - } - else { - if (location_setting_get_int(SENSOR_ENABLED) && - priv->mod->ops.start && !priv->is_started) { - LOCATION_LOGD("location resumed by setting"); - ret = priv->mod->ops.start (priv->mod->handler, sps_status_cb, sps_position_cb, sps_velocity_cb, self); - if (ret == LOCATION_ERROR_NONE) priv->is_started = TRUE; - } - } - -} - -static int -location_sps_start (LocationSps *self) -{ - LOCATION_LOGD("location_sps_start"); - LocationSpsPrivate* priv = GET_PRIVATE(self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.start, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.update_data, LOCATION_ERROR_NOT_AVAILABLE); - - if( priv->is_started == TRUE) return LOCATION_ERROR_NONE; - - int ret = LOCATION_ERROR_NONE; - int noti_err = 0; - - if (!location_setting_get_int(GPS_ENABLED) || !location_setting_get_int(SENSOR_ENABLED)) { - ret = LOCATION_ERROR_NOT_ALLOWED; - } - else { - ret = priv->mod->ops.start(priv->mod->handler, sps_status_cb, sps_position_cb, sps_velocity_cb, self); - if (ret == LOCATION_ERROR_NONE) { - priv->is_started = TRUE; - } - else { - return ret; - } - - priv->mod->ops.update_data(priv->mod->handler, priv->pos_base, priv->vel_base, priv->acc_info, priv->sat_info); - } - - if (priv->set_noti == FALSE) { - noti_err = location_setting_add_notify (GPS_ENABLED, location_setting_sps_cb, self); - if (noti_err != 0) { - return LOCATION_ERROR_UNKNOWN; - } - noti_err = location_setting_add_notify (SENSOR_ENABLED, location_setting_sps_cb, self); - if (noti_err != 0) { - return LOCATION_ERROR_UNKNOWN; - } - priv->set_noti = TRUE; - } - - return ret; -} - -static int -location_sps_stop (LocationSps *self) -{ - LOCATION_LOGD("location_sps_stop"); - LocationSpsPrivate* priv = GET_PRIVATE(self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.stop, LOCATION_ERROR_NOT_AVAILABLE); - - int ret = LOCATION_ERROR_NONE; - int noti_err = 0; - - if (priv->is_started == TRUE) { - ret = priv->mod->ops.stop (priv->mod->handler); - if (ret == LOCATION_ERROR_NONE) { - priv->is_started = FALSE; - } - else { - return ret; - } - } - - if (priv->set_noti == TRUE) { - noti_err = location_setting_ignore_notify (GPS_ENABLED, location_setting_sps_cb); - if (noti_err != 0) { - return LOCATION_ERROR_UNKNOWN; - } - noti_err = location_setting_ignore_notify (SENSOR_ENABLED, location_setting_sps_cb); - if (noti_err != 0) { - return LOCATION_ERROR_UNKNOWN; - } - priv->set_noti = FALSE; - } - - return ret; -} - -static void -location_sps_dispose (GObject *gobject) -{ - LOCATION_LOGD("location_sps_dispose"); - G_OBJECT_CLASS (location_sps_parent_class)->dispose (gobject); -} - -static void -location_sps_finalize (GObject *gobject) -{ - LOCATION_LOGD("location_sps_finalize"); - LocationSpsPrivate* priv = GET_PRIVATE(gobject); - module_free(priv->mod, "sps"); - priv->mod = NULL; - G_OBJECT_CLASS (location_sps_parent_class)->finalize (gobject); -} - -static void -location_sps_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - LocationSpsPrivate* priv = GET_PRIVATE(object); - - g_return_if_fail (priv->mod); - g_return_if_fail (priv->mod->handler); - LocModSpsOps ops = priv->mod->ops; - g_return_if_fail (ops.update_data); - - int ret = 0; - switch (property_id){ - case PROP_BOUNDARY:{ - GList *boundary_list = (GList *)g_list_copy(g_value_get_pointer(value)); - ret = set_prop_boundary(&priv->boundary_list, boundary_list); - if(ret != 0) LOCATION_LOGD("Set boundary. Error[%d]", ret); - break; - } - case PROP_REMOVAL_BOUNDARY: { - LocationBoundary *req_boundary = (LocationBoundary*) g_value_dup_boxed(value); - ret = set_prop_removal_boundary(&priv->boundary_list, req_boundary); - if(ret != 0) LOCATION_LOGD("Removal boundary. Error[%d]", ret); - break; - } - case PROP_POSITION_BASE:{ - if(priv->pos_base) location_position_free(priv->pos_base); - priv->pos_base = (LocationPosition*) g_value_dup_boxed (value); - LOCATION_LOGD("Set prop>> base position: \t%lf, %lf, %lf, time: %d", priv->pos_base->latitude, priv->pos_base->longitude, priv->pos_base->altitude, priv->pos_base->timestamp); - if (priv->is_started) ops.update_data (priv->mod->handler, priv->pos_base, priv->vel_base, priv->acc_info, priv->sat_info); - break; - } - case PROP_VELOCITY_BASE:{ - if(priv->vel_base) location_velocity_free(priv->vel_base); - priv->vel_base = (LocationVelocity*) g_value_dup_boxed (value); - LOCATION_LOGD("Set prop>> base velocity: \t%lf, %lf, %lf, time: %d", priv->vel_base->speed, priv->vel_base->direction, priv->vel_base->climb, priv->vel_base->timestamp); - if(priv->is_started) ops.update_data (priv->mod->handler, priv->pos_base, priv->vel_base, priv->acc_info, priv->sat_info); - break; - } - case PROP_ACCURACY_INFO:{ - if(priv->acc_info) location_accuracy_free(priv->acc_info); - priv->acc_info = (LocationAccuracy*) g_value_dup_boxed (value); - LOCATION_LOGD("Set prop>> accuracy information: \t%d, %lf, %lf", priv->acc_info->level, priv->acc_info->horizontal_accuracy, priv->acc_info->vertical_accuracy); - if(priv->is_started) ops.update_data (priv->mod->handler, priv->pos_base, priv->vel_base, priv->acc_info, priv->sat_info); - break; - } - case PROP_SATELLITE_INFO:{ - if(priv->sat_info) location_satellite_free(priv->sat_info); - priv->sat_info = (LocationSatellite*) g_value_dup_boxed (value); - LOCATION_LOGD("Set prop>> satellite information: \tNofView:%d, NofUsed:%d", priv->sat_info->num_of_sat_inview, priv->sat_info->num_of_sat_used); - if(priv->is_started) ops.update_data (priv->mod->handler, priv->pos_base, priv->vel_base, priv->acc_info, priv->sat_info); - break; - } - case PROP_UPDATE_INTERVAL: { - guint interval = g_value_get_uint(value); - if(interval > 0) { - if(interval < LOCATION_UPDATE_INTERVAL_MAX) - priv->interval = interval; - else - priv->interval = (guint)LOCATION_UPDATE_INTERVAL_MAX; - - } - else - priv->interval = (guint)LOCATION_UPDATE_INTERVAL_DEFAULT; - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -location_sps_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - LocationSpsPrivate *priv = GET_PRIVATE (object); - - switch (property_id){ - case PROP_METHOD_TYPE: - g_value_set_int(value, LOCATION_METHOD_SPS); - break; - case PROP_LAST_POSITION: - g_value_set_boxed (value, priv->pos); - break; - case PROP_BOUNDARY: - g_value_set_pointer(value, g_list_first(priv->boundary_list)); - break; - case PROP_POSITION_BASE: - g_value_set_boxed (value, priv->pos_base); - break; - case PROP_VELOCITY_BASE: - g_value_set_boxed (value, priv->vel_base); - break; - case PROP_ACCURACY_INFO: - g_value_set_boxed (value, priv->acc_info); - break; - case PROP_SATELLITE_INFO: - g_value_set_boxed (value, priv->sat_info); - break; - case PROP_UPDATE_INTERVAL: - g_value_set_uint(value, priv->interval); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static int -location_sps_get_position (LocationSps *self, - LocationPosition **position, - LocationAccuracy **accuracy) -{ - LOCATION_LOGD("location_sps_get_position"); - - LocationSpsPrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - setting_retval_if_fail(GPS_ENABLED); - setting_retval_if_fail(SENSOR_ENABLED); - - LocModSpsOps ops = priv->mod->ops; - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (ops.get_position, LOCATION_ERROR_NOT_AVAILABLE); - return ops.get_position(priv->mod->handler, position, accuracy); -} - -static int -location_sps_get_velocity (LocationSps *self, - LocationVelocity **velocity, - LocationAccuracy **accuracy) -{ - LOCATION_LOGD("location_sps_get_velocity"); - - LocationSpsPrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - setting_retval_if_fail(GPS_ENABLED); - setting_retval_if_fail(SENSOR_ENABLED); - - LocModSpsOps ops = priv->mod->ops; - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (ops.get_velocity, LOCATION_ERROR_NOT_AVAILABLE); - return ops.get_velocity(priv->mod->handler, velocity, accuracy); -} - -static void -location_ielement_interface_init (LocationIElementInterface *iface) -{ - iface->start = (TYPE_START_FUNC)location_sps_start; - iface->stop = (TYPE_STOP_FUNC)location_sps_stop; - iface->get_position = (TYPE_GET_POSITION)location_sps_get_position; - iface->get_velocity = (TYPE_GET_VELOCITY)location_sps_get_velocity; -} - -static void -location_sps_init (LocationSps *self) -{ - LOCATION_LOGD("location_sps_init"); - LocationSpsPrivate* priv = GET_PRIVATE(self); - - priv->mod = (LocationSpsMod*)module_new("sps"); - if(!priv->mod) - LOCATION_LOGW("module loading failed"); - - priv->is_started = FALSE; - priv->enabled= FALSE; - priv->interval = LOCATION_UPDATE_INTERVAL_DEFAULT; - priv->pos = NULL; - priv->vel = NULL; - priv->acc = NULL; - priv->zone_status = ZONE_STATUS_NONE; - priv->boundary_list = NULL; - - priv->pos_base = NULL; - priv->vel_base = NULL; - priv->acc_info = NULL; - priv->sat_info = NULL; -} - -static void -location_sps_class_init (LocationSpsClass *klass) -{ - LOCATION_LOGD("location_sps_class_init"); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->set_property = location_sps_set_property; - gobject_class->get_property = location_sps_get_property; - - gobject_class->dispose = location_sps_dispose; - gobject_class->finalize = location_sps_finalize; - - g_type_class_add_private (klass, sizeof (LocationSpsPrivate)); - - signals[SERVICE_ENABLED] = g_signal_new ("service-enabled", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationSpsClass, enabled), - NULL, NULL, - location_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - signals[SERVICE_DISABLED] = g_signal_new ("service-disabled", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationSpsClass, disabled), - NULL, NULL, - location_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - signals[SERVICE_UPDATED] = g_signal_new ("service-updated", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationSpsClass, updated), - NULL, NULL, - location_VOID__UINT_POINTER_POINTER, - G_TYPE_NONE, 3, - G_TYPE_UINT, - G_TYPE_POINTER, - G_TYPE_POINTER); - - signals[ZONE_IN] = g_signal_new ("zone-in", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationSpsClass, zone_in), - NULL, NULL, - location_VOID__UINT_POINTER_POINTER, - G_TYPE_NONE, 3, - G_TYPE_UINT, - G_TYPE_POINTER, - G_TYPE_POINTER); - - signals[ZONE_OUT] = g_signal_new ("zone-out", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationSpsClass, zone_out), - NULL, NULL, - location_VOID__UINT_POINTER_POINTER, - G_TYPE_NONE, 3, - G_TYPE_UINT, - G_TYPE_POINTER, - G_TYPE_POINTER); - - properties[PROP_METHOD_TYPE] = g_param_spec_int ("method", - "method type", - "location method type name", - LOCATION_METHOD_SPS, - LOCATION_METHOD_SPS, - LOCATION_METHOD_SPS, - G_PARAM_READABLE); - - properties[PROP_LAST_POSITION] = g_param_spec_boxed ("last-position", - "sps last position prop", - "sps last position data", - LOCATION_TYPE_POSITION, - G_PARAM_READABLE); - - properties[PROP_UPDATE_INTERVAL] = g_param_spec_uint ("update-interval", - "sps update interval prop", - "sps update interval data", - LOCATION_UPDATE_INTERVAL_MIN, - LOCATION_UPDATE_INTERVAL_MAX, - LOCATION_UPDATE_INTERVAL_DEFAULT, - G_PARAM_READWRITE); - - properties[PROP_BOUNDARY] = g_param_spec_pointer ("boundary", - "sps boundary prop", - "sps boundary data", - G_PARAM_READWRITE); - - properties[PROP_REMOVAL_BOUNDARY] = g_param_spec_boxed("removal-boundary", - "sps removal boundary prop", - "sps removal boundary data", - LOCATION_TYPE_BOUNDARY, - G_PARAM_READWRITE); - - properties[PROP_POSITION_BASE] = g_param_spec_boxed ("position-base", - "sps position base prop", - "sps position base data", - LOCATION_TYPE_POSITION, - G_PARAM_READWRITE); - - properties[PROP_VELOCITY_BASE] = g_param_spec_boxed ("velocity-base", - "sps velocity base prop", - "sps velocity base data", - LOCATION_TYPE_VELOCITY, - G_PARAM_READWRITE); - - properties[PROP_ACCURACY_INFO] = g_param_spec_boxed ("accuracy-info", - "sps accuracy information prop", - "sps accuracy information data", - LOCATION_TYPE_ACCURACY, - G_PARAM_READWRITE); - - properties[PROP_SATELLITE_INFO] = g_param_spec_boxed ("satellite-info", - "sps satellite information prop", - "sps satellite information data", - LOCATION_TYPE_SATELLITE, - G_PARAM_READWRITE); - - g_object_class_install_properties (gobject_class, - PROP_MAX, - properties); -} diff --git a/location/location-sps.h b/location/location-sps.h deleted file mode 100644 index 5d82a9a..0000000 --- a/location/location-sps.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * libslp-location - * - * 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_SPS_H__ -#define __LOCATION_SPS_H__ - -#include - -/** - * @file location-sps.h - * @brief This file contains the internal definitions and structures related to SPS. - * @addtogroup LocationInternal - * @{ - * @} - */ - -G_BEGIN_DECLS - -#define LOCATION_TYPE_SPS (location_sps_get_type ()) -#define LOCATION_SPS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_SPS, LocationSps)) -#define LOCATION_IS_SPS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_SPS)) -#define LOCATION_SPS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_SPS, LocationSpsClass)) -#define LOCATION_IS_SPS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_SPS)) -#define LOCATION_SPS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_SPS, LocationSpsClass)) - -typedef struct _LocationSps LocationSps; -typedef struct _LocationSpsClass LocationSpsClass; - -struct _LocationSps -{ - GObject parent_instance; -}; - -struct _LocationSpsClass -{ - GObjectClass parent_class; - - void (* enabled) (guint type); - void (* disabled) (guint type); - void (* updated) (guint type, gpointer data); - void (* zone_in) (guint type, gpointer position, gpointer boundary); - void (* zone_out) (guint type, gpointer position, gpointer boundary); -}; - -GType location_sps_get_type (void); - -G_END_DECLS - -#endif diff --git a/location/location-types.h b/location/location-types.h deleted file mode 100644 index ab0c147..0000000 --- a/location/location-types.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * libslp-location - * - * 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_TYPE_H__ -#define __LOCATION_TYPE_H__ - -#include -#include - -G_BEGIN_DECLS - -#ifndef LOCATION_DEPRECATED_API -#define LOCATION_DEPRECATED_API __attribute__ ((deprecated)) -#endif - -/** - * @file location-types.h - * @brief This file contains the Location related structure, enumeration, and asynchronous function definitions. - * @addtogroup LocationFW - * @{ - * @defgroup LocationTypes Location Types - * @brief This sub module provides structure, enumeration, and asynchronous function definitions. - * @addtogroup LocationTypes - * @{ - */ - -/** - * @brief This represents the returned error code of used functions. - */ -typedef enum { - LOCATION_ERROR_NONE = 0, ///< Success. - LOCATION_ERROR_NOT_ALLOWED, ///< Location servie is not allowed. - LOCATION_ERROR_NOT_AVAILABLE, ///< Location service is not available. - LOCATION_ERROR_NETWORK_FAILED, ///< Network is not available. - LOCATION_ERROR_NETWORK_NOT_CONNECTED, ///< Network is not connected. - LOCATION_ERROR_CONFIGURATION, ///< Configuration setting is not correct. - LOCATION_ERROR_PARAMETER, ///< Input parameter is not correct. - LOCATION_ERROR_NOT_FOUND, ///< Output is not found. - LOCATION_ERROR_UNKNOWN, ///< Unknown error. -} LocationError; - -/** - * @brief This represents location method to be used. - */ -typedef enum -{ - LOCATION_METHOD_NONE = -1, ///< Undefined method. - LOCATION_METHOD_HYBRID = 0, ///< This method selects best method. - LOCATION_METHOD_GPS, ///< This method uses Global Positioning System. - LOCATION_METHOD_WPS, ///< This method uses Wifi Positioning System. - LOCATION_METHOD_CPS, ///< This method uses cell ID of base station. - LOCATION_METHOD_IPS, ///< This method uses IP address. - LOCATION_METHOD_SPS ///< This method uses sensor. -} LocationMethod; - -/** - * @brief This represents the update type given by signal callback. - */ -typedef enum { - UPDATE_TYPE_NONE = -1, ///< Undefined update type. - POSITION_UPDATED = 0, ///< This type is used when position information is updated. - VELOCITY_UPDATED, ///< This type is used when velocity information is updated. - SATELLITE_UPDATED, ///< This type is used when satellite information is updated. - ADDRESS_UPDATED, ///< This type is used when address information is updated. This is not implemented yet. - GEOCODE_UPDATED, ///< This type is used when geocode information is updated. This is not implemented yet. - REVERSEGEOCODE_UPDATED ///< This type is used when reverse geocode information is updated. This is not implemented yet. -} LocationUpdateType; - -/** - * @brief Location object redefined by GObject. - */ -typedef GObject LocationObject; - -/** - * @brief This represents position information such as latitude-longitude-altitude values and timestamp. - */ -typedef struct _LocationPosition LocationPosition; - -/** - * @brief This represents last known position information such as latitude-longitude values and accuracy. - */ -typedef struct _LocationLastPosition LocationLastPosition; - -/** - * @brief This represents velocity information such as as speed, direction, climb. - */ -typedef struct _LocationVelocity LocationVelocity; - -/** - * @brief This represents location accuracy information such as accuracy level, horizontal and vertical accuracy. - */ -typedef struct _LocationAccuracy LocationAccuracy; - -/** - * @brief This represents address information such as building number, street name, etc. - */ -typedef struct _LocationAddress LocationAddress; - -/** - * @brief This represents boundary information such as rectangular or circle area. - */ -typedef struct _LocationBoundary LocationBoundary; - -/** - * @brief This represents position information such as number of satellites in used or in view. - */ -typedef struct _LocationSatellite LocationSatellite; - -/** - * @brief This represents a number of POI informations. - */ -typedef struct _LocationPOIInfo LocationPOIInfo; - -/** - * @brief This represents callback function which will be called to give position information. - */ -typedef void (*LocationPositionCB)(LocationError error, GList *position_list, GList *accuracy_list, gpointer userdata); - -/** - * @brief This represents callback function which will be called to give address information. - */ -typedef void (*LocationAddressCB)(LocationError error, LocationAddress *address, LocationAccuracy *acc, gpointer userdata); - -/** - * @brief This represents callback function which will be called to give POI information. - */ -typedef void (*LocationPOICB)(LocationError error, LocationPOIInfo *poi, gpointer userdata); - -/** - * @}@} - */ - -G_END_DECLS - -#endif /* __LOCATION_TYPE_H__ */ diff --git a/location/location-velocity.c b/location/location-velocity.c deleted file mode 100644 index fd7b523..0000000 --- a/location/location-velocity.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-velocity.h" -#include "location/location-log.h" - -GType -location_velocity_get_type (void) -{ - static volatile gsize type_volatile = 0; - if(g_once_init_enter(&type_volatile)) { - GType type = g_boxed_type_register_static ( - g_intern_static_string ("LocationVelocity"), - (GBoxedCopyFunc) location_velocity_copy, - (GBoxedFreeFunc) location_velocity_free); - g_once_init_leave(&type_volatile, type); - } - return type_volatile; -} - -EXPORT_API LocationVelocity* -location_velocity_new (guint timestamp, - gdouble speed, - gdouble direction, - gdouble climb) -{ - LocationVelocity* velocity = g_slice_new0(LocationVelocity); - velocity->timestamp = timestamp; - velocity->speed = speed; - velocity->direction = direction; - velocity->climb = climb; - return velocity; -} - -EXPORT_API void -location_velocity_free (LocationVelocity* velocity) -{ - g_return_if_fail(velocity); - g_slice_free(LocationVelocity, velocity); -} - -EXPORT_API gboolean -location_velocity_equal (const LocationVelocity *velocity1, const LocationVelocity *velocity2) -{ - g_return_val_if_fail(velocity1, FALSE); - g_return_val_if_fail(velocity2, FALSE); - - if (velocity1->timestamp == velocity2->timestamp && - velocity1->speed == velocity2->speed && - velocity1->direction == velocity2->direction && - velocity1->climb == velocity2->climb) - return TRUE; - return FALSE; -} - -EXPORT_API LocationVelocity* -location_velocity_copy (const LocationVelocity *velocity) -{ - g_return_val_if_fail(velocity, NULL); - - LocationVelocity *new_velocity = NULL; - - new_velocity = location_velocity_new(velocity->timestamp, - velocity->speed, - velocity->direction, - velocity->climb); - if(new_velocity) new_velocity->updated_timestamp = velocity->updated_timestamp; - - return new_velocity; -} diff --git a/location/location-velocity.h b/location/location-velocity.h deleted file mode 100644 index 5dc1c81..0000000 --- a/location/location-velocity.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * libslp-location - * - * 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_VELOCITY_H_ -#define __LOCATION_VELOCITY_H_ - -#include - -/** - * @file location-velocity.h - * @brief This file contains the internal definitions and structures related to velocity information. - * @addtogroup LocationTypes - * @{ - */ - -G_BEGIN_DECLS - -/** - * @brief This represents velocity information such as as speed, direction, climb. - */ -struct _LocationVelocity -{ - guint timestamp; ///< Time stamp. - guint updated_timestamp; ///< The latest updated time stamp. - gdouble speed; ///< The speed over ground. (km/h) - gdouble direction; ///< The course made in degrees relative to true north. The value is always in the range [0.0, 360.0] degree. - gdouble climb; ///< The vertical speed. (km/h) -}; - -GType location_velocity_get_type (void); -#define LOCATION_TYPE_VELOCITY (location_velocity_get_type ()) - -/** - * @brief Create a new #LocationVelocity with given information. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] timestamp - Time stamp. - * @param [in] speed - The speed over ground. (km/h) - * @param [in] direction - The course made in degrees relative to true north. The value is always in the range [0.0, 360.0] degree. - * @param [in] climb - The vertical speed. (km/h) - * @return a new #LocationVelocity - * @retval NULL if error occured - */ -LocationVelocity *location_velocity_new (guint timestamp, gdouble speed, gdouble direction, gdouble climb); - -/** - * @brief Free a #LocationVelocity. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] velocity - a #LocationVelocity. - * @return None. - */ -void location_velocity_free (LocationVelocity *velocity); - -/** - * @brief Compares two velocities for equality, returning TRUE if they are equal. - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] velocity1 - a #LocationVelocity - * @param [in] velocity2 - a #LocationVelocity - * @return gboolean - * @retval\n - * TRUE - if equal\n - * FALSE - if not equal\n - */ -gboolean location_velocity_equal (const LocationVelocity *velocity1, const LocationVelocity *velocity2); - -/** - * @brief Makes a copy of #LocationVelocity - * @remarks None. - * @pre #location_init should be called before.\n - * @post None. - * @param [in] velocity - a #LocationVelocity - * @return a new #LocationVelocity - * @retval NULL if error occured - */ -LocationVelocity *location_velocity_copy (const LocationVelocity *velocity); - -/** - * @} - */ - -G_END_DECLS - -#endif diff --git a/location/location-wps.c b/location/location-wps.c deleted file mode 100644 index 8d11352..0000000 --- a/location/location-wps.c +++ /dev/null @@ -1,476 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "location/location-setting.h" -#include "location/location-log.h" - -#include "location/location-module-internal.h" - -#include "location/location-wps.h" -#include "location/location-marshal.h" -#include "location/location-ielement.h" -#include "location/location-signaling-util.h" -#include "location/location-common-util.h" -/* - * forward definitions - */ - -typedef struct _LocationWpsPrivate { - LocationWpsMod* mod; - gboolean is_started; - gboolean set_noti; - gboolean enabled; - guint interval; - LocationPosition *pos; - LocationVelocity *vel; - LocationAccuracy *acc; - GList *boundary_list; - ZoneStatus zone_status; -} LocationWpsPrivate; - -enum { - PROP_0, - PROP_METHOD_TYPE, - PROP_LAST_POSITION, - PROP_UPDATE_INTERVAL, - PROP_BOUNDARY, - PROP_REMOVAL_BOUNDARY, - PROP_MAX -}; - -static guint32 signals[LAST_SIGNAL] = {0, }; -static GParamSpec *properties[PROP_MAX] = {NULL, }; - -#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_WPS, LocationWpsPrivate)) - -static void location_ielement_interface_init (LocationIElementInterface *iface); - -G_DEFINE_TYPE_WITH_CODE (LocationWps, location_wps, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, - location_ielement_interface_init)); - -static void -wps_status_cb (gboolean enabled, - LocationStatus status, - gpointer self) -{ - LOCATION_LOGD("wps_status_cb"); - g_return_if_fail(self); - LocationWpsPrivate* priv = GET_PRIVATE(self); - enable_signaling(self, signals, &(priv->enabled), enabled, status); -} - -static void -wps_position_cb (gboolean enabled, - LocationPosition *pos, - LocationAccuracy *acc, - gpointer self) -{ - LOCATION_LOGD("wps_position_cb"); - g_return_if_fail(self); - g_return_if_fail(pos); - g_return_if_fail(acc); - LocationWpsPrivate* priv = GET_PRIVATE(self); - enable_signaling(self, signals, &(priv->enabled), enabled, pos->status); - position_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->pos), &(priv->acc), priv->boundary_list, &(priv->zone_status), enabled, pos, acc); -} - -static void -wps_velocity_cb(gboolean enabled, - LocationVelocity *vel, - LocationAccuracy *acc, - gpointer self) -{ - LOCATION_LOGD("wps_velocity_cb"); - g_return_if_fail(self); - LocationWpsPrivate* priv = GET_PRIVATE(self); - velocity_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->vel), enabled, vel, acc); -} - -static void -location_setting_wps_cb(keynode_t *key, - gpointer self) -{ - LOCATION_LOGD("location_setting_wps_cb"); - g_return_if_fail(key); - g_return_if_fail(self); - LocationWpsPrivate* priv = GET_PRIVATE(self); - g_return_if_fail (priv->mod); - g_return_if_fail (priv->mod->handler); - - int ret = LOCATION_ERROR_NONE; - - if (location_setting_get_key_val(key) == 0) { - if (priv->mod->ops.stop && priv->is_started) { - ret = priv->mod->ops.stop(priv->mod->handler); - if (ret == LOCATION_ERROR_NONE) priv->is_started = FALSE; - } - } - else { - if (1 == location_setting_get_int(NETWORK_ENABLED) && priv->mod->ops.start && !priv->is_started) { - LOCATION_LOGD("location resumed by setting"); - ret = priv->mod->ops.start (priv->mod->handler, wps_status_cb, wps_position_cb, wps_velocity_cb, self); - if (ret == LOCATION_ERROR_NONE) priv->is_started = TRUE; - } - } - -} - -static int -location_wps_start (LocationWps *self) -{ - LOCATION_LOGD("location_wps_start"); - LocationWpsPrivate* priv = GET_PRIVATE(self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.start, LOCATION_ERROR_NOT_AVAILABLE); - - if (priv->is_started == TRUE) return LOCATION_ERROR_NONE; - - int ret = LOCATION_ERROR_NONE; - int noti_err = 0; - - if (!location_setting_get_int(GPS_ENABLED) || !location_setting_get_int(NETWORK_ENABLED)) { - ret = LOCATION_ERROR_NOT_ALLOWED; - } - else { - ret = priv->mod->ops.start (priv->mod->handler, wps_status_cb, wps_position_cb, wps_velocity_cb, self); - if (ret == LOCATION_ERROR_NONE) { - priv->is_started = TRUE; - } - else { - return ret; - } - } - - if (priv->set_noti == FALSE) { - noti_err = location_setting_add_notify (GPS_ENABLED, location_setting_wps_cb, self); - if (noti_err != 0) { - return LOCATION_ERROR_UNKNOWN; - } - noti_err = location_setting_add_notify (NETWORK_ENABLED, location_setting_wps_cb, self); - if (noti_err != 0) { - return LOCATION_ERROR_UNKNOWN; - } - priv->set_noti = TRUE; - } - - return ret; -} - -static int -location_wps_stop (LocationWps *self) -{ - LOCATION_LOGD("location_wps_stop"); - LocationWpsPrivate* priv = GET_PRIVATE(self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (priv->mod->ops.stop, LOCATION_ERROR_NOT_AVAILABLE); - - int ret = LOCATION_ERROR_NONE; - int noti_err = 0; - - if (priv->is_started == TRUE) { - ret = priv->mod->ops.stop (priv->mod->handler); - if (ret == LOCATION_ERROR_NONE) { - priv->is_started = FALSE; - } - else { - return ret; - } - } - - if (priv->set_noti == TRUE) { - noti_err = location_setting_ignore_notify (GPS_ENABLED, location_setting_wps_cb); - if (noti_err != 0) { - return LOCATION_ERROR_UNKNOWN; - } - noti_err = location_setting_ignore_notify (NETWORK_ENABLED, location_setting_wps_cb); - if (noti_err != 0) { - return LOCATION_ERROR_UNKNOWN; - } - priv->set_noti = FALSE; - } - - return ret; -} - -static void -location_wps_dispose (GObject *gobject) -{ - LOCATION_LOGD("location_wps_dispose"); - G_OBJECT_CLASS (location_wps_parent_class)->dispose (gobject); -} - -static void -location_wps_finalize (GObject *gobject) -{ - LOCATION_LOGD("location_wps_finalize"); - LocationWpsPrivate* priv = GET_PRIVATE(gobject); - module_free(priv->mod, "wps"); - G_OBJECT_CLASS (location_wps_parent_class)->finalize (gobject); -} - -static void -location_wps_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - LocationWpsPrivate* priv = GET_PRIVATE(object); - int ret = 0; - - switch (property_id){ - case PROP_BOUNDARY:{ - GList *boundary_list = (GList *)g_list_copy(g_value_get_pointer(value)); - ret = set_prop_boundary(&priv->boundary_list, boundary_list); - if(ret != 0) LOCATION_LOGD("Set boundary. Error[%d]", ret); - break; - } - case PROP_REMOVAL_BOUNDARY: { - LocationBoundary *req_boundary = (LocationBoundary*) g_value_dup_boxed(value); - ret = set_prop_removal_boundary(&priv->boundary_list, req_boundary); - if(ret != 0) LOCATION_LOGD("Set removal boundary. Error[%d]", ret); - break; - } - case PROP_UPDATE_INTERVAL: { - guint interval = g_value_get_uint(value); - if(interval > 0) { - if(interval < LOCATION_UPDATE_INTERVAL_MAX) - priv->interval = interval; - else - priv->interval = (guint)LOCATION_UPDATE_INTERVAL_MAX; - } - else - priv->interval = (guint)LOCATION_UPDATE_INTERVAL_DEFAULT; - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -location_wps_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - LocationWpsPrivate *priv = GET_PRIVATE (object); - - switch (property_id){ - case PROP_METHOD_TYPE: - g_value_set_int(value, LOCATION_METHOD_WPS); - break; - case PROP_LAST_POSITION: - g_value_set_boxed (value, priv->pos); - break; - case PROP_BOUNDARY: - g_value_set_pointer(value, g_list_first(priv->boundary_list)); - break; - case PROP_UPDATE_INTERVAL: - g_value_set_uint(value, priv->interval); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static int -location_wps_get_position (LocationWps *self, - LocationPosition **position, - LocationAccuracy **accuracy) -{ - LOCATION_LOGD("location_wps_get_position"); - - LocationWpsPrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - setting_retval_if_fail(GPS_ENABLED); - setting_retval_if_fail(NETWORK_ENABLED); - - LocModWpsOps ops = priv->mod->ops; - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (ops.get_position, LOCATION_ERROR_NOT_AVAILABLE); - return ops.get_position(priv->mod->handler, position, accuracy); -} - -static int -location_wps_get_velocity (LocationWps *self, - LocationVelocity **velocity, - LocationAccuracy **accuracy) -{ - LOCATION_LOGD("location_wps_get_velocity"); - - LocationWpsPrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); - setting_retval_if_fail(GPS_ENABLED); - setting_retval_if_fail(NETWORK_ENABLED); - - LocModWpsOps ops = priv->mod->ops; - g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (ops.get_velocity, LOCATION_ERROR_NOT_AVAILABLE); - return ops.get_velocity(priv->mod->handler, velocity, accuracy); -} - -static void -location_ielement_interface_init (LocationIElementInterface *iface) -{ - iface->start = (TYPE_START_FUNC)location_wps_start; - iface->stop = (TYPE_STOP_FUNC)location_wps_stop; - iface->get_position = (TYPE_GET_POSITION)location_wps_get_position; - iface->get_velocity = (TYPE_GET_VELOCITY)location_wps_get_velocity; -} - -static void -location_wps_init (LocationWps *self) -{ - LOCATION_LOGD("location_wps_init"); - LocationWpsPrivate* priv = GET_PRIVATE(self); - - priv->mod = (LocationWpsMod*)module_new("wps"); - if(!priv->mod) LOCATION_LOGW("module loading failed"); - - priv->is_started = FALSE; - priv->set_noti = FALSE; - priv->enabled= FALSE; - priv->interval = LOCATION_UPDATE_INTERVAL_DEFAULT; - - priv->pos = NULL; - priv->vel = NULL; - priv->acc = NULL; - priv->zone_status = ZONE_STATUS_NONE; - priv->boundary_list = NULL; -} - -static void -location_wps_class_init (LocationWpsClass *klass) -{ - LOCATION_LOGD("location_wps_class_init"); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->set_property = location_wps_set_property; - gobject_class->get_property = location_wps_get_property; - - gobject_class->dispose = location_wps_dispose; - gobject_class->finalize = location_wps_finalize; - - g_type_class_add_private (klass, sizeof (LocationWpsPrivate)); - - signals[SERVICE_ENABLED] = g_signal_new ("service-enabled", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationWpsClass, enabled), - NULL, NULL, - location_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - signals[SERVICE_DISABLED] = g_signal_new ("service-disabled", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationWpsClass, disabled), - NULL, NULL, - location_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - signals[SERVICE_UPDATED] = g_signal_new ("service-updated", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationWpsClass, updated), - NULL, NULL, - location_VOID__UINT_POINTER_POINTER, - G_TYPE_NONE, 3, - G_TYPE_UINT, - G_TYPE_POINTER, - G_TYPE_POINTER); - - signals[ZONE_IN] = g_signal_new ("zone-in", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationWpsClass, zone_in), - NULL, NULL, - location_VOID__UINT_POINTER_POINTER, - G_TYPE_NONE, 3, - G_TYPE_UINT, - G_TYPE_POINTER, - G_TYPE_POINTER); - - signals[ZONE_OUT] = g_signal_new ("zone-out", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | - G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (LocationWpsClass, zone_out), - NULL, NULL, - location_VOID__UINT_POINTER_POINTER, - G_TYPE_NONE, 3, - G_TYPE_UINT, - G_TYPE_POINTER, - G_TYPE_POINTER); - - properties[PROP_METHOD_TYPE] = g_param_spec_int ("method", - "method type", - "location method type name", - LOCATION_METHOD_WPS, - LOCATION_METHOD_WPS, - LOCATION_METHOD_WPS, - G_PARAM_READABLE); - - properties[PROP_LAST_POSITION] = g_param_spec_boxed ("last-position", - "wps last position prop", - "wps last position data", - LOCATION_TYPE_POSITION, - G_PARAM_READABLE); - - properties[PROP_UPDATE_INTERVAL] = g_param_spec_uint ("update-interval", - "wps update interval prop", - "wps update interval data", - LOCATION_UPDATE_INTERVAL_MIN, - LOCATION_UPDATE_INTERVAL_MAX, - LOCATION_UPDATE_INTERVAL_DEFAULT, - G_PARAM_READWRITE); - - properties[PROP_BOUNDARY] = g_param_spec_pointer ("boundary", - "wps boundary prop", - "wps boundary data", - G_PARAM_READWRITE); - - properties[PROP_REMOVAL_BOUNDARY] = g_param_spec_boxed("removal-boundary", - "wps removal boundary prop", - "wps removal boundary data", - LOCATION_TYPE_BOUNDARY, - G_PARAM_READWRITE); - - g_object_class_install_properties (gobject_class, - PROP_MAX, - properties); -} - diff --git a/location/location-wps.h b/location/location-wps.h deleted file mode 100644 index 77ec679..0000000 --- a/location/location-wps.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * libslp-location - * - * 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_WPS_H__ -#define __LOCATION_WPS_H__ - -#include - -/** - * @file location-wps.h - * @brief This file contains the internal definitions and structures related to WPS. - * @addtogroup LocationInternal - * @{ - * @} - */ - -G_BEGIN_DECLS - -#define LOCATION_TYPE_WPS (location_wps_get_type ()) -#define LOCATION_WPS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_WPS, LocationWps)) -#define LOCATION_IS_WPS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_WPS)) -#define LOCATION_WPS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_WPS, LocationWpsClass)) -#define LOCATION_IS_WPS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_WPS)) -#define LOCATION_WPS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_WPS, LocationWpsClass)) - -typedef struct _LocationWps LocationWps; -typedef struct _LocationWpsClass LocationWpsClass; - -struct _LocationWps -{ - GObject parent_instance; -}; - -struct _LocationWpsClass -{ - GObjectClass parent_class; - - void (* enabled) (guint type); - void (* disabled) (guint type); - void (* updated) (guint type, gpointer data); - void (* zone_in) (guint type, gpointer position, gpointer boundary); - void (* zone_out) (guint type, gpointer position, gpointer boundary); -}; - -GType location_wps_get_type (void); - -G_END_DECLS - -#endif diff --git a/location/location.c b/location/location.c deleted file mode 100644 index 637aef5..0000000 --- a/location/location.c +++ /dev/null @@ -1,473 +0,0 @@ -/* - * libslp-location - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "location/location.h" -#include "location/location-log.h" -#include "location/location-setting.h" -#include "location/location-module-internal.h" -#include "location/location-ielement.h" -#include "location/location-hybrid.h" -#include "location/location-gps.h" -#include "location/location-wps.h" -#include "location/location-ips.h" -#include "location/location-cps.h" -#include "location/location-sps.h" -#include "location/location-geocode.h" -#include "location/location-poi.h" -#include "location/location-position.h" - -static LocationObject *geocode = NULL; -static LocationObject *poi = NULL; - -static gboolean -is_connected_network() -{ - gboolean is_connected = TRUE; - int net_state = 0; - - net_state = location_setting_get_int(VCONFKEY_NETWORK_STATUS); - - LOCATION_LOGW("net_state[%d]", net_state); - if(net_state == VCONFKEY_NETWORK_OFF) { - is_connected = FALSE; - } - - return is_connected; - -} - -EXPORT_API int location_init (void) -{ - LOCATION_LOGD("location_init"); - g_type_init (); - if( FALSE == module_init() ) - return LOCATION_ERROR_NOT_AVAILABLE; - - return LOCATION_ERROR_NONE; -} - -EXPORT_API LocationObject* -location_new (LocationMethod method) -{ - LocationObject *self = NULL; - - if (!geocode) - geocode = g_object_new (LOCATION_TYPE_GEOCODE, NULL); - - /*if (!poi) - poi = g_object_new (LOCATION_TYPE_POI, NULL);*/ - - switch (method) { - case LOCATION_METHOD_HYBRID: - self = g_object_new (LOCATION_TYPE_HYBRID, NULL); - break; - case LOCATION_METHOD_GPS: - self = g_object_new (LOCATION_TYPE_GPS, NULL); - break; - case LOCATION_METHOD_WPS: - self = g_object_new (LOCATION_TYPE_WPS, NULL); - break; - case LOCATION_METHOD_CPS: - self = g_object_new (LOCATION_TYPE_CPS, NULL); - break; - case LOCATION_METHOD_IPS: - self = g_object_new (LOCATION_TYPE_IPS, NULL); - break; - case LOCATION_METHOD_SPS: - self = g_object_new (LOCATION_TYPE_SPS, NULL); - break; - default: - break; - } - return self; -} - -EXPORT_API int -location_free (LocationObject *obj) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - - //location_ielement_stop(LOCATION_IELEMENT(obj)); - if (geocode) { - g_object_unref (geocode); - geocode = NULL; - } - /*if (poi) { - g_object_unref (poi); - poi = NULL; - }*/ - g_object_unref (obj); - return LOCATION_ERROR_NONE; -} - -EXPORT_API int -location_start (LocationObject *obj) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - return location_ielement_start (LOCATION_IELEMENT(obj)); -} - -EXPORT_API int -location_stop (LocationObject *obj) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - return location_ielement_stop (LOCATION_IELEMENT(obj)); -} - -EXPORT_API gboolean -location_is_supported_method(LocationMethod method) -{ - gboolean is_supported = FALSE; - - switch(method) { - case LOCATION_METHOD_HYBRID: - if(module_is_supported("gps") || module_is_supported("wps") || module_is_supported("sps")) - is_supported = TRUE; - break; - case LOCATION_METHOD_GPS: - is_supported = module_is_supported("gps"); - break; - case LOCATION_METHOD_WPS: - is_supported = module_is_supported("wps"); - break; - case LOCATION_METHOD_SPS: - is_supported = module_is_supported("sps"); - break; - case LOCATION_METHOD_CPS: - case LOCATION_METHOD_IPS: - default: - break; - } - - return is_supported; -} - -EXPORT_API gboolean -location_is_enabled_gps(LocationObject *obj) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - - return (gboolean) location_setting_get_int(GPS_ENABLED); -} - -EXPORT_API int -location_get_position (LocationObject *obj, - LocationPosition **position, - LocationAccuracy **accuracy) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER); - return location_ielement_get_position (LOCATION_IELEMENT(obj), position, accuracy); -} - -EXPORT_API int -location_get_last_position (LocationObject *obj, LocationMethod method, - LocationPosition **position, - LocationAccuracy **accuracy) -{ - g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER); - - return LOCATION_ERROR_NONE; -} - -EXPORT_API int -location_get_last_known_position (LocationObject *obj, LocationMethod method, - LocationLastPosition *last_position) -{ - g_return_val_if_fail (last_position, LOCATION_ERROR_PARAMETER); - - LocationMethod redefined_method = method; - - if (!obj) redefined_method = LOCATION_METHOD_HYBRID; - - if (redefined_method == LOCATION_METHOD_HYBRID) { - int gps_timestamp = 0, wps_timestamp = 0, sps_timestamp = 0; - int latest_timestamp = 0; - - redefined_method = LOCATION_METHOD_SPS; - vconf_get_int(GPS_LAST_TIMESTAMP, &gps_timestamp); - vconf_get_int(WPS_LAST_TIMESTAMP, &wps_timestamp); - vconf_get_int(SPS_LAST_TIMESTAMP, &sps_timestamp); - - redefined_method = LOCATION_METHOD_SPS; - latest_timestamp = sps_timestamp; - if (gps_timestamp > sps_timestamp) { - redefined_method = LOCATION_METHOD_GPS; - latest_timestamp = gps_timestamp; - } - - if (wps_timestamp > latest_timestamp) { - redefined_method = LOCATION_METHOD_WPS; - } - - } - - if (get_last_known_position (redefined_method, last_position)) { - return LOCATION_ERROR_UNKNOWN; - } - - return LOCATION_ERROR_NONE; -} - -EXPORT_API int -location_get_satellite (LocationObject *obj, LocationSatellite **satellite) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (satellite, LOCATION_ERROR_PARAMETER); - - return LOCATION_ERROR_NONE;; -} - -EXPORT_API int -location_get_last_satellite (LocationObject *obj, LocationSatellite **satellite) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (satellite, LOCATION_ERROR_PARAMETER); - - return LOCATION_ERROR_NONE;; -} - -EXPORT_API int -location_get_position_from_address (LocationObject *obj, - const LocationAddress *address, - GList **position_list, - GList **accuracy_list) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - return location_ielement_get_geocode (LOCATION_IELEMENT(geocode), address, position_list, accuracy_list); -} - -EXPORT_API int -location_get_position_from_freeformed_address (LocationObject *obj, - const gchar *address, - GList **position_list, - GList **accuracy_list) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - return location_ielement_get_geocode_freeform (LOCATION_IELEMENT(geocode), address, position_list, accuracy_list); -} - -EXPORT_API int -location_get_velocity (LocationObject *obj, - LocationVelocity **velocity, - LocationAccuracy **accuracy) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER); - - return location_ielement_get_velocity (LOCATION_IELEMENT(obj), velocity, accuracy); -} - -EXPORT_API int -location_get_last_velocity (LocationObject *obj, - LocationVelocity **velocity, - LocationAccuracy **accuracy) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER); - return LOCATION_ERROR_NONE; -} - -EXPORT_API int -location_get_address (LocationObject *obj, - LocationAddress **address, - LocationAccuracy **accuracy) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - - LocationPosition *position = NULL; - int ret = location_ielement_get_position(LOCATION_IELEMENT (obj), &position, accuracy); - if (LOCATION_ERROR_NONE != ret) return ret; - ret = location_ielement_get_reversegeocode (LOCATION_IELEMENT(geocode), position, address, accuracy); - location_position_free (position); - return ret; -} - -EXPORT_API int -location_get_address_from_position (LocationObject *obj, - const LocationPosition *position, - LocationAddress **address, - LocationAccuracy **accuracy) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - return location_ielement_get_reversegeocode (LOCATION_IELEMENT(geocode), position, address, accuracy); -} - -EXPORT_API int -location_get_position_from_address_async (LocationObject *obj, - const LocationAddress *address, - LocationPositionCB callback, - gpointer userdata) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - return location_ielement_get_geocode_async (LOCATION_IELEMENT(geocode), address, callback, userdata); -} - - -EXPORT_API int -location_get_position_from_freeformed_address_async (LocationObject *obj, - const gchar *address, - LocationPositionCB callback, - gpointer userdata) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - return location_ielement_get_geocode_freeform_async (LOCATION_IELEMENT(geocode), address, callback, userdata); -} - -EXPORT_API int -location_get_address_async (LocationObject *obj, - LocationAddressCB callback, - gpointer userdata) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - - LocationPosition *position = NULL; - LocationAccuracy *acc = NULL; - int ret = location_ielement_get_position(LOCATION_IELEMENT(obj), &position, &acc); - if (LOCATION_ERROR_NONE != ret) return ret; - ret = location_ielement_get_reversegeocode_async (LOCATION_IELEMENT(geocode), position, callback, userdata); - location_position_free (position); - return ret; -} - -EXPORT_API int -location_get_address_from_position_async (LocationObject *obj, - const LocationPosition *position, - LocationAddressCB callback, - gpointer userdata) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - return location_ielement_get_reversegeocode_async (LOCATION_IELEMENT(geocode), position, callback, userdata); -} - -EXPORT_API int -location_get_poi (LocationObject *obj, - gdouble radius, - const gchar *keyword, - LocationPOIInfo **poi_info) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (poi, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - return location_ielement_get_poi(LOCATION_IELEMENT(poi), radius, keyword, poi_info); -} - -EXPORT_API int -location_get_poi_from_address(LocationObject *obj, - const LocationAddress *address, - gdouble radius, - const gchar *keyword, - LocationPOIInfo **poi_info) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (poi, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - return location_ielement_get_poi_from_address(LOCATION_IELEMENT(poi), address, radius, keyword, poi_info); -} - -EXPORT_API int -location_get_poi_from_position(LocationObject *obj, - const LocationPosition *position, - gdouble radius, - const gchar *keyword, - LocationPOIInfo **poi_info) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (poi, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - return location_ielement_get_poi_from_position(LOCATION_IELEMENT(poi), position, radius, keyword, poi_info); -} - -EXPORT_API int -location_get_poi_async (LocationObject *obj, - gdouble radius, - const gchar *keyword, - LocationPOICB callback, - gpointer userdata) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (poi, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - return location_ielement_get_poi_async(LOCATION_IELEMENT(poi), radius, keyword, callback, userdata); -} - -EXPORT_API int -location_get_poi_from_address_async (LocationObject *obj, - const LocationAddress *address, - gdouble radius, - const gchar *keyword, - LocationPOICB callback, - gpointer userdata) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (poi, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - return location_ielement_get_poi_from_address_async(LOCATION_IELEMENT(poi), address, radius, keyword, callback, userdata); -} - -EXPORT_API int -location_get_poi_from_position_async (LocationObject *obj, - const LocationPosition *position, - gdouble radius, - const gchar*keyword, - LocationPOICB callback, - gpointer userdata) -{ - g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); - g_return_val_if_fail (poi, LOCATION_ERROR_NOT_AVAILABLE); - g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); - return location_ielement_get_poi_from_position_async(LOCATION_IELEMENT(poi), position, radius, keyword, callback, userdata); -} - -EXPORT_API int -location_send_command(const char *cmd) -{ - g_return_val_if_fail (cmd, LOCATION_ERROR_PARAMETER); - - return LOCATION_ERROR_NONE; -} - diff --git a/location/location.h b/location/location.h deleted file mode 100644 index 42f6f58..0000000 --- a/location/location.h +++ /dev/null @@ -1,1442 +0,0 @@ -/* - * libslp-location - * - * 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_H__ -#define __LOCATION_H__ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -G_BEGIN_DECLS - -/** - * @file location.h - * @brief This file contains the Location API and related structure and enumeration. - */ -/** - * @defgroup LocationFW LocationFW - * @brief This is a Locatoin Framework for providing location based services. - * @addtogroup LocationFW - * @{ - * @defgroup LocationAPI Location API - * @brief This sub module provides the Location API. - * @addtogroup LocationAPI - * @{ - */ - -/** - * @brief - * Initialize location sub module. - * @remarks None. - * This API should be called before any other Location APIs. - * @pre None. - * @post None. - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @see None. - * @par Example - * @code -#include -int main (int argc, char *argv[]) -{ - location_init(); - // Now you can use any other Location APIs. - return 0; -} - * @endcode - */ -int location_init (void); - -/** - * @brief - * Create a new #LocationObject by using given #LocationMethod. - * @remarks - * Returned object is necessary for other APIs. - * @pre - * #location_init should be called before. - * @post None. - * @param [in] - * method - Location method to be used. - * @return a new #LocationObject - * @retval NULL if error occured - * @see location_free - * @par Example - * @code -#include -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - location_init (); - - loc = location_new (LOCATION_METHOD_GPS); - if(!loc) - return -1; - // You can use new location object now. - return 0; -} - * @endcode - */ -LocationObject *location_new (LocationMethod method); - -/** - * @brief - * Free memory of given #LocationObject. - * @remarks None. - * @pre - * #location_init should be called before. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new. - * @return int - * @retval 0 Success. - * - * Please refer #LocationError for more information. - * @see location_new - * @par Example - * @code -#include -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - location_init (); - loc = location_new (LOCATION_METHOD_GPS); - if(!loc) - return -1; - - location_free (loc); - // You can not use location object anymore. - return 0; -} - * @endcode - */ -int location_free (LocationObject *obj); - -/** - * @brief - * Start the location service by using given #LocationObject. - * @remarks - * If you want to recieve signals, you should use this API. - * @pre - * #location_init should be called before. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @return int - * @retval 0 Success. - * - * Please refer #LocationError for more information. - * @see location_stop - * @par Example - * @code -#include -static GMainLoop *loop = NULL; - -static void cb_service_enabled (GObject *self, guint status, gpointer userdata) -{ - LocationObject *loc = (LocationObject*)userdata; - LocationAccuracy *acc = NULL; - LocationPosition *pos = NULL; - LocationVelocity *vel = NULL; - LocationAddress *addr = NULL; - LocationMethod method; - - g_object_get(loc, "method", &method, NULL); - g_debug("Get property>> method:%d", method); - - if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) { - g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d", - pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", - acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - location_position_free(pos); - location_accuracy_free(acc); - } else g_warning ("SYNC>> Current position> failed"); - - if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) { - g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f", - vel->timestamp, vel->speed, vel->direction, vel->climb); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", - acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - location_velocity_free(vel); - location_accuracy_free(acc); - } else g_warning ("SYNC>> Current velocity> failed"); - - if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) { - g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s", - addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - location_address_free(addr); - location_accuracy_free(acc); - } else g_warning ("SYNC>> Current address> failed"); -} - -static void -cb_service_updated (GObject *self, - guint type, - gpointer data, - gpointer accuracy, - gpointer userdata) -{ - LocationAccuracy *acc = (LocationAccuracy*) accuracy; - switch (type) { - case POSITION_UPDATED: { - LocationPosition *pos = (LocationPosition*) data; - g_debug ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d", - pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", - acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - } - break; - case VELOCITY_UPDATED: { - LocationVelocity *vel = (LocationVelocity*) data; - g_debug ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f", - vel->timestamp, vel->speed, vel->direction, vel->climb); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", - acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - } - break; - default: - g_warning ("ASYNC>> Undefined update type"); - break; - } -} - - -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - int interval = 6; //seconds - location_init (); - - loc = location_new (LOCATION_METHOD_GPS); - if(!loc) - return -1; - - g_object_set(loc, "update-interval", interval, NULL); - - g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc); - g_signal_connect (loc, "service-updated", G_CALLBACK(cb_service_updated), loc); - - location_start(loc); - loop = g_main_loop_new (NULL, TRUE); - g_main_loop_run (loop); // GMainLoop is needed for receiving signals. - - // ... - return 0; -} -* @endcode -*/ -int location_start (LocationObject *obj); - -/** - * @brief - * Stop the location service by using given #LocationObject. - * @remarks - * After call this API, you can not recieve signals. - * @pre - * #location_init should be called before.\n - * #location_start should be called before. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @see location_start - * @par Example - * @code -#include -static GMainLoop *loop = NULL; - -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - location_init (); - loc = location_new (LOCATION_METHOD_GPS); - if(!loc) - return -1; - - location_start(loc); - loop = g_main_loop_new (NULL, TRUE); - g_main_loop_run (loop); - - // .... - - location_stop (loc); - // you can not receive signals anymore. - return 0; -} - * @endcode - */ -int location_stop (LocationObject *obj); - -/** - * @brief - * Check wheither a method is available. - * @remarks - * @pre - * #location_init should be called before.\n - * @post None. - * @param [in] method - a #LocationMethod - * @return int - * @retval True Supported - * False Not supported - * @par Example - #include -static GMainLoop *loop = NULL; - -int main (int argc, char *argv[]) -{ - gboolean is_supported = FALSE; - - // .... - - is_supported = location_is_supported_method(LOCATION_METHOD_HYBRID); - if(is_supported == TRUE) - g_printf("Hybrid Method is supported.\n"); - else - g_printf("Hybrid Method is not supported.\n"); - - return 0; -}* @code - * @endcode - */ -gboolean location_is_supported_method(LocationMethod method); - -/** - * @brief - * Check wheither GPS is turned on or off. - * @remarks - * @pre - * #location_init should be called before.\n - * @post None. - * @param [in] method - a #LocationMethod - * @return int - * @retval True Turned on - * False Turned off - * @par Example - #include -static GMainLoop *loop = NULL; - -int main (int argc, char *argv[]) -{ - gboolean is_enabled = FALSE; - - // .... - - is_enabled = location_is_enabled_gps(loc); - if(is_enable == TRUE) - g_printf("GPS is turned on.\n"); - else - g_printf("GPS is turned off.\n"); - - return 0; -}* @code - * @endcode - */ -gboolean location_is_enabled_gps(LocationObject *obj); - -/** - * @brief - * Get current position information with estimate of the accuracy. - * @remarks Out parameters are should be freed. - * @pre - * #location_init should be called before.\n - * #location_start should be called before. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [out] - * position - a new #LocationPosition - * @param [out] - * accuracy - a new #LocationAccuracy - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @see location_get_velocity - * @par Example - * @code -#include -static GMainLoop *loop = NULL; - -static void cb_service_enabled (GObject *self, guint status, gpointer userdata) -{ - g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata); - - LocationObject *loc = (LocationObject*)userdata; - LocationAccuracy *acc = NULL; - LocationPosition *pos = NULL; - - // This function works properly after service is enabled. - if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) { - g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d", - pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", - acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - location_position_free(pos); - location_accuracy_free(acc); - } else g_warning ("SYNC>> Current position> failed"); -} - -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - gulong handler_id = 0; - - location_init (); - loop = g_main_loop_new (NULL, TRUE); - loc = location_new (LOCATION_METHOD_GPS); - if(!loc){ - g_debug("location_new failed"); - return -1; - } - - handler_id = g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc); - location_start (loc); - g_main_loop_run (loop); - - g_signal_handler_disconnect(loc, handler_id); - location_stop (loc); - location_free (loc); - - return 0; -} - * @endcode - */ -int location_get_position (LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy); - -/** - * @brief - * Get last position information with estimate of the accuracy. - * @remarks This API is not implemented now. \n - * Out parameters are should be freed. - * @pre - * #location_init should be called before. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [out] - * position - a new #LocationPosition - * @param [out] - * accuracy - a new #LocationAccuracy - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @see location_get_position - * @par Example - * @code -#include - -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - int ret = 0; - LocationPosition *last_pos = NULL; - LocationAccuracy *last_acc = NULL; - - location_init (); - loc = location_new (LOCATION_METHOD_GPS); - if(!loc){ - g_debug("location_new failed"); - return -1; - } - - if (LOCATION_ERROR_NONE == location_get_last_position (loc, LOCATION_METHOD_GPS, &last_pos, &last_acc)) { - g_debug ("SYNC>> Last position> time: %d, lat: %f, long: %f, alt: %f, status: %d", - last_pos->timestamp, last_pos->latitude, last_pos->longitude, last_pos->altitude, last_pos->status); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", - last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy); - location_position_free(last_pos); - location_accuracy_free(last_acc); - } else g_warning ("SYNC>> Last position> failed"); - - location_free (loc); - - return 0; -} - * @endcode - */ -int location_get_last_position (LocationObject *obj, LocationMethod method, LocationPosition **position, LocationAccuracy **accuracy); - -/** - * @brief - * Get last satellite information. - * @remarks This API is not implemented now. \n - * Out parameters are should be freed. - * @pre - * #location_init should be called before. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [out] satellite - a new #LocationSatellite - * @return int - * @retval 0 Success - * Please refer #LocationError for more information. - * @see location_get_last_satellite - * @par Example - * @code -#include - -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - int ret = 0, idx = 0; - LocationSatellite *sat = NULL; - guint prn; - gboolean used; - guint elevation; - guint azimuth; - gint snr; - - location_init (); - loc = location_new (LOCATION_METHOD_GPS); - if(!loc){ - g_debug("location_new failed"); - return -1; - } - - if (LOCATION_ERROR_NONE == location_get_satellite (loc, &sat)) { - g_debug ("SYNC>> Current Sattelite> satellite in view = %d, satellite in used = %d", sat->num_of_sat_inview, sat->num_of_sat_used); - g_debug ("\tinview satellite information = "); - for (idx=0; idxnum_of_sat_inview; idx++) { - location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr); - g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr); - } - location_satellite_free (sat); - } else g_warning ("SYNC>> Current satellite> failed"); - - location_free (loc); - - return 0; -} - * @endcode - */ -int location_get_satellite (LocationObject *obj, LocationSatellite **satellite); - -/** - * @brief - * Get last satellite information. - * @remarks This API is not implemented now. \n - * Out parameters are should be freed. - * @pre - * #location_init should be called before. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [out] - * satellite - a new #LocationSatellite - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @par Example - * @code -#include - -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - int ret = 0, idx = 0; - LocationSatellite *last_sat = NULL; - guint prn; - gboolean used; - guint elevation; - guint azimuth; - gint snr; - - location_init (); - loc = location_new (LOCATION_METHOD_GPS); - if(!loc){ - g_debug("location_new failed"); - return -1; - } - - if (LOCATION_ERROR_NONE == location_get_last_satellite (loc, &last_sat)) { - g_debug ("SYNC>> Last Sattelite> satellite in view = %d, satellite in used = %d", last_sat->num_of_sat_inview, last_sat->num_of_sat_used); - g_debug ("\tinview satellite information = "); - for (idx=0; idxnum_of_sat_inview; idx++) { - location_satellite_get_satellite_details(last_sat, idx, &prn, &used, &elevation, &azimuth, &snr); - g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr); - } - location_satellite_free (last_sat); - } else g_warning ("SYNC>> Last satellite> failed"); - - location_free (loc); - - return 0; -} - * @endcode - */ -int location_get_last_satellite (LocationObject *obj, LocationSatellite **satellite); - -/** - * @brief - * Get last known position information with estimate of the accuracy. - * @remarks This API would be DEPRECATED. \n - * @see location_get_last_position - */ -int location_get_last_known_position (LocationObject *obj, LocationMethod method, LocationLastPosition *last_position) LOCATION_DEPRECATED_API; - -/** - * @brief - * Get current position information with estimate of the accuracy by using given address information. - * @remarks Out parameters are should be freed. - * @pre - * #location_init should be called before.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [in] - * address - a #LocationAddress - * @param [out] - * position_list - a list of #LocationPosition - * @param [out] - * accuracy_list - a list of #LocationAccuracy - * @return int - * @retval 0 Success. - * - * Please refer #LocationError for more information. - * @see - * location_get_position_from_address_async\n - * @par Example - * @code -#include - -static void PrintPos (gpointer data, gpointer user_data) -{ - LocationPosition *pos = (LocationPosition *)data; - - if (pos) { - g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude); - location_position_free (pos); - } -} - -static void PrintAcc (gpointer data, gpointer user_data) -{ - LocationAccuracy *acc = (LocationAccuracy *)data; - - if (acc) { - g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - location_accuracy_free (acc); - } -} - -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - int ret = LOCATION_ERROR_NONE; - - location_init (); - loc = location_new (LOCATION_METHOD_GPS); - if(!loc){ - g_debug("location_new failed"); - return -1; - } - - GList *pos_list = NULL; - GList *acc_list = NULL; - LocationAddress *addr = NULL; - - addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113"); - if (LOCATION_ERROR_NONE == location_get_position_from_address(loc, addr, &pos_list, &acc_list)) { - g_list_foreach (pos_list, PrintPos, NULL); - g_list_foreach (acc_list, PrintAcc, NULL); - } else g_warning ("SYNC>> position from address> failed"); - - if (pos_list) { - g_list_free (pos_list); - } - if (acc_list) { - g_list_free (acc_list); - } - - location_address_free (addr); - location_free (loc); - return 0; -} - * @endcode - */ -int location_get_position_from_address (LocationObject *obj, const LocationAddress *address, GList **position_list, GList **accuracy_list); - -/** - * @brief - * Get current position information asynchronously with estimate of the accuracy by using given address information. - * @remarks None. - * @pre - * #location_init should be called before.\n - * Calling application must have glib or ecore main loop.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [in] - * address - a #LocationAddress - * @param [in] - * callback - A pointer of function which will be called after position is gained or when an error occurs. - * @param [in] - * userdata - data to pass to function - * @return int - * @retval 0 Success. - * - * Please refer #LocationError for more information. - * @see - * location_get_position_from_address\n - * @par Example - * @code -#include - -static void PrintPos (gpointer data, gpointer user_data) -{ - LocationPosition *pos = (LocationPosition *)data; - - if (pos) { - g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude); - } -} - -static void PrintAcc (gpointer data, gpointer user_data) -{ - LocationAccuracy *acc = (LocationAccuracy *)data; - - if (acc) { - g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - } -} -static void -cb_position_from_address (LocationError error, GList *position_list, GList *accuracy_list, gpointer userdata) -{ - if (position_list && accuracy_list) { - g_list_foreach (position_list, PrintPos); - g_list_foreach (accuracy_list, PrintAcc); - } -} - -void get_position_from_address(LocationObject* loc) -{ - LocationAddress *addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113"); - //Calling application must have an active data connection before using this function. - if (LOCATION_ERROR_NONE == location_get_position_from_address_async(loc, addr, cb_position_from_address, loc)) - g_debug("location_get_position_from_address_async() success"); - else g_warning ("location_get_position_from_address_async() failed"); - location_address_free (addr); -} - * @endcode - */ -int location_get_position_from_address_async (LocationObject *obj, const LocationAddress *address, LocationPositionCB callback, gpointer userdata); - -/** - * @brief - * Get current position information with estimate of the accuracy by using given free-formed address string. - * @remarks Out parameters are should be freed. - * @pre - * #location_init should be called before.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [in] - * address - Free-formed address string to be used - * @param [out] - * position_list - a list of #LocationPosition - * @param [out] - * accuracy_list - a list of #LocationAccuracy - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @see - * location_get_position_from_freeformed_address_async\n - * @par Example - * @code -#include - -static void PrintPos (gpointer data, gpointer user_data) -{ - LocationPosition *pos = (LocationPosition *)data; - - if (pos) { - g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude); - location_position_free (pos); - } -} - -static void PrintAcc (gpointer data, gpointer user_data) -{ - LocationAccuracy *acc = (LocationAccuracy *)data; - - if (acc) { - g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - location_accuracy_free (acc); - } -} - -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - int ret = LOCATION_ERROR_NONE; - - location_init (); - loc = location_new (LOCATION_METHOD_GPS); - if(!loc){ - g_debug("location_new failed"); - return -1; - } - - GList *pos_list = NULL; - GList *acc_list = NULL; - char* addr_str = g_strdup("4 N 2nd Street 95113"); - //Calling application must have an active data connection before using this function. - if (LOCATION_ERROR_NONE == location_get_position_from_freeformed_address(loc, addr_str, &pos_list, &acc_list)) { - g_list_foreach (pos_list, PrintPos, NULL); - g_list_foreach (acc_list, PrintAcc, NULL); - } else g_warning ("SYNC>> position from freeformed address> failed"); - g_free(addr_str); - - location_free (loc); - return 0; -} - * @endcode - */ -int location_get_position_from_freeformed_address (LocationObject *obj, const gchar *address, GList **position_list, GList **accuracy_list); - -/** - * @brief - * Get current position information asynchronously with estimate of the accuracy by using given free-formed address string. - * @remarks None. - * @pre - * #location_init should be called before.\n - * Calling application must have glib or ecore main loop.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [in] - * address - Free-formed address string to be used - * @param [in] - * callback - A pointer of function which will be called after position is gained or when an error occurs. - * @param [in] - * userdata - data to pass to function - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @see - * location_get_position_from_freeformed_address\n - * @par Example - * @code -#include - -static void PrintPos (gpointer data, gpointer user_data) -{ - LocationPosition *pos = (LocationPosition *)data; - - if (pos) { - g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude); - } -} - -static void PrintAcc (gpointer data, gpointer user_data) -{ - LocationAccuracy *acc = (LocationAccuracy *)data; - - if (acc) { - g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - } -} - -static void -cb_position_from_freeformed_address (LocationError error, GList *position_list, GList *accuracy_list, gpointer userdata) -{ - if (position_list && accuracy_list) { - g_list_foreach (position_list, PrintPos); - g_list_foreach (accuracy_list, PrintAcc); - } -} - -void get_position_from_address(LocationObject* loc) -{ - gchar *addr_str = g_strdup("4 N 2nd Street 95113"); - //Calling application must have an active data connection before using this function. - if (LOCATION_ERROR_NONE == location_get_position_from_freeformed_address_async(loc, addr_str, cb_position_from_freeformed_address, loc)) - g_debug("location_get_position_from_freeformed_address_async() success"); - else g_warning ("location_get_position_from_freeformed_address_async() failed"); - g_free(addr_str); - -} - * @endcode - */ -int location_get_position_from_freeformed_address_async (LocationObject *obj, const gchar *address, LocationPositionCB callback, gpointer userdata); - -/** - * @brief - * Get current velocity information with estimate of the accuracy. - * @remarks Out parameters are should be freed. - * @pre - * #location_init should be called before.\n - * #location_start should be called before. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [out] - * velocity - a new #LocationVelocity - * @param [out] - * accuracy - a new #LocationAccuracy - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @see location_get_position - * @par Example - * @code -#include -static GMainLoop *loop = NULL; - -static void cb_service_enabled (GObject *self, guint status, gpointer userdata) -{ - g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata); - - LocationObject *loc = (LocationObject*)userdata; - LocationAccuracy *acc = NULL; - LocationVelocity *vel = NULL; - - if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) { - g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f", - vel->timestamp, vel->speed, vel->direction, vel->climb); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", - acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - location_velocity_free(vel); - location_accuracy_free(acc); - } else g_warning ("SYNC>> Current velocity> failed"); -} - -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - gulong hander_id = 0; - location_init (); - - loop = g_main_loop_new (NULL, TRUE); - - loc = location_new (LOCATION_METHOD_GPS); - if(!loc){ - g_debug("location_new failed"); - return -1; - } - - handler_id = g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc); - location_start (loc); - g_main_loop_run (loop); - - g_signal_handler_disconnect(loc, handler_id); - location_stop (loc); - location_free (loc); - - return 0; -} - - * @endcode - */ -int location_get_velocity (LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy); - -/** - * @brief - * Get last velocity information with estimate of the accuracy. - * @remarks This API is not implemented now. \n - * Out parameters are should be freed. - * @pre - * #location_init should be called before.\n - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [out] - * velocity - a new #LocationVelocity - * @param [out] - * accuracy - a new #LocationAccuracy - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @see location_get_velocity - * @par Example - * @code -#include - -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - LocationVelocity *last_vel = NULL; - LocationAccuracy *last_acc = NULL; - location_init (); - - loc = location_new (LOCATION_METHOD_GPS); - if(!loc){ - g_debug("location_new failed"); - return -1; - } - - if (LOCATION_ERROR_NONE == location_get_last_velocity (loc, &last_vel, &last_acc)) { - g_debug ("SYNC>> Last velocity> time: %d, speed: %f, direction:%f, climb:%f", - last_vel->timestamp, last_vel->speed, last_vel->direction, last_vel->climb); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", - last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy); - location_velocity_free(last_vel); - location_accuracy_free(last_acc); - } else g_warning ("SYNC>> Last velocity> failed."); - - location_free (loc); - - return 0; -} - * @endcode - */ -int location_get_last_velocity (LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy); - - -/** - * @brief - * Get current address information with estimate of the accuracy by using current position. - * @remarks Out parameters are should be freed. - * @pre - * #location_init should be called before.\n - * #location_start should be called before.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [out] - * address - a new #LocationAddress - * @param [out] - * accuracy - a new #LocationAccuracy - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @see - * location_get_address_async\n - * @par Example - * @code -#include -static GMainLoop *loop = NULL; - -static void cb_service_enabled (GObject *self, guint status, gpointer userdata) -{ - g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata); - - LocationAddress *addr = NULL; - LocationAccuracy *acc = NULL; - LocationObject *loc = (LocationObject*)userdata; - - // This function works properly after service is enabled. - //Calling application must have an active data connection before using this function. - if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) { - g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s", - addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - location_address_free(addr); - location_accuracy_free(acc); - } else g_warning ("SYNC>> Current address> failed"); -} - -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - gulong handler_id = 0; - int ret = LOCATION_ERROR_NONE; - - location_init (); - - loop = g_main_loop_new (NULL, TRUE); - - loc = location_new (LOCATION_METHOD_GPS); - if(!loc){ - g_debug("location_new failed"); - return -1; - } - - handler_id = g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc); - location_start (loc); - g_main_loop_run (loop); - - g_signal_handler_disconnect(loc, handler_id); - location_stop (loc); - location_free (loc); - - return 0; -} - * @endcode - */ -int location_get_address (LocationObject *obj, LocationAddress **address, LocationAccuracy **accuracy); - -/** - * @brief - * Get current address information asynchronously with estimate of the accuracy by using current position. - * @remarks None. - * @pre - * #location_init should be called before.\n - * #location_start should be called before.\n - * Calling application must have glib or ecore main loop.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [in] - * callback - A pointer of function which will be called after address is gained or when an error occurs. - * @param [in] - * userdata - data to pass to function - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @see - * location_get_address\n - * @par Example - * @code -#include -static GMainLoop *loop = NULL; - -static void -cb_address (LocationError error, LocationAddress *addr, LocationAccuracy *acc, gpointer userdata) -{ - g_debug ("ASYNC>> location_get_address_async> %s %s %s %s %s %s %s", - addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); -} - -static void cb_service_enabled (GObject *self, guint status, gpointer userdata) -{ - g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata); - - LocationObject *loc = (LocationObject*)userdata; - // This function works properly after service is enabled. - //Calling application must have an active data connection before using this function. - if (LOCATION_ERROR_NONE == location_get_address_async(loc, cb_address, loc)) - g_debug("location_get_address_async() success"); - else g_warning ("location_get_address_async() failed"); -} - - -int main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - gulong handler_id = 0; - int ret = LOCATION_ERROR_NONE; - - location_init (); - - loop = g_main_loop_new (NULL, TRUE); - - loc = location_new (LOCATION_METHOD_GPS); - if(!loc){ - g_debug("location_new failed"); - return -1; - } - - handler_id = g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc); - location_start (loc); - g_main_loop_run (loop); - - g_signal_handler_disconnect(loc, handler_id); - location_stop (loc); - location_free (loc); - - return 0; -} - * @endcode - */ -int location_get_address_async (LocationObject *obj, LocationAddressCB callback, gpointer userdata); - -/** - * @brief - * Get current address information with estimate of the accuracy by using given position information. - * @remarks Out parameters are should be freed. - * @pre - * #location_init should be called before.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [in] - * position - a #LocationPosition - * @param [out] - * address - a new #LocationAddress - * @param [out] - * accuracy - a new #LocationAccuracy - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @see - * location_get_address_from_position_async\n - * @par Example - * @code -#include -static GMainLoop *loop = NULL; - -int -main (int argc, char *argv[]) -{ - LocationObject *loc = NULL; - int ret = LOCATION_ERROR_NONE; - - location_init (); - - loop = g_main_loop_new (NULL, TRUE); - - loc = location_new (LOCATION_METHOD_GPS); - if(!loc){ - g_debug("location_new failed"); - return -1; - } - - LocationPosition *pos = NULL; - LocationAccuracy *acc = NULL; - LocationAddress *addr = NULL; - - //Calling application must have an active data connection before using this function. - pos = location_position_new (0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX); - if (LOCATION_ERROR_NONE == location_get_address_from_position(loc, pos, &addr, &acc)) { - g_debug ("SYNC>> address from position> %s %s %s %s %s %s %s", - addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - location_address_free(addr); - location_accuracy_free(acc); - } else g_warning ("SYNC>> address from position> failed"); - location_position_free (pos); -} - * @endcode - */ -int location_get_address_from_position (LocationObject *obj, const LocationPosition *position, LocationAddress **address, LocationAccuracy **accuracy); - -/** - * @brief - * Get current address information asynchronously with estimate of the accuracy by using given position information. - * @remarks None. - * @pre - * #location_init should be called before.\n - * Calling application must have glib or ecore main loop.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] - * obj - a #LocationObject created by #location_new - * @param [in] - * position - a #LocationPosition - * @param [in] - * callback - A pointer of function which will be called after address is gained or when an error occurs. - * @param [in] - * userdata - data to pass to function - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - * @see - * location_get_address_from_position\n - * @par Example - * @code -#include -static GMainLoop *loop = NULL; - -static void -cb_address_from_position (LocationError error, LocationAddress *addr, LocationAccuracy *acc, gpointer userdata) -{ - g_debug ("ASYNC>> location_get_address_from_position_async> %s %s %s %s %s %s %s", - addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); -} - -void get_address_from_position(LocationObject* loc) -{ - LocationPosition *pos = location_position_new (0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX); - //Calling application must have an active data connection before using this function. - if (LOCATION_ERROR_NONE == location_get_address_from_position_async(loc, pos, cb_address_from_position, loc)) - g_debug("location_get_address_from_position_async() success"); - else g_warning ("location_get_address_from_position_async() failed"); - location_position_free (pos); -} - * @endcode - */ -int location_get_address_from_position_async (LocationObject *obj, const LocationPosition *position, LocationAddressCB callback, gpointer userdata); - -/** - * @brief - * Get information of point of interests by using current position within a given radius. - * @remarks Out parameters are should be freed. - * \n This functions is not implemneted yet. - * @pre - * #location_init should be called before.\n - * #location_start should be called before.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] obj - a #LocationObject created by #location_new - * @param [in] radius - radius of a circle - * @param [in] keyword - keyword for POI - * @param [out] poi_info - a new #LocationPOIInfo - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - */ -int location_get_poi (LocationObject *obj, gdouble radius, const gchar *keyword, LocationPOIInfo **poi_info); - -/** - * @brief - * Get information of point of interests asynchronously by using current position within a given radius. - * @remarks This functions is not implemneted yet. - * @pre - * #location_init should be called before.\n - * #location_start should be called before.\n - * Calling application must have glib or ecore main loop.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] obj - a #LocationObject created by #location_new - * @param [in] radius - radius of a circle - * @param [in] callback - function to call - * @param [in] userdata - data to pass to function - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - */ -int location_get_poi_async (LocationObject *obj, gdouble radius, const gchar *keyword, LocationPOICB callback, gpointer userdata); - -/** - * @brief - * Get information of point of interests by using given address within a given radius. - * @remarks Out parameters are should be freed. - * \n This functions is not implemneted yet. - * @pre - * #location_init should be called before.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] obj - a #LocationObject created by #location_new - * @param [in] address - a #LocationAddress - * @param [in] radius - radius of a circle - * @param [in] keyword - keyword for POI - * @param [out] poi_info - a new #LocationPOIInfo - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - */ -int location_get_poi_from_address(LocationObject *obj, const LocationAddress *address, gdouble radius, const gchar *keyword, LocationPOIInfo **poi_info); - -/** - * @brief - * Get information of point of interests asynchronously by using given address within a given radius. - * @remarks This functions is not implemneted yet. - * @pre - * #location_init should be called before.\n - * Calling application must have glib or ecore main loop.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] obj - a #LocationObject created by #location_new - * @param [in] address - a #LocationAddress - * @param [in] radius - radius of a circle - * @param [in] callback - function to call - * @param [in] userdata - data to pass to function - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - */ -int location_get_poi_from_address_async (LocationObject *obj, const LocationAddress *address, gdouble radius, const gchar *keyword, LocationPOICB callback, gpointer userdata); - -/** - * @brief - * Get information of point of interests by using given position within a given radius. - * @remarks Out parameters are should be freed. - * \n This functions is not implemneted yet. - * @pre - * #location_init should be called before.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] obj - a #LocationObject created by #location_new - * @param [in] position - a #LocationPosition - * @param [in] radius - radius of a circle - * @param [in] keyword - keyword for POI - * @param [out] poi_info - a new #LocationPOIInfo - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - */ -int location_get_poi_from_position(LocationObject *obj, const LocationPosition *position, gdouble radius, const gchar *keyword, LocationPOIInfo **poi_info); - -/** - * @brief - * Get information of point of interests asynchronously by using given position within a given radius. - * @remarks This functions is not implemneted yet. - * @pre - * #location_init should be called before.\n - * Calling application must have glib or ecore main loop.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] obj - a #LocationObject created by #location_new - * @param [in] position - a #LocationPosition - * @param [in] radius - radius of a circle - * @param [in] callback - function to call - * @param [in] userdata - data to pass to function - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - */ -int location_get_poi_from_position_async (LocationObject *obj, const LocationPosition *position, gdouble radius, const gchar*keyword, LocationPOICB callback, gpointer userdata); - -/** - * @brief - * Send command to the server. - * @remarks This functions is not implemneted yet. - * @pre - * #location_init should be called before.\n - * Calling application must have glib or ecore main loop.\n - * Calling application must have an active data connection. - * @post None. - * @param [in] cmd - a #char - * @return int - * @retval 0 Success - * - * Please refer #LocationError for more information. - */ -int location_send_command(const char *cmd); - -/** - * @} @} - */ - -G_END_DECLS - -#endif /* __LOCATION_H__ */ diff --git a/location/manager/Makefile.am b/location/manager/Makefile.am new file mode 100644 index 0000000..df26216 --- /dev/null +++ b/location/manager/Makefile.am @@ -0,0 +1,41 @@ +noinst_LTLIBRARIES = liblocation-manager.la + +COMMON_HEADER_DIR = include +MANAGER_DIR = manager +MAP_SERVICE_DIR = map-service +MODULE_DIR = module + +liblocation_manager_la_SOURCES = \ + location-marshal.c \ + location-marshal.h \ + location-ielement.c \ + location-setting.c \ + location-position.c \ + location-velocity.c \ + location-accuracy.c \ + location-boundary.c \ + location-satellite.c \ + location-signaling-util.c \ + location-common-util.c \ + location-gps.c \ + location-wps.c \ + location-sps.c \ + location-hybrid.c + +liblocation_manager_la_CFLAGS = \ + -fPIC\ + -I${srcdir} \ + -I${srcdir}/.. \ + -I${srcdir}/../include \ + -I${srcdir}/../${MANAGER_DIR} \ + -I${srcdir}/../${MODULE_DIR} \ + -I${srcdir}/../${MAP_SERVICE_DIR} \ + $(LOCATION_CFLAGS) + +EXTRA_DIST = \ + location-marshal.list + +location-marshal.h: location-marshal.list $(GLIB_GENMARSHAL) + $(GLIB_GENMARSHAL) $< --header --prefix=location > $@ +location-marshal.c: location-marshal.list location-marshal.h $(GLIB_GENMARSHAL) + echo "#include \"location-marshal.h\"" > $@ && $(GLIB_GENMARSHAL) location-marshal.list --body --prefix=location >> $@ diff --git a/location/manager/location-accuracy.c b/location/manager/location-accuracy.c new file mode 100644 index 0000000..327e883 --- /dev/null +++ b/location/manager/location-accuracy.c @@ -0,0 +1,105 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-accuracy.h" +#include "location-log.h" + +GType +location_accuracy_get_type (void) +{ + static volatile gsize type_volatile = 0; + if(g_once_init_enter(&type_volatile)) { + GType type = g_boxed_type_register_static ( + g_intern_static_string ("LocationAccuracy"), + (GBoxedCopyFunc) location_accuracy_copy, + (GBoxedFreeFunc) location_accuracy_free); + g_once_init_leave(&type_volatile, type); + } + return type_volatile; +} + +EXPORT_API LocationAccuracy* +location_accuracy_new (LocationAccuracyLevel level, + gdouble horizontal_accuracy, + gdouble vertical_accuracy) +{ + LocationAccuracy* accuracy = g_slice_new0 (LocationAccuracy); + accuracy->level = level; + accuracy->horizontal_accuracy = horizontal_accuracy; + accuracy->vertical_accuracy = vertical_accuracy; + + return accuracy; +} + +EXPORT_API void +location_accuracy_free (LocationAccuracy* accuracy) +{ + g_return_if_fail (accuracy); + g_slice_free (LocationAccuracy, accuracy); +} + +static int +comp_int(int a, int b){ + if (a < b) return -1; + if (a == b) return 0; + return 1; +} + +static int +comp_double_reverse(double a, double b) { + if (a > b) return -1; + else if (a == b) return 0; + return 1; +} + +int +location_accuracy_level_compare(const LocationAccuracy *accuracy1, const LocationAccuracy *accuracy2) +{ + g_return_val_if_fail(accuracy1, -1); + g_return_val_if_fail(accuracy2, 1); + + return comp_int(accuracy1->level, accuracy2->level); +} + +EXPORT_API int +location_accuracy_compare (const LocationAccuracy *accuracy1, const LocationAccuracy *accuracy2) +{ + int ret = 0; + ret = location_accuracy_level_compare(accuracy1, accuracy2); + if(!ret){ + ret = comp_double_reverse(accuracy1->horizontal_accuracy, accuracy2->horizontal_accuracy); + if(!ret) return comp_double_reverse(accuracy1->vertical_accuracy, accuracy2->vertical_accuracy); + } + return ret; +} + +EXPORT_API LocationAccuracy* +location_accuracy_copy (const LocationAccuracy *accuracy) +{ + g_return_val_if_fail(accuracy, NULL); + return location_accuracy_new(accuracy->level, + accuracy->horizontal_accuracy, + accuracy->vertical_accuracy); +} diff --git a/location/manager/location-accuracy.h b/location/manager/location-accuracy.h new file mode 100644 index 0000000..f257705 --- /dev/null +++ b/location/manager/location-accuracy.h @@ -0,0 +1,139 @@ +/* + * libslp-location + * + * 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_ACCURACY_H_ +#define __LOCATION_ACCURACY_H_ + +#include + +G_BEGIN_DECLS + +GType location_accuracy_get_type(void); +#define LOCATION_TYPE_ACCURACY (location_accuracy_get_type()) + +/** + * @file location-accuracy.h + * @brief This file contains the definitions, structures, and functions related to accuracy information. + */ + +/** + * @addtogroup LocationAPI + * @{ + * @defgroup LocationAPIAccuracy Location Accuracy + * @breif This provides APIs related to Location Accuracy. + * @addtogroup LocationAPIAccuracy + * @{ + */ + +/** + * @brief This represents the approximate accuracy level of given information. + */ +typedef enum { + LOCATION_ACCURACY_LEVEL_NONE = 0, ///< Invalid data. + LOCATION_ACCURACY_LEVEL_COUNTRY, ///< Country accuracy level-> + LOCATION_ACCURACY_LEVEL_REGION, ///< Regional accuracy level-> + LOCATION_ACCURACY_LEVEL_LOCALITY, ///< Local accuracy level-> + LOCATION_ACCURACY_LEVEL_POSTALCODE, ///< Postal accuracy level-> + LOCATION_ACCURACY_LEVEL_STREET, ///< Street accuracy level-> + LOCATION_ACCURACY_LEVEL_DETAILED, ///< Detailed accuracy level-> +} LocationAccuracyLevel; + +/** + * @brief This represents location accuracy information such as accuracy level, horizontal and vertical accuracy. + */ +struct _LocationAccuracy +{ + LocationAccuracyLevel level; ///< The accuracy level of the location information. + gdouble horizontal_accuracy; ///< The horizontal position uncertainty of the location in meters. + gdouble vertical_accuracy; ///< The vertical position uncertainty of the location in meters. +}; + +/** + * @brief Create a new #LocationAccuracy with given information. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] level - The accuracy level of the location information. + * @param [in] horizontal_accuracy - The horizontal position uncertainty of the location in meters. + * @param [in] vertical_accuracy - The vertical position uncertainty of the location in meters. + * @return a new #LocationAccuracy + * @retval NULL if error occured + */ +LocationAccuracy *location_accuracy_new (LocationAccuracyLevel level, gdouble horizontal_accuracy, gdouble vertical_accuracy); + +/** + * @brief Free a #LocationAccuracy. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] accuracy - a #LocationAccuracy. + * @return None. + */ +void location_accuracy_free (LocationAccuracy *accuracy); + +/** + * @brief Compare for two accuracys. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] accuracy1 - a #LocationAccuracy + * @param [in] accuracy2 - another #LocationAccuracy + * @return integer + * @retval\n + * 0 - if the accuracy match\n + * positive value - if accuracy of accuracy1 is better than accuracy of accuracy2\n + * negative value - if accuracy of accuracy1 is worse than accuracy of accuracy2 + */ +int location_accuracy_compare (const LocationAccuracy *accuracy1, const LocationAccuracy *accuracy2); + +/** + * @brief Compare for two accuracys' level. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] accuracy1 - a #LocationAccuracy + * @param [in] accuracy2 - another #LocationAccuracy + * @return integer + * @retval\n + * 0 - if the accuracy match\n + * positive value - if accuracy1's level is better than accuracy2's level\n + * negative value - if accuracy1's level is worse than accuracy2's level + */ +int location_accuracy_level_compare(const LocationAccuracy *accuracy1, const LocationAccuracy *accuracy2); + +/** + * @brief Makes a copy of #LocationAccuracy + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] accuracy - a #LocationAccuracy + * @return a new #LocationAccuracy + * @retval NULL if error occured + */ +LocationAccuracy *location_accuracy_copy (const LocationAccuracy *accuracy); + +/** + * @} @} + */ + +G_END_DECLS + +#endif diff --git a/location/manager/location-boundary.c b/location/manager/location-boundary.c new file mode 100644 index 0000000..7fa79ea --- /dev/null +++ b/location/manager/location-boundary.c @@ -0,0 +1,373 @@ +/* + * libslp-location + * + * 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. + */ + +/* + * location_boundary_if_inside(LocationBoundary* boundary, + * LocationPosition* position) + * code from + * + * Copyright (c) 1970-2003, Wm. Randolph Franklin + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * 1.Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimers. + * 2.Redistributions in binary form must reproduce the above copyright notice + * in the documentation and/or other materials provided with the distribution. + * 3.The name of W. Randolph Franklin may not be used to endorse or promote + * products derived from this Software without specific prior written permission. + * + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include "location-boundary.h" +#include "location-log.h" + +GType +location_boundary_get_type (void) +{ + static volatile gsize type_volatile = 0; + if(g_once_init_enter(&type_volatile)) { + GType type = g_boxed_type_register_static ( + g_intern_static_string ("LocationBoundary"), + (GBoxedCopyFunc) location_boundary_copy, + (GBoxedFreeFunc) location_boundary_free); + g_once_init_leave(&type_volatile, type); + } + return type_volatile; +} + +static void _append_polygon_position(gpointer data, gpointer user_data) +{ + g_return_if_fail(data); + g_return_if_fail(user_data); + + LocationBoundary* boundary = (LocationBoundary*)user_data; + LocationPosition* position = (LocationPosition *)data; + LocationPosition* new_position = location_position_copy(position); + + boundary->polygon.position_list = g_list_append(boundary->polygon.position_list, new_position); +} + +static void _free_polygon_position(gpointer data) +{ + g_return_if_fail(data); + + LocationPosition* position = (LocationPosition *)data; + location_position_free(position); +} + + +EXPORT_API LocationBoundary * +location_boundary_new_for_rect (LocationPosition* left_top, + LocationPosition* right_bottom) +{ + g_return_val_if_fail(left_top, NULL); + g_return_val_if_fail(right_bottom, NULL); + + gdouble lon_interval = right_bottom->longitude - left_top->longitude; + + if(lon_interval < 180 && lon_interval > -180) { + if(right_bottom->longitude <= left_top->longitude || right_bottom->latitude >= left_top->latitude) + return NULL; + } + else { + if(right_bottom->longitude >= left_top->longitude || right_bottom->latitude >= left_top->latitude) + return NULL; + } + + LocationBoundary* boundary = g_slice_new0 (LocationBoundary); + boundary->type = LOCATION_BOUNDARY_RECT; + boundary->rect.left_top = location_position_copy(left_top); + boundary->rect.right_bottom = location_position_copy(right_bottom); + return boundary; +} + +EXPORT_API LocationBoundary * +location_boundary_new_for_circle (LocationPosition* center, + gdouble radius) +{ + g_return_val_if_fail(center, NULL); + g_return_val_if_fail(radius > 0, NULL); + LocationBoundary* boundary = g_slice_new0 (LocationBoundary); + boundary->type = LOCATION_BOUNDARY_CIRCLE; + boundary->circle.center = location_position_copy(center); + boundary->circle.radius = radius; + return boundary; +} + +EXPORT_API LocationBoundary * +location_boundary_new_for_polygon(GList *position_list) +{ + g_return_val_if_fail(position_list, NULL); + g_return_val_if_fail(g_list_length(position_list) > 2, NULL); + + LocationBoundary *boundary = g_slice_new0 (LocationBoundary); + + g_list_foreach(position_list, (GFunc)_append_polygon_position, boundary); + boundary->type = LOCATION_BOUNDARY_POLYGON; + boundary->polygon.position_list = g_list_first(boundary->polygon.position_list); + + return boundary; +} + +EXPORT_API void +location_boundary_free (LocationBoundary* boundary) +{ + g_return_if_fail(boundary); + + if (boundary->type == LOCATION_BOUNDARY_RECT) { + location_position_free(boundary->rect.left_top); + location_position_free(boundary->rect.right_bottom); + } else if (boundary->type == LOCATION_BOUNDARY_CIRCLE) { + location_position_free(boundary->circle.center); + } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) { + g_list_free_full(boundary->polygon.position_list, (GDestroyNotify)_free_polygon_position); + } + g_slice_free(LocationBoundary, boundary); +} + +EXPORT_API LocationBoundary* +location_boundary_copy (const LocationBoundary* boundary) +{ + g_return_val_if_fail(boundary, NULL); + if (boundary->type == LOCATION_BOUNDARY_RECT) { + return location_boundary_new_for_rect(boundary->rect.left_top, boundary->rect.right_bottom); + } else if (boundary->type == LOCATION_BOUNDARY_CIRCLE) { + return location_boundary_new_for_circle(boundary->circle.center, boundary->circle.radius); + } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) { + return location_boundary_new_for_polygon(boundary->polygon.position_list); + } + return NULL; +} + + +EXPORT_API gboolean +location_boundary_if_inside (LocationBoundary* boundary, + LocationPosition* position) +{ + g_return_val_if_fail(boundary, FALSE); + g_return_val_if_fail(position, FALSE); + + gboolean is_inside = FALSE; + + switch(boundary->type) { + + case LOCATION_BOUNDARY_RECT: { + gdouble y = position->latitude; + gdouble x = position->longitude; + + gdouble lt_y = boundary->rect.left_top->latitude; + gdouble lt_x = boundary->rect.left_top->longitude; + gdouble rb_y = boundary->rect.right_bottom->latitude; + gdouble rb_x = boundary->rect.right_bottom->longitude; + + if (lt_x - rb_x < 180 && lt_x - rb_x > -180) { + if ((rb_y < y && y < lt_y) && ( lt_x < x && x < rb_x)) { + LOCATION_LOGD("\tInside of Rectangular boundary"); + is_inside = TRUE; + } + } + else { + if ((rb_y < y && y < lt_y) && ( lt_x < x || x < rb_x)) { + LOCATION_LOGD("\tInside of Rectangular boundary near 180th meridian"); + is_inside = TRUE; + } + } + break; + } + case LOCATION_BOUNDARY_CIRCLE: { + + LocationPosition center; + gulong distance = 0; + + center.latitude = boundary->circle.center->latitude; + center.longitude = boundary->circle.center->longitude; + + location_get_distance(¢er, position, &distance); + if (distance < boundary->circle.radius){ + LOCATION_LOGD("\tInside Circle boundary"); + is_inside = TRUE; + } + break; + } + case LOCATION_BOUNDARY_POLYGON: { + + int i, j; + double interval_x = 0.0, interval_y = 0.0; + double x0, y0; + gboolean edge_area; + int crossing_num = 0; + GList *position_list = boundary->polygon.position_list; + int count = g_list_length(position_list); + GList *pos1_list = NULL; + GList *pos2_list = NULL; + LocationPosition* pos1 = NULL; + LocationPosition* pos2 = NULL; + + i = 0; + j = count - 1; + pos1_list = g_list_first(position_list); + pos2_list = g_list_last(position_list); + while(pos1_list) { + edge_area = FALSE; + pos1 = pos1_list->data; + pos2 = pos2_list->data; + interval_y = pos1->longitude - pos2->longitude; + interval_x = pos1->latitude - pos2->latitude; + /** + * Case 1. -180 < longitude2 - longitude1 < 180 : normal case + * Case 2. longitude2 - longitude1 < -180 : interval_y = longitude2 - longitude1 + 360 + * Case 3. longitude2 - longitude1 > 180 : intreval_y = longitude2 - longitude1 - 360 + */ + if (interval_y > 180) { + interval_y = interval_y - 360; + edge_area = TRUE; + } + else if (interval_y < -180) { + interval_y = interval_y + 360; + edge_area = TRUE; + } + + if (edge_area && (pos1->longitude > position->longitude) == (pos2->longitude > position->longitude)){ + if (pos2->longitude * position->longitude > 0) { + x0 = pos2->latitude; + y0 = pos2->longitude; + } + else { + x0 = pos1->latitude; + y0 = pos1->longitude; + } + + if (position->latitude < ((interval_x/interval_y)*(position->longitude - y0) + x0)) { + + LOCATION_LOGD("Reverse"); + crossing_num++; + } + } + else if (!edge_area && (pos1->longitude > position->longitude) != (pos2->longitude > position->longitude)) { + x0 = pos2->latitude; + y0 = pos2->longitude; + if (position->latitude < ((interval_x/interval_y)*(position->longitude - y0) + x0)) { + LOCATION_LOGD("Common"); + crossing_num++; + } + } + else LOCATION_LOGD("It is not crossed."); + + pos2_list = pos1_list; + pos1_list = g_list_next(pos1_list); + } + LOCATION_LOGW("num[%d]", crossing_num); + is_inside = crossing_num & 1; // Odd : inside, Even : outside + + break; + } + default: { + LOCATION_LOGW("\tboundary type is undefined.[%d]", boundary->type); + break; + } + } + + return is_inside; +} + +EXPORT_API int +location_boundary_add(const LocationObject *obj, const LocationBoundary *boundary) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (boundary, LOCATION_ERROR_PARAMETER); + + GList *boundary_list = NULL; + + boundary_list = g_list_append(boundary_list, (gpointer) boundary); + + g_object_set(G_OBJECT(obj), "boundary", boundary_list, NULL); + + + return LOCATION_ERROR_NONE; +} + +EXPORT_API int +location_boundary_remove(const LocationObject *obj, const LocationBoundary *boundary) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (boundary, LOCATION_ERROR_PARAMETER); + + g_object_set(G_OBJECT(obj), "removal-boundary", boundary, NULL); + + return LOCATION_ERROR_NONE; +} + +EXPORT_API int +location_boundary_foreach(const LocationObject *obj, LocationBoundaryFunc func, gpointer user_data) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (func, LOCATION_ERROR_PARAMETER); + + GList * boundary_list = NULL; + + g_object_get(G_OBJECT(obj), "boundary", &boundary_list, NULL); + + if (boundary_list == NULL) { + LOCATION_LOGD("There is no boundary."); + return LOCATION_ERROR_UNKNOWN; + } + g_list_foreach(boundary_list, (GFunc)func, user_data); + + return LOCATION_ERROR_NONE; +} + +EXPORT_API LocationBoundary * +location_boundary_get_bounding_box (LocationBoundary *boundary) +{ + g_return_val_if_fail (boundary, NULL); + LocationBoundary *bbox = NULL; + + return bbox; +} + +EXPORT_API LocationPosition * +location_boundary_get_center_position (LocationBoundary *boundary) +{ + g_return_val_if_fail (boundary, NULL); + LocationPosition *center = NULL; + + return center; +} diff --git a/location/manager/location-boundary.h b/location/manager/location-boundary.h new file mode 100644 index 0000000..c3603ef --- /dev/null +++ b/location/manager/location-boundary.h @@ -0,0 +1,317 @@ +/* + * libslp-location + * + * 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_BOUNDARY_H_ +#define __LOCATION_BOUNDARY_H_ + +#include +#include + +G_BEGIN_DECLS + +GType location_boundary_get_type (void); +#define LOCATION_TYPE_BOUNDARY (location_boundary_get_type ()) + + +/** + * @file location-boundary.h + * @brief This file contains the definitions, structures, and functions related to boundary information. + */ +/** + * @addtogroup LocationAPI + * @{ + * @defgroup LocationAPIBoundary Location Boundary + * @breif This provides APIs related to Location Boundary + * @addtogroup LocationAPIBoundary + * @{ + */ + +/** + * @brief + * The type of the @location_boundary_foreach function of #LocationObject + */ +typedef void (*LocationBoundaryFunc) (LocationBoundary *boundary, gpointer user_data); + +/** + * @brief This represents used geographical type, and supports rectangle or circle area. + */ +typedef enum { + LOCATION_BOUNDARY_NONE = 0, ///< Undefined geographical area type. + LOCATION_BOUNDARY_RECT, ///< Rectangular geographical area type. + LOCATION_BOUNDARY_CIRCLE, ///< Circle geographical area type. + LOCATION_BOUNDARY_POLYGON ///< Polygon geographical area type. +} LocationBoundaryType; + +/** + * @brief This represents a rectangular geographical area. + */ +typedef struct { + LocationPosition* left_top; ///< The left top position of rectangle. + LocationPosition* right_bottom; ///< The right bottom position of rectangle. +} LocationRect; + +/** + * @brief This represents a circle geographical area with center geographic position and radius. + */ +typedef struct { + LocationPosition* center; ///< The center position of a circle. + gdouble radius; ///< The radius of a circle. +} LocationCircle; + +/** + * @brief This represents a polygon geographical area. + */ +typedef struct { + GList *position_list; ///< The collection of positions +} LocationPolygon; + +/** + * @brief This represents boundary information such as rectangular or circle area. + */ +struct _LocationBoundary{ + LocationBoundaryType type; ///< The boundary type of this information. + union { + LocationRect rect; ///< The geographical information of a rectangle. + LocationCircle circle; ///< The geographical information of a circle. + LocationPolygon polygon; ///< The geographical information of a polygon. + }; +}; + +/** + * @brief Create a rectangular type of new #LocationBoundary with given information. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] left_top - left top position. + * @param [in] right_bottom - right bottom position. + * @return a new #LocationBoundary + * @retval NULL if error occured + */ +LocationBoundary *location_boundary_new_for_rect (LocationPosition *left_top, LocationPosition *right_bottom); + +/** + * @brief Create a circle type of new #LocationBoundary with given information. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] center - center position. + * @param [in] radius - radius. + * @return a new #LocationBoundary + * @retval NULL if error occured + */ +LocationBoundary *location_boundary_new_for_circle (LocationPosition *center, gdouble radius); + +/** + * @brief Create a polygon type of new #LocationBoundary with given information. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] position_list - the list of positions. + * @return a new #LocationBoundary + * @retval NULL if error occured + */ +LocationBoundary *location_boundary_new_for_polygon(GList *position_list); + +/** + * @brief Free a #LocationBoundary. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] boundary - a #LocationBoundary. + * @return None. + */ +void location_boundary_free (LocationBoundary *boundary); + +/** + * @brief Makes a copy of #LocationBoundary + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] boundary - a #LocationBoundary + * @return a new #LocationBoundary + * @retval NULL if error occured + */ +LocationBoundary *location_boundary_copy (const LocationBoundary* boundary); + +/** + * @brief + * Add Boundary on LocationFW. + * You should call this fuction when you want to receive a crossing signal(zone-in/zone-out) from #LocationBoundary. + * @remarks It supports multi-boundaries. \n + However a duplicated boundary would not be allowed. + * @pre + * #location_new should be called before.\n + * @post None. + * @param [in] obj - a #LocationObject + * @param [in] boundary - a #LocationBoundary + * @return int + * @retval 0 Success + * Please refer #LocationError for more information. + * @par Example + * @code +#include + +static void cb_zone_in (GObject *self, guint type, gpointer position, gpointer accuracy) +{ + g_printf ("[zone-in] position - lat: %f, long: %f", position->latitude, position->longitude); +} + +static void cb_zone_out (GObject *self, guint type, gpointer position, gpointer accuracy) +{ + g_printf ("[zone-out] position - lat: %f, long: %f", position->latitude, position->longitude); +} + +void location_test_boundary_add(LocationObject *loc) +{ + LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX); + LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX); + + LoationBoundary *boundary = location_boundary_new_for_rect (lt, rb); + + ret = location_boundary_add(loc, boundary); + + g_signal_connect(loc, "zone-in", G_CALLBACK(cb_zone_in), NULL); + g_siganl_connect(loc, "zone-out", G_CALLBACK(cb_zone_out), NULL); + + location_position_free(rb); + location_position_free(lt); +} + * @endcode + */ +int location_boundary_add(const LocationObject *obj, const LocationBoundary *boundary); + +/** + * @brief + * Remove Boundary on LocationFW. + * You should call this function when you don't want to receive a crossing signal(zone-in/zone-out) from #LocationBoundary any more. + * @remarks It supports multi-boundaries. + * @pre + * #location_init should be called before.\n + * @post None. + * @param [in] obj - a #LocationObject + * @param [in] boundary - a #LocationBoundary + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @par Example + * @code +#include + +void location_test_boundary_remove(LocationObject *loc) +{ + int ret = 0; + LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX); + LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX); + + LoationBoundary *boundary = location_boundary_new_for_rect (lt, rb); + + ret = location_boundary_remove(loc, boundary); + + location_position_free(rb); + location_position_free(lt); + +} + * @endcode + */ +int location_boundary_remove(const LocationObject *obj, const LocationBoundary *boundary); + +/** + * @brief + * Call a function for each element of a Boundary list. + * @remarks None. + * @pre + * #location_init should be called before.\n + * @post None. + * @param [in] obj - a #LocationObject + * @param [in] func - a #LocationBoundaryFunc + * @param [in] user_data - a #void + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @par Example + * @code +#include + +static void remove_boundary(LocationBoundary *boundary, void *user_data) +{ + LocationBoundary *loc = (LocationBoundary *) user_data; + if (loc == NULL || boundary == NULL) return; + + location_boundary_remove(loc, boundary); +} + +void location_test_boundary_foreach(LocationObject *loc) +{ + int ret = location_boundary_foreach(loc, remove_boundary, loc); +} + * @endcode + */ +int location_boundary_foreach(const LocationObject *obj, LocationBoundaryFunc func, gpointer user_data); + + +/** + * @brief Check if #LocationPosition is inside #LocationBoundary. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None.* @param [in] boundary - a #LocationBoundary + * @param [in] position - a #LocationPosition + * @return gboolean + * @retval\n + * TRUE - if inside\n + * FALSE - if outside\n + * @par Example + * @code +#include + +void location_test_boundary_if_inside(LocationObject *loc, LocationBoundary *boundary) +{ + gboolean is_inside = FALSE; + LocationPosition* position = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX); + is_inside = location_boundary_if_inside(boundary, position); + if (is_inside == TRUE) g_printf("The position is inside of the boundary\n"); + else g_printf("The position is outside of the boundary\n"); + +} + * @endcode + + */ +gboolean location_boundary_if_inside (LocationBoundary *boundary, LocationPosition *position); + +/** + * @brief Get bounding box of #LocationBoundary + */ +LocationBoundary *location_boundary_get_bounding_box (LocationBoundary *boundary); + + +/** + * @brief Get the center position of #LocationBoundary + */ +LocationPosition * location_boundary_get_center_position (LocationBoundary *boundary); + +/** + * @} @} + */ + +G_END_DECLS + +#endif diff --git a/location/manager/location-common-util.c b/location/manager/location-common-util.c new file mode 100644 index 0000000..290a6e0 --- /dev/null +++ b/location/manager/location-common-util.c @@ -0,0 +1,171 @@ +/* + * libslp-location + * + * 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 "location.h" +#include "location-common-util.h" +#include "location-setting.h" +#include "location-log.h" + +static gint compare_position (gconstpointer a, gconstpointer b) +{ + g_return_val_if_fail(a, 1); + g_return_val_if_fail(b, -1); + + if(location_position_equal((LocationPosition*) a, (LocationPosition *)b) == TRUE) { + return 0; + } + + return -1; +} + +static int +boundary_compare (gconstpointer comp1, gconstpointer comp2) +{ + g_return_val_if_fail(comp1, 1); + g_return_val_if_fail(comp2, -1); + + int ret = -1; + + LocationBoundary *boundary1 = (LocationBoundary *)comp1; + LocationBoundary *boundary2 = (LocationBoundary *)comp2; + + if (boundary1->type == boundary2->type) { + switch (boundary1->type) { + case LOCATION_BOUNDARY_CIRCLE: { + if (location_position_equal(boundary1->circle.center, boundary2->circle.center) + && boundary1->circle.radius == boundary2->circle.radius) { + ret = 0; + } + break; + } + case LOCATION_BOUNDARY_RECT: { + if (location_position_equal(boundary1->rect.left_top, boundary2->rect.left_top) + && location_position_equal(boundary1->rect.right_bottom, boundary2->rect.right_bottom)) { + ret = 0; + } + break; + } + case LOCATION_BOUNDARY_POLYGON: { + + GList *boundary1_next = NULL; + GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL; + if (g_list_length(boundary1->polygon.position_list) != g_list_length(boundary2->polygon.position_list)) { + return -1; + } + + // Find a matching index of Boundary2 with Boundary1's 1st postion. + boundary2_start = g_list_find_custom(boundary2->polygon.position_list, g_list_nth_data(boundary1->polygon.position_list, 0), (GCompareFunc) compare_position); + if (boundary2_start == NULL) return -1; + + boundary2_prev = g_list_previous(boundary2_start); + boundary2_next = g_list_next(boundary2_start); + if (boundary2_prev == NULL) boundary2_prev = g_list_last(boundary2->polygon.position_list); + if (boundary2_next == NULL) boundary2_next = g_list_first(boundary2->polygon.position_list); + + boundary1_next = g_list_next(boundary1->polygon.position_list); + if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_prev->data) == TRUE){ + boundary1_next = g_list_next(boundary1_next); + while (boundary1_next) { + boundary2_prev = g_list_previous(boundary2_prev); + if (boundary2_prev == NULL) boundary2_prev = g_list_last(boundary2->polygon.position_list); + if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*) boundary2_prev->data) == FALSE){ + return -1; + } + boundary1_next = g_list_next(boundary1_next); + } + ret = 0; + } + else if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_next->data) == TRUE) { + boundary1_next = g_list_next(boundary1_next); + while(boundary1_next) { + boundary2_next = g_list_next(boundary2_next); + if (boundary2_next == NULL) boundary2_next = g_list_first(boundary2->polygon.position_list); + if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*) boundary2_next->data) == FALSE){ + return -1; + } + boundary1_next = g_list_next(boundary1_next); + } + ret = 0; + } + else { + return -1; + } + break; + } + default:{ + ret = -1; + break; + } + + } + } + + return ret; +} + +int set_prop_boundary(GList **prev_boundary_list, GList *new_boundary_list) +{ + g_return_val_if_fail(new_boundary_list, LOCATION_ERROR_PARAMETER); + + int index; + GList *check_list = NULL; + + LocationBoundary *new_boundary = NULL; + LocationBoundary *copy_boundary = NULL; + + index = 0; + while((new_boundary = (LocationBoundary*) g_list_nth_data(new_boundary_list, index)) != NULL) { + + check_list = g_list_find_custom(*prev_boundary_list, new_boundary, (GCompareFunc)boundary_compare); + if (check_list == NULL) { + LOCATION_LOGD("Set Prop >> boundary type: [%d]", new_boundary->type); + copy_boundary = location_boundary_copy(new_boundary); + *prev_boundary_list = g_list_append(*prev_boundary_list, copy_boundary); + } + index++; + } + *prev_boundary_list = g_list_first(*prev_boundary_list); + + return LOCATION_ERROR_NONE; +} + + + +int set_prop_removal_boundary(GList **prev_boundary_list, LocationBoundary* boundary) +{ + g_return_val_if_fail(*prev_boundary_list, LOCATION_ERROR_PARAMETER); + + GList *check_list = NULL; + + check_list = g_list_find_custom (*prev_boundary_list, boundary, (GCompareFunc) boundary_compare); + if (check_list) { + LOCATION_LOGD("Found"); + *prev_boundary_list = g_list_delete_link(*prev_boundary_list, check_list); + } + + if (g_list_length(*prev_boundary_list) == 0 ) { + LOCATION_LOGD("Boundary List is empty"); + g_list_free(*prev_boundary_list); + *prev_boundary_list = NULL; + } + + return LOCATION_ERROR_NONE; +} diff --git a/location/manager/location-common-util.h b/location/manager/location-common-util.h new file mode 100644 index 0000000..99d005d --- /dev/null +++ b/location/manager/location-common-util.h @@ -0,0 +1,40 @@ +/* + * libslp-location + * + * 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_COMMON_UTIL_H__ +#define __LOCATION_COMMON_UTIL_H__ + +#include +#include + +/** + * @file location-common-util.h + * @brief This file contains the common utils for LocationObject. + */ + +G_BEGIN_DECLS + +int set_prop_boundary(GList **prev_boundary_list, GList *new_boundary_list); +int set_prop_removal_boundary(GList **prev_boundary_list, LocationBoundary *boundary); + +G_END_DECLS + +#endif diff --git a/location/manager/location-cps.c b/location/manager/location-cps.c new file mode 100644 index 0000000..63b0795 --- /dev/null +++ b/location/manager/location-cps.c @@ -0,0 +1,171 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-setting.h" +#include "location-log.h" + +#include "module-internal.h" + +#include "location-cps.h" +#include "location-marshal.h" +#include "location-ielement.h" + +typedef struct _LocationCpsPrivate { + LocationCpsMod *mod; + LocationPosition *pos; + LocationAccuracy *acc; +} LocationCpsPrivate; + +enum { + PROP_0, + PROP_METHOD_TYPE, + PROP_LAST_POSITION +}; + +#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_CPS, LocationCpsPrivate)) + +static void location_ielement_interface_init (LocationIElementInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (LocationCps, location_cps, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, + location_ielement_interface_init)); + +static void +location_cps_dispose (GObject *gobject) +{ + LOCATION_LOGD("location_cps_dispose"); + G_OBJECT_CLASS (location_cps_parent_class)->dispose (gobject); +} + +static void +location_cps_finalize (GObject *gobject) +{ + LOCATION_LOGD("location_cps_finalize"); + LocationCpsPrivate* priv = GET_PRIVATE(gobject); + module_free(priv->mod, "cps"); + priv->mod = NULL; + + G_OBJECT_CLASS (location_cps_parent_class)->finalize (gobject); +} + +static void +location_cps_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + LocationCpsPrivate *priv = GET_PRIVATE (object); + + switch (property_id){ + case PROP_METHOD_TYPE: + g_value_set_int(value, LOCATION_METHOD_CPS); + break; + case PROP_LAST_POSITION:{ + g_value_set_boxed (value, priv->pos); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static int +location_cps_get_position (LocationCps *self, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_cps_get_position"); + + LocationCpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + setting_retval_if_fail(GPS_ENABLED); + setting_retval_if_fail(NETWORK_ENABLED); + + LocModCpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_position, LOCATION_ERROR_NOT_AVAILABLE); + int ret = ops.get_position(priv->mod->handler, position, accuracy); + if(priv->pos) location_position_free(priv->pos); + if(priv->acc) location_accuracy_free(priv->acc); + priv->pos = location_position_copy(*position); + priv->acc = location_accuracy_copy(*accuracy); + return ret; +} + +static void +location_ielement_interface_init (LocationIElementInterface *iface) +{ + iface->get_position = (TYPE_GET_POSITION)location_cps_get_position; +} + +static void +location_cps_init (LocationCps *self) +{ + LOCATION_LOGD("location_cps_init"); + LocationCpsPrivate* priv = GET_PRIVATE(self); + + priv->mod = (LocationCpsMod*)module_new("cps"); + if(!priv->mod) LOCATION_LOGW("module loading failed"); + + priv->pos = NULL; + priv->acc = NULL; +} + +static void +location_cps_class_init (LocationCpsClass *klass) +{ + LOCATION_LOGD("location_cps_class_init"); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GParamSpec *pspec; + + gobject_class->get_property = location_cps_get_property; + + gobject_class->dispose = location_cps_dispose; + gobject_class->finalize = location_cps_finalize; + + g_type_class_add_private (klass, sizeof (LocationCpsPrivate)); + + pspec = g_param_spec_int ("method", + "method type", + "location method type name", + LOCATION_METHOD_CPS, + LOCATION_METHOD_CPS, + LOCATION_METHOD_CPS, + G_PARAM_READABLE); + g_object_class_install_property (gobject_class, + PROP_METHOD_TYPE, + pspec); + + pspec = g_param_spec_boxed ("last-position", + "cps last position prop", + "cps last position data", + LOCATION_TYPE_POSITION, + G_PARAM_READABLE); + g_object_class_install_property (gobject_class, + PROP_LAST_POSITION, + pspec); +} + diff --git a/location/manager/location-cps.h b/location/manager/location-cps.h new file mode 100644 index 0000000..8e12a36 --- /dev/null +++ b/location/manager/location-cps.h @@ -0,0 +1,58 @@ +/* + * libslp-location + * + * 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_CPS_H__ +#define __LOCATION_CPS_H__ + +#include + +/** + * @file location-cps.h + * @brief This file contains the internal definitions and structures related to CPS. + */ + +G_BEGIN_DECLS + +#define LOCATION_TYPE_CPS (location_cps_get_type ()) +#define LOCATION_CPS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_CPS, LocationCps)) +#define LOCATION_IS_CPS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_CPS)) +#define LOCATION_CPS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_CPS, LocationCpsClass)) +#define LOCATION_IS_CPS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_CPS)) +#define LOCATION_CPS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_CPS, LocationCpsClass)) + +typedef struct _LocationCps LocationCps; +typedef struct _LocationCpsClass LocationCpsClass; + +struct _LocationCps +{ + GObject parent_instance; +}; + +struct _LocationCpsClass +{ + GObjectClass parent_class; +}; + +GType location_cps_get_type (void); + +G_END_DECLS + +#endif diff --git a/location/manager/location-gps.c b/location/manager/location-gps.c new file mode 100644 index 0000000..131b41b --- /dev/null +++ b/location/manager/location-gps.c @@ -0,0 +1,617 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-setting.h" +#include "location-log.h" + +#include "module-internal.h" + +#include "location-gps.h" +#include "location-marshal.h" +#include "location-ielement.h" +#include "location-signaling-util.h" +#include "location-common-util.h" + + +typedef struct _LocationGpsPrivate { + LocationGpsMod* mod; + gboolean is_started; + gboolean set_noti; + gboolean enabled; + guint interval; + LocationPosition* pos; + LocationVelocity* vel; + LocationAccuracy* acc; + GList* boundary_list; + ZoneStatus zone_status; + guint sat_timestamp; + LocationSatellite* sat; +} LocationGpsPrivate; + +enum { + PROP_0, + PROP_DEV_NAME, + PROP_METHOD_TYPE, + PROP_LAST_POSITION, + PROP_UPDATE_INTERVAL, + PROP_BOUNDARY, + PROP_REMOVAL_BOUNDARY, + PROP_NMEA, + PROP_SATELLITE, + PROP_MAX +}; + +static guint32 signals[LAST_SIGNAL] = {0, }; +static GParamSpec *properties[PROP_MAX] = {NULL, }; + +#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_GPS, LocationGpsPrivate)) + +static void location_ielement_interface_init (LocationIElementInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (LocationGps, location_gps, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, + location_ielement_interface_init)); + +static void +gps_status_cb (gboolean enabled, + LocationStatus status, + gpointer self) +{ + LOCATION_LOGD("gps_status_cb"); + g_return_if_fail(self); + LocationGpsPrivate* priv = GET_PRIVATE(self); + enable_signaling(self, signals, &(priv->enabled), enabled, status); +} + +static void +gps_position_cb (gboolean enabled, + LocationPosition *pos, + LocationAccuracy *acc, + gpointer self) +{ + LOCATION_LOGD("gps_position_cb"); + g_return_if_fail(self); + g_return_if_fail(pos); + g_return_if_fail(acc); + LocationGpsPrivate* priv = GET_PRIVATE(self); + enable_signaling(self, signals, &(priv->enabled), enabled, pos->status); + position_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->pos), &(priv->acc), priv->boundary_list, &(priv->zone_status), enabled, pos, acc); +} + +static void +gps_velocity_cb (gboolean enabled, + LocationVelocity *vel, + LocationAccuracy *acc, + gpointer self) +{ + LOCATION_LOGD("gps_velocity_cb"); + g_return_if_fail(self); + LocationGpsPrivate* priv = GET_PRIVATE(self); + velocity_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->vel), enabled, vel, acc); +} + +static void +gps_satellite_cb (gboolean enabled, + LocationSatellite *sat, + gpointer self) +{ + LOCATION_LOGD("gps_satellite_cb"); + g_return_if_fail(self); + LocationGpsPrivate* priv = GET_PRIVATE(self); + satellite_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->sat_timestamp), &(priv->sat), enabled, sat); +} + +static void +location_setting_gps_cb (keynode_t *key, + gpointer self) +{ + LOCATION_LOGD("location_setting_gps_cb"); + g_return_if_fail(key); + g_return_if_fail(self); + LocationGpsPrivate* priv = GET_PRIVATE(self); + g_return_if_fail (priv->mod); + g_return_if_fail (priv->mod->handler); + + int ret = LOCATION_ERROR_NONE; + + if (0 == location_setting_get_key_val(key) && priv->mod->ops.stop && priv->is_started) { + LOCATION_LOGD("location stopped by setting"); + ret = priv->mod->ops.stop(priv->mod->handler); + if (ret == LOCATION_ERROR_NONE) priv->is_started = FALSE; + } + else if (1 == location_setting_get_key_val(key) && priv->mod->ops.start && !priv->is_started) { + LOCATION_LOGD("location resumed by setting"); + ret = priv->mod->ops.start (priv->mod->handler, gps_status_cb, gps_position_cb, gps_velocity_cb, gps_satellite_cb, self); + if (ret == LOCATION_ERROR_NONE) priv->is_started = TRUE; + } +} + +static int +location_gps_start (LocationGps *self) +{ + LOCATION_LOGD("location_gps_start"); + LocationGpsPrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.start, LOCATION_ERROR_NOT_AVAILABLE); + + if (priv->is_started == TRUE) return LOCATION_ERROR_NONE; + + int ret = LOCATION_ERROR_NONE; + int noti_err = 0; + + if (!location_setting_get_int(GPS_ENABLED)) { + ret = LOCATION_ERROR_NOT_ALLOWED; + } + else { + ret = priv->mod->ops.start (priv->mod->handler, gps_status_cb, gps_position_cb, gps_velocity_cb, gps_satellite_cb, self); + if (ret == LOCATION_ERROR_NONE) { + priv->is_started = TRUE; + } + else { + return ret; + } + } + + if(priv->set_noti == FALSE) { + noti_err = location_setting_add_notify (GPS_ENABLED, location_setting_gps_cb, self); + if (noti_err != 0) { + return LOCATION_ERROR_UNKNOWN; + } + priv->set_noti = TRUE; + } + + return ret; +} + +static int +location_gps_stop (LocationGps *self) +{ + LOCATION_LOGD("location_gps_stop"); + LocationGpsPrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.stop, LOCATION_ERROR_NOT_AVAILABLE); + + int ret = LOCATION_ERROR_NONE; + int noti_err = 0; + + if ( priv->is_started == TRUE) { + ret = priv->mod->ops.stop (priv->mod->handler); + if (ret == LOCATION_ERROR_NONE) { + priv->is_started = FALSE; + } + else { + return ret; + } + } + + if(priv->set_noti == TRUE) { + noti_err = location_setting_ignore_notify (GPS_ENABLED, location_setting_gps_cb); + if (noti_err != 0) { + return LOCATION_ERROR_UNKNOWN; + } + priv->set_noti = FALSE; + } + + return ret; +} + +static void +location_gps_dispose (GObject *gobject) +{ + LOCATION_LOGD("location_gps_dispose"); + G_OBJECT_CLASS (location_gps_parent_class)->dispose (gobject); +} + +static void +location_gps_finalize (GObject *gobject) +{ + LOCATION_LOGD("location_gps_finalize"); + LocationGpsPrivate* priv = GET_PRIVATE(gobject); + module_free(priv->mod, "gps"); + priv->mod = NULL; + G_OBJECT_CLASS (location_gps_parent_class)->finalize (gobject); +} + +static void +location_gps_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + LocationGpsPrivate* priv = GET_PRIVATE(object); + + g_return_if_fail (priv->mod); + g_return_if_fail (priv->mod->handler); + LocModGpsOps ops = priv->mod->ops; + + int ret = 0; + switch (property_id){ + case PROP_DEV_NAME: { + char* devname = g_value_dup_string(value); + LOCATION_LOGD("Set prop>> device_name: %s", devname); + if(ops.set_devname) + ops.set_devname(priv->mod->handler, devname); + g_free(devname); + break; + } + case PROP_BOUNDARY: { + GList *boundary_list = g_list_copy(g_value_get_pointer(value)); + ret = set_prop_boundary(&priv->boundary_list, boundary_list); + if(ret != 0) LOCATION_LOGD("Set boundary. Error[%d]", ret); + break; + } + case PROP_REMOVAL_BOUNDARY: { + LocationBoundary *req_boundary = (LocationBoundary*) g_value_dup_boxed(value); + ret = set_prop_removal_boundary(&priv->boundary_list, req_boundary); + if(ret != 0) LOCATION_LOGD("Removal boundary. Error[%d]", ret); + break; + } + case PROP_UPDATE_INTERVAL: { + guint interval = g_value_get_uint(value); + LOCATION_LOGD("Set prop>> update-interval: %u", interval); + if(interval > 0) { + if(interval < LOCATION_UPDATE_INTERVAL_MAX) + priv->interval = interval; + else + priv->interval = (guint)LOCATION_UPDATE_INTERVAL_MAX; + } + else + priv->interval = (guint)LOCATION_UPDATE_INTERVAL_DEFAULT; + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +location_gps_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + LocationGpsPrivate *priv = GET_PRIVATE (object); + + g_return_if_fail (priv->mod); + g_return_if_fail (priv->mod->handler); + LocModGpsOps ops = priv->mod->ops; + switch (property_id) { + case PROP_DEV_NAME: { + char* devname = NULL; + if(ops.get_devname) + ops.get_devname(priv->mod->handler, &devname); + LOCATION_LOGD ("Get prop>> device_name: %s", devname); + g_value_set_string (value, devname); + g_free(devname); + break; + } + case PROP_METHOD_TYPE: + g_value_set_int(value, LOCATION_METHOD_GPS); + break; + case PROP_LAST_POSITION: + g_value_set_boxed (value, priv->pos); + break; + case PROP_UPDATE_INTERVAL: + g_value_set_uint(value, priv->interval); + break; + case PROP_BOUNDARY: + g_value_set_pointer(value, g_list_first(priv->boundary_list)); + break; + case PROP_NMEA: { + char *nmea_data = NULL; + if (ops.get_nmea && LOCATION_ERROR_NONE == ops.get_nmea(priv->mod->handler, &nmea_data) && nmea_data) { + LOCATION_LOGD("Get prop>> Lastest nmea: \n%s", nmea_data); + g_value_set_string(value, nmea_data); + g_free(nmea_data); + } else { + LOCATION_LOGW("Get prop>> Lastest nmea: failed"); + g_value_set_string(value, NULL); + } + break; + } + case PROP_SATELLITE: { + LocationSatellite *satellite = NULL; + if (ops.get_satellite && priv->mod->handler && LOCATION_ERROR_NONE == ops.get_satellite(priv->mod->handler, &satellite) && satellite){ + LOCATION_LOGD("Get prop>> Last sat: num_used(%d) num_view(%d)", satellite->num_of_sat_used, satellite->num_of_sat_inview); + g_value_set_boxed (value, satellite); + location_satellite_free(satellite); + } else { + LOCATION_LOGW("Get prop>> Last sat: failed"); + g_value_set_boxed (value, NULL); + } + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static int +location_gps_get_position (LocationGps *self, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_gps_get_position"); + + LocationGpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + setting_retval_if_fail(GPS_ENABLED); + + LocModGpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_position, LOCATION_ERROR_NOT_AVAILABLE); + return ops.get_position(priv->mod->handler, position, accuracy); +} + +static int +location_gps_get_last_position (LocationGps *self, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_gps_get_position"); + // Enable to get a last position even though GPS_ENABLE dose not set on + + LocationGpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + + LocModGpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_last_position, LOCATION_ERROR_NOT_AVAILABLE); + return ops.get_last_position(priv->mod->handler, position, accuracy); + +} + +static int +location_gps_get_velocity (LocationGps *self, + LocationVelocity **velocity, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_gps_get_velocity"); + + LocationGpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + setting_retval_if_fail(GPS_ENABLED); + + LocModGpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_velocity, LOCATION_ERROR_NOT_AVAILABLE); + return ops.get_velocity(priv->mod->handler, velocity, accuracy); +} + +static int +location_gps_get_last_velocity (LocationGps *self, + LocationVelocity **velocity, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_gps_get_last_velocity"); + + LocationGpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + setting_retval_if_fail(GPS_ENABLED); + + LocModGpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_last_velocity, LOCATION_ERROR_NOT_AVAILABLE); + return ops.get_last_velocity(priv->mod->handler, velocity, accuracy); + +} + +static int +location_gps_get_satellite (LocationGps *self, + LocationSatellite **satellite) +{ + LOCATION_LOGD("location_gps_get_satellite"); + + LocationGpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + setting_retval_if_fail(GPS_ENABLED); + + LocModGpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_satellite, LOCATION_ERROR_NOT_AVAILABLE); + return ops.get_satellite(priv->mod->handler, satellite); +} + +static int +location_gps_get_last_satellite (LocationGps *self, + LocationSatellite **satellite) +{ + LOCATION_LOGD("location_gps_get_last_satellite"); + + LocationGpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + setting_retval_if_fail(GPS_ENABLED); + + LocModGpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_last_satellite, LOCATION_ERROR_NOT_AVAILABLE); + return ops.get_last_satellite(priv->mod->handler, satellite); +} + +static void +location_ielement_interface_init (LocationIElementInterface *iface) +{ + iface->start = (TYPE_START_FUNC)location_gps_start; + iface->stop = (TYPE_STOP_FUNC)location_gps_stop; + iface->get_position = (TYPE_GET_POSITION)location_gps_get_position; + iface->get_last_position = (TYPE_GET_POSITION)location_gps_get_last_position; + iface->get_velocity = (TYPE_GET_VELOCITY)location_gps_get_velocity; + iface->get_last_velocity = (TYPE_GET_VELOCITY)location_gps_get_last_velocity; + iface->get_satellite = (TYPE_GET_SATELLITE)location_gps_get_satellite; + iface->get_last_satellite = (TYPE_GET_SATELLITE)location_gps_get_last_satellite; +} + +static void +location_gps_init (LocationGps *self) +{ + LOCATION_LOGD("location_gps_init"); + LocationGpsPrivate* priv = GET_PRIVATE(self); + + priv->mod = (LocationGpsMod*)module_new("gps"); + if(!priv->mod) LOCATION_LOGW("module loading failed"); + + priv->is_started = FALSE; + priv->set_noti = FALSE; + priv->enabled= FALSE; + priv->interval = LOCATION_UPDATE_INTERVAL_DEFAULT; + + priv->pos = NULL; + priv->vel = NULL; + priv->acc = NULL; + priv->zone_status = ZONE_STATUS_NONE; + priv->boundary_list = NULL; +} + +static void +location_gps_class_init (LocationGpsClass *klass) +{ + LOCATION_LOGD("location_gps_class_init"); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->set_property = location_gps_set_property; + gobject_class->get_property = location_gps_get_property; + + gobject_class->dispose = location_gps_dispose; + gobject_class->finalize = location_gps_finalize; + + g_type_class_add_private (klass, sizeof (LocationGpsPrivate)); + + signals[SERVICE_ENABLED] = g_signal_new ("service-enabled", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationGpsClass, enabled), + NULL, NULL, + location_VOID__UINT, + G_TYPE_NONE, 1, + G_TYPE_UINT); + + signals[SERVICE_DISABLED] = g_signal_new ("service-disabled", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationGpsClass, disabled), + NULL, NULL, + location_VOID__UINT, + G_TYPE_NONE, 1, + G_TYPE_UINT); + + signals[SERVICE_UPDATED] = g_signal_new ("service-updated", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationGpsClass, updated), + NULL, NULL, + location_VOID__UINT_POINTER_POINTER, + G_TYPE_NONE, 3, + G_TYPE_UINT, + G_TYPE_POINTER, + G_TYPE_POINTER); + + signals[ZONE_IN] = g_signal_new ("zone-in", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationGpsClass, zone_in), + NULL, NULL, + location_VOID__UINT_POINTER_POINTER, + G_TYPE_NONE, 3, + G_TYPE_UINT, + G_TYPE_POINTER, + G_TYPE_POINTER); + + signals[ZONE_OUT] = g_signal_new ("zone-out", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationGpsClass, zone_out), + NULL, NULL, + location_VOID__UINT_POINTER_POINTER, + G_TYPE_NONE, 3, + G_TYPE_UINT, + G_TYPE_POINTER, + G_TYPE_POINTER); + + properties[PROP_DEV_NAME] = g_param_spec_string ("dev-name", + "gps device name prop", + "gps device name", + "/dev/rfcomm0", + G_PARAM_READWRITE); + + properties[PROP_METHOD_TYPE] = g_param_spec_int ("method", + "method type", + "location method type name", + LOCATION_METHOD_GPS, + LOCATION_METHOD_GPS, + LOCATION_METHOD_GPS, + G_PARAM_READABLE); + + properties[PROP_LAST_POSITION] = g_param_spec_boxed ("last-position", + "gps last position prop", + "gps last position data", + LOCATION_TYPE_POSITION, + G_PARAM_READABLE); + + properties[PROP_UPDATE_INTERVAL] = g_param_spec_uint ("update-interval", + "gps update interval prop", + "gps update interval data", + LOCATION_UPDATE_INTERVAL_MIN, + LOCATION_UPDATE_INTERVAL_MAX, + LOCATION_UPDATE_INTERVAL_DEFAULT, + G_PARAM_READWRITE); + + properties[PROP_BOUNDARY] = g_param_spec_pointer ("boundary", + "gps boundary prop", + "gps boundary data", + G_PARAM_READWRITE); + + properties[PROP_REMOVAL_BOUNDARY] = g_param_spec_boxed("removal-boundary", + "gps removal boundary prop", + "gps removal boundary data", + LOCATION_TYPE_BOUNDARY, + G_PARAM_READWRITE); + + + properties[PROP_NMEA] = g_param_spec_string ("nmea", + "gps NMEA name prop", + "gps NMEA", + NULL, + G_PARAM_READABLE); + + properties[PROP_SATELLITE] = g_param_spec_boxed ("satellite", + "gps satellite prop", + "gps satellite data", + LOCATION_TYPE_SATELLITE, + G_PARAM_READABLE); + + g_object_class_install_properties (gobject_class, + PROP_MAX, + properties); + +} diff --git a/location/manager/location-gps.h b/location/manager/location-gps.h new file mode 100644 index 0000000..e658ce9 --- /dev/null +++ b/location/manager/location-gps.h @@ -0,0 +1,65 @@ +/* + * libslp-location + * + * 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_GPS_H__ +#define __LOCATION_GPS_H__ + +#include + + +/** + * @file location-gps.h + * @brief This file contains the internal definitions and structures related to GPS. + */ + +G_BEGIN_DECLS + +#define LOCATION_TYPE_GPS (location_gps_get_type ()) +#define LOCATION_GPS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_GPS, LocationGps)) +#define LOCATION_IS_GPS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_GPS)) +#define LOCATION_GPS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_GPS, LocationGpsClass)) +#define LOCATION_IS_GPS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_GPS)) +#define LOCATION_GPS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_GPS, LocationGpsClass)) + +typedef struct _LocationGps LocationGps; +typedef struct _LocationGpsClass LocationGpsClass; + +struct _LocationGps +{ + GObject parent_instance; +}; + +struct _LocationGpsClass +{ + GObjectClass parent_class; + + void (* enabled) (guint type); + void (* disabled) (guint type); + void (* updated) (guint type, gpointer data, gpointer accuracy); + void (* zone_in) (guint type, gpointer position, gpointer boundary); + void (* zone_out) (guint type, gpointer position, gpointer boundary); +}; + +GType location_gps_get_type (void); + +G_END_DECLS + +#endif diff --git a/location/manager/location-hybrid.c b/location/manager/location-hybrid.c new file mode 100644 index 0000000..41f4c9c --- /dev/null +++ b/location/manager/location-hybrid.c @@ -0,0 +1,711 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-setting.h" +#include "location-log.h" + +#include "module-internal.h" + +#include "location-hybrid.h" +#include "location-marshal.h" +#include "location-ielement.h" +#include "location-signaling-util.h" +#include "location-common-util.h" + +#include "location-gps.h" +#include "location-wps.h" +#include "location-sps.h" + +typedef struct _LocationHybridPrivate { + gboolean is_started; + gboolean gps_enabled; + gboolean wps_enabled; + gboolean sps_enabled; + guint interval; + guint sat_timestamp; + LocationObject *gps; + LocationObject *wps; + LocationObject *sps; + gboolean enabled; + LocationMethod current_method; + LocationPosition *pos; + LocationVelocity *vel; + LocationAccuracy *acc; + LocationSatellite *sat; + GList* boundary_list; + ZoneStatus zone_status; + +} LocationHybridPrivate; + +enum { + PROP_0, + PROP_METHOD_TYPE, + PROP_LAST_POSITION, + PROP_UPDATE_INTERVAL, + PROP_BOUNDARY, + PROP_REMOVAL_BOUNDARY, + PROP_MAX +}; + +static guint32 signals[LAST_SIGNAL] = {0, }; +static GParamSpec *properties[PROP_MAX] = {NULL, }; + +#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_HYBRID, LocationHybridPrivate)) + +static void location_ielement_interface_init (LocationIElementInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (LocationHybrid, location_hybrid, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, + location_ielement_interface_init)); + + +static LocationObject* +hybrid_get_update_method_obj (LocationHybridPrivate* priv) +{ + if(!priv->sps && !priv->gps && !priv->wps) return NULL; + + LocationObject* obj = NULL; + if (priv->sps_enabled) { + LOCATION_LOGW("Current method is SPS"); + priv->current_method = LOCATION_METHOD_SPS; + obj = priv->sps; + } else if (priv->gps_enabled) { + LOCATION_LOGW("Current method is GPS"); + priv->current_method = LOCATION_METHOD_GPS; + obj = priv->gps; + } else if (priv->wps_enabled) { + LOCATION_LOGW("Current method is WPS"); + priv->current_method = LOCATION_METHOD_WPS; + obj = priv->wps; + } else { + LOCATION_LOGW("No current method available"); + priv->current_method = LOCATION_METHOD_HYBRID; + obj = NULL; + } + return obj; +} + +static gboolean +hybrid_is_equal_g_type_method(GType g_type, LocationMethod method) +{ + if (g_type == LOCATION_TYPE_SPS && method == LOCATION_METHOD_SPS) return TRUE; + if (g_type == LOCATION_TYPE_GPS && method == LOCATION_METHOD_GPS) return TRUE; + if (g_type == LOCATION_TYPE_WPS && method == LOCATION_METHOD_WPS) return TRUE; + return FALSE; +} + +static void +hybrid_update_sps(LocationHybrid* self, + guint type, + gpointer data, + gpointer accuracy) +{ + LocationHybridPrivate* priv = GET_PRIVATE(self); + if (!priv->sps) return; + LOCATION_LOGD ("hybrid_update_sps"); + + switch (type) { + case POSITION_UPDATED: { + if (data) g_object_set(priv->sps, "position-base", data, NULL); + if (priv->gps) { + LocationSatellite* sat = NULL; + g_object_get(priv->gps, "satellite", &sat, NULL); + if (sat) { + g_object_set(priv->sps, "satellite-info", sat, NULL); + location_satellite_free (sat); + } + } + if (accuracy) g_object_set(priv->sps, "accuracy-info", accuracy, NULL); + break; + } + case VELOCITY_UPDATED: + if (data) g_object_set(priv->sps, "velocity-base", data, NULL); + if (accuracy) g_object_set(priv->sps, "accuracy-info", accuracy, NULL); + break; + } +} + +static void +hybrid_service_updated (GObject *obj, + guint type, + gpointer data, + gpointer accuracy, + gpointer self) +{ + LOCATION_LOGD ("hybrid_service_updated"); + LocationHybridPrivate* priv = GET_PRIVATE((LocationHybrid*)self); + GType g_type = G_TYPE_FROM_INSTANCE(obj); + if (g_type == LOCATION_TYPE_GPS) { + if (type == SATELLITE_UPDATED) { + LocationSatellite *sat = (LocationSatellite *) data; + satellite_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->sat_timestamp), &(priv->sat), TRUE, sat); + } else hybrid_update_sps((LocationHybrid*)self, type, data, accuracy); + } + + if (hybrid_is_equal_g_type_method(g_type, priv->current_method)) { + LocationAccuracy *acc = (LocationAccuracy*)accuracy; + if (type == POSITION_UPDATED) { + LocationPosition *pos = (LocationPosition*)data; + position_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->pos), &(priv->acc), priv->boundary_list, &(priv->zone_status), TRUE, pos, acc); + } else if (type == VELOCITY_UPDATED) { + LocationVelocity *vel = (LocationVelocity*) data; + velocity_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->vel), TRUE, vel, acc); + }else LOCATION_LOGW ("Undefined GType updated"); + } + +} + +static void +hybrid_service_enabled (GObject *obj, + guint status, + gpointer self) +{ + LOCATION_LOGD ("hybrid_service_enabled"); + LocationHybridPrivate* priv = GET_PRIVATE((LocationHybrid*)self); + GType g_type = G_TYPE_FROM_INSTANCE(obj); + if (g_type == LOCATION_TYPE_SPS) priv->sps_enabled = TRUE; + else if(g_type == LOCATION_TYPE_GPS) priv->gps_enabled = TRUE; + else if(g_type == LOCATION_TYPE_WPS) priv->wps_enabled = TRUE; + else { + LOCATION_LOGW("Undefined GType enabled"); + return; + } + hybrid_get_update_method_obj(priv); + if(priv->sps_enabled || priv->gps_enabled || priv->wps_enabled) + enable_signaling(self, signals, &(priv->enabled), TRUE, status); +} + +static void +hybrid_service_disabled (GObject *obj, + guint status, + gpointer self) +{ + LOCATION_LOGD ("hybrid_service_disabled"); + LocationHybridPrivate* priv = GET_PRIVATE((LocationHybrid*)self); + GType g_type = G_TYPE_FROM_INSTANCE(obj); + if (g_type == LOCATION_TYPE_SPS) priv->sps_enabled = FALSE; + else if(g_type == LOCATION_TYPE_GPS) priv->gps_enabled = FALSE; + else if(g_type == LOCATION_TYPE_WPS) priv->wps_enabled = FALSE; + else { + LOCATION_LOGW("Undefined GType disabled"); + return; + } + hybrid_get_update_method_obj(priv); + if(!priv->sps_enabled && !priv->gps_enabled && !priv->wps_enabled) + enable_signaling(self, signals, &(priv->enabled), FALSE, status); +} + +static int +location_hybrid_start (LocationHybrid *self) +{ + LOCATION_LOGD("location_hybrid_start"); + + int ret_gps = LOCATION_ERROR_NONE; + int ret_wps = LOCATION_ERROR_NONE; + int ret_sps = LOCATION_ERROR_NONE; + + LocationHybridPrivate* priv = GET_PRIVATE(self); + if (priv->is_started == TRUE) + return LOCATION_ERROR_NONE; + + if(priv->gps) ret_gps = location_start(priv->gps); + if(priv->wps) ret_wps = location_start(priv->wps); + if(priv->sps) ret_sps = location_start(priv->sps); + + if (ret_gps != LOCATION_ERROR_NONE && + ret_wps != LOCATION_ERROR_NONE && + ret_sps != LOCATION_ERROR_NONE) { + if (ret_gps == LOCATION_ERROR_NOT_ALLOWED || + ret_wps == LOCATION_ERROR_NOT_ALLOWED || + ret_sps == LOCATION_ERROR_NOT_ALLOWED) { + priv->is_started = TRUE; + return LOCATION_ERROR_NOT_ALLOWED; + } + else { + return LOCATION_ERROR_NOT_AVAILABLE; + } + } + + priv->is_started = TRUE; + return LOCATION_ERROR_NONE; +} + +static int +location_hybrid_stop (LocationHybrid *self) +{ + LOCATION_LOGD("location_hybrid_stop"); + + LocationHybridPrivate* priv = GET_PRIVATE(self); + if( priv->is_started == FALSE) + return LOCATION_ERROR_NONE; + + int ret_gps = LOCATION_ERROR_NONE; + int ret_wps = LOCATION_ERROR_NONE; + int ret_sps = LOCATION_ERROR_NONE; + + if(priv->gps) ret_gps = location_stop(priv->gps); + if(priv->wps) ret_wps = location_stop(priv->wps); + if(priv->sps) ret_sps = location_stop(priv->sps); + + priv->is_started = FALSE; + + if (ret_gps != LOCATION_ERROR_NONE && + ret_wps != LOCATION_ERROR_NONE && + ret_sps != LOCATION_ERROR_NONE) + return LOCATION_ERROR_NOT_AVAILABLE; + + return LOCATION_ERROR_NONE; +} + +static void +location_hybrid_dispose (GObject *gobject) +{ + LOCATION_LOGD("location_hybrid_dispose"); + G_OBJECT_CLASS (location_hybrid_parent_class)->dispose (gobject); +} + +static void +location_hybrid_finalize (GObject *gobject) +{ + LOCATION_LOGD("location_hybrid_finalize"); + LocationHybridPrivate* priv = GET_PRIVATE(gobject); + + if (priv->gps) { + g_signal_handlers_disconnect_by_func(priv->gps, G_CALLBACK (hybrid_service_enabled), gobject); + g_signal_handlers_disconnect_by_func(priv->gps, G_CALLBACK (hybrid_service_disabled), gobject); + g_signal_handlers_disconnect_by_func(priv->gps, G_CALLBACK (hybrid_service_updated), gobject); + location_free(priv->gps); + } + if (priv->wps) { + g_signal_handlers_disconnect_by_func(priv->wps, G_CALLBACK (hybrid_service_enabled), gobject); + g_signal_handlers_disconnect_by_func(priv->wps, G_CALLBACK (hybrid_service_disabled), gobject); + g_signal_handlers_disconnect_by_func(priv->wps, G_CALLBACK (hybrid_service_updated), gobject); + location_free(priv->wps); + } + if (priv->sps) { + g_signal_handlers_disconnect_by_func(priv->sps, G_CALLBACK (hybrid_service_enabled), gobject); + g_signal_handlers_disconnect_by_func(priv->sps, G_CALLBACK (hybrid_service_disabled), gobject); + g_signal_handlers_disconnect_by_func(priv->sps, G_CALLBACK (hybrid_service_updated), gobject); + location_free(priv->sps); + } + + G_OBJECT_CLASS (location_hybrid_parent_class)->finalize (gobject); +} + +static void +location_hybrid_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + LocationHybridPrivate* priv = GET_PRIVATE(object); + if (!priv->gps && !priv->wps && !priv->sps) { + LOCATION_LOGW("Set property is not available now"); + return; + } + + int ret = 0; + switch (property_id){ + case PROP_BOUNDARY:{ + GList *boundary_list = (GList *)g_list_copy(g_value_get_pointer(value)); + ret = set_prop_boundary(&priv->boundary_list, boundary_list); + if(ret != 0) LOCATION_LOGD("Set boundary. Error[%d]", ret); + break; + } + case PROP_REMOVAL_BOUNDARY: { + LocationBoundary *req_boundary = (LocationBoundary*) g_value_dup_boxed(value); + ret = set_prop_removal_boundary(&priv->boundary_list, req_boundary); + if(ret != 0) LOCATION_LOGD("Removal boundary. Error[%d]", ret); + break; + } + case PROP_UPDATE_INTERVAL: { + guint interval = g_value_get_uint(value); + if(interval > 0) { + if(interval < LOCATION_UPDATE_INTERVAL_MAX) + priv->interval = interval; + else + priv->interval = (guint) LOCATION_UPDATE_INTERVAL_MAX; + + } + else + priv->interval = LOCATION_UPDATE_INTERVAL_DEFAULT; + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +location_hybrid_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + LocationHybridPrivate *priv = GET_PRIVATE (object); + if(!priv->gps && !priv->wps && !priv->sps){ + LOCATION_LOGW("Get property is not available now"); + return; + } + + LOCATION_LOGW("Get Propery ID[%d]", property_id); + + switch (property_id){ + case PROP_METHOD_TYPE: + g_value_set_int(value, priv->current_method); + break; + case PROP_LAST_POSITION: + g_value_set_boxed(value, priv->pos); + break; + case PROP_BOUNDARY: + g_value_set_pointer(value, g_list_first(priv->boundary_list)); + break; + case PROP_UPDATE_INTERVAL: + g_value_set_uint(value, priv->interval); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static int +location_hybrid_get_position (LocationHybrid *self, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_hybrid_get_position"); + setting_retval_if_fail(GPS_ENABLED); + + LocationHybridPrivate *priv = GET_PRIVATE (self); + LocationObject *obj = hybrid_get_update_method_obj(priv); + if(!obj) return LOCATION_ERROR_NOT_AVAILABLE; + return location_get_position (obj, position, accuracy); +} + +static int +location_hybrid_get_last_position (LocationHybrid *self, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_hybrid_get_last_position"); + setting_retval_if_fail(GPS_ENABLED); + + int ret = LOCATION_ERROR_NONE; + LocationPosition *gps_pos = NULL, *wps_pos = NULL; + LocationAccuracy *gps_acc = NULL, *wps_acc = NULL; + LocationHybridPrivate *priv = GET_PRIVATE (self); + + if (priv->gps) location_get_last_position (priv->gps, &gps_pos, &gps_acc); + if (priv->wps) location_get_last_position (priv->wps, &wps_pos, &wps_acc); + + if (gps_pos && wps_pos) { + if (wps_pos->timestamp > gps_pos->timestamp) { + *position = wps_pos; + *accuracy = wps_acc; + location_position_free (gps_pos); + location_accuracy_free (gps_acc); + } + else { + *position = gps_pos; + *accuracy = gps_acc; + location_position_free (wps_pos); + location_accuracy_free (wps_acc); + } + } else if (gps_pos) { + *position = gps_pos; + *accuracy = gps_acc; + } else if (wps_pos) { + *position = wps_pos; + *accuracy = wps_acc; + } else { + ret = LOCATION_ERROR_NOT_AVAILABLE; + } + + return ret; +} + +static int +location_hybrid_get_velocity (LocationHybrid *self, + LocationVelocity **velocity, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_hybrid_get_velocity"); + setting_retval_if_fail(GPS_ENABLED); + + LocationHybridPrivate *priv = GET_PRIVATE (self); + LocationObject *obj = hybrid_get_update_method_obj(priv); + if(!obj) return LOCATION_ERROR_NOT_AVAILABLE; + return location_get_velocity (obj, velocity, accuracy); +} + +static int +location_hybrid_get_last_velocity (LocationHybrid *self, + LocationVelocity **velocity, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_hybrid_get_last_velocity"); + setting_retval_if_fail(GPS_ENABLED); + + int ret = LOCATION_ERROR_NONE; + LocationHybridPrivate *priv = GET_PRIVATE (self); + LocationVelocity *gps_vel = NULL, *wps_vel = NULL; + LocationAccuracy *gps_acc = NULL, *wps_acc = NULL; + + if (priv->gps) location_get_last_velocity (priv->gps, &gps_vel, &gps_acc); + if (priv->wps) location_get_last_velocity (priv->wps, &wps_vel, &wps_acc); + + if (gps_vel && wps_vel) { + if (wps_vel->timestamp > gps_vel->timestamp) { + *velocity = wps_vel; + *accuracy = wps_acc; + location_velocity_free (gps_vel); + location_accuracy_free (gps_acc); + } else { + *velocity = gps_vel; + *accuracy = gps_acc; + location_velocity_free (wps_vel); + location_accuracy_free (wps_acc); + } + } + else if (gps_vel) { + *velocity = gps_vel; + *accuracy = gps_acc; + } else if (wps_vel) { + *velocity = wps_vel; + *accuracy = wps_acc; + } else { + *velocity = NULL; + *accuracy = NULL; + ret = LOCATION_ERROR_NOT_AVAILABLE; + } + + return ret; +} + +static int +location_hybrid_get_satellite (LocationHybrid *self, + LocationSatellite **satellite) +{ + LOCATION_LOGD("location_hybrid_get_satellite"); + setting_retval_if_fail(GPS_ENABLED); + + int ret = LOCATION_ERROR_NONE; + LocationHybridPrivate *priv = GET_PRIVATE (self); + if (priv->gps) ret = location_get_satellite (priv->gps, satellite); + else { + *satellite = NULL; + ret = LOCATION_ERROR_NOT_AVAILABLE; + } + + return ret; +} + +static int +location_hybrid_get_last_satellite (LocationHybrid *self, + LocationSatellite **satellite) +{ + LOCATION_LOGD("location_hybrid_get_last_satellite"); + setting_retval_if_fail(GPS_ENABLED); + + int ret = LOCATION_ERROR_NONE; + LocationHybridPrivate *priv = GET_PRIVATE (self); + + if (priv->gps) ret = location_get_last_satellite (priv->gps, satellite); + else { + *satellite = NULL; + ret = LOCATION_ERROR_NOT_AVAILABLE; + } + + return ret; +} + +static void +location_ielement_interface_init (LocationIElementInterface *iface) +{ + iface->start = (TYPE_START_FUNC)location_hybrid_start; + iface->stop = (TYPE_STOP_FUNC)location_hybrid_stop; + iface->get_position = (TYPE_GET_POSITION)location_hybrid_get_position; + iface->get_last_position = (TYPE_GET_POSITION)location_hybrid_get_last_position; + iface->get_velocity = (TYPE_GET_VELOCITY)location_hybrid_get_velocity; + iface->get_last_velocity = (TYPE_GET_VELOCITY)location_hybrid_get_last_velocity; + iface->get_satellite = (TYPE_GET_SATELLITE)location_hybrid_get_satellite; + iface->get_last_satellite = (TYPE_GET_SATELLITE)location_hybrid_get_last_satellite; +} + +static void +location_hybrid_init (LocationHybrid *self) +{ + LOCATION_LOGD("location_hybrid_init"); + LocationHybridPrivate* priv = GET_PRIVATE(self); + + priv->is_started = FALSE; + priv->interval = LOCATION_UPDATE_INTERVAL_DEFAULT; + priv->gps_enabled = FALSE; + priv->wps_enabled = FALSE; + priv->sps_enabled = FALSE; + priv->gps = NULL; + priv->wps = NULL; + priv->sps = NULL; + + if(location_is_supported_method(LOCATION_METHOD_GPS)) priv->gps = location_new (LOCATION_METHOD_GPS); + if(location_is_supported_method(LOCATION_METHOD_WPS)) priv->wps = location_new (LOCATION_METHOD_WPS); + if(location_is_supported_method(LOCATION_METHOD_SPS)) priv->sps = location_new (LOCATION_METHOD_SPS); + + if(priv->gps){ + g_signal_connect (priv->gps, "service-enabled", G_CALLBACK(hybrid_service_enabled), self); + g_signal_connect (priv->gps, "service-disabled", G_CALLBACK(hybrid_service_disabled), self); + g_signal_connect (priv->gps, "service-updated", G_CALLBACK(hybrid_service_updated), self); + } + if(priv->wps){ + g_signal_connect (priv->wps, "service-enabled", G_CALLBACK(hybrid_service_enabled), self); + g_signal_connect (priv->wps, "service-disabled", G_CALLBACK(hybrid_service_disabled), self); + g_signal_connect (priv->wps, "service-updated", G_CALLBACK(hybrid_service_updated), self); + } + if(priv->sps){ + g_signal_connect (priv->sps, "service-enabled", G_CALLBACK(hybrid_service_enabled), self); + g_signal_connect (priv->sps, "service-disabled", G_CALLBACK(hybrid_service_disabled), self); + g_signal_connect (priv->sps, "service-updated", G_CALLBACK(hybrid_service_updated), self); + } + + priv->current_method = LOCATION_METHOD_HYBRID; + priv->enabled= FALSE; + + priv->pos = NULL; + priv->vel = NULL; + priv->acc = NULL; + priv->zone_status = ZONE_STATUS_NONE; + priv->boundary_list = NULL; +} + +static void +location_hybrid_class_init (LocationHybridClass *klass) +{ + LOCATION_LOGD("location_hybrid_class_init"); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->set_property = location_hybrid_set_property; + gobject_class->get_property = location_hybrid_get_property; + + gobject_class->dispose = location_hybrid_dispose; + gobject_class->finalize = location_hybrid_finalize; + + g_type_class_add_private (klass, sizeof (LocationHybridPrivate)); + + signals[SERVICE_ENABLED] = g_signal_new ("service-enabled", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationHybridClass, enabled), + NULL, NULL, + location_VOID__UINT, + G_TYPE_NONE, 1, + G_TYPE_UINT); + + signals[SERVICE_DISABLED] = g_signal_new ("service-disabled", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationHybridClass, disabled), + NULL, NULL, + location_VOID__UINT, + G_TYPE_NONE, 1, + G_TYPE_UINT); + + signals[SERVICE_UPDATED] = g_signal_new ("service-updated", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationHybridClass, updated), + NULL, NULL, + location_VOID__UINT_POINTER_POINTER, + G_TYPE_NONE, 3, + G_TYPE_UINT, + G_TYPE_POINTER, + G_TYPE_POINTER); + + signals[ZONE_IN] = g_signal_new ("zone-in", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationHybridClass, zone_in), + NULL, NULL, + location_VOID__UINT_POINTER_POINTER, + G_TYPE_NONE, 3, + G_TYPE_UINT, + G_TYPE_POINTER, + G_TYPE_POINTER); + + signals[ZONE_OUT] = g_signal_new ("zone-out", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationHybridClass, zone_out), + NULL, NULL, + location_VOID__UINT_POINTER_POINTER, + G_TYPE_NONE, 3, + G_TYPE_UINT, + G_TYPE_POINTER, + G_TYPE_POINTER); + + properties[PROP_METHOD_TYPE] = g_param_spec_int ("method", + "method type", + "location method type name", + LOCATION_METHOD_HYBRID, + LOCATION_METHOD_HYBRID, + LOCATION_METHOD_HYBRID, + G_PARAM_READABLE); + + properties[PROP_LAST_POSITION] = g_param_spec_boxed ("last-position", + "hybrid last position prop", + "hybrid last position data", + LOCATION_TYPE_POSITION, + G_PARAM_READABLE); + + properties[PROP_UPDATE_INTERVAL] = g_param_spec_uint ("update-interval", + "update interval prop", + "update interval data", + LOCATION_UPDATE_INTERVAL_MIN, + LOCATION_UPDATE_INTERVAL_MAX, + LOCATION_UPDATE_INTERVAL_DEFAULT, + G_PARAM_READWRITE); + + properties[PROP_BOUNDARY] = g_param_spec_pointer ("boundary", + "hybrid boundary prop", + "hybrid boundary data", + G_PARAM_READWRITE); + + properties[PROP_REMOVAL_BOUNDARY] = g_param_spec_boxed("removal-boundary", + "hybrid removal boundary prop", + "hybrid removal boundary data", + LOCATION_TYPE_BOUNDARY, + G_PARAM_READWRITE); + + g_object_class_install_properties (gobject_class, + PROP_MAX, + properties); + +} diff --git a/location/manager/location-hybrid.h b/location/manager/location-hybrid.h new file mode 100644 index 0000000..a044992 --- /dev/null +++ b/location/manager/location-hybrid.h @@ -0,0 +1,64 @@ +/* + * libslp-location + * + * 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_HYBRID_H__ +#define __LOCATION_HYBRID_H__ + +#include + +/** + * @file location-hybrid.h + * @brief This file contains the internal definitions and structures related to Hybrid method. + */ + +G_BEGIN_DECLS + +typedef struct _LocationHybrid LocationHybrid; +typedef struct _LocationHybridClass LocationHybridClass; + +#define LOCATION_TYPE_HYBRID (location_hybrid_get_type ()) +#define LOCATION_HYBRID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_HYBRID, LocationHybrid)) +#define LOCATION_IS_HYBRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_HYBRID)) +#define LOCATION_HYBRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_HYBRID, LocationHybridClass)) +#define LOCATION_IS_HYBRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_HYBRID)) +#define LOCATION_HYBRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_HYBRID, LocationHybridClass)) + +struct _LocationHybrid +{ + GObject parent_instance; +}; + +struct _LocationHybridClass +{ + GObjectClass parent_class; + + void (* enabled) (guint type); + void (* disabled) (guint type); + void (* updated) (guint type, gpointer data, gpointer accuracy); + void (* zone_in) (guint type, gpointer position, gpointer boundary); + void (* zone_out) (guint type, gpointer position, gpointer boundary); +}; + +GType location_hybrid_get_type (void); + +G_END_DECLS + +#endif diff --git a/location/manager/location-ielement.c b/location/manager/location-ielement.c new file mode 100644 index 0000000..ffa63cb --- /dev/null +++ b/location/manager/location-ielement.c @@ -0,0 +1,346 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-log.h" +#include "location-ielement.h" + +static void +location_ielement_base_init (gpointer g_class) +{ + static gboolean is_initialized = FALSE; + + if (is_initialized){ + /* add properties and signals to the interface here */ + + is_initialized = TRUE; + } +} + +GType +location_ielement_get_type (void) +{ + static GType iface_type = 0; + + if (iface_type == 0) { + static const GTypeInfo info = { + sizeof (LocationIElementInterface), + location_ielement_base_init, /* base_init */ + NULL /* base_finalize */ + }; + + iface_type = g_type_register_static (G_TYPE_INTERFACE, "LocationIElement", + &info, 0); + } + + return iface_type; +} + +int +location_ielement_start (LocationIElement *self) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->start, LOCATION_ERROR_NOT_AVAILABLE); + return LOCATION_IELEMENT_GET_INTERFACE (self)->start (self); +} + +int +location_ielement_stop (LocationIElement *self) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->stop, LOCATION_ERROR_NOT_AVAILABLE); + return LOCATION_IELEMENT_GET_INTERFACE (self)->stop (self); +} + +int +location_ielement_get_position (LocationIElement *self, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_position, LOCATION_ERROR_NOT_AVAILABLE); + + return LOCATION_IELEMENT_GET_INTERFACE (self)->get_position (self, position, accuracy); +} + +int +location_ielement_get_last_position (LocationIElement *self, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_last_position, LOCATION_ERROR_NOT_AVAILABLE); + + return LOCATION_IELEMENT_GET_INTERFACE (self)->get_last_position (self, position, accuracy); +} + +int +location_ielement_get_satellite (LocationIElement *self, + LocationSatellite **satellite) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (satellite, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_satellite, LOCATION_ERROR_NOT_AVAILABLE); + + return LOCATION_IELEMENT_GET_INTERFACE (self)->get_satellite (self, satellite); +} + +int +location_ielement_get_last_satellite (LocationIElement *self, + LocationSatellite **satellite) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (satellite, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_last_satellite, LOCATION_ERROR_NOT_AVAILABLE); + + return LOCATION_IELEMENT_GET_INTERFACE (self)->get_last_satellite (self, satellite); +} + + +int +location_ielement_get_velocity (LocationIElement *self, + LocationVelocity **velocity, + LocationAccuracy **accuracy) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_velocity, LOCATION_ERROR_NOT_AVAILABLE); + return LOCATION_IELEMENT_GET_INTERFACE (self)->get_velocity (self, velocity, accuracy); +} + +int +location_ielement_get_last_velocity (LocationIElement *self, + LocationVelocity **velocity, + LocationAccuracy **accuracy) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_last_velocity, LOCATION_ERROR_NOT_AVAILABLE); + return LOCATION_IELEMENT_GET_INTERFACE (self)->get_last_velocity (self, velocity, accuracy); +} + +int +location_ielement_get_geocode (LocationIElement *self, + const LocationAddress *address, + GList **position_list, + GList **accuracy_list) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (address, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode, LOCATION_ERROR_NOT_AVAILABLE); + return LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode (self, address, position_list, accuracy_list); +} + +int +location_ielement_get_geocode_freeform (LocationIElement *self, + const gchar *address, + GList **position_list, + GList **accuracy_list) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (address, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode_freeform, LOCATION_ERROR_NOT_AVAILABLE); + return LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode_freeform (self, address, position_list, accuracy_list); +} + +int +location_ielement_get_reversegeocode (LocationIElement *self, + const LocationPosition *position, + LocationAddress **address, + LocationAccuracy **accuracy) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (address, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_reversegeocode, LOCATION_ERROR_NOT_AVAILABLE); + return LOCATION_IELEMENT_GET_INTERFACE (self)->get_reversegeocode (self, position, address, accuracy); +} + +int +location_ielement_get_geocode_async (LocationIElement *self, + const LocationAddress *address, + LocationPositionCB callback, + gpointer userdata) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (address, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (callback, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode_async, LOCATION_ERROR_NOT_AVAILABLE); + return LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode_async (self, address, callback, userdata); +} + +int +location_ielement_get_geocode_freeform_async (LocationIElement *self, + const gchar *address, + LocationPositionCB callback, + gpointer userdata) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (address, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (callback, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode_freeform_async, LOCATION_ERROR_NOT_AVAILABLE); + return LOCATION_IELEMENT_GET_INTERFACE (self)->get_geocode_freeform_async (self, address, callback, userdata); +} + +int +location_ielement_get_reversegeocode_async (LocationIElement *self, + const LocationPosition *position, + LocationAddressCB callback, + gpointer userdata) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (callback, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_reversegeocode_async, LOCATION_ERROR_NOT_AVAILABLE); + return LOCATION_IELEMENT_GET_INTERFACE (self)->get_reversegeocode_async (self, position, callback, userdata); +} + +int +location_ielement_search_poi (LocationIElement *self, + const LocationPOIFilter * filter, const LocationPosition *position, + const LocationPreference *svc_pref, const LocationPOIPreference * pref, + LocationPOICB cb, const gpointer user_data, guint * req_id) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + 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); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->search_poi, LOCATION_ERROR_NOT_AVAILABLE); + + return LOCATION_IELEMENT_GET_INTERFACE (self)->search_poi(self, + filter, position, svc_pref, pref, cb, user_data, req_id); +} + +int +location_ielement_search_poi_by_area (LocationIElement *self, + const LocationPOIFilter * filter, const LocationBoundary * boundary, + const LocationPreference *svc_pref, const LocationPOIPreference * pref, + LocationPOICB cb, const gpointer user_data, guint * req_id) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + 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 (LOCATION_IELEMENT_GET_INTERFACE (self)->search_poi_by_area, LOCATION_ERROR_NOT_AVAILABLE); + + return LOCATION_IELEMENT_GET_INTERFACE (self)->search_poi_by_area (self, + filter, boundary, svc_pref, pref, cb, user_data, req_id); +} + +int +location_ielement_search_poi_by_address (LocationIElement *self, + const LocationPOIFilter * filter, const LocationAddress * address, + const LocationPreference *svc_pref, const LocationPOIPreference * pref, + LocationPOICB cb, const gpointer user_data, guint * req_id) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (filter, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (address, 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 (LOCATION_IELEMENT_GET_INTERFACE (self)->search_poi_by_address, LOCATION_ERROR_NOT_AVAILABLE); + + return LOCATION_IELEMENT_GET_INTERFACE (self)->search_poi_by_address (self, + filter, address, svc_pref, pref, cb, user_data, req_id); +} + +int +location_ielement_search_poi_by_freeform (LocationIElement *self, const LocationPOIFilter * filter, + const gchar *freeform, const LocationPreference *svc_pref, const LocationPOIPreference *pref, LocationPOICB cb, + const gpointer user_data, guint * req_id) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (filter, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (freeform, 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 (LOCATION_IELEMENT_GET_INTERFACE (self)->search_poi_by_freeform, LOCATION_ERROR_NOT_AVAILABLE); + + return LOCATION_IELEMENT_GET_INTERFACE (self)->search_poi_by_freeform (self, + filter, freeform, svc_pref, pref, cb, user_data, req_id); +} + +int +location_ielement_cancel_poi_request (LocationIElement *self, guint req_id) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->cancel_poi_request, LOCATION_ERROR_NOT_AVAILABLE); + + return LOCATION_IELEMENT_GET_INTERFACE (self)->cancel_poi_request (self, req_id); +} + +int +location_ielement_request_route (LocationIElement *self, const LocationPosition *origin, + const LocationPosition *destination, GList *waypoint, + const LocationPreference *svc_pref, const LocationRoutePreference *pref, LocationRouteCB cb, const gpointer user_data, guint *req_id) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (origin, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (destination, 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 (LOCATION_IELEMENT_GET_INTERFACE (self)->request_route, LOCATION_ERROR_NOT_AVAILABLE); + + return LOCATION_IELEMENT_GET_INTERFACE (self)->request_route (self, + origin, destination, waypoint, svc_pref, pref, cb, user_data, req_id); +} + +int +location_ielement_cancel_route_request (LocationIElement *self, guint req_id) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->cancel_route_request, LOCATION_ERROR_NOT_AVAILABLE); + + return LOCATION_IELEMENT_GET_INTERFACE (self)->cancel_route_request (self, req_id); +} + +gboolean +location_ielement_is_supported_map_provider_capability (LocationIElement *self, LocationMapServiceType type) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->is_supported_map_provider_capability, LOCATION_ERROR_NOT_AVAILABLE); + + return LOCATION_IELEMENT_GET_INTERFACE (self)->is_supported_map_provider_capability (self, type); +} + +int +location_ielement_get_map_provider_capability_key (LocationIElement *self, LocationMapServiceType type, GList **key) +{ + g_return_val_if_fail (LOCATION_IS_IELEMENT (self), LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (LOCATION_IELEMENT_GET_INTERFACE (self)->get_map_provider_capability_key, LOCATION_ERROR_NOT_AVAILABLE); + + return LOCATION_IELEMENT_GET_INTERFACE (self)->get_map_provider_capability_key (self, type, key); +} diff --git a/location/manager/location-ielement.h b/location/manager/location-ielement.h new file mode 100644 index 0000000..325ff6d --- /dev/null +++ b/location/manager/location-ielement.h @@ -0,0 +1,138 @@ +/* + * libslp-location + * + * 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_IELEMENT_H__ +#define __LOCATION_IELEMENT_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * @file location-ielement.h + * @brief This file contains the internal definitions and structures related to location interface. + */ + +G_BEGIN_DECLS + +enum { + SERVICE_ENABLED, + SERVICE_DISABLED, + SERVICE_UPDATED, + ZONE_IN, + ZONE_OUT, + LAST_SIGNAL +}; + +#define LOCATION_TYPE_IELEMENT (location_ielement_get_type ()) +#define LOCATION_IELEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_IELEMENT, LocationIElement)) +#define LOCATION_IS_IELEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_IELEMENT)) +#define LOCATION_IELEMENT_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), LOCATION_TYPE_IELEMENT, LocationIElementInterface)) + +typedef struct _LocationIElement LocationIElement; +typedef struct _LocationIElementInterface LocationIElementInterface; + +typedef int (*TYPE_START_FUNC)(LocationIElement *self); +typedef int (*TYPE_STOP_FUNC) (LocationIElement *self); +typedef int (*TYPE_GET_POSITION)(LocationIElement *self, LocationPosition **position, LocationAccuracy **accuracy); +typedef int (*TYPE_GET_VELOCITY)(LocationIElement *self, LocationVelocity **velocity, LocationAccuracy **accuracy); +typedef int (*TYPE_GET_SATELLITE)(LocationIElement *self, LocationSatellite **satellite); +typedef int (*TYPE_GET_GEOCODE)(LocationIElement *self, const LocationAddress *address, GList **position_list, GList **accuracy_list); +typedef int (*TYPE_GET_GEOCODE_FREEFORM)(LocationIElement *self, const gchar *address, GList **position_list, GList **accuracy_list); +typedef int (*TYPE_GET_REVERSEGEOCODE)(LocationIElement *self, const LocationPosition *position, LocationAddress **address, LocationAccuracy **accuracy); +typedef int (*TYPE_GET_GEOCODE_ASYNC)(LocationIElement *self, const LocationAddress *address, LocationPositionCB callback, gpointer userdata); +typedef int (*TYPE_GET_GEOCODE_FREEFORM_ASYNC)(LocationIElement *self, const gchar *address, LocationPositionCB callback, gpointer userdata); +typedef int (*TYPE_GET_REVERSEGEOCODE_ASYNC)(LocationIElement *self, const LocationPosition *position, LocationAddressCB callback, gpointer userdata); +typedef int (*TYPE_SEARCH_POI) (LocationIElement *self, const LocationPOIFilter * filter, const LocationPosition *position, const LocationPreference *svc_pref, const LocationPOIPreference * pref, LocationPOICB cb, const gpointer user_data, guint *req_id); +typedef int (*TYPE_SEARCH_POI_BY_AREA) (LocationIElement *self, const LocationPOIFilter *filter, const LocationBoundary * boundary, const LocationPreference *svc_pref, const LocationPOIPreference * pref, LocationPOICB cb, const gpointer user_data, guint *req_id); +typedef int (*TYPE_SEARCH_POI_BY_ADDR) (LocationIElement *self, const LocationPOIFilter *filter, const LocationAddress * address, const LocationPreference *svc_pref, const LocationPOIPreference * pref, LocationPOICB cb, const gpointer user_data, guint *req_id); +typedef int (*TYPE_SEARCH_POI_BY_FREEFORM) (LocationIElement *self, const LocationPOIFilter *filter, const gchar *freeform, const LocationPreference *svc_pref, const LocationPOIPreference * pref, LocationPOICB cb, const gpointer user_data, guint *req_id); +typedef int (*TYPE_CANCEL_POI_REQUEST) (LocationIElement *self, guint req_id); +typedef int (*TYPE_REQUEST_ROUTE) (LocationIElement *self, const LocationPosition *origin, const LocationPosition *destination, GList *waypoint, const LocationPreference *svc_pref, const LocationRoutePreference *pref, LocationRouteCB cb, const gpointer user_data, guint *req_id); +typedef int (*TYPE_CANCEL_ROUTE_REQUEST) (LocationIElement *self, guint req_id); +typedef gboolean (*TYPE_IS_SUPPORTED_MAP_PROVIDER_CAPABILITY) (LocationIElement *self, LocationMapServiceType type); +typedef int (*TYPE_GET_MAP_PROVIDER_CAPABILITY_KEY)(LocationIElement *self, LocationMapServiceType type, GList **key); + +struct _LocationIElementInterface +{ + GTypeInterface parent_iface; + + TYPE_START_FUNC start; + TYPE_STOP_FUNC stop; + TYPE_GET_POSITION get_position; + TYPE_GET_POSITION get_last_position; + TYPE_GET_VELOCITY get_velocity; + TYPE_GET_VELOCITY get_last_velocity; + TYPE_GET_SATELLITE get_satellite; + TYPE_GET_SATELLITE get_last_satellite; + TYPE_GET_GEOCODE get_geocode; + TYPE_GET_GEOCODE_FREEFORM get_geocode_freeform; + TYPE_GET_REVERSEGEOCODE get_reversegeocode; + TYPE_GET_GEOCODE_ASYNC get_geocode_async; + TYPE_GET_GEOCODE_FREEFORM_ASYNC get_geocode_freeform_async; + TYPE_GET_REVERSEGEOCODE_ASYNC get_reversegeocode_async; + TYPE_SEARCH_POI search_poi; + TYPE_SEARCH_POI_BY_AREA search_poi_by_area; + TYPE_SEARCH_POI_BY_ADDR search_poi_by_address; + TYPE_SEARCH_POI_BY_FREEFORM search_poi_by_freeform; + TYPE_CANCEL_POI_REQUEST cancel_poi_request; + TYPE_REQUEST_ROUTE request_route; + TYPE_CANCEL_ROUTE_REQUEST cancel_route_request; + TYPE_IS_SUPPORTED_MAP_PROVIDER_CAPABILITY is_supported_map_provider_capability; + TYPE_GET_MAP_PROVIDER_CAPABILITY_KEY get_map_provider_capability_key; + +}; + +GType location_ielement_get_type (void); + +int location_ielement_start (LocationIElement *self); +int location_ielement_stop(LocationIElement *self); +int location_ielement_get_position (LocationIElement *self, LocationPosition **position, LocationAccuracy **accuracy); +int location_ielement_get_last_position (LocationIElement *self, LocationPosition **position, LocationAccuracy **accuracy); +int location_ielement_get_velocity (LocationIElement *self, LocationVelocity **velocity, LocationAccuracy **accuracy); +int location_ielement_get_last_velocity (LocationIElement *self, LocationVelocity **velocity, LocationAccuracy **accuracy); +int location_ielement_get_satellite (LocationIElement *self, LocationSatellite **satellite); +int location_ielement_get_last_satellite (LocationIElement *self, LocationSatellite **satellite); +int location_ielement_get_geocode (LocationIElement *self, const LocationAddress *address, GList **position_list, GList **accuracy_list); +int location_ielement_get_geocode_freeform (LocationIElement *self, const gchar *address, GList **position_list, GList **accuracy_list); +int location_ielement_get_reversegeocode (LocationIElement *self, const LocationPosition *position, LocationAddress **address, LocationAccuracy **accuracy); +int location_ielement_get_geocode_async (LocationIElement *self, const LocationAddress *address, LocationPositionCB callback, gpointer userdata); +int location_ielement_get_geocode_freeform_async (LocationIElement *self, const gchar *address, LocationPositionCB callback, gpointer userdata); +int location_ielement_get_reversegeocode_async (LocationIElement *self, const LocationPosition *position, LocationAddressCB callback, gpointer userdata); +int location_ielement_search_poi (LocationIElement *self, const LocationPOIFilter * filter, const LocationPosition *position, const LocationPreference *svc_pref, const LocationPOIPreference * pref, LocationPOICB cb, const gpointer user_data, guint * req_id); +int location_ielement_search_poi_by_area (LocationIElement *self, const LocationPOIFilter * filter, const LocationBoundary * boundary, const LocationPreference *svc_pref, const LocationPOIPreference * pref, LocationPOICB cb, const gpointer user_data, guint * req_id); +int location_ielement_search_poi_by_address (LocationIElement *self, const LocationPOIFilter * filter, const LocationAddress * address, const LocationPreference *svc_pref, const LocationPOIPreference * pref, LocationPOICB cb, const gpointer user_data, guint * req_id); +int location_ielement_search_poi_by_freeform (LocationIElement *self, const LocationPOIFilter * filter, const gchar * freeform, const LocationPreference *svc_pref, const LocationPOIPreference * pref, LocationPOICB cb, const gpointer user_data, guint * req_id); +int location_ielement_cancel_poi_request (LocationIElement *self, guint req_id); +int location_ielement_request_route (LocationIElement *self, const LocationPosition *origin, const LocationPosition *destination, GList *waypoint, const LocationPreference *svc_pref, const LocationRoutePreference * pref, LocationRouteCB cb, const gpointer user_data, guint * req_id); +int location_ielement_cancel_route_request (LocationIElement *self, guint req_id); +gboolean location_ielement_is_supported_map_provider_capability (LocationIElement *self, LocationMapServiceType type); +int location_ielement_get_map_provider_capability_key (LocationIElement *self, LocationMapServiceType type, GList **key); + +G_END_DECLS + +#endif diff --git a/location/manager/location-ips.c b/location/manager/location-ips.c new file mode 100644 index 0000000..b596404 --- /dev/null +++ b/location/manager/location-ips.c @@ -0,0 +1,171 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-setting.h" +#include "location-log.h" + +#include "module-internal.h" + +#include "location-ips.h" +#include "location-marshal.h" +#include "location-ielement.h" + +typedef struct _LocationIpsPrivate { + LocationIpsMod *mod; + LocationPosition *pos; + LocationAccuracy *acc; +} LocationIpsPrivate; + +enum { + PROP_0, + PROP_METHOD_TYPE, + PROP_LAST_POSITION +}; + +#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_IPS, LocationIpsPrivate)) + +static void location_ielement_interface_init (LocationIElementInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (LocationIps, location_ips, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, + location_ielement_interface_init)); + +static void +location_ips_dispose (GObject *gobject) +{ + LOCATION_LOGD("location_ips_dispose"); + G_OBJECT_CLASS (location_ips_parent_class)->dispose (gobject); +} + +static void +location_ips_finalize (GObject *gobject) +{ + LOCATION_LOGD("location_ips_finalize"); + LocationIpsPrivate* priv = GET_PRIVATE(gobject); + module_free(priv->mod, "ips"); + priv->mod = NULL; + + G_OBJECT_CLASS (location_ips_parent_class)->finalize (gobject); +} + +static void +location_ips_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + LocationIpsPrivate *priv = GET_PRIVATE (object); + + switch (property_id){ + case PROP_METHOD_TYPE: + g_value_set_int(value, LOCATION_METHOD_IPS); + break; + case PROP_LAST_POSITION:{ + g_value_set_boxed (value, priv->pos); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static int +location_ips_get_position (LocationIps *self, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_ips_get_position"); + + LocationIpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + setting_retval_if_fail(GPS_ENABLED); + setting_retval_if_fail(NETWORK_ENABLED); + + LocModIpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_position, LOCATION_ERROR_NOT_AVAILABLE); + int ret = ops.get_position(priv->mod->handler, position, accuracy); + if (priv->pos) location_position_free(priv->pos); + if (priv->acc) location_accuracy_free(priv->acc); + priv->pos = location_position_copy(*position); + priv->acc = location_accuracy_copy(*accuracy); + return ret; +} + +static void +location_ielement_interface_init (LocationIElementInterface *iface) +{ + iface->get_position = (TYPE_GET_POSITION)location_ips_get_position; +} + +static void +location_ips_init (LocationIps *self) +{ + LOCATION_LOGD("location_ips_init"); + LocationIpsPrivate* priv = GET_PRIVATE(self); + + priv->mod = (LocationIpsMod*)module_new("ips"); + if(!priv->mod) LOCATION_LOGW("module loading failed"); + + priv->pos = NULL; + priv->acc = NULL; +} + +static void +location_ips_class_init (LocationIpsClass *klass) +{ + LOCATION_LOGD("location_ips_class_init"); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GParamSpec *pspec; + + gobject_class->get_property = location_ips_get_property; + + gobject_class->dispose = location_ips_dispose; + gobject_class->finalize = location_ips_finalize; + + g_type_class_add_private (klass, sizeof (LocationIpsPrivate)); + + pspec = g_param_spec_int ("method", + "method type", + "location method type name", + LOCATION_METHOD_IPS, + LOCATION_METHOD_IPS, + LOCATION_METHOD_IPS, + G_PARAM_READABLE); + g_object_class_install_property (gobject_class, + PROP_METHOD_TYPE, + pspec); + + pspec = g_param_spec_boxed ("last-position", + "ips last position prop", + "ips last position data", + LOCATION_TYPE_POSITION, + G_PARAM_READABLE); + g_object_class_install_property (gobject_class, + PROP_LAST_POSITION, + pspec); +} + diff --git a/location/manager/location-ips.h b/location/manager/location-ips.h new file mode 100644 index 0000000..b8f1cc6 --- /dev/null +++ b/location/manager/location-ips.h @@ -0,0 +1,58 @@ +/* + * libslp-location + * + * 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_IPS_H__ +#define __LOCATION_IPS_H__ + +#include + +/** + * @file location-ips.h + * @brief This file contains the internal definitions and structures related to IPS. + */ + +G_BEGIN_DECLS + +#define LOCATION_TYPE_IPS (location_ips_get_type ()) +#define LOCATION_IPS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_IPS, LocationIps)) +#define LOCATION_IS_IPS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_IPS)) +#define LOCATION_IPS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_IPS, LocationIpsClass)) +#define LOCATION_IS_IPS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_IPS)) +#define LOCATION_IPS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_IPS, LocationIpsClass)) + +typedef struct _LocationIps LocationIps; +typedef struct _LocationIpsClass LocationIpsClass; + +struct _LocationIps +{ + GObject parent_instance; +}; + +struct _LocationIpsClass +{ + GObjectClass parent_class; +}; + +GType location_ips_get_type (void); + +G_END_DECLS + +#endif diff --git a/location/manager/location-marshal.list b/location/manager/location-marshal.list new file mode 100644 index 0000000..069387a --- /dev/null +++ b/location/manager/location-marshal.list @@ -0,0 +1,2 @@ +VOID:UINT,POINTER,POINTER +VOID:UINT diff --git a/location/manager/location-position.c b/location/manager/location-position.c new file mode 100644 index 0000000..bac60f9 --- /dev/null +++ b/location/manager/location-position.c @@ -0,0 +1,203 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "location-position.h" +#include "location-setting.h" +#include "location-log.h" + +#define DEG2RAD(x) ((x) * M_PI / 180) + +GType +location_position_get_type (void) +{ + static volatile gsize type_volatile = 0; + if(g_once_init_enter(&type_volatile)) { + GType type = g_boxed_type_register_static ( + g_intern_static_string ("LocationPosition"), + (GBoxedCopyFunc) location_position_copy, + (GBoxedFreeFunc) location_position_free); + g_once_init_leave(&type_volatile, type); + } + return type_volatile; +} + +EXPORT_API LocationPosition * +location_position_new (guint timestamp, + gdouble latitude, + gdouble longitude, + gdouble altitude, + LocationStatus status) +{ + if (latitude < -90 || latitude > 90) return NULL; + if (longitude < -180 || longitude > 180) return NULL; + + LocationPosition* position = g_slice_new0(LocationPosition); + position->timestamp = timestamp; + position->latitude = latitude; + position->longitude = longitude; + position->altitude = altitude; + position->status = status; + return position; +} + +EXPORT_API void +location_position_free (LocationPosition* position) +{ + g_return_if_fail(position); + g_slice_free(LocationPosition, position); +} + +EXPORT_API gboolean +location_position_equal (const LocationPosition *position1, const LocationPosition *position2) +{ + g_return_val_if_fail(position1, FALSE); + g_return_val_if_fail(position2, FALSE); + + if (position1->latitude == position2->latitude && + position1->longitude == position2->longitude && + position1->altitude == position2->altitude) + return TRUE; + return FALSE; +} + +EXPORT_API LocationPosition* +location_position_copy (const LocationPosition *position) +{ + g_return_val_if_fail(position, NULL); + + LocationPosition *new_position = NULL; + + new_position = location_position_new (position->timestamp, + position->latitude, + position->longitude, + position->altitude, + position->status); + + if(new_position) new_position->updated_timestamp = position->updated_timestamp; + + return new_position; + +} + +/* Vincenty formula. WGS-84 */ +EXPORT_API int +location_get_distance(const LocationPosition *pos1, const LocationPosition *pos2, gulong *distance) +{ + g_return_val_if_fail(pos1, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(pos2, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(distance, LOCATION_ERROR_PARAMETER); + + *distance = 0; + + const double a = 6378137.0, b = 6356752.314245, f = 1/298.257223563; + double delta_lon = DEG2RAD(pos2->longitude-pos1->longitude); + double u_1 = atan((1-f) * tan(DEG2RAD(pos1->latitude))); + double u_2 = atan((1-f) * tan(DEG2RAD(pos2->latitude))); + + double lambdaP, iter_limit = 100.0; + double lambda = delta_lon; + + double sin_sigma, sin_alpha, cos_sigma, sigma, sq_cos_alpha, cos_2sigma, C; + double sq_u, cal1, cal2, delta_sigma, cal_dist; + double sin_lambda, cos_lambda; + + double sin_u1 = sin(u_1); + double cos_u1 = cos(u_1); + double sin_u2 = sin(u_2); + double cos_u2 = cos(u_2); + + do { + sin_lambda = sin(lambda); + cos_lambda = cos(lambda); + + sin_sigma = sqrt((cos_u2*sin_lambda)*(cos_u2*sin_lambda) + \ + (cos_u1*sin_u2-sin_u1*cos_u2*cos_lambda) * \ + (cos_u1*sin_u2-sin_u1*cos_u2*cos_lambda)); + + if (sin_sigma ==0) + return LOCATION_ERROR_NONE; // co-incident points + + cos_sigma = sin_u1*sin_u2 + cos_u1*cos_u2*cos_lambda; + sigma = atan2(sin_sigma, cos_sigma); + + sin_alpha = cos_u1 * cos_u2 * sin_lambda / sin_sigma; + sq_cos_alpha = 1.0 - sin_alpha*sin_alpha; + cos_2sigma = cos_sigma - 2.0*sin_u1*sin_u2/sq_cos_alpha; + + if (isnan(cos_2sigma)) + cos_2sigma = 0; + + C = f/16.0*sq_cos_alpha*(4.0+f*(4.0-3.0*sq_cos_alpha)); + + lambdaP = lambda; + lambda = delta_lon + (1.0-C) * f * sin_alpha * \ + (sigma + C*sin_sigma*(cos_2sigma+C*cos_sigma*(-1.0+2.0*cos_2sigma*cos_2sigma))); + + } while (abs(lambda-lambdaP) > 1e-12 && --iter_limit>0); + + if (iter_limit==0) return LOCATION_ERROR_UNKNOWN; + + sq_u = sq_cos_alpha * (a*a - b*b) / (b*b); + + cal1 = 1.0 + sq_u/16384.0*(4096.0+sq_u*(-768.0+sq_u*(320.0-175.0*sq_u))); + cal2 = sq_u/1024.0 * (256.0+sq_u*(-128.0+sq_u*(74.0-47.0*sq_u))); + + delta_sigma = cal2*sin_sigma*(cos_2sigma+cal2/4.0*(cos_sigma*(-1.0+2.0*cos_2sigma*cos_2sigma)- \ + cal2/6.0*cos_2sigma*(-3.0+4.0*sin_sigma*sin_sigma)*(-3.0+4.0*cos_2sigma*cos_2sigma))); + cal_dist = b*cal1*(sigma-delta_sigma); + + *distance = (gulong) cal_dist; + + return LOCATION_ERROR_NONE; + +} + +EXPORT_API void +location_last_position_a2i(char *position, int *lat, int *lon) +{ + char *d_lat, *d_lon; + char latitude[HALF_KEY_LENGTH]; + char longitude[HALF_KEY_LENGTH]; + + memcpy(latitude, position + 1, HALF_KEY_LENGTH - 1); + memcpy(longitude, position + HALF_KEY_LENGTH + 1, HALF_KEY_LENGTH - 1); + latitude[HALF_KEY_LENGTH - 1] = '\0'; + longitude[HALF_KEY_LENGTH - 1] = '\0'; + d_lat = position; + d_lon = position + HALF_KEY_LENGTH; + + *lat = atoi(latitude); + *lon = atoi(longitude); + + if (*d_lat == 'S') { + *lat = *lat * -1; + } + if (*d_lon == 'W') { + *lon = *lon * -1; + } +} diff --git a/location/manager/location-position.h b/location/manager/location-position.h new file mode 100644 index 0000000..1a2b08c --- /dev/null +++ b/location/manager/location-position.h @@ -0,0 +1,177 @@ +/* + * libslp-location + * + * 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_POSITION_H_ +#define __LOCATION_POSITION_H_ + +#include + +#define MAX_KEY_LENGTH 16 +#define HALF_KEY_LENGTH 8 + +G_BEGIN_DECLS + +GType location_position_get_type (void); +#define LOCATION_TYPE_POSITION (location_position_get_type ()) + +/** + * @file location-position.h + * @brief This file contains the internal definitions and structures related to position information. + */ +/** + * @addtogroup LocationAPI + * @{ + * @defgroup LocationAPIPosition Location Position + * @breif This provides APIs related to Location Position + * @addtogroup LocationAPIPosition + * @{ + * + */ + +/** + * @brief This represents the various fix states. + */ +typedef enum +{ + LOCATION_STATUS_NO_FIX = 0, ///< No fix status. + LOCATION_STATUS_2D_FIX, ///< 2D fix status (latitude/longitude/speed/direction). + LOCATION_STATUS_3D_FIX ///< 3D fix status (altitude/climb as well). +} LocationStatus; + +/** + * @brief This represents position information such as latitude-longitude-altitude values and timestamp. + */ +struct _LocationPosition +{ + guint timestamp; ///< Time stamp. + guint updated_timestamp; ///< latest updated time stamp. + gdouble latitude; ///< Latitude data. + gdouble longitude; ///< Longitude data. + gdouble altitude; ///< Altitude data. + LocationStatus status; ///< Fix states. +}; + +/** + * @brief This represents last known position information such as latitude-longitude values and accuracy. + */ +struct _LocationLastPosition +{ + LocationMethod method; ///< Location Method. + guint timestamp; ///< Time stamp. + gdouble latitude; ///< Latitude data. + gdouble longitude; ///< Longitude data. + gdouble altitude; ///< Altitude data. + gdouble horizontal_accuracy; ///< Horizontal accuracy data. + gdouble vertical_accuracy; ///< Vertical accuracy data. +}; + +/** + * @brief Create a new #LocationPosition with given information. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] timestamp - Time stamp. + * @param [in] latitude - Latitude data. + * @param [in] longitude - Longitude data. + * @param [in] altitude - Altitude data. + * @param [in] status - a #LocationStatus. + * @return a new #LocationPosition + * @retval NULL if error occured + */ +LocationPosition *location_position_new (guint timestamp, gdouble latitude, gdouble longitude, gdouble altitude, LocationStatus status); + +/** + * @brief Free a #LocationPosition. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] position - a #LocationPosition. + * @return None. + */ +void location_position_free (LocationPosition *position); + +/** + * @brief Compares two positions for equality, returning TRUE if they are equal. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] position1 - a #LocationPosition + * @param [in] position2 - a #LocationPosition + * @return gboolean + * @retval\n + * TRUE - if equal\n + * FALSE - if not equal\n + */ +gboolean location_position_equal (const LocationPosition *position1, const LocationPosition *position2); + +/** + * @brief Makes a copy of #LocationPosition + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] position - a #LocationPosition + * @return a new #LocationPosition + * @retval NULL if error occured + */ +LocationPosition *location_position_copy (const LocationPosition *position); + +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ +/* Vincenty Inverse Solution of Geodesics on the Ellipsoid (c) Chris Veness 2002-2010 */ +/* */ +/* from: Vincenty inverse formula - T Vincenty, "Direct and Inverse Solutions of Geodesics on the */ +/* Ellipsoid with application of nested equations", Survey Review, vol XXII no 176, 1975 */ +/* http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf */ +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ + +/** + * @brief Gets the approximate distance between two points. A distance is defined using the WGS84 ellipsoid. + * @remarks Uses meters as a unit of measurement for a distance. + * @pre None. + * @post None. + * @param [in] pos1 - a #LocationPosition (decimal degree) + * @param [in] pos2 - a #LocationPosition (decimal degree) + * @param [out] distance - a #gulong (meters) + * @return int + * @retval 0 Success. + * + * Please refer #LocationError for more information. + */ +int location_get_distance(const LocationPosition *pos1, const LocationPosition *pos2, gulong *distance); + +/** + * @brief Change position string to latitude and longitude integer. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] position - string of last position. + * @param [in] lat - latitude. + * @param [in] lon - longitude. + * @return None. + */ +void location_last_position_a2i(char *position, int *lat, int *lon); + +/** + * @} @} + */ + +G_END_DECLS + +#endif diff --git a/location/manager/location-satellite.c b/location/manager/location-satellite.c new file mode 100644 index 0000000..f572c44 --- /dev/null +++ b/location/manager/location-satellite.c @@ -0,0 +1,139 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-satellite.h" +#include "location-log.h" + +GType +location_satellite_get_type (void) +{ + static volatile gsize type_volatile = 0; + if(g_once_init_enter(&type_volatile)) { + GType type = g_boxed_type_register_static ( + g_intern_static_string ("LocationSatellite"), + (GBoxedCopyFunc) location_satellite_copy, + (GBoxedFreeFunc) location_satellite_free); + g_once_init_leave(&type_volatile, type); + } + return type_volatile; +} + +static void +update_num_of_used (LocationSatellite *satellite) +{ + g_return_if_fail(satellite); + satellite->num_of_sat_used = 0; + if (satellite->num_of_sat_inview > 0 && satellite->sat_inview) { + int i = 0; + for (i = 0 ; i < satellite->num_of_sat_inview ; i++) + if(satellite->sat_inview[i].used) (satellite->num_of_sat_used)++; + } +} + +EXPORT_API LocationSatellite* +location_satellite_new (int num_of_sat_inview) +{ + LocationSatellite* satellite = g_slice_new0(LocationSatellite); + satellite->num_of_sat_inview = num_of_sat_inview; + satellite->num_of_sat_used = 0; + satellite->sat_inview = g_new0(LocationSatelliteDetail, satellite->num_of_sat_inview); + return satellite; +} + +EXPORT_API void +location_satellite_free (LocationSatellite* satellite) +{ + g_return_if_fail(satellite); + g_free(satellite->sat_inview); + g_slice_free(LocationSatellite, satellite); +} + +EXPORT_API LocationSatellite* +location_satellite_copy (const LocationSatellite *satellite) +{ + g_return_val_if_fail(satellite, NULL); + LocationSatellite* satellite_dup = location_satellite_new(satellite->num_of_sat_inview); + satellite_dup->timestamp = satellite->timestamp; + satellite_dup->num_of_sat_used = satellite->num_of_sat_used; + int i = 0; + for (i = 0 ; i < satellite_dup->num_of_sat_inview ; i++) + location_satellite_set_satellite_details(satellite_dup, i, + satellite->sat_inview[i].prn, + satellite->sat_inview[i].used, + satellite->sat_inview[i].elevation, + satellite->sat_inview[i].azimuth, + satellite->sat_inview[i].snr); + return satellite_dup; +} + +EXPORT_API gboolean +location_satellite_get_satellite_details (const LocationSatellite *satellite, + guint index, + guint* prn, + gboolean* used, + guint* elevation, + guint* azimuth, + gint* snr) +{ + g_return_val_if_fail(satellite, FALSE); + g_return_val_if_fail(prn, FALSE); + g_return_val_if_fail(used, FALSE); + g_return_val_if_fail(elevation, FALSE); + g_return_val_if_fail(azimuth, FALSE); + g_return_val_if_fail(snr, FALSE); + g_return_val_if_fail(satellite->sat_inview, FALSE); + g_return_val_if_fail(index < satellite->num_of_sat_inview, FALSE); + + *prn = satellite->sat_inview[index].prn; + *used = satellite->sat_inview[index].used; + *elevation = satellite->sat_inview[index].elevation; + *azimuth = satellite->sat_inview[index].azimuth; + *snr = satellite->sat_inview[index].snr; + + return TRUE; +} + +EXPORT_API gboolean +location_satellite_set_satellite_details (LocationSatellite *satellite, + guint index, + guint prn, + gboolean used, + guint elevation, + guint azimuth, + gint snr) +{ + g_return_val_if_fail(satellite, FALSE); + g_return_val_if_fail(satellite->sat_inview, FALSE); + g_return_val_if_fail(index < satellite->num_of_sat_inview, FALSE); + + satellite->sat_inview[index].prn= prn; + satellite->sat_inview[index].used= used; + satellite->sat_inview[index].elevation= elevation; + satellite->sat_inview[index].azimuth= azimuth; + satellite->sat_inview[index].snr= snr; + update_num_of_used (satellite); + + return TRUE; +} diff --git a/location/manager/location-satellite.h b/location/manager/location-satellite.h new file mode 100644 index 0000000..3bdb534 --- /dev/null +++ b/location/manager/location-satellite.h @@ -0,0 +1,143 @@ +/* + * libslp-location + * + * 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_SATELLITE_H_ +#define __LOCATION_SATELLITE_H_ + +#include + +G_BEGIN_DECLS + +GType location_satellite_get_type (void); +#define LOCATION_TYPE_SATELLITE (location_satellite_get_type ()) + +/** + * @file location-satellite.h + * @brief This file contains the internal definitions and structures related to satellite information. + */ +/** + * @addtogroup LocationAPI + * @{ + * @defgroup LocationAPISatellite Location Satellite + * @breif This provides APIs related to Location Satellite + * @addtogroup LocationAPISatellite + * @{ + */ + +/** + * @brief This represents one satellite information in view. + */ +typedef struct { + guint prn; ///< The PRNs(Pseudo-Random Noise code) of a satellite. + gboolean used; ///< TRUE if currently used satellite. + guint elevation; ///< The elevation of a satellite. + guint azimuth; ///< The degree from true north 000 to 359 of a satellite. + gint snr; ///< The signal-to-noise ratio, dB of a satellite. +} LocationSatelliteDetail; + +/** + * @brief This represents position information such as number of satellites in used or in view. + */ +struct _LocationSatellite +{ + guint timestamp; ///< Time stamp. + guint num_of_sat_inview; ///< The number of satellites in view. + guint num_of_sat_used; ///< The number of satellites in used. + LocationSatelliteDetail* sat_inview; ///< The information of satellites in view . +}; + +/** + * @brief Create a new #LocationSatellite with given number of #LocationSatelliteDetail. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] num_of_sat_inview - number of #LocationSatelliteDetail. + * @return a new #LocationSatellite + * @retval NULL if error occured + */ +LocationSatellite *location_satellite_new (int num_of_sat_inview); + +/** + * @brief Free a #LocationSatellite. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] satellite - a #LocationSatellite. + * @return None. + */ +void location_satellite_free (LocationSatellite *satellite); + +/** + * @brief Makes a copy of #LocationSatellite + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] satellite - a #LocationSatellite + * @return a new #LocationSatellite + * @retval NULL if error occured + */ +LocationSatellite *location_satellite_copy (const LocationSatellite *satellite); + +/** + * @brief Get elements of #LocationSatelliteDetail with given index in #LocationSatellite. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] satellite - a #LocationSatellite + * @param [in] index - index of #LocationSatelliteDetail in #LocationSatellite + * @param [out] prn - The PRNs(Pseudo-Random Noise code) of a #LocationSatellite + * @param [out] used - TRUE if a #LocationSatellite in used. + * @param [out] elevation - The elevation of a #LocationSatellite + * @param [out] azimuth - The degree from true north 000 to 359 of a#LocationSatellite + * @param [out] snr - The signal-to-noise ratio, dB of #LocationSatellite + * @return gboolean + * @retval\n + * TRUE - if success\n + * FALSE - if error occured\n + */ +gboolean location_satellite_get_satellite_details (const LocationSatellite *satellite, guint index, guint *prn, gboolean *used, guint *elevation, guint *azimuth, gint *snr); + +/** + * @brief Set elements of #LocationSatelliteDetail with given index in #LocationSatellite. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] satellite - a #LocationSatellite + * @param [in] index - index of #LocationSatelliteDetail in #LocationSatellite + * @param [in] prn - The PRNs(Pseudo-Random Noise code) of a #LocationSatellite + * @param [in] used - TRUE if a #LocationSatellite in used. + * @param [in] elevation - The elevation of a #LocationSatellite + * @param [in] azimuth - The degree from true north 000 to 359 of a#LocationSatellite + * @param [in] snr - The signal-to-noise ratio, dB of #LocationSatellite + * @return gboolean + * @retval\n + * TRUE - if success\n + * FALSE - if error occured\n + */ +gboolean location_satellite_set_satellite_details( LocationSatellite *satellite, guint index, guint prn, gboolean used, guint elevation, guint azimuth, gint snr); + +/** + * @} @} + */ + +G_END_DECLS + +#endif diff --git a/location/manager/location-setting.c b/location/manager/location-setting.c new file mode 100644 index 0000000..21358e2 --- /dev/null +++ b/location/manager/location-setting.c @@ -0,0 +1,101 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "location-log.h" +#include "location-setting.h" + + +gint location_setting_get_key_val(keynode_t *key) +{ + g_return_val_if_fail(key, -1); + int val = -1; + switch(vconf_keynode_get_type(key)) + { + case VCONF_TYPE_INT: + val = vconf_keynode_get_int(key); + LOCATION_LOGD("Setting changed [%s]:[%d]", vconf_keynode_get_name(key), val); + break; + default: + LOCATION_LOGW("Unused type(%d)", vconf_keynode_get_type(key)); + break; + } + return val; +} + +gint location_setting_get_int(const gchar* path) +{ + g_return_val_if_fail(path, -1); + int val = -1; + if( vconf_get_int(path, &val)){ + LOCATION_LOGW("vconf_get_int: failed [%s]", path); + val = -1; + } else if (val == 0) + LOCATION_LOGD("vconf_get_int: [%s]:[%d]", path, val); + return val; +} + +gboolean location_setting_get_bool(const gchar* path) +{ + g_return_val_if_fail(path, -1); + gboolean val = FALSE; + if( vconf_get_bool(path, &val)){ + LOCATION_LOGW("vconf_get_int: failed [%s]", path); + val = FALSE; + } + return val; +} + +gchar *location_setting_get_string(const gchar* path) +{ + g_return_val_if_fail(path, -1); + return vconf_get_str(path); +} + +gint location_setting_add_notify(const gchar* path, SettingCB setting_cb, gpointer self) +{ + g_return_val_if_fail(path, -1); + g_return_val_if_fail(self, -1); + + if( vconf_notify_key_changed(path, setting_cb, self)){ + LOCATION_LOGW("vconf notify add failed [%s]", path); + return -1; + } + LOCATION_LOGD("vconf notify added [%s]", path); + return 0; +} + +gint location_setting_ignore_notify(const gchar* path, SettingCB setting_cb) +{ + g_return_val_if_fail(path, -1); + g_return_val_if_fail(setting_cb, -1); + + if( vconf_ignore_key_changed(path, setting_cb)){ + LOCATION_LOGW("vconf notify remove failed [%s]", path); + return -1; + } + LOCATION_LOGD("vconf notify removed [%s]", path); + return 0; +} diff --git a/location/manager/location-setting.h b/location/manager/location-setting.h new file mode 100644 index 0000000..852e288 --- /dev/null +++ b/location/manager/location-setting.h @@ -0,0 +1,67 @@ +/* + * libslp-location + * + * 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_SETTING_H__ +#define __LOCATION_SETTING_H__ + +#include +#include +#include + +/** + * @file location-setting.h + * @brief This file contains the definitions and functions for setting. + */ + +#define VCONF_LOCATION_PATH "db/location" + +#define GPS_ENABLED VCONFKEY_LOCATION_ENABLED +#define LOCATION_SETTING_PATH VCONF_LOCATION_PATH"/setting" +#define AGPS_ENABLED LOCATION_SETTING_PATH"/AgpsEnabled" +#define NETWORK_ENABLED LOCATION_SETTING_PATH"/NetworkEnabled" +#define SENSOR_ENABLED LOCATION_SETTING_PATH"/SensorEnabled" + +#define LOCATION_UPDATE_INTERVAL_MIN 1 +#define LOCATION_UPDATE_INTERVAL_MAX 120 +#define LOCATION_UPDATE_INTERVAL_DEFAULT LOCATION_UPDATE_INTERVAL_MIN + +typedef void (*SettingCB)(keynode_t *key, gpointer data); + +gint location_setting_get_key_val(keynode_t *key); +gint location_setting_get_int(const gchar* path); +gchar *location_setting_get_string(const gchar* path); +gint location_setting_add_notify(const gchar* path, SettingCB setting_cb, gpointer self); +gint location_setting_ignore_notify(const gchar* path, SettingCB setting_cb); + +#define setting_retval_if_fail(path) {\ + if(!location_setting_get_int(path)){\ + return LOCATION_ERROR_NOT_ALLOWED;\ + }\ +} + +#define setting_ret_if_fail(path) {\ + if(!location_setting_get_int(path)){\ + return;\ + }\ +} + + +#endif diff --git a/location/manager/location-signaling-util.c b/location/manager/location-signaling-util.c new file mode 100644 index 0000000..4306c46 --- /dev/null +++ b/location/manager/location-signaling-util.c @@ -0,0 +1,199 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-signaling-util.h" +#include "location-log.h" + +#define POS_EXPIRATION_TIME 9 /* sec */ + +void +enable_signaling (LocationObject *obj, + guint32 signals[LAST_SIGNAL], + gboolean *prev_enabled, + gboolean enabled, + LocationStatus status) +{ + g_return_if_fail(obj); + g_return_if_fail(signals); + g_return_if_fail(prev_enabled); + if (*prev_enabled == TRUE && enabled == FALSE) { + *prev_enabled = FALSE; + LOCATION_LOGD("Signal emit: SERVICE_DISABLED"); + g_signal_emit (obj, signals[SERVICE_DISABLED], 0, LOCATION_STATUS_NO_FIX); + } else if (*prev_enabled == FALSE && enabled == TRUE){ + *prev_enabled = TRUE; + LOCATION_LOGD("Signal emit: SERVICE_ENABLED"); + g_signal_emit (obj, signals[SERVICE_ENABLED], 0, status); + } +} + +void +position_signaling (LocationObject *obj, + guint32 signals[LAST_SIGNAL], + gboolean *prev_enabled, + guint interval, + LocationPosition **prev_pos, + LocationAccuracy **prev_acc, + GList *prev_bound, + ZoneStatus *zone_status, + gboolean enabled, + const LocationPosition *pos, + const LocationAccuracy *acc) +{ + g_return_if_fail(zone_status); + g_return_if_fail(pos); + g_return_if_fail(acc); + g_return_if_fail(obj); + g_return_if_fail(signals); + + int index = 0; + gboolean is_inside = FALSE; + guint updated_timestamp = 0; + GList *boundary_list = prev_bound; + LocationBoundary *boundary = NULL; + + if(!*prev_pos || !*prev_acc || location_accuracy_level_compare(*prev_acc, acc) != -1 || + (pos->timestamp - (*prev_pos)->timestamp) > POS_EXPIRATION_TIME) { + + if(*prev_pos) { + updated_timestamp = (*prev_pos)->updated_timestamp; + location_position_free(*prev_pos); + } + if(*prev_acc) location_accuracy_free(*prev_acc); + + if(!updated_timestamp || pos->timestamp - updated_timestamp >= interval) { + LOCATION_LOGD("Signal emit: POSITION SERVICE_UPDATED"); + g_signal_emit(obj, signals[SERVICE_UPDATED], 0, POSITION_UPDATED, pos, acc); + updated_timestamp = pos->timestamp; + } + + if(boundary_list) { + while((boundary = (LocationBoundary *)g_list_nth_data(boundary_list, index))!= NULL) { + + is_inside = location_boundary_if_inside(boundary, pos); + if(is_inside) { + break; + } + index++; + } + + if(is_inside) { + if(*zone_status != ZONE_STATUS_IN) { + LOCATION_LOGD("Signal emit: ZONE IN"); + g_signal_emit(obj, signals[ZONE_IN], 0, NULL, pos, acc); + *zone_status = ZONE_STATUS_IN; + } + } + else { + if (*zone_status != ZONE_STATUS_OUT) { + LOCATION_LOGD("Signal emit : ZONE_OUT"); + g_signal_emit(obj, signals[ZONE_OUT], 0, NULL, pos, acc); + *zone_status = ZONE_STATUS_OUT; + } + } + + } + } + + *prev_pos = location_position_copy(pos); + *prev_acc = location_accuracy_copy(acc); + (*prev_pos)->updated_timestamp = updated_timestamp; +} + +void +velocity_signaling (LocationObject *obj, + guint32 signals[LAST_SIGNAL], + gboolean *prev_enabled, + guint interval, + LocationVelocity **prev_vel, + gboolean enabled, + const LocationVelocity *vel, + const LocationAccuracy *acc) +{ + g_return_if_fail(obj); + g_return_if_fail(signals); + g_return_if_fail(vel); + + guint updated_timestamp = 0; + + if(*prev_vel) { + updated_timestamp = (*prev_vel)->updated_timestamp; + if(!location_velocity_equal(*prev_vel, vel)) { + location_velocity_free (*prev_vel); + } + } + + *prev_vel = location_velocity_copy (vel); + + if(!updated_timestamp || vel->timestamp - updated_timestamp >= interval) { + + LOCATION_LOGD ("Signal emit: VELOCITY SERVICE_UPDATED"); + LocationVelocity *temp_vel = location_velocity_copy (*prev_vel); + LocationAccuracy *temp_acc = location_accuracy_copy(acc); + + g_signal_emit (obj, signals[SERVICE_UPDATED], 0, VELOCITY_UPDATED, temp_vel, temp_acc); + + (*prev_vel)->updated_timestamp = vel->timestamp; + + location_velocity_free(temp_vel); + location_accuracy_free(temp_acc); + } + else { + (*prev_vel)->updated_timestamp = updated_timestamp; + } + +} + +void +satellite_signaling(LocationObject *obj, + guint32 signals[LAST_SIGNAL], + gboolean *prev_enabled, + guint interval, + guint *sat_timestamp, + LocationSatellite **prev_sat, + gboolean enabled, + const LocationSatellite *sat) +{ + g_return_if_fail(obj); + g_return_if_fail(signals); + g_return_if_fail(sat); + + if (*prev_sat) { + location_satellite_free(*prev_sat); + } + + *prev_sat = location_satellite_copy (sat); + if (!(*sat_timestamp) || sat->timestamp - *sat_timestamp > interval) { + + LOCATION_LOGD ("Signal emit: SATELLITE SERVICE_UPDATED"); + LocationSatellite *temp_sat = location_satellite_copy (sat); + + g_signal_emit (obj, signals[SERVICE_UPDATED], 0, SATELLITE_UPDATED, temp_sat, NULL); + + *sat_timestamp = sat->timestamp; + + location_satellite_free(temp_sat); + } +} diff --git a/location/manager/location-signaling-util.h b/location/manager/location-signaling-util.h new file mode 100644 index 0000000..0ef62d5 --- /dev/null +++ b/location/manager/location-signaling-util.h @@ -0,0 +1,52 @@ +/* + * libslp-location + * + * 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_SIGNALING_UTIL_H__ +#define __LOCATION_SIGNALING_UTIL_H__ + +#include +#include + +/** + * @file location-signaling.h + * @brief This file contains the signaling utils for LocationObject. + */ + +G_BEGIN_DECLS + +typedef enum { + ZONE_STATUS_NONE = 0, + ZONE_STATUS_IN, + ZONE_STATUS_OUT, +} ZoneStatus; + +void enable_signaling (LocationObject *obj, guint32 signals[LAST_SIGNAL], gboolean *prev_enabled, gboolean enabled, LocationStatus status); + +void position_signaling (LocationObject *obj, guint32 signals[LAST_SIGNAL], gboolean *prev_enabled, guint interval, LocationPosition **prev_pos, LocationAccuracy **prev_acc, GList *prev_bound, ZoneStatus *zone_status, gboolean enabled, const LocationPosition *pos, const LocationAccuracy *acc); + +void velocity_signaling (LocationObject* obj, guint32 signals[LAST_SIGNAL], gboolean *prev_enabled, guint interval, LocationVelocity **prev_vel, gboolean enabled, const LocationVelocity *vel, const LocationAccuracy *acc); + +void +satellite_signaling(LocationObject *obj, guint32 signals[LAST_SIGNAL], gboolean *prev_enabled, guint interval, guint *sat_timestamp, LocationSatellite **pre_sat, gboolean enabled, const LocationSatellite *sat); + +G_END_DECLS + +#endif diff --git a/location/manager/location-sps.c b/location/manager/location-sps.c new file mode 100644 index 0000000..734d1d1 --- /dev/null +++ b/location/manager/location-sps.c @@ -0,0 +1,598 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-setting.h" +#include "location-log.h" + +#include "module-internal.h" + +#include "location-sps.h" +#include "location-marshal.h" +#include "location-ielement.h" +#include "location-signaling-util.h" +#include "location-common-util.h" + +typedef struct _LocationSpsPrivate { + LocationSpsMod* mod; + gboolean is_started; + gboolean set_noti; + gboolean enabled; + guint interval; + LocationPosition *pos; + LocationVelocity *vel; + LocationAccuracy *acc; + GList *boundary_list; + ZoneStatus zone_status; + LocationPosition *pos_base; + LocationVelocity *vel_base; + LocationAccuracy *acc_info; + LocationSatellite *sat_info; +} LocationSpsPrivate; + +enum { + PROP_0, + PROP_METHOD_TYPE, + PROP_LAST_POSITION, + PROP_UPDATE_INTERVAL, + PROP_BOUNDARY, + PROP_REMOVAL_BOUNDARY, + PROP_POSITION_BASE, + PROP_VELOCITY_BASE, + PROP_ACCURACY_INFO, + PROP_SATELLITE_INFO, + PROP_MAX +}; + +static guint32 signals[LAST_SIGNAL] = {0, }; +static GParamSpec *properties[PROP_MAX] = {NULL, }; + +#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_SPS, LocationSpsPrivate)) + +static void location_ielement_interface_init (LocationIElementInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (LocationSps, location_sps, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, + location_ielement_interface_init)); + +static void +sps_status_cb (gboolean enabled, + LocationStatus status, + gpointer self) +{ + LOCATION_LOGD("sps_status_cb"); + g_return_if_fail(self); + LocationSpsPrivate* priv = GET_PRIVATE(self); + enable_signaling(self, signals, &(priv->enabled), enabled, status); +} + +static void +sps_position_cb (gboolean enabled, + LocationPosition *pos, + LocationAccuracy *acc, + gpointer self) +{ + LOCATION_LOGD("sps_position_cb"); + g_return_if_fail(self); + g_return_if_fail(pos); + g_return_if_fail(acc); + LocationSpsPrivate* priv = GET_PRIVATE(self); + enable_signaling(self, signals, &(priv->enabled), enabled, pos->status); + + position_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->pos), &(priv->acc), priv->boundary_list, &(priv->zone_status), enabled, pos, acc); +} + +static void +sps_velocity_cb (gboolean enabled, + LocationVelocity *vel, + LocationAccuracy *acc, + gpointer self) +{ + LOCATION_LOGD("sps_velocity_cb"); + g_return_if_fail(self); + LocationSpsPrivate* priv = GET_PRIVATE(self); + velocity_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->vel), enabled, vel, acc); +} + +static void +location_setting_sps_cb(keynode_t *key, + gpointer self) +{ + LOCATION_LOGD("location_setting_sps_cb"); + g_return_if_fail(key); + g_return_if_fail(self); + LocationSpsPrivate* priv = GET_PRIVATE(self); + g_return_if_fail (priv->mod); + g_return_if_fail (priv->mod->handler); + + int ret = LOCATION_ERROR_NONE; + + if (location_setting_get_key_val(key) == 0) { + if (priv->mod->ops.stop && priv->is_started) { + ret = priv->mod->ops.stop(priv->mod->handler); + if (ret == LOCATION_ERROR_NONE) priv->is_started = FALSE; + } + } + else { + if (location_setting_get_int(SENSOR_ENABLED) && + priv->mod->ops.start && !priv->is_started) { + LOCATION_LOGD("location resumed by setting"); + ret = priv->mod->ops.start (priv->mod->handler, sps_status_cb, sps_position_cb, sps_velocity_cb, self); + if (ret == LOCATION_ERROR_NONE) priv->is_started = TRUE; + } + } + +} + +static int +location_sps_start (LocationSps *self) +{ + LOCATION_LOGD("location_sps_start"); + LocationSpsPrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.start, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.update_data, LOCATION_ERROR_NOT_AVAILABLE); + + if( priv->is_started == TRUE) return LOCATION_ERROR_NONE; + + int ret = LOCATION_ERROR_NONE; + int noti_err = 0; + + if (!location_setting_get_int(GPS_ENABLED) || !location_setting_get_int(SENSOR_ENABLED)) { + ret = LOCATION_ERROR_NOT_ALLOWED; + } + else { + ret = priv->mod->ops.start(priv->mod->handler, sps_status_cb, sps_position_cb, sps_velocity_cb, self); + if (ret == LOCATION_ERROR_NONE) { + priv->is_started = TRUE; + } + else { + return ret; + } + + priv->mod->ops.update_data(priv->mod->handler, priv->pos_base, priv->vel_base, priv->acc_info, priv->sat_info); + } + + if (priv->set_noti == FALSE) { + noti_err = location_setting_add_notify (GPS_ENABLED, location_setting_sps_cb, self); + if (noti_err != 0) { + return LOCATION_ERROR_UNKNOWN; + } + noti_err = location_setting_add_notify (SENSOR_ENABLED, location_setting_sps_cb, self); + if (noti_err != 0) { + return LOCATION_ERROR_UNKNOWN; + } + priv->set_noti = TRUE; + } + + return ret; +} + +static int +location_sps_stop (LocationSps *self) +{ + LOCATION_LOGD("location_sps_stop"); + LocationSpsPrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.stop, LOCATION_ERROR_NOT_AVAILABLE); + + int ret = LOCATION_ERROR_NONE; + int noti_err = 0; + + if (priv->is_started == TRUE) { + ret = priv->mod->ops.stop (priv->mod->handler); + if (ret == LOCATION_ERROR_NONE) { + priv->is_started = FALSE; + } + else { + return ret; + } + } + + if (priv->set_noti == TRUE) { + noti_err = location_setting_ignore_notify (GPS_ENABLED, location_setting_sps_cb); + if (noti_err != 0) { + return LOCATION_ERROR_UNKNOWN; + } + noti_err = location_setting_ignore_notify (SENSOR_ENABLED, location_setting_sps_cb); + if (noti_err != 0) { + return LOCATION_ERROR_UNKNOWN; + } + priv->set_noti = FALSE; + } + + return ret; +} + +static void +location_sps_dispose (GObject *gobject) +{ + LOCATION_LOGD("location_sps_dispose"); + G_OBJECT_CLASS (location_sps_parent_class)->dispose (gobject); +} + +static void +location_sps_finalize (GObject *gobject) +{ + LOCATION_LOGD("location_sps_finalize"); + LocationSpsPrivate* priv = GET_PRIVATE(gobject); + module_free(priv->mod, "sps"); + priv->mod = NULL; + G_OBJECT_CLASS (location_sps_parent_class)->finalize (gobject); +} + +static void +location_sps_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + LocationSpsPrivate* priv = GET_PRIVATE(object); + + g_return_if_fail (priv->mod); + g_return_if_fail (priv->mod->handler); + LocModSpsOps ops = priv->mod->ops; + g_return_if_fail (ops.update_data); + + int ret = 0; + switch (property_id){ + case PROP_BOUNDARY:{ + GList *boundary_list = (GList *)g_list_copy(g_value_get_pointer(value)); + ret = set_prop_boundary(&priv->boundary_list, boundary_list); + if(ret != 0) LOCATION_LOGD("Set boundary. Error[%d]", ret); + break; + } + case PROP_REMOVAL_BOUNDARY: { + LocationBoundary *req_boundary = (LocationBoundary*) g_value_dup_boxed(value); + ret = set_prop_removal_boundary(&priv->boundary_list, req_boundary); + if(ret != 0) LOCATION_LOGD("Removal boundary. Error[%d]", ret); + break; + } + case PROP_POSITION_BASE:{ + if(priv->pos_base) location_position_free(priv->pos_base); + priv->pos_base = (LocationPosition*) g_value_dup_boxed (value); + LOCATION_LOGD("Set prop>> base position: \t%lf, %lf, %lf, time: %d", priv->pos_base->latitude, priv->pos_base->longitude, priv->pos_base->altitude, priv->pos_base->timestamp); + if (priv->is_started) ops.update_data (priv->mod->handler, priv->pos_base, priv->vel_base, priv->acc_info, priv->sat_info); + break; + } + case PROP_VELOCITY_BASE:{ + if(priv->vel_base) location_velocity_free(priv->vel_base); + priv->vel_base = (LocationVelocity*) g_value_dup_boxed (value); + LOCATION_LOGD("Set prop>> base velocity: \t%lf, %lf, %lf, time: %d", priv->vel_base->speed, priv->vel_base->direction, priv->vel_base->climb, priv->vel_base->timestamp); + if(priv->is_started) ops.update_data (priv->mod->handler, priv->pos_base, priv->vel_base, priv->acc_info, priv->sat_info); + break; + } + case PROP_ACCURACY_INFO:{ + if(priv->acc_info) location_accuracy_free(priv->acc_info); + priv->acc_info = (LocationAccuracy*) g_value_dup_boxed (value); + LOCATION_LOGD("Set prop>> accuracy information: \t%d, %lf, %lf", priv->acc_info->level, priv->acc_info->horizontal_accuracy, priv->acc_info->vertical_accuracy); + if(priv->is_started) ops.update_data (priv->mod->handler, priv->pos_base, priv->vel_base, priv->acc_info, priv->sat_info); + break; + } + case PROP_SATELLITE_INFO:{ + if(priv->sat_info) location_satellite_free(priv->sat_info); + priv->sat_info = (LocationSatellite*) g_value_dup_boxed (value); + LOCATION_LOGD("Set prop>> satellite information: \tNofView:%d, NofUsed:%d", priv->sat_info->num_of_sat_inview, priv->sat_info->num_of_sat_used); + if(priv->is_started) ops.update_data (priv->mod->handler, priv->pos_base, priv->vel_base, priv->acc_info, priv->sat_info); + break; + } + case PROP_UPDATE_INTERVAL: { + guint interval = g_value_get_uint(value); + if(interval > 0) { + if(interval < LOCATION_UPDATE_INTERVAL_MAX) + priv->interval = interval; + else + priv->interval = (guint)LOCATION_UPDATE_INTERVAL_MAX; + + } + else + priv->interval = (guint)LOCATION_UPDATE_INTERVAL_DEFAULT; + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +location_sps_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + LocationSpsPrivate *priv = GET_PRIVATE (object); + + switch (property_id){ + case PROP_METHOD_TYPE: + g_value_set_int(value, LOCATION_METHOD_SPS); + break; + case PROP_LAST_POSITION: + g_value_set_boxed (value, priv->pos); + break; + case PROP_BOUNDARY: + g_value_set_pointer(value, g_list_first(priv->boundary_list)); + break; + case PROP_POSITION_BASE: + g_value_set_boxed (value, priv->pos_base); + break; + case PROP_VELOCITY_BASE: + g_value_set_boxed (value, priv->vel_base); + break; + case PROP_ACCURACY_INFO: + g_value_set_boxed (value, priv->acc_info); + break; + case PROP_SATELLITE_INFO: + g_value_set_boxed (value, priv->sat_info); + break; + case PROP_UPDATE_INTERVAL: + g_value_set_uint(value, priv->interval); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static int +location_sps_get_position (LocationSps *self, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_sps_get_position"); + + LocationSpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + setting_retval_if_fail(GPS_ENABLED); + setting_retval_if_fail(SENSOR_ENABLED); + + LocModSpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_position, LOCATION_ERROR_NOT_AVAILABLE); + return ops.get_position(priv->mod->handler, position, accuracy); +} + +static int +location_sps_get_last_position (LocationSps *self, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_sps_get_last_position"); + return LOCATION_ERROR_NOT_SUPPORTED; +} + +static int +location_sps_get_velocity (LocationSps *self, + LocationVelocity **velocity, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_sps_get_velocity"); + + LocationSpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + setting_retval_if_fail(GPS_ENABLED); + setting_retval_if_fail(SENSOR_ENABLED); + + LocModSpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_velocity, LOCATION_ERROR_NOT_AVAILABLE); + return ops.get_velocity(priv->mod->handler, velocity, accuracy); +} + +static int +location_sps_get_last_velocity (LocationSps *self, + LocationVelocity **velocity, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_sps_get_last_velocity"); + return LOCATION_ERROR_NOT_SUPPORTED; +} + +static int +location_sps_get_satellite (LocationSps *self, + LocationSatellite **satellite) +{ + LOCATION_LOGD("location_sps_get_satellite"); + return LOCATION_ERROR_NOT_SUPPORTED; +} + +static int +location_sps_get_last_satellite (LocationSps *self, + LocationSatellite **satellite) +{ + LOCATION_LOGD("location_sps_get_last_satellite"); + return LOCATION_ERROR_NOT_SUPPORTED; +} + +static void +location_ielement_interface_init (LocationIElementInterface *iface) +{ + iface->start = (TYPE_START_FUNC)location_sps_start; + iface->stop = (TYPE_STOP_FUNC)location_sps_stop; + iface->get_position = (TYPE_GET_POSITION)location_sps_get_position; + iface->get_last_position = (TYPE_GET_POSITION)location_sps_get_last_position; + iface->get_velocity = (TYPE_GET_VELOCITY)location_sps_get_velocity; + iface->get_last_velocity = (TYPE_GET_VELOCITY)location_sps_get_last_velocity; + iface->get_satellite = (TYPE_GET_SATELLITE)location_sps_get_satellite; + iface->get_last_satellite = (TYPE_GET_SATELLITE)location_sps_get_last_satellite; +} + +static void +location_sps_init (LocationSps *self) +{ + LOCATION_LOGD("location_sps_init"); + LocationSpsPrivate* priv = GET_PRIVATE(self); + + priv->mod = (LocationSpsMod*)module_new("sps"); + if(!priv->mod) + LOCATION_LOGW("module loading failed"); + + priv->is_started = FALSE; + priv->enabled= FALSE; + priv->interval = LOCATION_UPDATE_INTERVAL_DEFAULT; + priv->pos = NULL; + priv->vel = NULL; + priv->acc = NULL; + priv->zone_status = ZONE_STATUS_NONE; + priv->boundary_list = NULL; + + priv->pos_base = NULL; + priv->vel_base = NULL; + priv->acc_info = NULL; + priv->sat_info = NULL; +} + +static void +location_sps_class_init (LocationSpsClass *klass) +{ + LOCATION_LOGD("location_sps_class_init"); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->set_property = location_sps_set_property; + gobject_class->get_property = location_sps_get_property; + + gobject_class->dispose = location_sps_dispose; + gobject_class->finalize = location_sps_finalize; + + g_type_class_add_private (klass, sizeof (LocationSpsPrivate)); + + signals[SERVICE_ENABLED] = g_signal_new ("service-enabled", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationSpsClass, enabled), + NULL, NULL, + location_VOID__UINT, + G_TYPE_NONE, 1, + G_TYPE_UINT); + + signals[SERVICE_DISABLED] = g_signal_new ("service-disabled", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationSpsClass, disabled), + NULL, NULL, + location_VOID__UINT, + G_TYPE_NONE, 1, + G_TYPE_UINT); + + signals[SERVICE_UPDATED] = g_signal_new ("service-updated", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationSpsClass, updated), + NULL, NULL, + location_VOID__UINT_POINTER_POINTER, + G_TYPE_NONE, 3, + G_TYPE_UINT, + G_TYPE_POINTER, + G_TYPE_POINTER); + + signals[ZONE_IN] = g_signal_new ("zone-in", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationSpsClass, zone_in), + NULL, NULL, + location_VOID__UINT_POINTER_POINTER, + G_TYPE_NONE, 3, + G_TYPE_UINT, + G_TYPE_POINTER, + G_TYPE_POINTER); + + signals[ZONE_OUT] = g_signal_new ("zone-out", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationSpsClass, zone_out), + NULL, NULL, + location_VOID__UINT_POINTER_POINTER, + G_TYPE_NONE, 3, + G_TYPE_UINT, + G_TYPE_POINTER, + G_TYPE_POINTER); + + properties[PROP_METHOD_TYPE] = g_param_spec_int ("method", + "method type", + "location method type name", + LOCATION_METHOD_SPS, + LOCATION_METHOD_SPS, + LOCATION_METHOD_SPS, + G_PARAM_READABLE); + + properties[PROP_LAST_POSITION] = g_param_spec_boxed ("last-position", + "sps last position prop", + "sps last position data", + LOCATION_TYPE_POSITION, + G_PARAM_READABLE); + + properties[PROP_UPDATE_INTERVAL] = g_param_spec_uint ("update-interval", + "sps update interval prop", + "sps update interval data", + LOCATION_UPDATE_INTERVAL_MIN, + LOCATION_UPDATE_INTERVAL_MAX, + LOCATION_UPDATE_INTERVAL_DEFAULT, + G_PARAM_READWRITE); + + properties[PROP_BOUNDARY] = g_param_spec_pointer ("boundary", + "sps boundary prop", + "sps boundary data", + G_PARAM_READWRITE); + + properties[PROP_REMOVAL_BOUNDARY] = g_param_spec_boxed("removal-boundary", + "sps removal boundary prop", + "sps removal boundary data", + LOCATION_TYPE_BOUNDARY, + G_PARAM_READWRITE); + + properties[PROP_POSITION_BASE] = g_param_spec_boxed ("position-base", + "sps position base prop", + "sps position base data", + LOCATION_TYPE_POSITION, + G_PARAM_READWRITE); + + properties[PROP_VELOCITY_BASE] = g_param_spec_boxed ("velocity-base", + "sps velocity base prop", + "sps velocity base data", + LOCATION_TYPE_VELOCITY, + G_PARAM_READWRITE); + + properties[PROP_ACCURACY_INFO] = g_param_spec_boxed ("accuracy-info", + "sps accuracy information prop", + "sps accuracy information data", + LOCATION_TYPE_ACCURACY, + G_PARAM_READWRITE); + + properties[PROP_SATELLITE_INFO] = g_param_spec_boxed ("satellite-info", + "sps satellite information prop", + "sps satellite information data", + LOCATION_TYPE_SATELLITE, + G_PARAM_READWRITE); + + g_object_class_install_properties (gobject_class, + PROP_MAX, + properties); +} diff --git a/location/manager/location-sps.h b/location/manager/location-sps.h new file mode 100644 index 0000000..f39815d --- /dev/null +++ b/location/manager/location-sps.h @@ -0,0 +1,64 @@ +/* + * libslp-location + * + * 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_SPS_H__ +#define __LOCATION_SPS_H__ + +#include + +/** + * @file location-sps.h + * @brief This file contains the internal definitions and structures related to SPS. + */ + +G_BEGIN_DECLS + +#define LOCATION_TYPE_SPS (location_sps_get_type ()) +#define LOCATION_SPS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_SPS, LocationSps)) +#define LOCATION_IS_SPS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_SPS)) +#define LOCATION_SPS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_SPS, LocationSpsClass)) +#define LOCATION_IS_SPS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_SPS)) +#define LOCATION_SPS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_SPS, LocationSpsClass)) + +typedef struct _LocationSps LocationSps; +typedef struct _LocationSpsClass LocationSpsClass; + +struct _LocationSps +{ + GObject parent_instance; +}; + +struct _LocationSpsClass +{ + GObjectClass parent_class; + + void (* enabled) (guint type); + void (* disabled) (guint type); + void (* updated) (guint type, gpointer data); + void (* zone_in) (guint type, gpointer position, gpointer boundary); + void (* zone_out) (guint type, gpointer position, gpointer boundary); +}; + +GType location_sps_get_type (void); + +G_END_DECLS + +#endif diff --git a/location/manager/location-velocity.c b/location/manager/location-velocity.c new file mode 100644 index 0000000..61c839e --- /dev/null +++ b/location/manager/location-velocity.c @@ -0,0 +1,92 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-velocity.h" +#include "location-log.h" + +GType +location_velocity_get_type (void) +{ + static volatile gsize type_volatile = 0; + if(g_once_init_enter(&type_volatile)) { + GType type = g_boxed_type_register_static ( + g_intern_static_string ("LocationVelocity"), + (GBoxedCopyFunc) location_velocity_copy, + (GBoxedFreeFunc) location_velocity_free); + g_once_init_leave(&type_volatile, type); + } + return type_volatile; +} + +EXPORT_API LocationVelocity* +location_velocity_new (guint timestamp, + gdouble speed, + gdouble direction, + gdouble climb) +{ + LocationVelocity* velocity = g_slice_new0(LocationVelocity); + velocity->timestamp = timestamp; + velocity->speed = speed; + velocity->direction = direction; + velocity->climb = climb; + return velocity; +} + +EXPORT_API void +location_velocity_free (LocationVelocity* velocity) +{ + g_return_if_fail(velocity); + g_slice_free(LocationVelocity, velocity); +} + +EXPORT_API gboolean +location_velocity_equal (const LocationVelocity *velocity1, const LocationVelocity *velocity2) +{ + g_return_val_if_fail(velocity1, FALSE); + g_return_val_if_fail(velocity2, FALSE); + + if (velocity1->timestamp == velocity2->timestamp && + velocity1->speed == velocity2->speed && + velocity1->direction == velocity2->direction && + velocity1->climb == velocity2->climb) + return TRUE; + return FALSE; +} + +EXPORT_API LocationVelocity* +location_velocity_copy (const LocationVelocity *velocity) +{ + g_return_val_if_fail(velocity, NULL); + + LocationVelocity *new_velocity = NULL; + + new_velocity = location_velocity_new(velocity->timestamp, + velocity->speed, + velocity->direction, + velocity->climb); + if(new_velocity) new_velocity->updated_timestamp = velocity->updated_timestamp; + + return new_velocity; +} diff --git a/location/manager/location-velocity.h b/location/manager/location-velocity.h new file mode 100644 index 0000000..5112298 --- /dev/null +++ b/location/manager/location-velocity.h @@ -0,0 +1,112 @@ +/* + * libslp-location + * + * 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_VELOCITY_H_ +#define __LOCATION_VELOCITY_H_ + +#include + +G_BEGIN_DECLS + +GType location_velocity_get_type (void); +#define LOCATION_TYPE_VELOCITY (location_velocity_get_type ()) + +/** + * @file location-velocity.h + * @brief This file contains the internal definitions and structures related to velocity information. + */ +/** + * @addtogroup LocationAPI + * @{ + * @defgroup LocationAPIVelocity Location Velocity + * @breif This provides APIs related to Location Velocity + * @addtogroup LocationAPIVelocity + * @{ + */ + +/** + * @brief This represents velocity information such as as speed, direction, climb. + */ +struct _LocationVelocity +{ + guint timestamp; ///< Time stamp. + guint updated_timestamp; ///< The latest updated time stamp. + gdouble speed; ///< The speed over ground. (km/h) + gdouble direction; ///< The course made in degrees relative to true north. The value is always in the range [0.0, 360.0] degree. + gdouble climb; ///< The vertical speed. (km/h) +}; + +/** + * @brief Create a new #LocationVelocity with given information. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] timestamp - Time stamp. + * @param [in] speed - The speed over ground. (km/h) + * @param [in] direction - The course made in degrees relative to true north. The value is always in the range [0.0, 360.0] degree. + * @param [in] climb - The vertical speed. (km/h) + * @return a new #LocationVelocity + * @retval NULL if error occured + */ +LocationVelocity *location_velocity_new (guint timestamp, gdouble speed, gdouble direction, gdouble climb); + +/** + * @brief Free a #LocationVelocity. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] velocity - a #LocationVelocity. + * @return None. + */ +void location_velocity_free (LocationVelocity *velocity); + +/** + * @brief Compares two velocities for equality, returning TRUE if they are equal. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] velocity1 - a #LocationVelocity + * @param [in] velocity2 - a #LocationVelocity + * @return gboolean + * @retval\n + * TRUE - if equal\n + * FALSE - if not equal\n + */ +gboolean location_velocity_equal (const LocationVelocity *velocity1, const LocationVelocity *velocity2); + +/** + * @brief Makes a copy of #LocationVelocity + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] velocity - a #LocationVelocity + * @return a new #LocationVelocity + * @retval NULL if error occured + */ +LocationVelocity *location_velocity_copy (const LocationVelocity *velocity); + +/** + * @} @} + */ + +G_END_DECLS + +#endif diff --git a/location/manager/location-wps.c b/location/manager/location-wps.c new file mode 100644 index 0000000..06da7ca --- /dev/null +++ b/location/manager/location-wps.c @@ -0,0 +1,535 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-setting.h" +#include "location-log.h" + +#include "module-internal.h" + +#include "location-wps.h" +#include "location-marshal.h" +#include "location-ielement.h" +#include "location-signaling-util.h" +#include "location-common-util.h" +/* + * forward definitions + */ + +typedef struct _LocationWpsPrivate { + LocationWpsMod* mod; + gboolean is_started; + gboolean set_noti; + gboolean enabled; + guint interval; + LocationPosition *pos; + LocationVelocity *vel; + LocationAccuracy *acc; + GList *boundary_list; + ZoneStatus zone_status; +} LocationWpsPrivate; + +enum { + PROP_0, + PROP_METHOD_TYPE, + PROP_LAST_POSITION, + PROP_UPDATE_INTERVAL, + PROP_BOUNDARY, + PROP_REMOVAL_BOUNDARY, + PROP_MAX +}; + +static guint32 signals[LAST_SIGNAL] = {0, }; +static GParamSpec *properties[PROP_MAX] = {NULL, }; + +#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_WPS, LocationWpsPrivate)) + +static void location_ielement_interface_init (LocationIElementInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (LocationWps, location_wps, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, + location_ielement_interface_init)); + +static void +wps_status_cb (gboolean enabled, + LocationStatus status, + gpointer self) +{ + LOCATION_LOGD("wps_status_cb"); + g_return_if_fail(self); + LocationWpsPrivate* priv = GET_PRIVATE(self); + enable_signaling(self, signals, &(priv->enabled), enabled, status); +} + +static void +wps_position_cb (gboolean enabled, + LocationPosition *pos, + LocationAccuracy *acc, + gpointer self) +{ + LOCATION_LOGD("wps_position_cb"); + g_return_if_fail(self); + g_return_if_fail(pos); + g_return_if_fail(acc); + LocationWpsPrivate* priv = GET_PRIVATE(self); + enable_signaling(self, signals, &(priv->enabled), enabled, pos->status); + position_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->pos), &(priv->acc), priv->boundary_list, &(priv->zone_status), enabled, pos, acc); +} + +static void +wps_velocity_cb(gboolean enabled, + LocationVelocity *vel, + LocationAccuracy *acc, + gpointer self) +{ + LOCATION_LOGD("wps_velocity_cb"); + g_return_if_fail(self); + LocationWpsPrivate* priv = GET_PRIVATE(self); + velocity_signaling(self, signals, &(priv->enabled), priv->interval, &(priv->vel), enabled, vel, acc); +} + +static void +location_setting_wps_cb(keynode_t *key, + gpointer self) +{ + LOCATION_LOGD("location_setting_wps_cb"); + g_return_if_fail(key); + g_return_if_fail(self); + LocationWpsPrivate* priv = GET_PRIVATE(self); + g_return_if_fail (priv->mod); + g_return_if_fail (priv->mod->handler); + + int ret = LOCATION_ERROR_NONE; + + if (location_setting_get_key_val(key) == 0) { + if (priv->mod->ops.stop && priv->is_started) { + ret = priv->mod->ops.stop(priv->mod->handler); + if (ret == LOCATION_ERROR_NONE) priv->is_started = FALSE; + } + } + else { + if (1 == location_setting_get_int(NETWORK_ENABLED) && priv->mod->ops.start && !priv->is_started) { + LOCATION_LOGD("location resumed by setting"); + ret = priv->mod->ops.start (priv->mod->handler, wps_status_cb, wps_position_cb, wps_velocity_cb, NULL, self); + if (ret == LOCATION_ERROR_NONE) priv->is_started = TRUE; + } + } + +} + +static int +location_wps_start (LocationWps *self) +{ + LOCATION_LOGD("location_wps_start"); + LocationWpsPrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.start, LOCATION_ERROR_NOT_AVAILABLE); + + if (priv->is_started == TRUE) return LOCATION_ERROR_NONE; + + int ret = LOCATION_ERROR_NONE; + int noti_err = 0; + + if (!location_setting_get_int(GPS_ENABLED) || !location_setting_get_int(NETWORK_ENABLED)) { + ret = LOCATION_ERROR_NOT_ALLOWED; + } + else { + ret = priv->mod->ops.start (priv->mod->handler, wps_status_cb, wps_position_cb, wps_velocity_cb, NULL, self); + if (ret == LOCATION_ERROR_NONE) { + priv->is_started = TRUE; + } + else { + return ret; + } + } + + if (priv->set_noti == FALSE) { + noti_err = location_setting_add_notify (GPS_ENABLED, location_setting_wps_cb, self); + if (noti_err != 0) { + return LOCATION_ERROR_UNKNOWN; + } + noti_err = location_setting_add_notify (NETWORK_ENABLED, location_setting_wps_cb, self); + if (noti_err != 0) { + return LOCATION_ERROR_UNKNOWN; + } + priv->set_noti = TRUE; + } + + return ret; +} + +static int +location_wps_stop (LocationWps *self) +{ + LOCATION_LOGD("location_wps_stop"); + LocationWpsPrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.stop, LOCATION_ERROR_NOT_AVAILABLE); + + int ret = LOCATION_ERROR_NONE; + int noti_err = 0; + + if (priv->is_started == TRUE) { + ret = priv->mod->ops.stop (priv->mod->handler); + if (ret == LOCATION_ERROR_NONE) { + priv->is_started = FALSE; + } + else { + return ret; + } + } + + if (priv->set_noti == TRUE) { + noti_err = location_setting_ignore_notify (GPS_ENABLED, location_setting_wps_cb); + if (noti_err != 0) { + return LOCATION_ERROR_UNKNOWN; + } + noti_err = location_setting_ignore_notify (NETWORK_ENABLED, location_setting_wps_cb); + if (noti_err != 0) { + return LOCATION_ERROR_UNKNOWN; + } + priv->set_noti = FALSE; + } + + return ret; +} + +static void +location_wps_dispose (GObject *gobject) +{ + LOCATION_LOGD("location_wps_dispose"); + G_OBJECT_CLASS (location_wps_parent_class)->dispose (gobject); +} + +static void +location_wps_finalize (GObject *gobject) +{ + LOCATION_LOGD("location_wps_finalize"); + LocationWpsPrivate* priv = GET_PRIVATE(gobject); + module_free(priv->mod, "wps"); + G_OBJECT_CLASS (location_wps_parent_class)->finalize (gobject); +} + +static void +location_wps_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + LocationWpsPrivate* priv = GET_PRIVATE(object); + int ret = 0; + + switch (property_id){ + case PROP_BOUNDARY:{ + GList *boundary_list = (GList *)g_list_copy(g_value_get_pointer(value)); + ret = set_prop_boundary(&priv->boundary_list, boundary_list); + if(ret != 0) LOCATION_LOGD("Set boundary. Error[%d]", ret); + break; + } + case PROP_REMOVAL_BOUNDARY: { + LocationBoundary *req_boundary = (LocationBoundary*) g_value_dup_boxed(value); + ret = set_prop_removal_boundary(&priv->boundary_list, req_boundary); + if(ret != 0) LOCATION_LOGD("Set removal boundary. Error[%d]", ret); + break; + } + case PROP_UPDATE_INTERVAL: { + guint interval = g_value_get_uint(value); + if(interval > 0) { + if(interval < LOCATION_UPDATE_INTERVAL_MAX) + priv->interval = interval; + else + priv->interval = (guint)LOCATION_UPDATE_INTERVAL_MAX; + } + else + priv->interval = (guint)LOCATION_UPDATE_INTERVAL_DEFAULT; + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +location_wps_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + LocationWpsPrivate *priv = GET_PRIVATE (object); + + switch (property_id){ + case PROP_METHOD_TYPE: + g_value_set_int(value, LOCATION_METHOD_WPS); + break; + case PROP_LAST_POSITION: + g_value_set_boxed (value, priv->pos); + break; + case PROP_BOUNDARY: + g_value_set_pointer(value, g_list_first(priv->boundary_list)); + break; + case PROP_UPDATE_INTERVAL: + g_value_set_uint(value, priv->interval); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static int +location_wps_get_position (LocationWps *self, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_wps_get_position"); + + LocationWpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + setting_retval_if_fail(GPS_ENABLED); + setting_retval_if_fail(NETWORK_ENABLED); + + LocModWpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_position, LOCATION_ERROR_NOT_AVAILABLE); + return ops.get_position(priv->mod->handler, position, accuracy); +} + +static int +location_wps_get_last_position (LocationWps *self, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_wps_get_last_position"); + + /* Do not need to check GPS_ENABLED and NETWORK_ENABLED */ + + LocationWpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + + LocModWpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_last_position, LOCATION_ERROR_NOT_AVAILABLE); + + return ops.get_last_position(priv->mod->handler, position, accuracy); + +} + +static int +location_wps_get_velocity (LocationWps *self, + LocationVelocity **velocity, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_wps_get_velocity"); + + LocationWpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + setting_retval_if_fail(GPS_ENABLED); + setting_retval_if_fail(NETWORK_ENABLED); + + LocModWpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_velocity, LOCATION_ERROR_NOT_AVAILABLE); + return ops.get_velocity(priv->mod->handler, velocity, accuracy); +} + +static int +location_wps_get_last_velocity (LocationWps *self, + LocationVelocity **velocity, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("location_wps_get_last_velocity"); + + /* Do not need to check GPS_ENABLED and NETWORK_ENABLED */ + + LocationWpsPrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + + LocModWpsOps ops = priv->mod->ops; + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (ops.get_last_velocity, LOCATION_ERROR_NOT_AVAILABLE); + return ops.get_last_velocity(priv->mod->handler, velocity, accuracy); + +} + +static int +location_wps_get_satellite (LocationWps *self, + LocationSatellite **satellite) +{ + LOCATION_LOGD("location_wps_get_satellite"); + return LOCATION_ERROR_NOT_SUPPORTED; +} + +static int +location_wps_get_last_satellite (LocationWps *self, + LocationSatellite **satellite) +{ + LOCATION_LOGD("location_wps_get_last_satellite"); + return LOCATION_ERROR_NOT_SUPPORTED; +} + +static void +location_ielement_interface_init (LocationIElementInterface *iface) +{ + iface->start = (TYPE_START_FUNC)location_wps_start; + iface->stop = (TYPE_STOP_FUNC)location_wps_stop; + iface->get_position = (TYPE_GET_POSITION)location_wps_get_position; + iface->get_last_position = (TYPE_GET_POSITION)location_wps_get_last_position; + iface->get_velocity = (TYPE_GET_VELOCITY)location_wps_get_velocity; + iface->get_last_velocity = (TYPE_GET_VELOCITY)location_wps_get_last_velocity; + iface->get_satellite = (TYPE_GET_SATELLITE)location_wps_get_satellite; + iface->get_last_satellite = (TYPE_GET_SATELLITE)location_wps_get_last_satellite; +} + +static void +location_wps_init (LocationWps *self) +{ + LOCATION_LOGD("location_wps_init"); + LocationWpsPrivate* priv = GET_PRIVATE(self); + + priv->mod = (LocationWpsMod*)module_new("wps"); + if(!priv->mod) LOCATION_LOGW("module loading failed"); + + priv->is_started = FALSE; + priv->set_noti = FALSE; + priv->enabled= FALSE; + priv->interval = LOCATION_UPDATE_INTERVAL_DEFAULT; + + priv->pos = NULL; + priv->vel = NULL; + priv->acc = NULL; + priv->zone_status = ZONE_STATUS_NONE; + priv->boundary_list = NULL; +} + +static void +location_wps_class_init (LocationWpsClass *klass) +{ + LOCATION_LOGD("location_wps_class_init"); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->set_property = location_wps_set_property; + gobject_class->get_property = location_wps_get_property; + + gobject_class->dispose = location_wps_dispose; + gobject_class->finalize = location_wps_finalize; + + g_type_class_add_private (klass, sizeof (LocationWpsPrivate)); + + signals[SERVICE_ENABLED] = g_signal_new ("service-enabled", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationWpsClass, enabled), + NULL, NULL, + location_VOID__UINT, + G_TYPE_NONE, 1, + G_TYPE_UINT); + + signals[SERVICE_DISABLED] = g_signal_new ("service-disabled", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationWpsClass, disabled), + NULL, NULL, + location_VOID__UINT, + G_TYPE_NONE, 1, + G_TYPE_UINT); + + signals[SERVICE_UPDATED] = g_signal_new ("service-updated", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationWpsClass, updated), + NULL, NULL, + location_VOID__UINT_POINTER_POINTER, + G_TYPE_NONE, 3, + G_TYPE_UINT, + G_TYPE_POINTER, + G_TYPE_POINTER); + + signals[ZONE_IN] = g_signal_new ("zone-in", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationWpsClass, zone_in), + NULL, NULL, + location_VOID__UINT_POINTER_POINTER, + G_TYPE_NONE, 3, + G_TYPE_UINT, + G_TYPE_POINTER, + G_TYPE_POINTER); + + signals[ZONE_OUT] = g_signal_new ("zone-out", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | + G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (LocationWpsClass, zone_out), + NULL, NULL, + location_VOID__UINT_POINTER_POINTER, + G_TYPE_NONE, 3, + G_TYPE_UINT, + G_TYPE_POINTER, + G_TYPE_POINTER); + + properties[PROP_METHOD_TYPE] = g_param_spec_int ("method", + "method type", + "location method type name", + LOCATION_METHOD_WPS, + LOCATION_METHOD_WPS, + LOCATION_METHOD_WPS, + G_PARAM_READABLE); + + properties[PROP_LAST_POSITION] = g_param_spec_boxed ("last-position", + "wps last position prop", + "wps last position data", + LOCATION_TYPE_POSITION, + G_PARAM_READABLE); + + properties[PROP_UPDATE_INTERVAL] = g_param_spec_uint ("update-interval", + "wps update interval prop", + "wps update interval data", + LOCATION_UPDATE_INTERVAL_MIN, + LOCATION_UPDATE_INTERVAL_MAX, + LOCATION_UPDATE_INTERVAL_DEFAULT, + G_PARAM_READWRITE); + + properties[PROP_BOUNDARY] = g_param_spec_pointer ("boundary", + "wps boundary prop", + "wps boundary data", + G_PARAM_READWRITE); + + properties[PROP_REMOVAL_BOUNDARY] = g_param_spec_boxed("removal-boundary", + "wps removal boundary prop", + "wps removal boundary data", + LOCATION_TYPE_BOUNDARY, + G_PARAM_READWRITE); + + g_object_class_install_properties (gobject_class, + PROP_MAX, + properties); +} + diff --git a/location/manager/location-wps.h b/location/manager/location-wps.h new file mode 100644 index 0000000..67c9e54 --- /dev/null +++ b/location/manager/location-wps.h @@ -0,0 +1,64 @@ +/* + * libslp-location + * + * 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_WPS_H__ +#define __LOCATION_WPS_H__ + +#include + +/** + * @file location-wps.h + * @brief This file contains the internal definitions and structures related to WPS. + */ + +G_BEGIN_DECLS + +#define LOCATION_TYPE_WPS (location_wps_get_type ()) +#define LOCATION_WPS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOCATION_TYPE_WPS, LocationWps)) +#define LOCATION_IS_WPS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOCATION_TYPE_WPS)) +#define LOCATION_WPS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOCATION_TYPE_WPS, LocationWpsClass)) +#define LOCATION_IS_WPS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOCATION_TYPE_WPS)) +#define LOCATION_WPS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOCATION_TYPE_WPS, LocationWpsClass)) + +typedef struct _LocationWps LocationWps; +typedef struct _LocationWpsClass LocationWpsClass; + +struct _LocationWps +{ + GObject parent_instance; +}; + +struct _LocationWpsClass +{ + GObjectClass parent_class; + + void (* enabled) (guint type); + void (* disabled) (guint type); + void (* updated) (guint type, gpointer data); + void (* zone_in) (guint type, gpointer position, gpointer boundary); + void (* zone_out) (guint type, gpointer position, gpointer boundary); +}; + +GType location_wps_get_type (void); + +G_END_DECLS + +#endif diff --git a/location/manager/location.c b/location/manager/location.c new file mode 100644 index 0000000..29c6612 --- /dev/null +++ b/location/manager/location.c @@ -0,0 +1,230 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include "location.h" +#include "location-log.h" +#include "location-setting.h" +#include "location-ielement.h" +#include "location-hybrid.h" +#include "location-gps.h" +#include "location-wps.h" +#include "location-ips.h" +#include "location-cps.h" +#include "location-sps.h" +#include "location-position.h" +#include "map-service.h" +#include "module-internal.h" +#include "location-common-util.h" + +extern LocationObject *g_map_service; + +EXPORT_API +int location_init (void) +{ + LOCATION_LOGD("location_init"); + g_type_init (); + if (!g_thread_supported()) g_thread_init (NULL); + dbus_g_thread_init (); + if( FALSE == module_init() ) + return LOCATION_ERROR_NOT_AVAILABLE; + + return LOCATION_ERROR_NONE; +} + +EXPORT_API LocationObject* +location_new (LocationMethod method) +{ + LocationObject *self = NULL; + + if (!g_map_service) + g_map_service = g_object_new (MAP_TYPE_SERVICE, NULL); + + switch (method) { + case LOCATION_METHOD_HYBRID: + self = g_object_new (LOCATION_TYPE_HYBRID, NULL); + break; + case LOCATION_METHOD_GPS: + self = g_object_new (LOCATION_TYPE_GPS, NULL); + break; + case LOCATION_METHOD_WPS: + self = g_object_new (LOCATION_TYPE_WPS, NULL); + break; + case LOCATION_METHOD_SPS: + self = g_object_new (LOCATION_TYPE_SPS, NULL); + break; + default: + break; + } + return self; +} + +EXPORT_API int +location_free (LocationObject *obj) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + + if (g_map_service) { + g_object_unref (g_map_service); + g_map_service = NULL; + } + + g_object_unref (obj); + return LOCATION_ERROR_NONE; +} + +EXPORT_API int +location_start (LocationObject *obj) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + return location_ielement_start (LOCATION_IELEMENT(obj)); +} + +EXPORT_API int +location_stop (LocationObject *obj) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + return location_ielement_stop (LOCATION_IELEMENT(obj)); +} + +EXPORT_API gboolean +location_is_supported_method(LocationMethod method) +{ + gboolean is_supported = FALSE; + + switch(method) { + case LOCATION_METHOD_HYBRID: + if(module_is_supported("gps") || module_is_supported("wps") || module_is_supported("sps")) + is_supported = TRUE; + break; + case LOCATION_METHOD_GPS: + is_supported = module_is_supported("gps"); + break; + case LOCATION_METHOD_WPS: + is_supported = module_is_supported("wps"); + break; + case LOCATION_METHOD_SPS: + is_supported = module_is_supported("sps"); + break; + case LOCATION_METHOD_CPS: /* deprecated */ + case LOCATION_METHOD_IPS: /* deprecated */ + default: + break; + } + + return is_supported; +} + +EXPORT_API gboolean +location_is_enabled_gps(LocationObject *obj) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + + return (gboolean) location_setting_get_int(GPS_ENABLED); +} + +EXPORT_API int +location_get_position (LocationObject *obj, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER); + return location_ielement_get_position (LOCATION_IELEMENT(obj), position, accuracy); +} + +EXPORT_API int +location_get_last_position (LocationObject *obj, + LocationPosition **position, + LocationAccuracy **accuracy) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER); + return location_ielement_get_last_position (LOCATION_IELEMENT(obj), position, accuracy); +} + +EXPORT_API int +location_get_last_known_position (LocationObject *obj, LocationMethod method, + LocationLastPosition *last_position) +{ + return LOCATION_ERROR_NOT_SUPPORTED; +} + +EXPORT_API int +location_get_satellite (LocationObject *obj, LocationSatellite **satellite) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (satellite, LOCATION_ERROR_PARAMETER); + + return location_ielement_get_satellite (LOCATION_IELEMENT(obj), satellite); +} + +EXPORT_API int +location_get_last_satellite (LocationObject *obj, LocationSatellite **satellite) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (satellite, LOCATION_ERROR_PARAMETER); + + return location_ielement_get_last_satellite (LOCATION_IELEMENT(obj), satellite); +} + +EXPORT_API int +location_get_velocity (LocationObject *obj, + LocationVelocity **velocity, + LocationAccuracy **accuracy) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER); + + return location_ielement_get_velocity (LOCATION_IELEMENT(obj), velocity, accuracy); +} + +EXPORT_API int +location_get_last_velocity (LocationObject *obj, + LocationVelocity **velocity, + LocationAccuracy **accuracy) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER); + + return location_ielement_get_last_velocity (LOCATION_IELEMENT(obj), velocity, accuracy); +} + + +EXPORT_API int +location_send_command(const char *cmd) +{ + g_return_val_if_fail (cmd, LOCATION_ERROR_PARAMETER); + + return LOCATION_ERROR_NONE; +} + diff --git a/location/manager/location.h b/location/manager/location.h new file mode 100644 index 0000000..17f1164 --- /dev/null +++ b/location/manager/location.h @@ -0,0 +1,738 @@ +/* + * libslp-location + * + * 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_H__ +#define __LOCATION_H__ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +/** + * @file location.h + * @brief This file contains the Location API and related structure and enumeration. + */ +/** + * @defgroup LocationFW LocationFW + * @brief This is a Location Framework for providing location based services. + * @addtogroup LocationFW + * @{ + * @defgroup LocationAPI Location API + * @brief This sub module provides the Location API. + * @addtogroup LocationAPI + * @{ + */ + +/** + * @brief + * Initialize location sub module. + * @remarks None. + * This API should be called before any other Location APIs. + * @pre None. + * @post None. + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @see None. + */ +int location_init (void); + +/** + * @brief + * Create a new #LocationObject by using given #LocationMethod. + * @remarks + * Returned object is necessary for other APIs. + * @pre + * #location_init should be called before. + * @post None. + * @param [in] + * method - Location method to be used. + * @return a new #LocationObject + * @retval NULL if error occured + * @see location_free + */ +LocationObject *location_new (LocationMethod method); + +/** + * @brief + * Free memory of given #LocationObject. + * @remarks None. + * @pre + * #location_init should be called before. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new. + * @return int + * @retval 0 Success. + * + * Please refer #LocationError for more information. + * @see location_new + * @par Example + * @code +#include +int main (int argc, char *argv[]) +{ + LocationObject *loc = NULL; + location_init (); + loc = location_new (LOCATION_METHOD_GPS); + if(!loc) + return -1; + + // ... Implement your code + + location_free (loc); + // You must free LocationObject when you don't need to use anymore. + return 0; +} + * @endcode + */ +int location_free (LocationObject *obj); + +/** + * @brief + * Start the location service by using given #LocationObject. + * @remarks + * If you want to recieve signals, you should use this API. + * @pre + * #location_init should be called before. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @return int + * @retval 0 Success. + * + * Please refer #LocationError for more information. + * @see location_stop + * @par Example + * @code +#include +static GMainLoop *loop = NULL; + +static void cb_service_enabled (GObject *self, guint status, gpointer userdata) +{ + LocationObject *loc = (LocationObject*)userdata; + LocationAccuracy *acc = NULL; + LocationPosition *pos = NULL; + LocationVelocity *vel = NULL; + LocationAddress *addr = NULL; + LocationMethod method; + + g_object_get(loc, "method", &method, NULL); + g_debug("Get property>> method:%d", method); + + if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) { + g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d", + pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", + acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + location_position_free(pos); + location_accuracy_free(acc); + } else g_warning ("SYNC>> Current position> failed"); + + if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) { + g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f", + vel->timestamp, vel->speed, vel->direction, vel->climb); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", + acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + location_velocity_free(vel); + location_accuracy_free(acc); + } else g_warning ("SYNC>> Current velocity> failed"); + + if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) { + g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s", + addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + location_address_free(addr); + location_accuracy_free(acc); + } else g_warning ("SYNC>> Current address> failed"); +} + +static void +cb_service_updated (GObject *self, + guint type, + gpointer data, + gpointer accuracy, + gpointer userdata) +{ + LocationAccuracy *acc = (LocationAccuracy*) accuracy; + switch (type) { + case POSITION_UPDATED: { + LocationPosition *pos = (LocationPosition*) data; + g_debug ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d", + pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", + acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + } + break; + case VELOCITY_UPDATED: { + LocationVelocity *vel = (LocationVelocity*) data; + g_debug ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f", + vel->timestamp, vel->speed, vel->direction, vel->climb); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", + acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + } + break; + default: + g_warning ("ASYNC>> Undefined update type"); + break; + } +} + + +int main (int argc, char *argv[]) +{ + LocationObject *loc = NULL; + int interval = 6; //seconds + location_init (); + + loc = location_new (LOCATION_METHOD_GPS); + if(!loc) + return -1; + + g_object_set(loc, "update-interval", interval, NULL); + + g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc); + g_signal_connect (loc, "service-updated", G_CALLBACK(cb_service_updated), loc); + + location_start(loc); + loop = g_main_loop_new (NULL, TRUE); + g_main_loop_run (loop); // GMainLoop is needed for receiving signals. + + // ... + return 0; +} + * @endcode + */ +int location_start (LocationObject *obj); + +/** + * @brief + * Stop the location service by using given #LocationObject. + * @remarks + * After call this API, you can not recieve signals. + * @pre + * #location_init should be called before.\n + * #location_start should be called before. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @see location_start + * @par Example + * @code +#include +static GMainLoop *loop = NULL; + +int main (int argc, char *argv[]) +{ + LocationObject *loc = NULL; + location_init (); + loc = location_new (LOCATION_METHOD_GPS); + if(!loc) + return -1; + + location_start(loc); + loop = g_main_loop_new (NULL, TRUE); + g_main_loop_run (loop); + + // .... + + location_stop (loc); + // you can not receive signals anymore. + return 0; +} + * @endcode + */ +int location_stop (LocationObject *obj); + +/** + * @brief + * Check wheither a method is available. + * @remarks + * @pre + * #location_init should be called before.\n + * @post None. + * @param [in] method - a #LocationMethod + * @return int + * @retval True Supported + * False Not supported + * @par Example + #include +static GMainLoop *loop = NULL; + +int main (int argc, char *argv[]) +{ + gboolean is_supported = FALSE; + + // .... + + is_supported = location_is_supported_method(LOCATION_METHOD_HYBRID); + if(is_supported == TRUE) + g_printf("Hybrid Method is supported.\n"); + else + g_printf("Hybrid Method is not supported.\n"); + + return 0; +}* @code + * @endcode + */ +gboolean location_is_supported_method(LocationMethod method); + +/** + * @brief + * Check wheither GPS is turned on or off. + * @remarks + * @pre + * #location_init should be called before.\n + * @post None. + * @param [in] method - a #LocationMethod + * @return int + * @retval True Turned on + * False Turned off + * @par Example + #include +static GMainLoop *loop = NULL; + +int main (int argc, char *argv[]) +{ + gboolean is_enabled = FALSE; + + // .... + + is_enabled = location_is_enabled_gps(loc); + if(is_enable == TRUE) + g_printf("GPS is turned on.\n"); + else + g_printf("GPS is turned off.\n"); + + return 0; +}* @code + * @endcode + */ +gboolean location_is_enabled_gps(LocationObject *obj); + +/** + * @brief + * Get current position information with estimate of the accuracy. + * @remarks Out parameters are should be freed. + * @pre + * #location_init should be called before.\n + * #location_start should be called before. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [out] + * position - a new #LocationPosition + * @param [out] + * accuracy - a new #LocationAccuracy + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @see location_get_velocity + * @par Example + * @code +#include +static GMainLoop *loop = NULL; + +static void cb_service_enabled (GObject *self, guint status, gpointer userdata) +{ + g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata); + + LocationObject *loc = (LocationObject*)userdata; + LocationAccuracy *acc = NULL; + LocationPosition *pos = NULL; + + // This function works properly after service is enabled. + if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) { + g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d", + pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", + acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + location_position_free(pos); + location_accuracy_free(acc); + } else g_warning ("SYNC>> Current position> failed"); +} + +int main (int argc, char *argv[]) +{ + LocationObject *loc = NULL; + gulong handler_id = 0; + + location_init (); + loop = g_main_loop_new (NULL, TRUE); + loc = location_new (LOCATION_METHOD_GPS); + if(!loc){ + g_debug("location_new failed"); + return -1; + } + + handler_id = g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc); + location_start (loc); + g_main_loop_run (loop); + + g_signal_handler_disconnect(loc, handler_id); + location_stop (loc); + location_free (loc); + + return 0; +} + * @endcode + */ +int location_get_position (LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy); + +/** + * @brief + * Get last position information with estimate of the accuracy. + * @remarks This API is not implemented now. \n + * Out parameters are should be freed. + * @pre + * #location_init should be called before. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [out] + * position - a new #LocationPosition + * @param [out] + * accuracy - a new #LocationAccuracy + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @see location_get_position + * @par Example + * @code +#include + +int main (int argc, char *argv[]) +{ + LocationObject *loc = NULL; + int ret = 0; + LocationPosition *last_pos = NULL; + LocationAccuracy *last_acc = NULL; + + location_init (); + loc = location_new (LOCATION_METHOD_GPS); + if(!loc){ + g_debug("location_new failed"); + return -1; + } + + if (LOCATION_ERROR_NONE == location_get_last_position (loc, &last_pos, &last_acc)) { + g_debug ("SYNC>> Last position> time: %d, lat: %f, long: %f, alt: %f, status: %d", + last_pos->timestamp, last_pos->latitude, last_pos->longitude, last_pos->altitude, last_pos->status); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", + last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy); + location_position_free(last_pos); + location_accuracy_free(last_acc); + } else g_warning ("SYNC>> Last position> failed"); + + location_free (loc); + + return 0; +} + * @endcode + */ +int location_get_last_position (LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy); + +/** + * @brief + * Get last satellite information. + * @remarks This API is not implemented now. \n + * Out parameters are should be freed. + * @pre + * #location_init should be called before. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [out] satellite - a new #LocationSatellite + * @return int + * @retval 0 Success + * Please refer #LocationError for more information. + * @see location_get_last_satellite + * @par Example + * @code +#include + +int main (int argc, char *argv[]) +{ + LocationObject *loc = NULL; + int ret = 0, idx = 0; + LocationSatellite *sat = NULL; + guint prn; + gboolean used; + guint elevation; + guint azimuth; + gint snr; + + location_init (); + loc = location_new (LOCATION_METHOD_GPS); + if(!loc){ + g_debug("location_new failed"); + return -1; + } + + if (LOCATION_ERROR_NONE == location_get_satellite (loc, &sat)) { + g_debug ("SYNC>> Current Sattelite> satellite in view = %d, satellite in used = %d", sat->num_of_sat_inview, sat->num_of_sat_used); + g_debug ("\tinview satellite information = "); + for (idx=0; idxnum_of_sat_inview; idx++) { + location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr); + g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr); + } + location_satellite_free (sat); + } else g_warning ("SYNC>> Current satellite> failed"); + + location_free (loc); + + return 0; +} + * @endcode + */ +int location_get_satellite (LocationObject *obj, LocationSatellite **satellite); + +/** + * @brief + * Get last satellite information. + * @remarks This API is not implemented now. \n + * Out parameters are should be freed. + * @pre + * #location_init should be called before. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [out] + * satellite - a new #LocationSatellite + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @par Example + * @code +#include + +int main (int argc, char *argv[]) +{ + LocationObject *loc = NULL; + int ret = 0, idx = 0; + LocationSatellite *last_sat = NULL; + guint prn; + gboolean used; + guint elevation; + guint azimuth; + gint snr; + + location_init (); + loc = location_new (LOCATION_METHOD_GPS); + if(!loc){ + g_debug("location_new failed"); + return -1; + } + + if (LOCATION_ERROR_NONE == location_get_last_satellite (loc, &last_sat)) { + g_debug ("SYNC>> Last Sattelite> satellite in view = %d, satellite in used = %d", last_sat->num_of_sat_inview, last_sat->num_of_sat_used); + g_debug ("\tinview satellite information = "); + for (idx=0; idxnum_of_sat_inview; idx++) { + location_satellite_get_satellite_details(last_sat, idx, &prn, &used, &elevation, &azimuth, &snr); + g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr); + } + location_satellite_free (last_sat); + } else g_warning ("SYNC>> Last satellite> failed"); + + location_free (loc); + + return 0; +} + * @endcode + */ +int location_get_last_satellite (LocationObject *obj, LocationSatellite **satellite); + +/** + * @brief + * Get last known position information with estimate of the accuracy. + * @remarks This API would be DEPRECATED. \n + * @see location_get_last_position + */ +int location_get_last_known_position (LocationObject *obj, LocationMethod method, LocationLastPosition *last_position) LOCATION_DEPRECATED_API; + +/** + * @brief + * Get current velocity information with estimate of the accuracy. + * @remarks Out parameters are should be freed. + * @pre + * #location_init should be called before.\n + * #location_start should be called before. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [out] + * velocity - a new #LocationVelocity + * @param [out] + * accuracy - a new #LocationAccuracy + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @see location_get_position + * @par Example + * @code +#include +static GMainLoop *loop = NULL; + +static void cb_service_enabled (GObject *self, guint status, gpointer userdata) +{ + g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata); + + LocationObject *loc = (LocationObject*)userdata; + LocationAccuracy *acc = NULL; + LocationVelocity *vel = NULL; + + if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) { + g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f", + vel->timestamp, vel->speed, vel->direction, vel->climb); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", + acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + location_velocity_free(vel); + location_accuracy_free(acc); + } else g_warning ("SYNC>> Current velocity> failed"); +} + +int main (int argc, char *argv[]) +{ + LocationObject *loc = NULL; + gulong hander_id = 0; + location_init (); + + loop = g_main_loop_new (NULL, TRUE); + + loc = location_new (LOCATION_METHOD_GPS); + if(!loc){ + g_debug("location_new failed"); + return -1; + } + + handler_id = g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc); + location_start (loc); + g_main_loop_run (loop); + + g_signal_handler_disconnect(loc, handler_id); + location_stop (loc); + location_free (loc); + + return 0; +} + + * @endcode + */ +int location_get_velocity (LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy); + +/** + * @brief + * Get last velocity information with estimate of the accuracy. + * @remarks Out parameters are should be freed. + * @pre + * #location_init should be called before. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [out] + * velocity - a new #LocationVelocity + * @param [out] + * accuracy - a new #LocationAccuracy + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @see location_get_position + * @par Example + * @code +#include + +int main (int argc, char *argv[]) +{ + int ret = 0; + LocationObject *loc = NULL; + LocationVelocity *vel = NULL; + LocationAccuracy *acc = NULL; + gulong hander_id = 0; + + location_init (); + + loc = location_new (LOCATION_METHOD_GPS); + if(!loc){ + g_debug("location_new failed"); + return -1; + } + + ret = location_get_last_velocity (loc, &vel, &acc); + if (ret == LOCATION_ERROR_NONE) { + g_debug ("SYNC>> Last velocity> time: %d, speed: %f, direction:%f, climb:%f", + vel->timestamp, vel->speed, vel->direction, vel->climb); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", + acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + location_velocity_free(vel); + location_accuracy_free(acc); + } + + location_free (loc); + return 0; +} + * @endcode + */ +int location_get_last_velocity (LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy); + +/** + * @brief + * Send command to the server. + * @remarks This functions is not implemneted yet. + * @pre + * #location_init should be called before.\n + * Calling application must have glib or ecore main loop.\n + * Calling application must have an active data connection. + * @post None. + * @param [in] cmd - a #char + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + */ +int location_send_command(const char *cmd); + +/** + * @} @} + */ + +G_END_DECLS + +#endif /* __LOCATION_H__ */ diff --git a/location/map-service/Makefile.am b/location/map-service/Makefile.am new file mode 100644 index 0000000..8105fcb --- /dev/null +++ b/location/map-service/Makefile.am @@ -0,0 +1,27 @@ +noinst_LTLIBRARIES = liblocation-map-service.la + +COMMON_HEADER_DIR = include +MANAGER_DIR = manager +MAP_SERVICE_DIR = map-service +MODULE_DIR = module + +liblocation_map_service_la_SOURCES = \ + location-pref.c \ + location-address.c \ + location-geocode.c \ + location-poi.c \ + location-landmark.c \ + location-route.c \ + map-service.c \ + map-internal.c + +liblocation_map_service_la_CFLAGS = \ + -fPIC\ + -I${srcdir} \ + -I${srcdir}/.. \ + -I${srcdir}/../include \ + -I${srcdir}/../${MANAGER_DIR} \ + -I${srcdir}/../${MODULE_DIR} \ + -I${srcdir}/../${MAP_SERVICE_DIR} \ + $(LOCATION_CFLAGS) + diff --git a/location/map-service/location-address.c b/location/map-service/location-address.c new file mode 100644 index 0000000..856757c --- /dev/null +++ b/location/map-service/location-address.c @@ -0,0 +1,90 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-address.h" +#include "location-log.h" + +GType +location_address_get_type (void) +{ + static volatile gsize type_volatile = 0; + if(g_once_init_enter(&type_volatile)) { + GType type = g_boxed_type_register_static ( + g_intern_static_string ("LocationAddress"), + (GBoxedCopyFunc) location_address_copy, + (GBoxedFreeFunc) location_address_free); + g_once_init_leave(&type_volatile, type); + } + return type_volatile; +} + +EXPORT_API LocationAddress* +location_address_new (const gchar *building_number, + const gchar *street, + const gchar *district, + const gchar *city, + const gchar *state, + const gchar *country_code, + const gchar *postal_code) +{ + LocationAddress* address = g_slice_new0(LocationAddress); + + address->building_number = g_strdup(building_number); + address->street = g_strdup(street); + address->district = g_strdup(district); + address->city = g_strdup(city); + address->state = g_strdup(state); + address->country_code = g_strdup(country_code); + address->postal_code = g_strdup(postal_code); + + return address; +} + +EXPORT_API void +location_address_free (LocationAddress* address) +{ + g_return_if_fail(address); + g_free(address->building_number); + g_free(address->street); + g_free(address->district); + g_free(address->city); + g_free(address->state); + g_free(address->country_code); + g_free(address->postal_code); + g_slice_free(LocationAddress, address); +} + +EXPORT_API LocationAddress* +location_address_copy (const LocationAddress *address) +{ + g_return_val_if_fail(address, NULL); + return location_address_new(address->building_number, + address->street, + address->district, + address->city, + address->state, + address->country_code, + address->postal_code); +} diff --git a/location/map-service/location-address.h b/location/map-service/location-address.h new file mode 100644 index 0000000..77e6208 --- /dev/null +++ b/location/map-service/location-address.h @@ -0,0 +1,101 @@ +/* + * libslp-location + * + * 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_ADDRESS_H_ +#define __LOCATION_ADDRESS_H_ + +#include + +G_BEGIN_DECLS + +GType location_address_get_type(void); +#define LOCATION_TYPE_ADDRESS (location_address_get_type()) + +/** + * @file location-address.h + * @brief This file contains the definitions, structures, and functions related to address information. + * @addtogroup LocationMapService + * @{ + * @defgroup LocationMapServiceGeocode Location Geocode + * @brief This sub module provides structure, enumeration, and asynchronous function definitions. + * @addtogroup LocationMapServiceGeocode + * @{ + */ + +/** + * @brief This represents address information such as building number, street name, etc. + */ +struct _LocationAddress +{ + gchar *building_number; ///< Building number. + gchar *street; ///< Full street name. + gchar *district; ///< Municipal district name. + gchar *city; ///< City name. + gchar *state; ///< State or province region of a nation. + gchar *country_code; ///< Country name. + gchar *postal_code; ///< Postal delivery code. +}; + +/** + * @brief Create a new #LocationAddress with given information. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] building_number - Building number + * @param [in] street - Full street name. + * @param [in] district - Municipal district name. + * @param [in] city - City name. + * @param [in] state - State or province region of a nation. + * @param [in] country_code - Country name. + * @param [in] postal_code - Postal delivery code. + * @return a new #LocationAddress + * @retval NULL if error occured + */ +LocationAddress *location_address_new (const gchar *building_number, const gchar *street, const gchar *district, const gchar *city, const gchar *state, const gchar *country_code, const gchar *postal_code); + +/** + * @brief Free a #LocationAddress. + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] address - a #LocationAddress. + * @return None. + */ +void location_address_free (LocationAddress *address); + +/** + * @brief Makes a copy of #LocationAddress + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] address - a #LocationAddress + * @return a new #LocationAddress + * @retval NULL if error occured + */ +LocationAddress *location_address_copy (const LocationAddress *address); + +/** + * @} @} + */ + +G_END_DECLS + +#endif diff --git a/location/map-service/location-geocode.c b/location/map-service/location-geocode.c new file mode 100644 index 0000000..aee43c8 --- /dev/null +++ b/location/map-service/location-geocode.c @@ -0,0 +1,27 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-log.h" + diff --git a/location/map-service/location-geocode.h b/location/map-service/location-geocode.h new file mode 100644 index 0000000..1e8b4de --- /dev/null +++ b/location/map-service/location-geocode.h @@ -0,0 +1,39 @@ +/* + * libslp-location + * + * 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_GEOCODE_H__ +#define __LOCATION_GEOCODE_H__ + +#include + +G_BEGIN_DECLS + +/** + * @file location-geocode.h + * @brief This file contains the internal definitions and structures related to geocode. + * @addtogroup LocationMapService + * @{ + * @} + */ + +G_END_DECLS + +#endif diff --git a/location/map-service/location-landmark-ext.h b/location/map-service/location-landmark-ext.h new file mode 100644 index 0000000..3658d6d --- /dev/null +++ b/location/map-service/location-landmark-ext.h @@ -0,0 +1,117 @@ +/* + * libslp-location + * + * 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_LANDMARK_EXT_H__ +#define __LOCATION_LANDMARK_EXT_H__ + +#include + +G_BEGIN_DECLS + +/** + * @file location-landmark-ext.h + * @brief This file contains the extensional definitions and structures related to Landmark. + */ + +/** + * @addtogroup LocationMapServicePOI + * @{ + * @defgroup LocationMapServiceLandmarkExt Location Landmark Ext + * @brief This provides Location Landmark Ext APIs + * @addtogroup LocationMapServiceLandmarkExt + * @{ + */ + +/** + * @brief Set the ID of the given #LocationLandmark + */ +gboolean location_landmark_set_id (LocationLandmark *landmark, guint id); + +/** + * @brief Set the name of the given #LocationLandmark + */ +gboolean location_landmark_set_name (LocationLandmark *landmark, const gchar *name); +/** + * @brief Set the position in the given #LocationLandmark + */ +gboolean location_landmark_set_position (LocationLandmark *landmark, const LocationPosition *position); +/** + * @brief Set the address of the given #LocationLandmark + */ +gboolean location_landmark_set_address (LocationLandmark *landmark, const LocationAddress *addr); +/** + * @brief Set the description of the given #LocationLandmark + */ +gboolean location_landmark_set_description (LocationLandmark *landmark, const gchar *desc); +/** + * @brief Set the timestamp of the given #LocationLandmark + */ +gboolean location_landmark_set_timestamp (LocationLandmark *landmark, guint timestamp); +/** + * @brief Set the priority of the given #LocationLandmark + */ +gboolean location_landmark_set_priority (LocationLandmark *landmark, guint priority); +/** + * @brief Set the boundary of the given #LocationLandmark + */ +gboolean location_landmark_set_bounding_box (LocationLandmark *landmark, const LocationBoundary *bbox); +/** + * @brief Set the author of the given #LocationLandmark + */ +gboolean location_landmark_set_author (LocationLandmark *landmark, const gchar *author); +/** + * @brief Set the urls of the given #LocationLandmark + */ +gboolean location_landmark_set_url (LocationLandmark *landmark, GList *url); + +/** + * @brief Set the categories of the given #LocationLandmark + */ +gboolean location_landmark_set_category (const LocationLandmark *landmark, GList *category); + +/** + * @brief Set the phone number of the given #LocationLandmark + */ +gboolean location_landmark_set_phone_number (const LocationLandmark *landmark, const gchar *number); + +/** + * @brief Set the property data of the given #LocationLandmark + */ +gboolean location_landmark_set_property (const LocationLandmark *landmark, gconstpointer key, gconstpointer value); + +/** + * @brief Set url of the given #LocationLandmarkUrl + */ +gboolean location_landmark_url_set_url_path (LocationLandmarkUrl *url, const gchar *path); +/** + * @brief Set the description of the given #LocationLandmarkUrl + */ +gboolean location_landmark_url_set_description (LocationLandmarkUrl *url, const gchar *desc); + +/** + * @} @} + */ + +G_END_DECLS + +#endif + + diff --git a/location/map-service/location-landmark.c b/location/map-service/location-landmark.c new file mode 100644 index 0000000..91c4504 --- /dev/null +++ b/location/map-service/location-landmark.c @@ -0,0 +1,528 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-log.h" +#include "location.h" +#include "location-types.h" +#include "map-service.h" + +struct _LocationLandmark { + + guint id; ///< Unique identifier of the landmark + guint priority; ///< Degree of importance of the landmark (Between HIGHEST_LANDMARK_PRIORITY and LOWEST_LANDMARK_PRIORITY) + gchar *name; ///< Name of landmark + LocationPosition *position; ///< Positon of the landmark, may be null if not known + LocationAddress *addr; ///< Textual address information of the landmark, may be null if not + LocationBoundary *bbox; ///< Coverage area of the landmark, may be null if not available + guint timestamp; ///< Time when the landmark data was last updated (updated by system and used to facilitate tracking) + + gchar *author; ///< Provider of the landmark data, may be null + gchar *store; ///< Name of landmark store that the landmark belongs to + gchar *phone_number; ///< Nhone number of the landmark, may be null + GList *category; ///< Categories to which the landmark belongs to + GList *url; ///< Url to additional content (Optional) + gchar *desc; ///< Description of the landmark, may be null if not available + + GHashTable *properties; ///< Extra info of the landmark + +}; + +struct _LocationLandmarkUrl { + gchar *path; ///< Url of landmark url info + gchar *desc; ///< Description of landmark url info +}; + +EXPORT_API guint +location_landmark_get_id (const LocationLandmark *landmark) +{ + g_return_val_if_fail(landmark, 0); + + return landmark->id; +} + + +EXPORT_API gchar * +location_landmark_get_name (const LocationLandmark *landmark) +{ + g_return_val_if_fail(landmark, NULL); + + return landmark->name; +} + +EXPORT_API LocationPosition * +location_landmark_get_position (const LocationLandmark *landmark) +{ + g_return_val_if_fail(landmark, NULL); + + return landmark->position; +} + +EXPORT_API LocationAddress * +location_landmark_get_address (const LocationLandmark *landmark) +{ + g_return_val_if_fail(landmark, NULL); + + return landmark->addr; +} + +EXPORT_API gchar * +location_landmark_get_description (const LocationLandmark *landmark) +{ + g_return_val_if_fail(landmark, NULL); + + return landmark->desc; +} + +EXPORT_API guint +location_landmark_get_timestamp (const LocationLandmark *landmark) +{ + g_return_val_if_fail(landmark, 0); + + return landmark->timestamp; +} + +EXPORT_API guint +location_landmark_get_priority (const LocationLandmark *landmark) +{ + g_return_val_if_fail(landmark, 0); + + return landmark->priority; +} + +EXPORT_API LocationBoundary * +location_landmark_get_bounding_box (const LocationLandmark *landmark) +{ + g_return_val_if_fail(landmark, NULL); + + return landmark->bbox; +} + +EXPORT_API gchar * +location_landmark_get_author (const LocationLandmark *landmark) +{ + g_return_val_if_fail(landmark, NULL); + + return landmark->author; +} + +EXPORT_API GList * +location_landmark_get_url (const LocationLandmark *landmark) +{ + g_return_val_if_fail(landmark, NULL); + + return landmark->url; +} + +EXPORT_API GList * +location_landmark_get_category (const LocationLandmark *landmark) +{ + g_return_val_if_fail(landmark, NULL); + + return landmark->category; +} + +EXPORT_API gchar * +location_landmark_get_phone_number (const LocationLandmark *landmark) +{ + g_return_val_if_fail(landmark, NULL); + + return (const gchar *) landmark->phone_number; +} + +EXPORT_API GList * +location_landmark_get_property_key (const LocationLandmark *landmark) +{ + g_return_val_if_fail(landmark, NULL); + + return g_hash_table_get_keys (landmark->properties); +} + +EXPORT_API gconstpointer +location_landmark_get_property (const LocationLandmark *landmark, gconstpointer key) +{ + g_return_val_if_fail(landmark, NULL); + g_return_val_if_fail(key, NULL); + if (!landmark->properties) return NULL; + + return g_hash_table_lookup (landmark->properties, key); +} + +EXPORT_API gboolean +location_landmark_set_id (LocationLandmark *landmark, guint id) +{ + g_return_val_if_fail(landmark, FALSE); + + landmark->id = id; + + return TRUE; +} + +EXPORT_API gboolean +location_landmark_set_name (LocationLandmark *landmark, const gchar *name) +{ + g_return_val_if_fail(landmark, FALSE); + + if (landmark->name) { + g_free(landmark->name); + landmark->name = NULL; + } + if (name) landmark->name = g_strdup (name); + + return TRUE; +} + +EXPORT_API gboolean +location_landmark_set_position (LocationLandmark *landmark, const LocationPosition *position) +{ + g_return_val_if_fail(landmark, FALSE); + + if (landmark->position) { + location_position_free(landmark->position); + landmark->position = NULL; + } + + if (position) landmark->position = location_position_copy (position); + + return TRUE; + +} + +EXPORT_API gboolean +location_landmark_set_address (LocationLandmark *landmark, const LocationAddress *addr) +{ + g_return_val_if_fail(landmark, FALSE); + + if (landmark->addr) { + location_address_free (landmark->addr); + landmark->addr = NULL; + } + + if (addr) landmark->addr = location_address_copy (addr); + + return TRUE; + +} + +EXPORT_API gboolean +location_landmark_set_description (LocationLandmark *landmark, const gchar *desc) +{ + g_return_val_if_fail(landmark, FALSE); + + if (landmark->desc) { + g_free(landmark->desc); + landmark->desc = NULL; + } + + if (desc) landmark->desc = g_strdup (desc); + + return TRUE; +} + +EXPORT_API gboolean +location_landmark_set_timestamp (LocationLandmark *landmark, guint timestamp) +{ + g_return_val_if_fail(landmark, FALSE); + + landmark->timestamp = timestamp; + + return TRUE; + +} + +EXPORT_API gboolean +location_landmark_set_priority (LocationLandmark *landmark, guint priority) +{ + g_return_val_if_fail(landmark, FALSE); + + landmark->priority = priority; + + return TRUE; +} + +EXPORT_API gboolean +location_landmark_set_bounding_box (LocationLandmark *landmark, const LocationBoundary *bbox) +{ + g_return_val_if_fail(landmark, FALSE); + + if (landmark->bbox) { + location_boundary_free(landmark->bbox); + landmark->bbox = NULL; + } + + if (bbox) landmark->bbox = location_boundary_copy (bbox); + + return TRUE; +} + +EXPORT_API gboolean +location_landmark_set_author (LocationLandmark *landmark, const gchar *author) +{ + g_return_val_if_fail(landmark, FALSE); + + if (landmark->author) { + g_free(landmark->author); + landmark->author = NULL; + } + if (author) landmark->author = g_strdup (author); + + return TRUE; +} + +static void landmark_url_foreach_free (gpointer data) +{ + g_return_if_fail(data); + + LocationLandmarkUrl *url = (LocationLandmarkUrl *)data; + + location_landmark_url_free (url); +} + +static void landmark_foreach_url_copy (gpointer data, gpointer user_data) +{ + g_return_if_fail(data); + g_return_if_fail(user_data); + + LocationLandmarkUrl *url = (LocationLandmarkUrl *)data; + LocationLandmark *landmark = (LocationLandmark *) user_data; + + if(!url || !landmark) return; + + landmark->url = g_list_append(landmark->url, url); +} + +EXPORT_API gboolean +location_landmark_set_url (LocationLandmark *landmark, GList *url) +{ + g_return_val_if_fail(landmark, FALSE); + + if (landmark->url) { + g_list_free_full(landmark->url, landmark_url_foreach_free); + landmark->url = NULL; + } + + if (url) g_list_foreach (url, landmark_foreach_url_copy, landmark); + + return TRUE; +} + +static void landmark_foreach_copy_category (gpointer data, gpointer user_data) +{ + g_return_if_fail (data); + g_return_if_fail (user_data); + + gchar *category_name = (gchar *)data; + LocationLandmark *landmark = (LocationLandmark *) user_data; + + landmark->category = g_list_append (landmark->category, g_strdup(category_name)); +} + +static void landmark_free_category (gpointer data) +{ + g_return_if_fail (data); + + gchar * category_name = (gchar *)data; + + g_free (category_name); +} + +EXPORT_API gboolean +location_landmark_set_category (LocationLandmark *landmark, GList *category) +{ + g_return_val_if_fail(landmark, FALSE); + + if (landmark->category) { + g_list_free_full(landmark->category, landmark_free_category); + landmark->category = NULL; + } + + if (category) g_list_foreach ((GList*) category, landmark_foreach_copy_category, landmark); + + return TRUE; +} + +EXPORT_API gboolean +location_landmark_set_phone_number (LocationLandmark *landmark, const gchar *number) +{ + g_return_val_if_fail(landmark, FALSE); + g_return_val_if_fail(number, FALSE); + + if (landmark->phone_number) { + g_free(landmark->phone_number); + landmark->phone_number = NULL; + } + if (number) landmark->phone_number = g_strdup (number); + + return TRUE; +} + +EXPORT_API gboolean +location_landmark_set_property(LocationLandmark *landmark, gconstpointer key, gconstpointer value) +{ + g_return_val_if_fail(landmark, FALSE); + g_return_val_if_fail(key, FALSE); + if (!landmark->properties) return FALSE; + + if (value) { + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert(landmark->properties, re_key, re_val); + } + else g_hash_table_remove (landmark->properties, key); + + return TRUE; +} + +EXPORT_API gchar * +location_landmark_url_get_url_path (const LocationLandmarkUrl *url) +{ + g_return_val_if_fail (url, NULL); + + return url->path; +} + +EXPORT_API gchar * +location_landmark_url_get_description (const LocationLandmarkUrl *url) +{ + g_return_val_if_fail (url, NULL); + + return url->desc; +} + +EXPORT_API gboolean +location_landmark_url_set_url_path (LocationLandmarkUrl *url, const gchar *path) +{ + g_return_val_if_fail (url, FALSE); + + if (url->path) { + g_free(url->path); + url->path = NULL; + } + + if (path) url->path = g_strdup (path); + + return TRUE; +} + +EXPORT_API gboolean +location_landmark_url_set_description (LocationLandmarkUrl *url, const gchar *desc) +{ + g_return_val_if_fail (url, FALSE); + + if (url->desc) { + g_free(url->desc); + url->desc = NULL; + } + + if (desc) url->desc = g_strdup (desc); + + return TRUE; +} + +EXPORT_API LocationLandmarkUrl * +location_landmark_url_new (void) +{ + LocationLandmarkUrl *url = g_slice_new0 (LocationLandmarkUrl); + if(!url) return NULL; + + + return url; +} + +EXPORT_API void +location_landmark_url_free (LocationLandmarkUrl * url) +{ + g_return_if_fail (url); + + + location_landmark_url_set_url_path(url, NULL); + location_landmark_url_set_description(url, NULL); + + g_slice_free(LocationLandmarkUrl, url); +} + +EXPORT_API LocationLandmarkUrl * +location_landmark_url_copy (const LocationLandmarkUrl *url) +{ + g_return_val_if_fail(url, NULL); + + LocationLandmarkUrl *new_url = location_landmark_url_new(); + + location_landmark_url_set_url_path(new_url, location_landmark_url_get_url_path(url)); + location_landmark_url_set_description(new_url, location_landmark_url_get_description(url)); + + return new_url; +} + +EXPORT_API LocationLandmark * +location_landmark_new (void) +{ + LocationLandmark *landmark = g_slice_new0 (LocationLandmark); + if (!landmark) return NULL; + + landmark->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + + return landmark; +} + +EXPORT_API LocationLandmark * +location_landmark_copy (const LocationLandmark *landmark) +{ + g_return_val_if_fail (landmark, NULL); + + LocationLandmark *new_landmark = location_landmark_new(); + if (!new_landmark) return NULL; + + location_landmark_set_id(new_landmark, location_landmark_get_id(landmark)); + location_landmark_set_name (new_landmark, location_landmark_get_name (landmark)); + location_landmark_set_position (new_landmark, location_landmark_get_position(landmark)); + location_landmark_set_address (new_landmark, location_landmark_get_address (landmark)); + location_landmark_set_description (new_landmark, location_landmark_get_description(landmark)); + location_landmark_set_timestamp (new_landmark, location_landmark_get_timestamp(landmark)); + location_landmark_set_priority (new_landmark, location_landmark_get_priority(landmark)); + location_landmark_set_bounding_box (new_landmark, location_landmark_get_bounding_box(landmark)); + location_landmark_set_author (new_landmark, location_landmark_get_author(landmark)); + location_landmark_set_url(new_landmark, location_landmark_get_url(landmark)); + + return new_landmark; +} + +EXPORT_API void +location_landmark_free (LocationLandmark *landmark) +{ + g_return_if_fail (landmark); + + location_landmark_set_id(landmark, 0); + location_landmark_set_name (landmark, NULL); + location_landmark_set_position (landmark, NULL); + location_landmark_set_address (landmark, NULL); + location_landmark_set_description (landmark, NULL); + location_landmark_set_timestamp (landmark, 0); + location_landmark_set_priority (landmark, 0); + location_landmark_set_bounding_box (landmark, NULL); + location_landmark_set_author (landmark, NULL); + location_landmark_set_url(landmark, NULL); + + g_slice_free (LocationLandmark, landmark); +} diff --git a/location/map-service/location-landmark.h b/location/map-service/location-landmark.h new file mode 100644 index 0000000..401c801 --- /dev/null +++ b/location/map-service/location-landmark.h @@ -0,0 +1,147 @@ +/* + * libslp-location + * + * 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_LANDMARK_H__ +#define __LOCATION_LANDMARK_H__ + +#include + +G_BEGIN_DECLS + +/** + * @file location-landmark.h + * @brief This file contains the internal definitions and structures related to Landmark. + */ + +/** + * @addtogroup LocationMapServicePOI + * @{ + * @defgroup LocationMapServiceLandmark Location Landmark + * @brief This provides structure, enumeration and APIs for Landmark + * @addtogroup LocationMapServiceLandmark + * @{ + */ + +/** + * @brief Create a new Landmark + */ +LocationLandmark *location_landmark_new (void); + +/** + * @brief Copy the given Landmark + */ +LocationLandmark *location_landmark_copy (const LocationLandmark *landmark); + +/** + * @brief Free the given Landmark + */ +void location_landmark_free (LocationLandmark *landmark); + +/** + * @brief Get the ID of the given landmark + */ +guint location_landmark_get_id (const LocationLandmark *landmark); + +/** + * @brief Get the name of the given landmark + */ +gchar *location_landmark_get_name (const LocationLandmark *landmark); +/** + * @brief Get the position in the given landmark + */ +LocationPosition *location_landmark_get_position (const LocationLandmark *landmark); +/** + * @brief Get the address of the given landmark + */ +LocationAddress *location_landmark_get_address (const LocationLandmark *landmark); +/** + * @brief Get the description of the given landmark + */ +gchar *location_landmark_get_description (const LocationLandmark *landmark); +/** + * @brief Get the timestamp of the given landmark + */ +guint location_landmark_get_timestamp (const LocationLandmark *landmark); +/** + * @brief Get the priority of the given landmark + */ +guint location_landmark_get_priority (const LocationLandmark *landmark); +/** + * @brief Get the bounding box of the given landmark + */ +LocationBoundary *location_landmark_get_bounding_box (const LocationLandmark *landmark); +/** + * @brief Get the author of the given landmark + */ +gchar *location_landmark_get_author (const LocationLandmark *landmark); +/** + * @brief Get the list of urls of the given landmark + */ +GList *location_landmark_get_url (const LocationLandmark *landmark); +/** + * @brief Get the categories of the given landmark + */ +GList *location_landmark_get_category (const LocationLandmark *landmark); +/** + * @brief Get the phone number of the given landmark + */ +gchar *location_landmark_get_phone_number (const LocationLandmark *landmark); +/** + * @brief Get the property keys of the given landmark + */ +GList *location_landmark_get_property_key (const LocationLandmark *landmark); + +/** + * @brief Get the property data of the given landmark + */ +gconstpointer location_landmark_get_property (const LocationLandmark *landmark, gconstpointer key); + +/** + * @brief Create a new #LocationLandmarkUrl + */ +LocationLandmarkUrl * location_landmark_url_new (void); + +/** + * @brief Free a #LocationLandmarkUrl + */ +void location_landmark_url_free (LocationLandmarkUrl *url); + +/** + * @brief Copy a #LocationLandmarkUrl + */ +LocationLandmarkUrl *location_landmark_url_copy (const LocationLandmarkUrl *url); + +/** + * @brief Get the url path of the given #LocationLandmarkUrl + */ +gchar *location_landmark_url_get_url_path (const LocationLandmarkUrl *url); +/** + * @brief Get the url's description of the given #LocationLandmarkUrl + */ +gchar *location_landmark_url_get_description (const LocationLandmarkUrl *url); + +/** + * @} @} + */ + +G_END_DECLS + +#endif diff --git a/location/map-service/location-map-service-ext.h b/location/map-service/location-map-service-ext.h new file mode 100644 index 0000000..e7df5ae --- /dev/null +++ b/location/map-service/location-map-service-ext.h @@ -0,0 +1,40 @@ +/* + * libslp-location + * + * 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_MAP_SERVICE_EXT_H__ +#define __LOCATION_MAP_SERVICE_EXT_H__ + + +#include +#include +#include + +G_BEGIN_DECLS + +/** + * @file location-map-service-ext.h + * @brief This file contains the extensional headers. + */ + +G_END_DECLS + +#endif /* __LOCATION_MAP_SERVICE_EXT_H__ */ diff --git a/location/map-service/location-map-service.c b/location/map-service/location-map-service.c new file mode 100644 index 0000000..9bb0ebb --- /dev/null +++ b/location/map-service/location-map-service.c @@ -0,0 +1,327 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "location.h" +#include "location-log.h" +#include "location-setting.h" +#include "location-ielement.h" +#include "location-pref.h" +#include "map-service.h" + +LocationObject *g_map_service = NULL; + +//static LocationObject *poi = NULL; + +static gboolean +is_connected_network() +{ + gboolean is_connected = TRUE; + int net_state = 0; + + net_state = location_setting_get_int(VCONFKEY_NETWORK_STATUS); + + LOCATION_LOGW("net_state[%d]", net_state); + if(net_state == VCONFKEY_NETWORK_OFF) { + is_connected = FALSE; + } + + return is_connected; + +} + +EXPORT_API int +location_get_position_from_address (LocationObject *obj, + const LocationAddress *address, + GList **position_list, + GList **accuracy_list) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + return location_ielement_get_geocode (LOCATION_IELEMENT(g_map_service), address, position_list, accuracy_list); +} + +EXPORT_API int +location_get_position_from_freeformed_address (LocationObject *obj, + const gchar *address, + GList **position_list, + GList **accuracy_list) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + + return location_ielement_get_geocode_freeform (LOCATION_IELEMENT(g_map_service), address, position_list, accuracy_list); +} + +EXPORT_API int +location_get_address (LocationObject *obj, + LocationAddress **address, + LocationAccuracy **accuracy) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + + LocationPosition *position = NULL; + int ret = location_ielement_get_position(LOCATION_IELEMENT (obj), &position, accuracy); + if (LOCATION_ERROR_NONE != ret) return ret; + ret = location_ielement_get_reversegeocode (LOCATION_IELEMENT(g_map_service), position, address, accuracy); + location_position_free (position); + return ret; +} + +EXPORT_API int +location_get_address_from_position (LocationObject *obj, + const LocationPosition *position, + LocationAddress **address, + LocationAccuracy **accuracy) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + return location_ielement_get_reversegeocode (LOCATION_IELEMENT(g_map_service), position, address, accuracy); +} + +EXPORT_API int +location_get_position_from_address_async (LocationObject *obj, + const LocationAddress *address, + LocationPositionCB callback, + gpointer userdata) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + return location_ielement_get_geocode_async (LOCATION_IELEMENT(g_map_service), address, callback, userdata); +} + + +EXPORT_API int +location_get_position_from_freeformed_address_async (LocationObject *obj, + const gchar *address, + LocationPositionCB callback, + gpointer userdata) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + return location_ielement_get_geocode_freeform_async (LOCATION_IELEMENT(g_map_service), address, callback, userdata); +} + +EXPORT_API int +location_get_address_async (LocationObject *obj, + LocationAddressCB callback, + gpointer userdata) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + + LocationPosition *position = NULL; + LocationAccuracy *acc = NULL; + int ret = location_ielement_get_position(LOCATION_IELEMENT(obj), &position, &acc); + if (LOCATION_ERROR_NONE != ret) return ret; + ret = location_ielement_get_reversegeocode_async (LOCATION_IELEMENT(g_map_service), position, callback, userdata); + location_position_free (position); + return ret; +} + +EXPORT_API int +location_get_address_from_position_async (LocationObject *obj, + const LocationPosition *position, + LocationAddressCB callback, + gpointer userdata) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + + return location_ielement_get_reversegeocode_async (LOCATION_IELEMENT(g_map_service), position, callback, userdata); +} + +EXPORT_API int +location_search_poi (LocationObject *obj, + const LocationPOIFilter * filter, + const LocationPosition *position, + const LocationPOIPreference * pref, + LocationPOICB cb, gpointer user_data, guint * req_id) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + 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); + g_return_val_if_fail (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + + LocationPreference *svc_pref = location_get_map_service_pref (g_map_service); + + return location_ielement_search_poi (LOCATION_IELEMENT(g_map_service), filter, position, svc_pref, pref, cb, user_data, req_id); +} + +EXPORT_API int +location_search_poi_by_area (LocationObject *obj, + const LocationPOIFilter * filter, + const LocationBoundary * boundary, + const LocationPOIPreference * pref, + LocationPOICB cb, gpointer user_data, guint * req_id) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + 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 (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + + LocationPreference *svc_pref = location_get_map_service_pref (g_map_service); + + return location_ielement_search_poi_by_area (LOCATION_IELEMENT(g_map_service), filter, boundary, svc_pref, pref, cb, user_data, req_id); +} + +EXPORT_API int +location_search_poi_by_address (LocationObject *obj, const LocationPOIFilter * filter, + const LocationAddress * address, const LocationPOIPreference * pref, + LocationPOICB cb, gpointer user_data, guint * req_id) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (filter, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (address, 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 (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + + LocationPreference *svc_pref = location_get_map_service_pref (g_map_service); + + return location_ielement_search_poi_by_address (LOCATION_IELEMENT(g_map_service), filter, address, svc_pref, pref, cb, user_data, req_id); +} + +EXPORT_API int +location_search_poi_by_freeformed_address (LocationObject *obj, + const LocationPOIFilter * filter, + const gchar * address, + const LocationPOIPreference * pref, + LocationPOICB cb, gpointer user_data, guint * req_id) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (filter, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (address, 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 (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + + LocationPreference *svc_pref = location_get_map_service_pref (g_map_service); + + return location_ielement_search_poi_by_freeform (LOCATION_IELEMENT(g_map_service), filter, address, svc_pref, pref, cb, user_data, req_id); +} + +EXPORT_API int +location_cancel_poi_request (LocationObject *obj, guint req_id) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (req_id, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + + return location_ielement_cancel_poi_request (LOCATION_IELEMENT(g_map_service), req_id); +} + +EXPORT_API int +location_request_route (LocationObject *obj, LocationPosition *origin, LocationPosition *destination, + GList *waypoint, const LocationRoutePreference * pref, + LocationRouteCB cb, gpointer user_data, guint * req_id) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (origin, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (destination, 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 (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + + LocationPreference *svc_pref = location_get_map_service_pref (g_map_service); + + return location_ielement_request_route (LOCATION_IELEMENT(g_map_service), origin, destination, + waypoint, svc_pref, pref, cb, user_data, req_id); +} + +EXPORT_API int +location_cancel_route_request (LocationObject *obj, guint req_id) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (g_map_service, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + + return location_ielement_cancel_route_request (LOCATION_IELEMENT(g_map_service), req_id); +} + +EXPORT_API gboolean +location_is_supported_map_provider_capability (LocationObject *obj, LocationMapServiceType type) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (g_map_service, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + + return location_ielement_is_supported_map_provider_capability (LOCATION_IELEMENT(g_map_service), type); +} + +EXPORT_API int +location_get_map_provider_capability_key (LocationObject *obj, LocationMapServiceType type, GList **key) +{ + g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (key, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (g_map_service, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED); + + return location_ielement_get_map_provider_capability_key (LOCATION_IELEMENT(g_map_service), type, key); +} + +EXPORT_API LocationPreference * +location_get_map_service_pref (LocationObject *obj) +{ + g_return_val_if_fail (obj, NULL); + g_return_val_if_fail (g_map_service, NULL); + + return map_service_get_pref (g_map_service); +} + +EXPORT_API gboolean +location_set_map_service_pref (LocationObject *obj, LocationPreference *pref) +{ + g_return_val_if_fail (obj, FALSE); + g_return_val_if_fail (pref, FALSE); + g_return_val_if_fail (g_map_service, FALSE); + + return map_service_set_pref (g_map_service, pref); +} diff --git a/location/map-service/location-map-service.h b/location/map-service/location-map-service.h new file mode 100644 index 0000000..73421a4 --- /dev/null +++ b/location/map-service/location-map-service.h @@ -0,0 +1,1389 @@ +/* + * libslp-location + * + * 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_MAP_SERVICE_H__ +#define __LOCATION_MAP_SERVICE_H__ + + +#include +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +/** + * @file location-map-service.h + * @brief This file contains the Location API and related structure and enumeration. + */ +/** + * @addtogroup LocationFW + * @{ + * @defgroup LocationMapService Location Map Service API + * @brief This sub module provides the Location Map Service API. + * @addtogroup LocationMapService + * @{ + */ + +/** + * @brief + * Get current position information with estimate of the accuracy by using given address information. + * @remarks Out parameters are should be freed. + * @pre + * #location_init should be called before.\n + * Calling application must have an active data connection. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [in] + * address - a #LocationAddress + * @param [out] + * position_list - a list of #LocationPosition + * @param [out] + * accuracy_list - a list of #LocationAccuracy + * @return int + * @retval 0 Success. + * + * Please refer #LocationError for more information. + * @see + * location_get_position_from_address_async\n + * @par Example + * @code +#include +#include + +static void PrintPos (gpointer data, gpointer user_data) +{ + LocationPosition *pos = (LocationPosition *)data; + + if (pos) { + g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude); + location_position_free (pos); + } +} + +static void PrintAcc (gpointer data, gpointer user_data) +{ + LocationAccuracy *acc = (LocationAccuracy *)data; + + if (acc) { + g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + location_accuracy_free (acc); + } + +} + +static void PrintPos (gpointer data, gpointer user_data) +{ + LocationPosition *pos = (LocationPosition *)data; + + if (pos) { + g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude); + location_position_free (pos); + } +} + +static void PrintAcc (gpointer data, gpointer user_data) +{ + LocationAccuracy *acc = (LocationAccuracy *)data; + + if (acc) { + g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + location_accuracy_free (acc); + } +} + +int main (int argc, char *argv[]) +{ + LocationObject *loc = NULL; + int ret = LOCATION_ERROR_NONE; + + location_init (); + loc = location_new (LOCATION_METHOD_GPS); + if(!loc){ + g_debug("location_new failed"); + return -1; + } + + GList *pos_list = NULL; + GList *acc_list = NULL; + LocationAddress *addr = NULL; + + addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113"); + if (LOCATION_ERROR_NONE == location_get_position_from_address(loc, addr, &pos_list, &acc_list)) { + + } else g_warning ("SYNC>> position from address> failed"); + location_address_free (addr); + g_list_foreach (pos_list, PrintPos, NULL); + g_list_foreach (acc_list, PrintAcc, NULL); + g_list_free (pos_list); + g_list_free (acc_list); + location_free (loc); + return 0; +} + * @endcode + */ +int location_get_position_from_address (LocationObject *obj, const LocationAddress *address, GList **position_list, GList **accuracy_list); + +/** + * @brief + * Get current position information asynchronously with estimate of the accuracy by using given address information. + * @remarks None. + * @pre + * #location_init should be called before.\n + * Calling application must have glib or ecore main loop.\n + * Calling application must have an active data connection. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [in] + * address - a #LocationAddress + * @param [in] + * callback - A pointer of function which will be called after position is gained or when an error occurs. + * @param [in] + * userdata - data to pass to function + * @return int + * @retval 0 Success. + * + * Please refer #LocationError for more information. + * @see + * location_get_position_from_address\n + * @par Example + * @code +#include +#include + +static void PrintPos (gpointer data, gpointer user_data) +{ + LocationPosition *pos = (LocationPosition *)data; + + if (pos) { + g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude); + } +} + +static void PrintAcc (gpointer data, gpointer user_data) +{ + LocationAccuracy *acc = (LocationAccuracy *)data; + + if (acc) { + g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + } +} +static void +cb_position_from_address (LocationError error, GList *position_list, GList *accuracy_list, gpointer userdata) +{ + if (position_list && accuracy_list) { + g_list_foreach (position_list, PrintPos); + g_list_foreach (accuracy_list, PrintAcc); + } +} + +void get_position_from_address(LocationObject* loc) +{ + LocationAddress *addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113"); + //Calling application must have an active data connection before using this function. + if (LOCATION_ERROR_NONE == location_get_position_from_address_async(loc, addr, cb_position_from_address, loc)) + g_debug("location_get_position_from_address_async() success"); + else g_warning ("location_get_position_from_address_async() failed"); + location_address_free (addr); +} + * @endcode + */ +int location_get_position_from_address_async (LocationObject *obj, const LocationAddress *address, LocationPositionCB callback, gpointer userdata); + +/** + * @brief + * Get current position information with estimate of the accuracy by using given free-formed address string. + * @remarks Out parameters are should be freed. + * @pre + * #location_init should be called before.\n + * Calling application must have an active data connection. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [in] + * address - Free-formed address string to be used + * @param [out] + * position_list - a list of #LocationPosition + * @param [out] + * accuracy_list - a list of #LocationAccuracy + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @see + * location_get_position_from_freeformed_address_async\n + * @par Example + * @code +#include +#include + +static void PrintPos (gpointer data, gpointer user_data) +{ + LocationPosition *pos = (LocationPosition *)data; + + if (pos) { + g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude); + location_position_free (pos); + } +} + +static void PrintAcc (gpointer data, gpointer user_data) +{ + LocationAccuracy *acc = (LocationAccuracy *)data; + + if (acc) { + g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + location_accuracy_free (acc); + } +} + +static void PrintPos (gpointer data, gpointer user_data) +{ + LocationPosition *pos = (LocationPosition *)data; + + if (pos) { + g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude); + location_position_free (pos); + } +} + +static void PrintAcc (gpointer data, gpointer user_data) +{ + LocationAccuracy *acc = (LocationAccuracy *)data; + + if (acc) { + g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + location_accuracy_free (acc); + } +} + +int main (int argc, char *argv[]) +{ + LocationObject *loc = NULL; + int ret = LOCATION_ERROR_NONE; + + location_init (); + loc = location_new (LOCATION_METHOD_GPS); + if(!loc){ + g_debug("location_new failed"); + return -1; + } + + GList *pos_list = NULL; + GList *acc_list = NULL; + char* addr_str = g_strdup("4 N 2nd Street 95113"); + + //Calling application must have an active data connection before using this function. + if (LOCATION_ERROR_NONE == location_get_position_from_freeformed_address(loc, addr_str, &pos_list, &acc_list)) { + g_list_foreach (pos_list, PrintPos, NULL); + g_list_foreach (acc_list, PrintAcc, NULL); + g_list_free (pos_list); + g_list_free (acc_list); + } else g_warning ("SYNC>> position from freeformed address> failed"); + g_free(addr_str); + + location_free (loc); + return 0; +} + * @endcode + */ +int location_get_position_from_freeformed_address (LocationObject *obj, const gchar *address, GList **position_list, GList **accuracy_list); + +/** + * @brief + * Get current position information asynchronously with estimate of the accuracy by using given free-formed address string. + * @remarks None. + * @pre + * #location_init should be called before.\n + * Calling application must have glib or ecore main loop.\n + * Calling application must have an active data connection. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [in] + * address - Free-formed address string to be used + * @param [in] + * callback - A pointer of function which will be called after position is gained or when an error occurs. + * @param [in] + * userdata - data to pass to function + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @see + * location_get_position_from_freeformed_address\n + * @par Example + * @code +#include +#include + +static void PrintPos (gpointer data, gpointer user_data) +{ + LocationPosition *pos = (LocationPosition *)data; + + if (pos) { + g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude); + } +} + +static void PrintAcc (gpointer data, gpointer user_data) +{ + LocationAccuracy *acc = (LocationAccuracy *)data; + + if (acc) { + g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + } +} + +static void +cb_position_from_freeformed_address (LocationError error, GList *position_list, GList *accuracy_list, gpointer userdata) +{ + if (position_list && accuracy_list) { + g_list_foreach (position_list, PrintPos); + g_list_foreach (accuracy_list, PrintAcc); + } +} + +void get_position_from_address(LocationObject* loc) +{ + gchar *addr_str = g_strdup("4 N 2nd Street 95113"); + //Calling application must have an active data connection before using this function. + if (LOCATION_ERROR_NONE == location_get_position_from_freeformed_address_async(loc, addr_str, cb_position_from_freeformed_address, loc)) + g_debug("location_get_position_from_freeformed_address_async() success"); + else g_warning ("location_get_position_from_freeformed_address_async() failed"); + g_free(addr_str); + +} + * @endcode + */ +int location_get_position_from_freeformed_address_async (LocationObject *obj, const gchar *address, LocationPositionCB callback, gpointer userdata); + +/** + * @brief + * Get current address information with estimate of the accuracy by using current position. + * @remarks Out parameters are should be freed. + * @pre + * #location_init should be called before.\n + * #location_start should be called before.\n + * Calling application must have an active data connection. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [out] + * address - a new #LocationAddress + * @param [out] + * accuracy - a new #LocationAccuracy + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @see + * location_get_address_async\n + * @par Example + * @code +#include +#include +static GMainLoop *loop = NULL; + +static void cb_service_enabled (GObject *self, guint status, gpointer userdata) +{ + g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata); + + LocationAddress *addr = NULL; + LocationAccuracy *acc = NULL; + LocationObject *loc = (LocationObject*)userdata; + + // This function works properly after service is enabled. + //Calling application must have an active data connection before using this function. + if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) { + g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s", + addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + location_address_free(addr); + location_accuracy_free(acc); + } else g_warning ("SYNC>> Current address> failed"); +} + +int main (int argc, char *argv[]) +{ + LocationObject *loc = NULL; + gulong handler_id = 0; + int ret = LOCATION_ERROR_NONE; + + location_init (); + + loop = g_main_loop_new (NULL, TRUE); + + loc = location_new (LOCATION_METHOD_GPS); + if(!loc){ + g_debug("location_new failed"); + return -1; + } + + handler_id = g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc); + location_start (loc); + g_main_loop_run (loop); + + g_signal_handler_disconnect(loc, handler_id); + location_stop (loc); + location_free (loc); + + return 0; +} + * @endcode + */ +int location_get_address (LocationObject *obj, LocationAddress **address, LocationAccuracy **accuracy); + +/** + * @brief + * Get current address information asynchronously with estimate of the accuracy by using current position. + * @remarks None. + * @pre + * #location_init should be called before.\n + * #location_start should be called before.\n + * Calling application must have glib or ecore main loop.\n + * Calling application must have an active data connection. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [in] + * callback - A pointer of function which will be called after address is gained or when an error occurs. + * @param [in] + * userdata - data to pass to function + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @see + * location_get_address\n + * @par Example + * @code +#include +#include +static GMainLoop *loop = NULL; + +static void +cb_address (LocationError error, LocationAddress *addr, LocationAccuracy *acc, gpointer userdata) +{ + g_debug ("ASYNC>> location_get_address_async> %s %s %s %s %s %s %s", + addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); +} + +static void cb_service_enabled (GObject *self, guint status, gpointer userdata) +{ + g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata); + + LocationObject *loc = (LocationObject*)userdata; + // This function works properly after service is enabled. + //Calling application must have an active data connection before using this function. + if (LOCATION_ERROR_NONE == location_get_address_async(loc, cb_address, loc)) + g_debug("location_get_address_async() success"); + else g_warning ("location_get_address_async() failed"); +} + + +int main (int argc, char *argv[]) +{ + LocationObject *loc = NULL; + gulong handler_id = 0; + int ret = LOCATION_ERROR_NONE; + + location_init (); + + loop = g_main_loop_new (NULL, TRUE); + + loc = location_new (LOCATION_METHOD_GPS); + if(!loc){ + g_debug("location_new failed"); + return -1; + } + + handler_id = g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc); + location_start (loc); + g_main_loop_run (loop); + + g_signal_handler_disconnect(loc, handler_id); + location_stop (loc); + location_free (loc); + + return 0; +} + * @endcode + */ +int location_get_address_async (LocationObject *obj, LocationAddressCB callback, gpointer userdata); + +/** + * @brief + * Get current address information with estimate of the accuracy by using given position information. + * @remarks Out parameters are should be freed. + * @pre + * #location_init should be called before.\n + * Calling application must have an active data connection. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [in] + * position - a #LocationPosition + * @param [out] + * address - a new #LocationAddress + * @param [out] + * accuracy - a new #LocationAccuracy + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @see + * location_get_address_from_position_async\n + * @par Example + * @code +#include +#include +static GMainLoop *loop = NULL; + +int +main (int argc, char *argv[]) +{ + LocationObject *loc = NULL; + int ret = LOCATION_ERROR_NONE; + + location_init (); + + loop = g_main_loop_new (NULL, TRUE); + + loc = location_new (LOCATION_METHOD_GPS); + if(!loc){ + g_debug("location_new failed"); + return -1; + } + + LocationPosition *pos = NULL; + LocationAccuracy *acc = NULL; + LocationAddress *addr = NULL; + + //Calling application must have an active data connection before using this function. + pos = location_position_new (0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX); + if (LOCATION_ERROR_NONE == location_get_address_from_position(loc, pos, &addr, &acc)) { + g_debug ("SYNC>> address from position> %s %s %s %s %s %s %s", + addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + location_address_free(addr); + location_accuracy_free(acc); + } else g_warning ("SYNC>> address from position> failed"); + location_position_free (pos); +} + * @endcode + */ +int location_get_address_from_position (LocationObject *obj, const LocationPosition *position, LocationAddress **address, LocationAccuracy **accuracy); + +/** + * @brief + * Get current address information asynchronously with estimate of the accuracy by using given position information. + * @remarks None. + * @pre + * #location_init should be called before.\n + * Calling application must have glib or ecore main loop.\n + * Calling application must have an active data connection. + * @post None. + * @param [in] + * obj - a #LocationObject created by #location_new + * @param [in] + * position - a #LocationPosition + * @param [in] + * callback - A pointer of function which will be called after address is gained or when an error occurs. + * @param [in] + * userdata - data to pass to function + * @return int + * @retval 0 Success + * + * Please refer #LocationError for more information. + * @see + * location_get_address_from_position\n + * @par Example + * @code +#include +#include +static GMainLoop *loop = NULL; + +static void +cb_address_from_position (LocationError error, LocationAddress *addr, LocationAccuracy *acc, gpointer userdata) +{ + g_debug ("ASYNC>> location_get_address_from_position_async> %s %s %s %s %s %s %s", + addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); +} + +void get_address_from_position(LocationObject* loc) +{ + LocationPosition *pos = location_position_new (0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX); + //Calling application must have an active data connection before using this function. + if (LOCATION_ERROR_NONE == location_get_address_from_position_async(loc, pos, cb_address_from_position, loc)) + g_debug("location_get_address_from_position_async() success"); + else g_warning ("location_get_address_from_position_async() failed"); + location_position_free (pos); +} + * @endcode + */ +int location_get_address_from_position_async (LocationObject *obj, const LocationPosition *position, LocationAddressCB callback, gpointer userdata); + +/** + * @brief Request a search service from service provider. + * @remarks refer #LocationLandmark + * @pre #location_init should be called before.\n + * #location_poi_pref_new should be set before. + * @post None. + * @param [in] obj - a #LocationObject created by #location_new + * @param [in] filter - a #LocaitonPOIFilter created by #location_poi_filter_new + * @param [in] position - a #LocationPosition + * @param [in] pref - a #LocationPOIPreference created by #location_poi_pref_new + * @param [in] cb - #LocationPOICB + * @param [in] user_data - data to pass to function + * @param [out] req_id - a guint + * @return int + * @retval 0 Success + * Please refer #LocationError for more information. + * @par Example + * @code +#include +#include + +static GMainLoop *loop = NULL; + +void PrintLandmarkCb (gpointer data, gpointer user_data) +{ + g_return_if_fail (data); + + LocationLandmark *landmark = (LocationLandmark *)data; + + g_debug ("id[%d], Priority[%d], Name:[%s], Author[%s], Phone[%s], Category[%s]\n", location_landmark_get_id (landmark), + location_landmark_get_priority(landmark), + location_landmark_get_name(landmark), + location_landmark_get_author(landmark), + location_landmark_get_phone_number(landmark), + location_landmark_get_category(landmark)); +} + +static void poi_cb(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata) +{ + if (error != LOCATION_ERROR_NONE || landmark_list == NULL) { + g_debug ("Fail to get poi. Error[%d], ErrCode[%s], ErrMsg[%s]", error, error_code, error_msg); + return; + } + g_list_foreach (landmark_list, PrintLandmarkCb, NULL); +} + +void search_poi(LocationObject* loc) +{ + int ret = 0; + guint req_id = 0; + LocationPosition *pos = location_position_new (0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX); + LocationPOIFilter *filter = location_poi_filter_new(); + LocationPOIPreference *pref = location_poi_pref_new(); + + location_poi_filter_set(filter, "CATEGORY", "restaurant"); + + location_poi_pref_set_max_result(pref, 5); + location_poi_pref_set_sort_by(pref, "name"); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); + + ret = location_search_poi (loc, filter, pos, pref, poi_cb, loc, &req_id); + if (ret != LOCATION_ERROR_NONE) { + g_debug("Fail to get poi. Error[%d]", ret); + } + + location_poi_filter_free(filter); + location_poi_pref_free(pref); + location_position_free(pos); + +} + * @endcode + */ +int location_search_poi (LocationObject *obj, const LocationPOIFilter * filter, const LocationPosition *position, const LocationPOIPreference * pref, LocationPOICB cb, gpointer user_data, guint * req_id); + +/** + * @brief Request a search service with area filter from service provider. + * @remarks refer #LocationLandmark + * @pre #location_init should be called before.\n + * #location_poi_pref_new should be set before. + * @post None. + * @param [in] obj - a #LocationObject created by #location_new + * @param [in] filter - a #LocaitonPOIFilter created by #location_poi_filter_new + * @param [in] boundary - a #LocationBoundary + * @param [in] pref - a #LocationPOIPreference created by #location_poi_pref_new + * @param [in] cb - #LocationPOICB + * @param [in] user_data - data to pass to function + * @param [out] req_id - a guint + * @return int + * @retval 0 Success + * Please refer #LocationError for more information. + * @par Example + * @code +#include +#include + +static GMainLoop *loop = NULL; + +void PrintLandmarkCb (gpointer data, gpointer user_data) +{ + g_return_if_fail (data); + + LocationLandmark *landmark = (LocationLandmark *)data; + + g_debug ("id[%d], Priority[%d], Name:[%s], Author[%s], Phone[%s], Category[%s]\n", location_landmark_get_id (landmark), + location_landmark_get_priority(landmark), + location_landmark_get_name(landmark), + location_landmark_get_author(landmark), + location_landmark_get_phone_number(landmark), + location_landmark_get_category(landmark)); +} + +static void poi_cb(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata) +{ + if (error != LOCATION_ERROR_NONE || landmark_list == NULL) { + g_debug ("Fail to get poi. Error[%d], ErrCode[%s], ErrMsg[%s]", error, error_code, error_msg); + return; + } + g_list_foreach (landmark_list, PrintLandmarkCb, NULL); +} + +void search_poi(LocationObject* loc) +{ + int ret = 0; + guint req_id = 0; + + LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX); + LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX); + LocationBoundary *bbox = location_boundary_new_for_rect (lt, rb); + LocationPOIFilter *filter = location_poi_filter_new(); + LocationPOIPreference *pref = location_poi_pref_new(); + + location_poi_filter_set(filter, "CATEGORY", "restaurant"); + + location_poi_pref_set_max_result(pref, 5); + location_poi_pref_set_sort_by(pref, "name"); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); + + ret = location_search_poi_by_area (loc, filter, bbox, pref, poi_cb, loc, &req_id); + if (ret != LOCATION_ERROR_NONE) { + g_debug("Fail to get poi. Error[%d]", ret); + } + + location_poi_filter_free(filter); + location_poi_pref_free(pref); + location_boundary_free (bbox); +} + * @endcode + */ +int location_search_poi_by_area (LocationObject *obj, const LocationPOIFilter * filter, const LocationBoundary * boundary, const LocationPOIPreference * pref, LocationPOICB cb, gpointer user_data, guint * req_id); + +/** + * @brief Request a search service with address filter from service provider. + * @remarks refer #LocationLandmark + * @pre #location_init should be called before.\n + * #location_poi_pref_new should be set before. + * @post None. + * @param [in] obj - a #LocationObject created by #location_new + * @param [in] filter - a #LocaitonPOIFilter created by #location_poi_filter_new + * @param [in] address - a #LocationAddress + * @param [in] pref - a #LocationPOIPreference created by #location_poi_pref_new + * @param [in] cb - #LocationPOICB + * @param [in] user_data - data to pass to function + * @param [out] req_id - a guint + * @return int + * @retval 0 Success + * Please refer #LocationError for more information. + * @par Example + * @code +#include +#include + +static GMainLoop *loop = NULL; + +void PrintLandmarkCb (gpointer data, gpointer user_data) +{ + g_return_if_fail (data); + + LocationLandmark *landmark = (LocationLandmark *)data; + + g_debug ("id[%d], Priority[%d], Name:[%s], Author[%s], Phone[%s], Category[%s]\n", location_landmark_get_id (landmark), + location_landmark_get_priority(landmark), + location_landmark_get_name(landmark), + location_landmark_get_author(landmark), + location_landmark_get_phone_number(landmark), + location_landmark_get_category(landmark)); +} + +static void poi_cb(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata) +{ + if (error != LOCATION_ERROR_NONE || landmark_list == NULL) { + g_debug ("Fail to get poi. Error[%d], ErrCode[%s], ErrMsg[%s]", error, error_code, error_msg); + return; + } + g_list_foreach (landmark_list, PrintLandmarkCb, NULL); +} + +void search_poi(LocationObject* loc) +{ + int ret = 0; + guint req_id = 0; + + LocationAddress *addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113"); + LocationPOIFilter *filter = location_poi_filter_new(); + LocationPOIPreference *pref = location_poi_pref_new(); + + location_poi_filter_set(filter, "CATEGORY", "restaurant"); + + location_poi_pref_set_max_result(pref, 5); + location_poi_pref_set_sort_by(pref, "name"); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); + + ret = location_search_poi_by_address (loc, filter, addr, pref, poi_cb, loc, &req_id); + if (ret != LOCATION_ERROR_NONE) { + g_debug("Fail to get poi. Error[%d]", ret); + } + + location_poi_filter_free(filter); + location_poi_pref_free(pref); + location_address_free (addr); +} + * @endcode + */ +int location_search_poi_by_address (LocationObject *obj, const LocationPOIFilter * filter, const LocationAddress * addr, const LocationPOIPreference * pref, LocationPOICB cb, gpointer user_data, guint * req_id); + +/** + * @brief Request a search service with area filter from service provider. + * @remarks refer #LocationLandmark + * @pre #location_init should be called before.\n + * #location_poi_pref_new should be set before. + * @post None. + * @param [in] obj - a #LocationObject created by #location_new + * @param [in] filter - a #LocaitonPOIFilter created by #location_poi_filter_new + * @param [in] address - a freeformed address + * @param [in] pref - a #LocationPOIPreference created by #location_poi_pref_new + * @param [in] cb - #LocationPOICB + * @param [in] user_data - data to pass to function + * @param [out] req_id - a guint + * @return int + * @retval 0 Success + * Please refer #LocationError for more information. + * @par Example + * @code +#include +#include + +static GMainLoop *loop = NULL; + +void PrintLandmarkCb (gpointer data, gpointer user_data) +{ + g_return_if_fail (data); + + LocationLandmark *landmark = (LocationLandmark *)data; + + g_debug ("id[%d], Priority[%d], Name:[%s], Author[%s], Phone[%s], Category[%s]\n", location_landmark_get_id (landmark), + location_landmark_get_priority(landmark), + location_landmark_get_name(landmark), + location_landmark_get_author(landmark), + location_landmark_get_phone_number(landmark), + location_landmark_get_category(landmark)); +} + +static void poi_cb(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata) +{ + if (error != LOCATION_ERROR_NONE || landmark_list == NULL) { + g_debug ("Fail to get poi. Error[%d], ErrCode[%s], ErrMsg[%s]", error, error_code, error_msg); + return; + } + g_list_foreach (landmark_list, PrintLandmarkCb, NULL); +} + +void search_poi(LocationObject* loc) +{ + int ret = 0; + guint req_id = 0; + + gchar *addr = g_strdup("4 N 2nd Street 95113"); + LocationPOIFilter *filter = location_poi_filter_new(); + LocationPOIPreference *pref = location_poi_pref_new(); + + location_poi_filter_set(filter, "CATEGORY", "restaurant"); + + location_poi_pref_set_max_result(pref, 5); + location_poi_pref_set_sort_by(pref, "name"); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); + + ret = location_search_poi_by_freeformed_address (loc, filter, addr, pref, poi_cb, loc, &req_id); + if (ret != LOCATION_ERROR_NONE) { + g_debug("Fail to get poi. Error[%d]", ret); + } + + location_poi_filter_free(filter); + location_poi_pref_free(pref); + g_free (addr); +} + * @endcode + */ +int location_search_poi_by_freeformed_address (LocationObject *obj, const LocationPOIFilter * filter, const gchar * address, const LocationPOIPreference * pref, LocationPOICB cb, gpointer user_data, guint * req_id); + +/** + * @brief Cancel the previous poi search. + * @remarks refer #LocationLandmark + * @pre #location_search_poi should be called before. + * @post None. + * @param [in] obj - a #LocationObject created by #location_new + * @param [in] req_id - a poi request id returned by location_search_poi + * @return int + * @retval 0 Success + * Please refer #LocationError for more information. + * @par Example + * @code +#include +#include + +static GMainLoop *loop = NULL; + +void PrintLandmarkCb (gpointer data, gpointer user_data) +{ + g_return_if_fail (data); + + LocationLandmark *landmark = (LocationLandmark *)data; + + g_debug ("id[%d], Priority[%d], Name:[%s], Author[%s], Phone[%s], Category[%s]\n", location_landmark_get_id (landmark), + location_landmark_get_priority(landmark), + location_landmark_get_name(landmark), + location_landmark_get_author(landmark), + location_landmark_get_phone_number(landmark), + location_landmark_get_category(landmark)); +} + +static void poi_cb(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata) +{ + if (error != LOCATION_ERROR_NONE || landmark_list == NULL) { + g_debug ("Fail to get poi. Error[%d], ErrCode[%s], ErrMsg[%s]", error, error_code, error_msg); + return; + } + g_list_foreach (landmark_list, PrintLandmarkCb, NULL); +} + +void search_poi(LocationObject* loc) +{ + int ret = 0; + guint req_id = 0; + + gchar *addr = g_strdup("4 N 2nd Street 95113"); + LocationPOIFilter *filter = location_poi_filter_new(); + LocationPOIPreference *pref = location_poi_pref_new(); + + location_poi_filter_set(filter, "CATEGORY", "restaurant"); + + location_poi_pref_set_max_result(pref, 5); + location_poi_pref_set_sort_by(pref, "name"); + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); + + ret = location_search_poi (loc, filter, addr, pref, poi_cb, loc, &req_id); + if (ret != LOCATION_ERROR_NONE) { + g_debug("Fail to get poi. Error[%d]", ret); + } + + ret = location_cancel_poi_request (loc, req_id); + if (ret != LOCATION_ERROR_NONE) { + g_debug("Fail to cancel poi request. Err[%d]", ret); + } + + location_poi_filter_free(filter); + location_poi_pref_free(pref); + g_free (addr); +} + * @endcode + */ +int location_cancel_poi_request (LocationObject *obj, guint req_id); + +/** + * @brief Request a route service from service provider. + * @remarks refer #LocationRoute, #LocationRouteSegment and #LocationRouteStep + * @pre #location_new should be called before. + * @post None. + * @param [in] obj - a #LocationObject created by #location_new + * @param [in] origin - a #LocationPosition + * @param [in] destination - a #LocationPosition + * @param [in] waypoint - a list of #LocationPosition + * const LocationRoutePreference * pref, LocationRouteCB cb, gpointer user_data, guint * req_id); + * @param [in] pref - a #LocationRoutePreference created by #location_route_pref_new + * @param [in] cb - a #LocationRouteCB + * @param [in] user_data - a gpointer + * @param [out] req_id - a guint + * @return int + * @retval 0 Success + * Please refer #LocationError for more information. + * @par Example + * @code +#include +#include + +static void free_waypoint (gpointer data) +{ + LocationPosition *pos = (LocationPosition *)data; + + if (pos) location_position_free(pos); +} + +static void __print_route_step (gpointer data, gpointer user_data) +{ + g_printf("+++Step begin\n"); + LocationRouteStep *step = (LocationRouteStep *)data; + + const LocationPosition *start = location_route_step_get_start_point(step); + gdouble start_lat = 0; + gdouble start_lon = 0; + if (start) { + start_lat = start->latitude; + start_lon = start->longitude; + } else { + g_printf("Step start position NULL\n"); + } + const LocationPosition *end = location_route_step_get_end_point(step); + gdouble end_lat = 0; + gdouble end_lon = 0; + if (end) { + end_lat = end->latitude; + end_lon = end->longitude; + } else { + g_printf("Step end postion NULL\n"); + } + const gchar *inst = location_route_step_get_instruction(step); + + g_printf("Step: start(%f/%f), end(%f/%f), instruction(%s)\n", start_lat, start_lon, end_lat, end_lon, inst); + + g_printf("---Step end\n"); +} + +static void print_route_segment (gpointer data, gpointer user_data) +{ + g_printf("++Segment begin\n"); + LocationRouteSegment *seg = (LocationRouteSegment *)data; + gdouble seg_dist = location_route_segment_get_distance(seg); + glong seg_duration = location_route_segment_get_duration(seg); + const LocationPosition *start = location_route_segment_get_start_point(seg); + gdouble start_lat = 0; + gdouble start_lon = 0; + if (start) { + start_lat = start->latitude; + start_lon = start->longitude; + } else { + g_printf("Segment start postion NULL\n"); + } + const LocationPosition *end = location_route_segment_get_end_point(seg); + gdouble end_lat = 0; + gdouble end_lon = 0; + if (end) { + end_lat = end->latitude; + end_lon = end->longitude; + } else { + g_printf("Segment end postion NULL\n"); + } + g_printf("Segment info: Distance[%f], Duration[%ld], start(%f/%f), end(%f/%f)\n", seg_dist, seg_duration, + start_lat, start_lon, end_lat, end_lon); + + GList *step_list = location_route_segment_get_route_step(seg); + GList *tmp_list = (GList *)step_list; + if (tmp_list) { + g_list_foreach(tmp_list, print_route_step, NULL); + } + g_printf("--Segment end\n"); +} + + +static void print_route_list (gpointer data, gpointer user_data) +{ + g_printf("+Route begin\n"); + LocationRoute *route = (LocationRoute *)data; + + const LocationPosition *start = location_route_get_origin(route); + gdouble start_lat = 0; + gdouble start_lon = 0; + if (start) { + start_lat = start->latitude; + start_lon = start->longitude; + } else { + g_printf("Route start position NULL\n"); + } + const LocationPosition *end = location_route_get_destination(route); + gdouble end_lat = 0; + gdouble end_lon = 0; + if (end) { + end_lat = end->latitude; + end_lon = end->longitude; + } else { + g_printf("Route end position NULL\n"); + } + g_printf("Route: start(%f/%f), end(%f/%f)\n", start_lat, start_lon, end_lat, end_lon); + + gdouble distance = location_route_get_total_distance(route); + const gchar *dis_unit = location_route_get_distance_unit(route); + glong duration = location_route_get_total_duration(route); + const LocationBoundary *bound = location_route_get_bounding_box(route); + if (bound && bound->type == LOCATION_BOUNDARY_RECT) { + g_printf("RECT left top[%f-%f], right bottom[%f-%f]\n", bound->rect.left_top->latitude, bound->rect.left_top->longitude, + bound->rect.right_bottom->latitude, bound->rect.right_bottom->longitude); + } else { + g_printf("route boundary not exist, or not RECT\n"); + } + g_printf ("Distance[%f], Distance unit[%s], Duration[%ld]\n", distance, dis_unit, duration); + + GList *seg_list = location_route_get_route_segment(route); + if (seg_list) { + g_list_foreach(seg_list, print_route_segment, NULL); + } + + g_printf("-Route end\n"); +} + +static void cb_route(LocationError error, guint req_id, GList * route_list, gchar * error_code, gchar * error_msg, gpointer userdata) +{ + if (error != LOCATION_ERROR_NONE) { + g_printf("Failed :%d\n", error); + return; + } + + g_printf("Success, poi_list[0x%x] user_data[0x%x] req_id[%d]\n", (unsigned int)route_list, (unsigned int)userdata, req_id); + g_list_foreach (route_list, print_route_list, NULL); + + if (error_code && error_msg) { + g_printf("cb_route: error_code[%s], error_msg[%s]\n", error_code, error_msg); + } +} + +int request_route(LocationObject *loc) +{ + int ret = 0; + LocationPosition *origin = location_position_new(0, 37.564263, 126.974676, 0, LOCATION_STATUS_2D_FIX); // Seoul city hall + LocationPosition *destination = location_position_new(0, 37.557120, 126.992410, 0, LOCATION_STATUS_2D_FIX); // NamSan + + GList *waypoint = NULL; + LocationPosition *via_pos = location_position_new(0, 37.560950, 126.986240, 0, LOCATION_STATUS_2D_FIX); // Wangsimli + waypoint = g_list_append (waypoint, (gpointer)via_pos); + + LocationRoutePreference *pref = location_route_pref_new(); + gchar *type = g_strdup("FASTEST"); + location_route_pref_set_route_type(pref, type); + + ret = location_request_route(loc, origin, destination, waypoint, pref, cb_route, NULL, &req_id); + if (ret != LOCATION_ERROR_NONE) { + g_printf("Fail to search route by address. Error[%d]\n", ret); + } else { + g_printf("Search Route successfully, req_id %d\n", req_id); + } + + g_free(type); + g_list_free_full (waypoint, free_waypoint); + location_position_free(origin); + location_position_free(destination); + location_route_pref_free(pref); + + return ret; + } + * @endcode + */ +int location_request_route (LocationObject *obj, LocationPosition *origin, LocationPosition *destination, GList *waypoint, const LocationRoutePreference * pref, LocationRouteCB cb, gpointer user_data, guint * req_id); + +/** + * @brief Cancel the previous route request. + * @remarks None + * @pre #location_request_route should be called before. + * @post None. + * @param [in] obj - a #LocationObject created by #location_new + * @param [in] req_id - a route request id returned by location_search_route + * @return int + * @retval 0 Success + * Please refer #LocationError for more information. + * @par Example + * @code +#include +#include + +int cancel_route_request (LocationObject *loc, guint req_id) +{ + g_printf("cancel_route_request\n"); + + int ret = LOCATION_ERROR_NONE; + + ret = location_cancel_route_request(loc, req_id); + if (ret != LOCATION_ERROR_NONE) { + g_printf("Fail to cancel route request. Error[%d]\n", ret); + } + else { + g_printf("location_cancel_route_request, req_id %d\n", req_id); + } +} + * @endcode + */ +int location_cancel_route_request (LocationObject *obj, guint req_id); + +/** + * @brief Check wheither a map service is available on a service provider + * @remarks None + * @pre #location_new should be called before. + * @post None. + * @param [in] obj - a #LocationObject created by #location_new + * @param [in] type - a #LocationMapService + * @return gboolean + * @retval TRUE if supported + * @par Example + * @code +#include +#include + +int check_map_service (LocationObject *loc) +{ + g_printf("check_map_service\n"); + + gboolean is_supported = FALSE; + + is_supported = location_is_supported_map_provider_capability(loc, MAP_SERVICE_ROUTE_REQUEST_FEATURE_TO_AVOID); + if (is_supported == TRUE) { + g_printf("Map Service(MAP_SERVICE_ROUTE_REQUEST_FEATURE_TO_AVOID) is supported.\n"); + } + else { + g_printf("Map Service(MAP_SERVICE_ROUTE_REQUEST_FEATURE_TO_AVOID) is not supported.\n"); + } +} + * @endcode + */ +gboolean location_is_supported_map_provider_capability (LocationObject *obj, LocationMapServiceType type); + +/** + * @brief Get Map service key on a service provider + * @remarks None + * @pre #location_new should be called before. + * @post None. + * @param [in] obj - a #LocationObject created by #location_new + * @param [in] type - a #LocationMapService + * @return GList + * @retval a list of keys + * @par Example + * @code +#include +#include + +static void _print_keys(gpointer data) +{ + g_return_if_fail(data); + gchar *key = (gchar *)data; + + g_printf("Key[%s] is available now\n", key); +} + +int get_map_service_key (LocationObject *loc) +{ + g_printf("check_map_service\n"); + + GList *keys = NULL; + + keys = location_get_map_provider_capability_key(loc, MAP_SERVICE_ROUTE_REQUEST_FEATURE_TO_AVOID); + if (keys) { + g_list_foreach (keys, _print_keys, NULL); + g_list_free_full (keys, g_free); + } + else { + g_printf("Map Service(MAP_SERVICE_ROUTE_REQUEST_FEATURE_TO_AVOID) doesnot have keys. Need to check wheither its service is supported.\n"); + } +} + * @endcode + */ +int location_get_map_provider_capability_key (LocationObject *obj, LocationMapServiceType type, GList **key); + +/** + * @brief Get Map service Preference on a service provider + * @remarks None + * @pre #location_new should be called before. + * @post None. + * @param [in] obj - a #LocationObject created by #location_new + * @return #LocationPreference + * @retval a preference + * @par Example + * @code +#include +#include + int get_map_service_pref (LocationObject loc) + { + if (!loc) return -1; + + LocationPreference *svc_pref = location_get_map_service_pref (loc); + if (!svc_pref) return -1; + + gchar *name = location_pref_get_provider_name (svc_pref); + gchar *unit = location_pref_get_distance_unit (svc_pref); + gchar *language = location_pref_get_language (svc_pref); + + g_printf("provider [%s]: distance unit [%s], languange [%s]\n", name, unit, language); + + return 0; + } + + * @endcode + */ +LocationPreference *location_get_map_service_pref (LocationObject *obj); + +/** + * @brief Set Map service preference on a service provider + * @remarks None + * @pre #location_new should be called before. + * @post None. + * @param [in] obj - a #LocationObject created by #location_new + * @param [in] pref = a #LocationPreference + * @return gboolean + * @retval TRUE if success + * @par Example + * @code +#include +#include + +int set_map_service_pref (LocationObject *loc) +{ + if (!loc) return -1; + + LocationPreference *svc_pref = location_pref_new(); + location_pref_set_language (svc_pref, "en"); + location_pref_set_distance_unit (svc_pref, "MI"); + + gboolean ret = location_set_map_service_pref (loc, svc_pref); + if (!ret) { + location_pref_pref (svc_pref); + return -1; + } + location_pref_pref (svc_pref); + return 0; +} + * @endcode + */ +gboolean location_set_map_service_pref (LocationObject *obj, LocationPreference *pref); + +/** + * @} @} + */ + +G_END_DECLS + +#endif /* __LOCATION_MAP_SERVICE_H__ */ diff --git a/location/map-service/location-poi.c b/location/map-service/location-poi.c new file mode 100644 index 0000000..9dba262 --- /dev/null +++ b/location/map-service/location-poi.c @@ -0,0 +1,289 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-log.h" +#include "location-types.h" +#include "location-pref.h" + +#include "map-service.h" + +#include "location-poi.h" + +struct _LocationPOIPreference { + guint max_result_cnt; ///< Maximum number of results + LocationPOIPrefSortOrder sort_order; ///< Sort order + gchar* item; ///< Sory by item + GHashTable *properties; +}; + +struct _LocationPOIFilter { + // "CATEGORY", "KEYWORD", "POINAME" + GHashTable *properties; +}; + +EXPORT_API guint +location_poi_pref_get_max_result (const LocationPOIPreference *pref) +{ + g_return_val_if_fail(pref, 0); + + return pref->max_result_cnt; +} + +EXPORT_API gchar * +location_poi_pref_get_sort_by (const LocationPOIPreference *pref) +{ + g_return_val_if_fail(pref, NULL); + + return pref->item; +} + +EXPORT_API LocationPOIPrefSortOrder +location_poi_pref_get_sort_order (const LocationPOIPreference *pref) +{ + g_return_val_if_fail(pref, LOCATION_POI_PRE_SO_NONE); + + return pref->sort_order; +} + +EXPORT_API GList * +location_poi_pref_get_property_key (const LocationPOIPreference *pref) +{ + g_return_val_if_fail (pref, NULL); + if (!pref->properties) return NULL; + + return g_hash_table_get_keys (pref->properties); +} + +EXPORT_API gpointer +location_poi_pref_get_property (const LocationPOIPreference *pref, gconstpointer key) +{ + g_return_val_if_fail (pref, NULL); + g_return_val_if_fail (key, NULL); + + if (!pref->properties) return NULL; + + return g_hash_table_lookup (pref->properties, key); +} + + +EXPORT_API gboolean +location_poi_pref_set_max_result (LocationPOIPreference *pref, guint max_num) +{ + g_return_val_if_fail(pref, FALSE); + g_return_val_if_fail(max_num > 0, FALSE); + + pref->max_result_cnt = max_num; + + return TRUE; +} + +EXPORT_API gboolean +location_poi_pref_set_sort_by(LocationPOIPreference * pref, const gchar * item) +{ + g_return_val_if_fail(pref, FALSE); + + if (pref->item) { + g_free(pref->item); + pref->item = NULL; + } + + if (item) pref->item = g_strdup(item); + + return TRUE; +} + +EXPORT_API gboolean +location_poi_pref_set_sort_order (LocationPOIPreference *pref, LocationPOIPrefSortOrder sort_order) +{ + g_return_val_if_fail(pref, FALSE); + + if (sort_order < LOCATION_POI_PREF_SO_ASC || sort_order > LOCATION_POI_PREF_SO_DESC) return FALSE; + + pref->sort_order = sort_order; + + return TRUE; +} + +EXPORT_API gboolean +location_poi_pref_set_property (LocationPOIPreference *pref, gconstpointer key, gconstpointer value) +{ + g_return_val_if_fail(pref, FALSE); + g_return_val_if_fail(key, FALSE); + g_return_val_if_fail(pref->properties, FALSE); + + if (value) { + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert (pref->properties, re_key, re_val); + } else g_hash_table_remove (pref->properties, key); + + return TRUE; +} + +EXPORT_API LocationPOIPreference * +location_poi_pref_new (void) +{ + LocationPOIPreference *pref = g_slice_new0 (LocationPOIPreference); + g_return_val_if_fail(pref, NULL); + + pref->sort_order = LOCATION_POI_PREF_SO_ASC; + pref->max_result_cnt = 25; + pref->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + + return pref; +} + +static void poi_pref_property_copy_cb (gpointer key, gpointer value, gpointer user_data) +{ + g_return_if_fail (key); + g_return_if_fail (value); + g_return_if_fail (user_data); + + LocationPOIPreference *pref = (LocationPOIPreference *) user_data; + if (pref->properties) { + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert (pref->properties, re_key, re_val); + } +} + +EXPORT_API LocationPOIPreference * +location_poi_pref_copy (LocationPOIPreference *pref) +{ + LocationPOIPreference *new_pref = location_poi_pref_new(); + g_return_val_if_fail (new_pref, NULL); + + location_poi_pref_set_sort_by(new_pref, location_poi_pref_get_sort_by(pref)); + location_poi_pref_set_sort_order(new_pref, location_poi_pref_get_sort_order(pref)); + location_poi_pref_set_max_result(new_pref, location_poi_pref_get_max_result(pref)); + + g_hash_table_foreach (pref->properties, poi_pref_property_copy_cb ,new_pref); + + return new_pref; +} + +EXPORT_API void +location_poi_pref_free (LocationPOIPreference * pref) +{ + g_return_if_fail(pref); + + location_poi_pref_set_sort_by(pref, NULL); + if (pref->properties) g_hash_table_destroy (pref->properties); + + g_slice_free(LocationPOIPreference, pref); +} + +EXPORT_API gboolean +location_poi_filter_set (const LocationPOIFilter *filter, gconstpointer key, gconstpointer value) +{ + g_return_val_if_fail(filter, FALSE); + g_return_val_if_fail(key, FALSE); + + if (filter->properties) { + if (value) { + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert (filter->properties, re_key, re_val); + } else g_hash_table_remove (filter->properties, key); + } + else + return FALSE; + + return TRUE; +} + +EXPORT_API gpointer +location_poi_filter_get (const LocationPOIFilter *filter, gconstpointer key) +{ + g_return_val_if_fail(filter, NULL); + g_return_val_if_fail(key, NULL); + + if (filter->properties) { + return g_hash_table_lookup (filter->properties, key); + } + return NULL; +} + +EXPORT_API GList * +location_poi_filter_get_key (const LocationPOIFilter *filter) +{ + g_return_val_if_fail(filter, NULL); + + if (filter->properties) { + return g_hash_table_get_keys (filter->properties); + } + + return NULL; +} + +EXPORT_API LocationPOIFilter * +location_poi_filter_new (void) +{ + LocationPOIFilter *filter = g_slice_new0(LocationPOIFilter); + g_return_val_if_fail (filter, NULL); + + filter->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + + return filter; +} + +static void poi_filter_copy_cb (gpointer key, gpointer value, gpointer user_data) +{ + g_return_if_fail (key); + g_return_if_fail (value); + g_return_if_fail (user_data); + + LocationPOIFilter *filter = (LocationPOIFilter *) user_data; + if (filter->properties) { + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert (filter->properties, re_key, re_val); + } +} + +EXPORT_API LocationPOIFilter * +location_poi_filter_copy (LocationPOIFilter *filter) +{ + g_return_val_if_fail (filter, NULL); + + LocationPOIFilter * new_filter = location_poi_filter_new(); + g_return_val_if_fail (new_filter, NULL); + + if (new_filter->properties) g_hash_table_foreach (filter->properties, poi_filter_copy_cb, new_filter); + + return new_filter; +} + +EXPORT_API void +location_poi_filter_free (LocationPOIFilter *filter) +{ + g_return_if_fail(filter); + + if (filter->properties) { + g_hash_table_destroy (filter->properties); + filter->properties = NULL; + } + g_slice_free(LocationPOIFilter, filter); +} diff --git a/location/map-service/location-poi.h b/location/map-service/location-poi.h new file mode 100644 index 0000000..8e5d20b --- /dev/null +++ b/location/map-service/location-poi.h @@ -0,0 +1,282 @@ +/* + * libslp-location + * + * 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_POI_H__ +#define __LOCATION_POI_H__ + +#include + +G_BEGIN_DECLS + +/** + * @file location-poi.h + * @brief This file contains the internal definitions and structures related to POI. + */ + +/** + * @addtogroup LocationMapService + * @{ + * @defgroup LocationMapServicePOI Location POI + * @brief This is a location POI for providing location map services. + * @addtogroup LocationMapServicePOI + * @{ + */ + +typedef enum { + LOCATION_POI_PRE_SO_NONE, ///< None of sorting the results in order. + LOCATION_POI_PREF_SO_ASC, ///< A constant for sorting the results in ascending order + LOCATION_POI_PREF_SO_DESC ///< A constant for sorting the results in descending order +} LocationPOIPrefSortOrder; + +/** + * @brief Retrive LocationPreperence that the given LocationPOIPreference inherits. + */ + +/** + * @brief Create a new LocationPOIPreference + * @remarks None. + * @pre None + * @post None. + * @return #LocationPOIPreference + * @retval NULL if error occured + * @see location_location_poi_pref_free + * + */ +LocationPOIPreference *location_poi_pref_new (void); + +/** + * @brief Copy a LocationPOIPreference + * @remarks None. + * @pre None + * @post None. + * @return #LocationPOIPreference + * @retval NULL if error occured + * @see location_location_poi_pref_free + * + */ +LocationPOIPreference *location_poi_pref_copy (LocationPOIPreference *pref); + +/** + * @brief Free a LocationPOIPreference + * @remarks None. + * @pre #location_poi_pref_new should be called before. + * @post None. + * @param [in] pref - #LocationPOIPreference + * @return #LocationPreference + * @retval NULL if error occured + * @see location_location_poi_pref_set_pref + */ +void location_poi_pref_free (LocationPOIPreference * pref); + +/** + * @brief Get the maximum number of results for poi service. + * @remarks None. + * @pre #location_poi_pref_new should be called before. + * @post None. + * @param [in] pref - #LocationPOIPreference + * @return guint + * @retval 0 if error occured + * @see location_poi_pref_set_max_result + */ +guint location_poi_pref_get_max_result (const LocationPOIPreference * pref); + +/** + * @brief Get the sort criterion for poi service. + * @remarks None. + * @pre #location_poi_pref_new should be called before. + * @post None. + * @param [in] pref - #LocationPOIPreference + * @return gchar + * @retval sorting item + * @see location_poi_pref_set_sort_by + */ +gchar *location_poi_pref_get_sort_by (const LocationPOIPreference * pref); + +/** + * @brief Get the sort order for poi service. + * @remarks None. + * @pre #location_poi_pref_new should be called before. + * @post None. + * @param [in] pref - #LocationPOIPreference + * @return LocationPOIPrefSortOrder + * @retval sort order + * @see location_poi_pref_set_sort_order + */ +LocationPOIPrefSortOrder location_poi_pref_get_sort_order (const LocationPOIPreference * pref); + +/** + * @brief Get the property keys of poi preference + * @remarks None. + * @pre #location_poi_pref_new should be called before. + * @post None. + * @param [in] pref - #LocationPOIPreference + * @return GList + * @retval list of property key + * @see location_poi_pref_set_property + */ +GList *location_poi_pref_get_property_key (const LocationPOIPreference *pref); + +/** + * @brief Get the property of poi preference + * @remarks None. + * @pre #location_poi_pref_new should be called before. + * @post None. + * @param [in] pref - #LocationPOIPreference + * @param [in] key - gconstpointer + * @return gconstpointer + * @retval property value + * @see location_poi_pref_set_property + */ +gpointer location_poi_pref_get_property (const LocationPOIPreference *pref, gconstpointer key); + + +/** + * @brief Set the maximum number of results for poi service. + * @remarks None. + * @pre #location_poi_pref_new should be called before. + * @post None. + * @param [in] pref - #LocationPOIPreference + * @return gboolean + * @retval TRUE if success + * @see location_poi_pref_get_max_result + */ +gboolean location_poi_pref_set_max_result (LocationPOIPreference * pref, guint max_num); + +/** + * @brief Set the sort criterion for poi service. + * @remarks None. + * @pre #location_poi_pref_new should be called before. + * @post None. + * @param [in] pref - #LocationPOIPreference + * @param [in] item - gchar or NULL if reset + * @return gboolean + * @retval TRUE if success + * @see location_poi_pref_get_sort_by + */ +gboolean location_poi_pref_set_sort_by (LocationPOIPreference * pref, const gchar * item); + +/** + * @brief Set the sort order for poi service. + * @remarks None. + * @pre #location_poi_pref_new should be called before. + * @post None. + * @param [in] pref - #LocationPOIPreference + * @param [in] sort_order - #LocationPOIPrefSortOrder + * @return gboolean + * @retval TRUE if success + * @see location_poi_pref_get_sort_order + */ +gboolean location_poi_pref_set_sort_order (LocationPOIPreference *pref, LocationPOIPrefSortOrder sort_order); + +/** + * @brief Set property of poi preference. + * @remarks None. + * @pre #location_poi_pref_new should be called before. + * @post None. + * @param [in] pref - #LocationPOIPreference + * @param [in] key - gconstpoiner + * @param [in] value - gconstpointer or NULL if reset + * @return gboolean + * @retval TRUE if success + * @see location_poi_pref_get_property + */ +gboolean location_poi_pref_set_property (LocationPOIPreference *pref, gconstpointer key, gconstpointer value); + +/** + * @brief Create a new LocationPOIFilter + * @remarks None + * @pre #location_init should be called before. + * @post None. + * @return a new #LocationPOIFilter + * @retval NULL if error occured + * @see location_poi_filter_free + */ +LocationPOIFilter *location_poi_filter_new (void); + +/** + * @brief Copy a LocationPOIFilter + * @remarks None + * @pre #location_init should be called before. + * @post None. + * @return a #LocationPOIFilter + * @retval NULL if error occured + * @see location_poi_filter_new + */ +LocationPOIFilter *location_poi_filter_copy (LocationPOIFilter *filter); + +/** + * @brief Free a LocationPOIFilter + * @remarks None + * @pre #location_new should be called before. + * @post None. + * @param [in] filter - #LocationPOIFilter + * @return None + * @see location_poi_filter_new + */ +void location_poi_filter_free (LocationPOIFilter *filter); + +/** + * @brief Set filter for poi service + * @remarks None + * @pre #location_poi_filter_new should be called before. + * @post None. + * @param [in] filter - #LocationPOIFilter + * @param [in] key - gconstpointer + * @param [in] value - gconstpointer or NULL if reset + * @return gboolean + * @retval TRUE if success + * @see location_poi_filter_get + */ +gboolean location_poi_filter_set (const LocationPOIFilter *filter, gconstpointer key, gconstpointer value); + +/** + * @brief Get filter for poi service + * @remarks None + * @pre #location_poi_filter_new should be called before. + * @post None. + * @param [in] filter - #LocationPOIFilter + * @param [in] key - gconstpointer + * @return gconstpointer + * @retval Filter property key + * @see location_poi_filter_set + */ +gpointer location_poi_filter_get (const LocationPOIFilter *filter, gconstpointer key); + +/** + * @brief Get keys in the given filter + * @remarks The content of returned list is owned by the poi filter and should not be modified or freed. \n + * Use g_list_free when done using the returned. + * @pre #location_poi_filter_new should be called before. + * @post None. + * @param [in] filter - #LocationPOIFilter + * @return GList + * @retval Filter key + * @see None + */ +GList *location_poi_filter_get_key (const LocationPOIFilter *filter); + +/** + * @} @} + */ + +G_END_DECLS + +#endif diff --git a/location/map-service/location-pref.c b/location/map-service/location-pref.c new file mode 100644 index 0000000..28f2abb --- /dev/null +++ b/location/map-service/location-pref.c @@ -0,0 +1,222 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "location-types.h" +#include "map-service.h" +#include "location-pref.h" + +struct _LocationPreference { + gchar *provider_name; ///< Name of the service provier + gchar *language; ///< Language of the service preference. + gchar *country; ///< Country of the service preference. + gchar *distance_unit; ///< Distance unit of the service preference. + GHashTable *properties; ///< properties of the service preference. +}; + +EXPORT_API GList * +location_pref_get_property_key (const LocationPreference *pref) +{ + g_return_val_if_fail (pref, NULL); + + if (!pref->properties) return NULL; + + return g_hash_table_get_keys (pref->properties); +} + +EXPORT_API gchar * +location_pref_get_language (const LocationPreference *pref) +{ + g_return_val_if_fail (pref, NULL); + + return pref->language; +} + +EXPORT_API gchar * +location_pref_get_country (const LocationPreference *pref) +{ + g_return_val_if_fail (pref, NULL); + + return pref->country; +} + +EXPORT_API gchar * +location_pref_get_distance_unit (const LocationPreference *pref) +{ + g_return_val_if_fail (pref, NULL); + + return pref->distance_unit; +} + +EXPORT_API gconstpointer +location_pref_get_property (const LocationPreference *pref, gconstpointer key) +{ + g_return_val_if_fail (pref, NULL); + g_return_val_if_fail (key, NULL); + if (!pref->properties) return NULL; + + return (gconstpointer) g_hash_table_lookup (pref->properties, key); +} + +EXPORT_API gchar * +location_pref_get_provider_name (const LocationPreference *pref) +{ + g_return_val_if_fail (pref, NULL); + + return pref->provider_name; +} + +EXPORT_API gboolean +location_pref_set_provider_name (LocationPreference *pref, const gchar *name) +{ + g_return_val_if_fail (pref, FALSE); + + if (pref->provider_name) { + g_free (pref->provider_name); + pref->provider_name = NULL; + } + + if (name) pref->provider_name = g_strdup ((gchar *)name); + + return TRUE; +} + +EXPORT_API gboolean +location_pref_set_language (LocationPreference *pref, const gchar * language) +{ + g_return_val_if_fail (pref, FALSE); + + if (pref->language) { + g_free (pref->language); + pref->language = NULL; + } + + if (language) pref->language = g_strdup(language); + + return TRUE; +} + +EXPORT_API gboolean +location_pref_set_country (LocationPreference *pref, const gchar *country) +{ + g_return_val_if_fail (pref, FALSE); + + if (pref->country) { + g_free (pref->country); + pref->country = NULL; + } + + if (country) pref->country = g_strdup(country); + + return TRUE; +} + + +EXPORT_API gboolean +location_pref_set_distance_unit (LocationPreference *pref, const gchar * unit) +{ + g_return_val_if_fail (pref, FALSE); + + if (pref->distance_unit) { + g_free (pref->distance_unit); + pref->distance_unit = NULL; + } + + if (unit) pref->distance_unit = g_strdup (unit); + + return TRUE; +} + +EXPORT_API gboolean +location_pref_set_property (LocationPreference *pref, gconstpointer key, gconstpointer value) +{ + g_return_val_if_fail (pref, FALSE); + g_return_val_if_fail (key, FALSE); + if (!pref->properties) return FALSE; + + if (value) { + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert (pref->properties, re_key, re_val); + } else g_hash_table_remove (pref->properties, key); + + return TRUE; +} + +EXPORT_API LocationPreference * +location_pref_new (void) +{ + LocationPreference *pref = g_slice_new0(LocationPreference); + if (!pref) return NULL; + + pref->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + + return pref; +} + +static void property_copy (gpointer key, gpointer value, gpointer user_data) +{ + g_return_if_fail (key); + g_return_if_fail (value); + g_return_if_fail (user_data); + + GHashTable *properties = (GHashTable *) user_data; + + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert (properties, re_key, re_val); +} + +EXPORT_API LocationPreference * +location_pref_copy (LocationPreference *pref) +{ + g_return_val_if_fail (pref, NULL); + + LocationPreference *new_pref = location_pref_new(); + if (!new_pref) return NULL; + + location_pref_set_provider_name (new_pref, location_pref_get_provider_name(pref)); + location_pref_set_language (new_pref, location_pref_get_language(pref)); + location_pref_set_distance_unit (new_pref, location_pref_get_distance_unit(pref)); + + + g_hash_table_foreach (pref->properties, property_copy, new_pref->properties); + + return new_pref; +} + +EXPORT_API void +location_pref_free (LocationPreference * pref) +{ + g_return_if_fail(pref); + + location_pref_set_provider_name (pref, NULL); + location_pref_set_language (pref, NULL); + location_pref_set_distance_unit (pref, NULL); + g_hash_table_destroy (pref->properties); + + g_slice_free (LocationPreference, pref); + pref = NULL; +} diff --git a/location/map-service/location-pref.h b/location/map-service/location-pref.h new file mode 100644 index 0000000..577eb17 --- /dev/null +++ b/location/map-service/location-pref.h @@ -0,0 +1,121 @@ +/* + * libslp-location + * + * 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_PREF_H__ +#define __LOCATION_PREF_H__ + +#include + +G_BEGIN_DECLS + +/** + * @file location-pref.h + * @brief This file contains the internal definitions and structures related to a service provider. + * @addtogroup LocationMapService + * @{ + * @defgroup LocationMapServiceProvider Service Provider + * @brief This represents preference and capability of Service providers + * @addtogroup LocationMapServiceProvider + * @{ + */ + +/** + * @brief Get provider name to be used in the service request + */ +gchar *location_pref_get_provider_name (const LocationPreference *pref); + +/** + * @brief Get language to be used in the service request. + */ +gchar *location_pref_get_language (const LocationPreference *pref); + +/** + * @brief Get country to be used in the service request. + */ +gchar *location_pref_get_country (const LocationPreference *pref); + + +/** + * @brief Get the preferred length unit to be used in the service request. + */ +gchar *location_pref_get_distance_unit (const LocationPreference *pref); + +/** + * @brief Get available service of the service provider. + */ +GList *location_pref_get_property_key (const LocationPreference *pref); + +/** + * @brief Get property to be used in the service request. + */ +gconstpointer location_pref_get_property (const LocationPreference *pref, gconstpointer key); + +/** + * @brief Set provider's name to be used in the service request. + */ +gboolean location_pref_set_provider_name (LocationPreference *pref, const gchar *name); + +/** + * @brief Set language to be used in the service request. + */ +gboolean location_pref_set_language (LocationPreference *pref, const gchar *language); + +/** + * @brief Set country to be used in the service request. + */ +gboolean location_pref_set_country (LocationPreference *pref, const gchar *country); + +/** + * @brief Get the preferred length unit to be used in the service request. + */ +gboolean location_pref_set_distance_unit (LocationPreference *pref, const gchar * unit); + +/** + * @brief Set property to be used in the service request. + */ +gboolean location_pref_set_property (LocationPreference *pref, gconstpointer key, gconstpointer value); + +/** + * @brief Create a new LocationPreference. + */ +LocationPreference * location_pref_new (void); + +/** + * @brief Create a new LocationPreference. + */ +LocationPreference * location_pref_copy (LocationPreference *pref); + + +/** + * @brief Free a LocationPreference. + */ +void location_pref_free (LocationPreference * pref); + +/** + * @} @} + */ + +G_END_DECLS + +#endif /* __LOCATION_PREF_H__ */ + + + diff --git a/location/map-service/location-route-ext.h b/location/map-service/location-route-ext.h new file mode 100644 index 0000000..14f59cc --- /dev/null +++ b/location/map-service/location-route-ext.h @@ -0,0 +1,362 @@ +/* + * libslp-location + * + * 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_ROUTE_EXT_H__ +#define __LOCATION_ROUTE_EXT_H__ + +#include + +G_BEGIN_DECLS + +/** + * @file location-route-ext.h + * @brief This file contains the extensional definitions and structures related to Route. + */ +/** + * @addtogroup LocationMapServiceRoute + * @{ + * @defgroup LocationMapServiceRouteExt Location Route Ext + * @brief This provides Location Route Ext APIs. + * @addtogroup LocationMapServiceRouteExt + * @{ + */ + +/** + * @brief Set the origin #LocationPosition of #LocationRoute + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @param [in] origin - a #LocationPosition + * @return gboolean + * @retval TRUE if success + * @see location_route_get_origin + */ +gboolean location_route_set_origin (LocationRoute *route, const LocationPosition* origin); + +/** + * @brief Set the destication #LocationPosition of #LocationRoute + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @param [in] destination - a #LocationPosition + * @return gboolean + * @retval TRUE if success + * @see location_route_get_destination + */ +gboolean location_route_set_destination (LocationRoute *route, const LocationPosition* destination); + +/** + * @brief Set the bounding box #LocationBoundary of #LocationRoute + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @param [in] bbox - a #LocationBoundary + * @return gboolean + * @retval TRUE if success + * @see location_route_get_bounding_box + */ +gboolean location_route_set_bounding_box (LocationRoute *route, const LocationBoundary* bbox); +/** + * @brief Set the distance of #LocationRoute + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @param [in] total_distance - gdouble + * @return gboolean + * @retval TRUE if success + * @see location_route_get_total_distance + */ +gboolean location_route_set_total_distance (LocationRoute *route, gdouble total_distance); + +/** + * @brief Set the distance unit of #LocationRoute + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @param [in] distance_unit - gchar + * @return gboolean + * @retval TRUE if success + * @see location_route_get_distance_unit + */ +gboolean location_route_set_distance_unit (LocationRoute *route, const gchar* distance_unit); + +/** + * @brief Set the duration of #LocationRoute + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @param [in] total_duration - glong + * @return gboolean + * @retval TRUE if success + * @see location_route_get_total_duration + */ +gboolean location_route_set_total_duration (LocationRoute *route, glong total_duration); + +/** + * @brief Set the propery value of #LocationRoute + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @param [in] key - gconstpointer + * @param [in] value - gconstpointer + * @return gboolean + * @retval TRUE if success + * @see location_route_get_property + */ +gboolean location_route_set_property (LocationRoute *route, gconstpointer key, gconstpointer value); + +/** + * @brief Set the list of segments #LocationRouteSegment of #LocationRoute + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @param [in] segment - a list of #LocationRouteSegment + * @return gboolean + * @retval TRUE if success + * @see location_route_get_route_segment + */ +gboolean location_route_set_route_segment (LocationRoute *route, GList* segment); + +/** + * @brief Set the start point #LocationPosition of #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @param [in] start - a #LocationPosition + * @return gboolean + * @retval TRUE if success + * @see location_route_segment_get_start_point + */ +gboolean location_route_segment_set_start_point (LocationRouteSegment *segment, const LocationPosition *start); + +/** + * @brief Set the end point #LocationPosition of #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @param [in] end - a #LocationPosition + * @return gboolean + * @retval TRUE if success + * @see location_route_segment_get_end_point + */ +gboolean location_route_segment_set_end_point (LocationRouteSegment *segment, const LocationPosition *end); + +/** + * @brief Set the bounding box #LocationBoundary of #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @param [in] bbox - a #LocationBoundary + * @return gboolean + * @retval TRUE if success + * @see location_route_segment_get_bounding_box + */ +gboolean location_route_segment_set_bounding_box (LocationRouteSegment *segment, const LocationBoundary *bbox); + +/** + * @brief Set the distance of #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @param [in] distance - gdouble + * @return gboolean + * @retval TRUE if success + * @see location_route_segment_get_distance + */ +gboolean location_route_segment_set_distance (LocationRouteSegment *segment, gdouble distance); + +/** + * @brief Set the duration of #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @param [in] duration - glong + * @return gboolean + * @retval TRUE if success + * @see location_route_segment_get_duration + */ +gboolean location_route_segment_set_duration (LocationRouteSegment *segment, glong duration); + +/** + * @brief Set the property value of #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @param [in] key - gconstpointer + * @param [in] value - gconstpointer + * @return gboolean + * @retval TRUE if success + * @see location_route_segment_get_property + */ +gboolean location_route_segment_set_property (LocationRouteSegment *segment, gconstpointer key, gconstpointer value); + +/** + * @brief Set the list of route steps #LocationRouteStep in #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @param [in] step - a list of #locationRouteStep + * @return gboolean + * @retval TRUE if success + * @see location_route_segment_get_route_step + */ +gboolean location_route_segment_set_route_step (LocationRouteSegment *segment, GList* step); + +/** + * @brief Set the start point #LocationPosition of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @param [in] start - a #LocationPosition + * @return gboolean + * @retval TRUE if success + * @see location_route_step_get_start_point + */ +gboolean location_route_step_set_start_point (LocationRouteStep *step, const LocationPosition *start); + +/** + * @brief Set the end point #LocationPosition of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @param [in] end - a #LocationPosition + * @return gboolean + * @retval TRUE if success + * @see location_route_step_get_end_point + */ +gboolean location_route_step_set_end_point (LocationRouteStep *step, const LocationPosition *end); + +/** + * @brief Set the bounding box #LocationBoundary of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @param [in] bbox - a #LocationBoundary + * @return gboolean + * @retval TRUE if success + * @see location_route_step_get_bounding_box + */ +gboolean location_route_step_set_bounding_box (LocationRouteStep *step, const LocationBoundary *bbox); + +/** + * @brief Set the distance of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @param [in] distance - gdouble + * @return gboolean + * @retval TRUE if success + * @see location_route_step_get_distance + */ +gboolean location_route_step_set_distance (LocationRouteStep *step, gdouble distance); + +/** + * @brief Set the duration of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @param [in] duration - glong + * @return gboolean + * @retval TRUE if success + * @see location_route_step_get_duration + */ +gboolean location_route_step_set_duration (LocationRouteStep *step, glong duration); + +/** + * @brief Set the transport mode of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @param [in] transport_mode - gchar + * @return gboolean + * @retval TRUE if success + * @see location_route_step_get_transport_mode + */ +gboolean location_route_step_set_transport_mode (LocationRouteStep *step, const gchar *transport_mode); + +/** + * @brief Set the instruction of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @param [in] instruction - gchar + * @return gboolean + * @retval TRUE if success + * @see location_route_step_get_instruction + */ +gboolean location_route_step_set_instruction (LocationRouteStep *step, const gchar *instruction); + +/** + * @brief Set the list of geometry #LocationPosition in #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @param [in] geometry - a list of #LocationPosition + * @return gboolean + * @retval TRUE if success + * @see location_route_step_get_geometry + */ +gboolean location_route_step_set_geometry (LocationRouteStep *step, GList *geometry); + +/** + * @brief Set the property value of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @param [in] key - gconstpointer + * @param [in] value - gconstpointer + * @return gboolean + * @retval TRUE if success + * @see location_route_step_get_property + */ +gboolean location_route_step_set_property (LocationRouteStep *step, gconstpointer key, gconstpointer value); + +/** + * @} @} + */ + +G_END_DECLS + +#endif diff --git a/location/map-service/location-route.c b/location/map-service/location-route.c new file mode 100644 index 0000000..7ffe8e5 --- /dev/null +++ b/location/map-service/location-route.c @@ -0,0 +1,1372 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-types.h" +#include "location-route.h" +#include "location-route-ext.h" +#include "location-boundary.h" +#include "map-service.h" + + +struct _LocationRoute { +// gint req_id; //< Request id : for expandability + LocationPosition *origin; //< Coordinate StartCoord + LocationPosition *destination; //< Coordinates destCoord + LocationBoundary *bbox; //< a rectangular geographical area + gdouble total_distance; //< Total distance + gchar *distance_unit; //< Distance Unit + glong total_duration; //< Total duration + GHashTable *properties; // + GList *segment; +}; + +//Waypoints +struct _LocationRouteSegment { + LocationPosition *start; //< Coordinate StartCoord; + LocationPosition *end; //< Coordinates destCoord; + LocationBoundary *bbox; //< a rectangular geographical area + gdouble distance; + glong duration; + GHashTable *properties; // + GList *step; +}; + +// Each instruction +struct _LocationRouteStep { + LocationPosition *start; //< Coordinate StartCoord; + LocationPosition *end; //< Coordinates destCoord; + LocationBoundary *bbox; //< a rectangular geographical area + gdouble distance; + glong duration; + gchar *transport_mode; + gchar *instruction; + GList *geometry; + + GHashTable *properties; +}; + +struct _LocationRoutePreference { + GList* addr_to_avoid; + GList* area_to_avoid; + GList* feature_to_avoid; + GList* freeformed_addr_to_avoid; + LocationBoundary* bbox; + guint max_matches_count; + gchar *distance_unit; + + gchar *route_type; + gchar *transport_mode; + gboolean is_geometry_used; + gboolean is_instruction_bounding_box_used; + gboolean is_instruction_geometry_used; + gboolean is_instruction_used; + gboolean is_traffic_data_used; + + // AvoidFreeways, Easy, Fastest, MoreFreeways, NoFreeways, Pedestrian, Shortest + GHashTable *properties; + +}; + +static void route_pref_addr_to_avoid_copy_cb (gpointer data, gpointer user_data) +{ + g_return_if_fail(data); + g_return_if_fail(user_data); + + LocationAddress *address = (LocationAddress *)data; + LocationRoutePreference *pref = (LocationRoutePreference *)user_data; + + pref->addr_to_avoid = g_list_append (pref->addr_to_avoid, location_address_copy(address)); +} + +static void addr_to_avoid_free_cb (gpointer data) +{ + g_return_if_fail (data); + + LocationAddress *addr = (LocationAddress *)data; + + location_address_free (addr); +} + +EXPORT_API gboolean +location_route_pref_set_addr_to_avoid (LocationRoutePreference *pref, GList *addr) +{ + g_return_val_if_fail(pref, FALSE); + + if (pref->addr_to_avoid) { + g_list_free_full (pref->addr_to_avoid, addr_to_avoid_free_cb); + pref->addr_to_avoid = NULL; + } + + if (addr) g_list_foreach (addr, route_pref_addr_to_avoid_copy_cb, pref); + + return TRUE; +} + +static void route_pref_area_to_avoid_copy_cb (gpointer data, gpointer user_data) +{ + g_return_if_fail(data); + g_return_if_fail(user_data); + + LocationBoundary *area = (LocationBoundary *)data; + LocationRoutePreference *pref = (LocationRoutePreference *)user_data; + + pref->area_to_avoid = g_list_append (pref->area_to_avoid, location_boundary_copy((const LocationBoundary *)area)); +} + +static void route_pref_area_to_avoid_free_cb (gpointer data) +{ + g_return_if_fail (data); + + LocationBoundary *boundary = (LocationBoundary *)data; + + location_boundary_free (boundary); +} + +EXPORT_API gboolean +location_route_pref_set_area_to_avoid (LocationRoutePreference *pref, GList *area) +{ + g_return_val_if_fail(pref, FALSE); + + if (pref->area_to_avoid) { + g_list_free_full (pref->area_to_avoid, route_pref_area_to_avoid_free_cb); + pref->area_to_avoid = NULL; + } + + if (area) g_list_foreach (area, route_pref_area_to_avoid_copy_cb, pref); + + return TRUE; +} + +static void route_pref_feature_to_avoid_copy_cb (gpointer data, gpointer user_data) +{ + g_return_if_fail (data); + g_return_if_fail (user_data); + + gchar *feature = (gchar *)data; + LocationRoutePreference *pref = (LocationRoutePreference *) user_data; + + pref->feature_to_avoid = g_list_append (pref->feature_to_avoid, g_strdup (feature)); +} + +EXPORT_API gboolean +location_route_pref_set_feature_to_avoid (LocationRoutePreference *pref, GList * feature) +{ + g_return_val_if_fail(pref, FALSE); + + if (pref->feature_to_avoid) { + g_list_free_full (pref->feature_to_avoid, g_free); + pref->feature_to_avoid = NULL; + } + + g_list_foreach (feature, route_pref_feature_to_avoid_copy_cb, pref); + + return TRUE; +} + +static void route_pref_freeforemd_addr_to_avoid_foreach_copy (gpointer data, gpointer user_data) +{ + g_return_if_fail(data); + g_return_if_fail(user_data); + + gchar *freeformed_addr = (gchar *)data; + LocationRoutePreference *pref = (LocationRoutePreference *)user_data; + + pref->freeformed_addr_to_avoid = g_list_append (pref->freeformed_addr_to_avoid, g_strdup(freeformed_addr)); +} + +EXPORT_API gboolean +location_route_pref_set_freeformed_addr_to_avoid (LocationRoutePreference *pref, GList *freeformed_addr) +{ + g_return_val_if_fail(pref, FALSE); + + if (pref->freeformed_addr_to_avoid) { + g_list_free_full (pref->freeformed_addr_to_avoid, g_free); + pref->freeformed_addr_to_avoid = NULL; + } + + if (freeformed_addr) g_list_foreach (freeformed_addr, route_pref_freeforemd_addr_to_avoid_foreach_copy, pref); + + return TRUE; +} + +EXPORT_API gboolean +location_route_pref_set_bounding_box (LocationRoutePreference *pref, const LocationBoundary *bbox) +{ + g_return_val_if_fail(pref, FALSE); + + if (pref->bbox) { + location_boundary_free (pref->bbox); + pref->bbox = NULL; + } + + if (bbox) pref->bbox = location_boundary_copy (bbox); + + return TRUE; +} + +EXPORT_API gboolean +location_route_pref_set_max_result (LocationRoutePreference *pref, guint max_num) +{ + g_return_val_if_fail(pref, FALSE); + g_return_val_if_fail(max_num > 0, FALSE); + + pref->max_matches_count = max_num; + + return TRUE; +} + +EXPORT_API gboolean +location_route_pref_set_route_type (LocationRoutePreference *pref, const gchar *type) +{ + g_return_val_if_fail(pref, FALSE); + + if (pref->route_type) { + g_free(pref->route_type); + pref->route_type = NULL; + } + + if (type) pref->route_type = g_strdup (type); + + return TRUE; +} + +EXPORT_API gboolean +location_route_pref_set_transport_mode (LocationRoutePreference *pref, const gchar *mode) +{ + g_return_val_if_fail(pref, FALSE); + + if (pref->transport_mode) { + g_free(pref->transport_mode); + pref->transport_mode = NULL; + } + + if (mode) pref->transport_mode = g_strdup (mode); + + return TRUE; +} + +EXPORT_API gboolean +location_route_pref_set_geometry_used (LocationRoutePreference *pref, gboolean is_used) +{ + g_return_val_if_fail(pref, FALSE); + + pref->is_geometry_used = is_used; + + return TRUE; +} + +EXPORT_API gboolean +location_route_pref_set_instruction_bounding_box_used (LocationRoutePreference *pref, gboolean is_used) +{ + g_return_val_if_fail(pref, FALSE); + + pref->is_instruction_bounding_box_used = is_used; + + return TRUE; +} + +EXPORT_API gboolean +location_route_pref_set_instruction_geometry_used (LocationRoutePreference *pref, gboolean is_used) +{ + g_return_val_if_fail(pref, FALSE); + + pref->is_instruction_geometry_used = is_used; + + return TRUE; +} + +EXPORT_API gboolean +location_route_pref_set_instruction_used (LocationRoutePreference *pref, gboolean is_used) +{ + g_return_val_if_fail(pref, FALSE); + + pref->is_instruction_used = is_used; + + return TRUE; +} + +EXPORT_API gboolean +location_route_pref_set_traffic_data_used (LocationRoutePreference *pref, gboolean is_used) +{ + g_return_val_if_fail(pref, FALSE); + + pref->is_traffic_data_used = is_used; + + return TRUE; +} + +EXPORT_API gboolean +location_route_pref_set_property (LocationRoutePreference *pref, gconstpointer key, gconstpointer value) +{ + g_return_val_if_fail(pref, FALSE); + g_return_val_if_fail(key, FALSE); + + if (value) { + gchar *re_key = g_strdup(key); + gchar *re_val = g_strdup(value); + g_hash_table_insert (pref->properties, re_key, re_val); + } else g_hash_table_remove (pref->properties, key); + + return TRUE; +} + +EXPORT_API GList * +location_route_pref_get_addr_to_avoid (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, NULL); + + return pref->addr_to_avoid; +} + +EXPORT_API GList * +location_route_pref_get_area_to_avoid (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, NULL); + + return pref->area_to_avoid; +} + +EXPORT_API GList * +location_route_pref_get_feature_to_avoid (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, NULL); + + return pref->feature_to_avoid; +} + +EXPORT_API GList * +location_route_pref_get_freeformed_addr_to_avoid (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, NULL); + + return pref->freeformed_addr_to_avoid; +} + +EXPORT_API LocationBoundary * +location_route_pref_get_bounding_box (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, NULL); + + return pref->bbox; +} + +EXPORT_API guint +location_route_pref_get_max_result (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, 0); + + return pref->max_matches_count; +} + +EXPORT_API gchar * +location_route_pref_get_route_type (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, NULL); + + return pref->route_type; +} + +EXPORT_API gchar * +location_route_pref_get_transport_mode (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, NULL); + + return pref->transport_mode; +} + +EXPORT_API gboolean +location_route_pref_get_geometry_used (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, FALSE); + + return pref->is_geometry_used; +} + +EXPORT_API gboolean +location_route_pref_get_instruction_bounding_box_used (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, FALSE); + + return pref->is_instruction_bounding_box_used; +} + +EXPORT_API gboolean +location_route_pref_get_instruction_geometry_used (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, FALSE); + + return pref->is_instruction_geometry_used; +} + +EXPORT_API gboolean +location_route_pref_get_instruction_used (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, FALSE); + + return pref->is_instruction_used; +} + +EXPORT_API gboolean +location_route_pref_get_traffic_data_used (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, FALSE); + + return pref->is_traffic_data_used; +} + +EXPORT_API GList* +location_route_pref_get_property_key (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, NULL); + + return g_hash_table_get_keys(pref->properties); +} + +EXPORT_API gpointer +location_route_pref_get_property (const LocationRoutePreference *pref, gconstpointer key) +{ + g_return_val_if_fail(pref, NULL); + g_return_val_if_fail(key, NULL); + + return g_hash_table_lookup(pref->properties, key); +} + +EXPORT_API LocationRoutePreference * +location_route_pref_new (void) +{ + LocationRoutePreference *pref = g_slice_new0(LocationRoutePreference); + g_return_val_if_fail (pref, NULL); + + pref->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + return pref; +} + +static void route_pref_property_copy_cb (gpointer key, gpointer value, gpointer user_data) +{ + g_return_if_fail(key); + g_return_if_fail(value); + g_return_if_fail(user_data); + + LocationRoutePreference *pref = (LocationRoutePreference *)user_data; + + if (pref->properties) { + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert (pref->properties, re_key, re_val); + } +} + +EXPORT_API LocationRoutePreference * +location_route_pref_copy (const LocationRoutePreference *pref) +{ + g_return_val_if_fail(pref, NULL); + + LocationRoutePreference *new_pref = location_route_pref_new(); + g_return_val_if_fail (pref, NULL); + + location_route_pref_set_addr_to_avoid(new_pref, location_route_pref_get_addr_to_avoid (pref)); + location_route_pref_set_area_to_avoid(new_pref, location_route_pref_get_area_to_avoid (pref)); + location_route_pref_set_feature_to_avoid(new_pref, location_route_pref_get_feature_to_avoid (pref)); + location_route_pref_set_freeformed_addr_to_avoid(new_pref, location_route_pref_get_freeformed_addr_to_avoid (pref)); + location_route_pref_set_bounding_box(new_pref, location_route_pref_get_bounding_box (pref)); + location_route_pref_set_max_result(new_pref, location_route_pref_get_max_result (pref)); + location_route_pref_set_route_type(new_pref, location_route_pref_get_route_type (pref)); + location_route_pref_set_transport_mode(new_pref, location_route_pref_get_transport_mode (pref)); + location_route_pref_set_geometry_used(new_pref, location_route_pref_get_geometry_used (pref)); + location_route_pref_set_instruction_bounding_box_used(new_pref, location_route_pref_get_instruction_bounding_box_used (pref)); + location_route_pref_set_instruction_geometry_used(new_pref, location_route_pref_get_instruction_geometry_used (pref)); + location_route_pref_set_instruction_used(new_pref, location_route_pref_get_instruction_used (pref)); + location_route_pref_set_traffic_data_used(new_pref, location_route_pref_get_traffic_data_used (pref)); + location_route_pref_set_traffic_data_used(new_pref, location_route_pref_get_traffic_data_used (pref)); + + if (new_pref->properties) g_hash_table_foreach (pref->properties, route_pref_property_copy_cb, new_pref); + + return new_pref; +} + + +EXPORT_API void +location_route_pref_free (LocationRoutePreference *pref) +{ + g_return_if_fail(pref); + + location_route_pref_set_addr_to_avoid(pref, NULL); + location_route_pref_set_area_to_avoid(pref, NULL); + location_route_pref_set_feature_to_avoid(pref, NULL); + location_route_pref_set_freeformed_addr_to_avoid(pref, NULL); + location_route_pref_set_bounding_box(pref, NULL); + location_route_pref_set_route_type(pref, NULL); + location_route_pref_set_transport_mode(pref, NULL); + + if (pref->properties) { + g_hash_table_destroy (pref->properties); + pref->properties = NULL; + } + + g_slice_free (LocationRoutePreference, pref); +} + +/* for expandability +EXPORT_API gint +location_route_get_req_id (const LocationRoute *route) +{ + g_return_val_if_fail(route, 0); + + return route->req_id; +} +*/ + +EXPORT_API LocationPosition * +location_route_get_origin (const LocationRoute *route) +{ + g_return_val_if_fail(route, NULL); + + return route->origin; +} + +EXPORT_API LocationPosition * +location_route_get_destination (const LocationRoute *route) +{ + g_return_val_if_fail(route, NULL); + + return route->destination; +} + +EXPORT_API LocationBoundary * +location_route_get_bounding_box (const LocationRoute *route) +{ + g_return_val_if_fail(route, NULL); + + return route->bbox; +} + +EXPORT_API gdouble +location_route_get_total_distance (const LocationRoute *route) +{ + g_return_val_if_fail(route, 0.0); + + return route->total_distance; +} + +EXPORT_API gchar * +location_route_get_distance_unit (const LocationRoute *route) +{ + g_return_val_if_fail(route, NULL); + + return route->distance_unit; +} + +EXPORT_API glong +location_route_get_total_duration (const LocationRoute *route) +{ + g_return_val_if_fail(route, 0); + + return route->total_duration; +} + +EXPORT_API GList * +location_route_get_property_key (const LocationRoute *route) +{ + g_return_val_if_fail(route, NULL); + + return g_hash_table_get_keys(route->properties); +} + +EXPORT_API gpointer +location_route_get_property (const LocationRoute *route, gconstpointer key) +{ + g_return_val_if_fail(route, NULL); + g_return_val_if_fail(key, NULL); + + return g_hash_table_lookup(route->properties, key); +} + +EXPORT_API GList * +location_route_get_route_segment (const LocationRoute *route) +{ + g_return_val_if_fail(route, NULL); + + return route->segment; +} + +/* for expandability +EXPORT_API gboolean +location_route_set_req_id (LocationRoute *route, gint req_id) +{ + g_return_val_if_fail(route, FALSE); + + route->req_id = req_id; + + return TRUE; +} +*/ + +EXPORT_API gboolean +location_route_set_origin (LocationRoute *route, const LocationPosition* origin) +{ + g_return_val_if_fail(route, FALSE); + + if (route->origin) { + location_position_free(route->origin); + route->origin = NULL; + } + + if (origin) route->origin = location_position_copy(origin); + + return TRUE; +} + +EXPORT_API gboolean +location_route_set_destination (LocationRoute *route, const LocationPosition* destination) +{ + g_return_val_if_fail(route, FALSE); + + if (route->destination) { + location_position_free(route->destination); + route->destination = NULL; + } + + if (destination) route->destination = location_position_copy(destination); + + return TRUE; +} + +EXPORT_API gboolean +location_route_set_bounding_box (LocationRoute *route, const LocationBoundary* bbox) +{ + g_return_val_if_fail(route, FALSE); + + if (route->bbox) { + location_boundary_free(route->bbox); + route->bbox = NULL; + } + + if (bbox) route->bbox = location_boundary_copy(bbox); + + return TRUE; +} + +EXPORT_API +gboolean location_route_set_total_distance (LocationRoute *route, gdouble total_distance) +{ + g_return_val_if_fail(route, FALSE); + + route->total_distance = total_distance; + + return TRUE; +} + +EXPORT_API +gboolean location_route_set_distance_unit (LocationRoute *route, const gchar* distance_unit) +{ + g_return_val_if_fail(route, FALSE); + + if (route->distance_unit) { + g_free(route->distance_unit); + route->distance_unit = NULL; + } + + if (distance_unit) route->distance_unit = g_strdup(distance_unit); + + return TRUE; +} + +EXPORT_API gboolean +location_route_set_total_duration (LocationRoute *route, glong total_duration) +{ + g_return_val_if_fail(route, FALSE); + + route->total_duration = total_duration; + + return TRUE; +} + +EXPORT_API gboolean +location_route_set_property (LocationRoute *route, gconstpointer key, gconstpointer value) +{ + g_return_val_if_fail(route, FALSE); + g_return_val_if_fail(key, FALSE); + if (!route->properties) return FALSE; + + if (value) { + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert(route->properties, re_key, re_val); + } else g_hash_table_remove (route->properties, key); + + return TRUE; +} + +static void route_segment_foreach_copy (gpointer data, gpointer user_data) +{ + g_return_if_fail (data); + + LocationRouteSegment *segment = (LocationRouteSegment *) data; + LocationRoute *route = (LocationRoute *) user_data; + + route->segment = g_list_append (route->segment, location_route_segment_copy (segment)); +} + +static void route_segment_foreach_free (gpointer data) +{ + g_return_if_fail (data); + + LocationRouteSegment *segment = (LocationRouteSegment *)data; + + location_route_segment_free(segment); +} + + +EXPORT_API gboolean +location_route_set_route_segment (LocationRoute *route, GList* segment) +{ + g_return_val_if_fail(route, FALSE); + + if (route->segment) { + g_list_free_full (route->segment, route_segment_foreach_free); + route->segment = NULL; + } + + if (segment) g_list_foreach (segment, route_segment_foreach_copy, route); + + return TRUE; +} + +EXPORT_API LocationRoute * +location_route_new (void) +{ + LocationRoute *route = g_slice_new0(LocationRoute); + g_return_val_if_fail (route, NULL); + + route->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + + return route; +} + +static void route_property_copy_cb (gpointer key, gpointer value, gpointer user_data) +{ + g_return_if_fail (key); + g_return_if_fail (value); + g_return_if_fail (user_data); + + LocationRoute *route = (LocationRoute *)user_data; + + if (route->properties) { + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert (route->properties, re_key, re_val); + } +} + +EXPORT_API LocationRoute * +location_route_copy (const LocationRoute *route) +{ + g_return_val_if_fail(route, NULL); + LocationRoute *new_route = location_route_new(); + g_return_val_if_fail(new_route, NULL); + + location_route_set_origin (new_route, location_route_get_origin(route)); + location_route_set_destination (new_route, location_route_get_destination(route)); + location_route_set_bounding_box (new_route, location_route_get_bounding_box(route)); + location_route_set_total_distance (new_route, location_route_get_total_distance(route)); + location_route_set_distance_unit (new_route, location_route_get_distance_unit(route)); + location_route_set_total_duration (new_route, location_route_get_total_duration(route)); + + g_list_foreach(route->segment, route_segment_foreach_copy, new_route); + + if (route->properties) g_hash_table_foreach (route->properties, route_property_copy_cb, new_route); + + return new_route; +} + +EXPORT_API void +location_route_free (LocationRoute *route) +{ + g_return_if_fail (route); + + location_route_set_origin (route, NULL); + location_route_set_destination (route, NULL); + location_route_set_bounding_box (route, NULL); + location_route_set_distance_unit (route, NULL); + location_route_set_route_segment (route, NULL); + + if (route->properties) { + g_hash_table_destroy (route->properties); + route->properties = NULL; + } + + g_slice_free (LocationRoute, route); +} + +EXPORT_API LocationPosition * +location_route_segment_get_start_point (const LocationRouteSegment *segment) +{ + g_return_val_if_fail(segment, NULL); + + return segment->start; +} + +EXPORT_API LocationPosition * +location_route_segment_get_end_point (const LocationRouteSegment *segment) +{ + g_return_val_if_fail(segment, NULL); + + return segment->end; +} + +EXPORT_API LocationBoundary * +location_route_segment_get_bounding_box (const LocationRouteSegment *segment) +{ + g_return_val_if_fail(segment, NULL); + + return segment->bbox; +} + +EXPORT_API gdouble +location_route_segment_get_distance (const LocationRouteSegment *segment) +{ + g_return_val_if_fail(segment, 0.0); + + return segment->distance; +} + +EXPORT_API glong +location_route_segment_get_duration (const LocationRouteSegment *segment) +{ + g_return_val_if_fail(segment, 0); + + return segment->duration; +} + +EXPORT_API GList* +location_route_segment_get_property_key (const LocationRouteSegment *segment) +{ + g_return_val_if_fail(segment, NULL); + + return g_hash_table_get_keys(segment->properties); +} + +EXPORT_API gpointer +location_route_segment_get_property (const LocationRouteSegment *segment, gconstpointer key) +{ + g_return_val_if_fail(segment, NULL); + g_return_val_if_fail(key, NULL); + + return g_hash_table_lookup(segment->properties, (gpointer) key); +} + +EXPORT_API GList* +location_route_segment_get_route_step (const LocationRouteSegment *segment) +{ + g_return_val_if_fail(segment, NULL); + + return segment->step; +} + +EXPORT_API gboolean +location_route_segment_set_start_point (LocationRouteSegment *segment, const LocationPosition *start) +{ + g_return_val_if_fail (segment, FALSE); + + if (segment->start) { + location_position_free(segment->start); + segment->start = NULL; + } + + if (start) segment->start = location_position_copy (start); + + return TRUE; +} + +EXPORT_API gboolean +location_route_segment_set_end_point (LocationRouteSegment *segment, const LocationPosition *end) +{ + g_return_val_if_fail (segment, FALSE); + + if (segment->end) { + location_position_free(segment->end); + segment->end = NULL; + } + + if (end) segment->end = location_position_copy (end); + + return TRUE; + +} + +EXPORT_API gboolean +location_route_segment_set_bounding_box (LocationRouteSegment *segment, const LocationBoundary *bbox) +{ + g_return_val_if_fail (segment, FALSE); + + if (segment->bbox) { + location_boundary_free(segment->bbox); + segment->bbox = NULL; + } + + if (bbox) segment->bbox = location_boundary_copy (bbox); + + return TRUE; +} + +EXPORT_API gboolean +location_route_segment_set_distance (LocationRouteSegment *segment, gdouble distance) +{ + g_return_val_if_fail (segment, FALSE); + + segment->distance = distance; + + return TRUE; +} + +EXPORT_API gboolean +location_route_segment_set_duration (LocationRouteSegment *segment, glong duration) +{ + g_return_val_if_fail (segment, FALSE); + + segment->duration = duration; + + return TRUE; +} + +EXPORT_API gboolean +location_route_segment_set_property (LocationRouteSegment *segment, gconstpointer key, gconstpointer value) +{ + g_return_val_if_fail (segment, FALSE); + g_return_val_if_fail (key, FALSE); + if (!segment->properties) return FALSE; + + if (value) { + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert(segment->properties, re_key, re_val); + } else g_hash_table_remove (segment->properties, key); + + return TRUE; +} + +static void route_step_foreach_free (gpointer data) +{ + g_return_if_fail (data); + + LocationRouteStep *step = (LocationRouteStep *) data; + + location_route_step_free(step); +} + +static void route_step_foreach_copy (gpointer data, gpointer user_data) +{ + g_return_if_fail (data); + g_return_if_fail (user_data); + + LocationRouteStep *step = (LocationRouteStep *) data; + LocationRouteSegment *segment = (LocationRouteSegment *) user_data; + + LocationRouteStep *step_new = location_route_step_copy(step); + segment->step = g_list_append(segment->step, step_new); + +} + +EXPORT_API gboolean +location_route_segment_set_route_step (LocationRouteSegment *segment, GList* step) +{ + g_return_val_if_fail (segment, FALSE); + + if (segment->step) { + g_list_free_full (segment->step, route_step_foreach_free); + segment->step = NULL; + } + + if (step) g_list_foreach (step, route_step_foreach_copy, segment); + + return TRUE; + +} + +EXPORT_API LocationRouteSegment * +location_route_segment_new (void) +{ + LocationRouteSegment *segment = g_slice_new0 (LocationRouteSegment); + g_return_val_if_fail (segment, NULL); + + segment->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + + return segment; +} + +static void segment_property_copy_cb (gpointer key, gpointer value, gpointer user_data) +{ + g_return_if_fail (key); + g_return_if_fail (value); + g_return_if_fail (user_data); + + LocationRouteSegment *segment = (LocationRouteSegment *)user_data; + + if (segment->properties) { + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert (segment->properties, re_key, re_val); + } +} + +EXPORT_API LocationRouteSegment * +location_route_segment_copy (LocationRouteSegment *segment) +{ + g_return_val_if_fail(segment, NULL); + + LocationRouteSegment *new_segment = location_route_segment_new(); + g_return_val_if_fail(new_segment, NULL); + + location_route_segment_set_start_point(new_segment, location_route_segment_get_start_point(segment)); + location_route_segment_set_end_point(new_segment, location_route_segment_get_end_point(segment)); + location_route_segment_set_bounding_box(new_segment, location_route_segment_get_bounding_box(segment)); + location_route_segment_set_distance(new_segment, location_route_segment_get_distance(segment)); + location_route_segment_set_duration(new_segment, location_route_segment_get_duration(segment)); + location_route_segment_set_route_step(new_segment, location_route_segment_get_route_step(segment)); + + if (segment->properties) g_hash_table_foreach (segment->properties, segment_property_copy_cb, new_segment); + + return new_segment; +} + +EXPORT_API void +location_route_segment_free (LocationRouteSegment *segment) +{ + g_return_if_fail(segment); + + location_route_segment_set_start_point(segment, NULL); + location_route_segment_set_end_point(segment, NULL); + location_route_segment_set_bounding_box(segment, NULL); + location_route_segment_set_distance(segment, 0.0); + location_route_segment_set_duration(segment, 0); + location_route_segment_set_route_step(segment, NULL); + + if (segment->properties) { + g_hash_table_destroy (segment->properties); + segment->properties = NULL; + } + + g_slice_free(LocationRouteSegment, segment); +} + +EXPORT_API LocationPosition* +location_route_step_get_start_point (const LocationRouteStep *step) +{ + g_return_val_if_fail(step, NULL); + + return step->start; +} + +EXPORT_API LocationPosition* +location_route_step_get_end_point (const LocationRouteStep *step) +{ + g_return_val_if_fail(step, NULL); + + return step->end; +} + +EXPORT_API LocationBoundary* +location_route_step_get_bounding_box (const LocationRouteStep *step) +{ + g_return_val_if_fail(step, NULL); + + return step->bbox; +} + +EXPORT_API gdouble +location_route_step_get_distance (const LocationRouteStep *step) +{ + g_return_val_if_fail(step, 0.0); + + return step->distance; +} + +EXPORT_API glong +location_route_step_get_duration (const LocationRouteStep *step) +{ + g_return_val_if_fail(step, 0); + + return step->duration; +} + +EXPORT_API gchar* +location_route_step_get_transport_mode (const LocationRouteStep *step) +{ + g_return_val_if_fail(step, NULL); + + return step->transport_mode; +} + +EXPORT_API gchar* +location_route_step_get_instruction (const LocationRouteStep *step) +{ + g_return_val_if_fail(step, NULL); + + return step->instruction; +} + +EXPORT_API GList * +location_route_step_get_geometry (const LocationRouteStep *step) +{ + g_return_val_if_fail(step, NULL); + + return step->geometry; +} + +EXPORT_API GList* +location_route_step_get_property_key (const LocationRouteStep *step) +{ + g_return_val_if_fail(step, NULL); + + return g_hash_table_get_keys (step->properties); +} + +EXPORT_API gpointer +location_route_step_get_property (const LocationRouteStep *step, gconstpointer key) +{ + g_return_val_if_fail(step, NULL); + g_return_val_if_fail(key, NULL); + + return g_hash_table_lookup (step->properties, key); +} + +EXPORT_API gboolean +location_route_step_set_start_point (LocationRouteStep *step, const LocationPosition *start) +{ + g_return_val_if_fail (step, FALSE); + + if (step->start) { + location_position_free (step->start); + step->start = NULL; + } + + if (start) step->start = location_position_copy (start); + + return TRUE; +} + +EXPORT_API gboolean +location_route_step_set_end_point (LocationRouteStep *step, const LocationPosition *end) +{ + g_return_val_if_fail (step, FALSE); + + if (step->end) { + location_position_free (step->end); + step->end = NULL; + } + + if (end) step->end = location_position_copy (end); + + return TRUE; +} + +EXPORT_API gboolean +location_route_step_set_bounding_box (LocationRouteStep *step, const LocationBoundary *bbox) +{ + g_return_val_if_fail (step, FALSE); + + if (step->bbox) { + location_boundary_free (step->bbox); + step->bbox = NULL; + } + + if (bbox) step->bbox = location_boundary_copy (bbox); + + return TRUE; +} + +EXPORT_API gboolean +location_route_step_set_distance (LocationRouteStep *step, gdouble distance) +{ + g_return_val_if_fail (step, FALSE); + + step->distance = distance; + + return TRUE; + +} + +EXPORT_API gboolean +location_route_step_set_duration (LocationRouteStep *step, glong duration) +{ + g_return_val_if_fail (step, FALSE); + + step->duration = duration; + + return TRUE; +} + +EXPORT_API gboolean +location_route_step_set_transport_mode (LocationRouteStep *step, const gchar *transport_mode) +{ + g_return_val_if_fail (step, FALSE); + + if (step->transport_mode) { + g_free(step->transport_mode); + step->transport_mode = NULL; + } + + if (transport_mode) step->transport_mode = g_strdup(transport_mode); + + return TRUE; + +} + +EXPORT_API gboolean +location_route_step_set_instruction (LocationRouteStep *step, const gchar *instruction) +{ + g_return_val_if_fail (step, FALSE); + + if (step->instruction) { + g_free(step->instruction); + step->instruction = NULL; + } + + if (instruction) step->instruction = g_strdup(instruction); + + return TRUE; + +} + +static void route_step_geometry_foreach_copy (gpointer data, gpointer user_data) +{ + g_return_if_fail (data); + g_return_if_fail (user_data); + + LocationPosition *pos = (LocationPosition *)data; + LocationRouteStep *step = (LocationRouteStep *)user_data; + + step->geometry = g_list_append (step->geometry, location_position_copy (pos)); +} + +static void route_step_geometry_free (gpointer data) +{ + g_return_if_fail (data); + + LocationPosition *pos = (LocationPosition *)data; + + location_position_free(pos); +} + +EXPORT_API gboolean +location_route_step_set_geometry (LocationRouteStep *step, GList *geometry) +{ + g_return_val_if_fail (step, FALSE); + + if (step->geometry) { + g_list_free_full (step->geometry, route_step_geometry_free); + step->geometry = NULL; + } + + if (geometry) g_list_foreach (geometry, route_step_foreach_copy, step); + + return TRUE; + +} + +EXPORT_API gboolean +location_route_step_set_property (LocationRouteStep *step, gconstpointer key, gconstpointer value) +{ + g_return_val_if_fail(step, FALSE); + g_return_val_if_fail(key, FALSE); + + if (!step->properties) return FALSE; + + if (value) { + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert (step->properties, re_key, re_val); + } + else g_hash_table_remove (step->properties, key); + + return TRUE; +} + +EXPORT_API LocationRouteStep * +location_route_step_new (void) +{ + LocationRouteStep *step = g_slice_new0 (LocationRouteStep); + g_return_val_if_fail(step, NULL); + + step->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + + return step; +} + +static void step_property_copy_cb (gpointer key, gpointer value, gpointer user_data) +{ + g_return_if_fail (key); + g_return_if_fail (value); + g_return_if_fail (user_data); + + LocationRouteStep *step = (LocationRouteStep *) user_data; + + if (step->properties) { + gchar *re_key = g_strdup (key); + gchar *re_val = g_strdup (value); + g_hash_table_insert (step->properties, re_key, re_val); + } +} + + +EXPORT_API LocationRouteStep * +location_route_step_copy (LocationRouteStep *step) +{ + g_return_val_if_fail(step, NULL); + + LocationRouteStep *new_step = location_route_step_new (); + g_return_val_if_fail (new_step, NULL); + + location_route_step_set_start_point (new_step, location_route_step_get_start_point(step)); + location_route_step_set_end_point (new_step, location_route_step_get_end_point(step)); + location_route_step_set_bounding_box (new_step, location_route_step_get_bounding_box(step)); + location_route_step_set_distance (new_step, location_route_step_get_distance(step)); + location_route_step_set_duration (new_step, location_route_step_get_duration(step)); + location_route_step_set_instruction (new_step, location_route_step_get_instruction(step)); + location_route_step_set_geometry (new_step, location_route_step_get_geometry(step)); + + if (step->properties) g_hash_table_foreach (step->properties, step_property_copy_cb, new_step); + return new_step; +} + +EXPORT_API void +location_route_step_free (LocationRouteStep *step) +{ + g_return_if_fail(step); + + location_route_step_set_start_point (step, NULL); + location_route_step_set_end_point (step, NULL); + location_route_step_set_bounding_box (step, NULL); + location_route_step_set_distance (step, 0.0); + location_route_step_set_duration (step, 0); + location_route_step_set_instruction (step, NULL); + location_route_step_set_geometry (step, NULL); + + if (step->properties) { + g_hash_table_destroy (step->properties); + step->properties = NULL; + } + g_slice_free(LocationRouteStep, step); +} diff --git a/location/map-service/location-route.h b/location/map-service/location-route.h new file mode 100644 index 0000000..8bd8fa7 --- /dev/null +++ b/location/map-service/location-route.h @@ -0,0 +1,873 @@ +/* + * libslp-location + * + * 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_ROUTE_H__ +#define __LOCATION_ROUTE_H__ + +#include + +G_BEGIN_DECLS + +/** + * @file location-route.h + * @brief This file contains the internal definitions and structures related to Route. + */ + +/** + * @addtogroup LocationMapService + * @{ + * @defgroup LocationMapServiceRoute Location Route + * @brief This is a Location Route for providing location map services. + * @addtogroup LocationMapServiceRoute + * @{ + */ + +/** + * @brief Create a new Location route preference + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @return a #LocationRoutePreference + * @retval NULL if error occured + * @see location_route_pref_free + */ +LocationRoutePreference *location_route_pref_new (void); + +/** + * @brief Copy Location route preference + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return a new #LocationRoutePreference + * @retval NULL if error occured + */ +LocationRoutePreference *location_route_pref_copy (const LocationRoutePreference *pref); + +/** + * @brief Free Location route preference + * @remarks None. + * @pre #location_init should be called before.\n + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @see location_route_pref_new + * @return None + * @retval None + */ +void location_route_pref_free (LocationRoutePreference * pref); + +/** + * @brief Get a list of address structures to be avoided in Location route preference + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return GList + * @retval list of #LocationAddress + * @see location_route_pref_set_addr_to_avoid + */ +GList *location_route_pref_get_addr_to_avoid (const LocationRoutePreference *pref); + +/** + * @brief Get a list of area to be avoided in Location route preference + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return GList + * @retval list of #LocationBoundary + * @see location_route_pref_set_area_to_avoid + */ +GList *location_route_pref_get_area_to_avoid (const LocationRoutePreference *pref); + +/** + * @brief Get a list of features to be avoided in Location route preference + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return GList + * @retval list of gchar + * @see location_route_pref_set_feature_to_avoid + */ +GList *location_route_pref_get_feature_to_avoid (const LocationRoutePreference *pref); + +/** + * @brief Get a list of freeformed address to be avoided in Location route preference + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return GList + * @retval list of gchar + * @see location_route_pref_set_freeformed_to_avoid + */ +GList *location_route_pref_get_freeformed_addr_to_avoid (const LocationRoutePreference *pref); + +/** + * @brief Get a list of bounding box to be avoided in Location route preference + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return #LocationBoundary + * @retval bounding box + * @see location_route_pref_set_addr_to_avoid + */ +LocationBoundary *location_route_pref_get_bounding_box (const LocationRoutePreference *pref); + +/** + * @brief Get a maximum number of matches returned from route service provider + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return guint + * @retval maximum number of matches + * @see location_route_pref_set_max_result + */ +guint location_route_pref_get_max_result (const LocationRoutePreference *pref); + +/** + * @brief Get a route type to be used in route service + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return gchar + * @retval route type + * @see location_route_pref_set_route_type + */ +gchar *location_route_pref_get_route_type (const LocationRoutePreference *pref); + +/** + * @brief Get a transport mode to be used in route service + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return gchar + * @retval transport mode + * @see location_route_pref_set_transport_mode + */ +gchar *location_route_pref_get_transport_mode (const LocationRoutePreference *pref); + +/** + * @brief Get whether the route service provider must provide the route geometry in the service requests + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return gboolean + * @retval TRUE if used + * @see location_route_pref_set_geometry_used + */ +gboolean location_route_pref_get_geometry_used (const LocationRoutePreference *pref); +/** + * @brief Get whether the route service provider must provide the route instruction bounding box in the service requests + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return gboolean + * @retval TRUE if used + * @see location_route_pref_set_instruction_bounding_box_used + */ +gboolean location_route_pref_get_instruction_bounding_box_used (const LocationRoutePreference *pref); +/** + * @brief Get whether the route service provider must provide the route geometry in the service requests + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return gboolean + * @retval TRUE if used + * @see location_route_pref_set_instruction_geometry_used + */ +gboolean location_route_pref_get_instruction_geometry_used (const LocationRoutePreference *pref); + +/** + * @brief Get whether the route service provider must provide the route instruction in the service requests + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return gboolean + * @retval TRUE if used + * @see location_route_pref_set_instruction_used + */ +gboolean location_route_pref_get_instruction_used (const LocationRoutePreference *pref); +/** + * @brief Get whether the route service provider must provide traffic data in the service requests + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return gboolean + * @retval TRUE if used + * @see location_route_pref_set_traffic_data_used + */ +gboolean location_route_pref_get_traffic_data_used (const LocationRoutePreference *pref); +/** + * @brief Get a list of Property Keys in #LocationRoutePreference + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return GList + * @retval list of property key + */ +GList *location_route_pref_get_property_key (const LocationRoutePreference *pref); +/** + * @brief Get Property value in #LocationRoutePreference + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @return GList + * @retval property value + * @see location_route_pref_set_property + */ +gpointer location_route_pref_get_property (const LocationRoutePreference *pref, gconstpointer key); + +/** + * @brief Set a list of address structures to be avoided in #LocationRoutePreference + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] addr - a list of #LocationAddress + * @return gboolean + * @retval TRUE if success + * @see location_route_pref_get_addr_to_avoid + */ +gboolean location_route_pref_set_addr_to_avoid (LocationRoutePreference * pref, GList *addr); + +/** + * @brief Set a list of area to be avoided in Location route preference + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] area - a list of #LocationBoundary + * @return gboolean + * @retval TRUE if success + * @see location_route_pref_get_area_to_avoid + */ +gboolean location_route_pref_set_area_to_avoid (LocationRoutePreference * pref, GList *area); + +/** + * @brief Set a list of features to be avoided in Location route preference + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] feature - a list of features + * @return gboolean + * @retval TRUE if success + * @see location_route_pref_get_feature_to_avoid + */ +gboolean location_route_pref_set_feature_to_avoid (LocationRoutePreference * pref, GList * feature); + +/** + * @brief Set a list of freeformed address to be avoided in Location route preference + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] addr - a list of #gchar + * @return gboolean + * @retval TRUE if success + * @see location_route_pref_get_freeformed_addr_to_avoid + */ +gboolean location_route_pref_set_freeformed_addr_to_avoid (LocationRoutePreference *pref, GList * freeformed_addr); + +/** + * @brief Set a bounding box #LocationBoundary in Location route preference + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] bbox - a #LocationBoundary + * @return gboolean + * @retval TRUE if success + * @see location_route_pref_get_bounding_box + */ +gboolean location_route_pref_set_bounding_box (LocationRoutePreference *pref, const LocationBoundary *boundary); + +/** + * @brief Set a maximum number of matches returned from route service provider + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] max_num - a #gint + * @return gboolean + * @retval TRUE if success + * @see location_route_pref_set_max_result + */ +gboolean location_route_pref_set_max_result (LocationRoutePreference *pref, guint max_num); + +/** + * @brief Set a route type to be used in route service + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] type - a #gchar + * @return gboolean + * @retval TRUE if success + * @see location_route_pref_get_route_type + */ +gboolean location_route_pref_set_route_type (LocationRoutePreference *pref, const gchar *type); + +/** + * @brief Set a transport mode to be used in route service + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] mode - a #gchar + * @return gboolean + * @retval TRUE if success + * @see location_route_pref_get_transport_mode + */ +gboolean location_route_pref_set_transport_mode (LocationRoutePreference *pref, const gchar * mode); + +/** + * @brief Set whether the route service provider must provide the route geometry in the service requests + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] is_used - a #gboolean + * @return gboolean + * @retval TRUE if success + * @see location_route_pref_get_geometry_used + */ +gboolean location_route_pref_set_geometry_used (LocationRoutePreference *pref, gboolean is_used); + +/** + * @brief Set whether the route service provider must provide the route instruction bounding box in the service requests + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] is_used - a #gboolean + * @return gboolean + * @retval TRUE if success + * @see location_route_pref_get_instruction_bounding_box_used + */ +gboolean location_route_pref_set_instruction_bounding_box_used (LocationRoutePreference *pref, gboolean is_used); + +/** + * @brief Set whether the route service provider must provide the route geometry in the service requests + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] is_used - a #gboolean + * @return gboolean + * @retval TRUE if success + * @see location_route_pref_get_instruction_geometry_used + */ +gboolean location_route_pref_set_instruction_geometry_used (LocationRoutePreference *pref, gboolean is_used); + +/** + * @brief Set whether the route service provider must provide the route instruction in the service requests + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] is_used - a #gboolean + * @return gboolean + * @retval TRUE if success + * @see location_route_pref_get_instruction_used + */ +gboolean location_route_pref_set_instruction_used (LocationRoutePreference *pref, gboolean is_used); + +/** + * @brief Set whether the route service provider must provide traffic data in the service requests + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] is_used - a #gboolean + * @return #gboolean + * @retval TRUE if success + * @see location_route_pref_get_traffic_data_used + */ +gboolean location_route_pref_set_traffic_data_used (LocationRoutePreference *pref, gboolean is_used); + +/** + * @brief Set Property in Location route proference + * @remarks The service provider should support route service. + * @pre #location_route_pref_new should be called before. + * @post None. + * @param [in] pref - a #LocationRoutePreference + * @param [in] key - a #gconstpointer + * @param [in] value - a #gconstpointer + * @return gboolean + * @retval TRUE if success + * @see location_route_pref_get_property + */ +gboolean location_route_pref_set_property (LocationRoutePreference *pref, gconstpointer key, gconstpointer value); + +/** + * @defgroup LocationMapServiceRouteResult Location Route Result + * @brief This provides structure, enumeration and APIs for Route Result + * @addtogroup LocationMapServiceRouteResult + * @{ + */ +/** + * @brief Create a new Location route + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @return #LocationRoute + * @retval a new location route + * @see location_route_free + */ +LocationRoute *location_route_new (void); +/** + * @brief Copy Location route + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @return #LocationRoute + * @retval a copied location route + */ +LocationRoute *location_route_copy (const LocationRoute *route); + +/** + * @brief Free #LocationRoute + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @return void + * @retval None + */ +void location_route_free (LocationRoute *route); + +/** + * @brief Get the origin of Location route + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @return #Location position + * @retval origin + * @see location_route_set_origin + */ +LocationPosition *location_route_get_origin (const LocationRoute *route); + +/** + * @brief Get the destination of Location route + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @return #LocationPosition + * @retval destination + * @see location_route_set_destination + */ +LocationPosition *location_route_get_destination (const LocationRoute *route); + +/** + * @brief Get the bounding box of Location route + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @return #LocationBoundary + * @retval bounding box + * @see location_route_set_bounding box + */ +LocationBoundary *location_route_get_bounding_box (const LocationRoute *route); + +/** + * @brief Get the total distance of Location route + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @return gdouble + * @retval total distance + * @see location_route_set_total_distance + */ +gdouble location_route_get_total_distance (const LocationRoute *route); + +/** + * @brief Get the distance unit of Location route + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @return gchar + * @retval distance unit + * @see location_route_set_distance_unit + */ +gchar *location_route_get_distance_unit (const LocationRoute *route); + +/** + * @brief Get the total duration of location route + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @return glong + * @retval total duration + * @see location_route_set_total_duration + */ +glong location_route_get_total_duration (const LocationRoute *route); + +/** + * @brief Get the list of property key of Location route + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @return GList + * @retval list of property keys + * @see location_route_set_property + */ +GList *location_route_get_property_key (const LocationRoute *route); + +/** + * @brief Get the property value of Location route + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] route - a #LocationRoute + * @return gconstpointer + * @retval property + * @see location_route_set_property + */ +gpointer location_route_get_property (const LocationRoute *route, gconstpointer key); + +/** + * @brief Get the list of segments in Location route + * @remarks The service provider should support route service. + * @post None. + * @pre None. + * @param [in] route - a #LocationRoute + * @return GList + * @retval list of #LocationRouteSegment + * @see location_route_set_route_segment + */ +GList *location_route_get_route_segment (const LocationRoute *route); + +/** + * @brief Create a new Location route segment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @return #LocationPositionSegment + * @retval Location route segment + * @see location_route_segment_free + */ +LocationRouteSegment *location_route_segment_new (void); + +/** + * @brief Copy Location route segment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @return #LocationRouteSegment + * @retval copied Location route segment + */ +LocationRouteSegment *location_route_segment_copy (LocationRouteSegment *segment); + +/** + * @brief Free Location route segment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @return void + * @retval None. + * @see location_route_segment_new + */ +void location_route_segment_free (LocationRouteSegment *segment); + +/** + * @brief Get the start point #LocationPosition of #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @return void + * @retval None. + * @see location_route_segment_set_start_point + */ +LocationPosition *location_route_segment_get_start_point (const LocationRouteSegment *segment); + +/** + * @brief Get the end point #LocationPosition of #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @return void + * @retval None. + * @see location_route_segment_set_end_point + */ +LocationPosition *location_route_segment_get_end_point (const LocationRouteSegment *segment); + +/** + * @brief Get the bounding box #LocationBoundary of #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @return void + * @retval None. + * @see location_route_segment_set_bounding_box + */ +LocationBoundary *location_route_segment_get_bounding_box (const LocationRouteSegment *segment); + +/** + * @brief Get the distance of #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @return void + * @retval None. + * @see location_route_segment_set_distance + */ +gdouble location_route_segment_get_distance (const LocationRouteSegment *segment); + +/** + * @brief Get the duration #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @return void + * @retval None. + * @see location_route_segment_set_duration + */ +glong location_route_segment_get_duration (const LocationRouteSegment *segment); + +/** + * @brief Get the list of property keys of #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @return void + * @retval None. + * @see location_route_segment_set_property_key + */ +GList *location_route_segment_get_property_key (const LocationRouteSegment *segment); + +/** + * @brief Get the property value of #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @return void + * @retval None. + * @see location_route_segment_set_property + */ +gpointer location_route_segment_get_property (const LocationRouteSegment *segment, gconstpointer key); + +/** + * @brief Get the list of route steps #LocationRouteStep in #LocationRouteSegment + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] segment - a #LocationRouteSegment + * @return void + * @retval None. + * @see location_route_segment_set_route_step + */ +GList *location_route_segment_get_route_step (const LocationRouteSegment *segment); + +/** + * @brief Create a new #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param None. + * @return #LocationRouteStep + * @retval route step + * @see location_route_step_free + */ +LocationRouteStep *location_route_step_new (void); + +/** + * @brief Copy #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @return #LocationRouteStep + * @retval route step + * @see location_route_step_new + */ +LocationRouteStep *location_route_step_copy (LocationRouteStep *step); + +/** + * @brief Free #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @return void + * @retval None + * @see location_route_step_new + */ +void location_route_step_free (LocationRouteStep *step); + +/** + * @brief Get the start point #LocationPosition of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @return #LocationPosition + * @retval start point + * @see location_route_step_set_start_point + */ +LocationPosition *location_route_step_get_start_point (const LocationRouteStep *step); + +/** + * @brief Get the end point #LocationPosition of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @return #LocationPosition + * @retval end point + * @see location_route_step_set_end_point + */ +LocationPosition *location_route_step_get_end_point (const LocationRouteStep *step); + +/** + * @brief Get the bounding box #LocationBoundary of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @return #LocationBoundary + * @retval bounding box + * @see location_route_step_set_bounding_box + */ +LocationBoundary *location_route_step_get_bounding_box (const LocationRouteStep *step); + +/** + * @brief Get the distance of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @return gboolean + * @retval distance + * @see location_route_step_set_distance + */ +gdouble location_route_step_get_distance (const LocationRouteStep *step); + +/** + * @brief Get the duration of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @return glong + * @retval duration + * @see location_route_step_set_duration + */ +glong location_route_step_get_duration (const LocationRouteStep *step); + +/** + * @brief Get the transport mode of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @return gchar + * @retval transport mode + * @see location_route_step_set_transport_mode + */ +gchar *location_route_step_get_transport_mode (const LocationRouteStep *step); + +/** + * @brief Get the instruction of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @return gchar + * @retval instruction + * @see location_route_step_set_instruction + */ +gchar *location_route_step_get_instruction (const LocationRouteStep *step); + +/** + * @brief Get the list of geometry #LocationPosition of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @return GList + * @retval a list of LocationPosition + * @see location_route_step_set_geometry + */ +GList *location_route_step_get_geometry (const LocationRouteStep *step); + +/** + * @brief Get the list of property key of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @return GList + * @retval a list of property key + * @see location_route_step_set_property_key + */ +GList *location_route_step_get_property_key (const LocationRouteStep *step); + +/** + * @brief Get the property value of #LocationRouteStep + * @remarks The service provider should support route service. + * @pre None. + * @post None. + * @param [in] step - a #LocationRouteStep + * @param [in] key - a gconstpointer + * @return gpointer + * @retval value + * @see location_route_step_set_property + */ +gpointer location_route_step_get_property (const LocationRouteStep *step, gconstpointer key); + +/** + * @} @} @} + */ + +G_END_DECLS + +#endif diff --git a/location/map-service/map-internal.c b/location/map-service/map-internal.c new file mode 100644 index 0000000..0fcc499 --- /dev/null +++ b/location/map-service/map-internal.c @@ -0,0 +1,235 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "location-log.h" +#include "location-types.h" +#include "module-internal.h" +#include "location-route.h" +#include "location-ielement.h" +#include "map-service.h" + +int +map_service_get_geocode (LocationIElement *self, + const LocationAddress *address, + GList **position_list, + GList **accuracy_list) +{ + LOCATION_LOGD("map_service_get_geocode"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.get_geocode, LOCATION_ERROR_NOT_AVAILABLE); + return (priv->mod->ops.get_geocode)(priv->mod->handler, address, position_list, accuracy_list); +} + +int +map_service_get_geocode_freeform (LocationIElement *self, + const gchar *address, + GList **position_list, + GList **accuracy_list) +{ + LOCATION_LOGD("map_service_get_geocode_freeform"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.get_geocode_freetext, LOCATION_ERROR_NOT_AVAILABLE); + return (priv->mod->ops.get_geocode_freetext)(priv->mod->handler, address, position_list, accuracy_list); +} + +int +map_service_get_reversegeocode (LocationIElement *self, + const LocationPosition *position, + LocationAddress **address, + LocationAccuracy **accuracy) +{ + LOCATION_LOGD("map_service_get_reversegeocode"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.get_reverse_geocode, LOCATION_ERROR_NOT_AVAILABLE); + return (priv->mod->ops.get_reverse_geocode)(priv->mod->handler, position, address, accuracy); +} + +int +map_service_get_geocode_async (LocationIElement *self, + LocationAddress *address, + LocationPositionCB callback, + gpointer userdata) +{ + LOCATION_LOGD("map_service_get_geocode_async"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.get_geocode_async, LOCATION_ERROR_NOT_AVAILABLE); + return (priv->mod->ops.get_geocode_async)(priv->mod->handler, address, callback, userdata); +} + +int +map_service_get_geocode_freeform_async (LocationIElement *self, + const gchar *address, + LocationPositionCB callback, + gpointer userdata) +{ + LOCATION_LOGD("map_service_get_geocode_freeform_async"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.get_geocode_freetext_async, LOCATION_ERROR_NOT_AVAILABLE); + return (priv->mod->ops.get_geocode_freetext_async)(priv->mod->handler, address, callback, userdata); +} + +int +map_service_get_reversegeocode_async (LocationIElement *self, + const LocationPosition *position, + LocationAddressCB callback, + gpointer userdata) +{ + LOCATION_LOGD("map_service_get_reversegeocode_async"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.get_reverse_geocode_async, LOCATION_ERROR_NOT_AVAILABLE); + return (priv->mod->ops.get_reverse_geocode_async)(priv->mod->handler, position, callback, userdata); +} + +int +map_service_search_poi (LocationIElement *self, + const LocationPOIFilter *filter, const LocationPosition *position, + const LocationPreference *svc_pref, const LocationPOIPreference *pref, + LocationPOICB cb, const gpointer user_data, guint *req_id) +{ + LOCATION_LOGD("map_service_search_poi"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.search_poi, LOCATION_ERROR_NOT_AVAILABLE); + return (priv->mod->ops.search_poi)(priv->mod->handler, filter, position, svc_pref, pref, cb, user_data, req_id); +} + +int +map_service_search_poi_by_area (LocationIElement *self, + const LocationPOIFilter * filter, const LocationBoundary *boundary, + const LocationPreference *svc_pref, const LocationPOIPreference * pref, + LocationPOICB cb, const gpointer user_data, guint *req_id) +{ + LOCATION_LOGD("map_service_search_poi_by_area"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.search_poi_by_area, LOCATION_ERROR_NOT_AVAILABLE); + return (priv->mod->ops.search_poi_by_area)(priv->mod->handler, filter, boundary, svc_pref, pref, cb, user_data, req_id); +} + +int +map_service_search_poi_by_address (LocationIElement *self, + const LocationPOIFilter *filter, const LocationAddress *address, + const LocationPreference *svc_pref, const LocationPOIPreference *pref, + LocationPOICB cb, const gpointer user_data, guint *req_id) +{ + LOCATION_LOGD("map_service_search_poi_by_address"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.search_poi_by_address, LOCATION_ERROR_NOT_AVAILABLE); + return (priv->mod->ops.search_poi_by_address)(priv->mod->handler, filter, address, svc_pref, pref, cb, user_data, req_id); +} + +int +map_service_search_poi_by_freeform (LocationIElement *self, + const LocationPOIFilter *filter, const gchar *freeform, + const LocationPreference *svc_pref, const LocationPOIPreference *pref, + LocationPOICB cb, const gpointer user_data, guint *req_id) +{ + LOCATION_LOGD("map_service_search_poi_by_freeform"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.search_poi_by_freeform, LOCATION_ERROR_NOT_AVAILABLE); + return (priv->mod->ops.search_poi_by_freeform)(priv->mod->handler, filter, freeform, svc_pref, pref, cb, user_data, req_id); +} + +int +map_service_cancel_poi_request (LocationIElement *self, guint req_id) +{ + LOCATION_LOGD("map_service_cancel_poi_request"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.cancel_poi_request, LOCATION_ERROR_NOT_AVAILABLE); + return (priv->mod->ops.cancel_poi_request)(priv->mod->handler, req_id); +} + + +int +map_service_request_route (LocationIElement *self, + const LocationPosition *origin, const LocationPosition *destination, GList *waypoint, + const LocationPreference *svc_pref, const LocationRoutePreference * pref, + LocationRouteCB cb, const gpointer user_data, guint * req_id) +{ + LOCATION_LOGD("map_service_request_route"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.request_route, LOCATION_ERROR_NOT_AVAILABLE); + + return (priv->mod->ops.request_route)(priv->mod->handler, origin, destination, waypoint, svc_pref, pref, cb, user_data, req_id); +} + +int +map_service_cancel_route_request (LocationIElement *self, guint req_id) +{ + LOCATION_LOGD("map_service_cancel_route_request"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.cancel_route_request, LOCATION_ERROR_NOT_AVAILABLE); + + return (priv->mod->ops.cancel_route_request)(priv->mod->handler, req_id); +} + +gboolean +map_service_is_supported_map_provider_capability (LocationIElement *self, LocationMapServiceType type) +{ + LOCATION_LOGD("map_service_is_supported_map_provider_capability"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.is_supported_map_provider_capability, LOCATION_ERROR_NOT_AVAILABLE); + + return (priv->mod->ops.is_supported_map_provider_capability)(priv->mod->handler, type); +} + +int +map_service_get_map_provider_capability_key (LocationIElement *self, LocationMapServiceType type, GList **key) +{ + LOCATION_LOGD("map_service_get_map_provider_capability_key"); + MapServicePrivate* priv = GET_PRIVATE(self); + g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail (priv->mod->ops.get_map_provider_capability_key, LOCATION_ERROR_NOT_AVAILABLE); + + return (priv->mod->ops.get_map_provider_capability_key)(priv->mod->handler, type, key); +} + diff --git a/location/map-service/map-internal.h b/location/map-service/map-internal.h new file mode 100644 index 0000000..09aded7 --- /dev/null +++ b/location/map-service/map-internal.h @@ -0,0 +1,82 @@ +/* + * libslp-location + * + * 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 __MAP_INTERNAL_H__ +#define __MAP_INTERNAL_H__ + +#include "location-types.h" +#include "location-ielement.h" + +/** + * @file map-internal.h + * @brief This file contains the internal definitions and structures related to geocode. + */ + +G_BEGIN_DECLS + +int map_service_get_geocode (LocationIElement *self, const LocationAddress *address, GList **position_list, GList **accuracy_list); + +int map_service_get_geocode_freeform (LocationIElement *self, const gchar *address, GList **position_list, GList **accuracy_list); + +int map_service_get_reversegeocode (LocationIElement *self, const LocationPosition *position, LocationAddress **address, LocationAccuracy **accuracy); + +int map_service_get_geocode_async (LocationIElement *self, LocationAddress *address, LocationPositionCB callback, gpointer userdata); + +int map_service_get_geocode_freeform_async (LocationIElement *self, const gchar *address, LocationPositionCB callback, gpointer userdata); + +int map_service_get_reversegeocode_async (LocationIElement *self, const LocationPosition *position, LocationAddressCB callback, gpointer userdata); + +int map_service_search_poi (LocationIElement *self, + const LocationPOIFilter *filter, const LocationPosition *position, + const LocationPreference *svc_pref, const LocationPOIPreference *pref, + LocationPOICB cb, const gpointer user_data, guint * req_id); + +int map_service_search_poi_by_area (LocationIElement *self, + const LocationPOIFilter *filter, const LocationBoundary *boundary, + const LocationPreference *svc_pref, const LocationPOIPreference *pref, + LocationPOICB cb, const gpointer user_data, guint * req_id); + +int map_service_search_poi_by_address (LocationIElement *self, + const LocationPOIFilter *filter, const LocationAddress *address, + const LocationPreference *svc_pref, const LocationPOIPreference *pref, + LocationPOICB cb, const gpointer user_data, guint * req_id); + +int map_service_search_poi_by_freeform (LocationIElement *self, + const LocationPOIFilter * filter, const gchar *freeform, + const LocationPreference *svc_pref, const LocationPOIPreference *pref, + LocationPOICB cb, const gpointer user_data, guint *req_id); + +int map_service_cancel_poi_request (LocationIElement *self, guint req_id); + +int map_service_request_route (LocationIElement *self, + const LocationPosition *origin, const LocationPosition *destination, GList *waypoint, + const LocationPreference *svc_pref, const LocationRoutePreference *pref, + LocationRouteCB cb, const gpointer user_data, guint * req_id); + +int map_service_cancel_route_request (LocationIElement *self, guint req_id); + +gboolean map_service_is_supported_map_provider_capability (LocationIElement *self, LocationMapServiceType type); + +int map_service_get_map_provider_capability_key (LocationIElement *self, LocationMapServiceType type, GList **key); + +G_END_DECLS + +#endif diff --git a/location/map-service/map-service.c b/location/map-service/map-service.c new file mode 100644 index 0000000..6c811b6 --- /dev/null +++ b/location/map-service/map-service.c @@ -0,0 +1,209 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include "location-log.h" +#include "location-pref.h" + +#include "module-internal.h" + +#include "map-internal.h" +#include "map-service.h" +#include "location-ielement.h" + +enum { + PROP_0, + PROP_SERVICE_NAME +}; + +static void map_service_ielement_interface_init (LocationIElementInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (MapService, map_service, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, map_service_ielement_interface_init)); + +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); + LOCATION_LOGD("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); + } + LOCATION_LOGD("Language: %s, Country: %s", lang_code, country_code); +} + + +static void +map_service_dispose (GObject *gobject) +{ + LOCATION_LOGD("map_service_dispose"); + + G_OBJECT_CLASS (map_service_parent_class)->dispose (gobject); +} + +static void +map_service_finalize (GObject *gobject) +{ + LOCATION_LOGD("map_service_finalize"); + MapServicePrivate* priv = GET_PRIVATE(gobject); + module_free(priv->mod, "map-service"); + priv->mod = NULL; + G_OBJECT_CLASS (map_service_parent_class)->finalize (gobject); +} + +static void +map_service_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + MapServicePrivate *priv = GET_PRIVATE (object); + + g_return_if_fail(priv->mod); + g_return_if_fail(priv->mod->handler); + switch (property_id){ + case PROP_SERVICE_NAME:{ + char* service_name = NULL; + if(priv->mod->ops.get_service_name){ + if( LOCATION_ERROR_NONE != priv->mod->ops.get_service_name(priv->mod->handler, &service_name) ){ + service_name = NULL; + } + } + LOCATION_LOGD("Get prop>> Service name: %s", service_name); + g_value_set_string(value, service_name); + g_free(service_name); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +map_service_ielement_interface_init (LocationIElementInterface *iface) +{ + iface->get_geocode = (TYPE_GET_GEOCODE)map_service_get_geocode; + iface->get_geocode_freeform = (TYPE_GET_GEOCODE_FREEFORM)map_service_get_geocode_freeform; + iface->get_reversegeocode = (TYPE_GET_REVERSEGEOCODE)map_service_get_reversegeocode; + iface->get_geocode_async = (TYPE_GET_GEOCODE_ASYNC)map_service_get_geocode_async; + iface->get_geocode_freeform_async = (TYPE_GET_GEOCODE_FREEFORM_ASYNC)map_service_get_geocode_freeform_async; + iface->get_reversegeocode_async = (TYPE_GET_REVERSEGEOCODE_ASYNC)map_service_get_reversegeocode_async; + iface->search_poi = (TYPE_SEARCH_POI) map_service_search_poi; + iface->search_poi_by_area = (TYPE_SEARCH_POI_BY_AREA) map_service_search_poi_by_area; + iface->search_poi_by_address = (TYPE_SEARCH_POI_BY_ADDR) map_service_search_poi_by_address; + iface->search_poi_by_freeform = (TYPE_SEARCH_POI_BY_FREEFORM) map_service_search_poi_by_freeform; + iface->cancel_poi_request = (TYPE_CANCEL_POI_REQUEST) map_service_cancel_poi_request; + iface->request_route = (TYPE_REQUEST_ROUTE) map_service_request_route; + iface->cancel_route_request = (TYPE_CANCEL_ROUTE_REQUEST) map_service_cancel_route_request; + iface->is_supported_map_provider_capability = (TYPE_IS_SUPPORTED_MAP_PROVIDER_CAPABILITY) map_service_is_supported_map_provider_capability; + iface->get_map_provider_capability_key = (TYPE_GET_MAP_PROVIDER_CAPABILITY_KEY) map_service_get_map_provider_capability_key; + +} + +static void +map_service_init (MapService *self) +{ + LOCATION_LOGD("map_service_init"); + MapServicePrivate* priv = GET_PRIVATE(self); + + priv->mod = (LocationServiceMod*)module_new("map-service"); + if(!priv->mod) LOCATION_LOGW("module loading failed"); + priv->pref = location_pref_new (); + if(!priv->pref) LOCATION_LOGW("Service preference failed"); + + gchar country[3], lang[3]; + _get_lang (country, lang); + location_pref_set_language (priv->pref, lang); + location_pref_set_distance_unit (priv->pref, "MI"); + location_pref_set_provider_name (priv->pref, "decarta"); +} + +static void +map_service_class_init (MapServiceClass *klass) +{ + LOCATION_LOGD("map_service_class_init"); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GParamSpec *pspec; + + gobject_class->get_property = map_service_get_property; + + gobject_class->dispose = map_service_dispose; + gobject_class->finalize = map_service_finalize; + + g_type_class_add_private (klass, sizeof (MapServicePrivate)); + + pspec = g_param_spec_string ("service provider", + "map service provider name prop", + "map service provider name", + DEFAULT_SERVICE, + G_PARAM_READABLE); + g_object_class_install_property (gobject_class, + PROP_SERVICE_NAME, + pspec); +} + +LocationPreference * +map_service_get_pref(GObject *obj) +{ + LOCATION_LOGD("map_service_get_pref"); + MapServicePrivate* priv = GET_PRIVATE(obj); + if (!priv) return NULL; + if (!priv->pref) return NULL; + + LocationPreference *pref = location_pref_copy(priv->pref); + + return pref; +} + +gboolean +map_service_set_pref (GObject *obj, LocationPreference *pref) +{ + LOCATION_LOGD("map_service_set_pref"); + MapServicePrivate* priv = GET_PRIVATE(obj); + if (!priv) return FALSE; + if (!priv->pref) location_pref_free(priv->pref); + + priv->pref = location_pref_copy (pref); + + return TRUE; +} diff --git a/location/map-service/map-service.h b/location/map-service/map-service.h new file mode 100644 index 0000000..bde83c6 --- /dev/null +++ b/location/map-service/map-service.h @@ -0,0 +1,73 @@ +/* + * libslp-location + * + * 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 __MAP_SERVICE_H__ +#define __MAP_SERVICE_H__ + +#include +#include + +/** + * @file map-service.h + * @brief This file contains the internal definitions and structures related to a service provider. + */ + +G_BEGIN_DECLS + +typedef struct _MapService MapService; +typedef struct _MapServiceClass MapServiceClass; +typedef struct _MapServicePrivate MapServicePrivate; + +#define MAP_TYPE_SERVICE (map_service_get_type ()) +#define MAP_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAP_TYPE_SERVICE, MapService)) +#define MAP_IS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAP_TYPE_SERVICE)) +#define MAP_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MAP_TYPE_SERVICE, MapServiceClass)) +#define MAP_IS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MAP_TYPE_SERVICE)) +#define MAP_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MAP_TYPE_SERVICE, MapServiceClass)) + +#define DEFAULT_SERVICE "decarta" + +#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MAP_TYPE_SERVICE, MapServicePrivate)) + +struct _MapService +{ + GObject parent_instance; +}; + +struct _MapServiceClass +{ + GObjectClass parent_class; +}; + +struct _MapServicePrivate { + LocationServiceMod* mod; + LocationPreference *pref; +}; + +GType map_service_get_type (void); + +LocationPreference *map_service_get_pref(GObject *obj); + +gboolean map_service_set_preference (GObject *obj, LocationPreference *pref); + +G_END_DECLS + +#endif /* __MAP_SERVICE_H__ */ diff --git a/location/module/Makefile.am b/location/module/Makefile.am new file mode 100644 index 0000000..d517f09 --- /dev/null +++ b/location/module/Makefile.am @@ -0,0 +1,20 @@ +noinst_LTLIBRARIES = liblocation-module.la + +COMMON_HEADER_DIR = include +MANAGER_DIR = manager +MAP_SERVICE_DIR = map-service +MODULE_DIR = module + +liblocation_module_la_SOURCES = \ + module-internal.c + +liblocation_module_la_CFLAGS = \ + -fPIC\ + -I${srcdir} \ + -I${srcdir}/.. \ + -I${srcdir}/../include \ + -I${srcdir}/../${MANAGER_DIR} \ + -I${srcdir}/../${MODULE_DIR} \ + -I${srcdir}/../${MAP_SERVICE_DIR} \ + $(LOCATION_CFLAGS) + diff --git a/location/module/location-module.h b/location/module/location-module.h new file mode 100644 index 0000000..9f374c9 --- /dev/null +++ b/location/module/location-module.h @@ -0,0 +1,171 @@ +/* + * libslp-location + * + * 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_MODULE_H__ +#define __LOCATION_MODULE_H__ + +#include +#include +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +/** + * @file location-module.h + * @brief This file contains the structure and enumeration for location plug-in development. + */ + +/** + * @addtogroup LocationFW + * @{ + * @defgroup LocationModules Location Modules + * @brief This sub module provides the definitions and structrues for 3rd party plugin modules. + * @addtogroup LocationModules + * @{ + */ + +/** + * @brief This represents APIs declared in a geocode plug-in for location geocode modules. + */ +typedef struct{ + int (*get_service_name)(gpointer handle, gchar **servicename); + ///< This is used for getting a service name from a plug-in. + int (*get_geocode)(gpointer handle, const LocationAddress *address, GList **position_list, GList **accuracy_list); + ///< This is used for getting a geocode from a plug-in. + int (*get_geocode_freetext)(gpointer handle, const gchar *address, GList **position_list, GList **accuracy_list); + ///< This is used for getting a geocode by using a free-fromed address from a plug-in. + int (*get_reverse_geocode)(gpointer handle, const LocationPosition *position, LocationAddress **address, LocationAccuracy **accuracy); + ///< This is used for getting a reverse geocode from a plug-in. + int (*get_geocode_async)(gpointer handle, const LocationAddress *address, LocationPositionCB callback, gpointer userdata); + ///< This is used for getting a geocode from a plug-in asynchronously. + int (*get_geocode_freetext_async)(gpointer handle, const gchar *address, LocationPositionCB callback, gpointer userdata); + ///< This is used for getting a geocode by using a free-fromed address from a plug-in asynchronously. + int (*get_reverse_geocode_async)(gpointer handle, const LocationPosition *position, LocationAddressCB callback, gpointer userdata); + ///< This is used for getting a reverse geocode from a plug-in asynchronously. + 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); + ///< This is used for searching poi with the position from a plug-in asynchronously. + 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); + ///< This is used for searching poi with the boundary from a plug-in asynchronously. + 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); + ///< This is used for searching poi with the address from a plug-in asynchronously. + 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); + ///< This is used for searching poi with the freeform address from a plug-in asynchronously. + int (*cancel_poi_request) (gpointer handle, guint req_id); + ///< This is used for cancel poi request from a plug-in. + 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); + ///< This is used for requesting route from a plug-in asynchronously. + int (*cancel_route_request) (gpointer handle, guint req_id); + ///< This is used for cancel route request from a plug-in. + gboolean (*is_supported_map_provider_capability) (gpointer handle, LocationMapServiceType type); + ///< This is used to check whether map service is supported on a plug-in. + int (*get_map_provider_capability_key) (gpointer handle, LocationMapServiceType type, GList **key); + ///< This is used to get map service keys on a plug-in. +} LocModServiceOps; + +/** +* @brief This represents a enabled/disabled callback function for a plug-in. +*/ +typedef void (*LocModStatusCB)(gboolean enabled, LocationStatus status, gpointer userdata); + +/** + * @brief This represents a position callback function for a plug-in. + */ +typedef void (*LocModPositionCB) (gboolean enabled, LocationPosition *position, LocationAccuracy *accuracy, gpointer userdata); + +/** + * @brief This represents a velocity callback function for a plug-in. + */ +typedef void (*LocModVelocityCB) (gboolean enabled, LocationVelocity *velocity, LocationAccuracy *accuracy, gpointer userdata); + +/** + * @brief This represents a velocity callback function for a plug-in. + */ +typedef void (*LocModSatelliteCB) (gboolean enabled, LocationSatellite *satellite, gpointer userdata); + +/** + * @brief This represents APIs declared in a GPS plug-in for location GPS modules. + */ +typedef struct{ + int (*start)(gpointer handle, LocModStatusCB status_cb, LocModPositionCB pos_cb, LocModVelocityCB vel_cb, LocModSatelliteCB sat_cb, gpointer userdata); ///< This is used for starting a GPS device from a plug-in. #LocModStatusCB, #LocModPositionCB, and #LocModVelocityCB are given from a location framework to a plug-in for asynchronous signaling. + int (*stop)(gpointer handle); ///< This is used for stopping a GPS device name from a plug-in. + int (*get_position)(gpointer handle, LocationPosition **position, LocationAccuracy **accuracy); ///< This is used for getting a position from a plug-in. + int (*get_velocity)(gpointer handle, LocationVelocity **velocity, LocationAccuracy **accuracy); ///< This is used for getting a velocity from a plug-in. + int (*get_last_position)(gpointer handle, LocationPosition **position, LocationAccuracy **accuracy); ///< This is used for getting a last position from a plug-in. + int (*get_last_velocity)(gpointer handle, LocationVelocity **velocity, LocationAccuracy **accuracy); ///< This is used for getting a last velocity from a plug-in. + int (*get_nmea)(gpointer handle, gchar** nmea_data); ///< This is used for getting a nmea string from a plug-in. + int (*get_satellite)(gpointer handle, LocationSatellite **satellite); ///< This is used for getting a satellite information from a plug-in. + int (*get_last_satellite)(gpointer handle, LocationSatellite **satellite); ///< This is used for getting a last satellite information from a plug-in. + int (*set_devname)(gpointer handle, const gchar *devname); ///< This is used for setting a device name from a plug-in. + int (*get_devname)(gpointer handle, gchar **devname); ///< This is used for getting a device name from a plug-in. +} LocModGpsOps; + +/** + * @brief This represents APIs declared in a WPS plug-in for location WPS modules. + */ +typedef struct{ + int (*start)(gpointer handle, LocModStatusCB status_cb, LocModPositionCB pos_cb, LocModVelocityCB vel_cb, LocModSatelliteCB sat_cb, gpointer userdata); ///< This is used for starting a WPS service from a plug-in. #LocModStatusCB, #LocModPositionCB, #LocModVelocityCB and #LocModSatelliteCB(Not used) are given from a location framework to a plug-in for asynchronous signaling. + int (*stop)(gpointer handle); ///< This is used for stopping a WPS service from a plug-in. + int (*get_position)(gpointer handle, LocationPosition **position, LocationAccuracy **accuracy); ///< This is used for getting a position from a plug-in. + int (*get_velocity)(gpointer handle, LocationVelocity **velocity, LocationAccuracy **accuracy); ///< This is used for getting a velocity from a plug-in. + int (*get_last_position)(gpointer handle, LocationPosition **position, LocationAccuracy **accuracy); ///< This is used for getting a last position from a plug-in. + int (*get_last_velocity)(gpointer handle, LocationVelocity **velocity, LocationAccuracy **accuracy); ///< This is used for getting a last velocity from a plug-in. +} LocModWpsOps; + +/** + * @brief This represents APIs declared in a SPS plug-in for location SPS modules. + */ +typedef struct{ + int (*start)(gpointer handle, LocModStatusCB status_cb, LocModPositionCB pos_cb, LocModVelocityCB vel_cb, gpointer userdata); ///< This is used for starting a SPS service from a plug-in. #LocModStatusCB, #LocModPositionCB and #LocModVelocityCB are given from a location framework to a plug-in for asynchronous signaling. + int (*stop)(gpointer handle); ///< This is used for stopping a SPS service from a plug-in. + int (*get_position)(gpointer handle, LocationPosition **position, LocationAccuracy **accuracy); ///< This is used for getting a position from a plug-in. + int (*get_velocity)(gpointer handle, LocationVelocity **velocity, LocationAccuracy **accuracy); ///< This is used for getting a velocity from a plug-in. + int (*update_data)(gpointer handle, const LocationPosition *position, const LocationVelocity *velocity, const LocationAccuracy *accuracy, const LocationSatellite *satellite); ///< This is used for updating compensated position/velocity data for a plug-in. +} LocModSpsOps; + +/** + * @brief This represents APIs declared in a IPS plug-in for location IPS modules. + */ +typedef struct{ + int (*get_position)(gpointer handle, LocationPosition **position, LocationAccuracy **accuracy); ///< This is used for getting a position from a plug-in. +} LocModIpsOps; + +/** + * @brief This represents APIs declared in a CPS plug-in for location CPS modules. + */ +typedef struct{ + int (*get_position)(gpointer handle, LocationPosition **position, LocationAccuracy **accuracy); ///< This is used for getting a position from a plug-in. +} LocModCpsOps; + +/** + * @brief This is used for exported APIs in a plug-in for a location framework. + */ +#define LOCATION_MODULE_API __attribute__((visibility("default"))) G_MODULE_EXPORT + +/** + * @} @} + */ +G_END_DECLS + +#endif diff --git a/location/module/module-internal.c b/location/module/module-internal.c new file mode 100644 index 0000000..302a159 --- /dev/null +++ b/location/module/module-internal.c @@ -0,0 +1,366 @@ +/* + * libslp-location + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "module-internal.h" +#include "location-log.h" + +#define MAX_MODULE_INDEX 10 +const char* MODULE_PATH_PREFIX = "/usr/lib/location/module"; + +static GMod* +gmod_new (const char* module_name, gboolean is_resident) +{ + if(!module_name) + return NULL; + + GMod* gmod = g_new0(GMod, 1); + gmod->name = g_strdup(module_name); + if(!gmod->name) { + g_free(gmod); + return NULL; + } + gmod->path = g_module_build_path (MODULE_PATH_PREFIX, gmod->name); + if(!gmod->path){ + g_free(gmod->name); + g_free(gmod); + gmod->name = NULL; + return NULL; + } + gmod->module = g_module_open(gmod->path, G_MODULE_BIND_LAZY); + if(!gmod->module){ + g_free(gmod->name); + g_free(gmod->path); + g_free(gmod); + gmod->name = NULL; + gmod->path = NULL; + + return NULL; + } + if(is_resident) + g_module_make_resident(gmod->module); + + return gmod; +} + +static void +gmod_free (GMod* gmod) +{ + if(gmod->name) + g_free(gmod->name); + if(gmod->path) + g_free(gmod->path); + if(gmod->module) + g_module_close(gmod->module); + g_free(gmod); +} + +static gboolean +gmod_find_sym (GMod* gmod, + gpointer* init_func, gpointer* shutdown_func) +{ + char sym[256]; + g_stpcpy(sym, "init"); + if ( !g_module_symbol (gmod->module, sym, init_func) ){ + LOCATION_LOGW("symbol not found: %s", sym); + return FALSE; + } + g_stpcpy(sym, "shutdown"); + if ( !g_module_symbol (gmod->module, sym, shutdown_func) ){ + LOCATION_LOGW("symbol not found: %s", sym); + return FALSE; + } + return TRUE; +} + +static gpointer +mod_new (const char* module_name) +{ + gpointer ret_mod = NULL; + if(!module_name) + return NULL; + + GMod* gmod = NULL; + gpointer init = NULL; + gpointer shutdown = NULL; + gmod = gmod_new(module_name, TRUE); + if(!gmod){ + LOCATION_LOGW("module(%s) new failed", module_name); + return NULL; + } + if( !gmod_find_sym(gmod, &init, &shutdown) ){ + LOCATION_LOGW("symbol (init, shutdown) finding failed"); + gmod_free(gmod); + return NULL; + } + if(!init || !shutdown){ + LOCATION_LOGW("init, shutdown symbol is NULL"); + gmod_free(gmod); + return NULL; + } + if(g_str_has_prefix(module_name, "map-service")){ + LocationServiceMod* _mod = g_new0(LocationServiceMod, 1); + _mod->gmod = gmod; + _mod->init = init; + _mod->shutdown= shutdown; + _mod->handler= _mod->init(&(_mod->ops)); + if(!_mod->handler){ + LOCATION_LOGW("module init failed"); + gmod_free(_mod->gmod); + ret_mod = NULL; + }else + ret_mod = (gpointer)_mod; + }else if(g_str_has_prefix(module_name, "gps")){ + LocationGpsMod* _mod = g_new0(LocationGpsMod, 1); + _mod->gmod = gmod; + _mod->init = init; + _mod->shutdown= shutdown; + _mod->handler= _mod->init(&(_mod->ops)); + if(!_mod->handler){ + LOCATION_LOGW("module init failed"); + gmod_free(_mod->gmod); + ret_mod = NULL; + }else + ret_mod = (gpointer)_mod; + }else if(g_str_has_prefix(module_name, "wps")){ + LocationWpsMod* _mod = g_new0(LocationWpsMod, 1); + _mod->gmod = gmod; + _mod->init = init; + _mod->shutdown= shutdown; + _mod->handler= _mod->init(&(_mod->ops)); + if(!_mod->handler){ + LOCATION_LOGW("module init failed"); + gmod_free(_mod->gmod); + ret_mod = NULL; + }else + ret_mod = (gpointer)_mod; + }else if(g_str_has_prefix(module_name, "cps")){ + LocationCpsMod* _mod = g_new0(LocationCpsMod, 1); + _mod->gmod = gmod; + _mod->init = init; + _mod->shutdown= shutdown; + _mod->handler= _mod->init(&(_mod->ops)); + if(!_mod->handler){ + LOCATION_LOGW("module init failed"); + gmod_free(_mod->gmod); + ret_mod = NULL; + }else + ret_mod = (gpointer)_mod; + }else if(g_str_has_prefix(module_name, "ips")){ + LocationIpsMod* _mod = g_new0(LocationIpsMod, 1); + _mod->gmod = gmod; + _mod->init = init; + _mod->shutdown= shutdown; + _mod->handler= _mod->init(&(_mod->ops)); + if(!_mod->handler){ + LOCATION_LOGW("module init failed"); + gmod_free(_mod->gmod); + ret_mod = NULL; + }else + ret_mod = (gpointer)_mod; + }else if(g_str_has_prefix(module_name, "sps")){ + LocationSpsMod* _mod = g_new0(LocationSpsMod, 1); + _mod->gmod = gmod; + _mod->init = init; + _mod->shutdown= shutdown; + _mod->handler= _mod->init(&(_mod->ops)); + if(!_mod->handler){ + LOCATION_LOGW("module init failed"); + gmod_free(_mod->gmod); + ret_mod = NULL; + }else + ret_mod = (gpointer)_mod; + }else{ + LOCATION_LOGW("module name (%s) is wrong", module_name); + ret_mod = NULL; + } + return ret_mod; +} + + +static void +mod_free (gpointer mod, + const char* module_name) +{ + if(!mod || !module_name) + return; + + if(0 == g_strcmp0(module_name, "map-service")){ + LocationServiceMod* _mod = (LocationServiceMod*)mod; + if(_mod->shutdown && _mod->handler){ + _mod->shutdown(_mod->handler); + } + _mod->handler = NULL; + _mod->init = NULL; + _mod->shutdown= NULL; + gmod_free(_mod->gmod); + _mod->gmod = NULL; + }else if(0 == g_strcmp0(module_name, "gps")){ + LocationGpsMod* _mod = (LocationGpsMod*)mod; + if(_mod->shutdown && _mod->handler){ + _mod->shutdown(_mod->handler); + } + _mod->handler = NULL; + _mod->init = NULL; + _mod->shutdown= NULL; + gmod_free(_mod->gmod); + _mod->gmod = NULL; + }else if(0 == g_strcmp0(module_name, "wps")){ + LocationWpsMod* _mod = (LocationWpsMod*)mod; + if(_mod->shutdown && _mod->handler){ + _mod->shutdown(_mod->handler); + } + _mod->handler = NULL; + _mod->init = NULL; + _mod->shutdown= NULL; + gmod_free(_mod->gmod); + _mod->gmod = NULL; + }else if(0 == g_strcmp0(module_name, "cps")){ + LocationCpsMod* _mod = (LocationCpsMod*)mod; + if(_mod->shutdown && _mod->handler){ + _mod->shutdown(_mod->handler); + } + _mod->handler = NULL; + _mod->init = NULL; + _mod->shutdown= NULL; + gmod_free(_mod->gmod); + _mod->gmod = NULL; + }else if(0 == g_strcmp0(module_name, "ips")){ + LocationIpsMod* _mod = (LocationIpsMod*)mod; + if(_mod->shutdown && _mod->handler){ + _mod->shutdown(_mod->handler); + } + _mod->handler = NULL; + _mod->init = NULL; + _mod->shutdown= NULL; + gmod_free(_mod->gmod); + _mod->gmod = NULL; + }else if(0 == g_strcmp0(module_name, "sps")){ + LocationSpsMod* _mod = (LocationSpsMod*)mod; + if(_mod->shutdown && _mod->handler){ + _mod->shutdown(_mod->handler); + } + _mod->handler = NULL; + _mod->init = NULL; + _mod->shutdown= NULL; + gmod_free(_mod->gmod); + _mod->gmod = NULL; + }else + LOCATION_LOGW("module name (%s) is wrong", module_name); + + g_free(mod); +} + +static gboolean +mod_is_supported(const char *module_name) +{ + GMod * gmod = NULL; + gmod = gmod_new(module_name, FALSE); + if(!gmod) { + return FALSE; + } + gmod_free(gmod); + + return TRUE; +} + +gboolean module_init (void) +{ + if (!g_module_supported()) { + LOCATION_LOGW("module is not supported"); + return FALSE; + } + return TRUE; +} + +void +module_free (gpointer mod, + const char* module_name) +{ + if(!mod || !module_name) + return; + mod_free(mod, module_name); +} + +gpointer +module_new (const char* module_name) +{ + if(!module_name) + return NULL; + int index = 0; + char name[256]; + + gpointer mod = NULL; + for(index = -1 ; index < MAX_MODULE_INDEX ; index++){ + if(index >= 0){ + if( 0 >= g_snprintf(name, 256, "%s%d", module_name, index)){ + LOCATION_LOGW("module name(%s) is wrong", name); + continue; + } + }else{ + if( 0 >= g_snprintf(name, 256, "%s", module_name)){ + LOCATION_LOGW("module name(%s) is wrong", name); + continue; + } + } + mod = mod_new(name); + if(mod){ + LOCATION_LOGW("module (%s) open success", name); + break; + } + LOCATION_LOGW("module (%s) open failed", name); + } + return mod; +} + +gboolean +module_is_supported(const char *module_name) +{ + if(!module_name) + return FALSE; + + int index = 0; + gboolean ret = FALSE; + gboolean found = FALSE; + + char name[256] = {0, }; + + for(index = -1 ; index < MAX_MODULE_INDEX ; index++){ + if(index >= 0){ + g_snprintf(name, 256, "%s%d", module_name, index); + }else{ + g_snprintf(name, 256, "%s", module_name); + } + + ret = mod_is_supported(name); + if(ret == TRUE) { + found = TRUE; + LOCATION_LOGW("module name(%s) is found", name); + break; + } + } + + return found; +} diff --git a/location/module/module-internal.h b/location/module/module-internal.h new file mode 100644 index 0000000..47b8280 --- /dev/null +++ b/location/module/module-internal.h @@ -0,0 +1,96 @@ +/* + * libslp-location + * + * 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 __MODULE_INTERNAL_H__ +#define __MODULE_INTERNAL_H__ + +#include +#include "location-module.h" + +/** + * @file module-internal.h + * @brief This file contains the internal definitions and structures related to module. + */ + +typedef struct{ + GModule* module; + char* name; + char* path; +} GMod; + +typedef struct{ + GMod* gmod; + gpointer handler; + gpointer (*init)(LocModServiceOps* ops); + void (*shutdown)(gpointer handle); + LocModServiceOps ops; +} LocationServiceMod; + +typedef struct{ + GMod* gmod; + gpointer handler; + gpointer (*init)(LocModGpsOps* ops); + void (*shutdown)(gpointer handle); + LocModGpsOps ops; +} LocationGpsMod; + +typedef struct{ + GMod* gmod; + gpointer handler; + gpointer (*init)(LocModWpsOps* ops); + void (*shutdown)(gpointer handle); + LocModWpsOps ops; +} LocationWpsMod; + +typedef struct{ + GMod* gmod; + gpointer handler; + gpointer (*init)(LocModCpsOps* ops); + void (*shutdown)(gpointer handle); + LocModCpsOps ops; +} LocationCpsMod; + +typedef struct{ + GMod* gmod; + gpointer handler; + gpointer (*init)(LocModIpsOps* ops); + void (*shutdown)(gpointer handle); + LocModIpsOps ops; +} LocationIpsMod; + +typedef struct{ + GMod* gmod; + gpointer handler; + gpointer (*init)(LocModSpsOps* ops); + void (*shutdown)(gpointer handle); + LocModSpsOps ops; +} LocationSpsMod; + +G_BEGIN_DECLS + +gboolean module_init(void); +gpointer module_new(const char* module_name); +void module_free(gpointer mod, const char* module_name); +gboolean module_is_supported(const char *module_name); + +G_END_DECLS + +#endif diff --git a/packaging/libslp-location.spec b/packaging/libslp-location.spec index d0e3cb8..0ba8019 100644 --- a/packaging/libslp-location.spec +++ b/packaging/libslp-location.spec @@ -1,3 +1,4 @@ + Name: libslp-location Summary: Location Based Service Version: 0.3.34 @@ -10,9 +11,11 @@ Requires(post): /usr/bin/vconftool Requires(postun): /sbin/ldconfig BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gconf-2.0) +BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(gmodule-2.0) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(vconf) -BuildRequires: pkgconfig(json-glib-1.0) +BuildRequires: pkgconfig(json-glib-1.0) %description @@ -28,7 +31,6 @@ Requires: %{name} = %{version}-%{release} Location Based Service Development Package - %prep %setup -q -n %{name}-%{version} @@ -36,48 +38,57 @@ Location Based Service Development Package %build ./autogen.sh -./configure --prefix=%{_prefix} --enable-dlog +./configure --prefix=%{_prefix} --enable-dlog --enable-debug +# Call make instruction with smp support make %{?jobs:-j%jobs} + %install +rm -rf %{buildroot} %make_install +%clean +rm -rf %{buildroot} -%post + +%post /sbin/ldconfig -vconftool set -t int db/location/lastposition/gps/Timestamp "0" -f -vconftool set -t double db/location/lastposition/gps/Latitude "0.0" -f -vconftool set -t double db/location/lastposition/gps/Longitude "0.0" -f -vconftool set -t double db/location/lastposition/gps/Altitude "0.0" -f -vconftool set -t double db/location/lastposition/gps/HorAccuracy "0.0" -f -vconftool set -t double db/location/lastposition/gps/VerAccuracy "0.0" -f -vconftool set -t int db/location/lastposition/wps/Timestamp "0" -f -vconftool set -t double db/location/lastposition/wps/Latitude "0.0" -f -vconftool set -t double db/location/lastposition/wps/Longitude "0.0" -f -vconftool set -t double db/location/lastposition/wps/Altitude "0.0" -f -vconftool set -t double db/location/lastposition/wps/HorAccuracy "0.0" -f -vconftool set -t int db/location/lastposition/sps/Timestamp "0" -f -vconftool set -t double db/location/lastposition/sps/Latitude "0.0" -f -vconftool set -t double db/location/lastposition/sps/Longitude "0.0" -f -vconftool set -t double db/location/lastposition/sps/Altitude "0.0" -f -vconftool set -t double db/location/lastposition/sps/HorAccuracy "0.0" -f -vconftool set -t double db/location/lastposition/sps/VerAccuracy "0.0" -f +vconftool set -t int db/location/last/gps/Timestamp "0" -f +vconftool set -t double db/location/last/gps/Latitude "0.0" -f +vconftool set -t double db/location/last/gps/Longitude "0.0" -f +vconftool set -t double db/location/last/gps/Altitude "0.0" -f +vconftool set -t double db/location/last/gps/HorAccuracy "0.0" -f +vconftool set -t double db/location/last/gps/VerAccuracy "0.0" -f +vconftool set -t double db/location/last/gps/Speed "0.0" -f +vconftool set -t double db/location/last/gps/Direction "0.0" -f +vconftool set -t int db/location/last/wps/Timestamp "0" -f +vconftool set -t double db/location/last/wps/Latitude "0.0" -f +vconftool set -t double db/location/last/wps/Longitude "0.0" -f +vconftool set -t double db/location/last/wps/Altitude "0.0" -f +vconftool set -t double db/location/last/wps/HorAccuracy "0.0" -f +vconftool set -t double db/location/last/wps/Speed "0.0" -f +vconftool set -t double db/location/last/wps/Direction "0.0" -f +vconftool set -t int db/location/last/sps/Timestamp "0" -f +vconftool set -t double db/location/last/sps/Latitude "0.0" -f +vconftool set -t double db/location/last/sps/Longitude "0.0" -f +vconftool set -t double db/location/last/sps/Altitude "0.0" -f +vconftool set -t double db/location/last/sps/HorAccuracy "0.0" -f +vconftool set -t double db/location/last/sps/VerAccuracy "0.0" -f vconftool set -t int db/location/setting/GpsEnabled "0" -g 6514 -f vconftool set -t int db/location/setting/AgpsEnabled "0" -g 6514 -f vconftool set -t int db/location/setting/NetworkEnabled "0" -g 6514 -f vconftool set -t int db/location/setting/SensorEnabled "0" -g 6514 -f + %postun -p /sbin/ldconfig %files -%{_libdir}/lib*.so.* +%{_libdir}/lib*.so* %files devel %{_includedir}/location/*.h -%{_libdir}/lib*.so %{_libdir}/pkgconfig/*.pc - diff --git a/tests/Makefile.am b/tests/Makefile.am index 51837cd..c9d697d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -20,7 +20,10 @@ LDADD = \ $(dir_location)/libSLP-location.la\ $(TEST_LIBS) AM_CFLAGS = \ - -I$(dir_location)\ + -I$(dir_location) \ + -I$(dir_location)/include \ + -I$(dir_location)/manager \ + -I$(dir_location)/map-service \ $(TEST_CFLAGS) dir_tests = $(top_srcdir)/tests diff --git a/tests/address-sample.c b/tests/address-sample.c index 4505288..e830329 100644 --- a/tests/address-sample.c +++ b/tests/address-sample.c @@ -20,15 +20,10 @@ */ #include -#include +#include static GMainLoop *loop = NULL; -#define GCONF_PROXY_MODE "/system/proxy/mode" -#define GCONF_HTTP_PROXY_HOST "/system/http_proxy/host" -#define GCONF_HTTP_PROXY_PORT "/system/http_proxy/port" -#define ENV_HTTP_PROXY "http_proxy" - static gboolean exit_program (gpointer data) { diff --git a/tests/cps-test.c b/tests/cps-test.c index f4bfff0..ea7c707 100644 --- a/tests/cps-test.c +++ b/tests/cps-test.c @@ -20,7 +20,7 @@ */ #include -#include +#include int main (int argc, char *argv[]) diff --git a/tests/gps-test.c b/tests/gps-test.c index 23d5438..c36dbf7 100644 --- a/tests/gps-test.c +++ b/tests/gps-test.c @@ -20,7 +20,7 @@ */ #include -#include +#include static GMainLoop *loop = NULL; diff --git a/tests/hybrid-test.c b/tests/hybrid-test.c index 4b6ae5d..90b0d06 100644 --- a/tests/hybrid-test.c +++ b/tests/hybrid-test.c @@ -20,7 +20,7 @@ */ #include -#include +#include static GMainLoop *loop = NULL; diff --git a/tests/ips-test.c b/tests/ips-test.c index f7b2269..19e40a1 100644 --- a/tests/ips-test.c +++ b/tests/ips-test.c @@ -20,7 +20,7 @@ */ #include -#include +#include int main (int argc, char *argv[]) diff --git a/tests/location-api-test-util.c b/tests/location-api-test-util.c index 7131c42..fe565f2 100644 --- a/tests/location-api-test-util.c +++ b/tests/location-api-test-util.c @@ -17,189 +17,189 @@ * 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 "location.h" - -JsonParser *parser; -JsonNode *root; - -static int _get_polygon_position_count(int polygon_index) -{ - if (parser == NULL || root == NULL) return 0; - - JsonObject* polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); - if (polygon_obj == NULL) return 0; - - JsonArray * positions = json_object_get_array_member (polygon_obj, "positions"); - if (positions == NULL) return 0; - - return json_array_get_length(positions); -} - -static LocationPosition* _get_position_from_polygon(int polygon_index, int pos_index) -{ - double latitude = 0.0; - double longitude = 0.0; - LocationPosition *position = NULL; - if (parser == NULL || root == NULL) return NULL; - - JsonObject *polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); - JsonArray * pos_array = json_object_get_array_member(polygon_obj, "positions"); - JsonObject* pos = json_array_get_object_element(pos_array, pos_index); - - latitude = json_object_get_double_member(pos, "latitude"); - longitude = json_object_get_double_member(pos, "longitude"); - - if (latitude == 0.0 || longitude == 0.0) return NULL; - - position = location_position_new(0, latitude, longitude, 0.0, LOCATION_STATUS_2D_FIX); - - return position; -} - -static LocationPosition* _get_marker_position_from_polygon(int polygon_index, int pos_index) -{ - double latitude = 0.0; - double longitude = 0.0; - LocationPosition *position = NULL; - if (parser == NULL || root == NULL) return NULL; - - JsonObject *polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); - JsonArray * pos_array = json_object_get_array_member(polygon_obj, "marker_position"); - JsonObject* pos = json_array_get_object_element(pos_array, pos_index); - - latitude = json_object_get_double_member(pos, "latitude"); - longitude = json_object_get_double_member(pos, "longitude"); - - if (latitude == 0.0 || longitude == 0.0) return NULL; - - position = location_position_new(0, latitude, longitude, 0.0, LOCATION_STATUS_2D_FIX); - - return position; -} - -static void _free_position_list(gpointer data) -{ - if (data == NULL) return; - - LocationPosition *position = (LocationPosition*) data; - - location_position_free(position); -} - - -LocationBoundary* json_util_get_polygon_boundary(int polygon_index) -{ - if (parser == NULL || root == NULL) { - g_printf("invalid param parser[%d], root[%d]\n", parser, root); - return NULL; - } - GList* position_list = NULL; - LocationBoundary *boundary = NULL; - int index = 0; - int pos_count = _get_polygon_position_count(polygon_index); - if (pos_count == 0) return NULL; - - for(index = 0; index < pos_count; index++) { - position_list = g_list_append(position_list, _get_position_from_polygon(polygon_index, index)); - } - - boundary = location_boundary_new_for_polygon(position_list); - - g_list_free_full(position_list, (GDestroyNotify)_free_position_list); - - return boundary; -} - - -/* Polygon boundary */ -int json_util_get_polygon_count(void) -{ - JsonArray * array = json_node_get_array(root); - - return json_array_get_length(array); -} - -char *json_util_get_polygon_name(int polygon_index) -{ - char *name = NULL; - JsonObject *polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); - - name = (char *)json_object_get_string_member(polygon_obj, "name"); - if (name == NULL) return NULL; - - return g_strdup(name); -} - -/* Test Marker */ -char * json_util_get_marker_name(int polygon_index, int pos_index) -{ - char *result = NULL; - if (parser == NULL || root == NULL) return NULL; - - JsonObject *polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); - JsonArray * pos_array = json_object_get_array_member(polygon_obj, "marker_position"); - JsonObject* pos = json_array_get_object_element(pos_array, pos_index); - - result = (char *)json_object_get_string_member(pos, "where"); - if (result == NULL) return NULL; - - return g_strdup(result); -} - -int json_util_get_marker_position_count(int polygon_index) -{ - if (parser == NULL || root == NULL) return 0; - - JsonObject* polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); - JsonArray * marker_position = json_object_get_array_member (polygon_obj, "marker_position"); - - return json_array_get_length(marker_position); -} - -LocationPosition *json_util_get_marker_position(int polygon_index, int marker_index) -{ - if (parser == NULL || root == NULL) return NULL; - - LocationPosition* position = NULL; - position = _get_marker_position_from_polygon(polygon_index, marker_index); - - return position; -} - -char* json_util_result_zone_test(int polygon_index, int marker_index) -{ - if (parser == NULL || root == NULL) return NULL; - - char *result = NULL; - JsonObject *polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); - JsonArray * pos_array = json_object_get_array_member(polygon_obj, "marker_position"); - JsonObject* pos = json_array_get_object_element(pos_array, marker_index); - - result = (char *)json_object_get_string_member(pos, "result"); - if (result == NULL) return NULL; - - return g_strdup(result); -} - -void json_util_init(const char * file_name) -{ - g_print("Enter init_json_parser"); - GError *error; - gboolean ret = FALSE; - if (parser != NULL) return; - - parser = json_parser_new(); - - error = NULL; - ret = json_parser_load_from_file(parser, file_name, &error); - if (ret == FALSE) { - g_print("Unable to parser[%s]:[%s]\n", file_name, error->message); - return ; - } - - root = json_parser_get_root(parser); -} + */ + +#include +#include +#include "location.h" + +JsonParser *parser; +JsonNode *root; + +static int _get_polygon_position_count(int polygon_index) +{ + if (parser == NULL || root == NULL) return 0; + + JsonObject* polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); + if (polygon_obj == NULL) return 0; + + JsonArray * positions = json_object_get_array_member (polygon_obj, "positions"); + if (positions == NULL) return 0; + + return json_array_get_length(positions); +} + +static LocationPosition* _get_position_from_polygon(int polygon_index, int pos_index) +{ + double latitude = 0.0; + double longitude = 0.0; + LocationPosition *position = NULL; + if (parser == NULL || root == NULL) return NULL; + + JsonObject *polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); + JsonArray * pos_array = json_object_get_array_member(polygon_obj, "positions"); + JsonObject* pos = json_array_get_object_element(pos_array, pos_index); + + latitude = json_object_get_double_member(pos, "latitude"); + longitude = json_object_get_double_member(pos, "longitude"); + + if (latitude == 0.0 || longitude == 0.0) return NULL; + + position = location_position_new(0, latitude, longitude, 0.0, LOCATION_STATUS_2D_FIX); + + return position; +} + +static LocationPosition* _get_marker_position_from_polygon(int polygon_index, int pos_index) +{ + double latitude = 0.0; + double longitude = 0.0; + LocationPosition *position = NULL; + if (parser == NULL || root == NULL) return NULL; + + JsonObject *polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); + JsonArray * pos_array = json_object_get_array_member(polygon_obj, "marker_position"); + JsonObject* pos = json_array_get_object_element(pos_array, pos_index); + + latitude = json_object_get_double_member(pos, "latitude"); + longitude = json_object_get_double_member(pos, "longitude"); + + if (latitude == 0.0 || longitude == 0.0) return NULL; + + position = location_position_new(0, latitude, longitude, 0.0, LOCATION_STATUS_2D_FIX); + + return position; +} + +static void _free_position_list(gpointer data) +{ + if (data == NULL) return; + + LocationPosition *position = (LocationPosition*) data; + + location_position_free(position); +} + + +LocationBoundary* json_util_get_polygon_boundary(int polygon_index) +{ + if (parser == NULL || root == NULL) { + g_printf("invalid param parser[%d], root[%d]\n", parser, root); + return NULL; + } + GList* position_list = NULL; + LocationBoundary *boundary = NULL; + int index = 0; + int pos_count = _get_polygon_position_count(polygon_index); + if (pos_count == 0) return NULL; + + for(index = 0; index < pos_count; index++) { + position_list = g_list_append(position_list, _get_position_from_polygon(polygon_index, index)); + } + + boundary = location_boundary_new_for_polygon(position_list); + + g_list_free_full(position_list, (GDestroyNotify)_free_position_list); + + return boundary; +} + + +/* Polygon boundary */ +int json_util_get_polygon_count(void) +{ + JsonArray * array = json_node_get_array(root); + + return json_array_get_length(array); +} + +char *json_util_get_polygon_name(int polygon_index) +{ + char *name = NULL; + JsonObject *polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); + + name = (char *)json_object_get_string_member(polygon_obj, "name"); + if (name == NULL) return NULL; + + return g_strdup(name); +} + +/* Test Marker */ +char * json_util_get_marker_name(int polygon_index, int pos_index) +{ + char *result = NULL; + if (parser == NULL || root == NULL) return NULL; + + JsonObject *polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); + JsonArray * pos_array = json_object_get_array_member(polygon_obj, "marker_position"); + JsonObject* pos = json_array_get_object_element(pos_array, pos_index); + + result = (char *)json_object_get_string_member(pos, "where"); + if (result == NULL) return NULL; + + return g_strdup(result); +} + +int json_util_get_marker_position_count(int polygon_index) +{ + if (parser == NULL || root == NULL) return 0; + + JsonObject* polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); + JsonArray * marker_position = json_object_get_array_member (polygon_obj, "marker_position"); + + return json_array_get_length(marker_position); +} + +LocationPosition *json_util_get_marker_position(int polygon_index, int marker_index) +{ + if (parser == NULL || root == NULL) return NULL; + + LocationPosition* position = NULL; + position = _get_marker_position_from_polygon(polygon_index, marker_index); + + return position; +} + +char* json_util_result_zone_test(int polygon_index, int marker_index) +{ + if (parser == NULL || root == NULL) return NULL; + + char *result = NULL; + JsonObject *polygon_obj = json_array_get_object_element(json_node_get_array(root), polygon_index); + JsonArray * pos_array = json_object_get_array_member(polygon_obj, "marker_position"); + JsonObject* pos = json_array_get_object_element(pos_array, marker_index); + + result = (char *)json_object_get_string_member(pos, "result"); + if (result == NULL) return NULL; + + return g_strdup(result); +} + +void json_util_init(const char * file_name) +{ + g_print("Enter init_json_parser"); + GError *error; + gboolean ret = FALSE; + if (parser != NULL) return; + + parser = json_parser_new(); + + error = NULL; + ret = json_parser_load_from_file(parser, file_name, &error); + if (ret == FALSE) { + g_print("Unable to parser[%s]:[%s]\n", file_name, error->message); + return ; + } + + root = json_parser_get_root(parser); +} diff --git a/tests/location-api-test-util.h b/tests/location-api-test-util.h index 47948a9..7c31a86 100644 --- a/tests/location-api-test-util.h +++ b/tests/location-api-test-util.h @@ -29,7 +29,7 @@ G_BEGIN_DECLS void json_util_init(const char *file_file); char* json_util_result_zone_test(int polygon_index, int marker_index); -int* json_util_get_marker_name(int polygon_index, int marker_index); +char* json_util_get_marker_name(int polygon_index, int marker_index); int json_util_get_marker_position_count(int polygon_index); LocationPosition *json_util_get_marker_position(int polygon_index, int marker_index); diff --git a/tests/location-api-test.c b/tests/location-api-test.c index b69070b..2247f89 100644 --- a/tests/location-api-test.c +++ b/tests/location-api-test.c @@ -23,18 +23,15 @@ #include #include #include -#include +#include +#include +#include #include "location-api-test-util.h" #define STR_MAX 128 LocationObject* location_obj = NULL; static GMainLoop *g_mainloop = NULL; -#define GCONF_PROXY_MODE "/system/proxy/mode" -#define GCONF_HTTP_PROXY_HOST "/system/http_proxy/host" -#define GCONF_HTTP_PROXY_PORT "/system/http_proxy/port" -#define ENV_HTTP_PROXY "http_proxy" - #define LOCATION_API_TEST_JSON_FILE "/opt/data/location-api-test.json" static gpointer GmainThread(gpointer data) @@ -378,20 +375,37 @@ cb_service_updated (GObject *self, LocationAccuracy *acc = (LocationAccuracy*) accuracy; switch (type) { case POSITION_UPDATED: { - LocationPosition *pos = (LocationPosition*) data; - g_debug ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d", + LocationPosition *pos = (LocationPosition*) data; + g_debug ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d", pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); - } + } break; case VELOCITY_UPDATED: { - LocationVelocity *vel = (LocationVelocity*) data; - g_debug ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f", - vel->timestamp, vel->speed, vel->direction, vel->climb); - g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", - acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + LocationVelocity *vel = (LocationVelocity*) data; + g_debug ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f", + vel->timestamp, vel->speed, vel->direction, vel->climb); + g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", + acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + } + break; + case SATELLITE_UPDATED: { + int idx = 0; + guint prn; + gboolean used; + guint elevation; + guint azimuth; + gint snr; + + LocationSatellite *sat = (LocationSatellite *)data; + g_debug ("SYNC>> Current Satellite> time: %d, satellite in view = %d, satellite in used = %d", sat->timestamp, sat->num_of_sat_inview, sat->num_of_sat_used); + g_debug ("\tinview satellite information = "); + for (idx=0; idxnum_of_sat_inview; idx++) { + location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr); + g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr); } + } break; default: g_warning ("ASYNC>> Undefined update type"); @@ -399,6 +413,187 @@ cb_service_updated (GObject *self, } } +static void _print_property (gpointer data, gpointer user_data) +{ + LocationLandmark *landmark = (LocationLandmark *)user_data; + gpointer key = (gpointer)data; + gpointer value = NULL; + + if (key) { + value = (gpointer)location_landmark_get_property(landmark, key); + g_printf(", [%s:%s]", (gchar*) key, (gchar*) value); + } +} + +static void +__plugin_print_poi_list (gpointer data, gpointer user_data) +{ + LocationLandmark *landmark = (LocationLandmark *)data; + LocationPosition *pos = location_landmark_get_position (landmark); + LocationAddress *addr = location_landmark_get_address (landmark); + + g_printf ("[ID:%d], [NAME:%s], phone[%s],pos[%f:%f], addr[%s:%s:%s:%s:%s]", + location_landmark_get_id (landmark), + location_landmark_get_name(landmark), + location_landmark_get_phone_number (landmark), + pos->latitude, pos->longitude, + addr->building_number, addr->city, addr->country_code, addr->district, + addr->postal_code); + + GList *key_list = location_landmark_get_property_key(landmark); + if (key_list) { + g_list_foreach(key_list, _print_property, landmark); + } + + g_printf("\n"); +} + + +static void cb_poi(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata) +{ + g_printf("\n===== __location_POI_cb ======\n"); + if (error != LOCATION_ERROR_NONE) { + g_printf("Failed :%d\n", error); + return; + } + g_printf("Success, poi_list[0x%x] user_data[0x%x] req_id[%d]\n", (unsigned int)landmark_list, (unsigned int)userdata, req_id); + g_list_foreach (landmark_list, __plugin_print_poi_list, NULL); + + if (error_code && error_msg) { + g_printf("__location_POI_cb: error_code[%s], error_msg[%s]\n", error_code, error_msg); + } +} +static void PrintStepInfo(const LocationRouteStep *step) +{ + const LocationPosition *start = location_route_step_get_start_point(step); + gdouble start_lat = 0; + gdouble start_lon = 0; + if (start) { + start_lat = start->latitude; + start_lon = start->longitude; + } else { + g_printf("Step start position NULL\n"); + } + const LocationPosition *end = location_route_step_get_end_point(step); + gdouble end_lat = 0; + gdouble end_lon = 0; + if (end) { + end_lat = end->latitude; + end_lon = end->longitude; + } else { + g_printf("Step end position NULL\n"); + } + const gchar *inst = location_route_step_get_instruction(step); + + g_printf("Step: start(%f/%f), end(%f/%f), instruction(%s)\n", start_lat, start_lon, end_lat, end_lon, inst); +} + +static void cb_print_route_step (gpointer data, gpointer user_data) +{ + g_printf("+++Step begin\n"); + LocationRouteStep *step = (LocationRouteStep *)data; + + PrintStepInfo(step); + g_printf("---Step end\n"); +} + +static void cb_print_route_segment (gpointer data, gpointer user_data) +{ + g_printf("++Segment begin\n"); + LocationRouteSegment *seg = (LocationRouteSegment *)data; + gdouble seg_dist = location_route_segment_get_distance(seg); + glong seg_duration = location_route_segment_get_duration(seg); + const LocationPosition *start = location_route_segment_get_start_point(seg); + gdouble start_lat = 0; + gdouble start_lon = 0; + if (start) { + start_lat = start->latitude; + start_lon = start->longitude; + } else { + g_printf("Segment start position NULL\n"); + } + const LocationPosition *end = location_route_segment_get_end_point(seg); + gdouble end_lat = 0; + gdouble end_lon = 0; + if (end) { + end_lat = end->latitude; + end_lon = end->longitude; + } else { + g_printf("Segment end postion NULL\n"); + } + g_printf("Segment info: Distance[%f], Duration[%ld], start(%f/%f), end(%f/%f)\n", seg_dist, seg_duration, + start_lat, start_lon, end_lat, end_lon); + + GList *step_list = location_route_segment_get_route_step(seg); + GList *tmp_list = (GList *)step_list; + if (tmp_list) { + g_list_foreach(tmp_list, cb_print_route_step, NULL); + } + g_printf("--Segment end\n"); +} + + +static void cb_print_route_list (gpointer data, gpointer user_data) +{ + g_printf("+Route begin\n"); + LocationRoute *route = (LocationRoute *)data; + + const LocationPosition *start = location_route_get_origin(route); + gdouble start_lat = 0; + gdouble start_lon = 0; + if (start) { + start_lat = start->latitude; + start_lon = start->longitude; + } else { + g_printf("Route start position NULL\n"); + } + const LocationPosition *end = location_route_get_destination(route); + gdouble end_lat = 0; + gdouble end_lon = 0; + if (end) { + end_lat = end->latitude; + end_lon = end->longitude; + } else { + g_printf("Route end position NULL\n"); + } + g_printf("Route: start(%f/%f), end(%f/%f)\n", start_lat, start_lon, end_lat, end_lon); + + gdouble distance = location_route_get_total_distance(route); + const gchar *dis_unit = location_route_get_distance_unit(route); + glong duration = location_route_get_total_duration(route); + const LocationBoundary *bound = location_route_get_bounding_box(route); + if (bound && bound->type == LOCATION_BOUNDARY_RECT) { + g_printf("RECT left top[%f-%f], right bottom[%f-%f]\n", bound->rect.left_top->latitude, bound->rect.left_top->longitude, + bound->rect.right_bottom->latitude, bound->rect.right_bottom->longitude); + } else { + g_printf("route boundary not exist, or not RECT\n"); + } + g_printf ("Distance[%f], Distance unit[%s], Duration[%ld]\n", distance, dis_unit, duration); + + GList *seg_list = location_route_get_route_segment(route); + if (seg_list) { + g_list_foreach(seg_list, cb_print_route_segment, NULL); + } + + g_printf("-Route end\n"); +} + +static void cb_route(LocationError error, guint req_id, GList * route_list, gchar * error_code, gchar * error_msg, gpointer userdata) +{ + g_printf("\n===== cb_route ======\n"); + if (error != LOCATION_ERROR_NONE) { + g_printf("Failed :%d\n", error); + return; + } + + g_printf("Success, poi_list[0x%x] user_data[0x%x] req_id[%d]\n", (unsigned int)route_list, (unsigned int)userdata, req_id); + g_list_foreach (route_list, cb_print_route_list, NULL); + + if (error_code && error_msg) { + g_printf("cb_route: error_code[%s], error_msg[%s]\n", error_code, error_msg); + } +} + static void cb_position (LocationError error, GList *pos_list, GList *acc_list, @@ -483,6 +678,24 @@ static gboolean idle_address_from_position_async(gpointer data) return FALSE; } +void _print_keys(gpointer value) +{ + g_printf(" %s ", (gchar*) value); +} + +static void print_map_service_keys (LocationObject *obj, int type) +{ + GList *key = NULL; + + int ret = location_get_map_provider_capability_key (obj, type, &key); + + if (key) { + g_list_foreach (key, _print_keys, NULL); + } + + g_list_free_full(key, g_free); +} + static void print_menu() { g_printf("\n================================= Location API Test =================================\n"); @@ -510,6 +723,16 @@ static void print_menu() g_printf("13. location_get_distance\n"); g_printf("14. location_is_supported_method\n"); g_printf("15. location_is_enabled_gps\n"); + g_printf("16. location_search_poi\n"); + g_printf("16a. location_search_poi_by_area\n"); + g_printf("16b. location_search_poi_by_addr\n"); + g_printf("16c. location_search_poi_by_freeformed_address\n"); + g_printf("16d. location_search_poi_by_area\n"); + g_printf("16e. location_cancel_poi_request\n"); + g_printf("17. location_request_route\n"); + g_printf("17a. location_cancel_route_request\n"); + g_printf("18. location_is_supported_map_provider_capability\n"); + g_printf("19. location_get_map_provider_capability_key\n"); g_printf("99. location_send_command\n"); g_printf("a?. signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n"); g_printf("b?. disconnect signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n"); @@ -525,6 +748,7 @@ int main(int argc, char** argv) int ret; char str[STR_MAX]; GError *gerr = NULL; + guint req_id = 0; // If application is executed by AUL, this is not needed. g_setenv("PKG_NAME", "com.samsung.location-api-test", 1); @@ -602,14 +826,12 @@ int main(int argc, char** argv) if(pos) location_position_free(pos); if(acc) location_accuracy_free(acc); } else if (0 == g_strcmp0("6a",strOpt)) { - g_printf("LOCATION_METHOD_HYBRID[0] LOCATION_METHOD_GPS[1] LOCATION_METHOD_WPS[2] LOCATION_METHOD_SPS[5]\n"); - g_printf("Select Location Method: "); - LocationMethod method = PromptInt(); LocationPosition *last_pos; LocationAccuracy *last_acc; int ret = 0; - ret = location_get_last_position (location_obj, LOCATION_METHOD_GPS, &last_pos, &last_acc); + ret = location_get_last_position (location_obj, &last_pos, &last_acc); + GetLocationError(str, ret); if (ret == LOCATION_ERROR_NONE) { g_debug ("SYNC>> Last position> time: %d, lat: %f, long: %f, alt: %f, status: %d", last_pos->timestamp, last_pos->latitude, last_pos->longitude, last_pos->altitude, last_pos->status); @@ -617,7 +839,7 @@ int main(int argc, char** argv) last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy); location_position_free(last_pos); location_accuracy_free(last_acc); - } else g_warning ("SYNC>> Last position> failed. Error[%d]",ret); + } else g_warning ("SYNC>> Last position> failed. Error[%s]",str); } else if (0 == g_strcmp0("6b",strOpt)) { g_printf("LOCATION_METHOD_HYBRID[0] LOCATION_METHOD_GPS[1] LOCATION_METHOD_WPS[2] LOCATION_METHOD_SPS[5]\n"); @@ -684,7 +906,7 @@ int main(int argc, char** argv) g_printf("Select Address: "); int opt = PromptInt(); if (opt == 0) data->addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113"); - else if (opt == 1) data->addr = location_address_new (NULL, "삼성전자", "매탄3동", "수원시 영통구", "경기도", NULL, NULL); + else if (opt == 1) data->addr = location_address_new (NULL, "삼성전자", "매탄3동", "수원시 영통구", "경기도", NULL, NULL); else if (opt == 2) data->addr = location_address_new (NULL, "Samsung Electro-Mechanics Co. LTD", "Maetan 3-dong", "Suwon Si Yeongtong-gu", "Gyeonggi-do", NULL, NULL); else { char building_number[255], street[255], state[255], country_code[255], city[255], district[255], postal_code[255]; @@ -768,26 +990,31 @@ int main(int argc, char** argv) LocationVelocity *vel = NULL; LocationAccuracy *acc = NULL; ret = location_get_velocity(location_obj, &vel, &acc); - GetLocationError(str, ret); g_printf("location_get_velocity: returned value [%s]\n", str); if (ret == LOCATION_ERROR_NONE) { g_printf("time: [%d], speed: [%f], direction: [%f], climb: [%f]\n", vel->timestamp, vel->speed, vel->direction, vel->climb); GetAccuracyLevel(str, acc->level); g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy); } + else { + GetLocationError(str, ret); + g_warning ("SYNC>> velocity> failed. Error[%s]", str); + } if(vel) location_velocity_free(vel); if(acc) location_accuracy_free(acc); }else if(0 == g_strcmp0("9a",strOpt) ){ LocationVelocity *last_vel = NULL; LocationAccuracy *last_acc = NULL; - if (LOCATION_ERROR_NONE == location_get_last_velocity (location_obj, &last_vel, &last_acc)) { + ret = location_get_last_velocity (location_obj, &last_vel, &last_acc); + GetLocationError(str, ret); + if (ret == LOCATION_ERROR_NONE) { g_debug ("SYNC>> Last velocity> time: %d, speed: %f, direction:%f, climb:%f", last_vel->timestamp, last_vel->speed, last_vel->direction, last_vel->climb); g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy); location_velocity_free(last_vel); location_accuracy_free(last_acc); - } else g_warning ("SYNC>> Last velocity> failed."); + } else g_warning ("SYNC>> Last velocity> failed. Error[%s]", str); }else if(0 == g_strcmp0("10",strOpt) ){ int ret = 0, idx = 0; LocationSatellite *sat = NULL; @@ -798,15 +1025,16 @@ int main(int argc, char** argv) gint snr; ret = location_get_satellite (location_obj, &sat); + GetLocationError(str, ret); if (ret == LOCATION_ERROR_NONE) { - g_debug ("SYNC>> Current Sattelite> satellite in view = %d, satellite in used = %d", sat->num_of_sat_inview, sat->num_of_sat_used); + g_debug ("SYNC>> Current Sattelite> time = %d, satellite in view = %d, satellite in used = %d", sat->timestamp, sat->num_of_sat_inview, sat->num_of_sat_used); g_debug ("\tinview satellite information = "); for (idx=0; idxnum_of_sat_inview; idx++) { location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr); g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr); } location_satellite_free (sat); - } else g_warning ("SYNC>> Current satellite> failed. Error[%d]", ret); + } else g_warning ("SYNC>> Current satellite> failed. Error[%s]", str); }else if(0 == g_strcmp0("10a",strOpt) ){ int ret = 0, idx = 0; LocationSatellite *last_sat = NULL; @@ -817,16 +1045,16 @@ int main(int argc, char** argv) gint snr; ret = location_get_last_satellite (location_obj, &last_sat); - + GetLocationError(str, ret); if (ret == LOCATION_ERROR_NONE) { - g_debug ("SYNC>> Last Sattelite> satellite in view = %d, satellite in used = %d", last_sat->num_of_sat_inview, last_sat->num_of_sat_used); + g_debug ("SYNC>> Last Sattelite> time = %d, satellite in view = %d, satellite in used = %d", last_sat->timestamp, last_sat->num_of_sat_inview, last_sat->num_of_sat_used); g_debug ("\tinview satellite information = "); for (idx=0; idxnum_of_sat_inview; idx++) { location_satellite_get_satellite_details(last_sat, idx, &prn, &used, &elevation, &azimuth, &snr); g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr); } location_satellite_free (last_sat); - } else g_warning ("SYNC>> Last satellite> failed"); + } else g_warning ("SYNC>> Last satellite> failed. Error[%s]", str); } else if(0 == g_strcmp0("11",strOpt) ){ LocationAddress *addr = NULL; LocationAccuracy *acc = NULL; @@ -953,6 +1181,238 @@ int main(int argc, char** argv) is_enabled = location_is_enabled_gps(location_obj); if(is_enabled == TRUE) g_printf("GPS is turned on"); else g_printf("GPS is turned off"); + }else if(0 == g_strcmp0("16", strOpt)) { + g_printf("location_search_poi\n"); + //guint req_id = 0; // move to upper + + LocationPOIFilter *filter = location_poi_filter_new(); +// gchar *key = g_strdup("KEYWORD"); +// gchar *value = g_strdup("pizza"); +// location_poi_filter_set(filter, key, value); // same with Type ? CATEGORY, KEYWORD, POIName + //location_poi_filter_set(filter, "CATEGORY", "restaurant"); // error, const char* can't be free!!!!, 120214 + location_poi_filter_set(filter, "KEYWORD", "pizza"); + //location_poi_filter_set(filter, "POIName", "cafe"); + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 2); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !! + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_DESC); //LOCATION_POI_PREF_SO_ASC + + // only the latitude/longitude + LocationPosition *position = location_position_new(0, 37.771008, -122.41175, 0, LOCATION_STATUS_2D_FIX); + + ret = location_search_poi(location_obj, filter, position, pref, cb_poi, NULL, &req_id); + GetLocationError(str, ret); + if(ret != LOCATION_ERROR_NONE) { + g_printf("Fail to search POI. Error[%s]\n", str); + } else { + g_printf("Seach POI success, req_id %d\n", req_id); + } +// g_free(item); +// g_free(key); +// g_free(value); + location_poi_filter_free(filter); + location_poi_pref_free(pref); + location_position_free(position); + + }else if(0 == g_strcmp0("16a", strOpt)) { + g_printf("location_search_poi_by_area\n"); + + // only circle supported by decarta + LocationPosition *center = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX); + gdouble radius = 400; + LocationBoundary *bound = location_boundary_new_for_circle(center, radius); + + LocationPOIFilter *filter = location_poi_filter_new(); + gchar *key = g_strdup("KEYWORD"); + gchar *value = g_strdup("cafe"); + location_poi_filter_set(filter, key, value); // same with Type ? CATEGORY, KEYWORD, POIName + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 2); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !! + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); //LOCATION_POI_PREF_SO_ASC + + + ret = location_search_poi_by_area(location_obj, filter, bound, pref, cb_poi, NULL, &req_id); + GetLocationError(str, ret); + if (ret != LOCATION_ERROR_NONE) { + g_printf("Fail to search POI by area. Error[%s]\n", str); + } else { + g_printf("Seach POI by area sucess, req_id %d\n", req_id); + } + + g_free(key); + g_free(value); + g_free(item); + location_position_free(center); + location_boundary_free(bound); + location_poi_filter_free(filter); + location_poi_pref_free(pref); + }else if(0 == g_strcmp0("16b", strOpt)) { + g_printf("location_search_poi_by_address\n"); + + LocationAddress *addr = location_address_new("51", "N SAN PEDRO ST", NULL, "SAN JOSE", "SANTA CLARA", "CA", "95110"); + //landmark type ? + //landmark name ? + + LocationPOIFilter *filter = location_poi_filter_new(); + gchar *key = g_strdup("KEYWORD"); + gchar *value = g_strdup("cafe"); + location_poi_filter_set(filter, key, value); // same with Type ? CATEGORY, KEYWORD, POIName + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 10); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !! + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); //LOCATION_POI_PREF_SO_ASC + + ret = location_search_poi_by_address(location_obj, filter, addr, pref, cb_poi, NULL, &req_id); + GetLocationError(str, ret); + if(ret != LOCATION_ERROR_NONE) { + g_printf("Fail to search POI by address. Error[%s]\n", str); + } else { + g_printf("Seach POI by address sucess, req_id %d\n", req_id); + } + + g_free(key); + g_free(value); + g_free(item); + + location_address_free(addr); + location_poi_filter_free(filter); + location_poi_pref_free(pref); + }else if(0 == g_strcmp0("16c", strOpt)) { + g_printf("location_search_poi_by_freeformed_address\n"); + + gchar *addr = g_strdup("North Second St."); + + LocationPOIFilter *filter = location_poi_filter_new(); + gchar *key = g_strdup("KEYWORD"); + gchar *value = g_strdup("restaurant"); + location_poi_filter_set(filter, key, value); // same with Type ? CATEGORY, KEYWORD, POIName + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 10); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !! + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); //LOCATION_POI_PREF_SO_ASC + + ret = location_search_poi_by_freeformed_address(location_obj, filter, addr, pref, cb_poi, NULL, &req_id); + GetLocationError(str, ret); + if (ret != LOCATION_ERROR_NONE) { + g_printf("Fail to search POI by address. Error[%s]\n", str); + } else { + g_printf("Seach POI by address success, req_id %d\n", req_id); + } + + g_free(key); + g_free(value); + g_free(item); + + g_free(addr); + location_poi_filter_free(filter); + location_poi_pref_free(pref); + }else if(0 == g_strcmp0("16d", strOpt)) { + gchar value[255] = {0, }; + + // only circle supported by decarta + LocationPosition *center = location_position_new(0, 37.56693, 126.97819, 0, LOCATION_STATUS_2D_FIX); + gdouble radius = 800; + LocationBoundary *bound = location_boundary_new_for_circle(center, radius); + + LocationPOIFilter *filter = location_poi_filter_new(); + + g_printf("Input keyword :"); + scanf("%s", value); + gchar *key = g_strdup("KEYWORD"); + location_poi_filter_set(filter, key, value); // same with Type ? CATEGORY, KEYWORD, POIName + + LocationPOIPreference *pref = location_poi_pref_new(); + location_poi_pref_set_max_result(pref, 2); + gchar *item = g_strdup("Distance"); + location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !! + location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); //LOCATION_POI_PREF_SO_ASC + + + ret = location_search_poi_by_area(location_obj, filter, bound, pref, cb_poi, NULL, &req_id); + GetLocationError(str, ret); + if (ret != LOCATION_ERROR_NONE) { + g_printf("Fail to search POI by area. Error[%s]\n", str); + } else { + g_printf("Seach POI by area sucess, req_id %d\n", req_id); + } + + g_free(key); + g_free(value); + g_free(item); + location_position_free(center); + location_boundary_free(bound); + location_poi_filter_free(filter); + location_poi_pref_free(pref); + }else if(0 == g_strcmp0("16e", strOpt)) { + int req_id; + + g_printf("Input ReqID : "); + scanf("%d", &req_id); + + ret = location_cancel_poi_request(location_obj, req_id); + GetLocationError(str, ret); + if (ret != LOCATION_ERROR_NONE) { + g_printf("Fail to cancel POI request. Error[%s]\n", str); + } + else + g_printf("location_cancel_poi_request, req_id %d\n", req_id); + }else if(0 == g_strcmp0("17", strOpt)) { + g_printf("17. location_request_route\n\n"); + + LocationPosition *origin = location_position_new(0, 37.564263, 126.974676, 0, LOCATION_STATUS_2D_FIX); // Seoul city hall + LocationPosition *destination = location_position_new(0, 37.557120, 126.992410, 0, LOCATION_STATUS_2D_FIX); // NamSan + + GList *waypoint = NULL; + LocationPosition *via_pos = location_position_new(0, 37.560950, 126.986240, 0, LOCATION_STATUS_2D_FIX); // Wangsimli + waypoint = g_list_append (waypoint, (gpointer)via_pos); + + LocationRoutePreference *pref = location_route_pref_new(); + location_route_pref_set_route_type(pref, "FASTEST"); + + ret = location_request_route(location_obj, origin, destination, waypoint, pref, cb_route, NULL, &req_id); + GetLocationError(str, ret); + if (ret != LOCATION_ERROR_NONE) { + g_printf("Fail to search route by address. Error[%s]\n", str); + } else { + g_printf("Search Route successfully, req_id %d\n", req_id); + } + }else if(0 == g_strcmp0("17a", strOpt)) { + g_printf("17a. location_cancel_route_request\n"); + + int req_id; + g_printf("Input ReqID : "); + scanf("%d", &req_id); + + ret = location_cancel_route_request(location_obj, req_id); + GetLocationError(str, ret); + if (ret != LOCATION_ERROR_NONE) { + g_printf("Fail to cancel route request. Error[%s]\n", str); + } + else { + g_printf("location_cancel_route_request, req_id %d\n", req_id); + } + + }else if (0 == g_strcmp0 ("18", strOpt)) { + int idx = 0; + for (idx = 0; idx < MAP_SERVICE_TYPE_MAX; idx++) { + g_printf("[%d:%d], ", idx, location_is_supported_map_provider_capability (location_obj, idx)); + } + }else if (0 == g_strcmp0 ("19", strOpt)) { + int idx = 0; + for (idx = 0; idx < MAP_SERVICE_TYPE_MAX; idx++) { + g_printf("[%d:", idx); + print_map_service_keys(location_obj, idx); + g_printf("]\n"); + } }else if(0 == g_strcmp0("99", strOpt)) { int ret = 0; const *str = "command"; diff --git a/tests/nmea-sample.c b/tests/nmea-sample.c index 7491589..62073a3 100644 --- a/tests/nmea-sample.c +++ b/tests/nmea-sample.c @@ -20,7 +20,7 @@ */ #include -#include +#include static GMainLoop *loop = NULL; GSource* nmea_src = NULL; diff --git a/tests/position-sample-gps.c b/tests/position-sample-gps.c index 60432f3..fb5b7d8 100644 --- a/tests/position-sample-gps.c +++ b/tests/position-sample-gps.c @@ -20,7 +20,7 @@ */ #include -#include +#include static GMainLoop *loop = NULL; diff --git a/tests/property-sample.c b/tests/property-sample.c index b11844e..b3096bd 100644 --- a/tests/property-sample.c +++ b/tests/property-sample.c @@ -20,7 +20,7 @@ */ #include -#include +#include static GMainLoop *loop = NULL; diff --git a/tests/satellite-sample.c b/tests/satellite-sample.c index 50fac0a..0c48b9a 100644 --- a/tests/satellite-sample.c +++ b/tests/satellite-sample.c @@ -20,7 +20,7 @@ */ #include -#include +#include static GMainLoop *loop = NULL; GSource* sat_src = NULL; diff --git a/tests/sps-test.c b/tests/sps-test.c index d8c9745..a426aad 100644 --- a/tests/sps-test.c +++ b/tests/sps-test.c @@ -20,7 +20,7 @@ */ #include -#include +#include static GMainLoop *loop = NULL; diff --git a/tests/velocity-sample.c b/tests/velocity-sample.c index 18cffdf..f62aead 100644 --- a/tests/velocity-sample.c +++ b/tests/velocity-sample.c @@ -20,7 +20,7 @@ */ #include -#include +#include static GMainLoop *loop = NULL; diff --git a/tests/wps-test.c b/tests/wps-test.c index 0d45e4a..bd49060 100644 --- a/tests/wps-test.c +++ b/tests/wps-test.c @@ -20,7 +20,7 @@ */ #include -#include +#include static GMainLoop *loop = NULL; diff --git a/tests/zone-sample.c b/tests/zone-sample.c index 28b2c76..0be3195 100644 --- a/tests/zone-sample.c +++ b/tests/zone-sample.c @@ -20,7 +20,7 @@ */ #include -#include +#include static GMainLoop *loop = NULL; -- cgit v1.2.3