[vlc-commits] msg_Subscribe: expose structure to plugins
Rémi Denis-Courmont
git at videolan.org
Wed Apr 18 23:13:41 CEST 2012
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Apr 18 23:31:19 2012 +0300| [88bc3a7ec71a49635b9986925616b7e0d7342c05] | committer: Rémi Denis-Courmont
msg_Subscribe: expose structure to plugins
This eliminates one error case that nobody dealt with anyway.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=88bc3a7ec71a49635b9986925616b7e0d7342c05
---
include/vlc_interface.h | 17 +++++++++++------
modules/gui/macosx/intf.h | 2 +-
modules/gui/macosx/intf.m | 4 ++--
modules/gui/ncurses.c | 6 +++---
modules/gui/qt4/dialogs/messages.cpp | 4 ++--
modules/gui/qt4/dialogs/messages.hpp | 2 +-
modules/misc/logger.c | 6 +++---
src/misc/messages.c | 17 +----------------
8 files changed, 24 insertions(+), 34 deletions(-)
diff --git a/include/vlc_interface.h b/include/vlc_interface.h
index 2acf5aa..14898e3 100644
--- a/include/vlc_interface.h
+++ b/include/vlc_interface.h
@@ -108,18 +108,23 @@ VLC_API void libvlc_Quit( libvlc_int_t * );
*/
/**
- * Used by interface plugins which subscribe to the message bank.
- */
-typedef struct msg_subscription_t msg_subscription_t;
-
-/**
* Message logging callback signature.
* Accepts one private data pointer, the message, and an overrun counter.
*/
typedef void (*msg_callback_t) (void *, int, const msg_item_t *,
const char *, va_list);
-VLC_API msg_subscription_t *vlc_Subscribe(msg_callback_t, void *) VLC_USED;
+/**
+ * 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_Subscribe(msg_subscription_t *, msg_callback_t, void *);
VLC_API void vlc_Unsubscribe(msg_subscription_t *);
/*@}*/
diff --git a/modules/gui/macosx/intf.h b/modules/gui/macosx/intf.h
index b1ec6c0..46d93e9 100644
--- a/modules/gui/macosx/intf.h
+++ b/modules/gui/macosx/intf.h
@@ -75,7 +75,7 @@ struct intf_sys_t
bool b_vout_update;
/* The messages window */
- msg_subscription_t * p_sub;
+ msg_subscription_t sub;
};
/*****************************************************************************
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index b005ebc..e06299b 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -106,7 +106,7 @@ int OpenIntf ( vlc_object_t *p_this )
memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
/* subscribe to LibVLCCore's messages */
- p_intf->p_sys->p_sub = vlc_Subscribe( MsgCallback, NULL );
+ vlc_Subscribe( &p_intf->p_sys->sub, MsgCallback, NULL );
p_intf->pf_run = Run;
p_intf->b_should_run_on_first_thread = true;
@@ -775,7 +775,7 @@ static VLCMain *_o_sharedMainInstance = nil;
[o_eyetv release];
/* unsubscribe from libvlc's debug messages */
- vlc_Unsubscribe( p_intf->p_sys->p_sub );
+ vlc_Unsubscribe( &p_intf->p_sys->sub );
[o_msg_arr removeAllObjects];
[o_msg_arr release];
diff --git a/modules/gui/ncurses.c b/modules/gui/ncurses.c
index ec5319e..bf082e1 100644
--- a/modules/gui/ncurses.c
+++ b/modules/gui/ncurses.c
@@ -190,7 +190,7 @@ struct intf_sys_t
int box_start; // first line of box displayed
int box_idx; // selected line
- msg_subscription_t *sub; // message bank subscription
+ msg_subscription_t sub; // message bank subscription
struct
{
int type;
@@ -1789,7 +1789,7 @@ static int Open(vlc_object_t *p_this)
vlc_mutex_init(&sys->pl_lock);
sys->verbosity = var_InheritInteger(intf, "verbose");
- sys->sub = vlc_Subscribe(MsgCallback, sys);
+ vlc_Subscribe(&sys->sub, MsgCallback, sys);
sys->box_type = BOX_PLAYLIST;
sys->plidx_follow = true;
@@ -1842,7 +1842,7 @@ static void Close(vlc_object_t *p_this)
endwin(); /* Close the ncurses interface */
- vlc_Unsubscribe(sys->sub);
+ vlc_Unsubscribe(&sys->sub);
vlc_mutex_destroy(&sys->msg_lock);
vlc_mutex_destroy(&sys->pl_lock);
for(unsigned i = 0; i < sizeof sys->msgs / sizeof *sys->msgs; i++) {
diff --git a/modules/gui/qt4/dialogs/messages.cpp b/modules/gui/qt4/dialogs/messages.cpp
index 8a416b8..c711ed0 100644
--- a/modules/gui/qt4/dialogs/messages.cpp
+++ b/modules/gui/qt4/dialogs/messages.cpp
@@ -121,13 +121,13 @@ MessagesDialog::MessagesDialog( intf_thread_t *_p_intf)
readSettings( "Messages", QSize( 600, 450 ) );
/* Hook up to LibVLC messaging */
- sub = vlc_Subscribe( MsgCallback, this );
+ vlc_Subscribe( &sub, MsgCallback, this );
}
MessagesDialog::~MessagesDialog()
{
writeSettings( "Messages" );
- vlc_Unsubscribe( sub );
+ vlc_Unsubscribe( &sub );
};
void MessagesDialog::changeVerbosity( int i_verbosity )
diff --git a/modules/gui/qt4/dialogs/messages.hpp b/modules/gui/qt4/dialogs/messages.hpp
index 2f4995a..d8b1157 100644
--- a/modules/gui/qt4/dialogs/messages.hpp
+++ b/modules/gui/qt4/dialogs/messages.hpp
@@ -48,7 +48,7 @@ private:
virtual ~MessagesDialog();
Ui::messagesPanelWidget ui;
- msg_subscription_t *sub;
+ msg_subscription_t sub;
static void sinkMessage( void *, msg_item_t *, unsigned );
void customEvent( QEvent * );
void sinkMessage( const MsgEvent * );
diff --git a/modules/misc/logger.c b/modules/misc/logger.c
index 3652d94..4eed615 100644
--- a/modules/misc/logger.c
+++ b/modules/misc/logger.c
@@ -74,7 +74,7 @@
*****************************************************************************/
struct intf_sys_t
{
- msg_subscription_t *p_sub;
+ msg_subscription_t sub;
FILE *p_file;
const char *footer;
};
@@ -298,7 +298,7 @@ static int Open( vlc_object_t *p_this )
fputs( header, p_sys->p_file );
}
- p_sys->p_sub = vlc_Subscribe( cb, p_intf );
+ vlc_Subscribe( &p_sys->sub, cb, p_intf );
return VLC_SUCCESS;
}
@@ -311,7 +311,7 @@ static void Close( vlc_object_t *p_this )
intf_sys_t *p_sys = p_intf->p_sys;
/* Flush the queue and unsubscribe from the message queue */
- vlc_Unsubscribe( p_sys->p_sub );
+ vlc_Unsubscribe( &p_sys->sub );
/* Close the log file */
#ifdef HAVE_SYSLOG_H
diff --git a/src/misc/messages.c b/src/misc/messages.c
index c2f9820..f061436 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -55,13 +55,6 @@
vlc_rwlock_t msg_lock = VLC_STATIC_RWLOCK;
msg_subscription_t *msg_head;
-struct msg_subscription_t
-{
- msg_subscription_t *prev, *next;
- msg_callback_t func;
- void *opaque;
-};
-
/**
* Subscribe to the message queue.
* Whenever a message is emitted, a callback will be called.
@@ -69,14 +62,9 @@ struct msg_subscription_t
*
* @param cb callback function
* @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, void *opaque)
+void vlc_Subscribe (msg_subscription_t *sub, msg_callback_t cb, void *opaque)
{
- msg_subscription_t *sub = malloc (sizeof (*sub));
- if (sub == NULL)
- return NULL;
-
sub->prev = NULL;
sub->func = cb;
sub->opaque = opaque;
@@ -85,8 +73,6 @@ msg_subscription_t *vlc_Subscribe (msg_callback_t cb, void *opaque)
sub->next = msg_head;
msg_head = sub;
vlc_rwlock_unlock (&msg_lock);
-
- return sub;
}
/**
@@ -106,7 +92,6 @@ void vlc_Unsubscribe (msg_subscription_t *sub)
msg_head = sub->next;
}
vlc_rwlock_unlock (&msg_lock);
- free (sub);
}
/**
More information about the vlc-commits
mailing list