]> git.sesse.net Git - vlc/commitdiff
core: gather message initialization code
authorRémi Denis-Courmont <remi@remlab.net>
Thu, 21 Mar 2013 21:28:23 +0000 (23:28 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 21 Mar 2013 21:28:23 +0000 (23:28 +0200)
Also remove libvlc_int_t.b_color, and (re)print greetings when starting
a new log.

src/libvlc.c
src/libvlc.h
src/misc/messages.c

index 349efa3f51cf1d2156e30becb0ee7db4addbc707..54933cf76c38a4e60e67fb25c8e8dfd2b59162fa 100644 (file)
 
 #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.
index 79bce5ec384d2ebdc3eb2ec95bf71bbecb73769a..2a869bb7cb28fa100b2ab7cc9c6d4b0072612f8c 100644 (file)
@@ -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 */
index abc6c98cde915759f31e99b8ff5c132adb2fc4dd..780fb65fec48f75368138fc908e39fbdd2e724aa 100644 (file)
@@ -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);