[libsoup/cache] Keep a pointer to the session in the cache object.
- From: Xan Lopez <xan src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libsoup/cache] Keep a pointer to the session in the cache object.
- Date: Tue, 4 Aug 2009 11:57:40 +0000 (UTC)
commit ac98585d6cf58fc9fb822273e432704817fd66fe
Author: Xan Lopez <xan gnome org>
Date: Tue Aug 4 14:24:58 2009 +0300
Keep a pointer to the session in the cache object.
Allows to simplify some APIs.
libsoup/soup-cache.c | 23 ++++++++++++++++++++---
libsoup/soup-cache.h | 5 +----
libsoup/soup-session-async.c | 4 ++--
tests/cache-test.c | 2 +-
4 files changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/libsoup/soup-cache.c b/libsoup/soup-cache.c
index a32521a..0bfe1e9 100644
--- a/libsoup/soup-cache.c
+++ b/libsoup/soup-cache.c
@@ -26,6 +26,7 @@
#include <gio/gio.h>
+static SoupSessionFeatureInterface *soup_cache_default_feature_interface;
static void soup_cache_session_feature_init (SoupSessionFeatureInterface *feature_interface, gpointer interface_data);
typedef struct _SoupCacheEntry
@@ -609,7 +610,7 @@ msg_got_headers_cb (SoupMessage *msg, SoupCache *cache)
}
gboolean
-soup_cache_has_response (SoupCache *cache, SoupSession *session, SoupMessage *msg)
+soup_cache_has_response (SoupCache *cache, SoupMessage *msg)
{
char *key;
SoupCacheEntry *entry;
@@ -752,7 +753,7 @@ load_contents_ready_cb (GObject *source, GAsyncResult *result, SoupMessage *msg)
}
void
-soup_cache_send_response (SoupCache *cache, SoupSession *session, SoupMessage *msg)
+soup_cache_send_response (SoupCache *cache, SoupMessage *msg)
{
char *key;
SoupCacheEntry *entry;
@@ -800,9 +801,22 @@ request_started (SoupSessionFeature *feature, SoupSession *session,
}
static void
+attach (SoupSessionFeature *feature, SoupSession *session)
+{
+ SoupCache *cache = SOUP_CACHE (feature);
+ cache->priv->session = session;
+
+ soup_cache_default_feature_interface->attach (feature, session);
+}
+
+static void
soup_cache_session_feature_init (SoupSessionFeatureInterface *feature_interface,
gpointer interface_data)
{
+ soup_cache_default_feature_interface =
+ g_type_default_interface_peek (SOUP_TYPE_SESSION_FEATURE);
+
+ feature_interface->attach = attach;
feature_interface->request_started = request_started;
}
@@ -956,12 +970,15 @@ soup_cache_get_cacheability (SoupCache *cache, SoupMessage *msg)
* as needed.
**/
void
-soup_cache_flush (SoupCache *cache, SoupSession *session)
+soup_cache_flush (SoupCache *cache)
{
GMainContext *async_context;
+ SoupSession *session;
g_return_if_fail (SOUP_IS_CACHE (cache));
+ session = cache->priv->session;
+ g_return_if_fail (SOUP_IS_SESSION (session));
async_context = soup_session_get_async_context (session);
while (cache->priv->n_pending > 0)
diff --git a/libsoup/soup-cache.h b/libsoup/soup-cache.h
index e19fdde..dc7de55 100644
--- a/libsoup/soup-cache.h
+++ b/libsoup/soup-cache.h
@@ -46,15 +46,12 @@ typedef struct {
GType soup_cache_get_type (void);
SoupCache* soup_cache_new (const char *cache_dir);
gboolean soup_cache_has_response (SoupCache *cache,
- SoupSession *session,
SoupMessage *msg);
void soup_cache_send_response (SoupCache *cache,
- SoupSession *session,
SoupMessage *msg);
SoupCacheability soup_cache_get_cacheability (SoupCache *cache,
SoupMessage *msg);
-void soup_cache_flush (SoupCache *cache,
- SoupSession *session);
+void soup_cache_flush (SoupCache *cache);
void soup_cache_clear (SoupCache *cache);
G_END_DECLS
diff --git a/libsoup/soup-session-async.c b/libsoup/soup-session-async.c
index 483d947..e01f888 100644
--- a/libsoup/soup-session-async.c
+++ b/libsoup/soup-session-async.c
@@ -310,9 +310,9 @@ run_queue (SoupSessionAsync *sa)
item = soup_message_queue_next (queue, item)) {
msg = item->msg;
- if (cache && soup_cache_has_response (cache, session, msg)) {
+ if (cache && soup_cache_has_response (cache, msg)) {
soup_message_set_io_status (msg, SOUP_MESSAGE_IO_STATUS_RUNNING);
- soup_cache_send_response (cache, session, msg);
+ soup_cache_send_response (cache, msg);
continue;
}
diff --git a/tests/cache-test.c b/tests/cache-test.c
index ceba2dc..81a6866 100644
--- a/tests/cache-test.c
+++ b/tests/cache-test.c
@@ -75,7 +75,7 @@ server_callback (SoupServer *server,
static void
finished (SoupSession *session, SoupMessage *msg, gpointer data)
{
- soup_cache_flush (cache, session);
+ soup_cache_flush (cache);
if (g_main_loop_is_running (loop))
g_main_loop_quit (loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]