Commit 79c1ddfd authored by Antoine Cellerier's avatar Antoine Cellerier

* Make it possible to give names to vlc objects (psz_object_name

already existed but was only used by modules as far as is know). This
is done in the module_Need function. Needed module names now have this
syntax: '<module>[@<name>]'. If the @<name> part is present, once the
needed module is found it will change p_this->psz_object_name to <name>.
In about 99% of the module_Need calls, p_this is the module's parent
object so this is ok. The remaining calls won't use this syntax so it's
ok i guess :)

* Add new vlc_object_find_name function. It works like vlc_object_find
but uses a string (name) instead of an integer (type) as its second
argument.

* Change the marq, mosaic and logo commands in rc.c. They now take the
target object's name as first argument. Example:

Launch vlc with:
./vlc -I rc --no-audio --sub-filter "marq@test{marquee=Hello}:marq@testouille{marquee=Test}" ~/media/redefined-nintendo.mpg

Then issue the following command to move the second marq:
marq-x testouille 100

(and while testing I fixed #745)
parent cafb1863
...@@ -101,6 +101,7 @@ VLC_EXPORT( void, __vlc_object_attach, ( vlc_object_t *, vlc_object_t * ) ); ...@@ -101,6 +101,7 @@ VLC_EXPORT( void, __vlc_object_attach, ( vlc_object_t *, vlc_object_t * ) );
VLC_EXPORT( void, __vlc_object_detach, ( vlc_object_t * ) ); VLC_EXPORT( void, __vlc_object_detach, ( vlc_object_t * ) );
VLC_EXPORT( void *, __vlc_object_get, ( vlc_object_t *, int ) ); VLC_EXPORT( void *, __vlc_object_get, ( vlc_object_t *, int ) );
VLC_EXPORT( void *, __vlc_object_find, ( vlc_object_t *, int, int ) ); VLC_EXPORT( void *, __vlc_object_find, ( vlc_object_t *, int, int ) );
VLC_EXPORT( void *, __vlc_object_find_name, ( vlc_object_t *, const char *, int ) );
VLC_EXPORT( void, __vlc_object_yield, ( vlc_object_t * ) ); VLC_EXPORT( void, __vlc_object_yield, ( vlc_object_t * ) );
VLC_EXPORT( void, __vlc_object_release, ( vlc_object_t * ) ); VLC_EXPORT( void, __vlc_object_release, ( vlc_object_t * ) );
VLC_EXPORT( vlc_list_t *, __vlc_list_find, ( vlc_object_t *, int, int ) ); VLC_EXPORT( vlc_list_t *, __vlc_list_find, ( vlc_object_t *, int, int ) );
...@@ -128,6 +129,9 @@ VLC_EXPORT( libvlc_int_t *, vlc_current_object, ( int ) ); ...@@ -128,6 +129,9 @@ VLC_EXPORT( libvlc_int_t *, vlc_current_object, ( int ) );
#define vlc_object_find(a,b,c) \ #define vlc_object_find(a,b,c) \
__vlc_object_find( VLC_OBJECT(a),b,c) __vlc_object_find( VLC_OBJECT(a),b,c)
#define vlc_object_find_name(a,b,c) \
__vlc_object_find_name( VLC_OBJECT(a),b,c)
#define vlc_object_yield(a) \ #define vlc_object_yield(a) \
__vlc_object_yield( VLC_OBJECT(a) ) __vlc_object_yield( VLC_OBJECT(a) )
......
This diff is collapsed.
...@@ -428,7 +428,7 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability, ...@@ -428,7 +428,7 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
module_t *p_module; module_t *p_module;
int i_shortcuts = 0; int i_shortcuts = 0;
char *psz_shortcuts = NULL, *psz_var = NULL; char *psz_shortcuts = NULL, *psz_var = NULL, *psz_alias = NULL;
vlc_bool_t b_force_backup = p_this->b_force; vlc_bool_t b_force_backup = p_this->b_force;
...@@ -523,9 +523,15 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability, ...@@ -523,9 +523,15 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
{ {
for( unsigned i = 0; p_module->pp_shortcuts[i]; i++ ) for( unsigned i = 0; p_module->pp_shortcuts[i]; i++ )
{ {
if( !strcasecmp( psz_name, p_module->pp_shortcuts[i] ) ) char *c;
if( ( c = strchr( psz_name, '@' ) )
? !strncasecmp( psz_name, p_module->pp_shortcuts[i],
c-psz_name )
: !strcasecmp( psz_name, p_module->pp_shortcuts[i] ) )
{ {
/* Found it */ /* Found it */
if( c && c[1] )
psz_alias = c+1;
i_shortcut_bonus = i_short * 10000; i_shortcut_bonus = i_short * 10000;
goto found_shortcut; goto found_shortcut;
} }
...@@ -705,6 +711,12 @@ found_shortcut: ...@@ -705,6 +711,12 @@ found_shortcut:
else else
msg_StackSet( VLC_EGENERIC, "no suitable %s module", psz_capability ); msg_StackSet( VLC_EGENERIC, "no suitable %s module", psz_capability );
if( psz_alias && !p_this->psz_object_name )
/* This assumes that p_this is the object which will be using the
* module. That's not always the case ... but it is in most cases.
*/
p_this->psz_object_name = strdup( psz_alias );
if( psz_shortcuts ) if( psz_shortcuts )
{ {
free( psz_shortcuts ); free( psz_shortcuts );
......
...@@ -71,6 +71,7 @@ static int DumpCommand( vlc_object_t *, char const *, ...@@ -71,6 +71,7 @@ static int DumpCommand( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, vlc_value_t, void * );
static vlc_object_t * FindObject ( vlc_object_t *, int, int ); static vlc_object_t * FindObject ( vlc_object_t *, int, int );
static vlc_object_t * FindObjectName( vlc_object_t *, const char *, int );
static void DetachObject ( vlc_object_t * ); static void DetachObject ( vlc_object_t * );
static void PrintObject ( vlc_object_t *, const char * ); static void PrintObject ( vlc_object_t *, const char * );
static void DumpStructure ( vlc_object_t *, int, char * ); static void DumpStructure ( vlc_object_t *, int, char * );
...@@ -557,6 +558,60 @@ void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode ) ...@@ -557,6 +558,60 @@ void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
return p_found; return p_found;
} }
/**
****************************************************************************
* find a named object and increment its refcount
*****************************************************************************
* This function recursively looks for a given object name. i_mode can be one
* of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
*****************************************************************************/
void * __vlc_object_find_name( vlc_object_t *p_this, const char *psz_name,
int i_mode )
{
vlc_object_t *p_found;
vlc_mutex_lock( &structure_lock );
/* If have the requested name ourselves, don't look further */
if( !(i_mode & FIND_STRICT)
&& p_this->psz_object_name
&& !strcmp( p_this->psz_object_name, psz_name ) )
{
p_this->i_refcount++;
vlc_mutex_unlock( &structure_lock );
return p_this;
}
/* Otherwise, recursively look for the object */
if( (i_mode & 0x000f) == FIND_ANYWHERE )
{
vlc_object_t *p_root = p_this;
/* Find the root */
while( p_root->p_parent != NULL &&
p_root != VLC_OBJECT( p_this->p_libvlc ) )
{
p_root = p_root->p_parent;
}
p_found = FindObjectName( p_root, psz_name,
(i_mode & ~0x000f)|FIND_CHILD );
if( p_found == NULL && p_root != VLC_OBJECT( p_this->p_libvlc ) )
{
p_found = FindObjectName( VLC_OBJECT( p_this->p_libvlc ),
psz_name, (i_mode & ~0x000f)|FIND_CHILD );
}
}
else
{
p_found = FindObjectName( p_this, psz_name, i_mode );
}
vlc_mutex_unlock( &structure_lock );
return p_found;
}
/** /**
**************************************************************************** ****************************************************************************
* increment an object refcount * increment an object refcount
...@@ -974,6 +1029,61 @@ static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode ) ...@@ -974,6 +1029,61 @@ static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
return NULL; return NULL;
} }
static vlc_object_t * FindObjectName( vlc_object_t *p_this,
const char *psz_name,
int i_mode )
{
int i;
vlc_object_t *p_tmp;
switch( i_mode & 0x000f )
{
case FIND_PARENT:
p_tmp = p_this->p_parent;
if( p_tmp )
{
if( p_tmp->psz_object_name
&& !strcmp( p_tmp->psz_object_name, psz_name ) )
{
p_tmp->i_refcount++;
return p_tmp;
}
else
{
return FindObjectName( p_tmp, psz_name, i_mode );
}
}
break;
case FIND_CHILD:
for( i = p_this->i_children; i--; )
{
p_tmp = p_this->pp_children[i];
if( p_tmp->psz_object_name
&& !strcmp( p_tmp->psz_object_name, psz_name ) )
{
p_tmp->i_refcount++;
return p_tmp;
}
else if( p_tmp->i_children )
{
p_tmp = FindObjectName( p_tmp, psz_name, i_mode );
if( p_tmp )
{
return p_tmp;
}
}
}
break;
case FIND_ANYWHERE:
/* Handled in vlc_object_find */
break;
}
return NULL;
}
static void DetachObject( vlc_object_t *p_this ) static void DetachObject( vlc_object_t *p_this )
{ {
vlc_object_t *p_parent = p_this->p_parent; vlc_object_t *p_parent = p_this->p_parent;
......
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