Commit 1cee3172 authored by Patrick Griffis's avatar Patrick Griffis
Browse files

Pull SoupMessageIOSource into its own file

parent aeafebf2
Pipeline #274738 passed with stages
in 5 minutes and 3 seconds
......@@ -36,6 +36,7 @@ ignore_headers = [
'soup-message-io-backend.h',
'soup-message-io-data.h',
'soup-message-io-http1.h',
'soup-message-io-source.h',
'soup-uri-utils-private.h',
'soup-session-feature-private.h',
'soup-message-metrics-private.h',
......
......@@ -67,6 +67,7 @@ soup_sources = [
'soup-message-io-data.c',
'soup-message-metrics.c',
'soup-message-queue-item.c',
'soup-message-io-source.c',
'soup-method.c',
'soup-misc.c',
'soup-multipart.c',
......
......@@ -23,6 +23,7 @@
#include "soup-types.h"
#include "soup-message-headers.h"
#include "soup-filter-input-stream.h"
#include "soup-message-io-source.h"
G_BEGIN_DECLS
......@@ -30,8 +31,6 @@ G_BEGIN_DECLS
G_DECLARE_INTERFACE (SoupMessageIOBackend, soup_message_io_backend, SOUP, MESSAGE_IO_BACKEND, GObject)
typedef gboolean (*SoupMessageSourceFunc) (SoupMessage *, gpointer);
typedef enum {
SOUP_MESSAGE_IO_COMPLETE,
SOUP_MESSAGE_IO_INTERRUPTED,
......@@ -53,7 +52,7 @@ struct _SoupMessageIOBackendInterface
void (*stolen) (SoupMessage *);
gboolean (*is_paused) (SoupMessage *);
gboolean (*in_progress) (SoupMessage *);
GSource * (*get_source) (SoupMessage *, GCancellable *, SoupMessageSourceFunc, gpointer);
GSource * (*get_source) (SoupMessage *, GCancellable *, SoupMessageIOSourceFunc, gpointer);
GInputStream * (*get_response_istream) (SoupMessage *, GError **);
void (*run) (SoupMessage *, gboolean);
gboolean (*run_until_read) (SoupMessage *, GCancellable *, GError **);
......
......@@ -124,12 +124,6 @@ message_io_is_paused (GObject *msg)
return FALSE;
}
typedef struct {
GSource source;
GObject *msg;
gboolean paused;
} SoupMessageIOSource;
static gboolean
message_io_source_check (GSource *source)
{
......@@ -143,66 +137,6 @@ message_io_source_check (GSource *source)
return FALSE;
}
static gboolean
message_io_source_prepare (GSource *source,
gint *timeout)
{
*timeout = -1;
return message_io_source_check (source);
}
static gboolean
message_io_source_dispatch (GSource *source,
GSourceFunc callback,
gpointer user_data)
{
SoupMessageIOSourceFunc func = (SoupMessageIOSourceFunc)callback;
SoupMessageIOSource *message_source = (SoupMessageIOSource *)source;
return (*func) (message_source->msg, user_data);
}
static void
message_io_source_finalize (GSource *source)
{
SoupMessageIOSource *message_source = (SoupMessageIOSource *)source;
g_object_unref (message_source->msg);
}
static gboolean
message_io_source_closure_callback (GObject *msg,
gpointer data)
{
GClosure *closure = data;
GValue param = G_VALUE_INIT;
GValue result_value = G_VALUE_INIT;
gboolean result;
g_value_init (&result_value, G_TYPE_BOOLEAN);
g_value_init (&param, G_TYPE_OBJECT);
g_value_set_object (&param, msg);
g_closure_invoke (closure, &result_value, 1, &param, NULL);
result = g_value_get_boolean (&result_value);
g_value_unset (&result_value);
g_value_unset (&param);
return result;
}
static GSourceFuncs message_io_source_funcs =
{
message_io_source_prepare,
message_io_source_check,
message_io_source_dispatch,
message_io_source_finalize,
(GSourceFunc)message_io_source_closure_callback,
(GSourceDummyMarshal)g_cclosure_marshal_generic,
};
GSource *
soup_message_io_data_get_source (SoupMessageIOData *io,
GObject *msg,
......@@ -211,7 +145,6 @@ soup_message_io_data_get_source (SoupMessageIOData *io,
gpointer user_data)
{
GSource *base_source, *source;
SoupMessageIOSource *message_source;
if (!io) {
base_source = g_timeout_source_new (0);
......@@ -238,17 +171,7 @@ soup_message_io_data_get_source (SoupMessageIOData *io,
} else
base_source = g_timeout_source_new (0);
source = g_source_new (&message_io_source_funcs, sizeof (SoupMessageIOSource));
g_source_set_name (source, "SoupMessageIOSource");
message_source = (SoupMessageIOSource *)source;
message_source->msg = g_object_ref (msg);
message_source->paused = io && io->paused;
if (base_source) {
g_source_set_dummy_callback (base_source);
g_source_add_child_source (source, base_source);
g_source_unref (base_source);
}
source = soup_message_io_source_new (base_source, msg, io && io->paused, message_io_source_check);
g_source_set_callback (source, (GSourceFunc) callback, user_data, NULL);
return source;
}
......
......@@ -9,6 +9,7 @@
#include "soup-filter-input-stream.h"
#include "soup-message-headers.h"
#include "soup-message-io-backend.h"
#include "soup-message-io-source.h"
typedef enum {
SOUP_MESSAGE_IO_STATE_NOT_STARTED,
......@@ -74,9 +75,6 @@ gboolean soup_message_io_data_read_headers (SoupMessageIOData *io,
gushort *extra_bytes,
GError **error);
typedef gboolean (*SoupMessageIOSourceFunc) (GObject *msg,
gpointer user_data);
GSource *soup_message_io_data_get_source (SoupMessageIOData *io,
GObject *msg,
GCancellable *cancellable,
......
/* soup-message-io-source.c
*
* Copyright 2020 Igalia S.L.
*
* This file is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "soup-message-io-source.h"
static gboolean
message_io_source_prepare (GSource *source,
gint *timeout)
{
SoupMessageIOSource *message_io_source = (SoupMessageIOSource *)source;
*timeout = -1;
return message_io_source->check_func (source);
}
static gboolean
message_io_source_dispatch (GSource *source,
GSourceFunc callback,
gpointer user_data)
{
SoupMessageIOSourceFunc func = (SoupMessageIOSourceFunc)callback;
SoupMessageIOSource *message_io_source = (SoupMessageIOSource *)source;
return (*func) (message_io_source->msg, user_data);
}
static void
message_io_source_finalize (GSource *source)
{
SoupMessageIOSource *message_io_source = (SoupMessageIOSource *)source;
g_object_unref (message_io_source->msg);
}
static gboolean
message_io_source_closure_callback (SoupMessage *msg,
gpointer data)
{
GClosure *closure = data;
GValue param = G_VALUE_INIT;
GValue result_value = G_VALUE_INIT;
gboolean result;
g_value_init (&result_value, G_TYPE_BOOLEAN);
g_value_init (&param, SOUP_TYPE_MESSAGE);
g_value_set_object (&param, msg);
g_closure_invoke (closure, &result_value, 1, &param, NULL);
result = g_value_get_boolean (&result_value);
g_value_unset (&result_value);
g_value_unset (&param);
return result;
}
static GSourceFuncs message_io_source_funcs =
{
message_io_source_prepare,
NULL,
message_io_source_dispatch,
message_io_source_finalize,
(GSourceFunc)message_io_source_closure_callback,
(GSourceDummyMarshal)g_cclosure_marshal_generic,
};
GSource *
soup_message_io_source_new (GSource *base_source,
GObject *msg,
gboolean paused,
gboolean (*check_func) (GSource*))
{
GSource *source = g_source_new (&message_io_source_funcs, sizeof (SoupMessageIOSource));
g_source_set_name (source, "SoupMessageIOSource");
SoupMessageIOSource *message_io_source = (SoupMessageIOSource *)source;
message_io_source->msg = g_object_ref (msg);
message_io_source->paused = paused;
message_io_source->check_func = check_func;
if (base_source) {
g_source_set_dummy_callback (base_source);
g_source_add_child_source (source, base_source);
g_source_unref (base_source);
}
return source;
}
#pragma once
#include "soup.h"
typedef struct {
GSource source;
GObject *msg;
gboolean (*check_func) (GSource*);
gboolean paused;
} SoupMessageIOSource;
typedef gboolean (*SoupMessageIOSourceFunc) (GObject *msg,
gpointer user_data);
GSource *soup_message_io_source_new (GSource *base_source,
GObject *msg,
gboolean paused,
gboolean (*check_func) (GSource*));
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment