[vlc-commits] core: gather message initialization code

Rémi Denis-Courmont git at videolan.org
Thu Mar 21 22:29:21 CET 2013


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Mar 21 23:28:23 2013 +0200| [a52e23c7df668fde9915398db2f9d7c87ced4d39] | committer: Rémi Denis-Courmont

core: gather message initialization code

Also remove libvlc_int_t.b_color, and (re)print greetings when starting
a new log.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a52e23c7df668fde9915398db2f9d7c87ced4d39
---

 src/libvlc.c        |   32 --------------------------------
 src/libvlc.h        |    3 +--
 src/misc/messages.c |   28 +++++++++++++++++++++++++---
 3 files changed, 26 insertions(+), 37 deletions(-)

diff --git a/src/libvlc.c b/src/libvlc.c
index 349efa3..54933cf 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -49,10 +49,6 @@
 
 #include "config/vlc_getopt.h"
 
-#ifdef HAVE_UNISTD_H
-#   include <unistd.h> /* isatty() */
-#endif
-
 #ifdef HAVE_DBUS
 /* used for one-instance mode */
 #   include <dbus/dbus.h>
@@ -157,35 +153,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         return VLC_EGENERIC;
     }
 
-    /*
-     * Message queue options (read-only afterwards)
-     */
-#if defined (HAVE_ISATTY) && !defined (WIN32)
-    if (isatty (STDERR_FILENO))
-        priv->b_color = var_InheritBool (p_libvlc, "color");
-    else
-#endif
-        priv->b_color = false;
-
-    priv->i_verbose = var_InheritInteger (p_libvlc, "verbose");
-    psz_val = getenv ("VLC_VERBOSE");
-    if (psz_val != NULL)
-        priv->i_verbose = atoi (psz_val);
-
-    if (var_InheritBool (p_libvlc, "quiet"))
-    {
-        var_Create (p_libvlc, "verbose", VLC_VAR_INTEGER);
-        var_SetInteger (p_libvlc, "verbose", -1);
-        priv->i_verbose = -1;
-    }
-
     vlc_LogInit (p_libvlc);
-
-    /* Announce who we are (TODO: only first instance?) */
-    msg_Dbg( p_libvlc, "VLC media player - %s", VERSION_MESSAGE );
-    msg_Dbg( p_libvlc, "%s", COPYRIGHT_MESSAGE );
-    msg_Dbg( p_libvlc, "revision %s", psz_vlc_changeset );
-    msg_Dbg( p_libvlc, "configured with %s", CONFIGURE_LINE );
     vlc_threads_setup (p_libvlc);
 
     /* Load the builtins and plugins into the module_bank.
diff --git a/src/libvlc.h b/src/libvlc.h
index 79bce5e..2a869bb 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -152,10 +152,9 @@ typedef struct libvlc_priv_t
     {
         void (*cb) (void *, int, const vlc_log_t *, const char *, va_list);
         void *opaque;
+        signed char verbose;
         vlc_rwlock_t lock;
     } log;
-    signed char        i_verbose;   ///< info messages
-    bool               b_color;     ///< color messages?
     bool               b_stats;     ///< Whether to collect stats
 
     /* Singleton objects */
diff --git a/src/misc/messages.c b/src/misc/messages.c
index abc6c98..780fb65 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -32,6 +32,7 @@
 # include "config.h"
 #endif
 
+#include <stdlib.h>
 #include <stdarg.h>                                       /* va_list for BSD */
 #ifdef __APPLE__
 # include <xlocale.h>
@@ -40,6 +41,7 @@
 #endif
 #include <errno.h>                                                  /* errno */
 #include <assert.h>
+#include <unistd.h>
 
 #include <vlc_common.h>
 #include <vlc_interface.h>
@@ -164,7 +166,7 @@ void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
     va_list ap;
 
     va_copy (ap, args);
-    Win32DebugOutputMsg (&priv->i_verbose, type, &msg, format, ap);
+    Win32DebugOutputMsg (&priv->log.verbose, type, &msg, format, ap);
     va_end (ap);
 #endif
 
@@ -289,19 +291,39 @@ void vlc_LogSet (libvlc_int_t *vlc, vlc_log_cb cb, void *opaque)
 
     if (cb == NULL)
     {
-        cb = priv->b_color ? PrintColorMsg : PrintMsg;
-        opaque = (void *)(intptr_t)priv->i_verbose;
+#if defined (HAVE_ISATTY) && !defined (WIN32)
+        if (isatty (STDERR_FILENO) && var_InheritBool (vlc, "color"))
+            cb = PrintColorMsg;
+        else
+#endif
+            cb = PrintMsg;
+        opaque = (void *)(intptr_t)priv->log.verbose;
     }
 
     vlc_rwlock_wrlock (&priv->log.lock);
     priv->log.cb = cb;
     priv->log.opaque = opaque;
     vlc_rwlock_unlock (&priv->log.lock);
+
+    /* Announce who we are */
+    msg_Dbg (vlc, "VLC media player - %s", VERSION_MESSAGE);
+    msg_Dbg (vlc, "%s", COPYRIGHT_MESSAGE);
+    msg_Dbg (vlc, "revision %s", psz_vlc_changeset);
+    msg_Dbg (vlc, "configured with %s", CONFIGURE_LINE);
 }
 
 void vlc_LogInit (libvlc_int_t *vlc)
 {
     libvlc_priv_t *priv = libvlc_priv (vlc);
+    const char *str;
+
+    if (var_InheritBool (vlc, "quiet"))
+        priv->log.verbose = -1;
+    else
+    if ((str = getenv ("VLC_VERBOSE")) != NULL)
+        priv->log.verbose = atoi (str);
+    else
+        priv->log.verbose = var_InheritInteger (vlc, "verbose");
 
     vlc_rwlock_init (&priv->log.lock);
     vlc_LogSet (vlc, NULL, NULL);



More information about the vlc-commits mailing list