#define var_OptionParse(a,b) __var_OptionParse( VLC_OBJECT( a ) , b )
VLC_EXPORT( void, __var_OptionParse, ( vlc_object_t *, const char * ) );
+#define var_Command(a,b,c,d,e) __var_Command( VLC_OBJECT( a ), b, c, d, e )
+VLC_EXPORT( int, __var_Command, ( vlc_object_t *, const char *, const char *, const char *, char ** ) );
+
/**
* __var_Create() with automatic casting.
*/
char *psz_alias = psz_cmd + 1;
char *psz_mycmd = strdup( psz_arg );
char *psz_myarg = strchr( psz_mycmd, ' ' );
- int i_ret = VLC_EGENERIC;
+ char *psz_msg;
*psz_myarg = '\0';
psz_myarg ++;
- vlc_object_t *p_obj =
- vlc_object_find_name( p_input->p_libvlc, psz_alias,
- FIND_CHILD );
- if( !p_obj )
- msg_rc( "Unknown destination object!" );
- else
+ var_Command( p_input, psz_alias, psz_mycmd, psz_myarg, &psz_msg );
+
+
+ if( psz_msg )
{
- int i_type;
- if( (i_type = var_Type( p_obj, psz_mycmd )) & VLC_VAR_ISCOMMAND )
- {
- i_type &= 0xf0;
- if( i_type == VLC_VAR_INTEGER )
- {
- i_ret = var_SetInteger( p_obj, psz_mycmd,
- atoi( psz_myarg ) );
- }
- else if( i_type == VLC_VAR_FLOAT )
- {
- i_ret = var_SetFloat( p_obj, psz_mycmd,
- atof( psz_myarg ) );
- }
- else if( i_type == VLC_VAR_STRING )
- {
- i_ret = var_SetString( p_obj, psz_mycmd,
- psz_myarg );
- }
- else if( i_type == VLC_VAR_BOOL )
- {
- i_ret = var_SetBool( p_obj, psz_mycmd,
- atoi( psz_myarg ) );
- }
- else
- {
- msg_rc( "Unhandled command type. Fix the code!" );
- }
- }
- else
- {
- msg_rc( "Unknown command! %d", i_type );
- }
- vlc_object_release( p_obj );
+ msg_rc( psz_msg );
+ free( psz_msg );
}
free( psz_mycmd );
- msg_rc( "%s on object %s: returned %i (%s)",
- psz_mycmd, psz_alias, i_ret, vlc_error( i_ret ) );
}
/* If the user typed a registered local command, try it */
else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
msg_Err( p_intf, "shutdown requested" );
p_intf->p_libvlc->b_die = VLC_TRUE;
}
+ else if( *cl->buffer_read == '@'
+ && strchr( cl->buffer_read, ' ' ) )
+ {
+ /* Module specific commands (use same syntax as in the
+ * rc interface) */
+ char *psz_name = cl->buffer_read + 1;
+ char *psz_cmd, *psz_arg, *psz_msg;
+ int i_ret;
+
+ psz_cmd = strchr( cl->buffer_read, ' ' );
+ *psz_cmd = '\0'; psz_cmd++;
+ if( ( psz_arg = strchr( psz_cmd, '\n' ) ) ) *psz_arg = '\0';
+ if( ( psz_arg = strchr( psz_cmd, '\r' ) ) ) *psz_arg = '\0';
+ if( ( psz_arg = strchr( psz_cmd, ' ' ) )
+ && *psz_arg )
+ {
+ *psz_arg = '\0';
+ psz_arg++;
+ }
+
+ i_ret = var_Command( p_intf, psz_name, psz_cmd, psz_arg,
+ &psz_msg );
+
+ if( psz_msg )
+ {
+ vlm_message_t *message;
+ message = vlm_MessageNew( "Module command", psz_msg );
+ Write_message( cl, message, NULL, WRITE_MODE_CMD );
+ vlm_MessageDelete( message );
+ free( psz_msg );
+ }
+ }
else
{
vlm_message_t *message;
vlm_MessageNew( "logout, quit, exit" , NULL ) );
vlm_MessageAdd( p_my_help,
vlm_MessageNew( "shutdown" , NULL ) );
+ vlm_MessageAdd( p_my_help,
+ vlm_MessageNew( "@moduleinstance command argument",
+ NULL) );
vlm_MessageAdd( message, p_my_help );
}
Write_message( cl, message, NULL, WRITE_MODE_CMD );
return InheritValue( p_this->p_parent, psz_name, p_val, i_type );
}
+
+/**********************************************************************
+ * Execute a var command on an object identified by its name
+ **********************************************************************/
+int __var_Command( vlc_object_t *p_this, const char *psz_name,
+ const char *psz_cmd, const char *psz_arg, char **psz_msg )
+{
+ vlc_object_t *p_obj = vlc_object_find_name( p_this->p_libvlc,
+ psz_name, FIND_CHILD );
+ int i_type, i_ret;
+
+ if( !p_obj )
+ {
+ if( psz_msg )
+ *psz_msg = strdup( "Unknown destination object." );
+ return VLC_ENOOBJ;
+ }
+
+ i_type = var_Type( p_obj, psz_cmd );
+ if( !( i_type&VLC_VAR_ISCOMMAND ) )
+ {
+ vlc_object_release( p_obj );
+ if( psz_msg )
+ *psz_msg = strdup( "Variable doesn't exist or isn't a command." );
+ return VLC_EGENERIC;
+ }
+
+ i_type &= 0xf0;
+ switch( i_type )
+ {
+ case VLC_VAR_INTEGER:
+ i_ret = var_SetInteger( p_obj, psz_cmd, atoi( psz_arg ) );
+ break;
+ case VLC_VAR_FLOAT:
+ i_ret = var_SetFloat( p_obj, psz_cmd, atof( psz_arg ) );
+ break;
+ case VLC_VAR_STRING:
+ i_ret = var_SetString( p_obj, psz_cmd, psz_arg );
+ break;
+ case VLC_VAR_BOOL:
+ i_ret = var_SetBool( p_obj, psz_cmd, atoi( psz_arg ) );
+ break;
+ default:
+ i_ret = VLC_EGENERIC;
+ break;
+ }
+
+ vlc_object_release( p_obj );
+
+ if( psz_msg )
+ {
+ *psz_msg = (char*)malloc( 80 );
+ sprintf( *psz_msg, "%s on object %s returned %i (%s)",
+ psz_cmd, psz_name, i_ret, vlc_error( i_ret ) );
+ }
+
+ return i_ret;
+}