[Spice-devel] [PATCH v2 2/3] Cmdline: Get the preferred-compression property

Javier Celaya javier.celaya at flexvm.es
Mon Apr 27 01:04:35 PDT 2015


---
 gtk/spice-cmdline.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/gtk/spice-cmdline.c b/gtk/spice-cmdline.c
index 8619b57..c52b1a2 100644
--- a/gtk/spice-cmdline.c
+++ b/gtk/spice-cmdline.c
@@ -27,6 +27,39 @@ static char *port;
 static char *tls_port;
 static char *password;
 static char *uri;
+static int preferred_compression;
+
+GQuark spice_cmdline_error_quark(void)
+{
+    return g_quark_from_static_string("spice-cmdline-error");
+}
+
+static gboolean parse_preferred_compression(const gchar *option_name, const gchar *value,
+                                            gpointer data, GError **error) {
+    if (!strcmp(value, "auto-glz")) {
+        preferred_compression = SPICE_IMAGE_COMPRESS_AUTO_GLZ;
+    } else if (!strcmp(value, "auto-lz")) {
+        preferred_compression = SPICE_IMAGE_COMPRESS_AUTO_LZ;
+    } else if (!strcmp(value, "quic")) {
+        preferred_compression = SPICE_IMAGE_COMPRESS_QUIC;
+    } else if (!strcmp(value, "glz")) {
+        preferred_compression = SPICE_IMAGE_COMPRESS_GLZ;
+    } else if (!strcmp(value, "lz")) {
+        preferred_compression = SPICE_IMAGE_COMPRESS_LZ;
+#ifdef USE_LZ4
+    } else if (!strcmp(value, "lz4")) {
+        preferred_compression = SPICE_IMAGE_COMPRESS_LZ4;
+#endif
+    } else if (!strcmp(value, "off")) {
+        preferred_compression = SPICE_IMAGE_COMPRESS_OFF;
+    } else {
+        preferred_compression = SPICE_IMAGE_COMPRESS_INVALID;
+        g_set_error(error, spice_cmdline_error_quark(), G_OPTION_ERROR_FAILED,
+                    _("Image compression algorithm %s not supported"), value);
+        return FALSE;
+    }
+    return TRUE;
+}
 
 static GOptionEntry spice_entries[] = {
     {
@@ -64,6 +97,17 @@ static GOptionEntry spice_entries[] = {
         .description      = N_("Server password"),
         .arg_description  = N_("<password>"),
     },{
+        .long_name        = "preferred-compression",
+        .short_name       = 'c',
+        .arg              = G_OPTION_ARG_CALLBACK,
+        .arg_data         = parse_preferred_compression,
+        .description      = N_("Preferred image compression algorithm"),
+#ifdef USE_LZ4
+        .arg_description  = N_("<auto-glz|auto-lz|quic|glz|lz|lz4|off>"),
+#else
+        .arg_description  = N_("<auto-glz|auto-lz|quic|glz|lz|off>"),
+#endif
+    },{
         /* end of list */
     }
 };
@@ -72,6 +116,8 @@ GOptionGroup *spice_cmdline_get_option_group(void)
 {
     GOptionGroup *grp;
 
+    preferred_compression = SPICE_IMAGE_COMPRESS_INVALID;
+
     grp = g_option_group_new("spice",
                              _("Spice connection options:"),
                              _("Show Spice options"),
@@ -95,4 +141,6 @@ void spice_cmdline_session_setup(SpiceSession *session)
         g_object_set(session, "tls-port", tls_port, NULL);
     if (password)
         g_object_set(session, "password", password, NULL);
+    if (preferred_compression != SPICE_IMAGE_COMPRESS_INVALID)
+        g_object_set(session, "preferred-compression", preferred_compression, NULL);
 }
-- 
1.9.3



More information about the Spice-devel mailing list