[Spice-devel] [PATCH spice-gtk] Add SpiceVMC GIOStream
Marc-André Lureau
marcandre.lureau at gmail.com
Mon Feb 17 13:08:52 PST 2014
On Wed, Feb 12, 2014 at 1:57 PM, Christophe Fergeau <cfergeau at redhat.com> wrote:
> On Tue, Feb 11, 2014 at 06:52:49PM +0100, Marc-André Lureau wrote:
>> This allows to use conveniently GIOStream APIs without caring about
>> coroutine and Spice messages details.
>> ---
>> gtk/Makefile.am | 2 +
>> gtk/vmcstream.c | 532 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> gtk/vmcstream.h | 81 +++++++++
>> 3 files changed, 615 insertions(+)
>> create mode 100644 gtk/vmcstream.c
>> create mode 100644 gtk/vmcstream.h
>>
>> diff --git a/gtk/Makefile.am b/gtk/Makefile.am
>> index 62afd36..7ceb22f 100644
>> --- a/gtk/Makefile.am
>> +++ b/gtk/Makefile.am
>> @@ -255,6 +255,8 @@ libspice_client_glib_2_0_la_SOURCES = \
>> usbutil.c \
>> usbutil.h \
>> $(USB_ACL_HELPER_SRCS) \
>> + vmcstream.c \
>> + vmcstream.h \
>> \
>> decode.h \
>> decode-glz.c \
>> diff --git a/gtk/vmcstream.c b/gtk/vmcstream.c
>> new file mode 100644
>> index 0000000..f92f8b7
>> --- /dev/null
>> +++ b/gtk/vmcstream.c
>> @@ -0,0 +1,532 @@
>> +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
>> +/*
>> + Copyright (C) 2013 Red Hat, Inc.
>> +
>> + This library 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 2.1 of the License, or (at your option) any later version.
>> +
>> + This library 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 library; if not, see <http://www.gnu.org/licenses/>.
>> +*/
>> +#include <string.h>
>> +
>> +#include "vmcstream.h"
>> +#include "spice-channel-priv.h"
>> +#include "gio-coroutine.h"
>> +
>> +struct _SpiceVmcInputStream
>> +{
>> + GInputStream parent_instance;
>> + GSimpleAsyncResult *result;
>> + struct coroutine *coroutine;
>> +
>> + SpiceChannel *channel;
>> + gboolean all;
>> + guint8 *buffer;
>> + gsize count;
>> + gsize pos;
>> +
>> + GCancellable *cancellable;
>> + gulong cancel_id;
>> +};
>> +
>> +struct _SpiceVmcInputStreamClass
>> +{
>> + GInputStreamClass parent_class;
>> +};
>> +
>> +static gssize spice_vmc_input_stream_read (GInputStream *stream,
>> + void *buffer,
>> + gsize count,
>> + GCancellable *cancellable,
>> + GError **error);
>> +static void spice_vmc_input_stream_read_async (GInputStream *stream,
>> + void *buffer,
>> + gsize count,
>> + int io_priority,
>> + GCancellable *cancellable,
>> + GAsyncReadyCallback callback,
>> + gpointer user_data);
>> +static gssize spice_vmc_input_stream_read_finish (GInputStream *stream,
>> + GAsyncResult *result,
>> + GError **error);
>> +static gssize spice_vmc_input_stream_skip (GInputStream *stream,
>> + gsize count,
>> + GCancellable *cancellable,
>> + GError **error);
>> +static gboolean spice_vmc_input_stream_close (GInputStream *stream,
>> + GCancellable *cancellable,
>> + GError **error);
>> +
>> +G_DEFINE_TYPE(SpiceVmcInputStream, spice_vmc_input_stream, G_TYPE_INPUT_STREAM)
>> +
>> +
>> +static void
>> +spice_vmc_input_stream_class_init(SpiceVmcInputStreamClass *klass)
>> +{
>> + GInputStreamClass *istream_class;
>> +
>> + istream_class = G_INPUT_STREAM_CLASS(klass);
>> + istream_class->read_fn = spice_vmc_input_stream_read;
>> + istream_class->read_async = spice_vmc_input_stream_read_async;
>> + istream_class->read_finish = spice_vmc_input_stream_read_finish;
>> + istream_class->skip = spice_vmc_input_stream_skip;
>> + istream_class->close_fn = spice_vmc_input_stream_close;
>> +}
>> +
>> +static void
>> +spice_vmc_input_stream_init(SpiceVmcInputStream *self)
>> +{
>> +}
>> +
>> +static SpiceVmcInputStream *
>> +spice_vmc_input_stream_new(void)
>> +{
>> + SpiceVmcInputStream *self;
>> +
>> + self = g_object_new(SPICE_TYPE_VMC_INPUT_STREAM, NULL);
>> +
>> + return self;
>> +}
>> +
>> +/* coroutine */
>> +/**
>> + * Feed a SpiceVmc stream with new data from a coroutine
>> + *
>> + * The other end will be waiting on read_async() until data is fed
>> + * here.
>> + */
>> +G_GNUC_INTERNAL void
>
> Nit: Use of G_GNUC_INTERNAL is inconsistent in this file, you may want to
> change that before pushing. ACK either way.
ack, I modified internal functions declaration.
> Christophe
--
Marc-André Lureau
More information about the Spice-devel
mailing list