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,
#define msg_Dbg( p_this, ... ) \
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.
* 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 *);
/**
......
......@@ -70,7 +70,7 @@ static void updateProgressPanel (void *, const char *, float);
static bool checkProgressPanel (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 *,
vlc_value_t, vlc_value_t, void * );
......@@ -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
* 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();
......
......@@ -221,11 +221,6 @@ struct intf_sys_t
};
struct msg_cb_data_t
{
intf_sys_t *p_sys;
};
/*****************************************************************************
* Directories
*****************************************************************************/
......@@ -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
|| p_sys->i_verbosity < (msg->i_type - VLC_MSG_ERR))
......@@ -1883,25 +1878,16 @@ static int Open(vlc_object_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));
struct msg_cb_data_t *msg_cb_data;
if (!p_sys)
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->pl_lock);
memset(p_sys->msgs, 0, sizeof p_sys->msgs);
p_sys->i_msgs = 0;
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->b_plidx_follow = true;
......
......@@ -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)
: QVLCFrame( _p_intf )
{
......@@ -126,16 +121,13 @@ MessagesDialog::MessagesDialog( intf_thread_t *_p_intf)
readSettings( "Messages", QSize( 600, 450 ) );
/* Hook up to LibVLC messaging */
cbData = new msg_cb_data_t;
cbData->self = this;
sub = vlc_Subscribe( MsgCallback, cbData );
sub = vlc_Subscribe( MsgCallback, this );
}
MessagesDialog::~MessagesDialog()
{
writeSettings( "Messages" );
vlc_Unsubscribe( sub );
delete cbData;
};
void MessagesDialog::changeVerbosity( int verbosity )
......@@ -307,9 +299,9 @@ void MessagesDialog::tabChanged( int i )
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 );
if( verbosity < 0 || verbosity < (item->i_type - VLC_MSG_ERR) )
......
......@@ -48,13 +48,12 @@ private:
Ui::messagesPanelWidget ui;
msg_subscription_t *sub;
msg_cb_data_t *cbData;
static void sinkMessage( msg_cb_data_t *, msg_item_t *, unsigned );
static void sinkMessage( void *, msg_item_t *, unsigned );
void customEvent( QEvent * );
void sinkMessage( const MsgEvent * );
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;
bool filterDefault;
......
......@@ -72,20 +72,14 @@
#include <syslog.h>
#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
*****************************************************************************/
struct intf_sys_t
{
msg_subscription_t *p_sub;
msg_cb_data_t msg;
FILE *p_file;
int i_mode;
};
/*****************************************************************************
......@@ -94,7 +88,7 @@ struct intf_sys_t
static int Open ( 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 HtmlPrint ( const msg_item_t *, FILE * );
#ifdef HAVE_SYSLOG_H
......@@ -201,8 +195,7 @@ static int Open( vlc_object_t *p_this )
if( p_sys == NULL )
return VLC_ENOMEM;
p_sys->msg.p_intf = p_intf;
p_sys->msg.i_mode = MODE_TEXT;
p_sys->i_mode = MODE_TEXT;
psz_mode = var_InheritString( p_intf, "logmode" );
if( psz_mode )
{
......@@ -210,18 +203,18 @@ static int Open( vlc_object_t *p_this )
;
else if( !strcmp( psz_mode, "html" ) )
{
p_sys->msg.i_mode = MODE_HTML;
p_sys->i_mode = MODE_HTML;
}
#ifdef HAVE_SYSLOG_H
else if( !strcmp( psz_mode, "syslog" ) )
{
p_sys->msg.i_mode = MODE_SYSLOG;
p_sys->i_mode = MODE_SYSLOG;
}
#endif
else
{
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 );
}
......@@ -230,7 +223,7 @@ static int Open( vlc_object_t *p_this )
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" );
if( !psz_file )
......@@ -239,12 +232,12 @@ static int Open( vlc_object_t *p_this )
char *home = config_GetUserDir(VLC_DOCUMENTS_DIR);
if( home == NULL
|| 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 )
psz_file = NULL;
free(home);
#else
switch( p_sys->msg.i_mode )
switch( p_sys->i_mode )
{
case MODE_HTML:
psz_file = strdup( LOG_FILE_HTML );
......@@ -261,33 +254,33 @@ static int Open( vlc_object_t *p_this )
/* Open the log file and remove any buffering for the stream */
msg_Dbg( p_intf, "opening logfile `%s'", psz_file );
p_sys->msg.p_file = vlc_fopen( psz_file, "at" );
if( p_sys->msg.p_file == NULL )
p_sys->p_file = vlc_fopen( psz_file, "at" );
if( p_sys->p_file == NULL )
{
msg_Err( p_intf, "error opening logfile `%s'", psz_file );
free( p_sys );
free( psz_file );
return -1;
}
setvbuf( p_sys->msg.p_file, NULL, _IONBF, 0 );
setvbuf( p_sys->p_file, NULL, _IONBF, 0 );
free( psz_file );
switch( p_sys->msg.i_mode )
switch( p_sys->i_mode )
{
case MODE_HTML:
fputs( HTML_HEADER, p_sys->msg.p_file );
fputs( HTML_HEADER, p_sys->p_file );
break;
case MODE_TEXT:
default:
fputs( TEXT_HEADER, p_sys->msg.p_file );
fputs( TEXT_HEADER, p_sys->p_file );
break;
}
}
else
{
p_sys->msg.p_file = NULL;
p_sys->p_file = NULL;
#ifdef HAVE_SYSLOG_H
int i_facility;
char *psz_facility = var_InheritString( p_intf, "syslog-facility" );
......@@ -322,7 +315,7 @@ static int Open( vlc_object_t *p_this )
#endif
}
p_sys->p_sub = vlc_Subscribe( Overflow, &p_sys->msg );
p_sys->p_sub = vlc_Subscribe( Overflow, p_intf );
return 0;
}
......@@ -339,10 +332,10 @@ static void Close( vlc_object_t *p_this )
/* FIXME: flush */
vlc_Unsubscribe( p_sys->p_sub );
switch( p_sys->msg.i_mode )
switch( p_sys->i_mode )
{
case MODE_HTML:
fputs( HTML_FOOTER, p_sys->msg.p_file );
fputs( HTML_FOOTER, p_sys->p_file );
break;
#ifdef HAVE_SYSLOG_H
case MODE_SYSLOG:
......@@ -351,13 +344,13 @@ static void Close( vlc_object_t *p_this )
#endif
case MODE_TEXT:
default:
fputs( TEXT_FOOTER, p_sys->msg.p_file );
fputs( TEXT_FOOTER, p_sys->p_file );
break;
}
/* Close the log file */
if( p_sys->msg.p_file )
fclose( p_sys->msg.p_file );
if( p_sys->p_file )
fclose( p_sys->p_file );
/* Destroy structure */
free( p_sys );
......@@ -366,11 +359,14 @@ static void Close( vlc_object_t *p_this )
/**
* 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)
verbosity = var_InheritInteger( p_sys->p_intf, "verbose" );
verbosity = var_InheritInteger( p_intf, "verbose" );
switch( p_item->i_type )
{
......
......@@ -40,16 +40,18 @@
* -- some character, Beneath a Steel Sky
*/
struct msg_cb_data_t
typedef struct
{
vlc_spinlock_t lock;
msg_item_t *items[VLC_MSG_QSIZE];
unsigned count;
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)
return;
......
......@@ -66,7 +66,7 @@ struct msg_subscription_t
{
msg_subscription_t *prev, *next;
msg_callback_t func;
msg_cb_data_t *opaque;
void *opaque;
};
/**
......@@ -78,7 +78,7 @@ struct msg_subscription_t
* @param opaque data for the callback function
* @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));
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