X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=module%2Fmodule_gps_manager.c;h=98fb603142bee168ec4e62c9f6b3a890e0b608b8;hb=209c999100c1fd37e4e7c91b94608bd43abf0147;hp=e92ea4ed9b7310fc623e3387b3f95a69ff85b574;hpb=76aef537743d91a75c780eb6623b7b38a4c6547f;p=framework%2Flocation%2Fgps-manager.git diff --git a/module/module_gps_manager.c b/module/module_gps_manager.c index e92ea4e..98fb603 100644 --- a/module/module_gps_manager.c +++ b/module/module_gps_manager.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -37,19 +38,6 @@ #include "log.h" -#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; @@ -99,6 +87,7 @@ static void satellite_callback(GeoclueSatellite * satellite, int timestamp, g_return_if_fail(gps_manager->sat_cb); guint idx; + guint used_idx; LocationSatellite *sat = NULL; sat = location_satellite_new(satellite_visible); @@ -107,8 +96,7 @@ static void satellite_callback(GeoclueSatellite * satellite, int timestamp, sat->num_of_sat_inview = satellite_visible; sat->num_of_sat_used = satellite_used; for (idx = 0; idx < satellite_visible; idx++) { - guint used_idx; - gboolean used; + gboolean used = FALSE; 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)); @@ -118,8 +106,6 @@ static void satellite_callback(GeoclueSatellite * satellite, int timestamp, 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); @@ -291,23 +277,23 @@ static gboolean ref_gps_manager(GpsManagerData * gps_manager) 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); + MOD_LOGD("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); + MOD_LOGD("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); + MOD_LOGD("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); + MOD_LOGD("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); + MOD_LOGD("gsignal_connect nmea-changed %d", ret); return TRUE; } @@ -329,6 +315,24 @@ static int start(gpointer handle, LocModStatusCB status_cb, LocModPositionCB pos if (!ref_gps_manager(gps_manager)) return LOCATION_ERROR_NOT_AVAILABLE; + + GHashTable *options; + GError *error = NULL; + + options = g_hash_table_new(g_str_hash, g_str_equal); + g_hash_table_insert(options, "CMD", "START"); + + if (!geoclue_provider_set_options(GEOCLUE_PROVIDER(gps_manager->pos), options, &error)) { + MOD_LOGE("Error geoclue_provider_set_options(START) : %s", error->message); + g_error_free(error); + error = NULL; + g_hash_table_destroy(options); + return LOCATION_ERROR_NOT_AVAILABLE; + } else { + MOD_LOGD("Success to geoclue_provider_set_options(START)"); + } + g_hash_table_destroy(options); + return LOCATION_ERROR_NONE; } @@ -338,6 +342,24 @@ static int stop(gpointer 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); + + GHashTable *options; + GError *error = NULL; + + options = g_hash_table_new(g_str_hash, g_str_equal); + g_hash_table_insert(options, "CMD", "STOP"); + + if (!geoclue_provider_set_options(GEOCLUE_PROVIDER(gps_manager->pos), options, &error)) { + MOD_LOGE("Error geoclue_provider_set_options(STOP) : %s", error->message); + g_error_free(error); + error = NULL; + g_hash_table_destroy(options); + return LOCATION_ERROR_NOT_AVAILABLE; + } else { + MOD_LOGD("Success to geoclue_provider_set_options(STOP)"); + } + g_hash_table_destroy(options); + unref_gps_manager(gps_manager); gps_manager->status_cb(FALSE, LOCATION_STATUS_NO_FIX, gps_manager->userdata); return LOCATION_ERROR_NONE; @@ -503,64 +525,18 @@ static int get_last_position(gpointer handle, LocationPosition ** position, Loca g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER); g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER); -#if 0 /* replaced by reading vconf directly */ - GeocluePositionFields fields; - int timestamp; - double lat, lon, alt; - GeoclueAccuracy *_accuracy = NULL; - GError *error = NULL; - - gchar *service = g_strdup_printf(GPS_MANAGER_SERVICE_NAME); - gchar *path = g_strdup_printf(GPS_MANAGER_SERVICE_PATH); - - GeocluePosition *last_pos = geoclue_position_new(service, path); - - fields = geoclue_position_get_last_position(last_pos, ×tamp, &lat, &lon, &alt, &_accuracy, &error); - if (error) { - MOD_LOGD("Error getting last position: %s", error->message); - g_error_free(error); - g_object_unref(last_pos); - g_free (service); - g_free (path); - return LOCATION_ERROR_NOT_AVAILABLE; - } - - if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE && fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) { - if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE) - *position = location_position_new(timestamp, lat, lon, alt, LOCATION_STATUS_3D_FIX); - else - *position = location_position_new(timestamp, lat, lon, 0, LOCATION_STATUS_2D_FIX); - } else - *position = location_position_new(0, 0, 0, 0, LOCATION_STATUS_NO_FIX); - - if (_accuracy) { - GeoclueAccuracyLevel level; - double horiz_acc; - double vert_acc; - geoclue_accuracy_get_details(_accuracy, &level, &horiz_acc, &vert_acc); - *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, horiz_acc, vert_acc); - geoclue_accuracy_free(_accuracy); - } else - *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_NONE, 0, 0); - - 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)) { + if (vconf_get_int(VCONFKEY_LOCATION_LAST_GPS_TIMESTAMP, ×tamp) || + vconf_get_dbl(VCONFKEY_LOCATION_LAST_GPS_LATITUDE, &latitude) || + vconf_get_dbl(VCONFKEY_LOCATION_LAST_GPS_LONGITUDE, &longitude) || + vconf_get_dbl(VCONFKEY_LOCATION_LAST_GPS_ALTITUDE, &altitude) || + vconf_get_dbl(VCONFKEY_LOCATION_LAST_GPS_HOR_ACCURACY, &hor_accuracy) || + vconf_get_dbl(VCONFKEY_LOCATION_LAST_GPS_VER_ACCURACY, &ver_accuracy)) { *position = NULL; *accuracy = NULL; return LOCATION_ERROR_NOT_AVAILABLE; @@ -581,8 +557,6 @@ static int get_last_position(gpointer handle, LocationPosition ** position, Loca *accuracy = location_accuracy_new(level, hor_accuracy, ver_accuracy); return LOCATION_ERROR_NONE; - -#endif } static int get_last_velocity(gpointer handle, LocationVelocity ** velocity, LocationAccuracy ** accuracy) @@ -593,53 +567,15 @@ static int get_last_velocity(gpointer handle, LocationVelocity ** velocity, Loca 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)) { + if (vconf_get_int(VCONFKEY_LOCATION_LAST_GPS_TIMESTAMP, ×tamp) || + vconf_get_dbl(VCONFKEY_LOCATION_LAST_GPS_SPEED, &speed) || + vconf_get_dbl(VCONFKEY_LOCATION_LAST_GPS_DIRECTION, &direction) || + vconf_get_dbl(VCONFKEY_LOCATION_LAST_GPS_HOR_ACCURACY, &hor_accuracy) || + vconf_get_dbl(VCONFKEY_LOCATION_LAST_GPS_VER_ACCURACY, &ver_accuracy)) { *velocity = NULL; *accuracy = NULL; return LOCATION_ERROR_NOT_AVAILABLE;; @@ -655,7 +591,6 @@ static int get_last_velocity(gpointer handle, LocationVelocity ** velocity, Loca *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)