From: Kim Kibum Date: Sun, 29 Apr 2012 08:00:48 +0000 (+0900) Subject: upload tizen1.0 source X-Git-Tag: 2.0_alpha~1 X-Git-Url: http://review.tizen.org/git/?p=framework%2Flocation%2Fgps-manager.git;a=commitdiff_plain;h=76aef537743d91a75c780eb6623b7b38a4c6547f upload tizen1.0 source --- diff --git a/debian/changelog b/debian/changelog index 702cc2b..369a067 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,88 @@ +gps-manager (0.1.6-7) unstable; urgency=low + + * fixed bug for setting replay mode on emulator + * Git: slp/pkgs/g/gps-manager + * Tag: gps-manager_0.1.6-7 + + -- Genie Kim Fri, 06 Apr 2012 11:16:43 +0900 + +gps-manager (0.1.6-6) unstable; urgency=low + + * check abnormal value of speed and direction in last velocity + * Git: slp/pkgs/g/gps-manager + * Tag: gps-manager_0.1.6-6 + + -- Genie Kim Mon, 02 Apr 2012 17:12:29 +0900 + +gps-manager (0.1.6-5) unstable; urgency=low + + * Read vconf to get last_position and last_velocity on module + * Git: slp/pkgs/g/gps-manager + * Tag: gps-manager_0.1.6-5 + + -- Minjune Kim Tue, 27 Mar 2012 11:14:08 +0900 + +gps-manager (0.1.6-4) unstable; urgency=low + + * fixed bug for setting replay mode + * Git: slp/pkgs/g/gps-manager + * Tag: gps-manager_0.1.6-4 + + -- Genie Kim Fri, 23 Mar 2012 10:56:10 +0900 + +gps-manager (0.1.6-3) unstable; urgency=low + + * Move object_new to ref_gps_mananger in last_pos, last_vel and last_sat + * Git: slp/pkgs/g/gps-manager + * Tag: gps-manager_0.1.6-3 + + -- Minjune Kim Tue, 20 Mar 2012 13:14:23 +0900 + +gps-manager (0.1.6-2) unstable; urgency=low + + * Fix the bug that timestamp in satellite info had been wrong. + * Git: slp/pkgs/g/gps-manager + * Tag: gps-manager_0.1.6-2 + + -- Minjune Kim Mon, 19 Mar 2012 16:43:05 +0900 + +gps-manager (0.1.6-1) unstable; urgency=low + + * bug fix for last_pos/vel/sat functions + * Git: slp/pkgs/g/gps-manager + * Tag: gps-manager_0.1.6-1 + + -- Genie Kim Thu, 08 Mar 2012 22:15:53 +0900 + +gps-manager (0.1.5-3) unstable; urgency=low + + * Delete useless . in gps-manager.postinst.in + * Git: slp/pkgs/g/gps-manager + * Tag: gps-manager_0.1.5-3 + + -- Youngae Kang Thu, 08 Mar 2012 10:16:39 +0900 + +gps-manager (0.1.5-2) unstable; urgency=low + + * Remove checking a sat_cb to support an emulator. + * Git: slp/pkgs/g/gps-manager + * Tag: gps-manager_0.1.5-2 + + -- Minjune Kim Wed, 07 Mar 2012 10:57:03 +0900 + +gps-manager (0.1.5-1) unstable; urgency=low + + * add feature for pos/vel/sat + * add satellite callback in module + * Git: slp/pkgs/g/gps-manager + * Tag: gps-manager_0.1.5-1 + + -- Genie Kim Mon, 27 Feb 2012 21:54:47 +0900 + gps-manager (0.1.4-2) unstable; urgency=low * Fix a crash while init WPS module on emulator - * Git: pkgs/g/gps-manager + * Git: slp/pkgs/g/gps-manager * Tag: gps-manager_0.1.4-2 -- Minjune Kim Mon, 20 Feb 2012 22:36:47 +0900 @@ -9,7 +90,7 @@ gps-manager (0.1.4-2) unstable; urgency=low gps-manager (0.1.4-1) unstable; urgency=low * change indicator state to using gps and wps - * Git: pkgs/g/gps-manager + * Git: slp/pkgs/g/gps-manager * Tag: gps-manager_0.1.4-1 -- Minjune Kim Fri, 17 Feb 2012 17:08:22 +0900 @@ -17,7 +98,7 @@ gps-manager (0.1.4-1) unstable; urgency=low gps-manager (0.1.3-2) unstable; urgency=low * add qcom plugin in script - * Git: pkgs/g/gps-manager + * Git: slp/pkgs/g/gps-manager * Tag: gps-manager_0.1.3-2 -- Genie Kim Thu, 16 Feb 2012 11:18:58 +0900 @@ -25,7 +106,7 @@ gps-manager (0.1.3-2) unstable; urgency=low gps-manager (0.1.3-1) unstable; urgency=low * fixed bug at snprintf - * Git: pkgs/g/gps-manager + * Git: slp/pkgs/g/gps-manager * Tag: gps-manager_0.1.3-1 -- Genie Kim Mon, 13 Feb 2012 12:37:29 +0900 @@ -33,7 +114,7 @@ gps-manager (0.1.3-1) unstable; urgency=low gps-manager (0.1.2-1) unstable; urgency=low * adjust replay plugin - * Git: pkgs/g/gps-manager + * Git: slp/pkgs/g/gps-manager * Tag: gps-manager_0.1.2-1 -- Genie Kim Wed, 01 Feb 2012 16:30:55 +0900 @@ -41,7 +122,7 @@ gps-manager (0.1.2-1) unstable; urgency=low gps-manager (0.1.1-0) unstable; urgency=low * add last position and change setting key path - * Git: pkgs/g/gps-manager + * Git: slp/pkgs/g/gps-manager * Tag: gps-manager_0.1.1-0 -- Genie Kim Thu, 26 Jan 2012 17:30:31 +0900 @@ -49,7 +130,7 @@ gps-manager (0.1.1-0) unstable; urgency=low gps-manager (0.1.0-1) unstable; urgency=low * Refactor source code. - * Git: pkgs/g/gps-manager + * Git: slp/pkgs/g/gps-manager * Tag: gps-manager_0.1.0-1 -- Yunhan Kim Wed, 21 Dec 2011 17:01:05 +0900 @@ -57,7 +138,7 @@ gps-manager (0.1.0-1) unstable; urgency=low gps-manager (0.1.0-0) unstable; urgency=low * Initial release - * Git: pkgs/g/gps-manager + * Git: slp/pkgs/g/gps-manager * Tag: gps-manager_0.1.0-0 -- Yunhan Kim Thu, 06 Oct 2011 14:41:51 +0900 diff --git a/debian/control b/debian/control index b9e87fe..86d4841 100644 --- a/debian/control +++ b/debian/control @@ -2,18 +2,18 @@ Source: gps-manager Section: devel Priority: extra Maintainer: Youngae Kang , Yunhan Kim , Minjune Kim , Genie Kim -Build-Depends: debhelper (>= 4.0.0), autotools-dev, libslp-tapi-dev, libnetwork-dev, libslp-setting-dev, libglib2.0-dev, libdbus-glib-1-dev, dlog-dev, libslp-msg-service-dev, libslp-pm-dev, libheynoti-dev, libslp-sysman-dev, libgeoclue-dev, libslp-location-dev +Build-Depends: debhelper (>= 4.0.0), autotools-dev, libslp-tapi-dev, libnetwork-dev, libglib2.0-dev, libdbus-glib-1-dev, dlog-dev, libslp-msg-service-dev, libslp-pm-dev, libheynoti-dev, libslp-sysman-dev, libgeoclue-dev, libslp-location-dev, libvconf-dev Package: gps-manager Section: net Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, libslp-tapi-0, libnetwork-0, libslp-setting-0, libglib2.0-0, libdlog-0, libslp-msg-service-0, libslp-pm-0, libheynoti-0, libslp-sysman +Depends: ${shlibs:Depends}, ${misc:Depends}, libslp-tapi-0, libnetwork-0, libglib2.0-0, libdlog-0, libslp-msg-service-0, libslp-pm-0, libheynoti-0, libslp-sysman Description: GPS Manager for SLP Package: location-gps-manager Section: libs Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, gps-manager (= ${binary:Version}) +Depends: ${shlibs:Depends}, ${misc:Depends}, gps-manager (= ${binary:Version}), libvconf-0 Description: libslp-location module for gps-manager Package: gps-manager-plugin-dev diff --git a/debian/gps-manager.postinst b/debian/gps-manager.postinst.in similarity index 80% rename from debian/gps-manager.postinst rename to debian/gps-manager.postinst.in index fb5a453..f10afcb 100644 --- a/debian/gps-manager.postinst +++ b/debian/gps-manager.postinst.in @@ -1,5 +1,7 @@ #!/bin/sh +ARCH=@ARCH@ + if [ "${USER}" = "root" ] then #Change File owner @@ -33,8 +35,13 @@ vconftool set -t int db/location/nmea/LoggingEnabled "0" -f #REPLAY_SETTING vconftool set -t string db/location/replay/FileName "nmea_replay.log" -f -vconftool set -t int db/location/replay/ReplayEnabled "0" -f -vconftool set -t int db/location/replay/ReplayMode "1" -f +if [ $ARCH == "armel" ]; then + vconftool set -t int db/location/replay/ReplayEnabled "0" -f + vconftool set -t int db/location/replay/ReplayMode "1" -f +else + vconftool set -t int db/location/replay/ReplayEnabled "1" -f + vconftool set -t int db/location/replay/ReplayMode "0" -f +fi vconftool set -t double db/location/replay/ManualLatitude "0.0" -f vconftool set -t double db/location/replay/ManualLongitude "0.0" -f vconftool set -t double db/location/replay/ManualAltitude "0.0" -f diff --git a/debian/location-gps-manager.postinst.in b/debian/location-gps-manager.postinst.in new file mode 100644 index 0000000..995c987 --- /dev/null +++ b/debian/location-gps-manager.postinst.in @@ -0,0 +1,10 @@ +#!/bin/sh + +ARCH=@ARCH@ + +if [ $ARCH != "armel" ]; then + cp -f /usr/lib/location/module/libgps.so /usr/lib/location/module/libwps0.so +fi + +sync + diff --git a/debian/rules b/debian/rules index b84999d..e58d7f6 100755 --- a/debian/rules +++ b/debian/rules @@ -19,8 +19,10 @@ DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH) ifneq (,$(findstring armel,$(DEB_HOST_ARCH))) GPS_ENABLER ?= --enable-gps + ARCH ?= armel else - GPS_ENABLER ?= --disable-gps + GPS_ENABLER ?= --enable-gps + ARCH ?= x86 endif #CFLAGS ?= -Wall -g @@ -66,6 +68,7 @@ build-stamp: configure-stamp cat $$f > $${f%.in}; \ sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \ sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \ + sed -i -e "s#@ARCH@#$(ARCH)#g" $${f%.in}; \ done touch $@ diff --git a/gps-manager/gps_manager.c b/gps-manager/gps_manager.c index 4687f4a..5e976f3 100644 --- a/gps-manager/gps_manager.c +++ b/gps-manager/gps_manager.c @@ -42,6 +42,7 @@ #include "gps_manager.h" #include "server.h" +#include "last_position.h" #define GEOCLUE_GPSMANAGER_DBUS_SERVICE "org.freedesktop.Geoclue.Providers.GpsManager" #define GEOCLUE_GPSMANAGER_DBUS_PATH "/org/freedesktop/Geoclue/Providers/GpsManager" @@ -55,6 +56,9 @@ typedef struct { sv_data_t satellite; nmea_data_t nmea; + pos_data_t last_position; + sv_data_t last_satellite; + GHashTable *connections; } GeoclueGpsManager; @@ -163,6 +167,7 @@ static void update_position_cb(pos_data_t * pos, gps_error_t error, void *user_d GeoclueGpsManager *gpsmanager = (GEOCLUE_GPSMANAGER(user_data)); memcpy(&gpsmanager->position, pos, sizeof(pos_data_t)); + memcpy(&gpsmanager->last_position, pos, sizeof(pos_data_t)); gpsmanager->status = GEOCLUE_STATUS_AVAILABLE; @@ -193,6 +198,8 @@ static void update_satellite_cb(sv_data_t * sv, void *user_data) GeoclueGpsManager *gpsmanager = (GEOCLUE_GPSMANAGER(user_data)); memcpy(&gpsmanager->satellite, sv, sizeof(sv_data_t)); + memcpy(&gpsmanager->last_satellite, sv, sizeof(sv_data_t)); + timestamp = sv->timestamp; used_prn = g_array_new(FALSE, FALSE, sizeof(guint)); for (index = 0; index < sv->num_of_sat; ++index) { @@ -208,15 +215,14 @@ static void update_satellite_cb(sv_data_t * sv, void *user_data) GValue sv_info = { 0, }; g_value_init(&sv_info, GEOCLUE_SATELLITE_INFO); g_value_take_boxed(&sv_info, dbus_g_type_specialized_construct(GEOCLUE_SATELLITE_INFO)); - dbus_g_type_struct_set(&sv_info, - 0, sv->sat[index].prn, - 1, sv->sat[index].elevation, - 2, sv->sat[index].azimuth, 3, sv->sat[index].snr, G_MAXUINT); + dbus_g_type_struct_set(&sv_info, 0, sv->sat[index].prn, 1, + sv->sat[index].elevation, 2, sv->sat[index].azimuth, 3, sv->sat[index].snr, G_MAXUINT); g_ptr_array_add(satellite_info, g_value_get_boxed(&sv_info)); } - gc_iface_satellite_emit_satellite_changed(GC_IFACE_SATELLITE(gpsmanager), - timestamp, satellite_used, sv->num_of_sat, used_prn, satellite_info); + gc_iface_satellite_emit_satellite_changed(GC_IFACE_SATELLITE + (gpsmanager), timestamp, + satellite_used, sv->num_of_sat, used_prn, satellite_info); g_array_free(used_prn, TRUE); g_ptr_array_free(satellite_info, TRUE); @@ -359,6 +365,11 @@ static void geoclue_gpsmanager_init(GeoclueGpsManager * gpsmanager) dbus_g_proxy_connect_signal(driver, "NameOwnerChanged", G_CALLBACK(name_owner_changed), provider, NULL); dbus_g_connection_register_g_object(provider->connection, GEOCLUE_GPSMANAGER_DBUS_PATH, G_OBJECT(provider)); + + memset(&gpsmanager->last_position, 0x00, sizeof(pos_data_t)); + memset(&gpsmanager->last_satellite, 0x00, sizeof(sv_data_t)); + + gps_manager_get_last_position(&gpsmanager->last_position); } static gboolean get_position(GcIfacePosition * gc, @@ -406,8 +417,52 @@ static gboolean get_position(GcIfacePosition * gc, } if (accuracy) { - *accuracy = geoclue_accuracy_new(GEOCLUE_ACCURACY_LEVEL_DETAILED, - gpsmanager->position.hor_accuracy, gpsmanager->position.ver_accuracy); + *accuracy = + geoclue_accuracy_new(GEOCLUE_ACCURACY_LEVEL_DETAILED, + gpsmanager->position.hor_accuracy, gpsmanager->position.ver_accuracy); + } + + return TRUE; +} + +static gboolean get_last_position(GcIfacePosition * gc, + GeocluePositionFields * fields, + int *timestamp, double *latitude, + double *longitude, double *altitude, GeoclueAccuracy ** accuracy, GError ** error) +{ + GeoclueGpsManager *gpsmanager = (GEOCLUE_GPSMANAGER(gc)); + + if (!fields) { + g_set_error(error, GEOCLUE_ERROR, GEOCLUE_ERROR_FAILED, "ERROR: Invalid parameters"); + return FALSE; + } + + *fields = GEOCLUE_POSITION_FIELDS_NONE; + + if (timestamp) { + *timestamp = gpsmanager->last_position.timestamp; + } + + if (latitude) { + *fields |= GEOCLUE_POSITION_FIELDS_LATITUDE; + *latitude = gpsmanager->last_position.latitude; + } + + if (longitude) { + *fields |= GEOCLUE_POSITION_FIELDS_LONGITUDE; + *longitude = gpsmanager->last_position.longitude; + } + + if (altitude) { + *fields |= GEOCLUE_POSITION_FIELDS_ALTITUDE; + *altitude = gpsmanager->last_position.altitude; + + } + + if (accuracy) { + *accuracy = + geoclue_accuracy_new(GEOCLUE_ACCURACY_LEVEL_DETAILED, + gpsmanager->last_position.hor_accuracy, gpsmanager->last_position.ver_accuracy); } return TRUE; @@ -455,6 +510,36 @@ static gboolean get_velocity(GcIfaceVelocity * gc, return TRUE; } +static gboolean get_last_velocity(GcIfaceVelocity * gc, + GeoclueVelocityFields * fields, + int *timestamp, double *speed, double *direction, double *climb, GError ** error) +{ + GeoclueGpsManager *gpsmanager = (GEOCLUE_GPSMANAGER(gc)); + + if (!fields) { + g_set_error(error, GEOCLUE_ERROR, GEOCLUE_ERROR_FAILED, "ERROR: Invalid parameters"); + return FALSE; + } + + *fields = GEOCLUE_VELOCITY_FIELDS_NONE; + + if (timestamp) { + *timestamp = gpsmanager->last_position.timestamp; + } + + if (speed) { + *fields |= GEOCLUE_VELOCITY_FIELDS_SPEED; + *speed = gpsmanager->last_position.speed; + } + + if (direction) { + *fields |= GEOCLUE_VELOCITY_FIELDS_DIRECTION; + *direction = gpsmanager->last_position.bearing; + } + + return TRUE; +} + static gboolean get_nmea(GcIfaceNmea * gc, int *timestamp, char **nmea_data, GError ** error) { GeoclueGpsManager *gpsmanager = (GEOCLUE_GPSMANAGER(gc)); @@ -488,7 +573,7 @@ static gboolean get_satellite(GcIfaceSatellite * gc, } if (timestamp) { - *timestamp = gpsmanager->position.timestamp; + *timestamp = gpsmanager->satellite.timestamp; } if (satellite_used) { @@ -523,10 +608,62 @@ static gboolean get_satellite(GcIfaceSatellite * gc, g_value_init(&sv_info, GEOCLUE_SATELLITE_INFO); g_value_take_boxed(&sv_info, dbus_g_type_specialized_construct(GEOCLUE_SATELLITE_INFO)); dbus_g_type_struct_set(&sv_info, - 0, gpsmanager->satellite.sat[index].prn, - 1, gpsmanager->satellite.sat[index].elevation, - 2, gpsmanager->satellite.sat[index].azimuth, - 3, gpsmanager->satellite.sat[index].snr, G_MAXUINT); + 0, gpsmanager->satellite.sat[index].prn, + 1, gpsmanager->satellite.sat[index].elevation, + 2, gpsmanager->satellite.sat[index].azimuth, + 3, gpsmanager->satellite.sat[index].snr, G_MAXUINT); + g_ptr_array_add(*satellite_info, g_value_get_boxed(&sv_info)); + } + } + return TRUE; +} + +static gboolean get_last_satellite(GcIfaceSatellite * gc, + int *timestamp, int *satellite_used, + int *satellite_visible, GArray ** used_prn, GPtrArray ** satellite_info, GError ** error) +{ + GeoclueGpsManager *gpsmanager = (GEOCLUE_GPSMANAGER(gc)); + + if (timestamp) { + *timestamp = gpsmanager->last_satellite.timestamp; + } + + if (satellite_used) { + int index; + int count = 0; + for (index = 0; index < gpsmanager->last_satellite.num_of_sat; ++index) { + count += gpsmanager->last_satellite.sat[index].used ? 1 : 0; + } + *satellite_used = count; + } + + if (satellite_visible) { + *satellite_visible = gpsmanager->last_satellite.num_of_sat; + } + + if (used_prn) { + int index; + *used_prn = g_array_new(FALSE, FALSE, sizeof(guint)); + + for (index = 0; index < gpsmanager->last_satellite.num_of_sat; ++index) { + if (gpsmanager->last_satellite.sat[index].used) { + g_array_append_val(*used_prn, gpsmanager->last_satellite.sat[index].prn); + } + } + } + + if (satellite_info) { + int index; + *satellite_info = g_ptr_array_new(); + for (index = 0; index < gpsmanager->last_satellite.num_of_sat; ++index) { + GValue sv_info = { 0, }; + g_value_init(&sv_info, GEOCLUE_SATELLITE_INFO); + g_value_take_boxed(&sv_info, dbus_g_type_specialized_construct(GEOCLUE_SATELLITE_INFO)); + dbus_g_type_struct_set(&sv_info, 0, + gpsmanager->last_satellite.sat[index].prn, 1, + gpsmanager->last_satellite.sat[index].elevation, 2, + gpsmanager->last_satellite.sat[index].azimuth, 3, + gpsmanager->last_satellite.sat[index].snr, G_MAXUINT); g_ptr_array_add(*satellite_info, g_value_get_boxed(&sv_info)); } @@ -537,11 +674,13 @@ static gboolean get_satellite(GcIfaceSatellite * gc, static void init_position(GcIfacePositionClass * iface) { iface->get_position = get_position; + iface->get_last_position = get_last_position; } static void init_velocity(GcIfaceVelocityClass * iface) { iface->get_velocity = get_velocity; + iface->get_last_velocity = get_last_velocity; } static void init_nmea(GcIfaceNmeaClass * iface) @@ -552,6 +691,7 @@ static void init_nmea(GcIfaceNmeaClass * iface) static void init_satellite(GcIfaceSatelliteClass * iface) { iface->get_satellite = get_satellite; + iface->get_last_satellite = get_last_satellite; } static void init_geoclue(GcIfaceGeoclueClass * iface) diff --git a/gps-manager/last_position.c b/gps-manager/last_position.c index b9202b7..77baee3 100644 --- a/gps-manager/last_position.c +++ b/gps-manager/last_position.c @@ -20,75 +20,64 @@ */ #include -#include #include -#include #include "gps_manager_data_types.h" #include "last_position.h" #include "debug_util.h" #include "setting.h" -static void gps_manager_set_last_position(last_pos_t * last_pos) +void gps_manager_set_last_position(pos_data_t * last_pos) { - LOG_GPS(DBG_LOW, "set Last Latitude = %f Longitude = %f Altitude = %f H_Accuracy = %f V_Accuracy = %f", - last_pos->latitude, last_pos->longitude, last_pos->altitude, last_pos->hor_accuracy, last_pos->ver_accuracy); + LOG_GPS(DBG_LOW, "set Latitude = %f Longitude = %f Altitude = %f", last_pos->latitude, last_pos->longitude, last_pos->altitude); + LOG_GPS(DBG_LOW, "set Speed = %f Direction = %f", last_pos->speed, last_pos->bearing); + LOG_GPS(DBG_LOW, "set H_Accuracy = %f V_Accuracy = %f", last_pos->hor_accuracy, last_pos->ver_accuracy); - setting_set_int(LAST_TIMESTAMP, last_pos->timestamp); - setting_set_double(LAST_LATITUDE, last_pos->latitude); - setting_set_double(LAST_LONGITUDE, last_pos->longitude); - setting_set_double(LAST_ALTITUDE, last_pos->altitude); - setting_set_double(LAST_HOR_ACCURACY, last_pos->hor_accuracy); - setting_set_double(LAST_VER_ACCURACY, last_pos->ver_accuracy); -} - -double deg2rad(double deg) -{ - return (deg * M_PI / 180); -} - -void gps_manager_get_last_position(last_pos_t * last_pos) -{ - setting_get_int(LAST_TIMESTAMP, &last_pos->timestamp); - setting_get_double(LAST_LATITUDE, &last_pos->latitude); - setting_get_double(LAST_LONGITUDE, &last_pos->longitude); - setting_get_double(LAST_ALTITUDE, &last_pos->altitude); - setting_get_double(LAST_HOR_ACCURACY, &last_pos->hor_accuracy); - setting_get_double(LAST_VER_ACCURACY, &last_pos->ver_accuracy); + int timestamp = last_pos->timestamp; + double lat = last_pos->latitude; + double lon = last_pos->longitude; + double alt = last_pos->altitude; + double spd = last_pos->speed; + double dir = last_pos->bearing; + double h_acc = last_pos->hor_accuracy; + double v_acc = last_pos->ver_accuracy; - LOG_GPS(DBG_LOW, "get Last Latitude = %f Longitude = %f Altitude = %f H_Accuracy = %f V_Accuracy = %f", - last_pos->latitude, last_pos->longitude, last_pos->altitude, last_pos->hor_accuracy, last_pos->ver_accuracy); + setting_set_int(LAST_TIMESTAMP, timestamp); + setting_set_double(LAST_LATITUDE, lat); + setting_set_double(LAST_LONGITUDE, lon); + setting_set_double(LAST_ALTITUDE, alt); + setting_set_double(LAST_SPEED, spd); + setting_set_double(LAST_DIRECTION, dir); + setting_set_double(LAST_HOR_ACCURACY, h_acc); + setting_set_double(LAST_VER_ACCURACY, v_acc); } -int gps_manager_distance_to_last_position(const pos_data_t * pos, const last_pos_t * last_pos) +void gps_manager_get_last_position(pos_data_t * last_pos) { - double delta_lat, delta_long; - double dist; - - delta_lat = pos->latitude - last_pos->latitude; - delta_long = pos->longitude - last_pos->longitude; + int timestamp; + double lat, lon, alt; + double spd, dir; + double h_acc, v_acc; - dist = sin(deg2rad(delta_lat) / 2) * sin(deg2rad(delta_lat) / 2) + - cos(deg2rad(pos->latitude)) * cos(deg2rad(last_pos->latitude)) * - sin(deg2rad(delta_long) / 2) * sin(deg2rad(delta_long) / 2); - dist = 2 * atan2(sqrt(dist), sqrt(1 - dist)); - dist = 6371 * dist; // unit: 'km' + setting_get_int(LAST_TIMESTAMP, ×tamp); + setting_get_double(LAST_LATITUDE, &lat); + setting_get_double(LAST_LONGITUDE, &lon); + setting_get_double(LAST_ALTITUDE, &alt); + setting_get_double(LAST_SPEED, &spd); + setting_get_double(LAST_DIRECTION, &dir); + setting_get_double(LAST_HOR_ACCURACY, &h_acc); + setting_get_double(LAST_VER_ACCURACY, &v_acc); - if (dist > 0.3) { - return 0; - } else { - return -1; - } -} - -void gps_manager_update_last_position(const pos_data_t * pos, last_pos_t * last_pos) -{ - last_pos->timestamp = pos->timestamp; - last_pos->latitude = pos->latitude; - last_pos->longitude = pos->longitude; - last_pos->altitude = pos->altitude; - last_pos->hor_accuracy = pos->hor_accuracy; - last_pos->ver_accuracy = pos->ver_accuracy; + last_pos->timestamp = timestamp; + last_pos->latitude = lat; + last_pos->longitude = lon; + last_pos->altitude = alt; + last_pos->speed = spd; + last_pos->bearing = dir; + last_pos->hor_accuracy = h_acc; + last_pos->ver_accuracy = v_acc; - gps_manager_set_last_position(last_pos); + LOG_GPS(DBG_LOW, "get Latitude = %f Longitude = %f Altitude = %f", last_pos->latitude, last_pos->longitude, last_pos->altitude); + LOG_GPS(DBG_LOW, "get Speed = %f Direction = %f", last_pos->speed, last_pos->bearing); + LOG_GPS(DBG_LOW, "get H_Accuracy = %f V_Accuracy = %f", last_pos->hor_accuracy, last_pos->ver_accuracy); } diff --git a/gps-manager/last_position.h b/gps-manager/last_position.h index 38fb799..636db4c 100644 --- a/gps-manager/last_position.h +++ b/gps-manager/last_position.h @@ -24,17 +24,7 @@ #include "gps_manager_data_types.h" -typedef struct { - int timestamp; - double latitude; - double longitude; - double altitude; - double hor_accuracy; - double ver_accuracy; -} last_pos_t; - -void gps_manager_get_last_position(last_pos_t * last_pos); -int gps_manager_distance_to_last_position(const pos_data_t * pos, const last_pos_t * last_pos); -void gps_manager_update_last_position(const pos_data_t * pos, last_pos_t * last_pos); +void gps_manager_set_last_position(pos_data_t * last_pos); +void gps_manager_get_last_position(pos_data_t * last_pos); #endif /* _GPS_MANAGER_LAST_POSITON_H_ */ diff --git a/gps-manager/plugin_module.c b/gps-manager/plugin_module.c index ca36092..93824ed 100644 --- a/gps-manager/plugin_module.c +++ b/gps-manager/plugin_module.c @@ -24,6 +24,7 @@ #include #include #include "plugin_module.h" +#include "setting.h" #include "debug_util.h" #define SPECIFIC_PLUGIN_PATH_PREFIX "/usr/lib/libSLP-lbs-plugin-" @@ -47,6 +48,7 @@ int load_plugin_module(char *specific_name, void **plugin_handle) if (access (plugin_path, R_OK) != 0) { strncpy(plugin_path, GPS_MANAGER_PLUGIN_PATH, sizeof(plugin_path)); + setting_set_int(REPLAY_ENABLED, 1); } *plugin_handle = dlopen(plugin_path, RTLD_NOW); diff --git a/gps-manager/server.c b/gps-manager/server.c index 4fc3cd4..31c12dd 100644 --- a/gps-manager/server.c +++ b/gps-manager/server.c @@ -76,7 +76,7 @@ gps_server_param_t g_gps_params; pos_data_t *gps_pos_data = NULL; sv_data_t *gps_sv_data = NULL; nmea_data_t *gps_nmea_data = NULL; -last_pos_t *gps_last_pos = NULL; +pos_data_t *gps_last_pos = NULL; int g_dnet_used = 0; @@ -276,12 +276,12 @@ static gboolean _initialize_data() } if (gps_last_pos == NULL) { - gps_last_pos = (last_pos_t *) malloc(sizeof(last_pos_t)); + gps_last_pos = (pos_data_t *) malloc(sizeof(pos_data_t)); if (gps_last_pos == NULL) { LOG_GPS(DBG_ERR, "Failed to alloc gps_last_pos"); result = FALSE; } else { - memset(gps_last_pos, 0x00, sizeof(last_pos_t)); + memset(gps_last_pos, 0x00, sizeof(pos_data_t)); } } return result; @@ -348,10 +348,17 @@ static void _gps_plugin_handler_init(char *module_name) g_gps_plugin.handle = NULL; g_gps_plugin.name = (char *)malloc(strlen(module_name) + 1); snprintf(g_gps_plugin.name, strlen(module_name) + 1, "%s", module_name); + if (strcmp(REPLAY_MODULE, g_gps_plugin.name) == 0) { + setting_set_int(REPLAY_ENABLED, 1); + } else { + setting_set_int(REPLAY_ENABLED, 0); + } } static void _gps_plugin_handler_deinit() { + setting_set_int(REPLAY_ENABLED, 0); + if (g_gps_plugin.handle != NULL) { g_gps_plugin.handle = NULL; } @@ -369,13 +376,13 @@ static void _gps_read_params() if (setting_get_int(GPS_SESSION, &int_val) == FALSE) { LOG_GPS(DBG_ERR, "//ERROR!! GPS_SESSION setting get failed"); - int_val = GPS_SESSION_TRACKING_MODE; //set to default + int_val = GPS_SESSION_TRACKING_MODE; } g_gps_params.session_type = int_val; if (setting_get_int(GPS_OPERATION, &int_val) == FALSE) { LOG_GPS(DBG_ERR, "//ERROR!! GPS_OPERATION setting get failed"); - int_val = GPS_OPERATION_STANDALONE; //set to default + int_val = GPS_OPERATION_STANDALONE; } g_gps_params.operation_mode = int_val; @@ -481,11 +488,11 @@ static void _gps_server_start_event() } if (gps_last_pos == NULL) { - gps_last_pos = (last_pos_t *) malloc(sizeof(last_pos_t)); + gps_last_pos = (pos_data_t *) malloc(sizeof(pos_data_t)); if (gps_last_pos == NULL) { LOG_GPS(DBG_WARN, "//callback: gps_last_pos re-malloc Failed!!"); } else { - memset(gps_last_pos, 0x00, sizeof(last_pos_t)); + memset(gps_last_pos, 0x00, sizeof(pos_data_t)); gps_manager_get_last_position(gps_last_pos); } } @@ -529,10 +536,9 @@ static void _report_pos_event(gps_event_info_t * gps_event) { if (gps_pos_data != NULL) { memcpy(gps_pos_data, &(gps_event->event_data.pos_ind.pos), sizeof(pos_data_t)); + memcpy(gps_last_pos, gps_pos_data, sizeof(pos_data_t)); g_update_cb.pos_cb(gps_pos_data, gps_event->event_data.pos_ind.error, g_user_data); - if (gps_manager_distance_to_last_position(gps_pos_data, gps_last_pos) != -1) { - gps_manager_update_last_position(gps_pos_data, gps_last_pos); - } + gps_manager_set_last_position(gps_last_pos); memset(gps_pos_data, 0x00, sizeof(pos_data_t)); } else { LOG_GPS(DBG_ERR, "gps_sv_data is NULL"); diff --git a/gps-manager/setting.h b/gps-manager/setting.h index 5f2857d..b938af0 100644 --- a/gps-manager/setting.h +++ b/gps-manager/setting.h @@ -45,13 +45,15 @@ #define REPLAY_SETTING LOCATION_SETTING_PATH"/replay" #define REPLAY_ENABLED REPLAY_SETTING"/ReplayEnabled" -#define LAST_POSITION LOCATION_SETTING_PATH"/lastposition" +#define LAST_POSITION LOCATION_SETTING_PATH"/last" #define METHOD_GPS LAST_POSITION"/gps" #define LAST_TIMESTAMP METHOD_GPS"/Timestamp" #define LAST_LATITUDE METHOD_GPS"/Latitude" #define LAST_LONGITUDE METHOD_GPS"/Longitude" #define LAST_ALTITUDE METHOD_GPS"/Altitude" +#define LAST_SPEED METHOD_GPS"/Speed" +#define LAST_DIRECTION METHOD_GPS"/Direction" #define LAST_HOR_ACCURACY METHOD_GPS"/HorAccuracy" #define LAST_VER_ACCURACY METHOD_GPS"/VerAccuracy" diff --git a/module/module_gps_manager.c b/module/module_gps_manager.c index 70e0564..e92ea4e 100644 --- a/module/module_gps_manager.c +++ b/module/module_gps_manager.c @@ -21,6 +21,7 @@ #include +#include #include #include @@ -36,263 +37,285 @@ #include "log.h" -typedef struct{ - char devname[256]; - GeocluePosition *pos; - GeoclueVelocity *vel; - GeoclueNmea *nmea; +#define VCONF_LOCATION_PATH "db/location" +#define LOCATION_LAST_PATH VCONF_LOCATION_PATH"/last" +#define GPS_LAST_PATH LOCATION_LAST_PATH"/gps" +#define GPS_LAST_TIMESTAMP GPS_LAST_PATH"/Timestamp" +#define GPS_LAST_LATITUDE GPS_LAST_PATH"/Latitude" +#define GPS_LAST_LONGITUDE GPS_LAST_PATH"/Longitude" +#define GPS_LAST_ALTITUDE GPS_LAST_PATH"/Altitude" +#define GPS_LAST_HORACCURACY GPS_LAST_PATH"/HorAccuracy" +#define GPS_LAST_VERACCURACY GPS_LAST_PATH"/VerAccuracy" +#define GPS_LAST_SPEED GPS_LAST_PATH"/Speed" +#define GPS_LAST_DIRECTION GPS_LAST_PATH"/Direction" + + +typedef struct { + char devname[256]; + GeocluePosition *pos; + GeoclueVelocity *vel; + GeoclueNmea *nmea; GeoclueSatellite *sat; - LocModStatusCB status_cb; - LocModPositionCB pos_cb; - LocModVelocityCB vel_cb; - gpointer userdata; - gboolean is_started; + LocModStatusCB status_cb; + LocModPositionCB pos_cb; + LocModVelocityCB vel_cb; + LocModSatelliteCB sat_cb; + gpointer userdata; + gboolean is_started; } GpsManagerData; -static void -status_callback (GeoclueProvider *provider, - gint status, - gpointer userdata) +#define GPS_MANAGER_SERVICE_NAME "org.freedesktop.Geoclue.Providers.GpsManager" +#define GPS_MANAGER_SERVICE_PATH "/org/freedesktop/Geoclue/Providers/GpsManager" + + +static void status_callback(GeoclueProvider * provider, gint status, gpointer userdata) { - GpsManagerData* gps_manager = (GpsManagerData*)userdata; - g_return_if_fail (gps_manager); - g_return_if_fail (gps_manager->status_cb); - - switch(status){ - case GEOCLUE_STATUS_ERROR: - case GEOCLUE_STATUS_UNAVAILABLE: - case GEOCLUE_STATUS_ACQUIRING: - MOD_LOGD("GEOCLUE_STATUS_ACQUIRING/ERROR/UNAVAILABLE"); - gps_manager->status_cb(FALSE, LOCATION_STATUS_NO_FIX, gps_manager->userdata); - break; - case GEOCLUE_STATUS_AVAILABLE: - MOD_LOGD("GEOCLUE_STATUS_AVAILABLE"); - gps_manager->status_cb(TRUE, LOCATION_STATUS_3D_FIX, gps_manager->userdata); - break; - default: - break; - } + GpsManagerData *gps_manager = (GpsManagerData *) userdata; + g_return_if_fail(gps_manager); + g_return_if_fail(gps_manager->status_cb); + + switch (status) { + case GEOCLUE_STATUS_ERROR: + case GEOCLUE_STATUS_UNAVAILABLE: + case GEOCLUE_STATUS_ACQUIRING: + MOD_LOGD("GEOCLUE_STATUS_ACQUIRING/ERROR/UNAVAILABLE"); + gps_manager->status_cb(FALSE, LOCATION_STATUS_NO_FIX, gps_manager->userdata); + break; + case GEOCLUE_STATUS_AVAILABLE: + MOD_LOGD("GEOCLUE_STATUS_AVAILABLE"); + gps_manager->status_cb(TRUE, LOCATION_STATUS_3D_FIX, gps_manager->userdata); + break; + default: + break; + } } -static void -satellite_callback (GeoclueSatellite *satellite, - int timestamp, - int satellite_used, - int satellite_visible, - GArray *used_prn, - GPtrArray *sat_info, - gpointer userdata) +static void satellite_callback(GeoclueSatellite * satellite, int timestamp, + int satellite_used, int satellite_visible, + GArray * used_prn, GPtrArray * sat_info, gpointer userdata) { - int idx; + GpsManagerData *gps_manager = (GpsManagerData *) userdata; + g_return_if_fail(gps_manager); + g_return_if_fail(gps_manager->sat_cb); - MOD_LOGD("satellite_callback!!!\n"); - MOD_LOGD("timestamp: %d", timestamp); - MOD_LOGD("satellite_used: %d", satellite_used); - MOD_LOGD("satellite_visible: %d", satellite_visible); + guint idx; + LocationSatellite *sat = NULL; - for (idx = 0; idx < satellite_used; idx++) { - MOD_LOGD ("used_prn[%d] : %d", idx, g_array_index (used_prn, guint, idx)); - } + sat = location_satellite_new(satellite_visible); + + sat->timestamp = timestamp; + sat->num_of_sat_inview = satellite_visible; + sat->num_of_sat_used = satellite_used; for (idx = 0; idx < satellite_visible; idx++) { - GValueArray *vals = (GValueArray*)g_ptr_array_index (sat_info, idx); - gint prn = g_value_get_int (g_value_array_get_nth (vals, 0)); - gint elev = g_value_get_int (g_value_array_get_nth (vals, 1)); - gint azim = g_value_get_int (g_value_array_get_nth (vals, 2)); - gint snr = g_value_get_int (g_value_array_get_nth (vals, 3)); - MOD_LOGD ("visible_prn[%d] : elev %d azim %d snr %d", prn, elev, azim, snr); + guint used_idx; + gboolean used; + GValueArray *vals = (GValueArray *) g_ptr_array_index(sat_info, idx); + gint prn = g_value_get_int(g_value_array_get_nth(vals, 0)); + gint elev = g_value_get_int(g_value_array_get_nth(vals, 1)); + gint azim = g_value_get_int(g_value_array_get_nth(vals, 2)); + gint snr = g_value_get_int(g_value_array_get_nth(vals, 3)); + for (used_idx = 0; used_idx < satellite_used; used_idx++) { + if (prn == g_array_index(used_prn, guint, idx)) { + used = TRUE; + break; + } else { + used = FALSE; + } + } + MOD_LOGD("prn[%d] : used %d elev %d azim %d snr %d", prn, used, elev, azim, snr); + location_satellite_set_satellite_details(sat, idx, prn, used, elev, azim, snr); } + + gps_manager->sat_cb(TRUE, sat, gps_manager->userdata); + location_satellite_free(sat); } -static void -nmea_callback (GeoclueNmea *nmea, - int timestamp, - char *data, - gpointer userdata) + +static void nmea_callback(GeoclueNmea * nmea, int timestamp, char *data, gpointer userdata) { } -static void -position_callback (GeocluePosition *position, - GeocluePositionFields fields, - int timestamp, - double latitude, - double longitude, - double altitude, - GeoclueAccuracy *accuracy, - gpointer userdata) +static void position_callback(GeocluePosition * position, + GeocluePositionFields fields, int timestamp, + double latitude, double longitude, double altitude, GeoclueAccuracy * accuracy, gpointer userdata) { - GpsManagerData* gps_manager = (GpsManagerData*)userdata; - g_return_if_fail (gps_manager); - g_return_if_fail (gps_manager->pos_cb); + GpsManagerData *gps_manager = (GpsManagerData *) userdata; + g_return_if_fail(gps_manager); + g_return_if_fail(gps_manager->pos_cb); GeoclueAccuracyLevel level; double horiz_acc; double vert_acc; - geoclue_accuracy_get_details (accuracy, &level, &horiz_acc, &vert_acc); + geoclue_accuracy_get_details(accuracy, &level, &horiz_acc, &vert_acc); LocationPosition *pos = NULL; LocationAccuracy *acc = NULL; - if ((fields & GEOCLUE_POSITION_FIELDS_LATITUDE) && - (fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)) { + if ((fields & GEOCLUE_POSITION_FIELDS_LATITUDE) + && (fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)) { if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE) { - pos = location_position_new (timestamp, - latitude, - longitude, - altitude, - LOCATION_STATUS_3D_FIX); + pos = location_position_new(timestamp, latitude, longitude, altitude, LOCATION_STATUS_3D_FIX); } else { - pos = location_position_new (timestamp, - latitude, - longitude, - 0.0, - LOCATION_STATUS_2D_FIX); + pos = location_position_new(timestamp, latitude, longitude, 0.0, LOCATION_STATUS_2D_FIX); } } else { - pos = location_position_new (0.0, - 0.0, - 0.0, - 0.0, - LOCATION_STATUS_NO_FIX); + pos = location_position_new(0.0, 0.0, 0.0, 0.0, LOCATION_STATUS_NO_FIX); } if (accuracy) { GeoclueAccuracyLevel level; double horiz_acc; double vert_acc; - geoclue_accuracy_get_details (accuracy, &level, &horiz_acc, &vert_acc); - acc = location_accuracy_new (LOCATION_ACCURACY_LEVEL_DETAILED, horiz_acc, vert_acc); + geoclue_accuracy_get_details(accuracy, &level, &horiz_acc, &vert_acc); + acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, horiz_acc, vert_acc); } else { - acc = location_accuracy_new (LOCATION_ACCURACY_LEVEL_NONE, horiz_acc, vert_acc); + acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_NONE, horiz_acc, vert_acc); } - MOD_LOGD("time(%d) lat(%f) long(%f) alt(%f) status(%d) acc_level(%d) hoz_acc(%f) vert_acc(%f)", - pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status, - acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + MOD_LOGD + ("time(%d) lat(%f) long(%f) alt(%f) status(%d) acc_level(%d) hoz_acc(%f) vert_acc(%f)", + pos->timestamp, pos->latitude, pos->longitude, pos->altitude, + pos->status, acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); gps_manager->pos_cb(TRUE, pos, acc, gps_manager->userdata); - location_position_free (pos); - location_accuracy_free (acc); + location_position_free(pos); + location_accuracy_free(acc); } - -static void -velocity_callback (GeoclueVelocity *velocity, - GeoclueVelocityFields fields, - int timestamp, - double speed, - double direction, - double climb, - gpointer userdata) +static void velocity_callback(GeoclueVelocity * velocity, + GeoclueVelocityFields fields, int timestamp, + double speed, double direction, double climb, gpointer userdata) { - GpsManagerData* gps_manager = (GpsManagerData*)userdata; - g_return_if_fail (gps_manager); - g_return_if_fail (gps_manager->vel_cb); + GpsManagerData *gps_manager = (GpsManagerData *) userdata; + g_return_if_fail(gps_manager); + g_return_if_fail(gps_manager->vel_cb); LocationVelocity *vel = NULL; LocationAccuracy *acc = NULL; - if (fields & GEOCLUE_VELOCITY_FIELDS_SPEED && - fields & GEOCLUE_VELOCITY_FIELDS_DIRECTION) { - if (fields & GEOCLUE_VELOCITY_FIELDS_CLIMB) vel = location_velocity_new (timestamp, speed, direction, climb); - else vel = location_velocity_new (timestamp, speed, direction, 0); - acc = location_accuracy_new (LOCATION_ACCURACY_LEVEL_DETAILED, 0, 0); + if (fields & GEOCLUE_VELOCITY_FIELDS_SPEED && fields & GEOCLUE_VELOCITY_FIELDS_DIRECTION) { + if (fields & GEOCLUE_VELOCITY_FIELDS_CLIMB) + vel = location_velocity_new(timestamp, speed, direction, climb); + else + vel = location_velocity_new(timestamp, speed, direction, 0); + acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, 0, 0); } else { - vel = location_velocity_new (0, 0, 0, 0); - acc = location_accuracy_new (LOCATION_ACCURACY_LEVEL_NONE, 0, 0); + vel = location_velocity_new(0, 0, 0, 0); + acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_NONE, 0, 0); } - MOD_LOGD("timestamp(%d) speed(%f) direction(%f) climb(%f) acc_level(%d) hoz_acc(%f) vert_acc(%f)", - vel->timestamp, vel->speed, vel->direction, vel->climb, - acc->level, acc->horizontal_accuracy, acc->vertical_accuracy); + MOD_LOGD + ("timestamp(%d) speed(%f) direction(%f) climb(%f) acc_level(%d) hoz_acc(%f) vert_acc(%f)", + vel->timestamp, vel->speed, vel->direction, vel->climb, acc->level, + acc->horizontal_accuracy, acc->vertical_accuracy); gps_manager->vel_cb(TRUE, vel, acc, gps_manager->userdata); - location_velocity_free (vel); - location_accuracy_free (acc); + location_velocity_free(vel); + location_accuracy_free(acc); } -static void -unref_gps_manager(GpsManagerData* gps_manager) +static void unref_gps_manager(GpsManagerData * gps_manager) { - if(gps_manager->pos) { - g_signal_handlers_disconnect_by_func(G_OBJECT (GEOCLUE_PROVIDER(gps_manager->pos)), G_CALLBACK (status_callback), gps_manager); - g_signal_handlers_disconnect_by_func(G_OBJECT (GEOCLUE_PROVIDER(gps_manager->pos)), G_CALLBACK (position_callback), gps_manager); - g_object_unref (gps_manager->pos); + if (gps_manager->pos) { + g_signal_handlers_disconnect_by_func(G_OBJECT + (GEOCLUE_PROVIDER + (gps_manager->pos)), G_CALLBACK(status_callback), gps_manager); + g_signal_handlers_disconnect_by_func(G_OBJECT + (GEOCLUE_PROVIDER + (gps_manager->pos)), G_CALLBACK(position_callback), gps_manager); + g_object_unref(gps_manager->pos); gps_manager->pos = NULL; } - if(gps_manager->vel){ - g_signal_handlers_disconnect_by_func(G_OBJECT (GEOCLUE_PROVIDER(gps_manager->vel)), G_CALLBACK (velocity_callback), gps_manager); - g_object_unref (gps_manager->vel); + if (gps_manager->vel) { + g_signal_handlers_disconnect_by_func(G_OBJECT + (GEOCLUE_PROVIDER + (gps_manager->vel)), G_CALLBACK(velocity_callback), gps_manager); + g_object_unref(gps_manager->vel); gps_manager->vel = NULL; } - if(gps_manager->nmea) { - g_object_unref (gps_manager->nmea); + if (gps_manager->nmea) { + g_signal_handlers_disconnect_by_func(G_OBJECT + (GEOCLUE_PROVIDER + (gps_manager->nmea)), G_CALLBACK(nmea_callback), gps_manager); + g_object_unref(gps_manager->nmea); gps_manager->nmea = NULL; } - if(gps_manager->sat) { - g_object_unref (gps_manager->sat); + if (gps_manager->sat) { + g_signal_handlers_disconnect_by_func(G_OBJECT + (GEOCLUE_PROVIDER + (gps_manager->sat)), G_CALLBACK(satellite_callback), gps_manager); + g_object_unref(gps_manager->sat); gps_manager->sat = NULL; } + gps_manager->is_started = FALSE; } -static gboolean -ref_gps_manager(GpsManagerData* gps_manager) +static gboolean ref_gps_manager(GpsManagerData * gps_manager) { - if(gps_manager->is_started == TRUE){ - MOD_LOGW ("gps-manager is alredy started"); + gchar *service, *path; + + if (gps_manager->is_started == TRUE) { + MOD_LOGW("gps-manager is alredy started"); return TRUE; } - gchar *service, *path; - service = g_strdup_printf ("org.freedesktop.Geoclue.Providers.GpsManager"); - path = g_strdup_printf ("/org/freedesktop/Geoclue/Providers/GpsManager"); - if(!gps_manager->pos){ - gps_manager->pos = geoclue_position_new (service, path); + service = g_strdup_printf(GPS_MANAGER_SERVICE_NAME); + path = g_strdup_printf(GPS_MANAGER_SERVICE_PATH); + + if (!gps_manager->pos) { + gps_manager->pos = geoclue_position_new(service, path); } - if(!gps_manager->vel){ - gps_manager->vel = geoclue_velocity_new (service, path); + if (!gps_manager->vel) { + gps_manager->vel = geoclue_velocity_new(service, path); } - if(!gps_manager->nmea){ - gps_manager->nmea = geoclue_nmea_new (service, path); + if (!gps_manager->nmea) { + gps_manager->nmea = geoclue_nmea_new(service, path); } - if(!gps_manager->sat){ - gps_manager->sat = geoclue_satellite_new (service, path); + if (!gps_manager->sat) { + gps_manager->sat = geoclue_satellite_new(service, path); } - g_free (service); - g_free (path); + + g_free(service); + g_free(path); + if (!gps_manager->pos || !gps_manager->vel || !gps_manager->nmea || !gps_manager->sat) { - MOD_LOGW ("Error while creating Geoclue object."); + MOD_LOGW("Error while creating Geoclue object."); unref_gps_manager(gps_manager); return FALSE; } gps_manager->is_started = TRUE; int ret; - ret = g_signal_connect (G_OBJECT (GEOCLUE_PROVIDER(gps_manager->pos)), "status-changed", G_CALLBACK (status_callback), gps_manager); - g_debug ("gsignal_connect status-changed %d", ret); - ret = g_signal_connect (G_OBJECT (GEOCLUE_PROVIDER(gps_manager->pos)), "position-changed", G_CALLBACK (position_callback), gps_manager); - g_debug ("gsignal_connect position-changed %d", ret); - ret = g_signal_connect (G_OBJECT (GEOCLUE_PROVIDER(gps_manager->vel)), "velocity-changed", G_CALLBACK (velocity_callback), gps_manager); - g_debug ("gsignal_connect velocity-changed %d", ret); - ret = g_signal_connect (G_OBJECT (GEOCLUE_PROVIDER(gps_manager->sat)), "satellite-changed", G_CALLBACK (satellite_callback), gps_manager); - g_debug ("gsignal_connect satellite-changed %d", ret); - ret = g_signal_connect (G_OBJECT (GEOCLUE_PROVIDER(gps_manager->nmea)), "nmea-changed", G_CALLBACK (nmea_callback), gps_manager); - g_debug ("gsignal_connect nmea-changed %d", ret); + ret = + g_signal_connect(G_OBJECT(GEOCLUE_PROVIDER(gps_manager->pos)), + "status-changed", G_CALLBACK(status_callback), gps_manager); + g_debug("gsignal_connect status-changed %d", ret); + ret = + g_signal_connect(G_OBJECT(GEOCLUE_PROVIDER(gps_manager->pos)), + "position-changed", G_CALLBACK(position_callback), gps_manager); + g_debug("gsignal_connect position-changed %d", ret); + ret = + g_signal_connect(G_OBJECT(GEOCLUE_PROVIDER(gps_manager->vel)), + "velocity-changed", G_CALLBACK(velocity_callback), gps_manager); + g_debug("gsignal_connect velocity-changed %d", ret); + ret = + g_signal_connect(G_OBJECT(GEOCLUE_PROVIDER(gps_manager->sat)), + "satellite-changed", G_CALLBACK(satellite_callback), gps_manager); + g_debug("gsignal_connect satellite-changed %d", ret); + ret = + g_signal_connect(G_OBJECT(GEOCLUE_PROVIDER(gps_manager->nmea)), + "nmea-changed", G_CALLBACK(nmea_callback), gps_manager); + g_debug("gsignal_connect nmea-changed %d", ret); return TRUE; } -static int -start (gpointer handle, - LocModStatusCB status_cb, - LocModPositionCB pos_cb, - LocModVelocityCB vel_cb, - gpointer userdata) +static int start(gpointer handle, LocModStatusCB status_cb, LocModPositionCB pos_cb, LocModVelocityCB vel_cb, LocModSatelliteCB sat_cb, gpointer userdata) { MOD_LOGD("start"); - GpsManagerData* gps_manager = (GpsManagerData*)handle; + GpsManagerData *gps_manager = (GpsManagerData *) handle; g_return_val_if_fail(gps_manager, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(status_cb, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(pos_cb, LOCATION_ERROR_NOT_AVAILABLE); @@ -301,31 +324,29 @@ start (gpointer handle, gps_manager->status_cb = status_cb; gps_manager->pos_cb = pos_cb; gps_manager->vel_cb = vel_cb; + gps_manager->sat_cb = sat_cb; gps_manager->userdata = userdata; - if (!ref_gps_manager(gps_manager)) return LOCATION_ERROR_NOT_AVAILABLE; + if (!ref_gps_manager(gps_manager)) + return LOCATION_ERROR_NOT_AVAILABLE; return LOCATION_ERROR_NONE; } -static int -stop(gpointer handle) +static int stop(gpointer handle) { MOD_LOGD("stop"); - GpsManagerData* gps_manager = (GpsManagerData*)handle; + GpsManagerData *gps_manager = (GpsManagerData *) handle; g_return_val_if_fail(gps_manager, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(gps_manager->status_cb, LOCATION_ERROR_NOT_AVAILABLE); unref_gps_manager(gps_manager); - gps_manager->status_cb (FALSE, LOCATION_STATUS_NO_FIX, gps_manager->userdata); + gps_manager->status_cb(FALSE, LOCATION_STATUS_NO_FIX, gps_manager->userdata); return LOCATION_ERROR_NONE; } -static int -get_position(gpointer handle, - LocationPosition **position, - LocationAccuracy **accuracy) +static int get_position(gpointer handle, LocationPosition ** position, LocationAccuracy ** accuracy) { MOD_LOGD("get_position"); - GpsManagerData* gps_manager = (GpsManagerData*)handle; + GpsManagerData *gps_manager = (GpsManagerData *) handle; g_return_val_if_fail(gps_manager, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(gps_manager->pos, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER); @@ -337,40 +358,38 @@ get_position(gpointer handle, GeoclueAccuracy *_accuracy = NULL; GError *error = NULL; - fields = geoclue_position_get_position (gps_manager->pos, ×tamp, - &lat, &lon, &alt, - &_accuracy, &error); + fields = geoclue_position_get_position(gps_manager->pos, ×tamp, &lat, &lon, &alt, &_accuracy, &error); if (error) { - MOD_LOGD ("Error getting position: %s", error->message); - g_error_free (error); + MOD_LOGD("Error getting position: %s", error->message); + g_error_free(error); return LOCATION_ERROR_NOT_AVAILABLE; } - if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE && - fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) { - if(fields & GEOCLUE_POSITION_FIELDS_ALTITUDE) *position = location_position_new (timestamp, lat, lon, alt, LOCATION_STATUS_3D_FIX); - else *position = location_position_new (timestamp, lat, lon, 0, LOCATION_STATUS_2D_FIX); - } else *position = location_position_new (0, 0, 0, 0, LOCATION_STATUS_NO_FIX); + if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE && fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) { + if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE) + *position = location_position_new(timestamp, lat, lon, alt, LOCATION_STATUS_3D_FIX); + else + *position = location_position_new(timestamp, lat, lon, 0, LOCATION_STATUS_2D_FIX); + } else + *position = location_position_new(0, 0, 0, 0, LOCATION_STATUS_NO_FIX); if (_accuracy) { GeoclueAccuracyLevel level; double horiz_acc; double vert_acc; - geoclue_accuracy_get_details (_accuracy, &level, &horiz_acc, &vert_acc); - *accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_DETAILED, horiz_acc, vert_acc); - geoclue_accuracy_free (_accuracy); - } else *accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_NONE, 0, 0); + geoclue_accuracy_get_details(_accuracy, &level, &horiz_acc, &vert_acc); + *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, horiz_acc, vert_acc); + geoclue_accuracy_free(_accuracy); + } else + *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_NONE, 0, 0); return LOCATION_ERROR_NONE; } -static int -get_velocity(gpointer handle, - LocationVelocity **velocity, - LocationAccuracy **accuracy) +static int get_velocity(gpointer handle, LocationVelocity ** velocity, LocationAccuracy ** accuracy) { MOD_LOGD("get_velocity"); - GpsManagerData* gps_manager = (GpsManagerData*)handle; + GpsManagerData *gps_manager = (GpsManagerData *) handle; g_return_val_if_fail(gps_manager, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(gps_manager->vel, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER); @@ -381,45 +400,42 @@ get_velocity(gpointer handle, double spd, dir, climb; GError *error = NULL; - fields = geoclue_velocity_get_velocity (gps_manager->vel, ×tamp, - &spd, &dir, &climb, - &error); + fields = geoclue_velocity_get_velocity(gps_manager->vel, ×tamp, &spd, &dir, &climb, &error); if (error) { - MOD_LOGD ("Error getting velocity: %s", error->message); - g_error_free (error); + MOD_LOGD("Error getting velocity: %s", error->message); + g_error_free(error); return LOCATION_ERROR_NOT_AVAILABLE; } - if (fields & GEOCLUE_VELOCITY_FIELDS_SPEED && - fields & GEOCLUE_VELOCITY_FIELDS_DIRECTION) { - if (fields & GEOCLUE_VELOCITY_FIELDS_CLIMB) *velocity = location_velocity_new (timestamp, spd, dir, climb); - else *velocity = location_velocity_new (timestamp, spd, dir, 0); - *accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_DETAILED, 0, 0); + if (fields & GEOCLUE_VELOCITY_FIELDS_SPEED && fields & GEOCLUE_VELOCITY_FIELDS_DIRECTION) { + if (fields & GEOCLUE_VELOCITY_FIELDS_CLIMB) + *velocity = location_velocity_new(timestamp, spd, dir, climb); + else + *velocity = location_velocity_new(timestamp, spd, dir, 0); + *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, 0, 0); } else { - *velocity = location_velocity_new (0, 0, 0, 0); - *accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_NONE, 0, 0); + *velocity = location_velocity_new(0, 0, 0, 0); + *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_NONE, 0, 0); } return LOCATION_ERROR_NONE; } -static int -get_nmea(gpointer handle, - gchar** nmea_data) +static int get_nmea(gpointer handle, gchar ** nmea_data) { MOD_LOGD("get_nmea"); - GpsManagerData* gps_manager = (GpsManagerData*)handle; + GpsManagerData *gps_manager = (GpsManagerData *) handle; g_return_val_if_fail(gps_manager, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(gps_manager->nmea, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(nmea_data, LOCATION_ERROR_PARAMETER); gboolean ret = FALSE; int timestamp = 0; - char* _nmea_data = NULL; + char *_nmea_data = NULL; GError *error = NULL; - ret = geoclue_nmea_get_nmea (gps_manager->nmea, ×tamp, &_nmea_data, &error); - if( !ret && error) { - MOD_LOGD ("\t Error getting nmea: %s", error->message); - g_error_free (error); + ret = geoclue_nmea_get_nmea(gps_manager->nmea, ×tamp, &_nmea_data, &error); + if (!ret && error) { + MOD_LOGD("\t Error getting nmea: %s", error->message); + g_error_free(error); return LOCATION_ERROR_NOT_AVAILABLE; } *nmea_data = g_strdup(_nmea_data); @@ -427,61 +443,286 @@ get_nmea(gpointer handle, return LOCATION_ERROR_NONE; } -static int -get_satellite(gpointer handle, - LocationSatellite **satellite) +static int get_satellite(gpointer handle, LocationSatellite ** satellite) { MOD_LOGD("get_satellite"); - GpsManagerData* gps_manager = (GpsManagerData*)handle; + GpsManagerData *gps_manager = (GpsManagerData *) handle; g_return_val_if_fail(gps_manager, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(gps_manager->sat, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER); int timestamp = 0; - int idx = 0; + int idx = 0; int sat_used = 0; int sat_vis = 0; GArray *u_prn = NULL; GPtrArray *sat_info = NULL; GError *error = NULL; - geoclue_satellite_get_satellite (gps_manager->sat, ×tamp, &sat_used, &sat_vis, &u_prn, &sat_info, &error); + geoclue_satellite_get_satellite(gps_manager->sat, ×tamp, &sat_used, &sat_vis, &u_prn, &sat_info, &error); if (error) { MOD_LOGW("\t Error getting satellite: %s", error->message); - g_error_free (error); + g_error_free(error); return LOCATION_ERROR_NOT_AVAILABLE; } - *satellite = location_satellite_new (sat_vis); + *satellite = location_satellite_new(sat_vis); + (*satellite)->timestamp = timestamp; - for (idx=0; idxmessage); + g_error_free(error); + g_object_unref(last_pos); + g_free (service); + g_free (path); + return LOCATION_ERROR_NOT_AVAILABLE; } - if (u_prn) g_array_free (u_prn, TRUE); - if (sat_info) g_ptr_array_free (sat_info, TRUE); + if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE && fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) { + if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE) + *position = location_position_new(timestamp, lat, lon, alt, LOCATION_STATUS_3D_FIX); + else + *position = location_position_new(timestamp, lat, lon, 0, LOCATION_STATUS_2D_FIX); + } else + *position = location_position_new(0, 0, 0, 0, LOCATION_STATUS_NO_FIX); + + if (_accuracy) { + GeoclueAccuracyLevel level; + double horiz_acc; + double vert_acc; + geoclue_accuracy_get_details(_accuracy, &level, &horiz_acc, &vert_acc); + *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, horiz_acc, vert_acc); + geoclue_accuracy_free(_accuracy); + } else + *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_NONE, 0, 0); + + g_object_unref(last_pos); + g_free (service); + g_free (path); + + return LOCATION_ERROR_NONE; +#else + int timestamp = 0; + double longitude = 0.0, latitude = 0.0, altitude = 0.0; + double hor_accuracy = 0.0, ver_accuracy = 0.0; + LocationStatus status = LOCATION_STATUS_NO_FIX; + LocationAccuracyLevel level = LOCATION_ACCURACY_LEVEL_NONE; + + 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)) { + *position = NULL; + *accuracy = NULL; + return LOCATION_ERROR_NOT_AVAILABLE; + } + + if (timestamp) { + if (altitude) status = LOCATION_STATUS_3D_FIX; + else status = LOCATION_STATUS_2D_FIX; + } + else { + *position = NULL; + *accuracy = NULL; + return LOCATION_ERROR_NOT_AVAILABLE; + } + + level = LOCATION_ACCURACY_LEVEL_DETAILED; + *position = location_position_new(timestamp, latitude, longitude, altitude, status); + *accuracy = location_accuracy_new(level, hor_accuracy, ver_accuracy); return LOCATION_ERROR_NONE; + +#endif } -static int -set_devname(gpointer handle, - const char *devname) +static int get_last_velocity(gpointer handle, LocationVelocity ** velocity, LocationAccuracy ** accuracy) { - GpsManagerData* gps_manager = (GpsManagerData*)handle; + MOD_LOGD("get_last_velocity"); + GpsManagerData *gps_manager = (GpsManagerData *) handle; + g_return_val_if_fail(gps_manager, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER); + g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER); + +#if 0 /* replaced by reading vconf directly */ + GeoclueVelocityFields fields; + int timestamp; + double spd, dir, climb; + GError *error = NULL; + + gchar *service = g_strdup_printf(GPS_MANAGER_SERVICE_NAME); + gchar *path = g_strdup_printf(GPS_MANAGER_SERVICE_PATH); + + GeoclueVelocity *last_vel = geoclue_velocity_new(service, path); + + fields = geoclue_velocity_get_last_velocity(last_vel, ×tamp, &spd, &dir, &climb, &error); + if (error) { + MOD_LOGD("Error getting last velocity: %s", error->message); + g_error_free(error); + g_object_unref(last_vel); + g_free (service); + g_free (path); + return LOCATION_ERROR_NOT_AVAILABLE; + } + + if (fields & GEOCLUE_VELOCITY_FIELDS_SPEED && fields & GEOCLUE_VELOCITY_FIELDS_DIRECTION) { + if (fields & GEOCLUE_VELOCITY_FIELDS_CLIMB) + *velocity = location_velocity_new(timestamp, spd, dir, climb); + else + *velocity = location_velocity_new(timestamp, spd, dir, 0); + *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, 0, 0); + } else { + *velocity = location_velocity_new(0, 0, 0, 0); + *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_NONE, 0, 0); + } + + g_object_unref(last_vel); + g_free (service); + g_free (path); + + return LOCATION_ERROR_NONE; +#else + gint timestamp = 0; + gdouble speed = 0.0, direction = 0.0; + gdouble hor_accuracy = 0.0, ver_accuracy = 0.0; + + if (vconf_get_int(GPS_LAST_TIMESTAMP, ×tamp) || + vconf_get_dbl(GPS_LAST_SPEED, &speed) || + vconf_get_dbl(GPS_LAST_DIRECTION, &direction) || + vconf_get_dbl(GPS_LAST_HORACCURACY, &hor_accuracy) || + vconf_get_dbl(GPS_LAST_VERACCURACY, &ver_accuracy)) { + *velocity = NULL; + *accuracy = NULL; + return LOCATION_ERROR_NOT_AVAILABLE;; + } + + if (!timestamp || (speed < 0 && direction < 0)) { + *velocity = NULL; + *accuracy = NULL; + return LOCATION_ERROR_NOT_AVAILABLE; + } + + *velocity = location_velocity_new ((guint) timestamp, speed, direction, 0.0); + *accuracy = location_accuracy_new (LOCATION_ACCURACY_LEVEL_DETAILED, hor_accuracy, ver_accuracy); + + return LOCATION_ERROR_NONE; +#endif +} + +static int get_last_satellite(gpointer handle, LocationSatellite ** satellite) +{ + MOD_LOGD("get_last_satellite"); + GpsManagerData *gps_manager = (GpsManagerData *) handle; + g_return_val_if_fail(gps_manager, LOCATION_ERROR_NOT_AVAILABLE); + g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER); + + int timestamp = 0; + int idx = 0; + int sat_used = 0; + int sat_vis = 0; + GArray *u_prn = NULL; + GPtrArray *sat_info = NULL; + GError *error = NULL; + gchar *service = g_strdup_printf(GPS_MANAGER_SERVICE_NAME); + gchar *path = g_strdup_printf(GPS_MANAGER_SERVICE_PATH); + + GeoclueSatellite *last_sat = geoclue_satellite_new(service, path); + + geoclue_satellite_get_last_satellite(last_sat, ×tamp, &sat_used, &sat_vis, &u_prn, &sat_info, &error); + if (error) { + MOD_LOGW("\t Error getting last satellite: %s", error->message); + g_error_free(error); + g_object_unref(last_sat); + g_free (service); + g_free (path); + return LOCATION_ERROR_NOT_AVAILABLE; + } + *satellite = location_satellite_new(sat_vis); + (*satellite)->timestamp = timestamp; + + for (idx = 0; idx < sat_vis; idx++) { + GValueArray *vals = (GValueArray *) g_ptr_array_index(sat_info, idx); + gint prn = g_value_get_int(g_value_array_get_nth(vals, 0)); + gint elev = g_value_get_int(g_value_array_get_nth(vals, 1)); + gint azim = g_value_get_int(g_value_array_get_nth(vals, 2)); + gint snr = g_value_get_int(g_value_array_get_nth(vals, 3)); + + int used_idx = 0; + gboolean is_used = FALSE; + for (used_idx = 0; used_idx < sat_used; used_idx++) { + if ((guint) prn == (guint) g_array_index(u_prn, guint, used_idx)) { + is_used = TRUE; + break; + } + } + location_satellite_set_satellite_details(*satellite, idx, + (guint) prn, is_used, (guint) elev, (guint) azim, (guint) snr); + } + + if (u_prn) + g_array_free(u_prn, TRUE); + if (sat_info) + g_ptr_array_free(sat_info, TRUE); + + g_object_unref(last_sat); + g_free (service); + g_free (path); + + return LOCATION_ERROR_NONE; +} + +static int set_devname(gpointer handle, const char *devname) +{ + GpsManagerData *gps_manager = (GpsManagerData *) handle; g_return_val_if_fail(gps_manager, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(gps_manager->devname, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(devname, LOCATION_ERROR_PARAMETER); @@ -491,12 +732,9 @@ set_devname(gpointer handle, return LOCATION_ERROR_NONE; } - -static int -get_devname(gpointer handle, - char **devname) +static int get_devname(gpointer handle, char **devname) { - GpsManagerData* gps_manager = (GpsManagerData*)handle; + GpsManagerData *gps_manager = (GpsManagerData *) handle; g_return_val_if_fail(gps_manager, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(gps_manager->devname, LOCATION_ERROR_NOT_AVAILABLE); g_return_val_if_fail(devname, LOCATION_ERROR_PARAMETER); @@ -506,26 +744,30 @@ get_devname(gpointer handle, return LOCATION_ERROR_NONE; } -LOCATION_MODULE_API gpointer -init(LocModGpsOps* ops) +LOCATION_MODULE_API gpointer init(LocModGpsOps * ops) { MOD_LOGD("init"); + g_return_val_if_fail(ops, NULL); ops->start = start; - ops->stop = stop ; + ops->stop = stop; ops->get_position = get_position; ops->get_velocity = get_velocity; + ops->get_last_position = get_last_position; + ops->get_last_velocity = get_last_velocity; + Dl_info info; if (dladdr(&get_position, &info) == 0) { - MOD_LOGD ("Failed to get module name"); - } else if (g_str_has_prefix(info.dli_fname, "gps")) { + MOD_LOGD("Failed to get module name"); + } else if (g_strrstr(info.dli_fname, "gps")) { ops->get_nmea = get_nmea; ops->get_satellite = get_satellite; + ops->get_last_satellite = get_last_satellite; ops->set_devname = set_devname; ops->get_devname = get_devname; } - GpsManagerData* gps_manager = g_new0(GpsManagerData, 1); + GpsManagerData *gps_manager = g_new0(GpsManagerData, 1); g_return_val_if_fail(gps_manager, NULL); g_stpcpy(gps_manager->devname, "/dev/ttySAC1"); @@ -533,22 +775,23 @@ init(LocModGpsOps* ops) gps_manager->vel = NULL; gps_manager->nmea = NULL; gps_manager->sat = NULL; - gps_manager->status_cb= NULL; + gps_manager->status_cb = NULL; gps_manager->pos_cb = NULL; gps_manager->vel_cb = NULL; gps_manager->userdata = NULL; gps_manager->is_started = FALSE; - return (gpointer)gps_manager; + return (gpointer) gps_manager; } -LOCATION_MODULE_API void -shutdown(gpointer handle) +LOCATION_MODULE_API void shutdown(gpointer handle) { MOD_LOGD("shutdown"); g_return_if_fail(handle); - GpsManagerData* gps_manager = (GpsManagerData*)handle; + GpsManagerData *gps_manager = (GpsManagerData *) handle; + unref_gps_manager(gps_manager); - if(gps_manager->status_cb) gps_manager->status_cb(FALSE, LOCATION_STATUS_NO_FIX, gps_manager->userdata); + if (gps_manager->status_cb) + gps_manager->status_cb(FALSE, LOCATION_STATUS_NO_FIX, gps_manager->userdata); g_free(gps_manager); } diff --git a/packaging/gps-manager.spec b/packaging/gps-manager.spec index a541a39..21b4df0 100644 --- a/packaging/gps-manager.spec +++ b/packaging/gps-manager.spec @@ -1,95 +1,121 @@ -%define PREFIX /usr -%define DATADIR /opt - Name: gps-manager -Summary: Location Based Services server -Version: 0.3.5 +Summary: GPS Manager for Tizen +Version: 0.1.6 Release: 1 -Group: devel -License: Samsung +Group: TO_BE/FILLED_IN +License: TO_BE/FILLED_IN Source0: %{name}-%{version}.tar.gz -BuildRequires: pkgconfig(sysman) -BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(dbus-glib-1) -BuildRequires: pkgconfig(msg-service) -BuildRequires: pkgconfig(pmapi) -BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(network) -BuildRequires: pkgconfig(tapi) -BuildRequires: pkgconfig(heynoti) -BuildRequires: cmake -Requires(post): /usr/bin/vconftool -Requires(post): /sbin/ldconfig -Requires(postun): /sbin/ldconfig +BuildRequires: cmake +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(geoclue) +BuildRequires: pkgconfig(network) +BuildRequires: pkgconfig(tapi) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(heynoti) +BuildRequires: pkgconfig(sysman) +BuildRequires: pkgconfig(msg-service) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(pmapi) +BuildRequires: pkgconfig(location) %description -Location Based Services server binaries and libraries +GPS Manager for Tizen -%package devel -Summary: LBS Agps Server (devel) +%package -n location-gps-manager +Summary: GPS Manager for Tizen Group: Development/Libraries Requires: %{name} = %{version}-%{release} -%description devel -Location Based Services development headers +%description -n location-gps-manager +libslp-location module for gps-manager -%prep -%setup -q -%build +%package -n gps-manager-plugin-devel +Summary: GPS Manager for Tizen (development files) +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} -%autogen +%description -n gps-manager-plugin-devel +GPS Manager for Tizen (development files) + + +%prep +%setup -q -mkdir -p build -cd build %ifarch %{arm} -../configure --prefix=%{_prefix} --datadir=%{DATADIR} --enable-gps +%define GPS_ENABLER --enable-gps +%define ARCH armel %else -../configure --prefix=%{_prefix} --datadir=%{DATADIR} --disable-gps +%define GPS_ENABLER --enable-gps +%define ARCH x86 %endif -make +./autogen.sh +CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" ./configure --prefix=%{_prefix} %{GPS_ENABLER} -cd .. -%install +%build +make %{?jobs:-j%jobs} +%install rm -rf %{buildroot} -cd build %make_install -cd .. -%post +%clean +rm -rf %{buildroot} -/sbin/ldconfig +%post +#GPS Indicator value vconftool set -t int memory/gps/state 0 -i -vconftool set -t int db/lbs/GpsOperationMode "1" -f -vconftool set -t int db/lbs/GpsStartingMode "0" -f -vconftool set -t int db/lbs/GpsTrackingMode "1" -f -vconftool set -t int db/lbs/GpsPositionMode "1" -f -vconftool set -t string db/lbs/SUPL_SERVER "your.supl-server.com" -f -vconftool set -t int db/lbs/SUPL_PORT "7275" -f -vconftool set -t int db/lbs/AgpsSsl "1" -f -vconftool set -t int db/lbs/AgpsBearer "0" -f -vconftool set -t int db/lbs/NMEALoggingEnable "0" -f -vconftool set -t int db/lbs/NMEAReplayMode "0" -f -vconftool set -t int db/lbs/GpsAccuracy "100" -f - -%postun -/sbin/ldconfig +vconftool set -t int memory/wps/state 0 -i + +#GPS_SETTING +vconftool set -t int db/location/gps/Operation "1" -f +vconftool set -t int db/location/gps/Starting "0" -f +vconftool set -t int db/location/gps/Session "1" -f + +#SUPL_SETTING +vconftool set -t string db/location/supl/Server "your.supl-server.com" -f +vconftool set -t int db/location/supl/Port "7275" -f +vconftool set -t int db/location/supl/SslEnabled "1" -f + +#NMEA_SETTING +vconftool set -t int db/location/nmea/LoggingEnabled "0" -f + +#REPLAY_SETTING +vconftool set -t string db/location/replay/FileName "nmea_replay.log" -f +%ifarch %arm + vconftool set -t int db/location/replay/ReplayEnabled "0" -f + vconftool set -t int db/location/replay/ReplayMode "1" -f +%else + vconftool set -t int db/location/replay/ReplayEnabled "1" -f + vconftool set -t int db/location/replay/ReplayMode "0" -f +%endif +vconftool set -t double db/location/replay/ManualLatitude "0.0" -f +vconftool set -t double db/location/replay/ManualLongitude "0.0" -f +vconftool set -t double db/location/replay/ManualAltitude "0.0" -f + +%postun -p /sbin/ldconfig %files %defattr(-,root,root,-) -%attr(0700,root,root) /etc/rc.d/init.d/gps-manager -%attr(0700,root,root) /etc/rc.d/rc3.d/S90gps-manager -%attr(0700,root,root) /etc/rc.d/rc5.d/S90gps-manager -%{_bindir}/gps-manager +/usr/libexec/gps-manager +/usr/share/dbus-1/services/org.freedesktop.Geoclue.Providers.GpsManager.service +/usr/share/geoclue-providers/gps-manager.provider +/usr/etc/dbus-1/system.d/Geoclue.conf +/etc/rc.d/init.d/gps-manager +/etc/rc.d/rc3.d/S90gps-manager +/etc/rc.d/rc5.d/S90gps-manager + +%files -n location-gps-manager +%defattr(-,root,root,-) +%{_libdir}/location/module/libgps.so* -%files devel +%files -n gps-manager-plugin-devel %defattr(-,root,root,-) -%{_includedir}/gps-plugin/gps_manager_plugin_intf.h -%{_includedir}/gps-plugin/gps_manager_data_types.h -%{_includedir}/gps-plugin/gps_manager_extra_data_types.h %{_libdir}/pkgconfig/gps-manager-plugin.pc +%{_includedir}/gps-manager-plugin/*.h +