]> git.sesse.net Git - vlc/blobdiff - src/misc/messages.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / misc / messages.c
index 4ef2b281191ecbe8558631fe56f331135a5a3fdf..063ae608af898377900788fa088232727f9978fd 100644 (file)
@@ -37,7 +37,7 @@
 #include <stdarg.h>                                       /* va_list for BSD */
 #ifdef __APPLE__
 # include <xlocale.h>
-#elif HAVE_LOCALE_H
+#elif defined(HAVE_LOCALE_H)
 # include <locale.h>
 #endif
 #include <errno.h>                                                  /* errno */
@@ -142,6 +142,7 @@ msg_bank_t *msg_Create (void)
 static void const * kObjectPrintingEnabled = &kObjectPrintingEnabled;
 static void const * kObjectPrintingDisabled = &kObjectPrintingDisabled;
 
+
 #undef msg_EnableObjectPrinting
 void msg_EnableObjectPrinting (vlc_object_t *obj, const char * psz_object)
 {
@@ -202,6 +203,7 @@ struct msg_subscription_t
     libvlc_int_t   *instance;
     msg_callback_t  func;
     msg_cb_data_t  *opaque;
+    int             verbosity;
 };
 
 /**
@@ -224,6 +226,7 @@ msg_subscription_t *msg_Subscribe (libvlc_int_t *instance, msg_callback_t cb,
     sub->instance = instance;
     sub->func = cb;
     sub->opaque = opaque;
+    sub->verbosity = 2; /* by default, give all the messages */
 
     msg_bank_t *bank = libvlc_bank (instance);
     vlc_rwlock_wrlock (&bank->lock);
@@ -247,6 +250,18 @@ void msg_Unsubscribe (msg_subscription_t *sub)
     free (sub);
 }
 
+void msg_SubscriptionSetVerbosity( msg_subscription_t *sub, const int i_verbosity )
+{
+    if( i_verbosity < 0 || i_verbosity > 2 ) return;
+
+    msg_bank_t *bank = libvlc_bank ( sub->instance );
+
+    vlc_rwlock_wrlock (&bank->lock);
+
+    sub->verbosity = i_verbosity;
+
+    vlc_rwlock_unlock (&bank->lock);
+}
 /*****************************************************************************
  * msg_*: print a message
  *****************************************************************************
@@ -442,6 +457,33 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type,
     for (int i = 0; i < bank->i_sub; i++)
     {
         msg_subscription_t *sub = bank->pp_sub[i];
+        libvlc_priv_t *priv = libvlc_priv( sub->instance );
+        msg_bank_t *bank = priv->msg_bank;
+        void *val = vlc_dictionary_value_for_key( &bank->enabled_objects,
+                                                  p_item->psz_module );
+        if( val == kObjectPrintingDisabled ) continue;
+        if( val != kObjectPrintingEnabled  ) /*if not allowed */
+        {
+            val = vlc_dictionary_value_for_key( &bank->enabled_objects,
+                                                 p_item->psz_object_type );
+            if( val == kObjectPrintingDisabled ) continue;
+            if( val == kObjectPrintingEnabled  ); /* Allowed */
+            else if( !bank->all_objects_enabled ) continue;
+        }
+        switch( p_item->i_type )
+        {
+            case VLC_MSG_INFO:
+            case VLC_MSG_ERR:
+                if( sub->verbosity < 0 ) continue;
+                break;
+            case VLC_MSG_WARN:
+                if( sub->verbosity < 1 ) continue;
+                break;
+            case VLC_MSG_DBG:
+                if( sub->verbosity < 2 ) continue;
+                break;
+        }
+
         sub->func (sub->opaque, p_item, 0);
     }
     vlc_rwlock_unlock (&bank->lock);
@@ -455,11 +497,11 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type,
  *****************************************************************************/
 static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
 {
-#   define COL(x)  "\033[" #x ";1m"
-#   define RED     COL(31)
-#   define GREEN   COL(32)
-#   define YELLOW  COL(33)
-#   define WHITE   COL(0)
+#   define COL(x,y)  "\033[" #x ";" #y "m"
+#   define RED     COL(31,1)
+#   define GREEN   COL(32,1)
+#   define YELLOW  COL(0,33)
+#   define WHITE   COL(0,1)
 #   define GRAY    "\033[0m"
 
     static const char ppsz_type[4][9] = { "", " error", " warning", " debug" };