aboutsummaryrefslogtreecommitdiffstats
path: root/include/asterisk/module.h
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-02 08:53:16 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-02 08:53:16 +0000
commitbbd7d8014b8c0ad481e5a58686487f44799434d1 (patch)
tree337a11dc4d135c75bcc1e8d6b95d0401cdcc94a4 /include/asterisk/module.h
parentb68637439fbb067eb0821b761aac503009a03aec (diff)
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: http://svn.digium.com/svn/asterisk/trunk@95771 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk/module.h')
-rw-r--r--include/asterisk/module.h57
1 files changed, 24 insertions, 33 deletions
diff --git a/include/asterisk/module.h b/include/asterisk/module.h
index ac0fe5dd4..2344fe825 100644
--- a/include/asterisk/module.h
+++ b/include/asterisk/module.h
@@ -1,7 +1,7 @@
/*
* Asterisk -- An open source telephony toolkit.
*
- * Copyright (C) 1999 - 2006, Digium, Inc.
+ * Copyright (C) 1999 - 2008, Digium, Inc.
*
* Mark Spencer <markster@digium.com>
* Kevin P. Fleming <kpfleming@digium.com>
@@ -184,7 +184,6 @@ struct ast_module_user_list;
/*! \page ModMngmnt The Asterisk Module management interface
*
* All modules must implement the module API (load, unload...)
- * whose functions are exported through fields of a "struct module_symbol";
*/
enum ast_module_flags {
@@ -244,6 +243,8 @@ void ast_module_unref(struct ast_module *);
reload_func, \
unload_func, \
AST_MODULE, \
+ NULL, \
+ NULL, \
desc, \
keystr, \
flags_to_set, \
@@ -265,13 +266,26 @@ void ast_module_unref(struct ast_module *);
unload_module, \
NULL \
)
-#else
+#else /* plain C */
+
/* forward declare this pointer in modules, so that macro/function
calls that need it can get it, since it will actually be declared
and populated at the end of the module's source file... */
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(mod, type) make_var_sub(mod, type)
@@ -314,36 +328,15 @@ static void __restore_globals(void)
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_sub
-
-#else /* !defined(EMBEDDED_MODULE) */
+#endif /* EMBEDDED_MODULE */
#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, \
.flags = flags_to_set, \
.description = desc, \
@@ -361,14 +354,12 @@ static void __restore_globals(void)
} \
const static struct ast_module_info *ast_module_info = &__mod_info
-#endif /* !defined(EMBEDDED_MODULE) */
-
#define AST_MODULE_INFO_STANDARD(keystr, desc) \
AST_MODULE_INFO(keystr, AST_MODFLAG_DEFAULT, desc, \
.load = load_module, \
.unload = unload_module, \
)
-#endif
+#endif /* plain C */
/*!
* \brief Register an application.