* GPSD interfaces *
*******************/
-static void process_gps(gpointer data, gint source, GdkInputCondition condition)
+static gboolean process_gps(GIOChannel *source, GIOCondition condition, gpointer data)
{
struct gps_data_t *gps_data = (struct gps_data_t *)data;
/* Process any data from the gps and call the hook function */
if (gps_data != NULL) {
+ gdouble track = gps_data->fix.track;
gint result = gps_read(gps_data);
+ if (isnan(gps_data->fix.track))
+ gps_data->fix.track = track;
g_debug("GritsPluginGps: process_gps - gps_read returned %d, "
"position %f, %f.", result,
gps_data->fix.latitude, gps_data->fix.longitude);
} else {
g_warning("GritsPluginGps: process_gps - gps_data == NULL.");
}
+ return TRUE;
}
static gint initialize_gpsd(char *server, gchar *port, struct gps_data_t *gps_data)
#if GPSD_API_MAJOR_VERSION < 5
#error "GPSD protocol version 5 or greater required."
#endif
- gint result;
-
- if ((result = gps_open(server, port, gps_data)) != 0) {
+ gint result = gps_open(server, port, gps_data);
+ if (result > 0) {
g_warning("Unable to open gpsd connection to %s:%s: %d, %d, %s",
- server, port, result, errno, gps_errstr(errno));
- } else {
- (void)gps_stream(gps_data, WATCH_ENABLE|WATCH_JSON, NULL);
- g_debug("GritsPluginGps: initialize_gpsd - gpsd fd %u.",
- gps_data->gps_fd);
- gdk_input_add(gps_data->gps_fd, GDK_INPUT_READ, process_gps, gps_data);
+ server, port, result, errno, gps_errstr(errno));
+ return 0;
}
- return result;
+ (void)gps_stream(gps_data, WATCH_ENABLE|WATCH_JSON, NULL);
+ g_debug("GritsPluginGps: initialize_gpsd - gpsd fd %u.", gps_data->gps_fd);
+ GIOChannel *channel = g_io_channel_unix_new(gps_data->gps_fd);
+ gint input_tag = g_io_add_watch(channel, G_IO_IN, process_gps, gps_data);
+ g_io_channel_unref(channel);
+ return input_tag;
}
/* TODO: move to constructor if possible */
g_debug("GritsPluginGps: new");
GritsPluginGps *gps = g_object_new(GRITS_TYPE_PLUGIN_GPS, NULL);
- gps->viewer = viewer;
- gps->prefs = prefs;
+ gps->viewer = g_object_ref(viewer);
+ gps->prefs = g_object_ref(prefs);
- initialize_gpsd("localhost", DEFAULT_GPSD_PORT, &gps->gps_data);
+ gps->input_tag = initialize_gpsd("localhost", DEFAULT_GPSD_PORT, &gps->gps_data);
gps->follow_gps = FALSE;
gps_track_init(&gps->track);
g_debug("GritsPluginGps: dispose");
+ if (gps->gps_update_timeout_id) {
+ g_source_remove(gps->gps_update_timeout_id);
+ gps->gps_update_timeout_id = 0;
+ }
+ if (gps->ui.gps_log_timeout_id) {
+ g_source_remove(gps->ui.gps_log_timeout_id);
+ gps->ui.gps_log_timeout_id = 0;
+ }
+ if (gps->input_tag) {
+ g_source_remove(gps->input_tag);
+ gps->input_tag = 0;
+ }
if (gps->viewer) {
- if (gps->marker) {
- grits_viewer_remove(gps->viewer,
- GRITS_OBJECT(gps->marker));
- }
- g_object_unref(gps->viewer);
+ GritsViewer *viewer = gps->viewer;
gps->viewer = NULL;
+ if (gps->marker)
+ grits_viewer_remove(viewer,
+ GRITS_OBJECT(gps->marker));
+ g_object_unref(gps->prefs);
+ g_object_unref(viewer);
}
- gps_track_free(&gps->track);
-
/* Drop references */
G_OBJECT_CLASS(grits_plugin_gps_parent_class)->dispose(gobject);
}
g_debug("GritsPluginGps: finalize");
/* Free data */
- gtk_widget_destroy(gps->config);
+ gps_track_free(&gps->track);
G_OBJECT_CLASS(grits_plugin_gps_parent_class)->finalize(gobject);
}