[gtk-vnc] Replace 'bell' operation with a signal



commit cb0a72ef98840a27958fb5b8ae6ff01798e30d1f
Author: Daniel P. Berrange <berrange redhat com>
Date:   Fri Nov 20 16:17:22 2009 +0000

    Replace 'bell' operation with a signal
    
    Remove the 'bell' operation callback from VncConnection.
    Introduce a signal 'vnc-bell' for VncConnection.

 src/vncconnection.c |   27 +++++++++++++++++++++------
 src/vncconnection.h |    2 +-
 src/vncdisplay.c    |   12 +++++-------
 3 files changed, 27 insertions(+), 14 deletions(-)
---
diff --git a/src/vncconnection.c b/src/vncconnection.c
index 2a7aa24..d7bcbf5 100644
--- a/src/vncconnection.c
+++ b/src/vncconnection.c
@@ -189,11 +189,12 @@ G_DEFINE_TYPE(VncConnection, vnc_connection, G_TYPE_OBJECT);
 enum {
 	VNC_CURSOR_CHANGED,
 	VNC_POINTER_MODE_CHANGED,
+	VNC_BELL,
 
 	VNC_LAST_SIGNAL,
 };
 
-static guint signals[VNC_LAST_SIGNAL] = { 0, 0, };
+static guint signals[VNC_LAST_SIGNAL] = { 0, 0, 0, };
 
 #define nibhi(a) (((a) >> 4) & 0x0F)
 #define niblo(a) ((a) & 0x0F)
@@ -386,6 +387,12 @@ static gboolean do_vnc_connection_emit_main_context(gpointer opaque)
 			      0,
 			      data->params.absPointer);
 		break;
+
+	case VNC_BELL:
+		g_signal_emit(G_OBJECT(data->conn),
+			      signals[data->signum],
+			      0);
+		break;
 	}
 
 	coroutine_yieldto(data->caller, NULL);
@@ -2188,16 +2195,14 @@ static void vnc_connection_set_color_map_entry(VncConnection *conn, guint16 colo
 static void vnc_connection_bell(VncConnection *conn)
 {
 	VncConnectionPrivate *priv = conn->priv;
+	struct signal_data sigdata;
 
-	if (priv->has_error || !priv->ops.bell)
+	if (priv->has_error)
 		return;
 
 	GVNC_DEBUG("Server beep");
 
-	if (!priv->ops.bell(priv->ops_data)) {
-		GVNC_DEBUG("Closing the connection: vnc_connection_bell");
-		priv->has_error = TRUE;
-	}
+	vnc_connection_emit_main_context(conn, VNC_BELL, &sigdata);
 }
 
 static void vnc_connection_server_cut_text(VncConnection *conn, const void *data,
@@ -3690,6 +3695,16 @@ static void vnc_connection_class_init(VncConnectionClass *klass)
 			      1,
 			      G_TYPE_BOOLEAN);
 
+	signals[VNC_BELL] =
+		g_signal_new ("vnc-bell",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_FIRST,
+			      G_STRUCT_OFFSET (VncConnectionClass, vnc_bell),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE,
+			      0);
+
 	g_type_class_add_private(klass, sizeof(VncConnectionPrivate));
 }
 
diff --git a/src/vncconnection.h b/src/vncconnection.h
index 06d50f6..897620c 100644
--- a/src/vncconnection.h
+++ b/src/vncconnection.h
@@ -54,6 +54,7 @@ struct _VncConnectionClass
 	/* Signals */
 	void (*vnc_cursor_changed)(VncConnection *conn, VncCursor *cursor);
 	void (*vnc_pointer_mode_changed)(VncConnection *conn, gboolean absPointer);
+	void (*vnc_bell)(VncConnection *conn);
 };
 
 typedef void (rgb24_render_func)(void *, int, int, int, int, guint8 *, int);
@@ -66,7 +67,6 @@ struct vnc_connection_ops
 	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 *);
 	gboolean (*server_cut_text)(void *, const void *, size_t);
 	gboolean (*resize)(void *, int, int);
 	gboolean (*pixel_format)(void *, VncPixelFormat *);
diff --git a/src/vncdisplay.c b/src/vncdisplay.c
index 5f41a27..1d155c2 100644
--- a/src/vncdisplay.c
+++ b/src/vncdisplay.c
@@ -920,7 +920,6 @@ static gboolean emit_signal_auth_cred(gpointer opaque)
 			      0,
 			      s->str->str);
 		break;
-	case VNC_BELL:
 	case VNC_CONNECTED:
 	case VNC_INITIALIZED:
 	case VNC_DISCONNECTED:
@@ -1232,14 +1231,12 @@ static gboolean on_server_cut_text(void *opaque, const void* text, size_t len)
 	return TRUE;
 }
 
-static gboolean on_bell(void *opaque)
+static void on_bell(VncConnection *conn G_GNUC_UNUSED,
+		    gpointer opaque)
 {
 	VncDisplay *obj = VNC_DISPLAY(opaque);
-	struct signal_data s;
-
-	emit_signal_delayed(obj, VNC_BELL, &s);
 
-	return TRUE;
+	g_signal_emit(G_OBJECT(obj), signals[VNC_BELL], 0);
 }
 
 static void on_cursor_changed(VncConnection *conn G_GNUC_UNUSED,
@@ -1346,7 +1343,6 @@ static const struct vnc_connection_ops vnc_display_ops = {
         .pixel_format = on_pixel_format,
 	.auth_unsupported = on_auth_unsupported,
 	.server_cut_text = on_server_cut_text,
-	.bell = on_bell,
 	.render_jpeg = on_render_jpeg,
 	.get_preferred_pixel_format = on_get_preferred_pixel_format
 };
@@ -2032,6 +2028,8 @@ static void vnc_display_init(VncDisplay *display)
 			 G_CALLBACK(on_cursor_changed), display);
 	g_signal_connect(G_OBJECT(priv->conn), "vnc-pointer-mode-changed",
 			 G_CALLBACK(on_pointer_mode_changed), display);
+	g_signal_connect(G_OBJECT(priv->conn), "vnc-bell",
+			 G_CALLBACK(on_bell), display);
 }
 
 static char *



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