1 /*****************************************************************************
2 * extension.c: Lua Extensions (meta data, web information, ...)
3 *****************************************************************************
4 * Copyright (C) 2009-2010 VideoLAN and authors
7 * Authors: Jean-Philippe André < jpeg # videolan.org >
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
26 #include "extension.h"
29 #include <vlc_input.h>
30 #include <vlc_events.h>
32 /* Functions to register */
33 static const luaL_Reg p_reg[] =
39 * Extensions capabilities
40 * Note: #define and ppsz_capabilities must be in sync
42 #define EXT_HAS_MENU (1 << 0) ///< Hook: menu
43 #define EXT_TRIGGER_ONLY (1 << 1) ///< Hook: trigger. Not activable
44 #define EXT_INPUT_LISTENER (1 << 2) ///< Hook: input_changed
45 #define EXT_META_LISTENER (1 << 3) ///< Hook: meta_changed
47 const char* const ppsz_capabilities[] = {
55 static int ScanExtensions( extensions_manager_t *p_this );
56 static int ScanLuaCallback( vlc_object_t *p_this, const char *psz_script,
57 lua_State *L, void *pb_continue );
58 static int Control( extensions_manager_t *, int, va_list );
59 static int GetMenuEntries( extensions_manager_t *p_mgr, extension_t *p_ext,
60 char ***pppsz_titles, uint16_t **ppi_ids );
61 static lua_State* GetLuaState( extensions_manager_t *p_mgr,
63 static int TriggerMenu( extension_t *p_ext, int id );
64 static int TriggerExtension( extensions_manager_t *p_mgr,
67 int vlclua_extension_deactivate( lua_State *L );
70 static int vlclua_extension_dialog_callback( vlc_object_t *p_this,
76 /* Input item callback: vlc_InputItemMetaChanged */
77 static void inputItemMetaChanged( const vlc_event_t *p_event,
84 int Open_Extension( vlc_object_t *p_this )
86 msg_Dbg( p_this, "Opening EXPERIMENTAL Lua Extension module" );
88 extensions_manager_t *p_mgr = ( extensions_manager_t* ) p_this;
90 p_mgr->pf_control = Control;
92 extensions_manager_sys_t *p_sys = ( extensions_manager_sys_t* )
93 calloc( 1, sizeof( extensions_manager_sys_t ) );
94 if( !p_sys ) return VLC_ENOMEM;
97 ARRAY_INIT( p_sys->activated_extensions );
98 ARRAY_INIT( p_mgr->extensions );
99 vlc_mutex_init( &p_mgr->lock );
100 vlc_mutex_init( &p_mgr->p_sys->lock );
102 /* Initialise Lua state structure */
103 lua_State *L = GetLuaState( p_mgr, NULL );
111 /* Scan available Lua Extensions */
112 if( ScanExtensions( p_mgr ) != VLC_SUCCESS )
114 msg_Err( p_mgr, "Can't load extensions modules" );
121 // Create the dialog-event variable
122 var_Create( p_this, "dialog-event", VLC_VAR_ADDRESS );
123 var_AddCallback( p_this, "dialog-event",
124 vlclua_extension_dialog_callback, NULL );
130 * Module unload function
132 void Close_Extension( vlc_object_t *p_this )
134 extensions_manager_t *p_mgr = ( extensions_manager_t* ) p_this;
135 msg_Dbg( p_mgr, "Deactivating all loaded extensions" );
137 vlc_mutex_lock( &p_mgr->lock );
138 p_mgr->p_sys->b_killed = true;
139 vlc_mutex_unlock( &p_mgr->lock );
141 var_Destroy( p_mgr, "dialog-event" );
143 extension_t *p_ext = NULL;
144 FOREACH_ARRAY( p_ext, p_mgr->p_sys->activated_extensions )
147 msg_Dbg( p_mgr, "Deactivating '%s'", p_ext->psz_title );
148 Deactivate( p_mgr, p_ext );
149 WaitForDeactivation( p_ext );
153 msg_Dbg( p_mgr, "All extensions are now deactivated" );
154 ARRAY_RESET( p_mgr->p_sys->activated_extensions );
156 if( p_mgr->p_sys && p_mgr->p_sys->L )
157 lua_close( p_mgr->p_sys->L );
159 vlc_mutex_destroy( &p_mgr->lock );
160 vlc_mutex_destroy( &p_mgr->p_sys->lock );
161 free( p_mgr->p_sys );
164 /* Free extensions' memory */
165 FOREACH_ARRAY( p_ext, p_mgr->extensions )
169 if( p_ext->p_sys->L )
170 lua_close( p_ext->p_sys->L );
171 free( p_ext->psz_name );
172 free( p_ext->psz_title );
174 vlc_mutex_destroy( &p_ext->p_sys->running_lock );
175 vlc_mutex_destroy( &p_ext->p_sys->command_lock );
176 vlc_cond_destroy( &p_ext->p_sys->wait );
178 free( p_ext->p_sys );
183 ARRAY_RESET( p_mgr->extensions );
187 * Batch scan all Lua files in folder "extensions"
188 * @param p_mgr This extensions_manager_t object
190 static int ScanExtensions( extensions_manager_t *p_mgr )
194 vlclua_scripts_batch_execute( VLC_OBJECT( p_mgr ),
197 p_mgr->p_sys->L, &b_true );
206 * Batch scan all Lua files in folder "extensions": callback
207 * @param p_this This extensions_manager_t object
208 * @param psz_script Name of the script to run
209 * @param L Lua State, common to all scripts here
210 * @param pb_continue bool* that indicates whether to continue batch or not
212 int ScanLuaCallback( vlc_object_t *p_this, const char *psz_script,
213 lua_State *L, void *pb_continue )
215 extensions_manager_t *p_mgr = ( extensions_manager_t* ) p_this;
218 msg_Dbg( p_mgr, "Scanning Lua script %s", psz_script );
220 vlc_mutex_lock( &p_mgr->lock );
222 /* Create new script descriptor */
223 extension_t *p_ext = ( extension_t* ) calloc( 1, sizeof( extension_t ) );
226 vlc_mutex_unlock( &p_mgr->lock );
230 p_ext->psz_name = strdup( psz_script );
231 p_ext->p_sys = (extension_sys_t*) calloc( 1, sizeof( extension_sys_t ) );
232 if( !p_ext->p_sys || !p_ext->psz_name )
234 free( p_ext->psz_name );
235 free( p_ext->p_sys );
237 vlc_mutex_unlock( &p_mgr->lock );
240 p_ext->p_sys->p_mgr = p_mgr;
242 /* Mutexes and conditions */
243 vlc_mutex_init( &p_ext->p_sys->command_lock );
244 vlc_mutex_init( &p_ext->p_sys->running_lock );
245 vlc_cond_init( &p_ext->p_sys->wait );
247 /* Load and run the script(s) */
248 if( luaL_dofile( L, psz_script ) )
250 msg_Warn( p_mgr, "Error loading script %s: %s", psz_script,
251 lua_tostring( L, lua_gettop( L ) ) );
256 /* Scan script for capabilities */
257 lua_getglobal( L, "descriptor" );
259 if( !lua_isfunction( L, -1 ) )
261 msg_Warn( p_mgr, "Error while runing script %s, "
262 "function descriptor() not found", psz_script );
266 if( lua_pcall( L, 0, 1, 0 ) )
268 msg_Warn( p_mgr, "Error while runing script %s, "
269 "function descriptor(): %s", psz_script,
270 lua_tostring( L, lua_gettop( L ) ) );
274 if( lua_gettop( L ) )
276 if( lua_istable( L, -1 ) )
279 lua_getfield( L, -1, "capabilities" );
280 if( lua_istable( L, -1 ) )
283 while( lua_next( L, -2 ) != 0 )
285 /* Key is at index -2 and value at index -1. Discard key */
286 const char *psz_cap = luaL_checkstring( L, -1 );
289 /* Find this capability's flag */
290 for( const char *iter = *ppsz_capabilities;
292 iter = ppsz_capabilities[ ++i_cap ])
294 if( !strcmp( iter, psz_cap ) )
297 p_ext->p_sys->i_capabilities |= 1 << i_cap;
304 msg_Warn( p_mgr, "Extension capability '%s' unknown in"
305 " script %s", psz_cap, psz_script );
307 /* Removes 'value'; keeps 'key' for next iteration */
313 msg_Warn( p_mgr, "In script %s, function descriptor() "
314 "did not return a table of capabilities.",
320 lua_getfield( L, -1, "title" );
321 if( lua_isstring( L, -1 ) )
323 p_ext->psz_title = strdup( luaL_checkstring( L, -1 ) );
327 msg_Dbg( p_mgr, "In script %s, function descriptor() "
328 "did not return a string as title.",
330 p_ext->psz_title = strdup( psz_script );
335 lua_getfield( L, -1, "author" );
336 if( lua_isstring( L, -1 ) )
338 p_ext->psz_author = strdup( luaL_checkstring( L, -1 ) );
342 p_ext->psz_author = NULL;
346 /* Get description */
347 lua_getfield( L, -1, "description" );
348 if( lua_isstring( L, -1 ) )
350 p_ext->psz_description = strdup( luaL_checkstring( L, -1 ) );
354 p_ext->psz_description = NULL;
358 /* Get short description */
359 lua_getfield( L, -1, "shortdesc" );
360 if( lua_isstring( L, -1 ) )
362 p_ext->psz_shortdescription = strdup( luaL_checkstring( L, -1 ) );
366 p_ext->psz_shortdescription = NULL;
371 lua_getfield( L, -1, "url" );
372 if( lua_isstring( L, -1 ) )
374 p_ext->psz_url = strdup( luaL_checkstring( L, -1 ) );
378 p_ext->psz_url = NULL;
383 lua_getfield( L, -1, "version" );
384 if( lua_isstring( L, -1 ) )
386 p_ext->psz_version = strdup( luaL_checkstring( L, -1 ) );
390 p_ext->psz_version = NULL;
396 msg_Warn( p_mgr, "In script %s, function descriptor() "
397 "did not return a table!", psz_script );
403 msg_Err( p_mgr, "Script %s went completely foobar", psz_script );
407 msg_Dbg( p_mgr, "Script %s has the following capability flags: 0x%x",
408 psz_script, p_ext->p_sys->i_capabilities );
414 free( p_ext->psz_name );
415 free( p_ext->psz_title );
416 free( p_ext->psz_url );
417 free( p_ext->psz_author );
418 free( p_ext->psz_description );
419 free( p_ext->psz_version );
420 vlc_mutex_destroy( &p_ext->p_sys->command_lock );
421 vlc_mutex_destroy( &p_ext->p_sys->running_lock );
422 vlc_cond_destroy( &p_ext->p_sys->wait );
423 free( p_ext->p_sys );
428 /* Add the extension to the list of known extensions */
429 ARRAY_APPEND( p_mgr->extensions, p_ext );
432 vlc_mutex_unlock( &p_mgr->lock );
433 /* Continue batch execution */
434 return pb_continue ? ( (* (bool*)pb_continue) ? -1 : 0 ) : -1;
437 static int Control( extensions_manager_t *p_mgr, int i_control, va_list args )
439 extension_t *p_ext = NULL;
441 uint16_t **ppus = NULL;
442 char ***pppsz = NULL;
447 case EXTENSION_ACTIVATE:
448 p_ext = ( extension_t* ) va_arg( args, extension_t* );
449 return Activate( p_mgr, p_ext );
451 case EXTENSION_DEACTIVATE:
452 p_ext = ( extension_t* ) va_arg( args, extension_t* );
453 return Deactivate( p_mgr, p_ext );
455 case EXTENSION_IS_ACTIVATED:
456 p_ext = ( extension_t* ) va_arg( args, extension_t* );
457 pb = ( bool* ) va_arg( args, bool* );
458 *pb = IsActivated( p_mgr, p_ext );
461 case EXTENSION_HAS_MENU:
462 p_ext = ( extension_t* ) va_arg( args, extension_t* );
463 pb = ( bool* ) va_arg( args, bool* );
464 *pb = ( p_ext->p_sys->i_capabilities & EXT_HAS_MENU ) ? 1 : 0;
467 case EXTENSION_GET_MENU:
468 p_ext = ( extension_t* ) va_arg( args, extension_t* );
469 pppsz = ( char*** ) va_arg( args, char*** );
470 ppus = ( uint16_t** ) va_arg( args, uint16_t** );
471 return GetMenuEntries( p_mgr, p_ext, pppsz, ppus );
473 case EXTENSION_TRIGGER_ONLY:
474 p_ext = ( extension_t* ) va_arg( args, extension_t* );
475 pb = ( bool* ) va_arg( args, bool* );
476 *pb = ( p_ext->p_sys->i_capabilities & EXT_TRIGGER_ONLY ) ? 1 : 0;
479 case EXTENSION_TRIGGER:
480 p_ext = ( extension_t* ) va_arg( args, extension_t* );
481 return TriggerExtension( p_mgr, p_ext );
483 case EXTENSION_TRIGGER_MENU:
484 p_ext = ( extension_t* ) va_arg( args, extension_t* );
485 // GCC: 'uint16_t' is promoted to 'int' when passed through '...'
486 i = ( int ) va_arg( args, int );
487 return TriggerMenu( p_ext, i );
489 case EXTENSION_SET_INPUT:
491 p_ext = ( extension_t* ) va_arg( args, extension_t* );
492 input_thread_t *p_input = va_arg( args, struct input_thread_t * );
494 if( !LockExtension( p_ext ) )
498 input_thread_t *old = p_ext->p_sys->p_input;
499 input_item_t *p_item;
502 // Untrack meta fetched events
503 if( p_ext->p_sys->i_capabilities & EXT_META_LISTENER )
505 p_item = input_GetItem( old );
506 vlc_event_detach( &p_item->event_manager,
507 vlc_InputItemMetaChanged,
508 inputItemMetaChanged,
510 vlc_gc_decref( p_item );
512 vlc_object_release( old );
515 p_ext->p_sys->p_input = p_input ? vlc_object_hold( p_input )
518 // Tell the script the input changed
519 if( p_ext->p_sys->i_capabilities & EXT_INPUT_LISTENER )
521 PushCommandUnique( p_ext, CMD_SET_INPUT );
524 // Track meta fetched events
525 if( p_ext->p_sys->p_input &&
526 p_ext->p_sys->i_capabilities & EXT_META_LISTENER )
528 p_item = input_GetItem( p_ext->p_sys->p_input );
529 vlc_gc_incref( p_item );
530 vlc_event_attach( &p_item->event_manager,
531 vlc_InputItemMetaChanged,
532 inputItemMetaChanged,
536 UnlockExtension( p_ext );
541 msg_Warn( p_mgr, "Control '%d' not yet implemented in Extension",
549 int lua_ExtensionActivate( extensions_manager_t *p_mgr, extension_t *p_ext )
551 assert( p_mgr != NULL && p_ext != NULL );
552 return lua_ExecuteFunction( p_mgr, p_ext, "activate" );
555 int lua_ExtensionDeactivate( extensions_manager_t *p_mgr, extension_t *p_ext )
557 assert( p_mgr != NULL && p_ext != NULL );
559 if( !p_ext->p_sys->L )
562 // Unset and release input objects
563 if( p_ext->p_sys->p_input )
565 if( p_ext->p_sys->i_capabilities & EXT_META_LISTENER )
568 input_item_t *p_item = input_GetItem( p_ext->p_sys->p_input );
569 vlc_gc_decref( p_item );
571 vlc_object_release( p_ext->p_sys->p_input );
574 int i_ret = lua_ExecuteFunction( p_mgr, p_ext, "deactivate" );
576 /* Clear Lua State */
577 lua_close( p_ext->p_sys->L );
578 p_ext->p_sys->L = NULL;
583 int lua_ExtensionWidgetClick( extensions_manager_t *p_mgr,
585 extension_widget_t *p_widget )
587 if( !p_ext->p_sys->L )
590 return lua_ExecuteFunction( p_mgr, p_ext, (const char*) p_widget->p_sys );
595 * Get the list of menu entries from an extension script
598 * @param pppsz_titles Pointer to NULL. All strings must be freed by the caller
599 * @param ppi_ids Pointer to NULL. Must be feed by the caller.
600 * @note This function is allowed to run in the UI thread. This means
601 * that it MUST respond very fast.
602 * @todo Remove the menu() hook and provide a new function vlc.set_menu()
604 static int GetMenuEntries( extensions_manager_t *p_mgr, extension_t *p_ext,
605 char ***pppsz_titles, uint16_t **ppi_ids )
607 assert( *pppsz_titles == NULL );
608 assert( *ppi_ids == NULL );
610 if( !IsActivated( p_mgr, p_ext ) )
612 msg_Dbg( p_mgr, "Can't get menu before activating the extension!" );
616 if( !LockExtension( p_ext ) )
618 /* Dying extension, fail. */
622 int i_ret = VLC_EGENERIC;
623 lua_State *L = GetLuaState( p_mgr, p_ext );
625 if( ( p_ext->p_sys->i_capabilities & EXT_HAS_MENU ) == 0 )
627 msg_Dbg( p_mgr, "can't get a menu from an extension without menu!" );
631 lua_getglobal( L, "menu" );
633 if( !lua_isfunction( L, -1 ) )
635 msg_Warn( p_mgr, "Error while runing script %s, "
636 "function menu() not found", p_ext->psz_name );
640 if( lua_pcall( L, 0, 1, 0 ) )
642 msg_Warn( p_mgr, "Error while runing script %s, "
643 "function menu(): %s", p_ext->psz_name,
644 lua_tostring( L, lua_gettop( L ) ) );
648 if( lua_gettop( L ) )
650 if( lua_istable( L, -1 ) )
653 size_t i_size = lua_objlen( L, -1 );
654 *pppsz_titles = ( char** ) calloc( i_size+1, sizeof( char* ) );
655 *ppi_ids = ( uint16_t* ) calloc( i_size+1, sizeof( uint16_t ) );
660 while( lua_next( L, -2 ) != 0 )
662 assert( i_idx < i_size );
663 if( (!lua_isstring( L, -1 )) || (!lua_isnumber( L, -2 )) )
665 msg_Warn( p_mgr, "In script %s, an entry in "
666 "the menu table is invalid!", p_ext->psz_name );
669 (*pppsz_titles)[ i_idx ] = strdup( luaL_checkstring( L, -1 ) );
670 (*ppi_ids)[ i_idx ] = (uint16_t) ( luaL_checkinteger( L, -2 ) & 0xFFFF );
677 msg_Warn( p_mgr, "Function menu() in script %s "
678 "did not return a table", p_ext->psz_name );
684 msg_Warn( p_mgr, "Script %s went completely foobar", p_ext->psz_name );
691 UnlockExtension( p_ext );
692 if( i_ret != VLC_SUCCESS )
694 msg_Dbg( p_mgr, "Something went wrong in %s (%s:%d)",
695 __func__, __FILE__, __LINE__ );
700 /* Must be entered with the Lock on Extension */
701 static lua_State* GetLuaState( extensions_manager_t *p_mgr,
713 msg_Err( p_mgr, "Could not create new Lua State" );
717 luaL_register( L, "vlc", p_reg );
720 lua_pushlightuserdata( L, p_mgr );
721 lua_setfield( L, -2, "private" );
723 lua_pushlightuserdata( L, p_ext );
724 lua_setfield( L, -2, "extension" );
728 /* Load more libraries */
731 luaopen_dialog( L, p_ext );
738 luaopen_playlist( L );
741 luaopen_strings( L );
742 luaopen_variables( L );
747 /* Register extension specific functions */
748 lua_getglobal( L, "vlc" );
749 lua_pushcfunction( L, vlclua_extension_deactivate );
750 lua_setfield( L, -2, "deactivate" );
752 /* Load and run the script(s) */
753 if( luaL_dofile( L, p_ext->psz_name ) != 0 )
755 msg_Warn( p_mgr, "Error loading script %s: %s", p_ext->psz_name,
756 lua_tostring( L, lua_gettop( L ) ) );
767 msg_Dbg( p_mgr, "Reusing old Lua state for extension '%s'",
776 * Execute a function in a Lua script
777 * @return < 0 in case of failure, >= 0 in case of success
778 * @note It's better to call this function from a dedicated thread
779 * (see extension_thread.c)
781 int lua_ExecuteFunction( extensions_manager_t *p_mgr,
783 const char *psz_function )
785 int i_ret = VLC_EGENERIC;
786 assert( p_mgr != NULL );
787 assert( p_ext != NULL );
789 lua_State *L = GetLuaState( p_mgr, p_ext );
790 lua_getglobal( L, psz_function );
792 if( !lua_isfunction( L, -1 ) )
794 msg_Warn( p_mgr, "Error while runing script %s, "
795 "function %s() not found", p_ext->psz_name, psz_function );
799 if( lua_pcall( L, 0, 1, 0 ) )
801 msg_Warn( p_mgr, "Error while runing script %s, "
802 "function %s(): %s", p_ext->psz_name, psz_function,
803 lua_tostring( L, lua_gettop( L ) ) );
807 i_ret = lua_DialogFlush( L );
812 static inline int TriggerMenu( extension_t *p_ext, int i_id )
814 return PushCommand( p_ext, CMD_TRIGGERMENU, i_id );
817 int lua_ExtensionTriggerMenu( extensions_manager_t *p_mgr,
818 extension_t *p_ext, int id )
820 int i_ret = VLC_EGENERIC;
821 lua_State *L = GetLuaState( p_mgr, p_ext );
826 luaopen_dialog( L, p_ext );
828 lua_getglobal( L, "trigger_menu" );
829 if( !lua_isfunction( L, -1 ) )
831 msg_Warn( p_mgr, "Error while runing script %s, "
832 "function trigger_menu() not found", p_ext->psz_name );
836 /* Pass id as unique argument to the function */
837 lua_pushinteger( L, id );
839 if( lua_pcall( L, 1, 1, 0 ) != 0 )
841 msg_Warn( p_mgr, "Error while runing script %s, "
842 "function trigger_menu(): %s", p_ext->psz_name,
843 lua_tostring( L, lua_gettop( L ) ) );
847 i_ret = lua_DialogFlush( L );
848 if( i_ret < VLC_SUCCESS )
850 msg_Dbg( p_mgr, "Something went wrong in %s (%s:%d)",
851 __func__, __FILE__, __LINE__ );
856 /** Directly trigger an extension, without activating it
857 * This is NOT multithreaded, and this code runs in the UI thread
859 * @param p_ext Extension to trigger
860 * @return Value returned by the lua function "trigger"
862 static int TriggerExtension( extensions_manager_t *p_mgr,
865 int i_ret = lua_ExecuteFunction( p_mgr, p_ext, "trigger" );
867 /* Close lua state for trigger-only extensions */
868 if( p_ext->p_sys->L )
869 lua_close( p_ext->p_sys->L );
870 p_ext->p_sys->L = NULL;
875 /** Retrieve extension associated to the current script
876 * @param L current lua_State
877 * @return Lua userdata "vlc.extension"
879 extension_t *vlclua_extension_get( lua_State *L )
881 extension_t *p_ext = NULL;
882 lua_getglobal( L, "vlc" );
883 lua_getfield( L, -1, "extension" );
884 p_ext = (extension_t*) lua_topointer( L, lua_gettop( L ) );
889 /** Deactivate an extension by order from the extension itself
891 * @note This is an asynchronous call. A script calling vlc.deactivate() will
892 * be executed to the end before the last call to deactivate() is done.
894 int vlclua_extension_deactivate( lua_State *L )
896 extension_t *p_ext = vlclua_extension_get( L );
897 int i_ret = Deactivate( p_ext->p_sys->p_mgr, p_ext );
898 return ( i_ret == VLC_SUCCESS ) ? 1 : 0;
901 /** Callback for the variable "dialog-event"
902 * @param p_this Current object owner of the extension and the dialog
903 * @param psz_var "dialog-event"
904 * @param oldval Unused
905 * @param newval Address of the dialog
906 * @param p_data Unused
908 static int vlclua_extension_dialog_callback( vlc_object_t *p_this,
914 /* psz_var == "dialog-event" */
919 extension_dialog_command_t *command = newval.p_address;
920 assert( command != NULL );
921 assert( command->p_dlg != NULL);
923 extension_t *p_ext = command->p_dlg->p_sys;
924 assert( p_ext != NULL );
926 extension_widget_t *p_widget = command->p_data;
928 switch( command->event )
930 case EXTENSION_EVENT_CLICK:
931 assert( p_widget != NULL );
932 PushCommand( p_ext, CMD_CLICK, p_widget );
934 case EXTENSION_EVENT_CLOSE:
935 PushCommandUnique( p_ext, CMD_CLOSE );
938 msg_Dbg( p_this, "Received unknown UI event %d, discarded",
946 /** Callback on vlc_InputItemMetaChanged event
948 static void inputItemMetaChanged( const vlc_event_t *p_event,
951 assert( p_event && p_event->type == vlc_InputItemMetaChanged );
953 extension_t *p_ext = ( extension_t* ) data;
954 assert( p_ext != NULL );
956 PushCommandUnique( p_ext, CMD_UPDATE_META );
959 /* Lock this extension. Can fail. */
960 bool LockExtension( extension_t *p_ext )
962 if( p_ext->p_sys->b_exiting )
965 vlc_mutex_lock( &p_ext->p_sys->running_lock );
966 if( p_ext->p_sys->b_exiting )
968 vlc_mutex_unlock( &p_ext->p_sys->running_lock );
975 void UnlockExtension( extension_t *p_ext )
977 vlc_mutex_unlock( &p_ext->p_sys->running_lock );