Avoids registering type just to get the nick of an enum value

We don't use anymore GObject parameters so avoid having to
register enum values to GType system to use them.
We just need to get the nick value of the enum values for
debug purposes.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
Frediano Ziglio 2020-03-10 08:23:14 +00:00 committed by Frediano Ziglio
parent fd06625ba1
commit 31f0ce2086
4 changed files with 36 additions and 35 deletions

View File

@ -965,8 +965,7 @@ static bool dcc_handle_preferred_compression(DisplayChannelClient *dcc,
spice_warning("preferred-compression: unsupported image compression setting");
}
g_debug("Setting preferred compression to %s",
spice_genum_get_nick(SPICE_TYPE_SPICE_IMAGE_COMPRESSION_T,
dcc->priv->image_compression));
spice_image_compression_t_get_nick(dcc->priv->image_compression));
return TRUE;
}

View File

@ -38,9 +38,11 @@ install_headers(spice_server_headers, subdir : 'spice-server')
# generate enums
gnome = import('gnome')
spice_server_enums = gnome.mkenums_simple('spice-server-enums',
sources : 'spice-server.h',
symbol_prefix : 'SPICE')
spice_server_enums = gnome.mkenums('spice-server-enums',
sources : 'spice-server.h',
symbol_prefix : 'SPICE',
c_template: 'spice-server-enums.c.tmpl',
h_template: 'spice-server-enums.h.tmpl')
spice_server_sources = [
spice_server_headers,

View File

@ -1,37 +1,40 @@
/*** BEGIN file-header ***/
#include <config.h>
#include <glib-object.h>
#include "spice-server-enums.h"
#include "spice-server.h"
typedef struct EnumValues {
int value;
const char *nick;
} EnumValues;
static const char *
enum_values_get_nick(int value, const EnumValues *e)
{
for (; e->nick; e++) {
if (e->value == value) {
return e->nick;
}
}
return "???";
}
/*** END file-header ***/
/*** BEGIN value-header ***/
static const G@Type@Value _@enum_name@_values[] = {
const char *@EnumName@_get_nick(@EnumName@ value)
{
static const struct EnumValues @EnumName@_values[] = {
/*** END value-header ***/
/*** BEGIN value-production ***/
{ @VALUENAME@, "@VALUENAME@", "@valuenick@" },
{ @VALUENAME@, "@valuenick@" },
/*** END value-production ***/
/*** BEGIN value-tail ***/
{ 0, NULL, NULL }
};
GType
@enum_name@_get_type (void)
{
static GType type = 0;
static volatile gsize type_volatile = 0;
if (g_once_init_enter(&type_volatile)) {
type = g_@type@_register_static ("@EnumName@", _@enum_name@_values);
g_once_init_leave(&type_volatile, type);
}
return type;
{ 0, NULL, }
};
return enum_values_get_nick(value, @EnumName@_values);
}
/*** END value-tail ***/

View File

@ -1,19 +1,16 @@
/*** BEGIN file-header ***/
#ifndef SPICE_SERVER_ENUMS_H
#define SPICE_SERVER_ENUMS_H
#pragma once
G_BEGIN_DECLS
#include "spice.h"
SPICE_BEGIN_DECLS
/*** END file-header ***/
/*** BEGIN enumeration-production ***/
#define SPICE_TYPE_@ENUMSHORT@ @enum_name@_get_type()
GType @enum_name@_get_type (void);
const char *@EnumName@_get_nick(@EnumName@ value);
/*** END enumeration-production ***/
/*** BEGIN file-tail ***/
G_END_DECLS
#endif /* SPICE_SERVER_ENUMS_H */
SPICE_END_DECLS
/*** END file-tail ***/