Add grits_http_abort function
authorAndy Spencer <andy753421@gmail.com>
Wed, 23 Jan 2013 06:30:53 +0000 (06:30 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 23 Jan 2013 06:30:53 +0000 (06:30 +0000)
This is similar to soup_session_abort, except that it also prevents any
additional requests from being queued. This prevents long waits if we
cancel during a loop, as was done in the AWeather alerts plugin.

src/data/grits-http.c
src/data/grits-http.h
src/plugins/elev.c
src/plugins/map.c
src/plugins/sat.c

index 01bc705..45b30df 100644 (file)
@@ -59,6 +59,19 @@ GritsHttp *grits_http_new(const gchar *prefix)
 }
 
 /**
+ * grits_http_abort:
+ * @http: the #GritsHttp to abort
+ *
+ * Cancels any pending requests and prevents new requests.
+ */
+void grits_http_abort(GritsHttp *http)
+{
+       g_debug("GritsHttp: abort - %s", http->prefix);
+       http->aborted = TRUE;
+       soup_session_abort(http->soup);
+}
+
+/**
  * grits_http_free:
  * @http: the #GritsHttp to free
  *
@@ -67,7 +80,6 @@ GritsHttp *grits_http_new(const gchar *prefix)
 void grits_http_free(GritsHttp *http)
 {
        g_debug("GritsHttp: free - %s", http->prefix);
-       soup_session_abort(http->soup);
        g_object_unref(http->soup);
        g_free(http->prefix);
        g_free(http);
@@ -148,6 +160,10 @@ gchar *grits_http_fetch(GritsHttp *http, const gchar *uri, const char *local,
                GritsCacheType mode, GritsChunkCallback callback, gpointer user_data)
 {
        g_debug("GritsHttp: fetch - %s mode=%d", local, mode);
+       if (http->aborted) {
+               g_debug("GritsPluginSat: _load_tile_thread - aborted");
+               return NULL;
+       }
        gchar *path = _get_cache_path(http, local);
 
        /* Unlink the file if we're refreshing it */
index 04f9a63..55865bf 100644 (file)
 typedef struct _GritsHttp {
        SoupSession *soup;
        gchar *prefix;
+       gboolean aborted;
 } GritsHttp;
 
 GritsHttp *grits_http_new(const gchar *prefix);
 
+void grits_http_abort(GritsHttp *http);
+
 void grits_http_free(GritsHttp *http);
 
 gchar *grits_http_fetch(GritsHttp *http, const gchar *uri, const gchar *local,
index 3fbeb87..3634df6 100644 (file)
@@ -266,7 +266,7 @@ static void grits_plugin_elev_dispose(GObject *gobject)
        if (elev->viewer) {
                GritsViewer *viewer = elev->viewer;
                g_signal_handler_disconnect(viewer, elev->sigid);
-               soup_session_abort(elev->wms->http->soup);
+               grits_http_abort(elev->wms->http);
                g_thread_pool_free(elev->threads, TRUE, TRUE);
                elev->viewer = NULL;
                if (LOAD_BIL)
index 255f67c..23e8b24 100644 (file)
@@ -190,8 +190,8 @@ static void grits_plugin_map_dispose(GObject *gobject)
        if (map->viewer) {
                GritsViewer *viewer = map->viewer;
                g_signal_handler_disconnect(viewer, map->sigid);
-               soup_session_abort(map->tms->http->soup);
-               //soup_session_abort(map->wms->http->soup);
+               grits_http_abort(map->tms->http);
+               //grits_http_abort(map->wms->http);
                g_thread_pool_free(map->threads, TRUE, TRUE);
                map->viewer = NULL;
                grits_viewer_remove(viewer, GRITS_OBJECT(map->tiles));
index 5389ddb..bf3b598 100644 (file)
@@ -170,7 +170,7 @@ static void grits_plugin_sat_dispose(GObject *gobject)
        if (sat->viewer) {
                GritsViewer *viewer = sat->viewer;
                g_signal_handler_disconnect(viewer, sat->sigid);
-               soup_session_abort(sat->wms->http->soup);
+               grits_http_abort(sat->wms->http);
                g_thread_pool_free(sat->threads, TRUE, TRUE);
                sat->viewer = NULL;
                grits_viewer_remove(viewer, GRITS_OBJECT(sat->tiles));