r4094 - trunk/birnet



Author: timj
Date: 2006-11-21 16:25:55 -0500 (Tue, 21 Nov 2006)
New Revision: 4094

Modified:
   trunk/birnet/ChangeLog
   trunk/birnet/birnetmsg.cc
   trunk/birnet/birnetmsg.hh
   trunk/birnet/birnetutils.cc
Log:
Tue Nov 21 22:04:15 2006  Tim Janik  <timj gtk org>

        * birnetutils.cc: reworked browser launching logic to work around
        launcher scripts failing unnoticed by executing browser programs
        asyncronously and executing browser launch scripts syncronously
        to check the exit code.
        added "browser" debug key and messages.
        due to unreliable exit codes or foreground/background execution
        behaviour, support had to be removed for the launcher scripts
        xdg-open, htmlview, browser-config and sensible-browser,
        added support for exo-open, galeon, epiphany, amaya and dillo.

        * birnetmsg.hh, birnetmsg.cc: added Msg::CustomType class through
        which users can easily create new logging types. added printf-style
        Msg::display() variant for custom message types.




Modified: trunk/birnet/ChangeLog
===================================================================
--- trunk/birnet/ChangeLog	2006-11-21 01:04:05 UTC (rev 4093)
+++ trunk/birnet/ChangeLog	2006-11-21 21:25:55 UTC (rev 4094)
@@ -1,3 +1,19 @@
+Tue Nov 21 22:04:15 2006  Tim Janik  <timj gtk org>
+
+	* birnetutils.cc: reworked browser launching logic to work around
+	launcher scripts failing unnoticed by executing browser programs
+	asyncronously and executing browser launch scripts syncronously
+	to check the exit code.
+	added "browser" debug key and messages.
+	due to unreliable exit codes or foreground/background execution
+	behaviour, support had to be removed for the launcher scripts
+	xdg-open, htmlview, browser-config and sensible-browser,
+	added support for exo-open, galeon, epiphany, amaya and dillo.
+
+	* birnetmsg.hh, birnetmsg.cc: added Msg::CustomType class through
+	which users can easily create new logging types. added printf-style
+	Msg::display() variant for custom message types.
+
 Mon Nov 20 23:39:43 2006  Tim Janik  <timj gtk org>
 
 	* birnetmsg.hh, birnetmsg.cc: implemented C++ messaging API,

Modified: trunk/birnet/birnetmsg.cc
===================================================================
--- trunk/birnet/birnetmsg.cc	2006-11-21 01:04:05 UTC (rev 4093)
+++ trunk/birnet/birnetmsg.cc	2006-11-21 21:25:55 UTC (rev 4094)
@@ -533,7 +533,8 @@
 }
 
 void
-Msg::display_aparts (Type                message_type,
+Msg::display_aparts (const char         *log_domain,
+                     Type                message_type,
                      const Part &p0, const Part &p1,
                      const Part &p2, const Part &p3,
                      const Part &p4, const Part &p5,
@@ -552,10 +553,25 @@
   parts.push_back (p7);
   parts.push_back (p8);
   parts.push_back (p9);
-  display_parts (BIRNET_LOG_DOMAIN, message_type, parts);
+  display_parts (log_domain, message_type, parts);
   errno = saved_errno;
 }
 
+void
+Msg::display_vmsg (const char         *log_domain,
+                   Type                message_type,
+                   const char         *format,
+                   va_list             args)
+{
+  int saved_errno = errno;
+  char *text = g_strdup_vprintf (format, args);
+  vector<Part> parts;
+  parts.push_back (Primary (String (text)));
+  g_free (text);
+  display_parts (log_domain, message_type, parts);
+  errno = saved_errno;
+}
+
 /**
  * @param domain message domain
  * @param parts  message parts

Modified: trunk/birnet/birnetmsg.hh
===================================================================
--- trunk/birnet/birnetmsg.hh	2006-11-21 01:04:05 UTC (rev 4093)
+++ trunk/birnet/birnetmsg.hh	2006-11-21 21:25:55 UTC (rev 4094)
@@ -33,6 +33,7 @@
   struct Text2; typedef Text2 Secondary; /* secondary message (lengthy) */
   struct Text3; typedef Text3 Detail;    /* message details */
   struct Check;                          /* enable/disable message text */
+  struct CustomType;
   typedef enum {
     LOG_TO_STDERR     = 1,
     LOG_TO_STDLOG     = 2,
@@ -72,6 +73,9 @@
                                       const Part &p4 = empty_part, const Part &p5 = empty_part,
                                       const Part &p6 = empty_part, const Part &p7 = empty_part,
                                       const Part &p8 = empty_part, const Part &p9 = empty_part);
+  static inline void display         (const CustomType   &message_type,
+                                      const char         *format,
+                                      ...) BIRNET_PRINTF (2, 3);
   /* message handling */
   struct Part {
     String string;
@@ -97,12 +101,17 @@
                                       const vector<Part> &parts);
 protected:
   static const Part   &empty_part;
-  static void    display_aparts      (Type                message_type,
+  static void    display_aparts      (const char         *log_domain,
+                                      Type                message_type,
                                       const Part &p0, const Part &p1,
                                       const Part &p2, const Part &p3,
                                       const Part &p4, const Part &p5,
                                       const Part &p6, const Part &p7,
                                       const Part &p8, const Part &p9);
+  static void    display_vmsg        (const char         *log_domain,
+                                      Type                message_type,
+                                      const char         *format,
+                                      va_list             args);
   BIRNET_PRIVATE_CLASS_COPY (Msg);
 private:
   static volatile int    n_msg_types;
@@ -138,6 +147,15 @@
     explicit BIRNET_PRINTF (3, 4) Custom (uint8 ctype, const char *format, ...) { va_list a; va_start (a, format); setup (ctype | 0x80, format, a); va_end (a); }
     explicit                      Custom (uint8 ctype, const String &s)         { setup (ctype | 0x80, s); }
   };
+  struct CustomType {
+    Type type;
+    explicit CustomType (const char         *ident,
+                         Type                default_ouput,
+                         const char         *label = NULL) :
+      type (register_type (ident, default_ouput, label))
+    {}
+    BIRNET_PRIVATE_CLASS_COPY (CustomType);
+  };
 };
 
 /* --- inline implementations --- */
@@ -160,9 +178,23 @@
 {
   /* this function is supposed to preserve errno */
   if (check (message_type))
-    display_aparts (message_type, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
+    display_aparts (BIRNET_LOG_DOMAIN, message_type, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
 }
 
+inline void
+Msg::display (const CustomType   &message_type,
+              const char         *format,
+              ...)
+{
+  if (check (message_type.type))
+    {
+      va_list args;
+      va_start (args, format);
+      display_vmsg (BIRNET_LOG_DOMAIN, message_type.type, format, args);
+      va_end (args);
+    }
+}
+
 } // Birnet
 
 #endif /* __BIRNET_MSG_HH__ */

Modified: trunk/birnet/birnetutils.cc
===================================================================
--- trunk/birnet/birnetutils.cc	2006-11-21 01:04:05 UTC (rev 4093)
+++ trunk/birnet/birnetutils.cc	2006-11-21 21:25:55 UTC (rev 4094)
@@ -38,6 +38,8 @@
 
 namespace Birnet {
 
+static Msg::CustomType debug_browser ("browser", Msg::DEBUG);
+
 static const InitSettings *birnet_init_settings = NULL;
 
 InitSettings
@@ -1051,33 +1053,33 @@
 {
   static struct {
     const char   *prg, *arg1, *prefix, *postfix;
+    bool          asyncronous; /* start asyncronously and check exit code to catch launch errors */
     volatile bool disabled;
   } www_browsers[] = {
     /* program */               /* arg1 */      /* prefix+URL+postfix */
-    /* system browser launchers */
-    { "sensible-browser",       NULL,           "", "" },
-    { "x-www-browser",          NULL,           "", "" },
-    { "htmlview",               NULL,           "", "" },
-    /* portable browser launchers */
-    { "xdg-open",               NULL,           "", "" },
-#if 1
-    /* desktop browser launchers */
-    { "gnome-open",             NULL,           "", "" },
-    { "kfmclient",              "openURL",      "", "" },
-    { "gnome-moz-remote",       "--newwin"      "", "" },
-    /* specific browser programs */
-    { "firefox",                NULL,           "", "" },
-    { "mozilla-firefox",        NULL,           "", "" },
-    { "mozilla",                NULL,           "", "" },
-    { "opera",                  "-newwindow",   "", "" },
-    { "konqueror",              NULL,           "", "" },
+    /* working browser launchers */
+    { "gnome-open",             NULL,           "", "", 0 }, /* opens in background, correct exit_code */
+    { "kfmclient",              "openURL",      "", "", 0 }, /* opens in background, correct exit_code */
+    { "exo-open",               NULL,           "", "", 0 }, /* opens in background, correct exit_code */
+    { "gnome-moz-remote",       "--newwin",     "", "", 0 }, /* opens in background, correct exit_code */
+#if 0
+    /* broken/unpredictable browser launchers */
+    { "browser-config",         NULL,            "", "", 0 }, /* opens in background (+ sleep 5), broken exit_code (always 0) */
+    { "xdg-open",               NULL,            "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */
+    { "sensible-browser",       NULL,            "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */
+    { "htmlview",               NULL,            "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */
 #endif
-    /* above, we give system browser launchers precedence over xdg-open
-     * (especially the debian sensible-browser script), because xdg-open
-     * tends to exhibit bugs in desktop browser launchers still (e.g.
-     * gnome-open not honouring the users browser setting for file:///
-     * urls).
-     */
+    /* direct browser invocation */
+    { "x-www-browser",          NULL,           "", "", 1 }, /* opens in foreground, browser alias */
+    { "firefox",                NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
+    { "mozilla-firefox",        NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
+    { "mozilla",                NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
+    { "konqueror",              NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
+    { "opera",                  "-newwindow",   "", "", 1 }, /* opens in foreground, correct exit_code */
+    { "galeon",                 NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
+    { "epiphany",               NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
+    { "amaya",                  NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
+    { "dillo",                  NULL,           "", "", 1 }, /* opens in foreground, correct exit_code */
   };
   uint i;
   for (i = 0; i < G_N_ELEMENTS (www_browsers); i++)
@@ -1091,22 +1093,42 @@
         char *string = g_strconcat (www_browsers[i].prefix, url, www_browsers[i].postfix, NULL);
         args[n] = string;
         GError *error = NULL;
-        bool success = g_spawn_async (NULL, /* cwd */
-                                      args,
-                                      NULL, /* envp */
-                                      G_SPAWN_SEARCH_PATH,
-                                      NULL, /* child_setup() */
-                                      NULL, /* user_data */
-                                      NULL, /* child_pid */
-                                      &error);
+        char fallback_error[64] = "Ok";
+        bool success;
+        if (!www_browsers[i].asyncronous) /* start syncronously and check exit code */
+          {
+            int exit_status = -1;
+            success = g_spawn_sync (NULL, /* cwd */
+                                    args,
+                                    NULL, /* envp */
+                                    G_SPAWN_SEARCH_PATH,
+                                    NULL, /* child_setup() */
+                                    NULL, /* user_data */
+                                    NULL, /* standard_output */
+                                    NULL, /* standard_error */
+                                    &exit_status,
+                                    &error);
+            success = success && !exit_status;
+            if (exit_status)
+              g_snprintf (fallback_error, sizeof (fallback_error), "exitcode: %u", exit_status);
+          }
+        else
+          success = g_spawn_async (NULL, /* cwd */
+                                   args,
+                                   NULL, /* envp */
+                                   G_SPAWN_SEARCH_PATH,
+                                   NULL, /* child_setup() */
+                                   NULL, /* user_data */
+                                   NULL, /* child_pid */
+                                   &error);
         g_free (string);
-        // g_printerr ("show \"%s\": %s: %s\n", url, args[0], error ? error->message : "Ok");
+        Msg::display (debug_browser, "show \"%s\": %s: %s", url, args[0], error ? error->message : fallback_error);
         g_clear_error (&error);
         if (success)
-          return TRUE;
+          return true;
         www_browsers[i].disabled = true;
       }
-  /* reset disabled states if no browser could be found */
+  /* reset all disabled states if no browser could be found */
   for (i = 0; i < G_N_ELEMENTS (www_browsers); i++)
     www_browsers[i].disabled = false;
   return false;




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