extension.h 4.64 KB
Newer Older
JPeg's avatar
JPeg committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*****************************************************************************
 * extension.h: Lua Extensions (meta data, web information, ...)
 *****************************************************************************
 * Copyright (C) 2009-2010 VideoLAN and authors
 * $Id$
 *
 * Authors: Jean-Philippe André < jpeg # videolan.org >
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifndef LUA_EXTENSION_H
#define LUA_EXTENSION_H

#include <vlc_extensions.h>
#include <vlc_arrays.h>
JPeg's avatar
JPeg committed
29
#include <vlc_dialog.h>
JPeg's avatar
JPeg committed
30

31
32
#define WATCH_TIMER_PERIOD    (10 * CLOCK_FREQ) ///< 10s period for the timer

JPeg's avatar
JPeg committed
33
/* List of available commands */
34
35
36
37
38
39
40
41
42
43
44
typedef enum
{
    CMD_ACTIVATE = 1,
    CMD_DEACTIVATE,
    CMD_TRIGGERMENU,    /* Arg1 = int*, pointing to id to trigger. free */
    CMD_CLICK,          /* Arg1 = extension_widget_t* */
    CMD_CLOSE,
    CMD_SET_INPUT,      /* No arg. Just signal current input changed */
    CMD_UPDATE_META,    /* No arg. Just signal current input item meta changed */
    CMD_PLAYING_CHANGED /* Arg1 = int*, New playing status  */
} command_type_e;
JPeg's avatar
JPeg committed
45

46
47
48
49
50
51
52
53
//Data types
typedef enum
{
    LUA_END = 0,
    LUA_NUM,
    LUA_TEXT
} lua_datatype_e;

JPeg's avatar
JPeg committed
54
55
56
57
58
59
60
61
struct extension_sys_t
{
    /* Extension general */
    int i_capabilities;

    /* Lua specific */
    lua_State *L;

62
63
    vlclua_dtable_t dtable;

JPeg's avatar
JPeg committed
64
65
66
67
68
    /* Thread data */
    vlc_thread_t thread;
    vlc_mutex_t command_lock;
    vlc_mutex_t running_lock;
    vlc_cond_t wait;
69
70
71
72
73

    /* The input this extension should use for vlc.input
     * or NULL if it should use playlist's current input */
    struct input_thread_t *p_input;

JPeg's avatar
JPeg committed
74
75
76
77
    extensions_manager_t *p_mgr;     ///< Parent
    /* Queue of commands to execute */
    struct command_t
    {
78
        command_type_e i_command;
JPeg's avatar
JPeg committed
79
80
81
        void *data[10];         ///< Optional void* arguments
        struct command_t *next; ///< Next command
    } *command;
82

JPeg's avatar
JPeg committed
83
    // The two following booleans are protected by command_lock
Thomas Guillem's avatar
Thomas Guillem committed
84
    vlc_dialog_id *p_progress_id;
JPeg's avatar
JPeg committed
85
86
    vlc_timer_t timer; ///< This timer makes sure Lua never gets stuck >5s

87
    bool b_exiting;
88
89

    bool b_thread_running; //< Only accessed out of the extension thread.
90
    bool b_activated; ///< Protected by the command lock
JPeg's avatar
JPeg committed
91
92
93
94
95
};

/* Extensions: manager functions */
int Activate( extensions_manager_t *p_mgr, extension_t * );
int Deactivate( extensions_manager_t *p_mgr, extension_t * );
96
bool QueueDeactivateCommand( extension_t *p_ext );
JPeg's avatar
JPeg committed
97
void KillExtension( extensions_manager_t *p_mgr, extension_t *p_ext );
98
int PushCommand__( extension_t *ext, bool unique, command_type_e cmd, va_list options );
99
100
101
102
static inline int PushCommand( extension_t *ext, int cmd, ... )
{
    va_list args;
    va_start( args, cmd );
103
    int i_ret = PushCommand__( ext, false, cmd, args );
104
105
106
107
108
109
110
    va_end( args );
    return i_ret;
}
static inline int PushCommandUnique( extension_t *ext, int cmd, ... )
{
    va_list args;
    va_start( args, cmd );
111
    int i_ret = PushCommand__( ext, true, cmd, args );
112
113
114
    va_end( args );
    return i_ret;
}
JPeg's avatar
JPeg committed
115
116
117
118
bool LockExtension( extension_t *p_ext );
void UnlockExtension( extension_t *p_ext );

/* Lua specific functions */
119
void vlclua_extension_set( lua_State *L, extension_t * );
JPeg's avatar
JPeg committed
120
121
122
extension_t *vlclua_extension_get( lua_State *L );
int lua_ExtensionActivate( extensions_manager_t *, extension_t * );
int lua_ExtensionDeactivate( extensions_manager_t *, extension_t * );
123
124
int lua_ExecuteFunctionVa( extensions_manager_t *p_mgr, extension_t *p_ext,
                            const char *psz_function, va_list args );
JPeg's avatar
JPeg committed
125
int lua_ExecuteFunction( extensions_manager_t *p_mgr, extension_t *p_ext,
126
                         const char *psz_function, ... );
JPeg's avatar
JPeg committed
127
128
129
130
131
132
int lua_ExtensionWidgetClick( extensions_manager_t *p_mgr,
                              extension_t *p_ext,
                              extension_widget_t *p_widget );
int lua_ExtensionTriggerMenu( extensions_manager_t *p_mgr,
                              extension_t *p_ext, int id );

133
134
135
/* Dialog specific */
int lua_DialogFlush( lua_State *L );

JPeg's avatar
JPeg committed
136
#endif // LUA_EXTENSION_H