Commit 32d3e55a authored by Sam Hocevar's avatar Sam Hocevar

 . Added files needed for the forthcoming module management.

 Notes:

   Plugins are now called modules, because we will be able to compile
   them either as a dynamic plugin, or within the program. And, more
   important, I can commit this without having to break the vlc :)

   I tried to be as clear as possible in my comments, please tell me
   if a few prototypes still have an unclear beahaviour.

   Current features:
    . none, files haven't even been added to the Makefile yet.

   Future features:
    . dynamic loading (done)
    . built-in modules (still to do)
    . automatic unloading of plugins (done)
    . dynamic configuration (still to do)
    . automatic choosing of the most appropriate plugin for a given
       task (still to do but well prepared)
parent 38e1bc07
/*****************************************************************************
* modules.h : Module management functions.
*****************************************************************************
* Copyright (C) 2001 VideoLAN
*
* Authors: Samuel Hocevar <sam@zoy.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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/* Number of tries before we unload an unused module */
#define MODULE_HIDE_DELAY 10
/* The module handle type. */
#ifdef SYS_BEOS
typedef int module_handle_t;
#else
typedef void * module_handle_t;
#endif
/*****************************************************************************
* Configuration structure
*****************************************************************************/
typedef struct module_config_s
{
int i_type; /* Configuration widget type */
char * psz_text; /* Text commenting or describing the widget */
char * psz_name; /* Variable name */
void * p_getlist; /* Function to call to get a choice list */
void * p_change; /* Function to call when commiting a change */
} module_config_t;
/*****************************************************************************
* Bank and module description structures
*****************************************************************************/
/* The main module structure */
typedef struct module_s
{
boolean_t b_builtin; /* Set to true if the module is built in */
module_handle_t handle; /* Unique handle to refer to the module */
char * psz_filename; /* Module filename */
char * psz_name; /* Module _unique_ name */
char * psz_longname; /* Module descriptive name */
char * psz_version; /* Module version */
int i_usage; /* Reference counter */
int i_unused_delay; /* Delay until module is unloaded */
struct module_s * next; /* Next module */
struct module_s * prev; /* Previous module */
u32 i_capabilities; /* Capability list */
module_config_t * p_config; /* Module configuration structure table */
} module_t;
/* The module bank structure */
typedef struct module_bank_s
{
module_t * first; /* First module of the bank */
vlc_mutex_t lock; /* Global lock -- you can't imagine how awful it
is to design thread-safe linked lists. */
} module_bank_t;
/*****************************************************************************
* Stuff for handling dynamic modules
*****************************************************************************/
/* Function to load a dynamic module, returns 0 if successful. */
static __inline__ int
module_load( char * psz_filename, module_handle_t * handle )
{
#ifdef SYS_BEOS
*handle = load_add_on( psz_filename );
return( *handle >= 0 );
#else
*handle = dlopen( psz_filename, RTLD_NOW | RTLD_GLOBAL );
return( *handle != NULL );
#endif
}
/* Unload a dynamic module. */
static __inline__ void
module_unload( module_handle_t handle )
{
#ifdef SYS_BEOS
unload_add_on( handle );
#else
dlclose( handle );
#endif
return;
}
/* Get a given symbol from a module. */
static __inline__ void *
module_getsymbol( module_handle_t handle, char * psz_function )
{
#ifdef SYS_BEOS
void * p_symbol;
get_image_symbol( handle, psz_function, B_SYMBOL_TYPE_TEXT, &p_symbol );
return( p_symbol );
#else
return( dlsym( handle, psz_function ) );
#endif
}
/* Wrapper to dlerror() for systems that don't have it. */
static __inline__ char *
module_error( void )
{
#ifdef SYS_BEOS
return( "failed" );
#else
return( dlerror() );
#endif
}
/*****************************************************************************
* Exported functions.
*****************************************************************************/
module_bank_t * module_InitBank ( void );
int module_DestroyBank ( module_bank_t * p_bank );
int module_ResetBank ( module_bank_t * p_bank );
void module_ManageBank ( module_bank_t * p_bank );
int module_Need ( module_t * p_module );
int module_Unneed ( module_t * p_module );
/*****************************************************************************
* modules_config.h : Module configuration tools.
*****************************************************************************
* Copyright (C) 2001 VideoLAN
*
* Authors: Samuel Hocevar <sam@zoy.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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Module capabilities.
*****************************************************************************/
#define MODULE_CAPABILITY_NULL 0 /* The Module can't do anything */
#define MODULE_CAPABILITY_INTF 1<<0 /* Interface */
#define MODULE_CAPABILITY_INPUT 1<<1 /* Input */
#define MODULE_CAPABILITY_DECAPS 1<<2 /* Decaps */
#define MODULE_CAPABILITY_ADEC 1<<3 /* Audio decoder */
#define MODULE_CAPABILITY_VDEC 1<<4 /* Video decoder */
#define MODULE_CAPABILITY_AOUT 1<<5 /* Audio output */
#define MODULE_CAPABILITY_VOUT 1<<6 /* Video output */
#define MODULE_CAPABILITY_YUV 1<<7 /* YUV colorspace conversion */
#define MODULE_CAPABILITY_AFX 1<<8 /* Audio effects */
#define MODULE_CAPABILITY_VFX 1<<9 /* Video effects */
/*****************************************************************************
* Macros used to build the configuration structure.
*****************************************************************************/
/* Mandatory first and last parts of the structure */
#define MODULE_CONFIG_ITEM_START 0x01 /* The main window */
#define MODULE_CONFIG_ITEM_END 0x00 /* End of the window */
/* Configuration widgets */
#define MODULE_CONFIG_ITEM_PANE 0x02 /* A notebook pane */
#define MODULE_CONFIG_ITEM_FRAME 0x03 /* A frame */
#define MODULE_CONFIG_ITEM_COMMENT 0x04 /* A comment text */
#define MODULE_CONFIG_ITEM_STRING 0x05 /* A string */
#define MODULE_CONFIG_ITEM_FILE 0x06 /* A file selector */
#define MODULE_CONFIG_ITEM_CHECK 0x07 /* A checkbox */
#define MODULE_CONFIG_ITEM_CHOOSE 0x08 /* A choose box */
#define MODULE_CONFIG_ITEM_RADIO 0x09 /* A radio box */
#define MODULE_CONFIG_ITEM_SCALE 0x0a /* A horizontal ruler */
#define MODULE_CONFIG_ITEM_SPIN 0x0b /* A numerical selector */
/*****************************************************************************
* modules_inner.h : Macros used from within a module.
*****************************************************************************
* Copyright (C) 2001 VideoLAN
*
* Authors: Samuel Hocevar <sam@zoy.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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Check that we are within a module.
*****************************************************************************/
#ifndef MODULE_NAME
# error "You must define MODULE_NAME before using modules_inner.h !"
#endif
/*****************************************************************************
* Add a few defines. You do not want to read this section. Really.
*****************************************************************************/
/* Explanation:
*
* if user has #defined MODULE_NAME foo, then we will need:
* #define MODULE_STRING "foo"
* #define MODULE_VAR(blah) "VLC_MODULE_foo_blah"
*
* and, if BUILTIN is set, we will also need:
* #define InitModule foo_InitModule
* #define ActivateModule foo_ActivateModule
* #define DeactivateModule foo_DeactivateModule
*
* this can't easily be done with the C preprocessor, thus a few ugly hacks.
*/
/* I can't believe I need to do this to change foo to "foo" */
#define UGLY_KLUDGE(z) NASTY_CROCK(z)
#define NASTY_CROCK(z) #z
/* And I need to do _this_ to change foo bar to foo_bar ! */
#define AWFUL_BRITTLE(y,z) CRUDE_HACK(y,z)
#define CRUDE_HACK(y,z) y##_##z
/* Also, I need to do this to change blah to "VLC_MODULE_foo_blah" */
#define MODULE_STRING UGLY_KLUDGE(MODULE_NAME)
#define MODULE_VAR(z) "VLC_MODULE_" UGLY_KLUDGE(MODULE_NAME) "_" #z
/* If the module is built-in, then we need to define foo_InitModule instead
* of InitModule. Same for Activate- and DeactivateModule. */
#ifdef BUILTIN
# define InitModule AWFUL_BRITTLE(MODULE_NAME,InitModule)
# define ActivateModule AWFUL_BRITTLE(MODULE_NAME,ActivateModule)
# define DeactivateModule AWFUL_BRITTLE(MODULE_NAME,DeactivateModule)
#endif
/*****************************************************************************
* Macros used to build the configuration structure.
*****************************************************************************/
#define MODULE_CONFIG_START( text ) \
static module_config_t p_config[] = { \
{ MODULE_CONFIG_ITEM_START, text, NULL, NULL, NULL },
#define MODULE_CONFIG_END \
{ MODULE_CONFIG_ITEM_END, NULL, NULL, NULL, NULL } \
};
#define ADD_FRAME( text ) \
{ MODULE_CONFIG_ITEM_FRAME, text, NULL, NULL, NULL },
#define ADD_PANE( text ) \
{ MODULE_CONFIG_ITEM_PANE, text, NULL, NULL, NULL },
#define ADD_COMMENT( text ) \
{ MODULE_CONFIG_ITEM_COMMENT, text, NULL, NULL, NULL },
#define ADD_STRING( text, name, p_update ) \
{ MODULE_CONFIG_ITEM_STRING, text, name, NULL, p_update },
#define ADD_FILE( text, name, p_update ) \
{ MODULE_CONFIG_ITEM_FILE, text, name, NULL, p_update },
#define ADD_CHECK( text, name, p_update ) \
{ MODULE_CONFIG_ITEM_CHECK, text, name, NULL, p_update },
#define ADD_CHOOSE( text, name, p_getlist, p_update ) \
{ MODULE_CONFIG_ITEM_CHOOSE, text, name, p_getlist, p_update },
#define ADD_RADIO( text, name, p_getlist, p_update ) \
{ MODULE_CONFIG_ITEM_RADIO, text, name, p_getlist, p_update },
#define ADD_SCALE( text, name, p_getlist, p_update ) \
{ MODULE_CONFIG_ITEM_SCALE, text, name, p_getlist, p_update },
#define ADD_SPIN( text, name, p_getlist, p_update ) \
{ MODULE_CONFIG_ITEM_SPIN, text, name, p_getlist, p_update },
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment