]> git.sesse.net Git - vlc/commitdiff
Add ability to prepend headers to messages (object-specific) and use it for VLM media...
authorClément Stenac <zorglub@videolan.org>
Sun, 15 Jan 2006 20:29:38 +0000 (20:29 +0000)
committerClément Stenac <zorglub@videolan.org>
Sun, 15 Jan 2006 20:29:38 +0000 (20:29 +0000)
To use it, put a string in p_object->psz_header, all messages from this object and its parent will have the header prepended

include/vlc_common.h
include/vlc_input.h
include/vlc_messages.h
include/vlc_symbols.h
src/input/input.c
src/misc/messages.c
src/misc/objects.c
src/misc/vlm.c

index eeb3763f994b4d28f60f35d751cced3da1eeb9b5..7f7dfa9da8700454283a9d856cf77bb9a27e622f 100644 (file)
@@ -471,6 +471,9 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *,      /* variable's object */
     char *psz_object_type;                                                  \
     char *psz_object_name;                                                  \
                                                                             \
+    /* Messages header */                                                   \
+    char *psz_header;                                                       \
+                                                                            \
     /* Thread properties, if any */                                         \
     vlc_bool_t   b_thread;                                                  \
     vlc_thread_t thread_id;                                                 \
index b4a37ebf0f8769f0fa68c3ca99667f64f1016ce6..ee9065e566df0d5d6c0593d4af743de2ab87a810 100644 (file)
@@ -415,6 +415,8 @@ struct input_thread_t
  *****************************************************************************/
 #define input_CreateThread(a,b) __input_CreateThread(VLC_OBJECT(a),b)
 VLC_EXPORT( input_thread_t *, __input_CreateThread, ( vlc_object_t *, input_item_t * ) );
+#define input_CreateThread2(a,b,c) __input_CreateThread2(VLC_OBJECT(a),b,c)
+VLC_EXPORT( input_thread_t *, __input_CreateThread2, ( vlc_object_t *, input_item_t *, char * ) );
 #define input_Preparse(a,b) __input_Preparse(VLC_OBJECT(a),b)
 VLC_EXPORT( int, __input_Preparse, ( vlc_object_t *, input_item_t * ) );
 
index 2828a26185e10f81753f3ab186ab0de9676d5d59..2da48836e788e645b0680139f695ff8450d3f933 100644 (file)
@@ -47,7 +47,8 @@ typedef struct
     int     i_object_id;
     int     i_object_type;
     char *  psz_module;
-    char *  psz_msg;                                 /**< the message itself */
+    char *  psz_msg;                            /**< the message itself */
+    char *  psz_header;                         /**< Additional header */
 
     mtime_t date;                               /**< Message date */
 } msg_item_t;
index dd36620b6a7effc4101952054dc707762bbb4b58..e825d084635e7915d99e60aead52d9a00bb06bb2 100644 (file)
@@ -21,6 +21,7 @@ char * config_GetHomeDir (void);
 int playlist_ItemDelete (playlist_item_t *);
 osd_state_t * __osd_StateChange (osd_state_t *, const int);
 int vlm_ScheduleSetup (vlm_schedule_t *, const char *, const char *);
+input_thread_t * __input_CreateThread2 (vlc_object_t *, input_item_t *, char *);
 vlc_acl_t * __ACL_Duplicate (vlc_object_t *p_this, const vlc_acl_t *p_acl);
 int osd_Slider (vlc_object_t *, spu_t *, int, int, int, int, short);
 int playlist_ServicesDiscoveryRemove (playlist_t *, const char *);
@@ -883,6 +884,7 @@ struct module_symbols_t
     void (*stats_DumpInputStats_inner) (input_stats_t *);
     void (*stats_ReinitInputStats_inner) (input_stats_t *);
     counter_t* (*__stats_CounterGet_inner) (vlc_object_t*, int, char *);
+    input_thread_t * (*__input_CreateThread2_inner) (vlc_object_t *, input_item_t *, char *);
 };
 #  if defined (__PLUGIN__)
 #  define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
@@ -1310,6 +1312,7 @@ struct module_symbols_t
 #  define stats_DumpInputStats (p_symbols)->stats_DumpInputStats_inner
 #  define stats_ReinitInputStats (p_symbols)->stats_ReinitInputStats_inner
 #  define __stats_CounterGet (p_symbols)->__stats_CounterGet_inner
+#  define __input_CreateThread2 (p_symbols)->__input_CreateThread2_inner
 #  elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
 /******************************************************************
  * STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
@@ -1740,6 +1743,7 @@ struct module_symbols_t
     ((p_symbols)->stats_DumpInputStats_inner) = stats_DumpInputStats; \
     ((p_symbols)->stats_ReinitInputStats_inner) = stats_ReinitInputStats; \
     ((p_symbols)->__stats_CounterGet_inner) = __stats_CounterGet; \
+    ((p_symbols)->__input_CreateThread2_inner) = __input_CreateThread2; \
     (p_symbols)->net_ConvertIPv4_deprecated = NULL; \
 
 #  endif /* __PLUGIN__ */
index 6e4030f81b925d871129a013312b4ed3c92b3538..14983915e8be955b0c6320574b14b77d8796364e 100644 (file)
@@ -46,7 +46,8 @@
 static  int Run  ( input_thread_t *p_input );
 static  int RunAndClean  ( input_thread_t *p_input );
 
-static input_thread_t * Create  ( vlc_object_t *, input_item_t *, vlc_bool_t );
+static input_thread_t * Create  ( vlc_object_t *, input_item_t *, char *,
+                                  vlc_bool_t );
 static  int             Init    ( input_thread_t *p_input, vlc_bool_t b_quick );
 static void             Error   ( input_thread_t *p_input );
 static void             End     ( input_thread_t *p_input );
@@ -104,7 +105,7 @@ static vlc_meta_t *InputMetaUser( input_thread_t *p_input );
  * TODO complete this list (?)
  *****************************************************************************/
 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
-                               vlc_bool_t b_quick )
+                               char *psz_header, vlc_bool_t b_quick )
 {
     input_thread_t *p_input;                        /* thread descriptor */
     vlc_value_t val;
@@ -117,6 +118,7 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
         msg_Err( p_parent, "out of memory" );
         return NULL;
     }
+    p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
 
     /* Init Common fields */
     p_input->b_eof = VLC_FALSE;
@@ -239,11 +241,19 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
  */
 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
                                       input_item_t *p_item )
+{
+    __input_CreateThread2( p_parent, p_item, NULL );
+}
+
 
+/* Gruik ! */
+input_thread_t *__input_CreateThread2( vlc_object_t *p_parent,
+                                       input_item_t *p_item,
+                                       char *psz_header )
 {
     input_thread_t *p_input;                        /* thread descriptor */
 
-    p_input = Create( p_parent, p_item, VLC_FALSE );
+    p_input = Create( p_parent, p_item, psz_header, VLC_FALSE );
     /* Now we can attach our new input */
     vlc_object_attach( p_input, p_parent );
 
@@ -275,7 +285,7 @@ int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
 {
     input_thread_t *p_input;                        /* thread descriptor */
 
-    p_input = Create( p_parent, p_item, VLC_FALSE );
+    p_input = Create( p_parent, p_item, NULL, VLC_FALSE );
     /* Now we can attach our new input */
     vlc_object_attach( p_input, p_parent );
 
@@ -311,7 +321,7 @@ int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
     input_thread_t *p_input;                        /* thread descriptor */
 
     /* Allocate descriptor */
-    p_input = Create( p_parent, p_item, VLC_TRUE );
+    p_input = Create( p_parent, p_item, NULL, VLC_TRUE );
 
     /* Now we can attach our new input */
     vlc_object_attach( p_input, p_parent );
index 6a7a17e05b8d44336b965daced9ede8ab21d1757..281be07e7c8d37b74966d32dda88e5f238be159b 100644 (file)
@@ -292,9 +292,12 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
                       const char *psz_module,
                       const char *psz_format, va_list _args )
 {
+    int         i_header_size;               /* Size of the additionnal header */
+    vlc_object_t *p_obj;
     msg_bank_t * p_bank = &p_this->p_libvlc->msg_bank;       /* message bank */
     msg_queue_t *p_queue = NULL;
     char *       psz_str = NULL;                 /* formatted message string */
+    char *       psz_header = NULL;
     va_list      args;
     msg_item_t * p_item = NULL;                        /* pointer to message */
     msg_item_t   item;                    /* message in case of a full queue */
@@ -326,6 +329,33 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
         return;
     }
 
+    i_header_size = 0;
+    p_obj = p_this;
+    while( p_obj != NULL )
+    {
+        char *psz_old = NULL;
+        if( p_obj == NULL ) break;
+        if( p_obj->psz_header )
+        {
+            i_header_size += strlen( p_obj->psz_header ) + 4;
+            if( psz_header )
+            {
+                psz_old = strdup( psz_header );
+                psz_header = (char*)realloc( psz_header, i_header_size );
+                snprintf( psz_header, i_header_size , "[%s] %s",
+                          p_obj->psz_header, psz_old );
+            }
+            else
+            {
+                psz_header = (char *)malloc( i_header_size );
+                snprintf( psz_header, i_header_size, "[%s]",
+                          p_obj->psz_header );
+            }
+        }
+        if( psz_old ) free( psz_old );
+        p_obj = p_obj->p_parent;
+    }
+
 #if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
     vlc_va_copy( args, _args );
     vsnprintf( psz_str, i_size, psz_format, args );
@@ -386,6 +416,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
                 p_item->i_object_type = p_this->i_object_type;
                 p_item->psz_module =    strdup( "message" );
                 p_item->psz_msg =       strdup( "message queue overflowed" );
+                p_item->psz_header =    NULL;
 
                PrintMsg( p_this, p_item );
                /* We print from a dummy item */
@@ -407,6 +438,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
     p_item->i_object_type = p_this->i_object_type;
     p_item->psz_module =    strdup( psz_module );
     p_item->psz_msg =       psz_str;
+    p_item->psz_header =    psz_header;
 
     if( p_queue->i_id == MSG_QUEUE_NORMAL )
         PrintMsg( p_this, p_item );
@@ -546,16 +578,37 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
     /* Send the message to stderr */
     if( p_this->p_libvlc->b_color )
     {
-        fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s%s: %s%s" GRAY "\n",
+        if( p_item->psz_header )
+        {
+            fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s %s%s: %s%s" GRAY
+                              "\n",
+                         p_item->i_object_id, p_item->psz_header,
+                         p_item->psz_module, psz_object,
+                         ppsz_type[i_type], ppsz_color[i_type],
+                         p_item->psz_msg );
+        }
+        else
+        {
+             fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s%s: %s%s" GRAY "\n",
                          p_item->i_object_id, p_item->psz_module, psz_object,
                          ppsz_type[i_type], ppsz_color[i_type],
                          p_item->psz_msg );
+        }
     }
     else
     {
-        fprintf( stderr, "[%.8i] %s %s%s: %s\n", p_item->i_object_id,
+        if( p_item->psz_header )
+        {
+            fprintf( stderr, "[%.8i] %s %s %s%s: %s\n", p_item->i_object_id,
+                         p_item->psz_header, p_item->psz_module,
+                         psz_object, ppsz_type[i_type], p_item->psz_msg );
+        }
+        else
+        {
+            fprintf( stderr, "[%.8i] %s %s%s: %s\n", p_item->i_object_id,
                          p_item->psz_module, psz_object, ppsz_type[i_type],
                          p_item->psz_msg );
+        }
     }
 
 #   if defined(WIN32)
index 9596bf8f48abfaaba03d3d43297a8f4122d4e1dd..a7f231bacc0ae54c965e97782c1019d85cb9dae5 100644 (file)
@@ -248,6 +248,8 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
     p_new->b_attached = VLC_FALSE;
     p_new->b_force = VLC_FALSE;
 
+    p_new->psz_header = NULL;
+
     p_new->i_vars = 0;
     p_new->p_vars = (variable_t *)malloc( 16 * sizeof( variable_t ) );
 
index 453194db2a79a9f7b5ee4c4538999aa1f2f9e79a..7119ec4f66ea1650980568a2ed3b39374a005341 100644 (file)
@@ -1068,6 +1068,7 @@ int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, const char *psz_cmd,
             /* Pre-parse the input */
             input_thread_t *p_input;
             char *psz_output;
+            char *psz_header;
             int i;
 
             vlc_input_item_Clean( &media->item );
@@ -1092,7 +1093,10 @@ int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, const char *psz_cmd,
                     strdup( media->option[i] );
             }
 
-            if( (p_input = input_CreateThread( vlm, &media->item ) ) )
+            asprintf( &psz_header, _("Media: %s"), media->psz_name );
+
+            if( (p_input = input_CreateThread2( vlm, &media->item, psz_header
+                                              ) ) )
             {
                 while( !p_input->b_eof && !p_input->b_error ) msleep( 100000 );
 
@@ -1137,6 +1141,7 @@ int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, const char *psz_id,
 {
     vlm_media_instance_t *p_instance;
     int i;
+    char *psz_header;
 
     p_instance = vlm_MediaInstanceSearch( vlm, media, psz_id );
 
@@ -1194,7 +1199,9 @@ int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, const char *psz_id,
             vlc_object_destroy( p_instance->p_input );
         }
 
-        p_instance->p_input = input_CreateThread( vlm, &p_instance->item );
+        asprintf( &psz_header, _("Media: %s"), media->psz_name );
+        p_instance->p_input = input_CreateThread2( vlm, &p_instance->item,
+                                                   psz_header );
         if( !p_instance->p_input )
         {
             TAB_REMOVE( media->i_instance, media->instance, p_instance );