00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _ASTERISK_MODULE_H
00029 #define _ASTERISK_MODULE_H
00030
00031 #include "asterisk/utils.h"
00032
00033 #if defined(__cplusplus) || defined(c_plusplus)
00034 extern "C" {
00035 #endif
00036
00037
00038 #define ASTERISK_GPL_KEY \
00039 "This paragraph is copyright (c) 2006 by Digium, Inc. \
00040 In order for your module to load, it must return this \
00041 key via a function called \"key\". Any code which \
00042 includes this paragraph must be licensed under the GNU \
00043 General Public License version 2 or later (at your \
00044 option). In addition to Digium's general reservations \
00045 of rights, Digium expressly reserves the right to \
00046 allow other parties to license this paragraph under \
00047 different terms. Any use of Digium, Inc. trademarks or \
00048 logos (including \"Asterisk\" or \"Digium\") without \
00049 express written permission of Digium, Inc. is prohibited.\n"
00050
00051 #define AST_MODULE_CONFIG "modules.conf"
00052
00053 enum ast_module_unload_mode {
00054 AST_FORCE_SOFT = 0,
00055 AST_FORCE_FIRM = 1,
00056 AST_FORCE_HARD = 2,
00057
00058 };
00059
00060 enum ast_module_load_result {
00061 AST_MODULE_LOAD_SUCCESS = 0,
00062 AST_MODULE_LOAD_DECLINE = 1,
00063 AST_MODULE_LOAD_SKIP = 2,
00064 AST_MODULE_LOAD_FAILURE = -1,
00065 };
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 enum ast_module_load_result ast_load_resource(const char *resource_name);
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 int ast_unload_resource(const char *resource_name, enum ast_module_unload_mode);
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 void ast_update_use_count(void);
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 int ast_update_module_list(int (*modentry)(const char *module, const char *description, int usecnt, const char *like),
00114 const char *like);
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 int ast_loader_register(int (*updater)(void));
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 int ast_loader_unregister(int (*updater)(void));
00136
00137
00138
00139
00140
00141
00142 void ast_module_shutdown(void);
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 char *ast_module_helper(const char *line, const char *word, int pos, int state, int rpos, int needsreload);
00161
00162
00163
00164 struct ast_module;
00165
00166
00167
00168
00169
00170 struct ast_module_user;
00171 struct ast_module_user_list;
00172
00173
00174
00175
00176
00177
00178
00179 enum ast_module_flags {
00180 AST_MODFLAG_DEFAULT = 0,
00181 AST_MODFLAG_GLOBAL_SYMBOLS = (1 << 0),
00182 AST_MODFLAG_BUILDSUM = (1 << 1),
00183
00184
00185
00186
00187
00188
00189
00190 AST_MODFLAG_LOAD_FIRST = (1 << 2),
00191 };
00192
00193 struct ast_module_info {
00194
00195
00196
00197
00198
00199
00200
00201 struct ast_module *self;
00202 enum ast_module_load_result (*load)(void);
00203 int (*reload)(void);
00204 int (*unload)(void);
00205 const char *name;
00206 const char *description;
00207
00208
00209
00210
00211
00212
00213
00214 const char *key;
00215 unsigned int flags;
00216
00217
00218 const char buildopt_sum[33];
00219 };
00220
00221 void ast_module_register(const struct ast_module_info *);
00222 void ast_module_unregister(const struct ast_module_info *);
00223
00224 struct ast_module_user *__ast_module_user_add(struct ast_module *, struct ast_channel *);
00225 void __ast_module_user_remove(struct ast_module *, struct ast_module_user *);
00226 void __ast_module_user_hangup_all(struct ast_module *);
00227
00228 #define ast_module_user_add(chan) __ast_module_user_add(ast_module_info->self, chan)
00229 #define ast_module_user_remove(user) __ast_module_user_remove(ast_module_info->self, user)
00230 #define ast_module_user_hangup_all() __ast_module_user_hangup_all(ast_module_info->self)
00231
00232 struct ast_module *ast_module_ref(struct ast_module *);
00233 void ast_module_unref(struct ast_module *);
00234
00235 #if defined(__cplusplus) || defined(c_plusplus)
00236 #define AST_MODULE_INFO(keystr, flags_to_set, desc, load_func, unload_func, reload_func) \
00237 static struct ast_module_info __mod_info = { \
00238 NULL, \
00239 load_func, \
00240 reload_func, \
00241 unload_func, \
00242 AST_MODULE, \
00243 desc, \
00244 keystr, \
00245 flags_to_set | AST_MODFLAG_BUILDSUM, \
00246 AST_BUILDOPT_SUM, \
00247 }; \
00248 static void __attribute__((constructor)) __reg_module(void) \
00249 { \
00250 ast_module_register(&__mod_info); \
00251 } \
00252 static void __attribute__((destructor)) __unreg_module(void) \
00253 { \
00254 ast_module_unregister(&__mod_info); \
00255 } \
00256 const static __attribute__((unused)) struct ast_module_info *ast_module_info = &__mod_info
00257
00258 #define AST_MODULE_INFO_STANDARD(keystr, desc) \
00259 AST_MODULE_INFO(keystr, AST_MODFLAG_DEFAULT, desc, \
00260 load_module, \
00261 unload_module, \
00262 NULL \
00263 )
00264 #else
00265
00266
00267
00268 const static __attribute__((unused)) struct ast_module_info *ast_module_info;
00269
00270 #define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...) \
00271 static struct ast_module_info __mod_info = { \
00272 .name = AST_MODULE, \
00273 .flags = flags_to_set | AST_MODFLAG_BUILDSUM, \
00274 .description = desc, \
00275 .key = keystr, \
00276 .buildopt_sum = AST_BUILDOPT_SUM, \
00277 fields \
00278 }; \
00279 static void __attribute__((constructor)) __reg_module(void) \
00280 { \
00281 ast_module_register(&__mod_info); \
00282 } \
00283 static void __attribute__((destructor)) __unreg_module(void) \
00284 { \
00285 ast_module_unregister(&__mod_info); \
00286 } \
00287 const static struct ast_module_info *ast_module_info = &__mod_info
00288
00289 #define AST_MODULE_INFO_STANDARD(keystr, desc) \
00290 AST_MODULE_INFO(keystr, AST_MODFLAG_DEFAULT, desc, \
00291 .load = load_module, \
00292 .unload = unload_module, \
00293 )
00294 #endif
00295
00296 #if defined(__cplusplus) || defined(c_plusplus)
00297 }
00298 #endif
00299
00300 #endif