/**
* Message logging callback signature.
- * Accepts one private data pointer, the message, and an overrun counter.
+ * \param data data pointer as provided to vlc_msg_SetCallback().
+ * \param type message type (VLC_MSG_* values from enum msg_item_type)
+ * \param item meta informations
+ * \param fmt format string
+ * \param args format string arguments
*/
-typedef void (*msg_callback_t) (void *, int, const msg_item_t *,
- const char *, va_list);
+typedef void (*vlc_log_cb) (void *data, int type, const msg_item_t *item,
+ const char *fmt, va_list args);
-/**
- * Used by interface plugins which subscribe to the message bank.
- */
-typedef struct msg_subscription
-{
- struct msg_subscription *prev, *next;
- msg_callback_t func;
- void *opaque;
-} msg_subscription_t;
+VLC_API void vlc_LogSet(libvlc_int_t *, vlc_log_cb cb, void *data);
-VLC_API void vlc_Subscribe(msg_subscription_t *, msg_callback_t, void *);
-VLC_API void vlc_Unsubscribe(msg_subscription_t *);
+typedef struct msg_subscription { } msg_subscription_t;
+#define vlc_Subscribe(sub,cb,data) ((sub), (cb), (data))
+#define vlc_Unsubscribe(sub) ((void)(sub))
/*@}*/
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 );
if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) )
{
module_EndBank (true);
+ vlc_LogDeinit (p_libvlc);
return VLC_EGENERIC;
}
{
msg_Err( p_libvlc, "No plugins found! Check your VLC installation.");
module_EndBank (true);
+ vlc_LogDeinit (p_libvlc);
return VLC_ENOMOD;
}
{
msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
module_EndBank (true);
+ vlc_LogDeinit (p_libvlc);
return VLC_ENOMEM;
}
b_daemon = true;
/* Free module bank. It is refcounted, so we call this each time */
module_EndBank (true);
-
+ vlc_LogDeinit (p_libvlc);
#if defined(WIN32) || defined(__OS2__)
system_End( );
#endif
#include <vlc_charset.h>
#include "../libvlc.h"
-/**
- * Store all data required by messages interfaces.
- */
-vlc_rwlock_t msg_lock = VLC_STATIC_RWLOCK;
-msg_subscription_t *msg_head;
-
-/**
- * Subscribe to the message queue.
- * Whenever a message is emitted, a callback will be called.
- * Callback invocation are serialized within a subscription.
- *
- * @param cb callback function
- * @param opaque data for the callback function
- */
-void vlc_Subscribe (msg_subscription_t *sub, msg_callback_t cb, void *opaque)
-{
- sub->prev = NULL;
- sub->func = cb;
- sub->opaque = opaque;
-
- vlc_rwlock_wrlock (&msg_lock);
- sub->next = msg_head;
- msg_head = sub;
- vlc_rwlock_unlock (&msg_lock);
-}
-
-/**
- * Unsubscribe from the message queue.
- * This function waits for the message callback to return if needed.
- */
-void vlc_Unsubscribe (msg_subscription_t *sub)
-{
- vlc_rwlock_wrlock (&msg_lock);
- if (sub->next != NULL)
- sub->next->prev = sub->prev;
- if (sub->prev != NULL)
- sub->prev->next = sub->next;
- else
- {
- assert (msg_head == sub);
- msg_head = sub->next;
- }
- vlc_rwlock_unlock (&msg_lock);
-}
-
/**
* Emit a log message.
* \param obj VLC object emitting the message or NULL
va_end (args);
}
-static void PrintColorMsg (void *, int, const msg_item_t *,
- const char *, va_list);
-static void PrintMsg (void *, int, const msg_item_t *, const char *, va_list);
#ifdef WIN32
static void Win32DebugOutputMsg (void *, int , const msg_item_t *,
const char *, va_list);
break;
}
- /* Pass message to subscribers */
+ /* Pass message to the callback */
libvlc_priv_t *priv = libvlc_priv (obj->p_libvlc);
+#ifdef WIN32
va_list ap;
- va_copy (ap, args);
- if (priv->b_color)
- PrintColorMsg (&priv->i_verbose, type, &msg, format, ap);
- else
- PrintMsg (&priv->i_verbose, type, &msg, format, ap);
- va_end (ap);
-
-#ifdef WIN32
va_copy (ap, args);
Win32DebugOutputMsg (&priv->i_verbose, type, &msg, format, ap);
va_end (ap);
#endif
- vlc_rwlock_rdlock (&msg_lock);
- for (msg_subscription_t *sub = msg_head; sub != NULL; sub = sub->next)
- {
- va_copy (ap, args);
- sub->func (sub->opaque, type, &msg, format, ap);
- va_end (ap);
- }
- vlc_rwlock_unlock (&msg_lock);
+ vlc_rwlock_rdlock (&priv->log.lock);
+ priv->log.cb (priv->log.opaque, type, &msg, format, args);
+ vlc_rwlock_unlock (&priv->log.lock);
uselocale (locale);
freelocale (c);
static void PrintColorMsg (void *d, int type, const msg_item_t *p_item,
const char *format, va_list ap)
{
- const signed char *pverbose = d;
FILE *stream = stderr;
+ int verbose = (intptr_t)d;
- if (*pverbose < 0 || *pverbose < (type - VLC_MSG_ERR))
+ if (verbose < 0 || verbose < (type - VLC_MSG_ERR))
return;
int canc = vlc_savecancel ();
static void PrintMsg (void *d, int type, const msg_item_t *p_item,
const char *format, va_list ap)
{
- const signed char *pverbose = d;
FILE *stream = stderr;
+ int verbose = (intptr_t)d;
- if (*pverbose < 0 || *pverbose < (type - VLC_MSG_ERR))
+ if (verbose < 0 || verbose < (type - VLC_MSG_ERR))
return;
int canc = vlc_savecancel ();
free(msg);
}
#endif
+
+/**
+ * Sets the message logging callback.
+ * \param cb message callback, or NULL to reset
+ * \param data data pointer for the message callback
+ */
+void vlc_LogSet (libvlc_int_t *vlc, vlc_log_cb cb, void *opaque)
+{
+ libvlc_priv_t *priv = libvlc_priv (vlc);
+
+ if (cb == NULL)
+ {
+ cb = priv->b_color ? PrintColorMsg : PrintMsg;
+ opaque = (void *)(intptr_t)priv->i_verbose;
+ }
+
+ vlc_rwlock_wrlock (&priv->log.lock);
+ priv->log.cb = cb;
+ priv->log.opaque = opaque;
+ vlc_rwlock_unlock (&priv->log.lock);
+}
+
+void vlc_LogInit (libvlc_int_t *vlc)
+{
+ libvlc_priv_t *priv = libvlc_priv (vlc);
+
+ vlc_rwlock_init (&priv->log.lock);
+ vlc_LogSet (vlc, NULL, NULL);
+}
+
+void vlc_LogDeinit (libvlc_int_t *vlc)
+{
+ libvlc_priv_t *priv = libvlc_priv (vlc);
+
+ vlc_rwlock_destroy (&priv->log.lock);
+}