Commit 215c1a85 authored by Gildas Bazin's avatar Gildas Bazin

* src/misc/objects.c: implemented the FIND_CHILD mode for vlc_list_find().
   vlc_object_get() now increments the refcount of the object so you'll need to release
the object at some point.
* src/misc/variables.c, ALL: var_Change() with VLC_VAR_GETLIST now returns a vlc_value_t
which points to a vlc_list_t.
parent c4fde1e5
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* variables.h: variables handling * variables.h: variables handling
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: variables.h,v 1.10 2002/12/13 01:56:29 gbazin Exp $ * $Id: variables.h,v 1.11 2002/12/14 19:34:07 gbazin Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -51,8 +51,7 @@ struct variable_t ...@@ -51,8 +51,7 @@ struct variable_t
/* If the variable is to be chosen in a list */ /* If the variable is to be chosen in a list */
int i_default; int i_default;
int i_choices; vlc_list_t choices;
vlc_value_t *pp_choices;
/* Set to TRUE if the variable is in a callback */ /* Set to TRUE if the variable is in a callback */
vlc_bool_t b_incallback; vlc_bool_t b_incallback;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* vlc.h: global header for vlc * vlc.h: global header for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN * Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: vlc.h,v 1.19 2002/12/13 01:56:29 gbazin Exp $ * $Id: vlc.h,v 1.20 2002/12/14 19:34:07 gbazin Exp $
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -41,6 +41,7 @@ typedef union ...@@ -41,6 +41,7 @@ typedef union
char * psz_string; char * psz_string;
void * p_address; void * p_address;
vlc_object_t * p_object; vlc_object_t * p_object;
vlc_list_t * p_list;
/* Make sure the structure is at least 64bits */ /* Make sure the structure is at least 64bits */
struct { char a, b, c, d, e, f, g, h; } padding; struct { char a, b, c, d, e, f, g, h; } padding;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* rc.c : remote control stdin/stdout plugin for vlc * rc.c : remote control stdin/stdout plugin for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: rc.c,v 1.16 2002/12/07 23:50:30 massiot Exp $ * $Id: rc.c,v 1.17 2002/12/14 19:34:06 gbazin Exp $
* *
* Authors: Peter Surda <shurdeek@panorama.sth.ac.at> * Authors: Peter Surda <shurdeek@panorama.sth.ac.at>
* *
...@@ -735,9 +735,8 @@ static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd, ...@@ -735,9 +735,8 @@ static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
{ {
/* Retrieve all registered ***. */ /* Retrieve all registered ***. */
vlc_value_t val; vlc_value_t val;
int i, i_vals; int i;
vlc_value_t * p_vals; char * psz_value;
const char * psz_value;
if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 ) if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
{ {
...@@ -755,14 +754,12 @@ static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd, ...@@ -755,14 +754,12 @@ static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
} }
printf( "+----[ %s ]\n", psz_name ); printf( "+----[ %s ]\n", psz_name );
i_vals = ((vlc_value_t *)val.p_address)[0].i_int; for ( i = 0; i < val.p_list->i_count; i++ )
p_vals = &((vlc_value_t *)val.p_address)[1]; /* Starts at index 1 */
for ( i = 0; i < i_vals; i++ )
{ {
if ( !strcmp( psz_value, p_vals[i].psz_string ) ) if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
printf( "| %s *\n", p_vals[i].psz_string ); printf( "| %s *\n", val.p_list->p_values[i].psz_string );
else else
printf( "| %s\n", p_vals[i].psz_string ); printf( "| %s\n", val.p_list->p_values[i].psz_string );
} }
var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST, var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
&val ); &val );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* intf.m: MacOS X interface plugin * intf.m: MacOS X interface plugin
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: intf.m,v 1.9 2002/12/08 23:38:02 massiot Exp $ * $Id: intf.m,v 1.10 2002/12/14 19:34:06 gbazin Exp $
* *
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net> * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
* Christophe Massiot <massiot@via.ecp.fr> * Christophe Massiot <massiot@via.ecp.fr>
...@@ -839,8 +839,6 @@ static void Run( intf_thread_t *p_intf ) ...@@ -839,8 +839,6 @@ static void Run( intf_thread_t *p_intf )
int i, i_nb_items; int i, i_nb_items;
NSMenu * o_menu = [o_mi submenu]; NSMenu * o_menu = [o_mi submenu];
vlc_value_t val; vlc_value_t val;
int i_vals;
vlc_value_t * p_vals;
char * psz_value; char * psz_value;
/* remove previous items */ /* remove previous items */
...@@ -863,18 +861,15 @@ static void Run( intf_thread_t *p_intf ) ...@@ -863,18 +861,15 @@ static void Run( intf_thread_t *p_intf )
return; return;
} }
i_vals = ((vlc_value_t *)val.p_address)[0].i_int;
p_vals = &((vlc_value_t *)val.p_address)[1]; /* Starts at index 1 */
/* make (un)sensitive */ /* make (un)sensitive */
[o_mi setEnabled: (i_vals > 0)]; [o_mi setEnabled: (val.p_list->i_count > 0)];
for ( i = 0; i < i_vals; i++ ) for ( i = 0; i < val.p_list->i_count; i++ )
{ {
NSMenuItem * o_lmi; NSMenuItem * o_lmi;
NSString * o_title; NSString * o_title;
o_title = [NSString stringWithCString: p_vals[i].psz_string]; o_title = [NSString stringWithCString: val.p_list->p_values[i].psz_string];
o_lmi = [o_menu addItemWithTitle: o_title o_lmi = [o_menu addItemWithTitle: o_title
action: pf_callback keyEquivalent: @""]; action: pf_callback keyEquivalent: @""];
/* FIXME: this isn't 64-bit clean ! */ /* FIXME: this isn't 64-bit clean ! */
...@@ -883,7 +878,7 @@ static void Run( intf_thread_t *p_intf ) ...@@ -883,7 +878,7 @@ static void Run( intf_thread_t *p_intf )
[NSValue valueWithPointer: p_object]]; [NSValue valueWithPointer: p_object]];
[o_lmi setTarget: o_controls]; [o_lmi setTarget: o_controls];
if ( !strcmp( psz_value, p_vals[i].psz_string ) ) if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
[o_lmi setState: NSOnState]; [o_lmi setState: NSOnState];
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* test4.c : Miscellaneous stress tests module for vlc * test4.c : Miscellaneous stress tests module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: test4.c,v 1.5 2002/12/07 15:25:26 gbazin Exp $ * $Id: test4.c,v 1.6 2002/12/14 19:34:06 gbazin Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -82,8 +82,7 @@ static int Foo( vlc_object_t *p_this, char const *psz_cmd, ...@@ -82,8 +82,7 @@ static int Foo( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data ) vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
vlc_value_t val; vlc_value_t val;
int i, i_vals; int i;
vlc_value_t *p_vals;
var_Create( p_this, "honk", VLC_VAR_STRING | VLC_VAR_HASCHOICE ); var_Create( p_this, "honk", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
...@@ -113,11 +112,9 @@ static int Foo( vlc_object_t *p_this, char const *psz_cmd, ...@@ -113,11 +112,9 @@ static int Foo( vlc_object_t *p_this, char const *psz_cmd,
var_Get( p_this, "honk", &val ); printf( "value: %s\n", val.psz_string ); var_Get( p_this, "honk", &val ); printf( "value: %s\n", val.psz_string );
var_Change( p_this, "honk", VLC_VAR_GETLIST, &val ); var_Change( p_this, "honk", VLC_VAR_GETLIST, &val );
i_vals = ((vlc_value_t*)val.p_address)[0].i_int; for( i = 0 ; i < val.p_list->i_count ; i++ )
p_vals = &((vlc_value_t*)val.p_address)[1];
for( i = 0 ; i < i_vals ; i++ )
{ {
printf( "value %i: %s\n", i, p_vals[i].psz_string ); printf( "value %i: %s\n", i, val.p_list->p_values[i].psz_string );
} }
var_Change( p_this, "honk", VLC_VAR_FREELIST, &val ); var_Change( p_this, "honk", VLC_VAR_FREELIST, &val );
...@@ -307,6 +304,7 @@ static int Stress( vlc_object_t *p_this, char const *psz_cmd, ...@@ -307,6 +304,7 @@ static int Stress( vlc_object_t *p_this, char const *psz_cmd,
{ {
int id = (int) (MAXOBJ * i_level * 1.0 * rand() / (RAND_MAX)); int id = (int) (MAXOBJ * i_level * 1.0 * rand() / (RAND_MAX));
vlc_object_get( p_this, pp_objects[id]->i_object_id ); vlc_object_get( p_this, pp_objects[id]->i_object_id );
vlc_object_release( p_this );
} }
printf( " - destroying the objects (LIFO)\n" ); printf( " - destroying the objects (LIFO)\n" );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* libvlc.c: main libvlc source * libvlc.c: main libvlc source
***************************************************************************** *****************************************************************************
* Copyright (C) 1998-2002 VideoLAN * Copyright (C) 1998-2002 VideoLAN
* $Id: libvlc.c,v 1.51 2002/12/13 01:56:30 gbazin Exp $ * $Id: libvlc.c,v 1.52 2002/12/14 19:34:06 gbazin Exp $
* *
* Authors: Vincent Seguin <seguin@via.ecp.fr> * Authors: Vincent Seguin <seguin@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org> * Samuel Hocevar <sam@zoy.org>
...@@ -255,6 +255,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) ...@@ -255,6 +255,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
if( p_help_module == NULL ) if( p_help_module == NULL )
{ {
//module_EndBank( p_vlc ); //module_EndBank( p_vlc );
if( i_object ) vlc_object_release( p_vlc );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
p_help_module->psz_object_name = "help"; p_help_module->psz_object_name = "help";
...@@ -268,6 +269,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) ...@@ -268,6 +269,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
config_Free( p_help_module ); config_Free( p_help_module );
vlc_object_destroy( p_help_module ); vlc_object_destroy( p_help_module );
//module_EndBank( p_vlc ); //module_EndBank( p_vlc );
if( i_object ) vlc_object_release( p_vlc );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -298,6 +300,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) ...@@ -298,6 +300,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
config_Free( p_help_module ); config_Free( p_help_module );
vlc_object_destroy( p_help_module ); vlc_object_destroy( p_help_module );
//module_EndBank( p_vlc ); //module_EndBank( p_vlc );
if( i_object ) vlc_object_release( p_vlc );
return VLC_EEXIT; return VLC_EEXIT;
} }
...@@ -345,6 +348,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) ...@@ -345,6 +348,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
if( b_exit ) if( b_exit )
{ {
//module_EndBank( p_vlc ); //module_EndBank( p_vlc );
if( i_object ) vlc_object_release( p_vlc );
return VLC_EEXIT; return VLC_EEXIT;
} }
...@@ -367,6 +371,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) ...@@ -367,6 +371,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
getchar(); getchar();
#endif #endif
//module_EndBank( p_vlc ); //module_EndBank( p_vlc );
if( i_object ) vlc_object_release( p_vlc );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -462,6 +467,9 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) ...@@ -462,6 +467,9 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
config_PutInt( p_vlc, "network-channel", VLC_FALSE ); config_PutInt( p_vlc, "network-channel", VLC_FALSE );
} }
msg_Err( p_vlc, "SIZEOF: %i", sizeof(vlc_list_t) );
msg_Err( p_vlc, "SIZEOF: %i", sizeof(vlc_value_t) );
/* /*
* Initialize playlist and get commandline files * Initialize playlist and get commandline files
*/ */
...@@ -474,6 +482,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) ...@@ -474,6 +482,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
module_Unneed( p_vlc, p_vlc->p_memcpy_module ); module_Unneed( p_vlc, p_vlc->p_memcpy_module );
} }
//module_EndBank( p_vlc ); //module_EndBank( p_vlc );
if( i_object ) vlc_object_release( p_vlc );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -482,6 +491,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) ...@@ -482,6 +491,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
*/ */
GetFilenames( p_vlc, i_argc, ppsz_argv ); GetFilenames( p_vlc, i_argc, ppsz_argv );
if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -528,6 +538,7 @@ int VLC_AddIntf( int i_object, char const *psz_module, vlc_bool_t b_block ) ...@@ -528,6 +538,7 @@ int VLC_AddIntf( int i_object, char const *psz_module, vlc_bool_t b_block )
if( p_intf == NULL ) if( p_intf == NULL )
{ {
msg_Err( p_vlc, "interface initialization failed" ); msg_Err( p_vlc, "interface initialization failed" );
if( i_object ) vlc_object_release( p_vlc );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -538,9 +549,11 @@ int VLC_AddIntf( int i_object, char const *psz_module, vlc_bool_t b_block ) ...@@ -538,9 +549,11 @@ int VLC_AddIntf( int i_object, char const *psz_module, vlc_bool_t b_block )
{ {
vlc_object_detach( p_intf ); vlc_object_detach( p_intf );
intf_Destroy( p_intf ); intf_Destroy( p_intf );
if( i_object ) vlc_object_release( p_vlc );
return i_err; return i_err;
} }
if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -604,6 +617,7 @@ int VLC_Destroy( int i_object ) ...@@ -604,6 +617,7 @@ int VLC_Destroy( int i_object )
/* Stop thread system: last one out please shut the door! */ /* Stop thread system: last one out please shut the door! */
vlc_threads_end( &libvlc ); vlc_threads_end( &libvlc );
if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -626,6 +640,7 @@ int VLC_Die( int i_object ) ...@@ -626,6 +640,7 @@ int VLC_Die( int i_object )
p_vlc->b_die = VLC_TRUE; p_vlc->b_die = VLC_TRUE;
if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -657,6 +672,7 @@ int VLC_AddTarget( int i_object, char const *psz_target, int i_mode, int i_pos ) ...@@ -657,6 +672,7 @@ int VLC_AddTarget( int i_object, char const *psz_target, int i_mode, int i_pos )
if( p_playlist == NULL ) if( p_playlist == NULL )
{ {
if( i_object ) vlc_object_release( p_vlc );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -667,6 +683,7 @@ int VLC_AddTarget( int i_object, char const *psz_target, int i_mode, int i_pos ) ...@@ -667,6 +683,7 @@ int VLC_AddTarget( int i_object, char const *psz_target, int i_mode, int i_pos )
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
if( i_object ) vlc_object_release( p_vlc );
return i_err; return i_err;
} }
...@@ -678,6 +695,7 @@ int VLC_AddTarget( int i_object, char const *psz_target, int i_mode, int i_pos ) ...@@ -678,6 +695,7 @@ int VLC_AddTarget( int i_object, char const *psz_target, int i_mode, int i_pos )
int VLC_Set( int i_object, char const *psz_var, vlc_value_t value ) int VLC_Set( int i_object, char const *psz_var, vlc_value_t value )
{ {
vlc_t *p_vlc; vlc_t *p_vlc;
int i_ret;
p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc; p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
...@@ -712,11 +730,15 @@ int VLC_Set( int i_object, char const *psz_var, vlc_value_t value ) ...@@ -712,11 +730,15 @@ int VLC_Set( int i_object, char const *psz_var, vlc_value_t value )
config_PutPsz( p_vlc, psz_newvar, value.psz_string ); config_PutPsz( p_vlc, psz_newvar, value.psz_string );
break; break;
} }
if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
} }
return var_Set( p_vlc, psz_var, value ); i_ret = var_Set( p_vlc, psz_var, value );
if( i_object ) vlc_object_release( p_vlc );
return i_ret;
} }
/***************************************************************************** /*****************************************************************************
...@@ -727,6 +749,7 @@ int VLC_Set( int i_object, char const *psz_var, vlc_value_t value ) ...@@ -727,6 +749,7 @@ int VLC_Set( int i_object, char const *psz_var, vlc_value_t value )
int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value ) int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
{ {
vlc_t *p_vlc; vlc_t *p_vlc;
int i_ret;
p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc; p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
...@@ -735,7 +758,10 @@ int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value ) ...@@ -735,7 +758,10 @@ int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
return VLC_ENOOBJ; return VLC_ENOOBJ;
} }
return var_Get( p_vlc, psz_var, p_value ); i_ret = var_Get( p_vlc, psz_var, p_value );
if( i_object ) vlc_object_release( p_vlc );
return i_ret;
} }
/* FIXME: temporary hacks */ /* FIXME: temporary hacks */
...@@ -769,6 +795,7 @@ int VLC_Play( int i_object ) ...@@ -769,6 +795,7 @@ int VLC_Play( int i_object )
if( !p_playlist ) if( !p_playlist )
{ {
if( i_object ) vlc_object_release( p_vlc );
return VLC_ENOOBJ; return VLC_ENOOBJ;
} }
...@@ -785,6 +812,7 @@ int VLC_Play( int i_object ) ...@@ -785,6 +812,7 @@ int VLC_Play( int i_object )
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -853,6 +881,7 @@ int VLC_Stop( int i_object ) ...@@ -853,6 +881,7 @@ int VLC_Stop( int i_object )
aout_Delete( p_aout ); aout_Delete( p_aout );
} }
if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -875,12 +904,14 @@ int VLC_Pause( int i_object ) ...@@ -875,12 +904,14 @@ int VLC_Pause( int i_object )
if( !p_input ) if( !p_input )
{ {
if( i_object ) vlc_object_release( p_vlc );
return VLC_ENOOBJ; return VLC_ENOOBJ;
} }
input_SetStatus( p_input, INPUT_STATUS_PAUSE ); input_SetStatus( p_input, INPUT_STATUS_PAUSE );
vlc_object_release( p_input ); vlc_object_release( p_input );
if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -903,12 +934,14 @@ int VLC_FullScreen( int i_object ) ...@@ -903,12 +934,14 @@ int VLC_FullScreen( int i_object )
if( !p_vout ) if( !p_vout )
{ {
if( i_object ) vlc_object_release( p_vlc );
return VLC_ENOOBJ; return VLC_ENOOBJ;
} }
p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE; p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
vlc_object_release( p_vout ); vlc_object_release( p_vout );
if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* objects.c: vlc_object_t handling * objects.c: vlc_object_t handling
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: objects.c,v 1.32 2002/12/13 01:56:30 gbazin Exp $ * $Id: objects.c,v 1.33 2002/12/14 19:34:06 gbazin Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -60,6 +60,8 @@ static void SetAttachment ( vlc_object_t *, vlc_bool_t ); ...@@ -60,6 +60,8 @@ static void SetAttachment ( vlc_object_t *, vlc_bool_t );
static vlc_list_t NewList ( int ); static vlc_list_t NewList ( int );
static void ListReplace ( vlc_list_t *, vlc_object_t *, int ); static void ListReplace ( vlc_list_t *, vlc_object_t *, int );
static void ListAppend ( vlc_list_t *, vlc_object_t * ); static void ListAppend ( vlc_list_t *, vlc_object_t * );
static int CountChildren ( vlc_object_t *, int );
static void ListChildren ( vlc_list_t *, vlc_object_t *, int );
/***************************************************************************** /*****************************************************************************
* Local structure lock * Local structure lock
...@@ -351,6 +353,7 @@ void * __vlc_object_get( vlc_object_t *p_this, int i_id ) ...@@ -351,6 +353,7 @@ void * __vlc_object_get( vlc_object_t *p_this, int i_id )
if( pp_objects[i_middle+1]->i_object_id == i_id ) if( pp_objects[i_middle+1]->i_object_id == i_id )
{ {
vlc_mutex_unlock( &structure_lock ); vlc_mutex_unlock( &structure_lock );
pp_objects[i_middle+1]->i_refcount++;
return pp_objects[i_middle+1]; return pp_objects[i_middle+1];
} }
break; break;
...@@ -359,6 +362,7 @@ void * __vlc_object_get( vlc_object_t *p_this, int i_id ) ...@@ -359,6 +362,7 @@ void * __vlc_object_get( vlc_object_t *p_this, int i_id )
else else
{ {
vlc_mutex_unlock( &structure_lock ); vlc_mutex_unlock( &structure_lock );
pp_objects[i_middle]->i_refcount++;
return pp_objects[i_middle]; return pp_objects[i_middle];
} }
...@@ -490,15 +494,15 @@ void __vlc_object_detach( vlc_object_t *p_this ) ...@@ -490,15 +494,15 @@ void __vlc_object_detach( vlc_object_t *p_this )
vlc_list_t __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode ) vlc_list_t __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
{ {
vlc_list_t list; vlc_list_t list;
vlc_object_t **pp_current, **pp_end;
int i_count = 0, i_index = 0;
vlc_mutex_lock( &structure_lock ); vlc_mutex_lock( &structure_lock );
/* Look for the objects */ /* Look for the objects */
if( (i_mode & 0x000f) == FIND_ANYWHERE ) switch( i_mode & 0x000f )
{ {
vlc_object_t **pp_current, **pp_end; case FIND_ANYWHERE:
int i_count = 0, i_index = 0;
pp_current = p_this->p_libvlc->pp_objects; pp_current = p_this->p_libvlc->pp_objects;
pp_end = pp_current + p_this->p_libvlc->i_objects; pp_end = pp_current + p_this->p_libvlc->i_objects;
...@@ -523,11 +527,28 @@ vlc_list_t __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode ) ...@@ -523,11 +527,28 @@ vlc_list_t __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
if( i_index < i_count ) i_index++; if( i_index < i_count ) i_index++;
} }
} }
} break;
else
case FIND_CHILD:
i_count = CountChildren( p_this, i_type );
list = NewList( i_count );
/* Check allocation was successful */
if( list.i_count != i_count )
{ {
msg_Err( p_this, "list allocation failed!" );
list.i_count = 0;
break;
}
list.i_count = 0;
ListChildren( &list, p_this, i_type );
break;
default:
msg_Err( p_this, "unimplemented!" ); msg_Err( p_this, "unimplemented!" );
list = NewList( 0 ); list = NewList( 0 );
break;
} }
vlc_mutex_unlock( &structure_lock ); vlc_mutex_unlock( &structure_lock );
...@@ -570,6 +591,11 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd, ...@@ -570,6 +591,11 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
DumpStructure( p_object, 0, psz_foo ); DumpStructure( p_object, 0, psz_foo );
vlc_mutex_unlock( &structure_lock ); vlc_mutex_unlock( &structure_lock );
if( *newval.psz_string )
{
vlc_object_release( p_this );
}
} }
else if( *psz_cmd == 'l' ) else if( *psz_cmd == 'l' )
{ {
...@@ -915,3 +941,47 @@ static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object ) ...@@ -915,3 +941,47 @@ static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
return; return;
} }
static int CountChildren( vlc_object_t *p_this, int i_type )
{
vlc_object_t *p_tmp;
int i, i_count = 0;
for( i = 0; i < p_this->i_children; i++ )
{
p_tmp = p_this->pp_children[i];
if( p_tmp->i_object_type == i_type )
{
i_count++;
}
if( p_tmp->i_children )
{
i_count += CountChildren( p_tmp, i_type );
}
}
return i_count;
}
static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type )
{
vlc_object_t *p_tmp;
int i;
for( i = 0; i < p_this->i_children; i++ )
{
p_tmp = p_this->pp_children[i];
if( p_tmp->i_object_type == i_type )
{
ListReplace( p_list, p_tmp, p_list->i_count++ );
}
if( p_tmp->i_children )
{
ListChildren( p_list, p_tmp, i_type );
}
}
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* variables.c: routines for object variables handling * variables.c: routines for object variables handling
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: variables.c,v 1.17 2002/12/10 18:22:01 gbazin Exp $ * $Id: variables.c,v 1.18 2002/12/14 19:34:06 gbazin Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -132,8 +132,8 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type ) ...@@ -132,8 +132,8 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
p_var->i_usage = 1; p_var->i_usage = 1;
p_var->i_default = -1; p_var->i_default = -1;
p_var->i_choices = 0; p_var->choices.i_count = 0;
p_var->pp_choices = NULL; p_var->choices.p_values = NULL;
p_var->b_incallback = VLC_FALSE; p_var->b_incallback = VLC_FALSE;
p_var->i_entries = 0; p_var->i_entries = 0;
...@@ -220,13 +220,13 @@ int __var_Destroy( vlc_object_t *p_this, const char *psz_name ) ...@@ -220,13 +220,13 @@ int __var_Destroy( vlc_object_t *p_this, const char *psz_name )
p_var->pf_free( &p_var->val ); p_var->pf_free( &p_var->val );
/* Free choice list if needed */ /* Free choice list if needed */
if( p_var->pp_choices ) if( p_var->choices.i_count )
{ {
for( i = 0 ; i < p_var->i_choices ; i++ ) for( i = 0 ; i < p_var->choices.i_count ; i++ )
{ {
p_var->pf_free( &p_var->pp_choices[i] ); p_var->pf_free( &p_var->choices.p_values[i] );
} }
free( p_var->pp_choices ); free( p_var->choices.p_values );
} }
/* Free callbacks if needed */ /* Free callbacks if needed */
...@@ -309,12 +309,11 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, ...@@ -309,12 +309,11 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name,
p_var->pf_dup( &p_var->step ); p_var->pf_dup( &p_var->step );
CheckValue( p_var, &p_var->val ); CheckValue( p_var, &p_var->val );
break; break;
case VLC_VAR_ADDCHOICE: case VLC_VAR_ADDCHOICE:
/* FIXME: the list is sorted, dude. Use something cleverer. */ /* FIXME: the list is sorted, dude. Use something cleverer. */
for( i = p_var->i_choices ; i-- ; ) for( i = p_var->choices.i_count ; i-- ; )
{ {
if( p_var->pf_cmp( p_var->pp_choices[i], *p_val ) < 0 ) if( p_var->pf_cmp( p_var->choices.p_values[i], *p_val ) < 0 )
{ {
break; break;
} }
...@@ -328,22 +327,23 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, ...@@ -328,22 +327,23 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name,
p_var->i_default++; p_var->i_default++;
} }
INSERT_ELEM( p_var->pp_choices, p_var->i_choices, i, *p_val ); INSERT_ELEM( p_var->choices.p_values, p_var->choices.i_count,
p_var->pf_dup( &p_var->pp_choices[i] ); i, *p_val );
p_var->pf_dup( &p_var->choices.p_values[i] );
CheckValue( p_var, &p_var->val ); CheckValue( p_var, &p_var->val );
break; break;
case VLC_VAR_DELCHOICE: case VLC_VAR_DELCHOICE:
/* FIXME: the list is sorted, dude. Use something cleverer. */ /* FIXME: the list is sorted, dude. Use something cleverer. */
for( i = 0 ; i < p_var->i_choices ; i++ ) for( i = 0 ; i < p_var->choices.i_count ; i++ )
{ {
if( p_var->pf_cmp( p_var->pp_choices[i], *p_val ) == 0 ) if( p_var->pf_cmp( p_var->choices.p_values[i], *p_val ) == 0 )
{ {
break; break;
} }
} }
if( i == p_var->i_choices ) if( i == p_var->choices.i_count )
{ {
/* Not found */ /* Not found */
vlc_mutex_unlock( &p_this->var_lock ); vlc_mutex_unlock( &p_this->var_lock );
...@@ -359,22 +359,22 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, ...@@ -359,22 +359,22 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name,
p_var->i_default = -1; p_var->i_default = -1;
} }
p_var->pf_free( &p_var->pp_choices[i] ); p_var->pf_free( &p_var->choices.p_values[i] );
REMOVE_ELEM( p_var->pp_choices, p_var->i_choices, i ); REMOVE_ELEM( p_var->choices.p_values, p_var->choices.i_count, i );
CheckValue( p_var, &p_var->val ); CheckValue( p_var, &p_var->val );
break; break;
case VLC_VAR_SETDEFAULT: case VLC_VAR_SETDEFAULT:
/* FIXME: the list is sorted, dude. Use something cleverer. */ /* FIXME: the list is sorted, dude. Use something cleverer. */
for( i = 0 ; i < p_var->i_choices ; i++ ) for( i = 0 ; i < p_var->choices.i_count ; i++ )
{ {
if( p_var->pf_cmp( p_var->pp_choices[i], *p_val ) == 0 ) if( p_var->pf_cmp( p_var->choices.p_values[i], *p_val ) == 0 )
{ {
break; break;
} }
} }
if( i == p_var->i_choices ) if( i == p_var->choices.i_count )
{ {
/* Not found */ /* Not found */
break; break;
...@@ -385,21 +385,23 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, ...@@ -385,21 +385,23 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name,
break; break;
case VLC_VAR_GETLIST: case VLC_VAR_GETLIST:
p_val->p_address = malloc( (1 + p_var->i_choices) p_val->p_list = malloc( sizeof(vlc_list_t) );
p_val->p_list->p_values = malloc( p_var->choices.i_count
* sizeof(vlc_value_t) ); * sizeof(vlc_value_t) );
((vlc_value_t*)p_val->p_address)[0].i_int = p_var->i_choices; p_val->p_list->i_count = p_var->choices.i_count;
for( i = 0 ; i < p_var->i_choices ; i++ ) for( i = 0 ; i < p_var->choices.i_count ; i++ )
{ {
((vlc_value_t*)p_val->p_address)[i+1] = p_var->pp_choices[i]; p_val->p_list->p_values[i] = p_var->choices.p_values[i];
p_var->pf_dup( &((vlc_value_t*)p_val->p_address)[i+1] ); p_var->pf_dup( &p_val->p_list->p_values[i] );
} }
break; break;
case VLC_VAR_FREELIST: case VLC_VAR_FREELIST:
for( i = ((vlc_value_t*)p_val->p_address)[0].i_int ; i-- ; ) for( i = p_val->p_list->i_count ; i-- ; )
{ {
p_var->pf_free( &((vlc_value_t*)p_val->p_address)[i+1] ); p_var->pf_free( &p_val->p_list->p_values[i] );
} }
free( p_val->p_address ); free( p_val->p_list->p_values );
free( p_val->p_list );
break; break;
default: default:
...@@ -836,14 +838,14 @@ static int LookupInner( variable_t *p_vars, int i_count, uint32_t i_hash ) ...@@ -836,14 +838,14 @@ static int LookupInner( variable_t *p_vars, int i_count, uint32_t i_hash )
static void CheckValue ( variable_t *p_var, vlc_value_t *p_val ) static void CheckValue ( variable_t *p_var, vlc_value_t *p_val )
{ {
/* Check that our variable is in the list */ /* Check that our variable is in the list */
if( p_var->i_type & VLC_VAR_HASCHOICE && p_var->i_choices ) if( p_var->i_type & VLC_VAR_HASCHOICE && p_var->choices.i_count )
{ {
int i; int i;
/* FIXME: the list is sorted, dude. Use something cleverer. */ /* FIXME: the list is sorted, dude. Use something cleverer. */
for( i = p_var->i_choices ; i-- ; ) for( i = p_var->choices.i_count ; i-- ; )
{ {
if( p_var->pf_cmp( *p_val, p_var->pp_choices[i] ) == 0 ) if( p_var->pf_cmp( *p_val, p_var->choices.p_values[i] ) == 0 )
{ {
break; break;
} }
...@@ -854,7 +856,7 @@ static void CheckValue ( variable_t *p_var, vlc_value_t *p_val ) ...@@ -854,7 +856,7 @@ static void CheckValue ( variable_t *p_var, vlc_value_t *p_val )
{ {
/* Free the old variable, get the new one, dup it */ /* Free the old variable, get the new one, dup it */
p_var->pf_free( p_val ); p_var->pf_free( p_val );
*p_val = p_var->pp_choices[p_var->i_default >= 0 *p_val = p_var->choices.p_values[p_var->i_default >= 0
? p_var->i_default : 0 ]; ? p_var->i_default : 0 ];
p_var->pf_dup( p_val ); p_var->pf_dup( p_val );
} }
...@@ -907,4 +909,3 @@ static void CheckValue ( variable_t *p_var, vlc_value_t *p_val ) ...@@ -907,4 +909,3 @@ static void CheckValue ( variable_t *p_var, vlc_value_t *p_val )
break; break;
} }
} }
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