On Thu, Mar 02, 2017 at 12:30:25PM +0000, Frediano Ziglio wrote: > Add function to initialize and destroy this type. > Add GType type for boxing it. > These changes a in preparation for next patch. > > Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> > --- > server/Makefile.am | 2 ++ > server/red-channel-capabilities.c | 68 +++++++++++++++++++++++++++++++++++++++ > server/red-channel-capabilities.h | 51 +++++++++++++++++++++++++++++ > server/red-channel.h | 8 +---- > 4 files changed, 122 insertions(+), 7 deletions(-) > create mode 100644 server/red-channel-capabilities.c > create mode 100644 server/red-channel-capabilities.h > > diff --git a/server/Makefile.am b/server/Makefile.am > index a043660..49c0822 100644 > --- a/server/Makefile.am > +++ b/server/Makefile.am > @@ -101,6 +101,8 @@ libserver_la_SOURCES = \ > red-channel.h \ > red-channel-client.c \ > red-channel-client.h \ > + red-channel-capabilities.c \ > + red-channel-capabilities.h \ > red-client.c \ > red-client.h \ > red-common.h \ > diff --git a/server/red-channel-capabilities.c b/server/red-channel-capabilities.c > new file mode 100644 > index 0000000..eacb338 > --- /dev/null > +++ b/server/red-channel-capabilities.c > @@ -0,0 +1,68 @@ > +/* > + Copyright (C) 2017 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/>. > +*/ > +#ifdef HAVE_CONFIG_H > +#include <config.h> > +#endif > + > +#include <string.h> > +#include <common/mem.h> > +#include <common/macros.h> > + > +#include "red-channel-capabilities.h" > + > +GType red_channel_capabilities_type; > + > +void red_channel_capabilities_init(RedChannelCapabilities *dest, > + const RedChannelCapabilities *caps) > +{ > + *dest = *caps; > + if (caps->common_caps) { > + dest->common_caps = spice_memdup(caps->common_caps, > + caps->num_common_caps * sizeof(uint32_t)); > + } > + if (caps->num_caps) { > + dest->caps = spice_memdup(caps->caps, caps->num_caps * sizeof(uint32_t)); > + } > +} > + > +void red_channel_capabilities_reset(RedChannelCapabilities *caps) > +{ > + free(caps->common_caps); > + free(caps->caps); > + memset(caps, 0, sizeof(*caps)); > +} > + > +static RedChannelCapabilities *red_channel_capabilities_dup(const RedChannelCapabilities *caps) > +{ > + RedChannelCapabilities *res = spice_new(RedChannelCapabilities, 1); > + red_channel_capabilities_init(res, caps); > + return res; > +} > + > +static void red_channel_capabilities_free(RedChannelCapabilities *caps) > +{ > + red_channel_capabilities_reset(caps); > + free(caps); > +} > + > +SPICE_CONSTRUCTOR_FUNC(red_channel_capabilities_construct) > +{ > + red_channel_capabilities_type = > + g_boxed_type_register_static("red_channel_capabilities_type", Nit as well, but "RedChannelCapabilities"? Or you prefer to keep the same name as the GType variable that you use? > + (GBoxedCopyFunc) red_channel_capabilities_dup, > + (GBoxedFreeFunc) red_channel_capabilities_free); > +} > diff --git a/server/red-channel-capabilities.h b/server/red-channel-capabilities.h > new file mode 100644 > index 0000000..299409d > --- /dev/null > +++ b/server/red-channel-capabilities.h > @@ -0,0 +1,51 @@ > +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ > +/* > + Copyright (C) 2009-2017 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/>. > +*/ > + > +#ifndef RED_CHANNEL_CAPABILITIES_H_ > +#define RED_CHANNEL_CAPABILITIES_H_ > + > +#include <stdint.h> > +#include <glib-object.h> > + > +G_BEGIN_DECLS > + > +/* Holds channel capabilities. > + * Channel capabilities are composed by a common part > + * and a specific one. */ > +typedef struct RedChannelCapabilities { > + int num_common_caps; > + uint32_t *common_caps; > + int num_caps; > + uint32_t *caps; > +} RedChannelCapabilities; > + > +/* Initialize the structure based on a previous one. */ > +void red_channel_capabilities_init(RedChannelCapabilities *dest, > + const RedChannelCapabilities *caps); > + > +/* Reset capabilities. > + * All resources are freed by this function. */ > +void red_channel_capabilities_reset(RedChannelCapabilities *caps); > + > +/* GObject type that can be used to box RedChannelCapabilities */ > +extern GType red_channel_capabilities_type; > +#define TYPE_RED_CHANNEL_CAPABILITIES red_channel_capabilities_type RED_TYPE_CHANNEL_CAPABILITIES, similarly to RED_TYPE_CHANNEL, RED_TYPE_CHANNEL_CLIENT, ... Acked-by: Christophe Fergeau <cfergeau@xxxxxxxxxx> Christophe
Attachment:
signature.asc
Description: PGP signature
_______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel