X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/c60f82df6d7202e2fc96628124cda3a2f0debbd7..c75da9362bd81685e096a4d7a854485a5738c470:/src/osm-traces.c diff --git a/src/osm-traces.c b/src/osm-traces.c index 0cc1e40c..7e0792bd 100644 --- a/src/osm-traces.c +++ b/src/osm-traces.c @@ -127,11 +127,6 @@ static const gchar *get_default_user() void osm_set_login(const gchar *user, const gchar *password) { - /* Allocate mutex */ - if (login_mutex == NULL) - { - login_mutex = g_mutex_new(); - } g_mutex_lock(login_mutex); g_free(osm_user); osm_user = NULL; g_free(osm_password); osm_password = NULL; @@ -160,6 +155,12 @@ void osm_traces_init () { tmp.s = ""; a_preferences_register(prefs+1, tmp, VIKING_OSM_TRACES_PARAMS_GROUP_KEY); + login_mutex = vik_mutex_new(); +} + +void osm_traces_uninit() +{ + vik_mutex_free(login_mutex); } /* @@ -265,25 +266,11 @@ static void osm_traces_upload_thread ( OsmTracesInfo *oti, gpointer threaddata ) /* Due to OSM limits, we have to enforce ele and time fields also don't upload invisible tracks */ static GpxWritingOptions options = { TRUE, TRUE, FALSE, FALSE }; - FILE *file = NULL; - gchar *filename = NULL; - int fd; - GError *error = NULL; - int ret; - - g_assert(oti != NULL); - /* Opening temporary file */ - fd = g_file_open_tmp("viking_osm_upload_XXXXXX.gpx", &filename, &error); - if (fd < 0) { - g_error(_("failed to open temporary file: %s"), strerror(errno)); + if (!oti) return; - } - g_clear_error(&error); - g_debug("%s: temporary file = %s", __FUNCTION__, filename); - /* Creating FILE* */ - file = fdopen(fd, "w"); + gchar *filename = NULL; /* writing gpx file */ if (oti->trk != NULL) @@ -293,22 +280,20 @@ static void osm_traces_upload_thread ( OsmTracesInfo *oti, gpointer threaddata ) { VikTrack *trk = vik_track_copy(oti->trk, TRUE); vik_track_anonymize_times(trk); - a_gpx_write_track_file(trk, file, &options); + filename = a_gpx_write_track_tmp_file(trk, &options); vik_track_free(trk); } else - a_gpx_write_track_file(oti->trk, file, &options); + filename = a_gpx_write_track_tmp_file (oti->trk, &options); } else { /* Upload the whole VikTrwLayer */ - a_gpx_write_file(oti->vtl, file, &options); + filename = a_gpx_write_tmp_file (oti->vtl, &options); } - /* We can close the file */ - /* This also close the associated fd */ - fclose(file); - file = NULL; + if ( !filename ) + return; /* finally, upload it */ gint ans = osm_traces_upload_file(osm_user, osm_password, filename, @@ -350,7 +335,7 @@ static void osm_traces_upload_thread ( OsmTracesInfo *oti, gpointer threaddata ) g_free (msg); } /* Removing temporary file */ - ret = g_unlink(filename); + int ret = g_unlink(filename); if (ret != 0) { g_critical(_("failed to unlink temporary file: %s"), strerror(errno)); } @@ -540,14 +525,15 @@ void osm_traces_upload_viktrwlayer ( VikTrwLayer *vtl, VikTrack *trk ) title = g_strdup_printf(_("Uploading %s to OSM"), info->name); - /* launch the thread */ - a_background_thread(VIK_GTK_WINDOW_FROM_LAYER(vtl), /* parent window */ - title, /* description string */ - (vik_thr_func) osm_traces_upload_thread, /* function to call within thread */ - info, /* pass along data */ - (vik_thr_free_func) oti_free, /* function to free pass along data */ - (vik_thr_free_func) NULL, - 1 ); + // launch the thread + a_background_thread( BACKGROUND_POOL_REMOTE, + VIK_GTK_WINDOW_FROM_LAYER(vtl), /* parent window */ + title, /* description string */ + (vik_thr_func) osm_traces_upload_thread, /* function to call within thread */ + info, /* pass along data */ + (vik_thr_free_func) oti_free, /* function to free pass along data */ + (vik_thr_free_func) NULL, + 1 ); g_free ( title ); title = NULL; } gtk_widget_destroy ( dia );