#include "config.h"
#include "gfilterinputstream.h"
#include "ginputstream.h"
-#include "gsimpleasyncresult.h"
#include "glibintl.h"
-#include "gioalias.h"
/**
* SECTION:gfilterinputstream
* @short_description: Filter Input Stream
* @include: gio/gio.h
*
+ * Base class for input stream implementations that perform some
+ * kind of filtering operation on a base stream. Typical examples
+ * of filtering operations are character set conversion, compression
+ * and byte order flipping.
**/
enum {
static gboolean g_filter_input_stream_close (GInputStream *stream,
GCancellable *cancellable,
GError **error);
-static void g_filter_input_stream_read_async (GInputStream *stream,
- void *buffer,
- gsize count,
- int io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-static gssize g_filter_input_stream_read_finish (GInputStream *stream,
- GAsyncResult *result,
- GError **error);
-static void g_filter_input_stream_skip_async (GInputStream *stream,
- gsize count,
- int io_priority,
- GCancellable *cancellabl,
- GAsyncReadyCallback callback,
- gpointer datae);
-static gssize g_filter_input_stream_skip_finish (GInputStream *stream,
- GAsyncResult *result,
- GError **error);
-static void g_filter_input_stream_close_async (GInputStream *stream,
- int io_priority,
- GCancellable *cancellabl,
- GAsyncReadyCallback callback,
- gpointer data);
-static gboolean g_filter_input_stream_close_finish (GInputStream *stream,
- GAsyncResult *result,
- GError **error);
-
-G_DEFINE_TYPE (GFilterInputStream, g_filter_input_stream, G_TYPE_INPUT_STREAM)
-
-#define GET_PRIVATE(inst) G_TYPE_INSTANCE_GET_PRIVATE (inst, \
- G_TYPE_FILTER_INPUT_STREAM, GFilterInputStreamPrivate)
typedef struct
{
gboolean close_base;
} GFilterInputStreamPrivate;
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GFilterInputStream, g_filter_input_stream, G_TYPE_INPUT_STREAM)
+
static void
g_filter_input_stream_class_init (GFilterInputStreamClass *klass)
{
istream_class->skip = g_filter_input_stream_skip;
istream_class->close_fn = g_filter_input_stream_close;
- istream_class->read_async = g_filter_input_stream_read_async;
- istream_class->read_finish = g_filter_input_stream_read_finish;
- istream_class->skip_async = g_filter_input_stream_skip_async;
- istream_class->skip_finish = g_filter_input_stream_skip_finish;
- istream_class->close_async = g_filter_input_stream_close_async;
- istream_class->close_finish = g_filter_input_stream_close_finish;
-
- g_type_class_add_private (klass, sizeof (GFilterInputStreamPrivate));
-
g_object_class_install_property (object_class,
PROP_BASE_STREAM,
g_param_spec_object ("base-stream",
g_param_spec_boolean ("close-base-stream",
P_("Close Base Stream"),
P_("If the base stream should be closed when the filter stream is closed."),
- TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+ TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
}
GParamSpec *pspec)
{
GFilterInputStream *filter_stream;
+ GFilterInputStreamPrivate *priv;
filter_stream = G_FILTER_INPUT_STREAM (object);
+ priv = g_filter_input_stream_get_instance_private (filter_stream);
switch (prop_id)
{
break;
case PROP_CLOSE_BASE:
- g_value_set_boolean (value, GET_PRIVATE (filter_stream)->close_base);
+ g_value_set_boolean (value, priv->close_base);
break;
default:
static void
g_filter_input_stream_init (GFilterInputStream *stream)
{
-
}
/**
*
* Gets the base stream for the filter stream.
*
- * Returns: a #GInputStream.
+ * Returns: (transfer none): a #GInputStream.
**/
GInputStream *
g_filter_input_stream_get_base_stream (GFilterInputStream *stream)
gboolean
g_filter_input_stream_get_close_base_stream (GFilterInputStream *stream)
{
+ GFilterInputStreamPrivate *priv;
+
g_return_val_if_fail (G_IS_FILTER_INPUT_STREAM (stream), FALSE);
- return GET_PRIVATE (stream)->close_base;
+ priv = g_filter_input_stream_get_instance_private (stream);
+
+ return priv->close_base;
}
/**
close_base = !!close_base;
- priv = GET_PRIVATE (stream);
+ priv = g_filter_input_stream_get_instance_private (stream);
if (priv->close_base != close_base)
{
GCancellable *cancellable,
GError **error)
{
+ GFilterInputStream *filter_stream = G_FILTER_INPUT_STREAM (stream);
+ GFilterInputStreamPrivate *priv = g_filter_input_stream_get_instance_private (filter_stream);
gboolean res = TRUE;
- if (GET_PRIVATE (stream)->close_base)
+ if (priv->close_base)
{
- GFilterInputStream *filter_stream;
- GInputStream *base_stream;
-
- filter_stream = G_FILTER_INPUT_STREAM (stream);
- base_stream = filter_stream->base_stream;
-
- res = g_input_stream_close (base_stream,
+ res = g_input_stream_close (filter_stream->base_stream,
cancellable,
error);
}
return res;
}
-
-static void
-g_filter_input_stream_read_async (GInputStream *stream,
- void *buffer,
- gsize count,
- int io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GFilterInputStream *filter_stream;
- GInputStream *base_stream;
-
- filter_stream = G_FILTER_INPUT_STREAM (stream);
- base_stream = filter_stream->base_stream;
-
- g_input_stream_read_async (base_stream,
- buffer,
- count,
- io_priority,
- cancellable,
- callback,
- user_data);
-}
-
-static gssize
-g_filter_input_stream_read_finish (GInputStream *stream,
- GAsyncResult *result,
- GError **error)
-{
- GFilterInputStream *filter_stream;
- GInputStream *base_stream;
- gssize nread;
-
- filter_stream = G_FILTER_INPUT_STREAM (stream);
- base_stream = filter_stream->base_stream;
-
- nread = g_input_stream_read_finish (base_stream,
- result,
- error);
-
- return nread;
-}
-
-static void
-g_filter_input_stream_skip_async (GInputStream *stream,
- gsize count,
- int io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GFilterInputStream *filter_stream;
- GInputStream *base_stream;
-
- filter_stream = G_FILTER_INPUT_STREAM (stream);
- base_stream = filter_stream->base_stream;
-
- g_input_stream_skip_async (base_stream,
- count,
- io_priority,
- cancellable,
- callback,
- user_data);
-
-}
-
-static gssize
-g_filter_input_stream_skip_finish (GInputStream *stream,
- GAsyncResult *result,
- GError **error)
-{
- GFilterInputStream *filter_stream;
- GInputStream *base_stream;
- gssize nskipped;
-
- filter_stream = G_FILTER_INPUT_STREAM (stream);
- base_stream = filter_stream->base_stream;
-
- nskipped = g_input_stream_skip_finish (base_stream,
- result,
- error);
-
- return nskipped;
-}
-
-static void
-g_filter_input_stream_close_ready (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
-{
- GSimpleAsyncResult *simple = user_data;
- GError *error = NULL;
-
- g_input_stream_close_finish (G_INPUT_STREAM (object), result, &error);
-
- if (error)
- {
- g_simple_async_result_set_from_error (simple, error);
- g_error_free (error);
- }
-
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
-}
-
-static void
-g_filter_input_stream_close_async (GInputStream *stream,
- int io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GSimpleAsyncResult *simple;
-
- simple = g_simple_async_result_new (G_OBJECT (stream),
- callback, user_data,
- g_filter_input_stream_close_async);
-
- if (GET_PRIVATE (stream)->close_base)
- {
- GFilterInputStream *filter_stream = G_FILTER_INPUT_STREAM (stream);
-
- g_input_stream_close_async (filter_stream->base_stream,
- io_priority, cancellable,
- g_filter_input_stream_close_ready,
- g_object_ref (simple));
- }
- else
- /* do nothing */
- g_simple_async_result_complete_in_idle (simple);
-
- g_object_unref (simple);
-}
-
-static gboolean
-g_filter_input_stream_close_finish (GInputStream *stream,
- GAsyncResult *result,
- GError **error)
-{
- GSimpleAsyncResult *simple;
-
- g_return_val_if_fail (g_simple_async_result_is_valid (
- result, G_OBJECT (stream), g_filter_input_stream_close_async), FALSE);
-
- simple = G_SIMPLE_ASYNC_RESULT (result);
-
- return !g_simple_async_result_propagate_error (simple, error);
-}
-
-#define __G_FILTER_INPUT_STREAM_C__
-#include "gioaliasdef.c"