* objects.c: vlc_object_t handling
*****************************************************************************
* Copyright (C) 2002 VideoLAN
- * $Id: objects.c,v 1.32 2002/12/13 01:56:30 gbazin Exp $
+ * $Id: objects.c,v 1.37 2003/06/26 12:19:59 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#include "input_ext-intf.h"
#include "input_ext-dec.h"
-#include "video.h"
+#include "vlc_video.h"
#include "video_output.h"
#include "audio_output.h"
#include "stream_output.h"
#include "vlc_playlist.h"
-#include "interface.h"
+#include "vlc_interface.h"
+#include "httpd.h"
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int FindIndex ( vlc_object_t *, vlc_object_t **, int );
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 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
i_size = sizeof(sout_instance_t);
psz_type = "stream output";
break;
+ case VLC_OBJECT_HTTPD:
+ i_size = sizeof( httpd_t );
+ psz_type = "http daemon";
+ break;
default:
i_size = i_type > 0
? i_type > (int)sizeof(vlc_object_t)
if( pp_objects[i_middle+1]->i_object_id == i_id )
{
vlc_mutex_unlock( &structure_lock );
+ pp_objects[i_middle+1]->i_refcount++;
return pp_objects[i_middle+1];
}
break;
else
{
vlc_mutex_unlock( &structure_lock );
+ pp_objects[i_middle]->i_refcount++;
return pp_objects[i_middle];
}
* This function recursively looks for a given object type. i_mode can be one
* of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
*****************************************************************************/
-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 *p_list;
+ vlc_object_t **pp_current, **pp_end;
+ int i_count = 0, i_index = 0;
vlc_mutex_lock( &structure_lock );
/* Look for the objects */
- if( (i_mode & 0x000f) == FIND_ANYWHERE )
+ switch( i_mode & 0x000f )
{
- vlc_object_t **pp_current, **pp_end;
- int i_count = 0, i_index = 0;
-
+ case FIND_ANYWHERE:
pp_current = p_this->p_libvlc->pp_objects;
pp_end = pp_current + p_this->p_libvlc->i_objects;
}
}
- list = NewList( i_count );
+ p_list = NewList( i_count );
pp_current = p_this->p_libvlc->pp_objects;
for( ; pp_current < pp_end ; pp_current++ )
if( (*pp_current)->b_attached
&& (*pp_current)->i_object_type == i_type )
{
- ListReplace( &list, *pp_current, i_index );
+ ListReplace( p_list, *pp_current, i_index );
if( i_index < i_count ) i_index++;
}
}
- }
- else
- {
+ break;
+
+ case FIND_CHILD:
+ i_count = CountChildren( p_this, i_type );
+ p_list = NewList( i_count );
+
+ /* Check allocation was successful */
+ if( p_list->i_count != i_count )
+ {
+ msg_Err( p_this, "list allocation failed!" );
+ p_list->i_count = 0;
+ break;
+ }
+
+ p_list->i_count = 0;
+ ListChildren( p_list, p_this, i_type );
+ break;
+
+ default:
msg_Err( p_this, "unimplemented!" );
- list = NewList( 0 );
+ p_list = NewList( 0 );
+ break;
}
vlc_mutex_unlock( &structure_lock );
- return list;
+ return p_list;
}
/*****************************************************************************
DumpStructure( p_object, 0, psz_foo );
vlc_mutex_unlock( &structure_lock );
+
+ if( *newval.psz_string )
+ {
+ vlc_object_release( p_this );
+ }
}
else if( *psz_cmd == 'l' )
{
}
free( p_list->p_values );
+ free( p_list );
}
/* Following functions are local */
}
}
-static vlc_list_t NewList( int i_count )
+static vlc_list_t * NewList( int i_count )
{
- vlc_list_t list;
+ vlc_list_t * p_list = (vlc_list_t *)malloc( sizeof( vlc_list_t ) );
+ if( p_list == NULL )
+ {
+ return NULL;
+ }
- list.i_count = i_count;
+ p_list->i_count = i_count;
if( i_count == 0 )
{
- list.p_values = NULL;
- return list;
+ p_list->p_values = NULL;
+ return p_list;
}
- list.p_values = malloc( i_count * sizeof( vlc_value_t ) );
- if( list.p_values == NULL )
+ p_list->p_values = malloc( i_count * sizeof( vlc_value_t ) );
+ if( p_list->p_values == NULL )
{
- list.i_count = 0;
- return list;
+ p_list->i_count = 0;
+ return p_list;
}
- return list;
+ return p_list;
}
static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
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 );
+ }
+ }
+}