]> git.sesse.net Git - vlc/blobdiff - src/misc/objects.c
* added a vlc_current_charset function. This tries to get the current charset
[vlc] / src / misc / objects.c
index f6ae50bde1ff0697af09211c947271d854f5fb61..333fbe147b26a2ef4a8b1f7bfd6d18e7212dac3f 100644 (file)
@@ -2,7 +2,7 @@
  * 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>
  *
@@ -10,7 +10,7 @@
  * 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
@@ -34,7 +34,7 @@
 #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"
@@ -42,8 +42,9 @@
 #include "stream_output.h"
 
 #include "vlc_playlist.h"
-#include "interface.h"
+#include "vlc_interface.h"
 
+#include "httpd.h"
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -57,9 +58,11 @@ static void           DumpStructure ( vlc_object_t *, int, char * );
 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
@@ -121,6 +124,10 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
             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)
@@ -351,6 +358,7 @@ void * __vlc_object_get( vlc_object_t *p_this, int i_id )
                 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;
@@ -359,6 +367,7 @@ void * __vlc_object_get( vlc_object_t *p_this, int i_id )
         else
         {
             vlc_mutex_unlock( &structure_lock );
+            pp_objects[i_middle]->i_refcount++;
             return pp_objects[i_middle];
         }
 
@@ -487,18 +496,18 @@ void __vlc_object_detach( vlc_object_t *p_this )
  * 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;
 
@@ -511,7 +520,7 @@ vlc_list_t __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
             }
         }
 
-        list = NewList( i_count );
+        p_list = NewList( i_count );
         pp_current = p_this->p_libvlc->pp_objects;
 
         for( ; pp_current < pp_end ; pp_current++ )
@@ -519,20 +528,37 @@ vlc_list_t __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
             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;
 }
 
 /*****************************************************************************
@@ -570,6 +596,11 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
         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' )
     {
@@ -620,6 +651,7 @@ void vlc_list_release( vlc_list_t *p_list )
     }
 
     free( p_list->p_values );
+    free( p_list );
 }
 
 /* Following functions are local */
@@ -856,26 +888,30 @@ static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
     }
 }
 
-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,
@@ -915,3 +951,47 @@ static void ListAppend( 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 );
+        }
+    }
+}