Commit a0783549 authored by Clément Stenac's avatar Clément Stenac

Add support for several message queues - please test

Initial support for registering and handling some shared stats 
parent d68a17b3
......@@ -455,6 +455,7 @@ SOURCES_libvlc_common = \
src/misc/block.c \
src/misc/modules.c \
src/misc/threads.c \
src/misc/stats.c \
src/misc/unicode.c \
src/misc/cpu.c \
src/misc/configuration.c \
......
......@@ -205,6 +205,7 @@ typedef struct date_t date_t;
/* 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;
/* Playlist */
......@@ -415,6 +416,10 @@ typedef struct vlm_schedule_t vlm_schedule_t;
/* divers */
typedef struct vlc_meta_t vlc_meta_t;
typedef struct counter_t counter_t;
typedef struct counter_sample_t counter_sample_t;
typedef struct stats_handler_t stats_handler_t;
/*****************************************************************************
* Variable callbacks
......
......@@ -45,12 +45,7 @@ typedef struct
char * psz_module;
char * psz_msg; /**< the message itself */
#if 0
mtime_t date; /* date of the message */
char * psz_file; /* file in which the function was called */
char * psz_function; /* function from which the function was called */
int i_line; /* line at which the function was called */
#endif
mtime_t date; /**< Message date */
} msg_item_t;
/* Message types */
......@@ -63,14 +58,25 @@ typedef struct
/** debug messages */
#define VLC_MSG_DBG 3
#define MSG_QUEUE_NORMAL 0
#define MSG_QUEUE_HTTPD_ACCESS 1
/**
* Store all data requiered by messages interfaces.
*/
struct msg_bank_t
{
vlc_mutex_t lock;
int i_queues;
msg_queue_t **pp_queues;
};
struct msg_queue_t
{
int i_id;
/** Message queue lock */
vlc_mutex_t lock;
vlc_bool_t b_configured;
vlc_bool_t b_overflow;
/* Message queue */
......@@ -103,9 +109,9 @@ struct msg_subscription_t
/*****************************************************************************
* Prototypes
*****************************************************************************/
VLC_EXPORT( void, __msg_Generic, ( vlc_object_t *, int, const char *, const char *, ... ) ATTRIBUTE_FORMAT( 4, 5 ) );
VLC_EXPORT( void, __msg_GenericVa, ( vlc_object_t *, int, const char *, const char *, va_list args ) );
#define msg_GenericVa(a, b, c, d, e) __msg_GenericVa(VLC_OBJECT(a), b, c, d, e)
VLC_EXPORT( void, __msg_Generic, ( vlc_object_t *, int, int, const char *, const char *, ... ) ATTRIBUTE_FORMAT( 5, 6 ) );
VLC_EXPORT( void, __msg_GenericVa, ( vlc_object_t *, int, int, const char *, const char *, va_list args ) );
#define msg_GenericVa(a, b, c, d, e),f __msg_GenericVa(VLC_OBJECT(a), b, c, d, e,f)
VLC_EXPORT( void, __msg_Info, ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
VLC_EXPORT( void, __msg_Err, ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
VLC_EXPORT( void, __msg_Warn, ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
......@@ -114,19 +120,19 @@ VLC_EXPORT( void, __msg_Dbg, ( vlc_object_t *, const char *, ... ) ATTRIBUTE_
#ifdef HAVE_VARIADIC_MACROS
# define msg_Info( p_this, psz_format, args... ) \
__msg_Generic( VLC_OBJECT(p_this), VLC_MSG_INFO, MODULE_STRING, \
__msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL,VLC_MSG_INFO, MODULE_STRING, \
psz_format, ## args )
# define msg_Err( p_this, psz_format, args... ) \
__msg_Generic( VLC_OBJECT(p_this), VLC_MSG_ERR, MODULE_STRING, \
__msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL, VLC_MSG_ERR, MODULE_STRING, \
psz_format, ## args )
# define msg_Warn( p_this, psz_format, args... ) \
__msg_Generic( VLC_OBJECT(p_this), VLC_MSG_WARN, MODULE_STRING, \
__msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL, VLC_MSG_WARN, MODULE_STRING, \
psz_format, ## args )
# define msg_Dbg( p_this, psz_format, args... ) \
__msg_Generic( VLC_OBJECT(p_this), VLC_MSG_DBG, MODULE_STRING, \
__msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL, VLC_MSG_DBG, MODULE_STRING, \
psz_format, ## args )
#elif defined(_MSC_VER) /* To avoid warnings and even errors with c++ files */
......@@ -135,7 +141,7 @@ inline void msg_Info( void *p_this, const char *psz_format, ... )
{
va_list ap;
va_start( ap, psz_format );
__msg_GenericVa( ( vlc_object_t *)p_this, VLC_MSG_INFO, MODULE_STRING,
__msg_GenericVa( ( vlc_object_t *)p_this, MSG_QUEUE_NORMAL,VLC_MSG_INFO, MODULE_STRING,
psz_format, ap );
va_end(ap);
}
......@@ -143,7 +149,7 @@ inline void msg_Err( void *p_this, const char *psz_format, ... )
{
va_list ap;
va_start( ap, psz_format );
__msg_GenericVa( ( vlc_object_t *)p_this, VLC_MSG_ERR, MODULE_STRING,
__msg_GenericVa( ( vlc_object_t *)p_this,MSG_QUEUE_NORMAL, VLC_MSG_ERR, MODULE_STRING,
psz_format, ap );
va_end(ap);
}
......@@ -151,7 +157,7 @@ inline void msg_Warn( void *p_this, const char *psz_format, ... )
{
va_list ap;
va_start( ap, psz_format );
__msg_GenericVa( ( vlc_object_t *)p_this, VLC_MSG_WARN, MODULE_STRING,
__msg_GenericVa( ( vlc_object_t *)p_this, MSG_QUEUE_NORMAL, VLC_MSG_WARN, MODULE_STRING,
psz_format, ap );
va_end(ap);
}
......@@ -159,7 +165,7 @@ inline void msg_Dbg( void *p_this, const char *psz_format, ... )
{
va_list ap;
va_start( ap, psz_format );
__msg_GenericVa( ( vlc_object_t *)p_this, VLC_MSG_DBG, MODULE_STRING,
__msg_GenericVa( ( vlc_object_t *)p_this, MSG_QUEUE_NORMAL, VLC_MSG_DBG, MODULE_STRING,
psz_format, ap );
va_end(ap);
}
......@@ -180,12 +186,64 @@ void __msg_Create ( vlc_object_t * );
void __msg_Flush ( vlc_object_t * );
void __msg_Destroy ( vlc_object_t * );
#define msg_Subscribe(a) __msg_Subscribe(VLC_OBJECT(a))
#define msg_Subscribe(a,b) __msg_Subscribe(VLC_OBJECT(a),b)
#define msg_Unsubscribe(a,b) __msg_Unsubscribe(VLC_OBJECT(a),b)
VLC_EXPORT( msg_subscription_t*, __msg_Subscribe, ( vlc_object_t * ) );
VLC_EXPORT( msg_subscription_t*, __msg_Subscribe, ( vlc_object_t *, int ) );
VLC_EXPORT( void, __msg_Unsubscribe, ( vlc_object_t *, msg_subscription_t * ) );
/**
* @}
*/
/**
* \defgroup statistics Statistics
*
* @{
*/
enum
{
STATS_LAST,
STATS_COUNTER,
STATS_MAX,
STATS_MIN,
};
struct counter_sample_t
{
vlc_value_t value;
mtime_t date;
};
struct counter_t
{
char * psz_name;
int i_source_object;
int i_compute_type;
int i_type;
int i_samples;
counter_sample_t ** pp_samples;
};
struct stats_handler_t
{
VLC_COMMON_MEMBERS
int i_counters;
counter_t **pp_counters;
};
#define stats_Update( a,b,c) __stats_Update( VLC_OBJECT( a ), b, c )
VLC_EXPORT( int, __stats_Update, (vlc_object_t*, char *, vlc_value_t) );
#define stats_Create( a,b,c,d ) __stats_Create( VLC_OBJECT(a), b, c, d )
VLC_EXPORT( int, __stats_Create, (vlc_object_t*, char *, int, int) );
static inline int __stats_UpdateInteger( vlc_object_t *p_obj, char *psz_name,
int i )
{
vlc_value_t val;
val.i_int = i;
return __stats_Update( p_obj, psz_name, val );
}
#define stats_UpdateInteger( a,b,c ) __stats_UpdateInteger( VLC_OBJECT(a),b,c )
......@@ -60,6 +60,7 @@
#define VLC_OBJECT_SD (-26)
#define VLC_OBJECT_XML (-27)
#define VLC_OBJECT_OSDMENU (-28)
#define VLC_OBJECT_STATS (-29)
#define VLC_OBJECT_GENERIC (-666)
......
......@@ -62,6 +62,7 @@ int playlist_ItemSetName (playlist_item_t *, char *);
void __osd_MenuShow (vlc_object_t *);
httpd_url_t * httpd_UrlNewUnique (httpd_host_t *, const char *psz_url, const char *psz_user, const char *psz_password, const vlc_acl_t *p_acl);
void httpd_ClientModeStream (httpd_client_t *cl);
int __stats_Create (vlc_object_t*, char *, int, int);
void httpd_RedirectDelete (httpd_redirect_t *);
void __sout_CfgParse (vlc_object_t *, char *psz_prefix, const char **ppsz_options, sout_cfg_t *);
vlm_media_t * vlm_MediaNew (vlm_t *, const char *, int);
......@@ -118,6 +119,7 @@ void vlm_MessageDelete (vlm_message_t *);
void vout_SynchroDecode (vout_synchro_t *);
int playlist_Delete (playlist_t *, int);
void aout_FiltersPlay (aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_buffer_t ** pp_input_buffer);
int __stats_Update (vlc_object_t*, char *, vlc_value_t);
char* httpd_ClientIP (httpd_client_t *cl, char *psz_ip);
int __intf_UserProgress (vlc_object_t*, const char*, const char*, float);
void httpd_FileDelete (httpd_file_t *);
......@@ -204,7 +206,7 @@ struct dirent * vlc_readdir_wrapper (void *);
void config_UnsetCallbacks (module_config_t *);
void vout_SynchroRelease (vout_synchro_t *);
void __intf_UserProgressUpdate (vlc_object_t*, int, const char*, float);
void __msg_Generic (vlc_object_t *, int, const char *, const char *, ... ) ATTRIBUTE_FORMAT( 4, 5);
void __msg_Generic (vlc_object_t *, int, int, const char *, const char *, ... ) ATTRIBUTE_FORMAT( 5, 6);
int vlc_closedir_wrapper (void *);
int playlist_ServicesDiscoveryAdd (playlist_t *, const char *);
char * vlc_strndup (const char *s, size_t n);
......@@ -339,7 +341,7 @@ int intf_RunThread (intf_thread_t *);
int httpd_StreamSend (httpd_stream_t *, uint8_t *p_data, int i_data);
decoder_t * input_DecoderNew (input_thread_t *, es_format_t *, vlc_bool_t b_force_decoder);
xml_t * __xml_Create (vlc_object_t *);
msg_subscription_t* __msg_Subscribe (vlc_object_t *);
msg_subscription_t* __msg_Subscribe (vlc_object_t *, int);
const char * VLC_Version (void);
session_descriptor_t* sout_AnnounceRegisterSDP (sout_instance_t *,const char *, const char *, announce_method_t*);
char * stream_ReadLine (stream_t *);
......@@ -380,7 +382,7 @@ char * ToLocale (const char *);
int vlm_Load (vlm_t *, const char *);
int aout_FiltersCreatePipeline (aout_instance_t * p_aout, aout_filter_t ** pp_filters, int * pi_nb_filters, const audio_sample_format_t * p_input_format, const audio_sample_format_t * p_output_format);
playlist_item_t * playlist_ChildSearchName (playlist_item_t*, const char*);
void __msg_GenericVa (vlc_object_t *, int, const char *, const char *, va_list args);
void __msg_GenericVa (vlc_object_t *, int, int, const char *, const char *, va_list args);
int aout_ChannelsRestart (vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void *);
char const * vlc_error (int);
int playlist_NodeGroup (playlist_t *, int,playlist_item_t *,playlist_item_t **,int, int, int);
......@@ -669,13 +671,13 @@ struct module_symbols_t
int (*intf_RunThread_inner) (intf_thread_t *);
void (*intf_StopThread_inner) (intf_thread_t *);
void (*intf_Destroy_inner) (intf_thread_t *);
void (*__msg_Generic_inner) (vlc_object_t *, int, const char *, const char *, ... ) ATTRIBUTE_FORMAT( 4, 5);
void (*__msg_GenericVa_inner) (vlc_object_t *, int, const char *, const char *, va_list args);
void (*__msg_Generic_inner) (vlc_object_t *, int, int, const char *, const char *, ... ) ATTRIBUTE_FORMAT( 5, 6);
void (*__msg_GenericVa_inner) (vlc_object_t *, int, int, const char *, const char *, va_list args);
void (*__msg_Info_inner) (vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3);
void (*__msg_Err_inner) (vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3);
void (*__msg_Warn_inner) (vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3);
void (*__msg_Dbg_inner) (vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3);
msg_subscription_t* (*__msg_Subscribe_inner) (vlc_object_t *);
msg_subscription_t* (*__msg_Subscribe_inner) (vlc_object_t *, int);
void (*__msg_Unsubscribe_inner) (vlc_object_t *, msg_subscription_t *);
void * (*__vlc_object_create_inner) (vlc_object_t *, int);
void (*__vlc_object_destroy_inner) (vlc_object_t *);
......@@ -869,6 +871,8 @@ struct module_symbols_t
int (*__intf_UserProgress_inner) (vlc_object_t*, const char*, const char*, float);
void (*__intf_UserProgressUpdate_inner) (vlc_object_t*, int, const char*, float);
void (*__intf_UserHide_inner) (vlc_object_t *, int);
int (*__stats_Create_inner) (vlc_object_t*, char *, int, int);
int (*__stats_Update_inner) (vlc_object_t*, char *, vlc_value_t);
};
# if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
......@@ -1289,6 +1293,8 @@ struct module_symbols_t
# define __intf_UserProgress (p_symbols)->__intf_UserProgress_inner
# define __intf_UserProgressUpdate (p_symbols)->__intf_UserProgressUpdate_inner
# define __intf_UserHide (p_symbols)->__intf_UserHide_inner
# define __stats_Create (p_symbols)->__stats_Create_inner
# define __stats_Update (p_symbols)->__stats_Update_inner
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/******************************************************************
* STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
......@@ -1712,6 +1718,8 @@ struct module_symbols_t
((p_symbols)->__intf_UserProgress_inner) = __intf_UserProgress; \
((p_symbols)->__intf_UserProgressUpdate_inner) = __intf_UserProgressUpdate; \
((p_symbols)->__intf_UserHide_inner) = __intf_UserHide; \
((p_symbols)->__stats_Create_inner) = __stats_Create; \
((p_symbols)->__stats_Update_inner) = __stats_Update; \
(p_symbols)->net_ConvertIPv4_deprecated = NULL; \
# endif /* __PLUGIN__ */
......
......@@ -135,7 +135,7 @@ MessagesWindow::MessagesWindow( intf_thread_t * _p_intf,
{
SetSizeLimits( 400, 2000, 200, 2000 );
p_sub = msg_Subscribe( p_intf );
p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
BRect rect, textRect;
......
......@@ -75,7 +75,7 @@ int E_(OpenIntf) ( vlc_object_t *p_this )
[NSThread detachNewThreadSelector:@selector(self) toTarget:[NSString string] withObject:nil];
p_intf->p_sys->o_sendport = [[NSPort port] retain];
p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
p_intf->p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
p_intf->b_play = VLC_TRUE;
p_intf->pf_run = Run;
......
......@@ -200,7 +200,7 @@ static int Open( vlc_object_t *p_this )
p_sys->i_box_plidx = 0;
p_sys->p_plnode = NULL;
p_sys->i_box_bidx = 0;
p_sys->p_sub = msg_Subscribe( p_intf );
p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
/* Initialize the curses library */
p_sys->w = initscr();
......
......@@ -77,7 +77,7 @@ static int Open( vlc_object_t *p_this )
p_intf->pf_run = Run;
// Suscribe to messages bank
p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
p_intf->p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
p_intf->p_sys->p_input = NULL;
p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
......
......@@ -112,7 +112,7 @@ static int Open( vlc_object_t *p_this )
}
// Suscribe to messages bank
p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
p_intf->p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
// Misc init
p_intf->p_sys->p_audio_menu = NULL;
......
......@@ -173,7 +173,7 @@ static int Open( vlc_object_t *p_this )
p_intf->pf_run = Run;
p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
p_intf->p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
/* Initialize wxWidgets thread */
p_intf->p_sys->b_playing = 0;
......
......@@ -262,7 +262,7 @@ static int Open( vlc_object_t *p_this )
#endif
}
p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
p_intf->p_sys->p_sub = msg_Subscribe( p_intf , MSG_QUEUE_NORMAL );
p_intf->pf_run = Run;
return 0;
......
......@@ -60,115 +60,136 @@
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static void QueueMsg ( vlc_object_t *, int , const char *,
static void QueueMsg ( vlc_object_t *, int, int , const char *,
const char *, va_list );
static void FlushMsg ( msg_bank_t * );
static void FlushMsg ( msg_queue_t * );
static void PrintMsg ( vlc_object_t *, msg_item_t * );
static void CreateMsgQueue( vlc_object_t *p_this, int i_queue );
/**
* Initialize messages interface
*
* This functions has to be called before any call to other msg_* functions.
* It set up the locks and the message queue if it is used.
* Initialize messages queues
* This function initializes all message queues
*/
void __msg_Create( vlc_object_t *p_this )
{
/* Message queue initialization */
vlc_mutex_init( p_this, &p_this->p_libvlc->msg_bank.lock );
p_this->p_libvlc->msg_bank.b_configured = VLC_FALSE;
p_this->p_libvlc->msg_bank.b_overflow = VLC_FALSE;
p_this->p_libvlc->msg_bank.i_start = 0;
p_this->p_libvlc->msg_bank.i_stop = 0;
p_this->p_libvlc->msg_bank.i_sub = 0;
p_this->p_libvlc->msg_bank.pp_sub = NULL;
CreateMsgQueue( p_this, MSG_QUEUE_NORMAL );
CreateMsgQueue( p_this, MSG_QUEUE_HTTPD_ACCESS );
#ifdef UNDER_CE
p_this->p_libvlc->msg_bank.logfile =
p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile =
CreateFile( L"vlc-log.txt", GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
CREATE_ALWAYS, 0, NULL );
SetFilePointer( p_this->p_libvlc->msg_bank.logfile, 0, NULL, FILE_END );
SetFilePointer( p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->
logfile, 0, NULL, FILE_END );
#endif
}
static void CreateMsgQueue( vlc_object_t *p_this, int i_queue )
{
msg_queue_t *p_queue = (msg_queue_t *)malloc( sizeof( msg_queue_t ) );
vlc_mutex_init( p_this, &p_queue->lock );
p_queue->b_overflow = VLC_FALSE;
p_queue->i_id = i_queue;
p_queue->i_start = 0;
p_queue->i_stop = 0;
p_queue->i_sub = 0;
p_queue->pp_sub = NULL;
INSERT_ELEM( p_this->p_libvlc->msg_bank.pp_queues,
p_this->p_libvlc->msg_bank.i_queues,
i_queue,
p_queue );
}
/**
* Flush the message queue
* Flush all message queues
*/
void __msg_Flush( vlc_object_t *p_this )
{
vlc_mutex_lock( &p_this->p_libvlc->msg_bank.lock );
int i;
p_this->p_libvlc->msg_bank.b_configured = VLC_TRUE;
#if 0
/* Some messages remain in the queue, dont rewrite them */
for( i_index = p_this->p_libvlc->msg_bank.i_start;
i_index != p_this->p_libvlc->msg_bank.i_stop;
i_index = (i_index+1) % VLC_MSG_QSIZE )
for( i = 0 ; i < p_this->p_libvlc->msg_bank.i_queues; i++ )
{
PrintMsg( p_this, &p_this->p_libvlc->msg_bank.msg[i_index] );
vlc_mutex_lock( &p_this->p_libvlc->msg_bank.pp_queues[i]->lock );
FlushMsg( p_this->p_libvlc->msg_bank.pp_queues[i] );
vlc_mutex_unlock( &p_this->p_libvlc->msg_bank.pp_queues[i]->lock );
}
#endif
FlushMsg( &p_this->p_libvlc->msg_bank );
vlc_mutex_unlock( &p_this->p_libvlc->msg_bank.lock );
}
/**
* Free resources allocated by msg_Create
*
* This functions prints all messages remaining in queue, then free all the
* resources allocated by msg_Create.
* This functions prints all messages remaining in the normal queue,
* then frees all the allocated ressources
* No other messages interface functions should be called after this one.
*/
void __msg_Destroy( vlc_object_t *p_this )
{
if( p_this->p_libvlc->msg_bank.i_sub )
{
msg_Err( p_this, "stale interface subscribers" );
}
/* Flush the queue */
if( !p_this->p_libvlc->msg_bank.b_configured )
int i;
for( i = 0 ; i < p_this->p_libvlc->msg_bank.i_queues; i++ )
{
msg_Flush( p_this );
}
else
{
FlushMsg( &p_this->p_libvlc->msg_bank );
}
msg_queue_t *p_queue = p_this->p_libvlc->msg_bank.pp_queues[i];
if( p_queue->i_sub )
{
msg_Err( p_this, "stale interface subscribers" );
}
FlushMsg( p_queue );
#ifdef UNDER_CE
CloseHandle( p_this->p_libvlc->msg_bank.logfile );
if( i == MSG_STREAM_NORMAL )
CloseHandle( p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile );
#endif
/* Destroy lock */
vlc_mutex_destroy( &p_this->p_libvlc->msg_bank.lock );
/* Destroy lock */
vlc_mutex_destroy( &p_queue->lock );
}
}
/**
* Subscribe to the message queue.
*/
msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this )
msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this, int i_queue )
{
msg_bank_t *p_bank = &p_this->p_libvlc->msg_bank;
msg_subscription_t *p_sub = malloc( sizeof( msg_subscription_t ) );
msg_queue_t *p_queue = NULL;
int i;
vlc_mutex_lock( &p_bank->lock );
for( i = 0 ; i <p_bank->i_queues ;i++ )
{
if( p_bank->pp_queues[i]->i_id == i_queue )
{
p_queue = p_bank->pp_queues[i];
}
}
if( p_queue == NULL )
{
vlc_mutex_unlock( &p_bank->lock );
return NULL;
}
vlc_mutex_lock( &p_queue->lock );
/* Add subscription to the list */
INSERT_ELEM( p_bank->pp_sub, p_bank->i_sub, p_bank->i_sub, p_sub );
INSERT_ELEM( p_bank->pp_queues[i_queue]->pp_sub,
p_bank->pp_queues[i_queue]->i_sub,
p_bank->pp_queues[i_queue]->i_sub,
p_sub );
p_sub->i_start = p_bank->i_start;
p_sub->pi_stop = &p_bank->i_stop;
p_sub->i_start = p_queue->i_start;
p_sub->pi_stop = &p_queue->i_stop;
p_sub->p_msg = p_bank->msg;
p_sub->p_lock = &p_bank->lock;
p_sub->p_msg = p_queue->msg;
p_sub->p_lock = &p_queue->lock;
vlc_mutex_unlock( &p_queue->lock );
vlc_mutex_unlock( &p_bank->lock );
return p_sub;
......@@ -180,37 +201,26 @@ msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this )
void __msg_Unsubscribe( vlc_object_t *p_this, msg_subscription_t *p_sub )
{
msg_bank_t *p_bank = &p_this->p_libvlc->msg_bank;
int i_index;
int i,j;
vlc_mutex_lock( &p_bank->lock );
/* Sanity check */
if( !p_bank->i_sub )
{
msg_Err( p_this, "no subscriber in the list" );
return;
}
/* Look for the appropriate subscription */
for( i_index = 0; i_index < p_bank->i_sub; i_index++ )
for( i = 0 ; i< p_bank->i_queues ; i++ )
{
if( p_bank->pp_sub[ i_index ] == p_sub )
vlc_mutex_lock( & p_bank->pp_queues[i]->lock );
for( j = 0 ; j< p_bank->pp_queues[i]->i_sub ; j++ )
{
break;
if( p_bank->pp_queues[i]->pp_sub[j] == p_sub )
{
REMOVE_ELEM( p_bank->pp_queues[i]->pp_sub,
p_bank->pp_queues[i]->i_sub,
j );
if( p_sub ) free( p_sub );
}
}
vlc_mutex_unlock( & p_bank->pp_queues[i]->lock );
}
if( p_bank->pp_sub[ i_index ] != p_sub )
{
msg_Err( p_this, "subscriber not found" );
vlc_mutex_unlock( &p_bank->lock );
return;
}
/* Remove this subscription */
REMOVE_ELEM( p_bank->pp_sub, p_bank->i_sub, i_index );
if( p_sub ) free( p_sub );
vlc_mutex_unlock( &p_bank->lock );
}
......@@ -219,20 +229,22 @@ void __msg_Unsubscribe( vlc_object_t *p_this, msg_subscription_t *p_sub )
*****************************************************************************
* These functions queue a message for later printing.
*****************************************************************************/
void __msg_Generic( vlc_object_t *p_this, int i_type, const char *psz_module,
void __msg_Generic( vlc_object_t *p_this, int i_queue_id, int i_type,
const char *psz_module,
const char *psz_format, ... )
{
va_list args;
va_start( args, psz_format );
QueueMsg( p_this, i_type, psz_module, psz_format, args );
QueueMsg( p_this, i_queue_id, i_type, psz_module, psz_format, args );
va_end( args );
}
void __msg_GenericVa( vlc_object_t *p_this, int i_type, const char *psz_module,
void __msg_GenericVa( vlc_object_t *p_this, int i_queue_id,
int i_type, const char *psz_module,
const char *psz_format, va_list args )
{
QueueMsg( p_this, i_type, psz_module, psz_format, args );
QueueMsg( p_this, i_queue_id, i_type, psz_module, psz_format, args );
}
/* Generic functions used when variadic macros are not available. */
......@@ -241,7 +253,7 @@ void __msg_GenericVa( vlc_object_t *p_this, int i_type, const char *psz_module,
{ \
va_list args; \
va_start( args, psz_format ); \
QueueMsg( (vlc_object_t *)p_this, FN_TYPE, "unknown", \
QueueMsg( (vlc_object_t *)p_this,MSG_QUEUE_NORMAL, FN_TYPE, "unknown", \
psz_format, args ); \
va_end( args ); \
} \
......@@ -273,10 +285,12 @@ DECLARE_MSG_FN( __msg_Dbg, VLC_MSG_DBG );
* is full). If the message can't be converted to string in memory, it issues
* a warning.
*/
static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
const char *psz_module,
const char *psz_format, va_list _args )
{
msg_bank_t * p_bank = &p_this->p_libvlc->msg_bank; /* message bank */
msg_queue_t *p_queue = NULL;
char * psz_str = NULL; /* formatted message string */
va_list args;
msg_item_t * p_item = NULL; /* pointer to message */
......@@ -285,6 +299,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
#if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
int i_size = strlen(psz_format) + INTF_MAX_MSG_SIZE;
#endif
int i;
/*
* Convert message to string
......@@ -317,13 +332,24 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
/* Put message in queue */
vlc_mutex_lock( &p_bank->lock );
for( i = 0 ; i <p_bank->i_queues ;i++ )
{
if( p_bank->pp_queues[i]->i_id == i_queue_id )
{
p_queue = p_bank->pp_queues[i];
}
}
if( p_queue == NULL ) return;
vlc_mutex_lock( &p_queue->lock );
/* Check there is room in the queue for our message */
if( p_bank->b_overflow )
if( p_queue->b_overflow )
{
FlushMsg( p_bank );
FlushMsg( p_queue );
if( ((p_bank->i_stop - p_bank->i_start + 1) % VLC_MSG_QSIZE) == 0 )
if( ((p_queue->i_stop - p_queue->i_start + 1) % VLC_MSG_QSIZE) == 0 )
{
/* Still in overflow mode, print from a dummy item */
p_item = &item;
......@@ -331,39 +357,41 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
else
{
/* Pheeew, at last, there is room in the queue! */
p_bank->b_overflow = VLC_FALSE;
p_queue->b_overflow = VLC_FALSE;
}
}
else if( ((p_bank->i_stop - p_bank->i_start + 2) % VLC_MSG_QSIZE) == 0 )
else if( ((p_queue->i_stop - p_queue->i_start + 2) % VLC_MSG_QSIZE) == 0 )
{
FlushMsg( p_bank );
FlushMsg( p_queue );
if( ((p_bank->i_stop - p_bank->i_start + 2) % VLC_MSG_QSIZE) == 0 )
if( ((p_queue->i_stop - p_queue->i_start + 2) % VLC_MSG_QSIZE) == 0 )
{
p_bank->b_overflow = VLC_TRUE;
/* Put the overflow message in the queue */
p_item = p_bank->msg + p_bank->i_stop;
p_bank->i_stop = (p_bank->i_stop + 1) % VLC_MSG_QSIZE;
p_item->i_type = VLC_MSG_WARN;
p_item->i_object_id = p_this->i_object_id;
p_item->i_object_type = p_this->i_object_type;
p_item->psz_module = strdup( "message" );
p_item->psz_msg = strdup( "message queue overflowed" );
PrintMsg( p_this, p_item );
/* We print from a dummy item */
p_item = &item;
p_queue->b_overflow = VLC_TRUE;
if( p_queue->i_id == MSG_QUEUE_NORMAL )
{
/* Put the overflow message in the queue */
p_item = p_queue->msg + p_queue->i_stop;
p_queue->i_stop = (p_queue->i_stop + 1) % VLC_MSG_QSIZE;
p_item->i_type = VLC_MSG_WARN;
p_item->i_object_id = p_this->i_object_id;
p_item->i_object_type = p_this->i_object_type;
p_item->psz_module = strdup( "message" );
p_item->psz_msg = strdup( "message queue overflowed" );
PrintMsg( p_this, p_item );
/* We print from a dummy item */
p_item = &item;
}
}
}
if( !p_bank->b_overflow )
if( !p_queue->b_overflow )
{
/* Put the message in the queue */
p_item = p_bank->msg + p_bank->i_stop;
p_bank->i_stop = (p_bank->i_stop + 1) % VLC_MSG_QSIZE;
p_item = p_queue->msg + p_queue->i_stop;
p_queue->i_stop = (p_queue->i_stop + 1) % VLC_MSG_QSIZE;
}
/* Fill message information fields */
......@@ -373,9 +401,10 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
p_item->psz_module = strdup( psz_module );
p_item->psz_msg = psz_str;
PrintMsg( p_this, p_item );
if( p_queue->i_id == MSG_QUEUE_NORMAL )
PrintMsg( p_this, p_item );
if( p_bank->b_overflow )
if( p_queue->b_overflow )
{
if( p_item->psz_module )
free( p_item->psz_module );
......@@ -383,6 +412,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
free( p_item->psz_msg );
}
vlc_mutex_unlock ( &p_queue->lock );
vlc_mutex_unlock( &p_bank->lock );
}
......@@ -394,52 +424,46 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
* Print all messages remaining in queue. MESSAGE QUEUE MUST BE LOCKED, since
* this function does not check the lock.
*****************************************************************************/
static void FlushMsg ( msg_bank_t *p_bank )
static void FlushMsg ( msg_queue_t *p_queue )
{
int i_index, i_start, i_stop;
/* Only flush the queue if it has been properly configured */
if( !p_bank->b_configured )
{
return;
}
/* Get the maximum message index that can be freed */
i_stop = p_bank->i_stop;
i_stop = p_queue->i_stop;
/* Check until which value we can free messages */
for( i_index = 0; i_index < p_bank->i_sub; i_index++ )
for( i_index = 0; i_index < p_queue->i_sub; i_index++ )
{
i_start = p_bank->pp_sub[ i_index ]->i_start;
i_start = p_queue->pp_sub[ i_index ]->i_start;
/* If this subscriber is late, we don't free messages before
* his i_start value, otherwise he'll miss messages */
if( ( i_start < i_stop
&& (p_bank->i_stop <= i_start || i_stop <= p_bank->i_stop) )
&& (p_queue->i_stop <= i_start || i_stop <= p_queue->i_stop) )
|| ( i_stop < i_start
&& (i_stop <= p_bank->i_stop && p_bank->i_stop <= i_start) ) )
&& (i_stop <= p_queue->i_stop && p_queue->i_stop <= i_start) ) )
{
i_stop = i_start;
}
}
/* Free message data */
for( i_index = p_bank->i_start;
for( i_index = p_queue->i_start;
i_index != i_stop;
i_index = (i_index+1) % VLC_MSG_QSIZE )
{
if( p_bank->msg[i_index].psz_msg )
free( p_bank->msg[i_index].psz_msg );
if( p_bank->msg[i_index].psz_module )
free( p_bank->msg[i_index].psz_module );
if( p_queue->msg[i_index].psz_msg )
free( p_queue->msg[i_index].psz_msg );
if( p_queue->msg[i_index].psz_module )
free( p_queue->msg[i_index].psz_module );
}
/* Update the new start value */
p_bank->i_start = i_index;
p_queue->i_start = i_index;
}
/*****************************************************************************
* PrintMsg: output a message item to stderr
* PrintMsg: output a standard message item to stderr
*****************************************************************************
* Print a message to stderr, with colour formatting if needed.
*****************************************************************************/
......
......@@ -212,6 +212,10 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
i_size = sizeof( osd_menu_t );
psz_type = "osd menu";
break;
case VLC_OBJECT_STATS:
i_size = sizeof( stats_handler_t );
psz_type = "statistics";
break;
default:
i_size = i_type > 0
? i_type > (int)sizeof(vlc_object_t)
......
/*****************************************************************************
* stats.c: Statistics handling
*****************************************************************************
* Copyright (C) 1998-2005 the VideoLAN team
* $Id: messages.c 12729 2005-10-02 08:00:06Z courmisch $
*
* Authors: Clément Stenac <zorglub@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <stdio.h> /* required */
#include <vlc/vlc.h>
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static counter_t *stats_GetCounter( stats_handler_t *p_handler, int i_object_id,
char *psz_name );
static int stats_CounterUpdate( stats_handler_t *p_handler,
counter_t *p_counter,
vlc_value_t val );
static stats_handler_t* stats_HandlerCreate( vlc_object_t *p_this );
static stats_handler_t *stats_HandlerGet( vlc_object_t *p_this );
/*****************************************************************************
* Exported functions
*****************************************************************************/
int __stats_Create( vlc_object_t *p_this, char *psz_name, int i_type,
int i_compute_type )
{
counter_t *p_counter;
stats_handler_t *p_handler = stats_HandlerGet( p_this );
p_counter = (counter_t*) malloc( sizeof( counter_t ) ) ;
p_counter->psz_name = strdup( psz_name );
p_counter->i_source_object = p_this->i_object_id;
p_counter->i_compute_type = i_compute_type;
p_counter->i_type = i_type;
p_counter->i_samples = 0;
p_counter->pp_samples = NULL;
INSERT_ELEM( p_handler->pp_counters,
p_handler->i_counters,
p_handler->i_counters,
p_counter );
fprintf (stderr, "Counter created\n");
return VLC_SUCCESS;
}
int __stats_Update( vlc_object_t *p_this, char *psz_name, vlc_value_t val )
{
counter_t *p_counter;
fprintf( stderr, "Updating\n");
/* Get stats handler singleton */
stats_handler_t *p_handler = stats_HandlerGet( p_this );
if( !p_handler ) return VLC_ENOMEM;
fprintf( stderr, "Got handler\n");
/* Look for existing element */
p_counter = stats_GetCounter( p_handler, p_this->i_object_id,
psz_name );
if( !p_counter )
{
vlc_object_release( p_handler );
return VLC_ENOOBJ;
}
fprintf (stderr, "Got counter, updating it\n");
return stats_CounterUpdate( p_handler, p_counter, val );
}
static int stats_CounterUpdate( stats_handler_t *p_handler,
counter_t *p_counter,
vlc_value_t val )
{
switch( p_counter->i_compute_type )
{
case STATS_LAST:
if( p_counter->i_samples > 1)
{
msg_Err( p_handler, "LAST counter has several samples !" );
return VLC_EGENERIC;
}
if( p_counter->i_samples == 0 )
{
counter_sample_t *p_new = (counter_sample_t*)malloc(
sizeof( counter_sample_t ) );
p_new->value.psz_string = NULL;
INSERT_ELEM( p_counter->pp_samples, p_counter->i_samples,
p_counter->i_samples, p_new );
}
if( p_counter->i_samples == 1 )
{
if( p_counter->i_type == VLC_VAR_STRING &&
p_counter->pp_samples[0]->value.psz_string )
{
free( p_counter->pp_samples[0]->value.psz_string );
}
p_counter->pp_samples[0]->value = val;
}
break;
case STATS_COUNTER:
if( p_counter->i_samples > 1)
{
msg_Err( p_handler, "LAST counter has several samples !" );
return VLC_EGENERIC;
}
if( p_counter->i_samples == 0 )
{
counter_sample_t *p_new = (counter_sample_t*)malloc(
sizeof( counter_sample_t ) );
p_new->value.psz_string = NULL;
INSERT_ELEM( p_counter->pp_samples, p_counter->i_samples,
p_counter->i_samples, p_new );
}
if( p_counter->i_samples == 1 )
{
switch( p_counter->i_type )
{
case VLC_VAR_INTEGER:
case VLC_VAR_FLOAT:
p_counter->pp_samples[0]->value.i_int += val.i_int;
break;
default:
msg_Err( p_handler, "Trying to increment invalid variable %s",
p_counter->psz_name );
return VLC_EGENERIC;
}
}
break;
}
fprintf (stderr, "Counter value is %i\n", p_counter->pp_samples[0]->value.i_int );
return VLC_SUCCESS;
}
static counter_t *stats_GetCounter( stats_handler_t *p_handler, int i_object_id,
char *psz_name )
{
int i;
fprintf( stderr, "Looking through %i counters\n", p_handler->i_counters );
for( i = 0; i< p_handler->i_counters; i++ )
{
counter_t *p_counter = p_handler->pp_counters[i];
fprintf( stderr, "%i - %s\n", p_counter->i_source_object, p_counter->psz_name );
if( p_counter->i_source_object == i_object_id &&
!strcmp( p_counter->psz_name, psz_name ) )
{
return p_counter;
}
}
return NULL;
}
static stats_handler_t *stats_HandlerGet( vlc_object_t *p_this )
{
fprintf (stderr, "Getting handler\n");
stats_handler_t *p_handler = (stats_handler_t*)
vlc_object_find( p_this->p_vlc, VLC_OBJECT_STATS,
FIND_ANYWHERE );
fprintf( stderr, "Got it %p\n", p_handler );
if( !p_handler )
{
p_handler = stats_HandlerCreate( p_this );
if( !p_handler )
{
return NULL;
}
vlc_object_yield( p_handler );
}
return p_handler;
}
/**
* Initialize statistics handler
*
* This function initializes the global statistics handler singleton,
* \param p_this the parent VLC object
*/
static stats_handler_t* stats_HandlerCreate( vlc_object_t *p_this )
{
stats_handler_t *p_handler;
msg_Dbg( p_this, "creating statistics handler" );
p_handler = (stats_handler_t*) vlc_object_create( p_this,
VLC_OBJECT_STATS );
if( !p_handler )
{
msg_Err( p_this, "out of memory" );
return NULL;
}
p_handler->i_counters = 0;
p_handler->pp_counters = NULL;
/// \bug is it p_vlc or p_libvlc ?
vlc_object_attach( p_handler, p_this->p_vlc );
return p_handler;
}
......@@ -2058,6 +2058,8 @@ static void httpd_HostThread( httpd_host_t *host )
{
tls_session_t *p_tls = NULL;
stats_Create( host, "client_connections", VLC_VAR_INTEGER, STATS_COUNTER );
while( !host->b_die )
{
struct timeval timeout;
......@@ -2520,6 +2522,7 @@ static void httpd_HostThread( httpd_host_t *host )
struct sockaddr_storage sock;
fd = accept( fd, (struct sockaddr *)&sock, &i_sock_size );
fprintf ( stderr, "Accepting\n");
if( fd >= 0 )
{
int i_state = 0;
......@@ -2554,17 +2557,18 @@ static void httpd_HostThread( httpd_host_t *host )
break;
}
}
if( fd >= 0 )
{
httpd_client_t *cl;
stats_UpdateInteger( host, "client_connections",
1 );
cl = httpd_ClientNew( fd, &sock, i_sock_size, p_tls );
p_tls = NULL;
vlc_mutex_lock( &host->lock );
TAB_APPEND( host->i_client, host->client, cl );
vlc_mutex_unlock( &host->lock );
if( i_state != 0 )
cl->i_state = i_state; // override state for TLS
}
......
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