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

Remove msg_cb_data_t and simplify accordingly

parent fad10ee5
...@@ -108,15 +108,13 @@ VLC_API void vlc_vaLog(vlc_object_t *, int, ...@@ -108,15 +108,13 @@ VLC_API void vlc_vaLog(vlc_object_t *, int,
#define msg_Dbg( p_this, ... ) \ #define msg_Dbg( p_this, ... ) \
vlc_Log( VLC_OBJECT(p_this), VLC_MSG_DBG, MODULE_STRING, __VA_ARGS__ ) vlc_Log( VLC_OBJECT(p_this), VLC_MSG_DBG, MODULE_STRING, __VA_ARGS__ )
typedef struct msg_cb_data_t msg_cb_data_t;
/** /**
* Message logging callback signature. * Message logging callback signature.
* Accepts one private data pointer, the message, and an overrun counter. * Accepts one private data pointer, the message, and an overrun counter.
*/ */
typedef void (*msg_callback_t) (msg_cb_data_t *, const msg_item_t *); typedef void (*msg_callback_t) (void *, const msg_item_t *);
VLC_API msg_subscription_t *vlc_Subscribe(msg_callback_t, msg_cb_data_t *) VLC_USED; VLC_API msg_subscription_t *vlc_Subscribe(msg_callback_t, void *) VLC_USED;
VLC_API void vlc_Unsubscribe(msg_subscription_t *); VLC_API void vlc_Unsubscribe(msg_subscription_t *);
/** /**
......
...@@ -70,7 +70,7 @@ static void updateProgressPanel (void *, const char *, float); ...@@ -70,7 +70,7 @@ static void updateProgressPanel (void *, const char *, float);
static bool checkProgressPanel (void *); static bool checkProgressPanel (void *);
static void destroyProgressPanel (void *); static void destroyProgressPanel (void *);
static void MsgCallback( msg_cb_data_t *, const msg_item_t * ); static void MsgCallback( void *, const msg_item_t * );
static int InputEvent( vlc_object_t *, const char *, static int InputEvent( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, vlc_value_t, void * );
...@@ -219,7 +219,7 @@ static void Run( intf_thread_t *p_intf ) ...@@ -219,7 +219,7 @@ static void Run( intf_thread_t *p_intf )
* ready to be displayed. We store everything in a NSArray in our Cocoa part * ready to be displayed. We store everything in a NSArray in our Cocoa part
* of this file. * of this file.
*****************************************************************************/ *****************************************************************************/
static void MsgCallback( msg_cb_data_t *data, const msg_item_t *item ) static void MsgCallback( void *data, const msg_item_t *item )
{ {
int canc = vlc_savecancel(); int canc = vlc_savecancel();
......
...@@ -221,11 +221,6 @@ struct intf_sys_t ...@@ -221,11 +221,6 @@ struct intf_sys_t
}; };
struct msg_cb_data_t
{
intf_sys_t *p_sys;
};
/***************************************************************************** /*****************************************************************************
* Directories * Directories
*****************************************************************************/ *****************************************************************************/
...@@ -1816,9 +1811,9 @@ static void HandleKey(intf_thread_t *p_intf) ...@@ -1816,9 +1811,9 @@ static void HandleKey(intf_thread_t *p_intf)
* *
*/ */
static void MsgCallback(msg_cb_data_t *data, const msg_item_t *msg) static void MsgCallback(void *data, const msg_item_t *msg)
{ {
intf_sys_t *p_sys = data->p_sys; intf_sys_t *p_sys = data;
if (p_sys->i_verbosity < 0 if (p_sys->i_verbosity < 0
|| p_sys->i_verbosity < (msg->i_type - VLC_MSG_ERR)) || p_sys->i_verbosity < (msg->i_type - VLC_MSG_ERR))
...@@ -1883,25 +1878,16 @@ static int Open(vlc_object_t *p_this) ...@@ -1883,25 +1878,16 @@ static int Open(vlc_object_t *p_this)
{ {
intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_thread_t *p_intf = (intf_thread_t *)p_this;
intf_sys_t *p_sys = p_intf->p_sys = calloc(1, sizeof(intf_sys_t)); intf_sys_t *p_sys = p_intf->p_sys = calloc(1, sizeof(intf_sys_t));
struct msg_cb_data_t *msg_cb_data;
if (!p_sys) if (!p_sys)
return VLC_ENOMEM; return VLC_ENOMEM;
msg_cb_data = malloc(sizeof *msg_cb_data);
if (!msg_cb_data)
{
free(p_sys);
return VLC_ENOMEM;
}
msg_cb_data->p_sys = p_sys;
vlc_mutex_init(&p_sys->msg_lock); vlc_mutex_init(&p_sys->msg_lock);
vlc_mutex_init(&p_sys->pl_lock); vlc_mutex_init(&p_sys->pl_lock);
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 = vlc_Subscribe(MsgCallback, msg_cb_data); p_sys->p_sub = vlc_Subscribe(MsgCallback, p_sys);
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;
......
...@@ -69,11 +69,6 @@ MsgEvent::MsgEvent( const msg_item_t *msg ) ...@@ -69,11 +69,6 @@ MsgEvent::MsgEvent( const msg_item_t *msg )
{ {
} }
struct msg_cb_data_t
{
MessagesDialog *self;
};
MessagesDialog::MessagesDialog( intf_thread_t *_p_intf) MessagesDialog::MessagesDialog( intf_thread_t *_p_intf)
: QVLCFrame( _p_intf ) : QVLCFrame( _p_intf )
{ {
...@@ -126,16 +121,13 @@ MessagesDialog::MessagesDialog( intf_thread_t *_p_intf) ...@@ -126,16 +121,13 @@ MessagesDialog::MessagesDialog( intf_thread_t *_p_intf)
readSettings( "Messages", QSize( 600, 450 ) ); readSettings( "Messages", QSize( 600, 450 ) );
/* Hook up to LibVLC messaging */ /* Hook up to LibVLC messaging */
cbData = new msg_cb_data_t; sub = vlc_Subscribe( MsgCallback, this );
cbData->self = this;
sub = vlc_Subscribe( MsgCallback, cbData );
} }
MessagesDialog::~MessagesDialog() MessagesDialog::~MessagesDialog()
{ {
writeSettings( "Messages" ); writeSettings( "Messages" );
vlc_Unsubscribe( sub ); vlc_Unsubscribe( sub );
delete cbData;
}; };
void MessagesDialog::changeVerbosity( int verbosity ) void MessagesDialog::changeVerbosity( int verbosity )
...@@ -307,9 +299,9 @@ void MessagesDialog::tabChanged( int i ) ...@@ -307,9 +299,9 @@ void MessagesDialog::tabChanged( int i )
updateButton->setVisible( i == 1 ); updateButton->setVisible( i == 1 );
} }
void MessagesDialog::MsgCallback( msg_cb_data_t *data, const msg_item_t *item ) void MessagesDialog::MsgCallback( void *self, const msg_item_t *item )
{ {
MessagesDialog *dialog = data->self; MessagesDialog *dialog = (MessagesDialog *)self;
int verbosity = vlc_atomic_get( &dialog->verbosity ); int verbosity = vlc_atomic_get( &dialog->verbosity );
if( verbosity < 0 || verbosity < (item->i_type - VLC_MSG_ERR) ) if( verbosity < 0 || verbosity < (item->i_type - VLC_MSG_ERR) )
......
...@@ -48,13 +48,12 @@ private: ...@@ -48,13 +48,12 @@ private:
Ui::messagesPanelWidget ui; Ui::messagesPanelWidget ui;
msg_subscription_t *sub; msg_subscription_t *sub;
msg_cb_data_t *cbData; static void sinkMessage( void *, msg_item_t *, unsigned );
static void sinkMessage( msg_cb_data_t *, msg_item_t *, unsigned );
void customEvent( QEvent * ); void customEvent( QEvent * );
void sinkMessage( const MsgEvent * ); void sinkMessage( const MsgEvent * );
vlc_atomic_t verbosity; vlc_atomic_t verbosity;
static void MsgCallback( msg_cb_data_t *, const msg_item_t * ); static void MsgCallback( void *, const msg_item_t * );
QStringList filter; QStringList filter;
bool filterDefault; bool filterDefault;
......
...@@ -72,20 +72,14 @@ ...@@ -72,20 +72,14 @@
#include <syslog.h> #include <syslog.h>
#endif #endif
struct msg_cb_data_t
{
intf_thread_t *p_intf;
FILE *p_file;
int i_mode;
};
/***************************************************************************** /*****************************************************************************
* intf_sys_t: description and status of log interface * intf_sys_t: description and status of log interface
*****************************************************************************/ *****************************************************************************/
struct intf_sys_t struct intf_sys_t
{ {
msg_subscription_t *p_sub; msg_subscription_t *p_sub;
msg_cb_data_t msg; FILE *p_file;
int i_mode;
}; };
/***************************************************************************** /*****************************************************************************
...@@ -94,7 +88,7 @@ struct intf_sys_t ...@@ -94,7 +88,7 @@ struct intf_sys_t
static int Open ( vlc_object_t * ); static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * ); static void Close ( vlc_object_t * );
static void Overflow (msg_cb_data_t *p_sys, const msg_item_t *p_item); static void Overflow (void *p_sys, const msg_item_t *p_item);
static void TextPrint ( const msg_item_t *, FILE * ); static void TextPrint ( const msg_item_t *, FILE * );
static void HtmlPrint ( const msg_item_t *, FILE * ); static void HtmlPrint ( const msg_item_t *, FILE * );
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
...@@ -201,8 +195,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -201,8 +195,7 @@ static int Open( vlc_object_t *p_this )
if( p_sys == NULL ) if( p_sys == NULL )
return VLC_ENOMEM; return VLC_ENOMEM;
p_sys->msg.p_intf = p_intf; p_sys->i_mode = MODE_TEXT;
p_sys->msg.i_mode = MODE_TEXT;
psz_mode = var_InheritString( p_intf, "logmode" ); psz_mode = var_InheritString( p_intf, "logmode" );
if( psz_mode ) if( psz_mode )
{ {
...@@ -210,18 +203,18 @@ static int Open( vlc_object_t *p_this ) ...@@ -210,18 +203,18 @@ static int Open( vlc_object_t *p_this )
; ;
else if( !strcmp( psz_mode, "html" ) ) else if( !strcmp( psz_mode, "html" ) )
{ {
p_sys->msg.i_mode = MODE_HTML; p_sys->i_mode = MODE_HTML;
} }
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
else if( !strcmp( psz_mode, "syslog" ) ) else if( !strcmp( psz_mode, "syslog" ) )
{ {
p_sys->msg.i_mode = MODE_SYSLOG; p_sys->i_mode = MODE_SYSLOG;
} }
#endif #endif
else else
{ {
msg_Warn( p_intf, "invalid log mode `%s', using `text'", psz_mode ); msg_Warn( p_intf, "invalid log mode `%s', using `text'", psz_mode );
p_sys->msg.i_mode = MODE_TEXT; p_sys->i_mode = MODE_TEXT;
} }
free( psz_mode ); free( psz_mode );
} }
...@@ -230,7 +223,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -230,7 +223,7 @@ static int Open( vlc_object_t *p_this )
msg_Warn( p_intf, "no log mode specified, using `text'" ); msg_Warn( p_intf, "no log mode specified, using `text'" );
} }
if( p_sys->msg.i_mode != MODE_SYSLOG ) if( p_sys->i_mode != MODE_SYSLOG )
{ {
char *psz_file = var_InheritString( p_intf, "logfile" ); char *psz_file = var_InheritString( p_intf, "logfile" );
if( !psz_file ) if( !psz_file )
...@@ -239,12 +232,12 @@ static int Open( vlc_object_t *p_this ) ...@@ -239,12 +232,12 @@ static int Open( vlc_object_t *p_this )
char *home = config_GetUserDir(VLC_DOCUMENTS_DIR); char *home = config_GetUserDir(VLC_DOCUMENTS_DIR);
if( home == NULL if( home == NULL
|| asprintf( &psz_file, "%s/"LOG_DIR"/%s", home, || asprintf( &psz_file, "%s/"LOG_DIR"/%s", home,
(p_sys->msg.i_mode == MODE_HTML) ? LOG_FILE_HTML (p_sys->i_mode == MODE_HTML) ? LOG_FILE_HTML
: LOG_FILE_TEXT ) == -1 ) : LOG_FILE_TEXT ) == -1 )
psz_file = NULL; psz_file = NULL;
free(home); free(home);
#else #else
switch( p_sys->msg.i_mode ) switch( p_sys->i_mode )
{ {
case MODE_HTML: case MODE_HTML:
psz_file = strdup( LOG_FILE_HTML ); psz_file = strdup( LOG_FILE_HTML );
...@@ -261,33 +254,33 @@ static int Open( vlc_object_t *p_this ) ...@@ -261,33 +254,33 @@ static int Open( vlc_object_t *p_this )
/* Open the log file and remove any buffering for the stream */ /* Open the log file and remove any buffering for the stream */
msg_Dbg( p_intf, "opening logfile `%s'", psz_file ); msg_Dbg( p_intf, "opening logfile `%s'", psz_file );
p_sys->msg.p_file = vlc_fopen( psz_file, "at" ); p_sys->p_file = vlc_fopen( psz_file, "at" );
if( p_sys->msg.p_file == NULL ) if( p_sys->p_file == NULL )
{ {
msg_Err( p_intf, "error opening logfile `%s'", psz_file ); msg_Err( p_intf, "error opening logfile `%s'", psz_file );
free( p_sys ); free( p_sys );
free( psz_file ); free( psz_file );
return -1; return -1;
} }
setvbuf( p_sys->msg.p_file, NULL, _IONBF, 0 ); setvbuf( p_sys->p_file, NULL, _IONBF, 0 );
free( psz_file ); free( psz_file );
switch( p_sys->msg.i_mode ) switch( p_sys->i_mode )
{ {
case MODE_HTML: case MODE_HTML:
fputs( HTML_HEADER, p_sys->msg.p_file ); fputs( HTML_HEADER, p_sys->p_file );
break; break;
case MODE_TEXT: case MODE_TEXT:
default: default:
fputs( TEXT_HEADER, p_sys->msg.p_file ); fputs( TEXT_HEADER, p_sys->p_file );
break; break;
} }
} }
else else
{ {
p_sys->msg.p_file = NULL; p_sys->p_file = NULL;
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
int i_facility; int i_facility;
char *psz_facility = var_InheritString( p_intf, "syslog-facility" ); char *psz_facility = var_InheritString( p_intf, "syslog-facility" );
...@@ -322,7 +315,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -322,7 +315,7 @@ static int Open( vlc_object_t *p_this )
#endif #endif
} }
p_sys->p_sub = vlc_Subscribe( Overflow, &p_sys->msg ); p_sys->p_sub = vlc_Subscribe( Overflow, p_intf );
return 0; return 0;
} }
...@@ -339,10 +332,10 @@ static void Close( vlc_object_t *p_this ) ...@@ -339,10 +332,10 @@ static void Close( vlc_object_t *p_this )
/* FIXME: flush */ /* FIXME: flush */
vlc_Unsubscribe( p_sys->p_sub ); vlc_Unsubscribe( p_sys->p_sub );
switch( p_sys->msg.i_mode ) switch( p_sys->i_mode )
{ {
case MODE_HTML: case MODE_HTML:
fputs( HTML_FOOTER, p_sys->msg.p_file ); fputs( HTML_FOOTER, p_sys->p_file );
break; break;
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
case MODE_SYSLOG: case MODE_SYSLOG:
...@@ -351,13 +344,13 @@ static void Close( vlc_object_t *p_this ) ...@@ -351,13 +344,13 @@ static void Close( vlc_object_t *p_this )
#endif #endif
case MODE_TEXT: case MODE_TEXT:
default: default:
fputs( TEXT_FOOTER, p_sys->msg.p_file ); fputs( TEXT_FOOTER, p_sys->p_file );
break; break;
} }
/* Close the log file */ /* Close the log file */
if( p_sys->msg.p_file ) if( p_sys->p_file )
fclose( p_sys->msg.p_file ); fclose( p_sys->p_file );
/* Destroy structure */ /* Destroy structure */
free( p_sys ); free( p_sys );
...@@ -366,11 +359,14 @@ static void Close( vlc_object_t *p_this ) ...@@ -366,11 +359,14 @@ static void Close( vlc_object_t *p_this )
/** /**
* Log a message * Log a message
*/ */
static void Overflow (msg_cb_data_t *p_sys, const msg_item_t *p_item) static void Overflow (void *opaque, const msg_item_t *p_item)
{ {
int verbosity = var_InheritInteger( p_sys->p_intf, "log-verbose" ); intf_thread_t *p_intf = opaque;
intf_sys_t *p_sys = p_intf->p_sys;
int verbosity = var_InheritInteger( p_intf, "log-verbose" );
if (verbosity == -1) if (verbosity == -1)
verbosity = var_InheritInteger( p_sys->p_intf, "verbose" ); verbosity = var_InheritInteger( p_intf, "verbose" );
switch( p_item->i_type ) switch( p_item->i_type )
{ {
......
...@@ -40,16 +40,18 @@ ...@@ -40,16 +40,18 @@
* -- some character, Beneath a Steel Sky * -- some character, Beneath a Steel Sky
*/ */
struct msg_cb_data_t typedef struct
{ {
vlc_spinlock_t lock; vlc_spinlock_t lock;
msg_item_t *items[VLC_MSG_QSIZE]; msg_item_t *items[VLC_MSG_QSIZE];
unsigned count; unsigned count;
int verbosity; int verbosity;
}; } msg_cb_data_t;
static void handler( msg_cb_data_t *d, const msg_item_t *p_item ) static void handler( void *opaque, const msg_item_t *p_item )
{ {
msg_cb_data_t *d = opaque;
if (p_item->i_type > d->verbosity) if (p_item->i_type > d->verbosity)
return; return;
......
...@@ -66,7 +66,7 @@ struct msg_subscription_t ...@@ -66,7 +66,7 @@ struct msg_subscription_t
{ {
msg_subscription_t *prev, *next; msg_subscription_t *prev, *next;
msg_callback_t func; msg_callback_t func;
msg_cb_data_t *opaque; void *opaque;
}; };
/** /**
...@@ -78,7 +78,7 @@ struct msg_subscription_t ...@@ -78,7 +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 *vlc_Subscribe (msg_callback_t cb, msg_cb_data_t *opaque) msg_subscription_t *vlc_Subscribe (msg_callback_t cb, void *opaque)
{ {
msg_subscription_t *sub = malloc (sizeof (*sub)); msg_subscription_t *sub = malloc (sizeof (*sub));
if (sub == NULL) if (sub == NULL)
......
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