Re: [gtk-vnc-devel] disconnect signal



On Thu, Sep 13, 2007 at 10:47:21AM -0500, Anthony Liguori wrote:
> >   
> >> One thing I do want to add though is a 'error' signal which would be emitted
> >> whenever anything goes wrong in the client (ie anywhere the code which sets
> >> the has_error flag to TRUE). In particular this signal would include some
> >> kind of info about what failed - perhaps just the 'strerror(errno)' data or
> >> a message generated by our own code for some semantic error eg "Unsupported
> >> protocol version", or "Supported authentiction method", or 'Remote server
> >> closed connection". Would a general 'error' signal solve the issue you want
> >> to address ?  The 'error' signal would of course be immediately followed by
> >> the 'disconnected' signal too. 
> >>
> >> Dan.
> >>     
> >
> > Indeed again, but, in this case, the 'disconnected' signal is useless in
> > my opinion.
> >   
> 
> I agree with Dan.  I think simpler semantics is always better.  
> Disconnected doesn't necessarily mean error.
> 
> > I was about to ask for a 'auth error' signal, but this 'error' signal is
> > more generic and i think it solves my problems.
> >   
> 
> I don't much like the idea of an "error" signal.  It means that you end 
> up with a catch-all handler.
> 
> You definitely want a separate authentication-error signal.  For the 
> case where the server prematurely closes the connection, and 
> unexpected-end-of-file signal or something similar would be useful.  
> Note that an unexpected EOF is not the same as disconnected.

I looked at this and there is not currently any easy way to distinguish
between a regular shutdown (from vnc_display_close/gvnc_close) and an
unplanned shutdown (remote server closes / protocol error), so I've not
addressed this. 

The attached patch does however add a 'vnc-auth-failure' signal so you
can explicitly handle that common scenario. It also adds a vnc-desktop-resize
signal that Gerd previously requested.

So as not to delay the release further I'd say we go with this for now and
I'll investigate if there's a way to add separate useful signals for detecting
more interesting shutdown / error conditions.

Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
diff -r 381f8531daab examples/gvncviewer.c
--- a/examples/gvncviewer.c	Mon Sep 10 14:37:17 2007 -0400
+++ b/examples/gvncviewer.c	Thu Sep 13 14:06:46 2007 -0400
@@ -58,6 +58,16 @@ static void vnc_initialized(GtkWidget *v
 	printf("Connection initialized\n");
 	set_title(VNC_DISPLAY(vnc), window, FALSE);
 	gtk_widget_show_all(window);
+}
+
+static void vnc_auth_failure(GtkWidget *vnc, const char *msg)
+{
+	printf("Authentication failed '%s'\n", msg ? msg : "");
+}
+
+static void vnc_desktop_resize(GtkWidget *vnc, int width, int height)
+{
+	printf("Remote desktop size changed to %dx%d\n", width, height);
 }
 
 static void vnc_disconnected(GtkWidget *vnc G_GNUC_UNUSED)
@@ -271,8 +281,13 @@ int main(int argc, char **argv)
 			   GTK_SIGNAL_FUNC(vnc_initialized), window);
 	gtk_signal_connect(GTK_OBJECT(vnc), "vnc-disconnected",
 			   GTK_SIGNAL_FUNC(vnc_disconnected), NULL);
-	g_signal_connect(GTK_OBJECT(vnc), "vnc-auth-credential",
+	gtk_signal_connect(GTK_OBJECT(vnc), "vnc-auth-credential",
 			   GTK_SIGNAL_FUNC(vnc_credential), NULL);
+	gtk_signal_connect(GTK_OBJECT(vnc), "vnc-auth-failure",
+			   GTK_SIGNAL_FUNC(vnc_auth_failure), NULL);
+
+	gtk_signal_connect(GTK_OBJECT(vnc), "vnc-desktop-resize",
+			   GTK_SIGNAL_FUNC(vnc_desktop_resize), NULL);
 
 	gtk_signal_connect(GTK_OBJECT(vnc), "vnc-pointer-grab",
 			   GTK_SIGNAL_FUNC(vnc_grab), window);
diff -r 381f8531daab src/Makefile.am
--- a/src/Makefile.am	Mon Sep 10 14:37:17 2007 -0400
+++ b/src/Makefile.am	Thu Sep 13 14:09:24 2007 -0400
@@ -1,5 +1,5 @@
 
-EXTRA_DIST = libgtk-vnc_sym.version
+EXTRA_DIST = libgtk-vnc_sym.version vncmarshal.txt
 
 lib_LTLIBRARIES = libgtk-vnc-1.0.la
 
@@ -20,7 +20,18 @@ libgtk_vnc_1_0_la_SOURCES = blt.h blt1.h
 	gvnc.h gvnc.c \
 	vncdisplay.h vncdisplay.c \
 	vncshmimage.h vncshmimage.c \
+        vncmarshal.h vncmarshal.c \
 	utils.h
+
+vncmarshal.c: vncmarshal.txt
+	glib-genmarshal --body $< > $@ || (rm -f $@ && exit 1)
+
+vncmarshal.h: vncmarshal.txt
+	glib-genmarshal --header $< > $@ || (rm -f $@ && exit 1)
+
+vncdisplay.c:: vncmarshal.h
+
+CLEANFILES = vncmarshal.c vncmarshal.h
 
 if WITH_PYTHON
 pyexec_LTLIBRARIES = gtkvnc.la
@@ -44,7 +55,7 @@ vncmodule.defs.c: vnc.override vnc.defs
                           --register $(DEFSDIR)/gtk-types.defs \
                           --override $(srcdir)/vnc.override vnc.defs > $@
 
-CLEANFILES = vnc.defs
+CLEANFILES += vnc.defs vncmodule.defs.c
 EXTRA_DIST += vnc.override
 
 else
diff -r 381f8531daab src/gvnc.c
--- a/src/gvnc.c	Mon Sep 10 14:37:17 2007 -0400
+++ b/src/gvnc.c	Thu Sep 13 12:58:22 2007 -0400
@@ -1326,8 +1326,12 @@ static gboolean gvnc_check_auth_result(s
 		gvnc_read(gvnc, reason, len);
 		reason[len] = '\0';
 		GVNC_DEBUG("Fail %s\n", reason);
+		if (!gvnc->has_error && gvnc->ops.auth_failure)
+			gvnc->ops.auth_failure(gvnc->ops_data, reason);
 	} else {
 		GVNC_DEBUG("Fail\n");
+		if (!gvnc->has_error && gvnc->ops.auth_failure)
+			gvnc->ops.auth_failure(gvnc->ops_data, NULL);
 	}
 	return FALSE;
 }
diff -r 381f8531daab src/gvnc.h
--- a/src/gvnc.h	Mon Sep 10 14:37:17 2007 -0400
+++ b/src/gvnc.h	Thu Sep 13 12:56:11 2007 -0400
@@ -11,6 +11,7 @@ struct gvnc_ops
 	gboolean (*auth_cred)(void *);
 	gboolean (*auth_type)(void *, unsigned int, unsigned int *);
 	gboolean (*auth_subtype)(void *, unsigned int, unsigned int *);
+	gboolean (*auth_failure)(void *, const char *);
 	gboolean (*update)(void *, int, int, int, int);
 	gboolean (*set_color_map_entry)(void *, int, int, int, int);
 	gboolean (*bell)(void *);
diff -r 381f8531daab src/vncdisplay.c
--- a/src/vncdisplay.c	Mon Sep 10 14:37:17 2007 -0400
+++ b/src/vncdisplay.c	Thu Sep 13 14:07:49 2007 -0400
@@ -13,6 +13,7 @@
 #include "gvnc.h"
 #include "vncshmimage.h"
 #include "utils.h"
+#include "vncmarshal.h"
 
 #include <gtk/gtk.h>
 #include <string.h>
@@ -72,11 +73,16 @@ typedef enum
 	VNC_DISCONNECTED,
  	VNC_AUTH_CREDENTIAL,
 
+	VNC_DESKTOP_RESIZE,
+
+	VNC_AUTH_FAILURE,
+
 	LAST_SIGNAL
 } vnc_display_signals;
 
 static guint signals[LAST_SIGNAL] = { 0, 0, 0, 0,
-				      0, 0, 0, 0 };
+				      0, 0, 0, 0,
+				      0, 0, };
 static GParamSpec *signalCredParam;
 
 GtkWidget *vnc_display_new(void)
@@ -480,6 +486,11 @@ static gboolean on_resize(void *opaque, 
 
 	gvnc_set_local(priv->gvnc, &priv->fb);
 
+	g_signal_emit (G_OBJECT (obj),
+		       signals[VNC_DESKTOP_RESIZE],
+		       0,
+		       width, height);
+
 	return TRUE;
 }
 
@@ -575,6 +586,18 @@ static gboolean on_auth_subtype(void *op
 	 */
 	if (ntype)
 		gvnc_set_auth_subtype(priv->gvnc, types[0]);
+
+	return TRUE;
+}
+
+static gboolean on_auth_failure(void *opaque, const char *msg)
+{
+	VncDisplay *obj = VNC_DISPLAY(opaque);
+
+	g_signal_emit (G_OBJECT (obj),
+		       signals[VNC_AUTH_FAILURE],
+		       0,
+		       msg);
 
 	return TRUE;
 }
@@ -610,11 +633,11 @@ static gboolean on_local_cursor(void *op
 	return TRUE;
 }
 
-
 static const struct gvnc_ops vnc_display_ops = {
 	.auth_cred = on_auth_cred,
 	.auth_type = on_auth_type,
 	.auth_subtype = on_auth_subtype,
+	.auth_failure = on_auth_failure,
 	.update = on_update,
 	.resize = on_resize,
 	.pointer_type_change = on_pointer_type_change,
@@ -900,6 +923,31 @@ static void vnc_display_class_init(VncDi
 			     g_cclosure_marshal_VOID__VOID,
 			     G_TYPE_NONE,
 			     0);
+
+
+	signals[VNC_DESKTOP_RESIZE] =
+		g_signal_new("vnc-desktop-resize",
+			     G_TYPE_FROM_CLASS(klass),
+			     G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS,
+			     0,
+			     NULL,
+			     NULL,
+			     g_cclosure_user_marshal_VOID__INT_INT,
+			     G_TYPE_NONE,
+			     2,
+			     G_TYPE_INT, G_TYPE_INT);
+
+	signals[VNC_AUTH_FAILURE] =
+		g_signal_new("vnc-auth-failure",
+			     G_TYPE_FROM_CLASS(klass),
+			     G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS,
+			     0,
+			     NULL,
+			     NULL,
+			     g_cclosure_marshal_VOID__STRING,
+			     G_TYPE_NONE,
+			     1,
+			     G_TYPE_STRING);
 
 	g_type_class_add_private(klass, sizeof(VncDisplayPrivate));
 }
diff -r 381f8531daab src/vncmarshal.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/vncmarshal.txt	Thu Sep 13 13:54:29 2007 -0400
@@ -0,0 +1,1 @@
+VOID:INT,INT


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