Commit fad10ee5 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Fix namespace, remove useless variable and clean up msg_* functions()

parent 9ffae683
...@@ -93,22 +93,20 @@ typedef struct msg_subscription_t msg_subscription_t; ...@@ -93,22 +93,20 @@ typedef struct msg_subscription_t msg_subscription_t;
/***************************************************************************** /*****************************************************************************
* Prototypes * Prototypes
*****************************************************************************/ *****************************************************************************/
VLC_API void msg_Generic( vlc_object_t *, int, const char *, const char *, ... ) VLC_FORMAT( 4, 5 ); VLC_API void vlc_Log(vlc_object_t *, int,
VLC_API void msg_GenericVa( vlc_object_t *, int, const char *, const char *, va_list args ); const char *, const char *, ...) VLC_FORMAT( 4, 5 );
#define msg_GenericVa(a, b, c, d, e) msg_GenericVa(VLC_OBJECT(a), b, c, d, e) VLC_API void vlc_vaLog(vlc_object_t *, int,
const char *, const char *, va_list);
#define msg_GenericVa(a, b, c, d, e) vlc_vaLog(VLC_OBJECT(a), b, c, d, e)
#define msg_Info( p_this, ... ) \ #define msg_Info( p_this, ... ) \
msg_Generic( VLC_OBJECT(p_this), VLC_MSG_INFO, \ vlc_Log( VLC_OBJECT(p_this), VLC_MSG_INFO, MODULE_STRING, __VA_ARGS__ )
MODULE_STRING, __VA_ARGS__ )
#define msg_Err( p_this, ... ) \ #define msg_Err( p_this, ... ) \
msg_Generic( VLC_OBJECT(p_this), VLC_MSG_ERR, \ vlc_Log( VLC_OBJECT(p_this), VLC_MSG_ERR, MODULE_STRING, __VA_ARGS__ )
MODULE_STRING, __VA_ARGS__ )
#define msg_Warn( p_this, ... ) \ #define msg_Warn( p_this, ... ) \
msg_Generic( VLC_OBJECT(p_this), VLC_MSG_WARN, \ vlc_Log( VLC_OBJECT(p_this), VLC_MSG_WARN, MODULE_STRING, __VA_ARGS__ )
MODULE_STRING, __VA_ARGS__ )
#define msg_Dbg( p_this, ... ) \ #define msg_Dbg( p_this, ... ) \
msg_Generic( VLC_OBJECT(p_this), VLC_MSG_DBG, \ vlc_Log( VLC_OBJECT(p_this), VLC_MSG_DBG, MODULE_STRING, __VA_ARGS__ )
MODULE_STRING, __VA_ARGS__ )
typedef struct msg_cb_data_t msg_cb_data_t; typedef struct msg_cb_data_t msg_cb_data_t;
...@@ -118,8 +116,8 @@ typedef struct msg_cb_data_t msg_cb_data_t; ...@@ -118,8 +116,8 @@ typedef struct msg_cb_data_t msg_cb_data_t;
*/ */
typedef void (*msg_callback_t) (msg_cb_data_t *, const msg_item_t *); typedef void (*msg_callback_t) (msg_cb_data_t *, const msg_item_t *);
VLC_API msg_subscription_t* msg_Subscribe( libvlc_int_t *, msg_callback_t, msg_cb_data_t * ) VLC_USED; VLC_API msg_subscription_t *vlc_Subscribe(msg_callback_t, msg_cb_data_t *) VLC_USED;
VLC_API void msg_Unsubscribe( msg_subscription_t * ); VLC_API void vlc_Unsubscribe(msg_subscription_t *);
/** /**
* @} * @}
......
...@@ -102,7 +102,7 @@ int OpenIntf ( vlc_object_t *p_this ) ...@@ -102,7 +102,7 @@ int OpenIntf ( vlc_object_t *p_this )
memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) ); memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
/* subscribe to LibVLCCore's messages */ /* subscribe to LibVLCCore's messages */
p_intf->p_sys->p_sub = msg_Subscribe( p_intf->p_libvlc, MsgCallback, NULL ); p_intf->p_sys->p_sub = vlc_Subscribe( MsgCallback, NULL );
p_intf->pf_run = Run; p_intf->pf_run = Run;
p_intf->b_should_run_on_first_thread = true; p_intf->b_should_run_on_first_thread = true;
...@@ -721,7 +721,7 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -721,7 +721,7 @@ static VLCMain *_o_sharedMainInstance = nil;
[o_mainwindow release]; [o_mainwindow release];
/* unsubscribe from libvlc's debug messages */ /* unsubscribe from libvlc's debug messages */
msg_Unsubscribe( p_intf->p_sys->p_sub ); vlc_Unsubscribe( p_intf->p_sys->p_sub );
[o_msg_arr removeAllObjects]; [o_msg_arr removeAllObjects];
[o_msg_arr release]; [o_msg_arr release];
......
...@@ -1901,7 +1901,7 @@ static int Open(vlc_object_t *p_this) ...@@ -1901,7 +1901,7 @@ static int Open(vlc_object_t *p_this)
memset(p_sys->msgs, 0, sizeof p_sys->msgs); memset(p_sys->msgs, 0, sizeof p_sys->msgs);
p_sys->i_msgs = 0; p_sys->i_msgs = 0;
p_sys->i_verbosity = var_InheritInteger(p_intf, "verbose"); p_sys->i_verbosity = var_InheritInteger(p_intf, "verbose");
p_sys->p_sub = msg_Subscribe(p_intf->p_libvlc, MsgCallback, msg_cb_data); p_sys->p_sub = vlc_Subscribe(MsgCallback, msg_cb_data);
p_sys->i_box_type = BOX_PLAYLIST; p_sys->i_box_type = BOX_PLAYLIST;
p_sys->b_plidx_follow = true; p_sys->b_plidx_follow = true;
...@@ -1956,7 +1956,7 @@ static void Close(vlc_object_t *p_this) ...@@ -1956,7 +1956,7 @@ static void Close(vlc_object_t *p_this)
endwin(); /* Close the ncurses interface */ endwin(); /* Close the ncurses interface */
msg_Unsubscribe(p_sys->p_sub); vlc_Unsubscribe(p_sys->p_sub);
vlc_mutex_destroy(&p_sys->msg_lock); vlc_mutex_destroy(&p_sys->msg_lock);
vlc_mutex_destroy(&p_sys->pl_lock); vlc_mutex_destroy(&p_sys->pl_lock);
for(unsigned i = 0; i < sizeof p_sys->msgs / sizeof *p_sys->msgs; i++) for(unsigned i = 0; i < sizeof p_sys->msgs / sizeof *p_sys->msgs; i++)
......
...@@ -128,13 +128,13 @@ MessagesDialog::MessagesDialog( intf_thread_t *_p_intf) ...@@ -128,13 +128,13 @@ MessagesDialog::MessagesDialog( intf_thread_t *_p_intf)
/* Hook up to LibVLC messaging */ /* Hook up to LibVLC messaging */
cbData = new msg_cb_data_t; cbData = new msg_cb_data_t;
cbData->self = this; cbData->self = this;
sub = msg_Subscribe( p_intf->p_libvlc, MsgCallback, cbData ); sub = vlc_Subscribe( MsgCallback, cbData );
} }
MessagesDialog::~MessagesDialog() MessagesDialog::~MessagesDialog()
{ {
writeSettings( "Messages" ); writeSettings( "Messages" );
msg_Unsubscribe( sub ); vlc_Unsubscribe( sub );
delete cbData; delete cbData;
}; };
......
...@@ -83,7 +83,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -83,7 +83,7 @@ static int Open( vlc_object_t *p_this )
// Suscribe to messages bank // Suscribe to messages bank
#if 0 #if 0
p_intf->p_sys->p_sub = msg_Subscribe( p_intf ); p_intf->p_sys->p_sub = vlc_Subscribe( p_intf );
#endif #endif
p_intf->p_sys->p_input = NULL; p_intf->p_sys->p_input = NULL;
...@@ -152,7 +152,7 @@ static void Close( vlc_object_t *p_this ) ...@@ -152,7 +152,7 @@ static void Close( vlc_object_t *p_this )
// Unsubscribe from messages bank // Unsubscribe from messages bank
#if 0 #if 0
msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub ); vlc_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
#endif #endif
// Destroy structure // Destroy structure
......
...@@ -322,7 +322,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -322,7 +322,7 @@ static int Open( vlc_object_t *p_this )
#endif #endif
} }
p_sys->p_sub = msg_Subscribe( p_intf->p_libvlc, Overflow, &p_sys->msg ); p_sys->p_sub = vlc_Subscribe( Overflow, &p_sys->msg );
return 0; return 0;
} }
...@@ -337,7 +337,7 @@ static void Close( vlc_object_t *p_this ) ...@@ -337,7 +337,7 @@ static void Close( vlc_object_t *p_this )
/* Flush the queue and unsubscribe from the message queue */ /* Flush the queue and unsubscribe from the message queue */
/* FIXME: flush */ /* FIXME: flush */
msg_Unsubscribe( p_sys->p_sub ); vlc_Unsubscribe( p_sys->p_sub );
switch( p_sys->msg.i_mode ) switch( p_sys->msg.i_mode )
{ {
......
...@@ -100,7 +100,7 @@ libvlc_log_t *libvlc_log_open( libvlc_instance_t *p_instance ) ...@@ -100,7 +100,7 @@ libvlc_log_t *libvlc_log_open( libvlc_instance_t *p_instance )
vlc_spin_init( &p_log->data.lock ); vlc_spin_init( &p_log->data.lock );
p_log->data.count = 0; p_log->data.count = 0;
p_log->data.verbosity = p_instance->verbosity; p_log->data.verbosity = p_instance->verbosity;
p_log->p_messages = msg_Subscribe(p_instance->p_libvlc_int, handler, &p_log->data); p_log->p_messages = vlc_Subscribe(handler, &p_log->data);
if( !p_log->p_messages ) if( !p_log->p_messages )
{ {
...@@ -119,7 +119,7 @@ void libvlc_log_close( libvlc_log_t *p_log ) ...@@ -119,7 +119,7 @@ void libvlc_log_close( libvlc_log_t *p_log )
return; return;
assert( p_log->p_messages ); assert( p_log->p_messages );
msg_Unsubscribe(p_log->p_messages); vlc_Unsubscribe(p_log->p_messages);
libvlc_release( p_log->p_instance ); libvlc_release( p_log->p_instance );
libvlc_log_clear( p_log ); libvlc_log_clear( p_log );
vlc_spin_destroy( &p_log->data.lock ); vlc_spin_destroy( &p_log->data.lock );
......
...@@ -275,10 +275,10 @@ module_provides ...@@ -275,10 +275,10 @@ module_provides
module_unneed module_unneed
vlc_module_load vlc_module_load
vlc_module_unload vlc_module_unload
msg_Generic vlc_Log
msg_GenericVa vlc_vaLog
msg_Subscribe vlc_Subscribe
msg_Unsubscribe vlc_Unsubscribe
msleep msleep
mstrtime mstrtime
mwait mwait
......
...@@ -78,8 +78,7 @@ struct msg_subscription_t ...@@ -78,8 +78,7 @@ struct msg_subscription_t
* @param opaque data for the callback function * @param opaque data for the callback function
* @return a subscription pointer, or NULL in case of failure * @return a subscription pointer, or NULL in case of failure
*/ */
msg_subscription_t *msg_Subscribe (libvlc_int_t *instance, msg_callback_t cb, msg_subscription_t *vlc_Subscribe (msg_callback_t cb, msg_cb_data_t *opaque)
msg_cb_data_t *opaque)
{ {
msg_subscription_t *sub = malloc (sizeof (*sub)); msg_subscription_t *sub = malloc (sizeof (*sub));
if (sub == NULL) if (sub == NULL)
...@@ -101,7 +100,7 @@ msg_subscription_t *msg_Subscribe (libvlc_int_t *instance, msg_callback_t cb, ...@@ -101,7 +100,7 @@ msg_subscription_t *msg_Subscribe (libvlc_int_t *instance, msg_callback_t cb,
* Unsubscribe from the message queue. * Unsubscribe from the message queue.
* This function waits for the message callback to return if needed. * This function waits for the message callback to return if needed.
*/ */
void msg_Unsubscribe (msg_subscription_t *sub) void vlc_Unsubscribe (msg_subscription_t *sub)
{ {
vlc_rwlock_wrlock (&msg_lock); vlc_rwlock_wrlock (&msg_lock);
if (sub->next != NULL) if (sub->next != NULL)
...@@ -117,36 +116,34 @@ void msg_Unsubscribe (msg_subscription_t *sub) ...@@ -117,36 +116,34 @@ void msg_Unsubscribe (msg_subscription_t *sub)
free (sub); free (sub);
} }
/***************************************************************************** /**
* msg_*: print a message * Emit a log message.
***************************************************************************** * \param obj VLC object emitting the message
* These functions queue a message for later printing. * \param type VLC_MSG_* message type (info, error, warning or debug)
*****************************************************************************/ * \param module name of module from which the message come
void msg_Generic( vlc_object_t *p_this, int i_type, const char *psz_module, * (normally MODULE_STRING)
const char *psz_format, ... ) * \param format printf-like message format
*/
void vlc_Log (vlc_object_t *obj, int type, const char *module,
const char *format, ... )
{ {
va_list args; va_list args;
va_start( args, psz_format ); va_start (args, format);
msg_GenericVa (p_this, i_type, psz_module, psz_format, args); vlc_vaLog (obj, type, module, format, args);
va_end( args ); va_end (args);
} }
#undef msg_GenericVa
/** /**
* Add a message to a queue * Emit a log message. This function is the variable argument list equivalent
* * to vlc_Log().
* This function provides basic functionnalities to other msg_* functions.
* It adds a message to a queue (after having printed all stored messages if it
* is full). If the message can't be converted to string in memory, it issues
* a warning.
*/ */
void msg_GenericVa (vlc_object_t *p_this, int i_type, const char *psz_module, void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
const char *psz_format, va_list args) const char *format, va_list args)
{ {
assert (p_this); assert (obj != NULL);
if( p_this->i_flags & OBJECT_FLAGS_QUIET ) if (obj->i_flags & OBJECT_FLAGS_QUIET)
return; return;
/* C locale to get error messages in English in the logs */ /* C locale to get error messages in English in the logs */
...@@ -155,10 +152,10 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type, const char *psz_module, ...@@ -155,10 +152,10 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type, const char *psz_module,
#ifndef __GLIBC__ #ifndef __GLIBC__
/* Expand %m to strerror(errno) - only once */ /* Expand %m to strerror(errno) - only once */
char buf[strlen( psz_format ) + 2001], *ptr; char buf[strlen(format) + 2001], *ptr;
strcpy( buf, psz_format ); strcpy (buf, format);
ptr = (char*)buf; ptr = (char*)buf;
psz_format = (const char*) buf; format = (const char*) buf;
for( ;; ) for( ;; )
{ {
...@@ -213,7 +210,7 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type, const char *psz_module, ...@@ -213,7 +210,7 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type, const char *psz_module,
static const char nomemstr[] = "<not enough memory to format message>"; static const char nomemstr[] = "<not enough memory to format message>";
char *str; char *str;
if (unlikely(vasprintf (&str, psz_format, args) == -1)) if (unlikely(vasprintf (&str, format, args) == -1))
str = (char *)nomemstr; str = (char *)nomemstr;
uselocale (locale); uselocale (locale);
...@@ -222,21 +219,21 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type, const char *psz_module, ...@@ -222,21 +219,21 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type, const char *psz_module,
/* Fill message information fields */ /* Fill message information fields */
msg_item_t msg; msg_item_t msg;
msg.i_type = i_type; msg.i_type = type;
msg.i_object_id = (uintptr_t)p_this; msg.i_object_id = (uintptr_t)obj;
msg.psz_object_type = p_this->psz_object_type; msg.psz_object_type = obj->psz_object_type;
msg.psz_module = psz_module; msg.psz_module = module;
msg.psz_msg = str; msg.psz_msg = str;
msg.psz_header = NULL; msg.psz_header = NULL;
for (vlc_object_t *o = p_this; o != NULL; o = o->p_parent) for (vlc_object_t *o = obj; o != NULL; o = o->p_parent)
if (o->psz_header != NULL) if (o->psz_header != NULL)
{ {
msg.psz_header = o->psz_header; msg.psz_header = o->psz_header;
break; break;
} }
PrintMsg( p_this, &msg ); PrintMsg (obj, &msg);
vlc_rwlock_rdlock (&msg_lock); vlc_rwlock_rdlock (&msg_lock);
for (msg_subscription_t *sub = msg_head; sub != NULL; sub = sub->next) for (msg_subscription_t *sub = msg_head; sub != NULL; sub = sub->next)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment