]> git.sesse.net Git - vlc/commitdiff
Remove msg_cb_data_t and simplify accordingly
authorRémi Denis-Courmont <remi@remlab.net>
Fri, 19 Aug 2011 19:27:41 +0000 (22:27 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Fri, 19 Aug 2011 20:38:37 +0000 (23:38 +0300)
include/vlc_messages.h
modules/gui/macosx/intf.m
modules/gui/ncurses.c
modules/gui/qt4/dialogs/messages.cpp
modules/gui/qt4/dialogs/messages.hpp
modules/misc/logger.c
src/control/log.c
src/misc/messages.c

index 9f8ffde160cc57790efe21a5ee87e7147e624009..7e02df3dfb1652777d2319c542ede2266e1c4e47 100644 (file)
@@ -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 *);
 
 /**
index cf1457ed881770a5e97515bc615de7b723627464..be31ab3961e4d2f60253f4a095cd0c52d836bea4 100644 (file)
@@ -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();
 
index d5d4cb84fa3c3b23f184c08f020680b4de34adab..c7125749c06a918519902639577f5077e4553454 100644 (file)
@@ -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;
index cca9738f924f181ff9378dff6d4cec49853502b4..3fcd53c88c945e8210a83445833ad16d9c52adc2 100644 (file)
@@ -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) )
index 81930e7d37385e92a973f68ce1289e80850b7a30..bc1693396c667d9996049c87087b2991fdd8c51e 100644 (file)
@@ -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;
index 14357645a1e51711e301942c4a0da80a262bfdc5..38b983693d7b9f70cbd1e0a6c0a705b1410957e7 100644 (file)
 #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 )
     {
index dc81a35934ccb4f7d4710954af53ae383c62fd82..e678a42a45b4706668a23ade324466f384bf99a2 100644 (file)
  *   -- 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;
 
index 74aeabf6236f3adc6f890f13dc23daf4a178cd42..708e50f9384a05d7e8dd7fc3a0c6fe229208d186 100644 (file)
@@ -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)