[vlc-devel] [PATCH 2/3] core: add a new type of callback for list variables
Felix Abecassis
felix.abecassis at gmail.com
Wed Jul 23 18:56:41 CEST 2014
2014-07-23 18:02 GMT+02:00 Rémi Denis-Courmont <remi at remlab.net>:
> Le mercredi 23 juillet 2014, 14:43:08 Felix Abecassis a écrit :
>> This new callback is triggered when an element is added/removed from
>> the list, or when the list is cleared.
>> ---
>> include/vlc_common.h | 17 +++++++-
>> include/vlc_variables.h | 6 +++
>> src/libvlccore.sym | 2 +
>> src/misc/variables.c | 102
>> ++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 118
>> insertions(+), 9 deletions(-)
>>
>> diff --git a/include/vlc_common.h b/include/vlc_common.h
>> index 8b4b923..128177e 100644
>> --- a/include/vlc_common.h
>> +++ b/include/vlc_common.h
>> @@ -382,7 +382,7 @@ struct vlc_list_t
>> #define VLC_ENOITEM (-8) /**< Item not found */
>>
>> /**************************************************************************
>> *** - * Variable callbacks
>> + * Variable callbacks: called when the value is modified
>>
>> ***************************************************************************
>> **/ typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's
>> object */ char const *, /* variable name */ @@ -391,6 +391,21 @@
>> typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's
>> object */ void * ); /* callback data */
>>
>> /**************************************************************************
>> *** + * List callbacks: called when elements are added/removed from the list
>> +
>> ***************************************************************************
>> **/ +typedef int ( * vlc_list_callback_t ) ( vlc_object_t *, /*
>> variable's object */ + char const *,
>> /* variable name */ +
>> int, /* VLC_VAR_* action */ +
>> vlc_value_t *, /* new/deleted value */ +
>> void *); /* callback data */ +
>> +typedef enum
>> +{
>> + vlc_value_callback,
>> + vlc_list_callback
>> +} vlc_callback_type_t;
>> +
>> +/**************************************************************************
>> *** * OS-specific headers and thread types
>>
>> ***************************************************************************
>> **/ #if defined( _WIN32 )
>> diff --git a/include/vlc_variables.h b/include/vlc_variables.h
>> index 420f0b4..6f48aa1 100644
>> --- a/include/vlc_variables.h
>> +++ b/include/vlc_variables.h
>> @@ -183,10 +183,16 @@ VLC_API int var_AddCallback( vlc_object_t *, const
>> char *, vlc_callback_t, void VLC_API int var_DelCallback( vlc_object_t *,
>> const char *, vlc_callback_t, void * ); VLC_API int var_TriggerCallback(
>> vlc_object_t *, const char * );
>>
>> +VLC_API int var_AddListCallback( vlc_object_t *, const char *,
>> vlc_list_callback_t, void * ); +VLC_API int var_DelListCallback(
>> vlc_object_t *, const char *, vlc_list_callback_t, void * ); +
>> #define var_AddCallback(a,b,c,d) var_AddCallback( VLC_OBJECT(a), b, c, d )
>> #define var_DelCallback(a,b,c,d) var_DelCallback( VLC_OBJECT(a), b, c, d )
>> #define var_TriggerCallback(a,b) var_TriggerCallback( VLC_OBJECT(a), b )
>>
>> +#define var_AddListCallback(a,b,c,d) var_AddListCallback( VLC_OBJECT(a), b,
>> c, d ) +#define var_DelListCallback(a,b,c,d) var_DelListCallback(
>> VLC_OBJECT(a), b, c, d ) +
>> /**************************************************************************
>> *** * helpers functions
>>
>> ***************************************************************************
>> **/ diff --git a/src/libvlccore.sym b/src/libvlccore.sym
>> index 325c8f6..679958d 100644
>> --- a/src/libvlccore.sym
>> +++ b/src/libvlccore.sym
>> @@ -452,9 +452,11 @@ vlc_socket
>> vlc_accept
>> utf8_vfprintf
>> var_AddCallback
>> +var_AddListCallback
>> var_Change
>> var_Create
>> var_DelCallback
>> +var_DelListCallback
>> var_Destroy
>> var_FreeList
>> var_Get
>> diff --git a/src/misc/variables.c b/src/misc/variables.c
>> index 369d2e5..659ab72 100644
>> --- a/src/misc/variables.c
>> +++ b/src/misc/variables.c
>> @@ -49,7 +49,13 @@
>>
>> ***************************************************************************
>> **/ struct callback_entry_t
>> {
>> - vlc_callback_t pf_callback;
>> + vlc_callback_type_t i_type;
>
> I'd rather add a new table. Is there any particular reason for multiplexing
> the different callback types?
>
With an additional type like list_callback_entry_t and a separate
table for storing these callbacks, I think too much code would have to
be duplicated.
We would have to almost entirely duplicate var_AddCallback and
var_DelCallback to implement var_AddListCallback and
var_DelListCallback. Unless we use a macro in order to be generic on
the callback/table type, but that would be ugly imo.
--
Félix Abecassis
http://felix.abecassis.me
More information about the vlc-devel
mailing list