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

Privatize msg_bank

parent 40f43d32
...@@ -130,8 +130,6 @@ typedef struct dict_t dict_t; ...@@ -130,8 +130,6 @@ typedef struct dict_t dict_t;
typedef struct gc_object_t gc_object_t ; typedef struct gc_object_t gc_object_t ;
/* Messages */ /* Messages */
typedef struct msg_bank_t msg_bank_t;
typedef struct msg_queue_t msg_queue_t;
typedef struct msg_subscription_t msg_subscription_t; typedef struct msg_subscription_t msg_subscription_t;
/* Playlist */ /* Playlist */
......
...@@ -57,11 +57,6 @@ struct libvlc_int_t ...@@ -57,11 +57,6 @@ struct libvlc_int_t
input_item_array_t input_items; ///< Array of all created input items input_item_array_t input_items; ///< Array of all created input items
int i_last_input_id ; ///< Last id of input item int i_last_input_id ; ///< Last id of input item
/* Messages */
msg_bank_t msg_bank; ///< The message bank
int i_verbose; ///< info messages
bool b_color; ///< color messages?
/* Structure storing the action name / key associations */ /* Structure storing the action name / key associations */
struct hotkey struct hotkey
{ {
......
...@@ -79,39 +79,6 @@ typedef struct ...@@ -79,39 +79,6 @@ typedef struct
#define MSG_QUEUE_NORMAL 0 #define MSG_QUEUE_NORMAL 0
#define MSG_QUEUE_HTTPD_ACCESS 1 #define MSG_QUEUE_HTTPD_ACCESS 1
#define NB_QUEUES 2
struct msg_queue_t
{
int i_id;
/** Message queue lock */
vlc_mutex_t lock;
bool b_overflow;
/* Message queue */
msg_item_t msg[VLC_MSG_QSIZE]; /**< message queue */
int i_start;
int i_stop;
/* Subscribers */
int i_sub;
msg_subscription_t **pp_sub;
/* Logfile for WinCE */
#ifdef UNDER_CE
FILE *logfile;
#endif
};
/**
* Store all data requiered by messages interfaces.
*/
struct msg_bank_t
{
vlc_mutex_t lock;
msg_queue_t queues[NB_QUEUES];
};
/** /**
* Used by interface plugins which subscribe to the message bank. * Used by interface plugins which subscribe to the message bank.
......
...@@ -190,13 +190,13 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -190,13 +190,13 @@ libvlc_int_t * libvlc_InternalCreate( void )
/* Find verbosity from VLC_VERBOSE environment variable */ /* Find verbosity from VLC_VERBOSE environment variable */
psz_env = getenv( "VLC_VERBOSE" ); psz_env = getenv( "VLC_VERBOSE" );
if( psz_env != NULL ) if( psz_env != NULL )
p_libvlc->i_verbose = atoi( psz_env ); priv->i_verbose = atoi( psz_env );
else else
p_libvlc->i_verbose = 3; priv->i_verbose = 3;
#if defined( HAVE_ISATTY ) && !defined( WIN32 ) #if defined( HAVE_ISATTY ) && !defined( WIN32 )
p_libvlc->b_color = isatty( 2 ); /* 2 is for stderr */ priv->b_color = isatty( 2 ); /* 2 is for stderr */
#else #else
p_libvlc->b_color = false; priv->b_color = false;
#endif #endif
/* Announce who we are - Do it only for first instance ? */ /* Announce who we are - Do it only for first instance ? */
...@@ -313,7 +313,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -313,7 +313,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
} }
/* Will be re-done properly later on */ /* Will be re-done properly later on */
p_libvlc->i_verbose = config_GetInt( p_libvlc, "verbose" ); priv->i_verbose = config_GetInt( p_libvlc, "verbose" );
/* Check for daemon mode */ /* Check for daemon mode */
#ifndef WIN32 #ifndef WIN32
...@@ -656,8 +656,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -656,8 +656,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
var_AddCallback( p_libvlc, "verbose", VerboseCallback, NULL ); var_AddCallback( p_libvlc, "verbose", VerboseCallback, NULL );
var_Change( p_libvlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL ); var_Change( p_libvlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
if( p_libvlc->b_color ) if( priv->b_color )
p_libvlc->b_color = config_GetInt( p_libvlc, "color" ) > 0; priv->b_color = config_GetInt( p_libvlc, "color" ) > 0;
/* /*
* Output messages that may still be in the queue * Output messages that may still be in the queue
...@@ -1973,7 +1973,7 @@ static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -1973,7 +1973,7 @@ static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
if( new_val.i_int >= -1 ) if( new_val.i_int >= -1 )
{ {
p_libvlc->i_verbose = __MIN( new_val.i_int, 2 ); libvlc_priv (p_libvlc)->i_verbose = __MIN( new_val.i_int, 2 );
} }
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -72,6 +72,44 @@ extern vlc_threadvar_t msg_context_global_key; ...@@ -72,6 +72,44 @@ extern vlc_threadvar_t msg_context_global_key;
extern uint32_t cpu_flags; extern uint32_t cpu_flags;
uint32_t CPUCapabilities( void ); uint32_t CPUCapabilities( void );
/*
* Message/logging stuff
*/
#define NB_QUEUES 2
typedef struct msg_queue_t
{
int i_id;
/** Message queue lock */
vlc_mutex_t lock;
bool b_overflow;
/* Message queue */
msg_item_t msg[VLC_MSG_QSIZE]; /**< message queue */
int i_start;
int i_stop;
/* Subscribers */
int i_sub;
msg_subscription_t **pp_sub;
/* Logfile for WinCE */
#ifdef UNDER_CE
FILE *logfile;
#endif
} msg_queue_t;
/**
* Store all data requiered by messages interfaces.
*/
typedef struct msg_bank_t
{
vlc_mutex_t lock;
msg_queue_t queues[NB_QUEUES];
} msg_bank_t;
/* /*
* Unicode stuff * Unicode stuff
*/ */
...@@ -172,6 +210,12 @@ typedef struct libvlc_priv_t ...@@ -172,6 +210,12 @@ typedef struct libvlc_priv_t
{ {
vlc_mutex_t config_lock; ///< config file lock vlc_mutex_t config_lock; ///< config file lock
/* Messages */
msg_bank_t msg_bank; ///< The message bank
int i_verbose; ///< info messages
bool b_color; ///< color messages?
/* Timer stats */
vlc_mutex_t timer_lock; ///< Lock to protect timers vlc_mutex_t timer_lock; ///< Lock to protect timers
counter_t **pp_timers; ///< Array of all timers counter_t **pp_timers; ///< Array of all timers
int i_timers; ///< Number of timers int i_timers; ///< Number of timers
......
...@@ -66,9 +66,9 @@ ...@@ -66,9 +66,9 @@
# define vlc_va_copy(dest,src) (dest)=(src) # define vlc_va_copy(dest,src) (dest)=(src)
#endif #endif
#define QUEUE(i) p_this->p_libvlc->msg_bank.queues[i] #define QUEUE(i) priv->msg_bank.queues[i]
#define LOCK_BANK vlc_mutex_lock( &p_this->p_libvlc->msg_bank.lock ); #define LOCK_BANK vlc_mutex_lock( &priv->msg_bank.lock );
#define UNLOCK_BANK vlc_mutex_unlock( &p_this->p_libvlc->msg_bank.lock ); #define UNLOCK_BANK vlc_mutex_unlock( &priv->msg_bank.lock );
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
...@@ -84,10 +84,10 @@ static void PrintMsg ( vlc_object_t *, msg_item_t * ); ...@@ -84,10 +84,10 @@ static void PrintMsg ( vlc_object_t *, msg_item_t * );
*/ */
void __msg_Create( vlc_object_t *p_this ) void __msg_Create( vlc_object_t *p_this )
{ {
int i; libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
vlc_mutex_init( &(p_this->p_libvlc->msg_bank.lock) ); vlc_mutex_init( &priv->msg_bank.lock );
for( i = 0; i < 2; i++ ) for( int i = 0; i < 2; i++ )
{ {
vlc_mutex_init( &QUEUE(i).lock ); vlc_mutex_init( &QUEUE(i).lock );
QUEUE(i).b_overflow = false; QUEUE(i).b_overflow = false;
...@@ -112,8 +112,9 @@ void __msg_Create( vlc_object_t *p_this ) ...@@ -112,8 +112,9 @@ void __msg_Create( vlc_object_t *p_this )
*/ */
void __msg_Flush( vlc_object_t *p_this ) void __msg_Flush( vlc_object_t *p_this )
{ {
int i; libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
for( i = 0 ; i < NB_QUEUES ; i++ )
for( int i = 0 ; i < NB_QUEUES ; i++ )
{ {
vlc_mutex_lock( &QUEUE(i).lock ); vlc_mutex_lock( &QUEUE(i).lock );
FlushMsg( &QUEUE(i) ); FlushMsg( &QUEUE(i) );
...@@ -130,8 +131,9 @@ void __msg_Flush( vlc_object_t *p_this ) ...@@ -130,8 +131,9 @@ void __msg_Flush( vlc_object_t *p_this )
*/ */
void __msg_Destroy( vlc_object_t *p_this ) void __msg_Destroy( vlc_object_t *p_this )
{ {
int i; libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
for( i = NB_QUEUES -1 ; i >= 0; i-- )
for( int i = NB_QUEUES -1 ; i >= 0; i-- )
{ {
if( QUEUE(i).i_sub ) if( QUEUE(i).i_sub )
msg_Err( p_this, "stale interface subscribers" ); msg_Err( p_this, "stale interface subscribers" );
...@@ -145,7 +147,7 @@ void __msg_Destroy( vlc_object_t *p_this ) ...@@ -145,7 +147,7 @@ void __msg_Destroy( vlc_object_t *p_this )
/* Destroy lock */ /* Destroy lock */
vlc_mutex_destroy( &QUEUE(i).lock ); vlc_mutex_destroy( &QUEUE(i).lock );
} }
vlc_mutex_destroy( &(p_this->p_libvlc->msg_bank.lock) ); vlc_mutex_destroy( &priv->msg_bank.lock);
} }
/** /**
...@@ -153,8 +155,12 @@ void __msg_Destroy( vlc_object_t *p_this ) ...@@ -153,8 +155,12 @@ void __msg_Destroy( vlc_object_t *p_this )
*/ */
msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this, int i ) msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this, int i )
{ {
libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
msg_subscription_t *p_sub = malloc( sizeof( msg_subscription_t ) ); msg_subscription_t *p_sub = malloc( sizeof( msg_subscription_t ) );
if (p_sub == NULL)
return NULL;
assert( i < NB_QUEUES ); assert( i < NB_QUEUES );
LOCK_BANK; LOCK_BANK;
...@@ -178,13 +184,13 @@ msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this, int i ) ...@@ -178,13 +184,13 @@ msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this, int i )
*/ */
void __msg_Unsubscribe( vlc_object_t *p_this, msg_subscription_t *p_sub ) void __msg_Unsubscribe( vlc_object_t *p_this, msg_subscription_t *p_sub )
{ {
int i,j; libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
LOCK_BANK; LOCK_BANK;
for( i = 0 ; i< NB_QUEUES ; i++ ) for( int i = 0 ; i< NB_QUEUES ; i++ )
{ {
vlc_mutex_lock( &QUEUE(i).lock ); vlc_mutex_lock( &QUEUE(i).lock );
for( j = 0 ; j< QUEUE(i).i_sub ; j++ ) for( int j = 0 ; j< QUEUE(i).i_sub ; j++ )
{ {
if( QUEUE(i).pp_sub[j] == p_sub ) if( QUEUE(i).pp_sub[j] == p_sub )
{ {
...@@ -262,6 +268,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue, int i_type, ...@@ -262,6 +268,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue, int i_type,
const char *psz_module, const char *psz_module,
const char *psz_format, va_list _args ) const char *psz_format, va_list _args )
{ {
libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
int i_header_size; /* Size of the additionnal header */ int i_header_size; /* Size of the additionnal header */
vlc_object_t *p_obj; vlc_object_t *p_obj;
char * psz_str = NULL; /* formatted message string */ char * psz_str = NULL; /* formatted message string */
...@@ -556,21 +563,22 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item ) ...@@ -556,21 +563,22 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
static const char * ppsz_type[4] = { "", " error", " warning", " debug" }; static const char * ppsz_type[4] = { "", " error", " warning", " debug" };
static const char *ppsz_color[4] = { WHITE, RED, YELLOW, GRAY }; static const char *ppsz_color[4] = { WHITE, RED, YELLOW, GRAY };
const char *psz_object; const char *psz_object;
libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
int i_type = p_item->i_type; int i_type = p_item->i_type;
switch( i_type ) switch( i_type )
{ {
case VLC_MSG_ERR: case VLC_MSG_ERR:
if( p_this->p_libvlc->i_verbose < 0 ) return; if( priv->i_verbose < 0 ) return;
break; break;
case VLC_MSG_INFO: case VLC_MSG_INFO:
if( p_this->p_libvlc->i_verbose < 0 ) return; if( priv->i_verbose < 0 ) return;
break; break;
case VLC_MSG_WARN: case VLC_MSG_WARN:
if( p_this->p_libvlc->i_verbose < 1 ) return; if( priv->i_verbose < 1 ) return;
break; break;
case VLC_MSG_DBG: case VLC_MSG_DBG:
if( p_this->p_libvlc->i_verbose < 2 ) return; if( priv->i_verbose < 2 ) return;
break; break;
} }
...@@ -590,7 +598,7 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item ) ...@@ -590,7 +598,7 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
#else #else
/* Send the message to stderr */ /* Send the message to stderr */
if( p_this->p_libvlc->b_color ) if( priv->b_color )
{ {
if( p_item->psz_header ) if( p_item->psz_header )
{ {
......
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