]> git.sesse.net Git - vlc/blob - modules/lua/extension.h
05776729ca5686b46c7535dd0e5c24c95b6a634c
[vlc] / modules / 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 #include <vlc_dialog.h>
30
31 /* List of available commands */
32 typedef enum
33 {
34     CMD_ACTIVATE = 1,
35     CMD_DEACTIVATE,
36     CMD_TRIGGERMENU,    /* Arg1 = int*, pointing to id to trigger. free */
37     CMD_CLICK,          /* Arg1 = extension_widget_t* */
38     CMD_CLOSE,
39     CMD_SET_INPUT,      /* No arg. Just signal current input changed */
40     CMD_UPDATE_META,    /* No arg. Just signal current input item meta changed */
41     CMD_PLAYING_CHANGED /* Arg1 = int*, New playing status  */
42 } command_type_e;
43
44 //Data types
45 typedef enum
46 {
47     LUA_END = 0,
48     LUA_NUM,
49     LUA_TEXT
50 } lua_datatype_e;
51
52 struct extensions_manager_sys_t
53 {
54     /* List of activated extensions */
55     DECL_ARRAY( extension_t* ) activated_extensions;
56
57     /* Lock for this list */
58     vlc_mutex_t lock;
59
60     /* Flag indicating that the module is about to be unloaded */
61     bool b_killed;
62 };
63
64 struct extension_sys_t
65 {
66     /* Extension general */
67     int i_capabilities;
68
69     /* Lua specific */
70     lua_State *L;
71
72     /* Thread data */
73     vlc_thread_t thread;
74     vlc_mutex_t command_lock;
75     vlc_mutex_t running_lock;
76     vlc_cond_t wait;
77
78     /* The input this extension should use for vlc.input
79      * or NULL if it should use playlist's current input */
80     struct input_thread_t *p_input;
81
82     extensions_manager_t *p_mgr;     ///< Parent
83     /* Queue of commands to execute */
84     struct command_t
85     {
86         command_type_e i_command;
87         void *data[10];         ///< Optional void* arguments
88         struct command_t *next; ///< Next command
89     } *command;
90
91     // The two following booleans are protected by command_lock
92     dialog_progress_bar_t *progress;
93     vlc_timer_t timer; ///< This timer makes sure Lua never gets stuck >5s
94
95     bool b_exiting;
96 };
97
98 /* Extensions: manager functions */
99 int Activate( extensions_manager_t *p_mgr, extension_t * );
100 bool IsActivated( extensions_manager_t *p_mgr, extension_t * );
101 int Deactivate( extensions_manager_t *p_mgr, extension_t * );
102 void KillExtension( extensions_manager_t *p_mgr, extension_t *p_ext );
103 int __PushCommand( extension_t *ext, bool unique, command_type_e cmd, va_list options );
104 static inline int PushCommand( extension_t *ext, int cmd, ... )
105 {
106     va_list args;
107     va_start( args, cmd );
108     int i_ret = __PushCommand( ext, false, cmd, args );
109     va_end( args );
110     return i_ret;
111 }
112 static inline int PushCommandUnique( extension_t *ext, int cmd, ... )
113 {
114     va_list args;
115     va_start( args, cmd );
116     int i_ret = __PushCommand( ext, true, cmd, args );
117     va_end( args );
118     return i_ret;
119 }
120 bool LockExtension( extension_t *p_ext );
121 void UnlockExtension( extension_t *p_ext );
122
123 /* Lua specific functions */
124 void vlclua_extension_set( lua_State *L, extension_t * );
125 extension_t *vlclua_extension_get( lua_State *L );
126 int lua_ExtensionActivate( extensions_manager_t *, extension_t * );
127 int lua_ExtensionDeactivate( extensions_manager_t *, extension_t * );
128 int lua_ExecuteFunctionVa( extensions_manager_t *p_mgr, extension_t *p_ext,
129                             const char *psz_function, va_list args );
130 int lua_ExecuteFunction( extensions_manager_t *p_mgr, extension_t *p_ext,
131                          const char *psz_function, ... );
132 int lua_ExtensionWidgetClick( extensions_manager_t *p_mgr,
133                               extension_t *p_ext,
134                               extension_widget_t *p_widget );
135 int lua_ExtensionTriggerMenu( extensions_manager_t *p_mgr,
136                               extension_t *p_ext, int id );
137
138 /* Dialog specific */
139 int lua_DialogFlush( lua_State *L );
140
141 #endif // LUA_EXTENSION_H