[libgweather] GWeatherInfo: add API to store the cache explicitly
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather] GWeatherInfo: add API to store the cache explicitly
- Date: Tue, 26 Mar 2013 14:29:12 +0000 (UTC)
commit b688d230b3c67bdb3021468c011b3fecb3b18146
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sun Mar 17 18:48:13 2013 +0100
GWeatherInfo: add API to store the cache explicitly
Not all languages can make sure that the GWeatherInfo object is properly
finalized at shutdown.
libgweather/gweather-weather.h | 1 +
libgweather/weather.c | 31 +++++++++++++++++++++++++++++--
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)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]