[libsoup/wip/http2-upstreaming] Pull SoupMessageIOSource into its own file




commit 1d2258dcfb23785d45507a84d31c4d666bc27b8e
Author: Patrick Griffis <pgriffis igalia com>
Date:   Fri Nov 20 15:29:12 2020 -0600

    Pull SoupMessageIOSource into its own file

 docs/reference/meson.build        |   1 +
 libsoup/meson.build               |   1 +
 libsoup/soup-message-io-backend.h |   5 +-
 libsoup/soup-message-io-data.c    |  79 +------------------------
 libsoup/soup-message-io-data.h    |   4 +-
 libsoup/soup-message-io-source.c  | 117 ++++++++++++++++++++++++++++++++++++++
 libsoup/soup-message-io-source.h  |  19 +++++++
 7 files changed, 142 insertions(+), 84 deletions(-)
---
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
index bb09f7d9..058bdd62 100644
--- a/docs/reference/meson.build
+++ b/docs/reference/meson.build
@@ -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',
diff --git a/libsoup/meson.build b/libsoup/meson.build
index 629962b3..6e6b7ef6 100644
--- a/libsoup/meson.build
+++ b/libsoup/meson.build
@@ -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',
diff --git a/libsoup/soup-message-io-backend.h b/libsoup/soup-message-io-backend.h
index a43dc5bd..e90131eb 100644
--- a/libsoup/soup-message-io-backend.h
+++ b/libsoup/soup-message-io-backend.h
@@ -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 **);
diff --git a/libsoup/soup-message-io-data.c b/libsoup/soup-message-io-data.c
index 87026633..d8792033 100644
--- a/libsoup/soup-message-io-data.c
+++ b/libsoup/soup-message-io-data.c
@@ -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;
 }
diff --git a/libsoup/soup-message-io-data.h b/libsoup/soup-message-io-data.h
index 0f317385..329ad805 100644
--- a/libsoup/soup-message-io-data.h
+++ b/libsoup/soup-message-io-data.h
@@ -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,
diff --git a/libsoup/soup-message-io-source.c b/libsoup/soup-message-io-source.c
new file mode 100644
index 00000000..138b7ba4
--- /dev/null
+++ b/libsoup/soup-message-io-source.c
@@ -0,0 +1,117 @@
+
+/* 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_check (GSource *source)
+{
+       SoupMessageIOSource *message_io_source = (SoupMessageIOSource *)source;
+        return message_io_source->check_func (source);
+}
+
+
+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,
+       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_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;
+}
diff --git a/libsoup/soup-message-io-source.h b/libsoup/soup-message-io-source.h
new file mode 100644
index 00000000..6b95194c
--- /dev/null
+++ b/libsoup/soup-message-io-source.h
@@ -0,0 +1,19 @@
+
+#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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]