libsoup r1133 - in trunk: . libsoup tests
- From: danw svn gnome org
- To: svn-commits-list gnome org
- Subject: libsoup r1133 - in trunk: . libsoup tests
- Date: Tue, 8 Apr 2008 23:05:15 +0100 (BST)
Author: danw
Date: Tue Apr 8 23:05:14 2008
New Revision: 1133
URL: http://svn.gnome.org/viewvc/libsoup?rev=1133&view=rev
Log:
* 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.
Added:
trunk/libsoup/soup-session-feature.c
trunk/libsoup/soup-session-feature.h
Modified:
trunk/ChangeLog
trunk/libsoup/Makefile.am
trunk/libsoup/soup-logger.c
trunk/libsoup/soup-logger.h
trunk/libsoup/soup-session.c
trunk/libsoup/soup-session.h
trunk/libsoup/soup-types.h
trunk/libsoup/soup.h
trunk/tests/test-utils.c
Modified: trunk/libsoup/Makefile.am
==============================================================================
--- trunk/libsoup/Makefile.am (original)
+++ trunk/libsoup/Makefile.am Tue Apr 8 23:05:14 2008
@@ -64,6 +64,7 @@
soup-server.h \
soup-session.h \
soup-session-async.h \
+ soup-session-feature.h \
soup-session-sync.h \
soup-socket.h \
soup-status.h \
@@ -132,6 +133,7 @@
soup-server.c \
soup-session.c \
soup-session-async.c \
+ soup-session-feature.c \
soup-session-private.h \
soup-session-sync.c \
soup-socket.c \
Modified: trunk/libsoup/soup-logger.c
==============================================================================
--- trunk/libsoup/soup-logger.c (original)
+++ trunk/libsoup/soup-logger.c Tue Apr 8 23:05:14 2008
@@ -15,6 +15,8 @@
#include "soup-logger.h"
#include "soup-message.h"
+#include "soup-session.h"
+#include "soup-session-feature.h"
#include "soup-uri.h"
/**
@@ -66,7 +68,18 @@
* connection.
**/
-G_DEFINE_TYPE (SoupLogger, soup_logger, G_TYPE_OBJECT)
+static void soup_logger_session_feature_init (SoupSessionFeatureInterface *feature_interface, gpointer interface_data);
+
+static void request_queued (SoupSessionFeature *feature, SoupSession *session,
+ SoupMessage *msg);
+static void request_started (SoupSessionFeature *feature, SoupSession *session,
+ SoupMessage *msg, SoupSocket *socket);
+static void request_unqueued (SoupSessionFeature *feature,
+ SoupSession *session, SoupMessage *msg);
+
+G_DEFINE_TYPE_WITH_CODE (SoupLogger, soup_logger, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE,
+ soup_logger_session_feature_init));
typedef struct {
/* We use a mutex so that if requests are being run in
@@ -133,6 +146,15 @@
object_class->finalize = finalize;
}
+static void
+soup_logger_session_feature_init (SoupSessionFeatureInterface *feature_interface,
+ gpointer interface_data)
+{
+ feature_interface->request_queued = request_queued;
+ feature_interface->request_started = request_started;
+ feature_interface->request_unqueued = request_unqueued;
+}
+
/**
* SoupLoggerLogLevel:
* @SOUP_LOGGER_LOG_NONE: No logging
@@ -313,27 +335,6 @@
return GPOINTER_TO_UINT (id);
}
-static void
-soup_logger_clear_id (SoupLogger *logger, gpointer object)
-{
- SoupLoggerPrivate *priv = SOUP_LOGGER_GET_PRIVATE (logger);
-
- g_object_set_qdata (object, priv->tag, NULL);
-}
-
-static void request_queued (SoupSession *session, SoupMessage *msg,
- gpointer user_data);
-static void request_started (SoupSession *session, SoupMessage *msg,
- SoupSocket *socket, gpointer user_data);
-static void request_unqueued (SoupSession *session, SoupMessage *msg,
- gpointer user_data);
-
-static void
-weak_notify_unref (gpointer logger, GObject *ex_session)
-{
- g_object_unref (logger);
-}
-
/**
* soup_logger_attach:
* @logger: a #SoupLogger
@@ -345,22 +346,14 @@
* (The session will take a reference on @logger, which will be
* removed when you call soup_logger_detach(), or when the session is
* destroyed.)
+ *
+ * Deprecated: Use soup_session_add_feature() instead.
**/
void
soup_logger_attach (SoupLogger *logger,
SoupSession *session)
{
- if (!soup_logger_get_id (logger, session))
- soup_logger_set_id (logger, session);
- g_signal_connect (session, "request_queued",
- G_CALLBACK (request_queued), logger);
- g_signal_connect (session, "request_started",
- G_CALLBACK (request_started), logger);
- g_signal_connect (session, "request_unqueued",
- G_CALLBACK (request_unqueued), logger);
-
- g_object_weak_ref (G_OBJECT (session),
- weak_notify_unref, g_object_ref (logger));
+ soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger));
}
/**
@@ -369,17 +362,14 @@
* @session: a #SoupSession
*
* Stops @logger from watching @session.
+ *
+ * Deprecated: Use soup_session_remove_feature() instead.
**/
void
soup_logger_detach (SoupLogger *logger,
SoupSession *session)
{
- g_signal_handlers_disconnect_by_func (session, request_queued, logger);
- g_signal_handlers_disconnect_by_func (session, request_started, logger);
- g_signal_handlers_disconnect_by_func (session, request_unqueued, logger);
-
- g_object_weak_unref (G_OBJECT (session),
- weak_notify_unref, logger);
+ soup_session_remove_feature (session, SOUP_SESSION_FEATURE (logger));
}
static void
@@ -610,10 +600,9 @@
}
static void
-request_queued (SoupSession *session, SoupMessage *msg, gpointer user_data)
+request_queued (SoupSessionFeature *logger, SoupSession *session,
+ SoupMessage *msg)
{
- SoupLogger *logger = user_data;
-
g_signal_connect (msg, "got-informational",
G_CALLBACK (got_informational),
logger);
@@ -623,10 +612,10 @@
}
static void
-request_started (SoupSession *session, SoupMessage *msg,
- SoupSocket *socket, gpointer user_data)
+request_started (SoupSessionFeature *feature, SoupSession *session,
+ SoupMessage *msg, SoupSocket *socket)
{
- SoupLogger *logger = user_data;
+ SoupLogger *logger = SOUP_LOGGER (feature);
gboolean restarted;
guint msg_id;
@@ -638,6 +627,9 @@
restarted = FALSE;
}
+ if (!soup_logger_get_id (logger, session))
+ soup_logger_set_id (logger, session);
+
if (!soup_logger_get_id (logger, socket))
soup_logger_set_id (logger, socket);
@@ -646,12 +638,9 @@
}
static void
-request_unqueued (SoupSession *session, SoupMessage *msg, gpointer user_data)
+request_unqueued (SoupSessionFeature *logger, SoupSession *session,
+ SoupMessage *msg)
{
- SoupLogger *logger = user_data;
-
g_signal_handlers_disconnect_by_func (msg, got_informational, logger);
g_signal_handlers_disconnect_by_func (msg, got_body, logger);
-
- soup_logger_clear_id (logger, msg);
}
Modified: trunk/libsoup/soup-logger.h
==============================================================================
--- trunk/libsoup/soup-logger.h (original)
+++ trunk/libsoup/soup-logger.h Tue Apr 8 23:05:14 2008
@@ -51,10 +51,13 @@
SoupLogger *soup_logger_new (SoupLoggerLogLevel level,
int max_body_size);
+#ifndef LIBSOUP_DISABLE_DEPRECATED
+/* Use soup_session_add/remove_feature */
void soup_logger_attach (SoupLogger *logger,
SoupSession *session);
void soup_logger_detach (SoupLogger *logger,
SoupSession *session);
+#endif
void soup_logger_set_request_filter (SoupLogger *logger,
SoupLoggerFilter request_filter,
Added: trunk/libsoup/soup-session-feature.c
==============================================================================
--- (empty file)
+++ trunk/libsoup/soup-session-feature.c Tue Apr 8 23:05:14 2008
@@ -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);
+}
Added: trunk/libsoup/soup-session-feature.h
==============================================================================
--- (empty file)
+++ trunk/libsoup/soup-session-feature.h Tue Apr 8 23:05:14 2008
@@ -0,0 +1,51 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008 Red Hat, Inc.
+ */
+
+#ifndef SOUP_SESSION_FEATURE_H
+#define SOUP_SESSION_FEATURE_H 1
+
+#include <libsoup/soup-types.h>
+
+G_BEGIN_DECLS
+
+#define SOUP_TYPE_SESSION_FEATURE (soup_session_feature_get_type ())
+#define SOUP_SESSION_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOUP_TYPE_SESSION_FEATURE, SoupSessionFeature))
+#define SOUP_SESSION_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SOUP_TYPE_SESSION_FEATURE, SoupSessionFeatureInterface))
+#define SOUP_IS_SESSION_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SOUP_TYPE_SESSION_FEATURE))
+#define SOUP_IS_SESSION_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SOUP_TYPE_SESSION_FEATURE))
+#define SOUP_SESSION_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), SOUP_TYPE_SESSION_FEATURE, SoupSessionFeatureInterface))
+
+typedef struct {
+ GTypeInterface parent;
+
+ /* methods */
+ void (*attach) (SoupSessionFeature *feature,
+ SoupSession *session);
+ void (*detach) (SoupSessionFeature *feature,
+ SoupSession *session);
+
+ void (*request_queued) (SoupSessionFeature *feature,
+ SoupSession *session,
+ SoupMessage *msg);
+ void (*request_started) (SoupSessionFeature *feature,
+ SoupSession *session,
+ SoupMessage *msg,
+ SoupSocket *socket);
+ void (*request_unqueued) (SoupSessionFeature *feature,
+ SoupSession *session,
+ SoupMessage *msg);
+
+} SoupSessionFeatureInterface;
+
+GType soup_session_feature_get_type (void);
+
+void soup_session_feature_attach (SoupSessionFeature *feature,
+ SoupSession *session);
+void soup_session_feature_detach (SoupSessionFeature *feature,
+ SoupSession *session);
+
+G_END_DECLS
+
+#endif /* SOUP_SESSION_FEATURE_H */
Modified: trunk/libsoup/soup-session.c
==============================================================================
--- trunk/libsoup/soup-session.c (original)
+++ trunk/libsoup/soup-session.c Tue Apr 8 23:05:14 2008
@@ -23,6 +23,7 @@
#include "soup-message-private.h"
#include "soup-message-queue.h"
#include "soup-session.h"
+#include "soup-session-feature.h"
#include "soup-session-private.h"
#include "soup-socket.h"
#include "soup-ssl.h"
@@ -75,6 +76,7 @@
char *user_agent;
+ GSList *features;
SoupAuthManager *auth_manager;
SoupAuthManagerNTLM *ntlm_manager;
@@ -137,6 +139,9 @@
PROP_TIMEOUT,
PROP_USER_AGENT,
PROP_IDLE_TIMEOUT,
+ PROP_ADD_FEATURE,
+ PROP_ADD_FEATURE_BY_TYPE,
+ PROP_REMOVE_FEATURE_BY_TYPE,
LAST_PROP
};
@@ -197,6 +202,9 @@
soup_session_abort (session);
cleanup_hosts (priv);
+ while (priv->features)
+ soup_session_remove_feature (session, priv->features->data);
+
G_OBJECT_CLASS (soup_session_parent_class)->dispose (object);
}
@@ -472,6 +480,28 @@
"User-Agent string",
NULL,
G_PARAM_READWRITE));
+
+ g_object_class_install_property (
+ object_class, PROP_ADD_FEATURE,
+ g_param_spec_object (SOUP_SESSION_ADD_FEATURE,
+ "Add Feature",
+ "Add a feature object to the session",
+ SOUP_TYPE_SESSION_FEATURE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (
+ object_class, PROP_ADD_FEATURE_BY_TYPE,
+ g_param_spec_gtype (SOUP_SESSION_ADD_FEATURE_BY_TYPE,
+ "Add Feature By Type",
+ "Add a feature object of the given type to the session",
+ SOUP_TYPE_SESSION_FEATURE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (
+ object_class, PROP_REMOVE_FEATURE_BY_TYPE,
+ g_param_spec_gtype (SOUP_SESSION_REMOVE_FEATURE_BY_TYPE,
+ "Remove Feature By Type",
+ "Remove features of the given type from the session",
+ SOUP_TYPE_SESSION_FEATURE,
+ G_PARAM_READWRITE));
}
static gboolean
@@ -589,6 +619,15 @@
case PROP_IDLE_TIMEOUT:
priv->idle_timeout = g_value_get_uint (value);
break;
+ case PROP_ADD_FEATURE:
+ soup_session_add_feature (session, g_value_get_object (value));
+ break;
+ case PROP_ADD_FEATURE_BY_TYPE:
+ soup_session_add_feature_by_type (session, g_value_get_gtype (value));
+ break;
+ case PROP_REMOVE_FEATURE_BY_TYPE:
+ soup_session_remove_feature_by_type (session, g_value_get_gtype (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1291,3 +1330,62 @@
g_slist_free (conns);
}
+
+void
+soup_session_add_feature (SoupSession *session, SoupSessionFeature *feature)
+{
+ SoupSessionPrivate *priv;
+
+ g_return_if_fail (SOUP_IS_SESSION (session));
+ g_return_if_fail (SOUP_IS_SESSION_FEATURE (feature));
+
+ priv = SOUP_SESSION_GET_PRIVATE (session);
+ priv->features = g_slist_prepend (priv->features, g_object_ref (feature));
+ soup_session_feature_attach (feature, session);
+}
+
+void
+soup_session_add_feature_by_type (SoupSession *session, GType feature_type)
+{
+ SoupSessionFeature *feature;
+
+ g_return_if_fail (SOUP_IS_SESSION (session));
+ g_return_if_fail (g_type_is_a (feature_type, SOUP_TYPE_SESSION_FEATURE));
+
+ feature = g_object_new (feature_type, NULL);
+ soup_session_add_feature (session, feature);
+ g_object_unref (feature);
+}
+
+void
+soup_session_remove_feature (SoupSession *session, SoupSessionFeature *feature)
+{
+ SoupSessionPrivate *priv;
+
+ g_return_if_fail (SOUP_IS_SESSION (session));
+
+ priv = SOUP_SESSION_GET_PRIVATE (session);
+ if (g_slist_find (priv->features, feature)) {
+ priv->features = g_slist_remove (priv->features, feature);
+ soup_session_feature_detach (feature, session);
+ g_object_unref (feature);
+ }
+}
+
+void
+soup_session_remove_feature_by_type (SoupSession *session, GType feature_type)
+{
+ SoupSessionPrivate *priv;
+ GSList *f;
+
+ g_return_if_fail (SOUP_IS_SESSION (session));
+
+ priv = SOUP_SESSION_GET_PRIVATE (session);
+restart:
+ for (f = priv->features; f; f = f->next) {
+ if (G_TYPE_CHECK_INSTANCE_TYPE (f->data, feature_type)) {
+ soup_session_remove_feature (session, f->data);
+ goto restart;
+ }
+ }
+}
Modified: trunk/libsoup/soup-session.h
==============================================================================
--- trunk/libsoup/soup-session.h (original)
+++ trunk/libsoup/soup-session.h Tue Apr 8 23:05:14 2008
@@ -64,6 +64,9 @@
#define SOUP_SESSION_TIMEOUT "timeout"
#define SOUP_SESSION_USER_AGENT "user-agent"
#define SOUP_SESSION_IDLE_TIMEOUT "idle-timeout"
+#define SOUP_SESSION_ADD_FEATURE "add-feature"
+#define SOUP_SESSION_ADD_FEATURE_BY_TYPE "add-feature-by-type"
+#define SOUP_SESSION_REMOVE_FEATURE_BY_TYPE "remove-feature-by-type"
GMainContext *soup_session_get_async_context(SoupSession *session);
@@ -87,6 +90,16 @@
guint status_code);
void soup_session_abort (SoupSession *session);
+
+void soup_session_add_feature (SoupSession *session,
+ SoupSessionFeature *feature);
+void soup_session_add_feature_by_type (SoupSession *session,
+ GType feature_type);
+void soup_session_remove_feature (SoupSession *session,
+ SoupSessionFeature *feature);
+void soup_session_remove_feature_by_type (SoupSession *session,
+ GType feature_type);
+
G_END_DECLS
#endif /* SOUP_SESSION_H */
Modified: trunk/libsoup/soup-types.h
==============================================================================
--- trunk/libsoup/soup-types.h (original)
+++ trunk/libsoup/soup-types.h Tue Apr 8 23:05:14 2008
@@ -20,6 +20,7 @@
typedef struct _SoupServer SoupServer;
typedef struct _SoupSession SoupSession;
typedef struct _SoupSessionAsync SoupSessionAsync;
+typedef struct _SoupSessionFeature SoupSessionFeature;
typedef struct _SoupSessionSync SoupSessionSync;
typedef struct _SoupSocket SoupSocket;
typedef struct _SoupURI SoupURI;
Modified: trunk/libsoup/soup.h
==============================================================================
--- trunk/libsoup/soup.h (original)
+++ trunk/libsoup/soup.h Tue Apr 8 23:05:14 2008
@@ -25,6 +25,7 @@
#include <libsoup/soup-misc.h>
#include <libsoup/soup-server.h>
#include <libsoup/soup-session-async.h>
+#include <libsoup/soup-session-feature.h>
#include <libsoup/soup-session-sync.h>
#include <libsoup/soup-socket.h>
#include <libsoup/soup-status.h>
Modified: trunk/tests/test-utils.c
==============================================================================
--- trunk/tests/test-utils.c (original)
+++ trunk/tests/test-utils.c Tue Apr 8 23:05:14 2008
@@ -3,9 +3,7 @@
#endif
#include "test-utils.h"
-#include "libsoup/soup-logger.h"
-#include "libsoup/soup-misc.h"
-#include "libsoup/soup-server.h"
+#include "libsoup/soup.h"
#include <signal.h>
#include <stdio.h>
@@ -222,7 +220,7 @@
}
if (logger)
- soup_logger_attach (logger, session);
+ soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger));
return session;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]