diff options
author | Dan Winship <danw@src.gnome.org> | 2008-04-08 22:05:14 +0000 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2008-04-08 22:05:14 +0000 |
commit | 700b6a340c5142255b2189fb78580ca2dc96a1ae (patch) | |
tree | 1541a0336852cc927f825dfd5b1d1933ac9d0009 /libsoup/soup-session-feature.c | |
parent | f51262fbeef000816ba12a52a7967fd812eab0c6 (diff) | |
download | libsoup-700b6a340c5142255b2189fb78580ca2dc96a1ae.tar.gz |
New interface type representing a feature that can be added to a
* libsoup/soup-session-feature.c: New interface type representing
a feature that can be added to a SoupSession.
* libsoup/soup-session.c (soup_session_add_feature): Add a feature
to the session by prepending it to priv->features and calling
soup_session_feature_attach() on it.
(soup_session_add_feature_by_type): Add a feature to the session
by creating an object of the indicated type and passing it to
soup_session_add_feature.
(soup_session_remove_feature)
(soup_session_remove_feature_by_type): Likewise, remove features
(soup_session_class_init, set_property): register/handle
construct-time feature adding/removing properties
(dispose): cleanup features
* libsoup/soup-logger.c: port to SoupSessionFeature
* tests/test-utils.c (soup_test_session_new): Use
soup_session_add_feature rather than soup_logger_attach.
svn path=/trunk/; revision=1133
Diffstat (limited to 'libsoup/soup-session-feature.c')
-rw-r--r-- | libsoup/soup-session-feature.c | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/libsoup/soup-session-feature.c b/libsoup/soup-session-feature.c new file mode 100644 index 00000000..a2abb0b8 --- /dev/null +++ b/libsoup/soup-session-feature.c @@ -0,0 +1,136 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * soup-session-feature.c: Miscellaneous session feature-provider interface + * + * Copyright (C) 2008 Red Hat, Inc. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "soup-session-feature.h" + +static void soup_session_feature_interface_init (SoupSessionFeatureInterface *interface); + +static void attach (SoupSessionFeature *feature, SoupSession *session); +static void detach (SoupSessionFeature *feature, SoupSession *session); + +GType +soup_session_feature_get_type (void) +{ + static volatile gsize g_define_type_id__volatile = 0; + if (g_once_init_enter (&g_define_type_id__volatile)) + { + GType g_define_type_id = + g_type_register_static_simple (G_TYPE_INTERFACE, + g_intern_static_string ("SoupSessionFeature"), + sizeof (SoupSessionFeatureInterface), + (GClassInitFunc)soup_session_feature_interface_init, + 0, + (GInstanceInitFunc)NULL, + (GTypeFlags) 0); + g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_OBJECT); + g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + } + return g_define_type_id__volatile; +} + +static void +soup_session_feature_interface_init (SoupSessionFeatureInterface *interface) +{ + interface->attach = attach; + interface->detach = detach; +} + +static void +weak_notify_unref (gpointer feature, GObject *ex_object) +{ + g_object_unref (feature); +} + +static void +request_queued (SoupSession *session, SoupMessage *msg, gpointer feature) +{ + SOUP_SESSION_FEATURE_GET_CLASS (feature)-> + request_queued (feature, session, msg); +} + +static void +request_started (SoupSession *session, SoupMessage *msg, + SoupSocket *socket, gpointer feature) +{ + SOUP_SESSION_FEATURE_GET_CLASS (feature)-> + request_started (feature, session, msg, socket); +} + +static void +request_unqueued (SoupSession *session, SoupMessage *msg, gpointer feature) +{ + SOUP_SESSION_FEATURE_GET_CLASS (feature)-> + request_unqueued (feature, session, msg); +} + +static void +attach (SoupSessionFeature *feature, SoupSession *session) +{ + g_object_weak_ref (G_OBJECT (session), + weak_notify_unref, g_object_ref (feature)); + + if (SOUP_SESSION_FEATURE_GET_CLASS (feature)->request_queued) { + g_signal_connect (session, "request_queued", + G_CALLBACK (request_queued), feature); + } + + if (SOUP_SESSION_FEATURE_GET_CLASS (feature)->request_started) { + g_signal_connect (session, "request_started", + G_CALLBACK (request_started), feature); + } + + if (SOUP_SESSION_FEATURE_GET_CLASS (feature)->request_unqueued) { + g_signal_connect (session, "request_unqueued", + G_CALLBACK (request_unqueued), feature); + } +} + +/** + * soup_session_feature_attach: + * @feature: a #SoupSessionFeature + * @session: a #SoupSession + * + * Adds @feature to @session. + **/ +void +soup_session_feature_attach (SoupSessionFeature *feature, + SoupSession *session) +{ + SOUP_SESSION_FEATURE_GET_CLASS (feature)->attach (feature, session); +} + +static void +detach (SoupSessionFeature *feature, SoupSession *session) +{ + g_object_weak_unref (G_OBJECT (session), weak_notify_unref, feature); + + g_signal_handlers_disconnect_by_func (session, request_queued, feature); + g_signal_handlers_disconnect_by_func (session, request_started, feature); + g_signal_handlers_disconnect_by_func (session, request_unqueued, feature); + + g_object_unref (feature); +} + +/** + * soup_session_feature_detach: + * @feature: a #SoupSessionFeature + * @session: a #SoupSession + * + * Removes @feature from @session. + * + * Return value: success or failure + **/ +void +soup_session_feature_detach (SoupSessionFeature *feature, + SoupSession *session) +{ + SOUP_SESSION_FEATURE_GET_CLASS (feature)->detach (feature, session); +} |