[virt-tools-list] [virt-viewer 4/8 v4] virt-viewer-app: create_session() should return a boolean

Fabiano Fidêncio fidencio at redhat.com
Fri Mar 27 16:21:54 UTC 2015


By convention functions that take GError parameters should return FALSE
(or NULL) or error.

Related: rhbz#1085216
---
 src/remote-viewer.c   |  6 +++---
 src/virt-viewer-app.c | 12 ++++++------
 src/virt-viewer-app.h |  2 +-
 src/virt-viewer.c     |  2 +-
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index 8a8bb9c..c870aba 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -950,7 +950,7 @@ create_ovirt_session(VirtViewerApp *app, const char *uri, GError **err)
     virt_viewer_app_set_connect_info(app, NULL, ghost, gport, gtlsport,
                                      session_type, NULL, NULL, 0, NULL);
 
-    if (virt_viewer_app_create_session(app, session_type, &error) < 0)
+    if (!virt_viewer_app_create_session(app, session_type, &error))
         goto error;
 
 #ifdef HAVE_SPICE_GTK
@@ -1221,7 +1221,7 @@ remote_viewer_start(VirtViewerApp *app, GError **err)
     g_signal_connect(app, "notify", G_CALLBACK(app_notified), self);
 
     if (priv->controller) {
-        if (virt_viewer_app_create_session(app, "spice", &error) < 0) {
+        if (!virt_viewer_app_create_session(app, "spice", &error)) {
             virt_viewer_app_simple_message_dialog(app, _("Couldn't create a Spice session"));
             goto cleanup;
         }
@@ -1283,7 +1283,7 @@ retry_dialog:
         } else
 #endif
         {
-            if (virt_viewer_app_create_session(app, type, &error) < 0)
+            if (!virt_viewer_app_create_session(app, type, &error))
                 goto cleanup;
         }
 
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 6b58cf6..e6a2ec0 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -1051,13 +1051,13 @@ static void notify_software_reader_cb(GObject    *gobject G_GNUC_UNUSED,
     virt_viewer_update_smartcard_accels(VIRT_VIEWER_APP(user_data));
 }
 
-int
+gboolean
 virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type, GError **error)
 {
-    g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), -1);
+    g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE);
     VirtViewerAppPrivate *priv = self->priv;
-    g_return_val_if_fail(priv->session == NULL, -1);
-    g_return_val_if_fail(type != NULL, -1);
+    g_return_val_if_fail(priv->session == NULL, FALSE);
+    g_return_val_if_fail(type != NULL, FALSE);
 
 #ifdef HAVE_GTK_VNC
     if (g_ascii_strcasecmp(type, "vnc") == 0) {
@@ -1084,7 +1084,7 @@ virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type, GError **
                               priv->guest_name, type);
         virt_viewer_app_simple_message_dialog(self, _("Unknown graphic type for the guest %s"),
                                               priv->guest_name);
-        return -1;
+        return FALSE;
     }
 
     g_signal_connect(priv->session, "session-initialized",
@@ -1119,7 +1119,7 @@ virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type, GError **
 
     g_signal_connect(priv->session, "notify::software-smartcard-reader",
                      (GCallback)notify_software_reader_cb, self);
-    return 0;
+    return TRUE;
 }
 
 static gboolean
diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
index 8c1268d..6af9c01 100644
--- a/src/virt-viewer-app.h
+++ b/src/virt-viewer-app.h
@@ -68,7 +68,7 @@ void virt_viewer_app_trace(VirtViewerApp *self, const char *fmt, ...);
 void virt_viewer_app_simple_message_dialog(VirtViewerApp *self, const char *fmt, ...);
 gboolean virt_viewer_app_is_active(VirtViewerApp *app);
 void virt_viewer_app_free_connect_info(VirtViewerApp *self);
-int virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type, GError **error);
+gboolean virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type, GError **error);
 gboolean virt_viewer_app_activate(VirtViewerApp *self, GError **error);
 gboolean virt_viewer_app_initial_connect(VirtViewerApp *self, GError **error);
 void virt_viewer_app_set_zoom_level(VirtViewerApp *self, gint zoom_level);
diff --git a/src/virt-viewer.c b/src/virt-viewer.c
index cba38e4..5cef139 100644
--- a/src/virt-viewer.c
+++ b/src/virt-viewer.c
@@ -420,7 +420,7 @@ virt_viewer_extract_connect_info(VirtViewer *self,
         goto cleanup;
     }
 
-    if (virt_viewer_app_create_session(app, type, error) < 0)
+    if (!virt_viewer_app_create_session(app, type, error))
         goto cleanup;
 
     xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s' v4]/@port)", type);
-- 
2.3.3




More information about the virt-tools-list mailing list