Skip to content
Snippets Groups Projects
Commit ca2a8e3f authored by Luigi Rizzo's avatar Luigi Rizzo
Browse files

There are three instances of the module definition macros,

which make maintaining this file very error prone.

This commit merges the embedded and !embedded versions,
and fixes the C++ version. Eventually we should move to
a single version of the macro.

Too bad C++ doesn't like the C-style struct initializers
    .foo = some_value



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@95771 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 04db372b
No related branches found
No related tags found
No related merge requests found
/* /*
* Asterisk -- An open source telephony toolkit. * Asterisk -- An open source telephony toolkit.
* *
* Copyright (C) 1999 - 2006, Digium, Inc. * Copyright (C) 1999 - 2008, Digium, Inc.
* *
* Mark Spencer <markster@digium.com> * Mark Spencer <markster@digium.com>
* Kevin P. Fleming <kpfleming@digium.com> * Kevin P. Fleming <kpfleming@digium.com>
...@@ -184,7 +184,6 @@ struct ast_module_user_list; ...@@ -184,7 +184,6 @@ struct ast_module_user_list;
/*! \page ModMngmnt The Asterisk Module management interface /*! \page ModMngmnt The Asterisk Module management interface
* *
* All modules must implement the module API (load, unload...) * All modules must implement the module API (load, unload...)
* whose functions are exported through fields of a "struct module_symbol";
*/ */
enum ast_module_flags { enum ast_module_flags {
...@@ -244,6 +243,8 @@ void ast_module_unref(struct ast_module *); ...@@ -244,6 +243,8 @@ void ast_module_unref(struct ast_module *);
reload_func, \ reload_func, \
unload_func, \ unload_func, \
AST_MODULE, \ AST_MODULE, \
NULL, \
NULL, \
desc, \ desc, \
keystr, \ keystr, \
flags_to_set, \ flags_to_set, \
...@@ -265,13 +266,26 @@ void ast_module_unref(struct ast_module *); ...@@ -265,13 +266,26 @@ void ast_module_unref(struct ast_module *);
unload_module, \ unload_module, \
NULL \ NULL \
) )
#else #else /* plain C */
/* forward declare this pointer in modules, so that macro/function /* forward declare this pointer in modules, so that macro/function
calls that need it can get it, since it will actually be declared calls that need it can get it, since it will actually be declared
and populated at the end of the module's source file... */ and populated at the end of the module's source file... */
const static __attribute__((unused)) struct ast_module_info *ast_module_info; const static __attribute__((unused)) struct ast_module_info *ast_module_info;
#if defined(EMBEDDED_MODULE) #if !defined(EMBEDDED_MODULE)
#define __MODULE_INFO_SECTION
#define __MODULE_INFO_GLOBALS
#else
/*
* For embedded modules we need additional information to backup and
* restore the global variables in the module itself, so we can unload
* reload the module.
* EMBEDDED_MODULE is defined as the module name, so the calls to make_var()
* below will actually define different symbols for each module.
*/
#define __MODULE_INFO_SECTION __attribute__((section(".embed_module")))
#define __MODULE_INFO_GLOBALS .backup_globals = __backup_globals, .restore_globals = __restore_globals,
#define make_var_sub(mod, type) __ ## mod ## _ ## type #define make_var_sub(mod, type) __ ## mod ## _ ## type
#define make_var(mod, type) make_var_sub(mod, type) #define make_var(mod, type) make_var_sub(mod, type)
...@@ -314,36 +328,15 @@ static void __restore_globals(void) ...@@ -314,36 +328,15 @@ static void __restore_globals(void)
memcpy(& make_var(EMBEDDED_MODULE, data_start), __global_backup, data_size); memcpy(& make_var(EMBEDDED_MODULE, data_start), __global_backup, data_size);
} }
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...) \
static struct ast_module_info \
__attribute__((section(".embed_module"))) \
__mod_info = { \
.backup_globals = __backup_globals, \
.restore_globals = __restore_globals, \
.name = AST_MODULE, \
.flags = flags_to_set, \
.description = desc, \
.key = keystr, \
fields \
}; \
static void __attribute__ ((constructor)) __reg_module(void) \
{ \
ast_module_register(&__mod_info); \
} \
static void __attribute__ ((destructor)) __unreg_module(void) \
{ \
ast_module_unregister(&__mod_info); \
} \
const static struct ast_module_info *ast_module_info = &__mod_info
#undef make_var #undef make_var
#undef make_var_sub #undef make_var_sub
#endif /* EMBEDDED_MODULE */
#else /* !defined(EMBEDDED_MODULE) */
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...) \ #define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...) \
static struct ast_module_info __mod_info = { \ static struct ast_module_info \
__MODULE_INFO_SECTION \
__mod_info = { \
__MODULE_INFO_GLOBALS \
.name = AST_MODULE, \ .name = AST_MODULE, \
.flags = flags_to_set, \ .flags = flags_to_set, \
.description = desc, \ .description = desc, \
...@@ -361,14 +354,12 @@ static void __restore_globals(void) ...@@ -361,14 +354,12 @@ static void __restore_globals(void)
} \ } \
const static struct ast_module_info *ast_module_info = &__mod_info const static struct ast_module_info *ast_module_info = &__mod_info
#endif /* !defined(EMBEDDED_MODULE) */
#define AST_MODULE_INFO_STANDARD(keystr, desc) \ #define AST_MODULE_INFO_STANDARD(keystr, desc) \
AST_MODULE_INFO(keystr, AST_MODFLAG_DEFAULT, desc, \ AST_MODULE_INFO(keystr, AST_MODFLAG_DEFAULT, desc, \
.load = load_module, \ .load = load_module, \
.unload = unload_module, \ .unload = unload_module, \
) )
#endif #endif /* plain C */
/*! /*!
* \brief Register an application. * \brief Register an application.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment