[PATCH spice-gtk 4/6] Add function to return Spice channel type from string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 gtk/spice-channel.c | 40 +++++++++++++++++++++++++++-------------
 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
 
-- 
1.8.2.1.342.gfa7285d

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]