Re: [gtk-vnc-devel] [patch] debug messages revisited



Ok, guys.

Here it's another approach:

- I dropped --enable-debug stuff in configure stage. We always build
with debug framework.

- There's a new function, vnc_display_get_option_group() which returns a
GOptionGroup, and should be used by apps if they want debug (and future
other stuff from gtk-vnc) support.

Example of usage in a client (vinagre):

  context = g_option_context_new (_("- VNC Client for GNOME"));
  g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
  g_option_context_add_group (context, gtk_get_option_group (TRUE));
  g_option_context_add_group (context, vnc_display_get_option_group ());
  g_option_context_parse (context, &argc, &argv, &error);

And that will appear like that:

LANG=C ./vinagre --help
Usage:
  vinagre [OPTION...] [server:port] - VNC Client for GNOME

Help Options:
  -?, --help               Show help options
  --help-all               Show all help options
  --help-gtk               Show GTK+ Options
  --help-gtk-vnc           Show GTK-VNC Options

Application Options:
  -f, --file=filename      Opens a .vnc file
  --display=DISPLAY        X display to use

 LANG=C ./vinagre --help-gtk-vnc
Usage:
  vinagre [OPTION...] [server:port] - VNC Client for GNOME

GTK-VNC Options
  --gtk-vnc-debug          Enables debug output

Very easy, all dirty job is done by GLib.

About the initialization of gtkglext:
I took a look at its source code, and all it does with the arguments is
to check for debug. I don't care about this. I think we don't need to
change anything. If it uses GOptions, we could easily add them into
gtk-vnc. One day, when it get merged into gtk+ that initialization will
be no longer necessary.

About the patch itself... comments?

Cheers,
-- 
Jonh Wendell
www.bani.com.br

diff -r 15d01d93a5fe configure.ac
--- a/configure.ac	Tue Mar 25 17:09:36 2008 -0300
+++ b/configure.ac	Fri Mar 28 23:44:11 2008 -0300
@@ -196,15 +196,6 @@ if test "$WITH_PYTHON" = "yes"; then
   fi
 fi
 
-dnl --enable-debug=(yes|no)
-AC_ARG_ENABLE(debug, [  --enable-debug=[no/yes] turn on debugging [default=no]],,enable_debug=no)
-if test "$enable_debug" = "yes"; then
-  DEBUG_CFLAGS="-DENABLE_DEBUG"
-else
-  DEBUG_CFLAGS=""
-fi
-AC_SUBST(DEBUG_CFLAGS)
-
 dnl --enable-plugin to enable the browser plugin.
 AC_ARG_ENABLE(plugin,
 	[  --enable-plugin=[no/yes] enable browser plugin [default=no]],,
@@ -251,6 +242,5 @@ Configure summary:
 	Python biding ..............:  ${WITH_PYTHON}
 	Install example programs ...:  ${WITH_EXAMPLES}
 	Browser plugin .............:  ${enable_plugin}
-	DEBUG messages..............:  ${enable_debug}
 	Scaling support.............:  ${with_scaling}
 "
diff -r 15d01d93a5fe src/Makefile.am
--- a/src/Makefile.am	Tue Mar 25 17:09:36 2008 -0300
+++ b/src/Makefile.am	Fri Mar 28 23:44:11 2008 -0300
@@ -8,7 +8,7 @@ libgtk_vnc_1_0_la_CFLAGS = @GTK_CFLAGS@ 
 libgtk_vnc_1_0_la_CFLAGS = @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@ @GNUTLS_CFLAGS@ \
 			   @GTHREAD_CFLAGS@ @WARNING_CFLAGS@ \
 			   -DSYSCONFDIR=\""$(sysconfdir)"\" \
-                           @DEBUG_CFLAGS@
+                           -DG_LOG_DOMAIN=\"gtk-vnc\"
 libgtk_vnc_1_0_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libgtk-vnc_sym.version \
                             -version-info 0:1:0
 
@@ -49,7 +49,7 @@ gtkvnc_la_LIBADD = libgtk-vnc-1.0.la @PY
 # Auto-generated C code for Python binding is full of compiler warnings :-(
 #gtkvnc_la_CFLAGS = @GTK_CFLAGS@ @WARNING_CFLAGS@ @PYTHON_INCLUDES@ @PYGTK_CFLAGS@
 gtkvnc_la_CFLAGS = @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@ @PYTHON_INCLUDES@ \
-		   @PYGTK_CFLAGS@ @DEBUG_CFLAGS@
+		   @PYGTK_CFLAGS@
 gtkvnc_la_LDFLAGS = -module -avoid-version -fPIC
 gtkvnc_la_SOURCES = vncmodule.c vncmodule.defs.c
 
diff -r 15d01d93a5fe src/libgtk-vnc_sym.version
--- a/src/libgtk-vnc_sym.version	Tue Mar 25 17:09:36 2008 -0300
+++ b/src/libgtk-vnc_sym.version	Fri Mar 28 23:44:11 2008 -0300
@@ -45,6 +45,8 @@
     vnc_display_force_grab;
     vnc_display_is_pointer_absolute;
 
+    vnc_display_get_option_group;
+
   local:
       *;
 };
diff -r 15d01d93a5fe src/utils.h
--- a/src/utils.h	Tue Mar 25 17:09:36 2008 -0300
+++ b/src/utils.h	Fri Mar 28 23:44:11 2008 -0300
@@ -11,10 +11,10 @@
 #ifndef _UTILS_H
 #define _UTILS_H
 
-#ifdef ENABLE_DEBUG
-#define GVNC_DEBUG(fmt, ...) do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
-#else
-#define GVNC_DEBUG(fmt, ...) do { } while (0)
-#endif
+#include <glib.h>
+
+extern gboolean debug_enabled;
+
+#define GVNC_DEBUG(fmt, ...) do { if (G_UNLIKELY(debug_enabled)) g_debug(fmt, ## __VA_ARGS__); } while (0)
 
 #endif
diff -r 15d01d93a5fe src/vncdisplay.c
--- a/src/vncdisplay.c	Tue Mar 25 17:09:36 2008 -0300
+++ b/src/vncdisplay.c	Fri Mar 28 23:44:11 2008 -0300
@@ -150,6 +150,14 @@ static guint signals[LAST_SIGNAL] = { 0,
 				      0, 0, 0, 0,
 				      0, 0, 0, 0, 0,};
 static GParamSpec *signalCredParam;
+gboolean debug_enabled = FALSE;
+
+static const GOptionEntry gtk_vnc_args[] =
+{
+  { "gtk-vnc-debug", 0, 0, G_OPTION_ARG_NONE, &debug_enabled, "Enables debug output", 0 },
+  { NULL }
+};
+
 
 static void
 vnc_display_get_property (GObject    *object,
@@ -2354,6 +2362,18 @@ gboolean vnc_display_is_pointer_absolute
 	return obj->priv->absolute;
 }
 
+GOptionGroup *
+vnc_display_get_option_group (void)
+{
+  GOptionGroup *group;
+
+  group = g_option_group_new ("gtk-vnc", "GTK-VNC Options", "Show GTK-VNC Options", NULL, NULL);
+
+  g_option_group_add_entries (group, gtk_vnc_args);
+  
+  return group;
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8
diff -r 15d01d93a5fe src/vncdisplay.h
--- a/src/vncdisplay.h	Tue Mar 25 17:09:36 2008 -0300
+++ b/src/vncdisplay.h	Fri Mar 28 23:44:11 2008 -0300
@@ -120,6 +120,8 @@ void		vnc_display_force_grab(VncDisplay 
 
 gboolean	vnc_display_is_pointer_absolute(VncDisplay *obj);
 
+GOptionGroup *  vnc_display_get_option_group(void);
+
 G_END_DECLS
 
 #endif


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