diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2013-04-11 14:58:03 +0200 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2013-04-11 14:58:03 +0200 |
commit | b1fcae0a0f2df3603f10f8b71e8d5cad954a1d0c (patch) | |
tree | abab3a218b15246749811c00d0ab041c50fa8147 | |
parent | 5bda83f9505aa2f9f063206c9a813b1285203a73 (diff) |
Add function to return Spice channel type from string
-rw-r--r-- | gtk/spice-channel.c | 40 | ||||
-rw-r--r-- | gtk/spice-channel.h | 1 |
2 files changed, 28 insertions, 13 deletions
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c index 10ed892..b9ce899 100644 --- a/gtk/spice-channel.c +++ b/gtk/spice-channel.c @@ -1870,21 +1870,22 @@ end: spice_msg_in_unref(in); } +static const char *to_string[] = { + NULL, + [ SPICE_CHANNEL_MAIN ] = "main", + [ SPICE_CHANNEL_DISPLAY ] = "display", + [ SPICE_CHANNEL_INPUTS ] = "inputs", + [ SPICE_CHANNEL_CURSOR ] = "cursor", + [ SPICE_CHANNEL_PLAYBACK ] = "playback", + [ SPICE_CHANNEL_RECORD ] = "record", + [ SPICE_CHANNEL_TUNNEL ] = "tunnel", + [ SPICE_CHANNEL_SMARTCARD ] = "smartcard", + [ SPICE_CHANNEL_USBREDIR ] = "usbredir", + [ SPICE_CHANNEL_PORT ] = "port", +}; + const gchar* spice_channel_type_to_string(gint type) { - static const char *to_string[] = { - NULL, - [ SPICE_CHANNEL_MAIN ] = "main", - [ SPICE_CHANNEL_DISPLAY ] = "display", - [ SPICE_CHANNEL_INPUTS ] = "inputs", - [ SPICE_CHANNEL_CURSOR ] = "cursor", - [ SPICE_CHANNEL_PLAYBACK ] = "playback", - [ SPICE_CHANNEL_RECORD ] = "record", - [ SPICE_CHANNEL_TUNNEL ] = "tunnel", - [ SPICE_CHANNEL_SMARTCARD ] = "smartcard", - [ SPICE_CHANNEL_USBREDIR ] = "usbredir", - [ SPICE_CHANNEL_PORT ] = "port", - }; const char *str = NULL; if (type >= 0 && type < G_N_ELEMENTS(to_string)) { @@ -1894,6 +1895,19 @@ const gchar* spice_channel_type_to_string(gint type) return str ? str : "unknown channel type"; } +gint spice_channel_string_to_type(const gchar *str) +{ + int i; + + g_return_val_if_fail(str != NULL, -1); + + for (i = 0; i < G_N_ELEMENTS(to_string); i++) + if (g_strcmp0(str, to_string[i]) == 0) + return i; + + return -1; +} + G_GNUC_INTERNAL gchar *spice_channel_supported_string(void) { diff --git a/gtk/spice-channel.h b/gtk/spice-channel.h index 4b2af33..0507b68 100644 --- a/gtk/spice-channel.h +++ b/gtk/spice-channel.h @@ -120,6 +120,7 @@ void spice_channel_set_capability(SpiceChannel *channel, guint32 cap); #endif const gchar* spice_channel_type_to_string(gint type); +gint spice_channel_string_to_type(const gchar *str); G_END_DECLS |