Commit c4cd36ee authored by Felix Abecassis's avatar Felix Abecassis

variables: add internal type callback_table_t for storing a list of callbacks

parent f8187680
...@@ -603,8 +603,8 @@ static void DumpVariable (const void *data, const VISIT which, const int depth) ...@@ -603,8 +603,8 @@ static void DumpVariable (const void *data, const VISIT which, const int depth)
fputs( ", has choices", stdout ); fputs( ", has choices", stdout );
if( p_var->i_type & VLC_VAR_ISCOMMAND ) if( p_var->i_type & VLC_VAR_ISCOMMAND )
fputs( ", command", stdout ); fputs( ", command", stdout );
if( p_var->i_entries ) if( p_var->value_callbacks.i_entries )
printf( ", %d callbacks", p_var->i_entries ); printf( ", %d callbacks", p_var->value_callbacks.i_entries );
switch( p_var->i_type & VLC_VAR_CLASS ) switch( p_var->i_type & VLC_VAR_CLASS )
{ {
case VLC_VAR_VOID: case VLC_VAR_VOID:
......
...@@ -169,10 +169,11 @@ static void Destroy( variable_t *p_var ) ...@@ -169,10 +169,11 @@ static void Destroy( variable_t *p_var )
free( p_var->choices_text.p_values ); free( p_var->choices_text.p_values );
} }
#if 0 // ndef NDEBUG #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 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__ # ifdef __GLIBC__
Dl_info info; Dl_info info;
...@@ -189,7 +190,7 @@ static void Destroy( variable_t *p_var ) ...@@ -189,7 +190,7 @@ static void Destroy( variable_t *p_var )
free( p_var->psz_name ); free( p_var->psz_name );
free( p_var->psz_text ); free( p_var->psz_text );
free( p_var->p_entries ); free( p_var->value_callbacks.p_entries );
free( p_var ); free( p_var );
} }
...@@ -228,8 +229,7 @@ int var_Create( vlc_object_t *p_this, const char *psz_name, int i_type ) ...@@ -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->choices_text.p_values = NULL;
p_var->b_incallback = false; p_var->b_incallback = false;
p_var->i_entries = 0; p_var->value_callbacks = (callback_table_t){ 0 };
p_var->p_entries = NULL;
/* Always initialize the variable, even if it is a list variable; this /* 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 * 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, ...@@ -825,10 +825,11 @@ static int AddCallback( vlc_object_t *p_this, const char *psz_name,
} }
WaitUnused( p_this, p_var ); WaitUnused( p_this, p_var );
INSERT_ELEM( p_var->p_entries, callback_table_t *p_table = &p_var->value_callbacks;
p_var->i_entries, INSERT_ELEM( p_table->p_entries,
p_var->i_entries, p_table->i_entries,
entry ); p_table->i_entries,
entry);
vlc_mutex_unlock( &p_priv->var_lock ); vlc_mutex_unlock( &p_priv->var_lock );
...@@ -886,15 +887,16 @@ static int DelCallback( vlc_object_t *p_this, const char *psz_name, ...@@ -886,15 +887,16 @@ static int DelCallback( vlc_object_t *p_this, const char *psz_name,
WaitUnused( p_this, p_var ); 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 if( p_table->p_entries[i_entry].pf_callback == entry.pf_callback
&& p_var->p_entries[i_entry].p_data == entry.p_data ) && p_table->p_entries[i_entry].p_data == entry.p_data )
{ {
break; break;
} }
#ifndef NDEBUG #ifndef NDEBUG
else if( p_var->p_entries[i_entry].pf_callback == entry.pf_callback ) else if( p_table->p_entries[i_entry].pf_callback == entry.pf_callback )
b_found_similar = true; b_found_similar = true;
#endif #endif
} }
...@@ -911,7 +913,7 @@ static int DelCallback( vlc_object_t *p_this, const char *psz_name, ...@@ -911,7 +913,7 @@ static int DelCallback( vlc_object_t *p_this, const char *psz_name,
return VLC_EGENERIC; 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 ); vlc_mutex_unlock( &p_priv->var_lock );
...@@ -1317,11 +1319,12 @@ static int TriggerCallback( vlc_object_t *p_this, variable_t *p_var, ...@@ -1317,11 +1319,12 @@ static int TriggerCallback( vlc_object_t *p_this, variable_t *p_var,
{ {
assert( p_this ); 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 ) if( i_entries == 0 )
return VLC_SUCCESS; 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 ); vlc_object_internals_t *p_priv = vlc_internals( p_this );
assert( !p_var->b_incallback ); assert( !p_var->b_incallback );
......
...@@ -66,6 +66,12 @@ typedef struct variable_ops_t ...@@ -66,6 +66,12 @@ typedef struct variable_ops_t
void (*pf_free) ( vlc_value_t * ); void (*pf_free) ( vlc_value_t * );
} variable_ops_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. * The structure describing a variable.
* \note vlc_value_t is the common union for variable values * \note vlc_value_t is the common union for variable values
...@@ -99,10 +105,8 @@ struct variable_t ...@@ -99,10 +105,8 @@ struct variable_t
/** Set to TRUE if the variable is in a callback */ /** Set to TRUE if the variable is in a callback */
bool b_incallback; bool b_incallback;
/** Number of registered callbacks */ /** Registered value callbacks */
int i_entries; callback_table_t value_callbacks;
/** Array of registered callbacks */
callback_entry_t * p_entries;
}; };
extern void var_DestroyAll( vlc_object_t * ); extern void var_DestroyAll( vlc_object_t * );
......
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