1 /*****************************************************************************
2 * objects.c: vlc_object_t handling
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
26 * This file contains the functions to handle the vlc_object_t type
30 /*****************************************************************************
32 *****************************************************************************/
36 # include <stdlib.h> /* realloc() */
41 #include "audio_output/aout_internal.h"
43 #include <vlc_access.h>
44 #include <vlc_demux.h>
45 #include <vlc_stream.h>
48 #include "stream_output/stream_output.h"
50 #include "vlc_playlist.h"
51 #include "vlc_interface.h"
52 #include "vlc_codec.h"
53 #include "vlc_filter.h"
55 #include "vlc_httpd.h"
56 #include "../network/httpd.h"
64 #include "variables.h"
66 /*****************************************************************************
68 *****************************************************************************/
69 static int DumpCommand( vlc_object_t *, char const *,
70 vlc_value_t, vlc_value_t, void * );
72 static vlc_object_t * FindObject ( vlc_object_t *, int, int );
73 static void DetachObject ( vlc_object_t * );
74 static void PrintObject ( vlc_object_t *, const char * );
75 static void DumpStructure ( vlc_object_t *, int, char * );
76 static int FindIndex ( vlc_object_t *, vlc_object_t **, int );
77 static void SetAttachment ( vlc_object_t *, vlc_bool_t );
79 static vlc_list_t * NewList ( int );
80 static void ListReplace ( vlc_list_t *, vlc_object_t *, int );
81 /*static void ListAppend ( vlc_list_t *, vlc_object_t * );*/
82 static int CountChildren ( vlc_object_t *, int );
83 static void ListChildren ( vlc_list_t *, vlc_object_t *, int );
85 /*****************************************************************************
86 * Local structure lock
87 *****************************************************************************/
88 static vlc_mutex_t structure_lock;
91 * Initialize a vlc object
93 * This function allocates memory for a vlc object and initializes it. If
94 * i_type is not a known value such as VLC_OBJECT_LIBVLC, VLC_OBJECT_VOUT and
95 * so on, vlc_object_create will use its value for the object size.
97 void * __vlc_object_create( vlc_object_t *p_this, int i_type )
100 const char * psz_type;
105 case VLC_OBJECT_GLOBAL:
106 i_size = sizeof(libvlc_global_data_t);
109 case VLC_OBJECT_LIBVLC:
110 i_size = sizeof(libvlc_int_t);
113 case VLC_OBJECT_MODULE:
114 i_size = sizeof(module_t);
117 case VLC_OBJECT_INTF:
118 i_size = sizeof(intf_thread_t);
119 psz_type = "interface";
121 case VLC_OBJECT_DIALOGS:
122 i_size = sizeof(intf_thread_t);
123 psz_type = "dialogs";
125 case VLC_OBJECT_PLAYLIST:
126 i_size = sizeof(playlist_t);
127 psz_type = "playlist";
130 i_size = sizeof(services_discovery_t);
131 psz_type = "services discovery";
133 case VLC_OBJECT_INPUT:
134 i_size = sizeof(input_thread_t);
137 case VLC_OBJECT_DEMUX:
138 i_size = sizeof(demux_t);
141 case VLC_OBJECT_STREAM:
142 i_size = sizeof(stream_t);
145 case VLC_OBJECT_ACCESS:
146 i_size = sizeof(access_t);
149 case VLC_OBJECT_DECODER:
150 i_size = sizeof(decoder_t);
151 psz_type = "decoder";
153 case VLC_OBJECT_PACKETIZER:
154 i_size = sizeof(decoder_t);
155 psz_type = "packetizer";
157 case VLC_OBJECT_ENCODER:
158 i_size = sizeof(encoder_t);
159 psz_type = "encoder";
161 case VLC_OBJECT_FILTER:
162 i_size = sizeof(filter_t);
165 case VLC_OBJECT_VOUT:
166 i_size = sizeof(vout_thread_t);
167 psz_type = "video output";
170 i_size = sizeof(spu_t);
171 psz_type = "subpicture";
173 case VLC_OBJECT_AOUT:
174 i_size = sizeof(aout_instance_t);
175 psz_type = "audio output";
177 case VLC_OBJECT_SOUT:
178 i_size = sizeof(sout_instance_t);
179 psz_type = "stream output";
181 case VLC_OBJECT_HTTPD:
182 i_size = sizeof( httpd_t );
183 psz_type = "http server";
185 case VLC_OBJECT_HTTPD_HOST:
186 i_size = sizeof( httpd_host_t );
187 psz_type = "http server";
190 i_size = sizeof( vlm_t );
191 psz_type = "vlm dameon";
194 i_size = sizeof( vod_t );
195 psz_type = "vod server";
198 i_size = sizeof( tls_t );
202 i_size = sizeof( xml_t );
205 case VLC_OBJECT_OPENGL:
206 i_size = sizeof( vout_thread_t );
209 case VLC_OBJECT_ANNOUNCE:
210 i_size = sizeof( announce_handler_t );
211 psz_type = "announce";
213 case VLC_OBJECT_META_ENGINE:
214 i_size = sizeof( meta_engine_t );
215 psz_type = "meta engine";
217 case VLC_OBJECT_OSDMENU:
218 i_size = sizeof( osd_menu_t );
219 psz_type = "osd menu";
222 i_size = i_type > (int)sizeof(vlc_object_t)
223 ? i_type : (int)sizeof(vlc_object_t);
224 i_type = VLC_OBJECT_GENERIC;
225 psz_type = "generic";
229 if( i_type == VLC_OBJECT_GLOBAL )
235 p_new = malloc( i_size );
236 if( !p_new ) return NULL;
237 memset( p_new, 0, i_size );
240 p_new->i_object_type = i_type;
241 p_new->psz_object_type = psz_type;
243 p_new->psz_object_name = NULL;
245 p_new->b_die = VLC_FALSE;
246 p_new->b_error = VLC_FALSE;
247 p_new->b_dead = VLC_FALSE;
248 p_new->b_attached = VLC_FALSE;
249 p_new->b_force = VLC_FALSE;
251 p_new->psz_header = NULL;
254 if( p_this->i_flags & OBJECT_FLAGS_NODBG )
255 p_new->i_flags |= OBJECT_FLAGS_NODBG;
256 if( p_this->i_flags & OBJECT_FLAGS_QUIET )
257 p_new->i_flags |= OBJECT_FLAGS_QUIET;
258 if( p_this->i_flags & OBJECT_FLAGS_NOINTERACT )
259 p_new->i_flags |= OBJECT_FLAGS_NOINTERACT;
262 p_new->p_vars = (variable_t *)malloc( 16 * sizeof( variable_t ) );
266 if( i_type != VLC_OBJECT_GLOBAL )
271 if( i_type == VLC_OBJECT_GLOBAL )
273 /* If i_type is global, then p_new is actually p_libvlc_global */
274 p_new->p_libvlc_global = (libvlc_global_data_t*)p_new;
275 p_new->p_libvlc = NULL;
277 p_new->p_libvlc_global->i_counter = 0;
278 p_new->i_object_id = 0;
280 p_new->p_libvlc_global->i_objects = 1;
281 p_new->p_libvlc_global->pp_objects = malloc( sizeof(vlc_object_t *) );
282 p_new->p_libvlc_global->pp_objects[0] = p_new;
283 p_new->b_attached = VLC_TRUE;
287 p_new->p_libvlc_global = p_this->p_libvlc_global;
288 p_new->p_libvlc = ( i_type == VLC_OBJECT_LIBVLC ) ? (libvlc_int_t*)p_new
291 vlc_mutex_lock( &structure_lock );
293 p_new->p_libvlc_global->i_counter++;
294 p_new->i_object_id = p_new->p_libvlc_global->i_counter;
296 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
297 * useless to try and recover anything if pp_objects gets smashed. */
298 TAB_APPEND( p_new->p_libvlc_global->i_objects,
299 p_new->p_libvlc_global->pp_objects,
302 vlc_mutex_unlock( &structure_lock );
305 p_new->i_refcount = 0;
306 p_new->p_parent = NULL;
307 p_new->pp_children = NULL;
308 p_new->i_children = 0;
310 p_new->p_private = NULL;
312 /* Initialize mutexes and condvars */
313 vlc_mutex_init( p_new, &p_new->object_lock );
314 vlc_cond_init( p_new, &p_new->object_wait );
315 vlc_mutex_init( p_new, &p_new->var_lock );
317 if( i_type == VLC_OBJECT_GLOBAL )
319 vlc_mutex_init( p_new, &structure_lock );
321 var_Create( p_new, "list", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
322 var_AddCallback( p_new, "list", DumpCommand, NULL );
323 var_Create( p_new, "tree", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
324 var_AddCallback( p_new, "tree", DumpCommand, NULL );
331 ****************************************************************************
332 * Destroy a vlc object
334 * This function destroys an object that has been previously allocated with
335 * vlc_object_create. The object's refcount must be zero and it must not be
336 * attached to other objects in any way.
337 *****************************************************************************/
338 void __vlc_object_destroy( vlc_object_t *p_this )
342 if( p_this->i_children )
344 msg_Err( p_this, "cannot delete object (%i, %s) with children" ,
345 p_this->i_object_id, p_this->psz_object_name );
349 if( p_this->p_parent )
351 msg_Err( p_this, "cannot delete object (%i, %s) with a parent",
352 p_this->i_object_id, p_this->psz_object_name );
356 while( p_this->i_refcount )
360 /* Don't warn immediately ... 100ms seems OK */
364 "refcount is %i, delaying before deletion (id=%d,type=%d)",
365 p_this->i_refcount, p_this->i_object_id,
366 p_this->i_object_type );
368 else if( i_delay == 10 )
371 "refcount is %i, delaying again (id=%d,type=%d)",
372 p_this->i_refcount, p_this->i_object_id,
373 p_this->i_object_type );
375 else if( i_delay == 20 )
378 "waited too long, cancelling destruction (id=%d,type=%d)",
379 p_this->i_object_id, p_this->i_object_type );
386 /* Destroy the associated variables, starting from the end so that
387 * no memmove calls have to be done. */
388 while( p_this->i_vars )
390 var_Destroy( p_this, p_this->p_vars[p_this->i_vars - 1].psz_name );
393 free( p_this->p_vars );
394 vlc_mutex_destroy( &p_this->var_lock );
396 if( p_this->psz_header ) free( p_this->psz_header );
398 if( p_this->i_object_type == VLC_OBJECT_GLOBAL )
400 /* We are the global object ... no need to lock. */
401 free( p_this->p_libvlc_global->pp_objects );
402 p_this->p_libvlc_global->pp_objects = NULL;
403 p_this->p_libvlc_global->i_objects--;
405 vlc_mutex_destroy( &structure_lock );
411 vlc_mutex_lock( &structure_lock );
413 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
414 * useless to try and recover anything if pp_objects gets smashed. */
415 i_index = FindIndex( p_this, p_this->p_libvlc_global->pp_objects,
416 p_this->p_libvlc_global->i_objects );
417 REMOVE_ELEM( p_this->p_libvlc_global->pp_objects,
418 p_this->p_libvlc_global->i_objects, i_index );
420 vlc_mutex_unlock( &structure_lock );
423 vlc_mutex_destroy( &p_this->object_lock );
424 vlc_cond_destroy( &p_this->object_wait );
426 /* global is not dynamically allocated by vlc_object_create */
427 if( p_this->i_object_type != VLC_OBJECT_GLOBAL )
432 * find an object given its ID
434 * This function looks for the object whose i_object_id field is i_id. We
435 * use a dichotomy so that lookups are in log2(n).
436 *****************************************************************************/
437 void * __vlc_object_get( vlc_object_t *p_this, int i_id )
440 vlc_object_t **pp_objects;
442 vlc_mutex_lock( &structure_lock );
444 pp_objects = p_this->p_libvlc_global->pp_objects;
446 /* Perform our dichotomy */
447 for( i_max = p_this->p_libvlc_global->i_objects - 1 ; ; )
449 i_middle = i_max / 2;
451 if( pp_objects[i_middle]->i_object_id > i_id )
455 else if( pp_objects[i_middle]->i_object_id < i_id )
459 pp_objects += i_middle;
464 /* This happens when there are only two remaining objects */
465 if( pp_objects[i_middle+1]->i_object_id == i_id )
467 vlc_mutex_unlock( &structure_lock );
468 pp_objects[i_middle+1]->i_refcount++;
469 return pp_objects[i_middle+1];
476 vlc_mutex_unlock( &structure_lock );
477 pp_objects[i_middle]->i_refcount++;
478 return pp_objects[i_middle];
483 /* this means that i_max == i_middle, and since we have already
484 * tested pp_objects[i_middle]), p_found is properly set. */
489 vlc_mutex_unlock( &structure_lock );
494 ****************************************************************************
495 * find a typed object and increment its refcount
496 *****************************************************************************
497 * This function recursively looks for a given object type. i_mode can be one
498 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
499 *****************************************************************************/
500 void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
502 vlc_object_t *p_found;
504 vlc_mutex_lock( &structure_lock );
506 /* If we are of the requested type ourselves, don't look further */
507 if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
509 p_this->i_refcount++;
510 vlc_mutex_unlock( &structure_lock );
514 /* Otherwise, recursively look for the object */
515 if( (i_mode & 0x000f) == FIND_ANYWHERE )
517 vlc_object_t *p_root = p_this;
520 while( p_root->p_parent != NULL &&
521 p_root != VLC_OBJECT( p_this->p_libvlc ) )
523 p_root = p_root->p_parent;
526 p_found = FindObject( p_root, i_type, (i_mode & ~0x000f)|FIND_CHILD );
527 if( p_found == NULL && p_root != VLC_OBJECT( p_this->p_libvlc ) )
529 p_found = FindObject( VLC_OBJECT( p_this->p_libvlc ),
530 i_type, (i_mode & ~0x000f)|FIND_CHILD );
535 p_found = FindObject( p_this, i_type, i_mode );
538 vlc_mutex_unlock( &structure_lock );
544 ****************************************************************************
545 * increment an object refcount
546 *****************************************************************************/
547 void __vlc_object_yield( vlc_object_t *p_this )
549 vlc_mutex_lock( &structure_lock );
550 p_this->i_refcount++;
551 vlc_mutex_unlock( &structure_lock );
555 ****************************************************************************
556 * decrement an object refcount
557 *****************************************************************************/
558 void __vlc_object_release( vlc_object_t *p_this )
560 vlc_mutex_lock( &structure_lock );
561 p_this->i_refcount--;
562 vlc_mutex_unlock( &structure_lock );
566 ****************************************************************************
567 * attach object to a parent object
568 *****************************************************************************
569 * This function sets p_this as a child of p_parent, and p_parent as a parent
570 * of p_this. This link can be undone using vlc_object_detach.
571 *****************************************************************************/
572 void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
574 vlc_mutex_lock( &structure_lock );
576 /* Attach the parent to its child */
577 p_this->p_parent = p_parent;
579 /* Attach the child to its parent */
580 INSERT_ELEM( p_parent->pp_children, p_parent->i_children,
581 p_parent->i_children, p_this );
583 /* Climb up the tree to see whether we are connected with the root */
584 if( p_parent->b_attached )
586 SetAttachment( p_this, VLC_TRUE );
589 vlc_mutex_unlock( &structure_lock );
593 ****************************************************************************
594 * detach object from its parent
595 *****************************************************************************
596 * This function removes all links between an object and its parent.
597 *****************************************************************************/
598 void __vlc_object_detach( vlc_object_t *p_this )
600 vlc_mutex_lock( &structure_lock );
601 if( !p_this->p_parent )
603 msg_Err( p_this, "object is not attached" );
604 vlc_mutex_unlock( &structure_lock );
608 /* Climb up the tree to see whether we are connected with the root */
609 if( p_this->p_parent->b_attached )
611 SetAttachment( p_this, VLC_FALSE );
614 DetachObject( p_this );
615 vlc_mutex_unlock( &structure_lock );
619 ****************************************************************************
620 * find a list typed objects and increment their refcount
621 *****************************************************************************
622 * This function recursively looks for a given object type. i_mode can be one
623 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
624 *****************************************************************************/
625 vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
628 vlc_object_t **pp_current, **pp_end;
629 int i_count = 0, i_index = 0;
631 vlc_mutex_lock( &structure_lock );
633 /* Look for the objects */
634 switch( i_mode & 0x000f )
637 pp_current = p_this->p_libvlc_global->pp_objects;
638 pp_end = pp_current + p_this->p_libvlc_global->i_objects;
640 for( ; pp_current < pp_end ; pp_current++ )
642 if( (*pp_current)->b_attached
643 && (*pp_current)->i_object_type == i_type )
649 p_list = NewList( i_count );
650 pp_current = p_this->p_libvlc_global->pp_objects;
652 for( ; pp_current < pp_end ; pp_current++ )
654 if( (*pp_current)->b_attached
655 && (*pp_current)->i_object_type == i_type )
657 ListReplace( p_list, *pp_current, i_index );
658 if( i_index < i_count ) i_index++;
664 i_count = CountChildren( p_this, i_type );
665 p_list = NewList( i_count );
667 /* Check allocation was successful */
668 if( p_list->i_count != i_count )
670 msg_Err( p_this, "list allocation failed!" );
676 ListChildren( p_list, p_this, i_type );
680 msg_Err( p_this, "unimplemented!" );
681 p_list = NewList( 0 );
685 vlc_mutex_unlock( &structure_lock );
690 /*****************************************************************************
691 * DumpCommand: print the current vlc structure
692 *****************************************************************************
693 * This function prints either an ASCII tree showing the connections between
694 * vlc objects, and additional information such as their refcount, thread ID,
695 * etc. (command "tree"), or the same data as a simple list (command "list").
696 *****************************************************************************/
697 static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
698 vlc_value_t oldval, vlc_value_t newval, void *p_data )
700 if( *psz_cmd == 't' )
702 char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
703 vlc_object_t *p_object;
705 if( *newval.psz_string )
707 p_object = vlc_object_get( p_this, atoi(newval.psz_string) );
716 p_object = p_this->p_libvlc ? VLC_OBJECT(p_this->p_libvlc) : p_this;
719 vlc_mutex_lock( &structure_lock );
722 DumpStructure( p_object, 0, psz_foo );
724 vlc_mutex_unlock( &structure_lock );
726 if( *newval.psz_string )
728 vlc_object_release( p_this );
731 else if( *psz_cmd == 'l' )
733 vlc_object_t **pp_current, **pp_end;
735 vlc_mutex_lock( &structure_lock );
737 pp_current = p_this->p_libvlc_global->pp_objects;
738 pp_end = pp_current + p_this->p_libvlc_global->i_objects;
740 for( ; pp_current < pp_end ; pp_current++ )
742 if( (*pp_current)->b_attached )
744 PrintObject( *pp_current, "" );
748 printf( " o %.8i %s (not attached)\n",
749 (*pp_current)->i_object_id,
750 (*pp_current)->psz_object_type );
754 vlc_mutex_unlock( &structure_lock );
760 /*****************************************************************************
761 * vlc_list_release: free a list previously allocated by vlc_list_find
762 *****************************************************************************
763 * This function decreases the refcount of all objects in the list and
765 *****************************************************************************/
766 void vlc_list_release( vlc_list_t *p_list )
770 for( i_index = 0; i_index < p_list->i_count; i_index++ )
772 vlc_mutex_lock( &structure_lock );
774 p_list->p_values[i_index].p_object->i_refcount--;
776 vlc_mutex_unlock( &structure_lock );
779 free( p_list->p_values );
783 /* Following functions are local */
785 /*****************************************************************************
786 * FindIndex: find the index of an object in an array of objects
787 *****************************************************************************
788 * This function assumes that p_this can be found in pp_objects. It will not
789 * crash if p_this cannot be found, but will return a wrong value. It is your
790 * duty to check the return value if you are not certain that the object could
792 *****************************************************************************/
793 static int FindIndex( vlc_object_t *p_this,
794 vlc_object_t **pp_objects, int i_count )
796 int i_middle = i_count / 2;
803 if( pp_objects[i_middle] == p_this )
813 /* We take advantage of the sorted array */
814 if( pp_objects[i_middle]->i_object_id < p_this->i_object_id )
816 return i_middle + FindIndex( p_this, pp_objects + i_middle,
817 i_count - i_middle );
821 return FindIndex( p_this, pp_objects, i_middle );
825 static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
830 switch( i_mode & 0x000f )
833 p_tmp = p_this->p_parent;
836 if( p_tmp->i_object_type == i_type )
843 return FindObject( p_tmp, i_type, i_mode );
849 for( i = p_this->i_children; i--; )
851 p_tmp = p_this->pp_children[i];
852 if( p_tmp->i_object_type == i_type )
857 else if( p_tmp->i_children )
859 p_tmp = FindObject( p_tmp, i_type, i_mode );
869 /* Handled in vlc_object_find */
876 static void DetachObject( vlc_object_t *p_this )
878 vlc_object_t *p_parent = p_this->p_parent;
881 /* Remove p_this's parent */
882 p_this->p_parent = NULL;
884 /* Remove all of p_parent's children which are p_this */
885 for( i_index = p_parent->i_children ; i_index-- ; )
887 if( p_parent->pp_children[i_index] == p_this )
889 p_parent->i_children--;
890 for( i = i_index ; i < p_parent->i_children ; i++ )
892 p_parent->pp_children[i] = p_parent->pp_children[i+1];
897 if( p_parent->i_children )
899 p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children,
900 p_parent->i_children * sizeof(vlc_object_t *) );
904 free( p_parent->pp_children );
905 p_parent->pp_children = NULL;
909 /*****************************************************************************
910 * SetAttachment: recursively set the b_attached flag of a subtree.
911 *****************************************************************************
912 * This function is used by the attach and detach functions to propagate
913 * the b_attached flag in a subtree.
914 *****************************************************************************/
915 static void SetAttachment( vlc_object_t *p_this, vlc_bool_t b_attached )
919 for( i_index = p_this->i_children ; i_index-- ; )
921 SetAttachment( p_this->pp_children[i_index], b_attached );
924 p_this->b_attached = b_attached;
927 static void PrintObject( vlc_object_t *p_this, const char *psz_prefix )
929 char psz_children[20], psz_refcount[20], psz_thread[20], psz_name[50];
932 if( p_this->psz_object_name )
934 snprintf( psz_name, 50, " \"%s\"", p_this->psz_object_name );
939 psz_children[0] = '\0';
940 switch( p_this->i_children )
945 strcpy( psz_children, ", 1 child" );
948 snprintf( psz_children, 20,
949 ", %i children", p_this->i_children );
950 psz_children[19] = '\0';
954 psz_refcount[0] = '\0';
955 if( p_this->i_refcount )
957 snprintf( psz_refcount, 20, ", refcount %i", p_this->i_refcount );
958 psz_refcount[19] = '\0';
961 psz_thread[0] = '\0';
962 if( p_this->b_thread )
964 snprintf( psz_thread, 20, " (thread %d)", (int)p_this->thread_id );
965 psz_thread[19] = '\0';
968 printf( " %so %.8i %s%s%s%s%s\n", psz_prefix,
969 p_this->i_object_id, p_this->psz_object_type,
970 psz_name, psz_thread, psz_refcount, psz_children );
973 static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
976 char i_back = psz_foo[i_level];
977 psz_foo[i_level] = '\0';
979 PrintObject( p_this, psz_foo );
981 psz_foo[i_level] = i_back;
983 if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH )
985 msg_Warn( p_this, "structure tree is too deep" );
989 for( i = 0 ; i < p_this->i_children ; i++ )
993 psz_foo[i_level-1] = ' ';
995 if( psz_foo[i_level-2] == '`' )
997 psz_foo[i_level-2] = ' ';
1001 if( i == p_this->i_children - 1 )
1003 psz_foo[i_level] = '`';
1007 psz_foo[i_level] = '|';
1010 psz_foo[i_level+1] = '-';
1011 psz_foo[i_level+2] = '\0';
1013 DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo );
1017 static vlc_list_t * NewList( int i_count )
1019 vlc_list_t * p_list = (vlc_list_t *)malloc( sizeof( vlc_list_t ) );
1020 if( p_list == NULL )
1025 p_list->i_count = i_count;
1029 p_list->p_values = NULL;
1033 p_list->p_values = malloc( i_count * sizeof( vlc_value_t ) );
1034 if( p_list->p_values == NULL )
1036 p_list->i_count = 0;
1043 static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
1046 if( p_list == NULL || i_index >= p_list->i_count )
1051 p_object->i_refcount++;
1053 p_list->p_values[i_index].p_object = p_object;
1058 /*static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
1060 if( p_list == NULL )
1065 p_list->p_values = realloc( p_list->p_values, (p_list->i_count + 1)
1066 * sizeof( vlc_value_t ) );
1067 if( p_list->p_values == NULL )
1069 p_list->i_count = 0;
1073 p_object->i_refcount++;
1075 p_list->p_values[p_list->i_count].p_object = p_object;
1081 static int CountChildren( vlc_object_t *p_this, int i_type )
1083 vlc_object_t *p_tmp;
1086 for( i = 0; i < p_this->i_children; i++ )
1088 p_tmp = p_this->pp_children[i];
1090 if( p_tmp->i_object_type == i_type )
1095 if( p_tmp->i_children )
1097 i_count += CountChildren( p_tmp, i_type );
1104 static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type )
1106 vlc_object_t *p_tmp;
1109 for( i = 0; i < p_this->i_children; i++ )
1111 p_tmp = p_this->pp_children[i];
1113 if( p_tmp->i_object_type == i_type )
1115 ListReplace( p_list, p_tmp, p_list->i_count++ );
1118 if( p_tmp->i_children )
1120 ListChildren( p_list, p_tmp, i_type );