break;
case CMD_TRIGGERMENU:
+ case CMD_PLAYING_CHANGED:
free( command->data[0] ); // Arg1 is int*, to free
break;
+
+ default:
+ break;
}
free( command );
FreeCommands( next );
}
/* Free the list of commands */
- FreeCommands( p_ext->p_sys->command );
+ if( p_ext->p_sys->command )
+ FreeCommands( p_ext->p_sys->command->next );
/* Push command */
struct command_t *cmd = calloc( 1, sizeof( struct command_t ) );
cmd->i_command = CMD_DEACTIVATE;
- p_ext->p_sys->command = cmd;
+ if( p_ext->p_sys->command )
+ p_ext->p_sys->command->next = cmd;
+ else
+ p_ext->p_sys->command = cmd;
vlc_cond_signal( &p_ext->p_sys->wait );
vlc_mutex_unlock( &p_ext->p_sys->command_lock );
/** Wait for an extension to finish */
void WaitForDeactivation( extension_t *p_ext )
{
- void *pointer = NULL;
- vlc_cond_signal( &p_ext->p_sys->wait );
- vlc_join( p_ext->p_sys->thread, &pointer );
+ vlc_join( p_ext->p_sys->thread, NULL );
}
/** Push a UI command */
-int PushCommand( extension_t *p_ext,
- int i_command,
- ... )
+int __PushCommand( extension_t *p_ext, bool b_unique, int i_command,
+ va_list args )
{
vlc_mutex_lock( &p_ext->p_sys->command_lock );
- va_list args;
- va_start( args, i_command );
-
/* Create command */
struct command_t *cmd = calloc( 1, sizeof( struct command_t ) );
cmd->i_command = i_command;
case CMD_CLICK:
cmd->data[0] = va_arg( args, void* );
break;
- case CMD_CLOSE:
- // Nothing to do here
- break;
case CMD_TRIGGERMENU:
{
int *pi = malloc( sizeof( int ) );
cmd->data[0] = pi;
}
break;
+ case CMD_PLAYING_CHANGED:
+ {
+ int *pi = malloc( sizeof( int ) );
+ if( !pi )
+ {
+ free( cmd );
+ vlc_mutex_unlock( &p_ext->p_sys->command_lock );
+ return VLC_ENOMEM;
+ }
+ *pi = va_arg( args, int );
+ cmd->data[0] = pi;
+ }
+ break;
+ case CMD_CLOSE:
+ case CMD_SET_INPUT:
+ case CMD_UPDATE_META:
+ // Nothing to do here
+ break;
default:
msg_Dbg( p_ext->p_sys->p_mgr,
"Unknown command send to extension: %d", i_command );
break;
}
- va_end( args );
-
/* Push command to the end of the queue */
struct command_t *last = p_ext->p_sys->command;
if( !last )
}
else
{
+ bool b_skip = false;
while( last->next != NULL )
{
- last = last->next;
+ if( b_unique && last->i_command == i_command )
+ {
+ // Do not push this 'unique' command a second time
+ b_skip = !memcmp( last->data, cmd->data, sizeof( cmd->data ) );
+ break;
+ }
+ else
+ {
+ last = last->next;
+ }
+ }
+ if( !b_skip )
+ {
+ last->next = cmd;
+ }
+ else
+ {
+ FreeCommands( cmd );
}
- last->next = cmd;
}
vlc_cond_signal( &p_ext->p_sys->wait );
{
/* Pop command in front */
struct command_t *cmd = p_ext->p_sys->command;
- if( cmd )
- {
- p_ext->p_sys->command = cmd->next;
- }
-
vlc_mutex_unlock( &p_ext->p_sys->command_lock );
/* Run command */
{
case CMD_ACTIVATE:
{
- if( lua_ExecuteFunction( p_mgr, p_ext, "activate" ) < 0 )
+ if( lua_ExecuteFunction( p_mgr, p_ext, "activate", LUA_END ) < 0 )
{
msg_Dbg( p_mgr, "Could not activate extension!" );
Deactivate( p_mgr, p_ext );
+ cmd = NULL;
}
break;
}
case CMD_CLOSE:
{
- lua_ExecuteFunction( p_mgr, p_ext, "close" );
+ lua_ExecuteFunction( p_mgr, p_ext, "close", LUA_END );
break;
}
msg_Dbg( p_mgr, "Trigger menu %d of '%s'",
*pi_id, p_ext->psz_name );
lua_ExtensionTriggerMenu( p_mgr, p_ext, *pi_id );
- free( pi_id );
break;
}
case CMD_SET_INPUT:
{
- lua_ExecuteFunction( p_mgr, p_ext, "input_changed" );
+ lua_ExecuteFunction( p_mgr, p_ext, "input_changed", LUA_END );
+ break;
+ }
+
+ case CMD_UPDATE_META:
+ {
+ lua_ExecuteFunction( p_mgr, p_ext, "meta_changed", LUA_END );
+ break;
+ }
+
+ case CMD_PLAYING_CHANGED:
+ {
+ lua_ExecuteFunction( p_mgr, p_ext, "playing_changed",
+ LUA_NUM, *((int *)cmd->data[0]), LUA_END );
break;
}
}
vlc_mutex_lock( &p_ext->p_sys->command_lock );
+ if( p_ext->p_sys->command )
+ {
+ cmd = p_ext->p_sys->command;
+ p_ext->p_sys->command = cmd->next;
+ cmd->next = NULL; // This prevents FreeCommands from freeing next
+ FreeCommands( cmd );
+ }
+
if( !p_ext->p_sys->b_exiting && !p_ext->p_sys->command )
{
vlc_cond_wait( &p_ext->p_sys->wait, &p_ext->p_sys->command_lock );
}
vlc_mutex_unlock( &p_ext->p_sys->command_lock );
- msg_Dbg( p_mgr, "Extension thread ending..." );
+ msg_Dbg( p_mgr, "Extension thread end: '%s'", p_ext->psz_title );
// Note: At this point, the extension should be deactivated
return NULL;