diff options
author | Mike Ruprecht <cmaiku@gmail.com> | 2016-04-29 02:03:24 -0500 |
---|---|---|
committer | Mike Ruprecht <cmaiku@gmail.com> | 2016-04-29 02:03:24 -0500 |
commit | 968dfab53fcaa95782121229b90cb1136a0fcbe3 (patch) | |
tree | b065e5ac57b8af2c6d21e9ce0b642f03c5b7ac27 /libpurple/queuedoutputstream.h | |
parent | 67df26bcaad99b64bd7ee350d45963bc06e69a93 (diff) | |
download | pidgin-968dfab53fcaa95782121229b90cb1136a0fcbe3.tar.gz |
libpurple: Add PurpleQueuedOutputStream for fire and forget output
This patch adds a queued GOutputStream implementation to allow
queuing data to send even if a stream operation is in progress.
This could potentially be upstreamed to Gio with some
cleanup/reformatting.
Diffstat (limited to 'libpurple/queuedoutputstream.h')
-rw-r--r-- | libpurple/queuedoutputstream.h | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/libpurple/queuedoutputstream.h b/libpurple/queuedoutputstream.h new file mode 100644 index 0000000000..80888ed2fc --- /dev/null +++ b/libpurple/queuedoutputstream.h @@ -0,0 +1,109 @@ +/* + * + * purple + * + * Purple is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + */ + +#ifndef _PURPLE_QUEUED_OUTPUT_STREAM_H +#define _PURPLE_QUEUED_OUTPUT_STREAM_H +/** + * SECTION:queued-output-stream + * @section_id: libpurple-queued-output-stream + * @short_description: GOutputStream for queuing data to output + * @title: GOutputStream class + * + * A #GQueuedOutputStream is a #GOutputStream which allows data to be queued + * for outputting. It differs from a #GBufferedOutputStream in that it allows + * for data to be queued while other operations are in progress. + */ + +#include <gio/gio.h> + +G_BEGIN_DECLS + +#define PURPLE_TYPE_QUEUED_OUTPUT_STREAM (purple_queued_output_stream_get_type()) +#define PURPLE_QUEUED_OUTPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_CAST((o), PURPLE_TYPE_QUEUED_OUTPUT_STREAM, PurpleQueuedOutputStream)) +#define PURPLE_QUEUED_OUTPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PURPLE_TYPE_QUEUED_OUTPUT_STREAM, GQueuedOutputStreamClass)) +#define PURPLE_IS_QUEUED_OUTPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), PURPLE_TYPE_QUEUED_OUTPUT_STREAM) +#define PURPLE_IS_QUEUED_OUTPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), PURPLE_TYPE_QUEUED_OUTPUT_STREAM)) +#define PURPLE_IS_QUEUED_OUTPUT_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), PURPLE_TYPE_UEUED_OUTPUT_STREAM, GQueuedOutputStreamClass)) + +/** + * PurpleQueuedOutputStream: + * + * An implementation of #GFilterOutputStream which allows queuing data for + * output. This allows data to be queued while other data is being output. + * Therefore, data doesn't have to be manually stored while waiting for + * stream operations to finish. + * + * To create a queued output stream, use #purple_queued_output_stream_new(). + * + * To queue data, use #purple_queued_output_stream_push_bytes(). + * + * Once data has been queued, flush the stream with #g_output_stream_flush() + * or #g_output_stream_flush_async(). + */ +typedef struct _PurpleQueuedOutputStream PurpleQueuedOutputStream; +typedef struct _PurpleQueuedOutputStreamClass PurpleQueuedOutputStreamClass; +typedef struct _PurpleQueuedOutputStreamPrivate PurpleQueuedOutputStreamPrivate; + +struct _PurpleQueuedOutputStream +{ + GFilterOutputStream parent_instance; + + /*< protected >*/ + PurpleQueuedOutputStreamPrivate *priv; +}; + +struct _PurpleQueuedOutputStreamClass +{ + GFilterOutputStreamClass parent_class; + + /*< private >*/ + /* Padding for future expansion */ + void (*_g_reserved1)(void); + void (*_g_reserved2)(void); +}; + +GType purple_queued_output_stream_get_type(void) G_GNUC_CONST; + +/* + * purple_queued_output_stream_new + * @base_stream: Base output stream to wrap with the queued stream + * + * Creates a new queued output stream for a base stream. + */ +PurpleQueuedOutputStream *purple_queued_output_stream_new( + GOutputStream *base_stream); + +/* + * purple_queued_output_stream_push_bytes + * @stream: Stream to push bytes to + * @bytes: Bytes to queue + * + * Queues data to be output through the stream. Flush the stream to + * output this data. + */ +void purple_queued_output_stream_push_bytes(PurpleQueuedOutputStream *stream, + GBytes *bytes); + +G_END_DECLS + +#endif /* _PURPLE_QUEUED_OUTPUT_STREAM_H */ |