#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"
sv_data_t satellite;
nmea_data_t nmea;
+ pos_data_t last_position;
+ sv_data_t last_satellite;
+
GHashTable *connections;
} GeoclueGpsManager;
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;
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) {
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);
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,
}
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;
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));
}
if (timestamp) {
- *timestamp = gpsmanager->position.timestamp;
+ *timestamp = gpsmanager->satellite.timestamp;
}
if (satellite_used) {
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));
}
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)
static void init_satellite(GcIfaceSatelliteClass * iface)
{
iface->get_satellite = get_satellite;
+ iface->get_last_satellite = get_last_satellite;
}
static void init_geoclue(GcIfaceGeoclueClass * iface)
#include <glib.h>
+#include <vconf.h>
#include <location-module.h>
#include <geoclue/geoclue-position.h>
#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);
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);
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);
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);
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; 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));
+ 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)) {
+ 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);
+ 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);
+
+ return LOCATION_ERROR_NONE;
+}
+
+static int get_last_position(gpointer handle, LocationPosition ** position, LocationAccuracy ** accuracy)
+{
+ MOD_LOGD("get_last_position");
+ GpsManagerData *gps_manager = (GpsManagerData *) handle;
+ g_return_val_if_fail(gps_manager, LOCATION_ERROR_NOT_AVAILABLE);
+ 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 (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);
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);
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");
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);
}