]> git.sesse.net Git - vlc/blob - modules/misc/lua/extension.h
78928b53a6598fbb4cfaa8d0b7d79af7f22897c1
[vlc] / modules / misc / lua / extension.h
1 /*****************************************************************************
2  * extension.h: Lua Extensions (meta data, web information, ...)
3  *****************************************************************************
4  * Copyright (C) 2009-2010 VideoLAN and authors
5  * $Id$
6  *
7  * Authors: Jean-Philippe AndrĂ© < jpeg # videolan.org >
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifndef LUA_EXTENSION_H
25 #define LUA_EXTENSION_H
26
27 #include <vlc_extensions.h>
28 #include <vlc_arrays.h>
29
30 ///< Array of extension_t
31 TYPEDEF_ARRAY( extension_t, array_extension_t );
32
33 /* List of available commands */
34 #define CMD_ACTIVATE    1
35 #define CMD_DEACTIVATE  2
36 #define CMD_TRIGGERMENU 3    /* Arg1 = int*, pointing to id to trigger. free */
37 #define CMD_CLICK       4    /* Arg1 = extension_widget_t* */
38 #define CMD_CLOSE       5
39 #define CMD_SET_INPUT   6    /* No arg. Just signal current input changed */
40 #define CMD_UPDATE_META 7    /* No arg. Just signal current input item meta
41                               * changed */
42
43 struct extensions_manager_sys_t
44 {
45     /* List of activated extensions */
46     DECL_ARRAY( extension_t* ) activated_extensions;
47
48     /* Lock for this list */
49     vlc_mutex_t lock;
50
51     /* Lua specific */
52     lua_State *L;
53
54     /* Flag indicating that the module is about to be unloaded */
55     bool b_killed;
56 };
57
58 struct extension_sys_t
59 {
60     /* Extension general */
61     int i_capabilities;
62
63     /* Lua specific */
64     lua_State *L;
65
66     /* Thread data */
67     vlc_thread_t thread;
68     vlc_mutex_t command_lock;
69     vlc_mutex_t running_lock;
70     vlc_cond_t wait;
71
72     /* The input this extension should use for vlc.input
73      * or NULL if it should use playlist's current input */
74     struct input_thread_t *p_input;
75
76     extensions_manager_t *p_mgr;     ///< Parent
77     /* Queue of commands to execute */
78     struct command_t
79     {
80         int i_command;
81         void *data[10];         ///< Optional void* arguments
82         struct command_t *next; ///< Next command
83     } *command;
84
85     bool b_exiting;
86 };
87
88 /* Extensions: manager functions */
89 int Activate( extensions_manager_t *p_mgr, extension_t * );
90 bool IsActivated( extensions_manager_t *p_mgr, extension_t * );
91 int Deactivate( extensions_manager_t *p_mgr, extension_t * );
92 void WaitForDeactivation( extension_t *p_ext );
93 int __PushCommand( extension_t *ext, bool unique, int cmd, va_list options );
94 static inline int PushCommand( extension_t *ext, int cmd, ... )
95 {
96     va_list args;
97     va_start( args, cmd );
98     int i_ret = __PushCommand( ext, false, cmd, args );
99     va_end( args );
100     return i_ret;
101 }
102 static inline int PushCommandUnique( extension_t *ext, int cmd, ... )
103 {
104     va_list args;
105     va_start( args, cmd );
106     int i_ret = __PushCommand( ext, true, cmd, args );
107     va_end( args );
108     return i_ret;
109 }
110 bool LockExtension( extension_t *p_ext );
111 void UnlockExtension( extension_t *p_ext );
112
113 /* Lua specific functions */
114 extension_t *vlclua_extension_get( lua_State *L );
115 int lua_ExtensionActivate( extensions_manager_t *, extension_t * );
116 int lua_ExtensionDeactivate( extensions_manager_t *, extension_t * );
117 int lua_ExecuteFunction( extensions_manager_t *p_mgr, extension_t *p_ext,
118                          const char *psz_function );
119 int lua_ExtensionWidgetClick( extensions_manager_t *p_mgr,
120                               extension_t *p_ext,
121                               extension_widget_t *p_widget );
122 int lua_ExtensionTriggerMenu( extensions_manager_t *p_mgr,
123                               extension_t *p_ext, int id );
124
125 /* Dialog specific */
126 int lua_DialogFlush( lua_State *L );
127
128 #endif // LUA_EXTENSION_H