[vlc-devel] [PATCH 2/3] variables: add internal type callback_table_t for storing a list of callbacks
Felix Abecassis
felix.abecassis at gmail.com
Fri Jul 25 16:38:58 CEST 2014
---
src/misc/objects.c | 4 ++--
src/misc/variables.c | 33 ++++++++++++++++++---------------
src/misc/variables.h | 12 ++++++++----
3 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/src/misc/objects.c b/src/misc/objects.c
index 0026ea8..3b04518 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -603,8 +603,8 @@ static void DumpVariable (const void *data, const VISIT which, const int depth)
fputs( ", has choices", stdout );
if( p_var->i_type & VLC_VAR_ISCOMMAND )
fputs( ", command", stdout );
- if( p_var->i_entries )
- printf( ", %d callbacks", p_var->i_entries );
+ if( p_var->value_callbacks.i_entries )
+ printf( ", %d callbacks", p_var->value_callbacks.i_entries );
switch( p_var->i_type & VLC_VAR_CLASS )
{
case VLC_VAR_VOID:
diff --git a/src/misc/variables.c b/src/misc/variables.c
index 369d2e5..d40469f 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -169,10 +169,11 @@ static void Destroy( variable_t *p_var )
free( p_var->choices_text.p_values );
}
#if 0 // ndef NDEBUG
- for (int i = 0; i < p_var->i_entries; i++)
+ callback_table_t *p_table = &p_var->value_callbacks;
+ for (int i = 0; i < p_table->i_entries; i++)
{
const char *file = "?", *symbol = "?";
- const void *addr = p_var->p_entries[i].pf_callback;
+ const void *addr = p_table->p_entries[i].pf_callback;
# ifdef __GLIBC__
Dl_info info;
@@ -189,7 +190,7 @@ static void Destroy( variable_t *p_var )
free( p_var->psz_name );
free( p_var->psz_text );
- free( p_var->p_entries );
+ free( p_var->value_callbacks.p_entries );
free( p_var );
}
@@ -228,8 +229,7 @@ int var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
p_var->choices_text.p_values = NULL;
p_var->b_incallback = false;
- p_var->i_entries = 0;
- p_var->p_entries = NULL;
+ p_var->value_callbacks = (callback_table_t){ 0 };
/* Always initialize the variable, even if it is a list variable; this
* will lead to errors if the variable is not initialized, but it will
@@ -825,10 +825,11 @@ static int AddCallback( vlc_object_t *p_this, const char *psz_name,
}
WaitUnused( p_this, p_var );
- INSERT_ELEM( p_var->p_entries,
- p_var->i_entries,
- p_var->i_entries,
- entry );
+ callback_table_t *p_table = &p_var->value_callbacks;
+ INSERT_ELEM( p_table->p_entries,
+ p_table->i_entries,
+ p_table->i_entries,
+ entry);
vlc_mutex_unlock( &p_priv->var_lock );
@@ -886,10 +887,11 @@ static int DelCallback( vlc_object_t *p_this, const char *psz_name,
WaitUnused( p_this, p_var );
- for( i_entry = p_var->i_entries ; i_entry-- ; )
+ callback_table_t *p_table = &p_var->value_callbacks;
+ for( i_entry = p_table->i_entries ; i_entry-- ; )
{
- if( p_var->p_entries[i_entry].pf_callback == entry.pf_callback
- && p_var->p_entries[i_entry].p_data == entry.p_data )
+ if( p_table->p_entries[i_entry].pf_callback == entry.pf_callback
+ && p_table->p_entries[i_entry].p_data == entry.p_data )
{
break;
}
@@ -911,7 +913,7 @@ static int DelCallback( vlc_object_t *p_this, const char *psz_name,
return VLC_EGENERIC;
}
- REMOVE_ELEM( p_var->p_entries, p_var->i_entries, i_entry );
+ REMOVE_ELEM( p_table->p_entries, p_table->i_entries, i_entry );
vlc_mutex_unlock( &p_priv->var_lock );
@@ -1317,11 +1319,12 @@ static int TriggerCallback( vlc_object_t *p_this, variable_t *p_var,
{
assert( p_this );
- int i_entries = p_var->i_entries;
+ callback_table_t *p_table = &p_var->value_callbacks;
+ int i_entries = p_table->i_entries;
if( i_entries == 0 )
return VLC_SUCCESS;
- callback_entry_t *p_entries = p_var->p_entries;
+ callback_entry_t *p_entries = p_table->p_entries;
vlc_object_internals_t *p_priv = vlc_internals( p_this );
assert( !p_var->b_incallback );
diff --git a/src/misc/variables.h b/src/misc/variables.h
index 8c203b6..d09ba66 100644
--- a/src/misc/variables.h
+++ b/src/misc/variables.h
@@ -66,6 +66,12 @@ typedef struct variable_ops_t
void (*pf_free) ( vlc_value_t * );
} variable_ops_t;
+typedef struct callback_table_t
+{
+ int i_entries;
+ callback_entry_t * p_entries;
+} callback_table_t;
+
/**
* The structure describing a variable.
* \note vlc_value_t is the common union for variable values
@@ -99,10 +105,8 @@ struct variable_t
/** Set to TRUE if the variable is in a callback */
bool b_incallback;
- /** Number of registered callbacks */
- int i_entries;
- /** Array of registered callbacks */
- callback_entry_t * p_entries;
+ /** Registered value callbacks */
+ callback_table_t value_callbacks;
};
extern void var_DestroyAll( vlc_object_t * );
--
1.9.1
More information about the vlc-devel
mailing list