summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiovanni Campagna <gcampagna@src.gnome.org>2013-03-17 18:48:13 +0100
committerGiovanni Campagna <gcampagna@src.gnome.org>2013-03-26 15:26:01 +0100
commitb688d230b3c67bdb3021468c011b3fecb3b18146 (patch)
treef19bf836770741297684cfca32a097ec1e3ecafc
parent3ebea5790be0b70e91959c0381941664d2f9a6ea (diff)
downloadlibgweather-b688d230b3c67bdb3021468c011b3fecb3b18146.tar.gz
GWeatherInfo: add API to store the cache explicitly
Not all languages can make sure that the GWeatherInfo object is properly finalized at shutdown.
-rw-r--r--libgweather/gweather-weather.h1
-rw-r--r--libgweather/weather.c31
2 files changed, 30 insertions, 2 deletions
diff --git a/libgweather/gweather-weather.h b/libgweather/gweather-weather.h
index a597bf7..86c1f29 100644
--- a/libgweather/gweather-weather.h
+++ b/libgweather/gweather-weather.h
@@ -82,6 +82,7 @@ GWeatherInfo * gweather_info_new_for_world (GWeatherLocation *wo
GWeatherForecastType forecast_type);
void gweather_info_update (GWeatherInfo *info);
void gweather_info_abort (GWeatherInfo *info);
+void gweather_info_store_cache (void);
GWeatherProvider gweather_info_get_enabled_providers (GWeatherInfo *info);
void gweather_info_set_enabled_providers (GWeatherInfo *info,
diff --git a/libgweather/weather.c b/libgweather/weather.c
index e63fda8..b36534d 100644
--- a/libgweather/weather.c
+++ b/libgweather/weather.c
@@ -447,12 +447,16 @@ dump_and_unref_cache (SoupCache *cache)
g_object_unref (cache);
}
+static SoupSession *static_session;
+
static SoupSession *
ref_session (void)
{
- static SoupSession *session;
+ SoupSession *session;
SoupCache *cache;
+ session = static_session;
+
if (session != NULL)
return g_object_ref (session);
@@ -468,11 +472,34 @@ ref_session (void)
soup_cache_load (cache);
g_object_unref (cache);
- g_object_add_weak_pointer (G_OBJECT (session), (void**) &session);
+ static_session = session;
+ g_object_add_weak_pointer (G_OBJECT (session), (void**) &static_session);
return session;
}
+/**
+ * gweather_info_store_cache:
+ *
+ * Ensures that any data cached from the network is stored to disk.
+ * Calling this is not necessary, as the cache will be saved when
+ * the last reference to a #GWeatherInfo will be dropped.
+ * On the other hand, it must be called if there is any chance that
+ * the application will be closed without unreffing all objects, such
+ * as when using a language binding that employs a GC.
+ */
+void
+gweather_info_store_cache (void)
+{
+ SoupCache *cache;
+
+ if (static_session == NULL)
+ return;
+
+ cache = g_object_get_data (G_OBJECT (static_session), "libgweather-cache");
+ soup_cache_dump (cache);
+}
+
void
gweather_info_update (GWeatherInfo *info)
{