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_PRIORITY = 3,
00065 AST_MODULE_LOAD_FAILURE = -1,
00066 };
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 enum ast_module_load_result ast_load_resource(const char *resource_name);
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 int ast_unload_resource(const char *resource_name, enum ast_module_unload_mode);
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 void ast_update_use_count(void);
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 int ast_update_module_list(int (*modentry)(const char *module, const char *description, int usecnt, const char *like),
00116 const char *like);
00117
00118
00119
00120
00121
00122
00123
00124 int ast_module_check(const char *name);
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 int ast_loader_register(int (*updater)(void));
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 int ast_loader_unregister(int (*updater)(void));
00148
00149
00150
00151
00152
00153
00154 void ast_module_shutdown(void);
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 char *ast_module_helper(const char *line, const char *word, int pos, int state, int rpos, int needsreload);
00173
00174
00175
00176 struct ast_module;
00177
00178
00179
00180
00181
00182 struct ast_module_user;
00183 struct ast_module_user_list;
00184
00185
00186
00187
00188
00189
00190 enum ast_module_flags {
00191 AST_MODFLAG_DEFAULT = 0,
00192 AST_MODFLAG_GLOBAL_SYMBOLS = (1 << 0),
00193 AST_MODFLAG_LOAD_ORDER = (1 << 1),
00194 };
00195
00196 enum ast_module_load_priority {
00197 AST_MODPRI_REALTIME_DEPEND = 10,
00198 AST_MODPRI_REALTIME_DEPEND2 = 20,
00199 AST_MODPRI_REALTIME_DRIVER = 30,
00200 AST_MODPRI_CHANNEL_DEPEND = 50,
00201 AST_MODPRI_CHANNEL_DRIVER = 60,
00202 AST_MODPRI_APP_DEPEND = 70,
00203 AST_MODPRI_DEVSTATE_PROVIDER = 80,
00204 AST_MODPRI_DEVSTATE_PLUGIN = 90,
00205 AST_MODPRI_CDR_DRIVER = 100,
00206 AST_MODPRI_DEFAULT = 128,
00207 AST_MODPRI_DEVSTATE_CONSUMER = 150,
00208 };
00209
00210 struct ast_module_info {
00211
00212
00213
00214
00215
00216
00217
00218 struct ast_module *self;
00219 enum ast_module_load_result (*load)(void);
00220 int (*reload)(void);
00221 int (*unload)(void);
00222 int (*backup_globals)(void);
00223 void (*restore_globals)(void);
00224 const char *name;
00225 const char *description;
00226
00227
00228
00229
00230
00231
00232
00233 const char *key;
00234 unsigned int flags;
00235
00236
00237 const char buildopt_sum[33];
00238
00239
00240
00241
00242
00243
00244 unsigned char load_pri;
00245
00246
00247
00248
00249 const char *nonoptreq;
00250 };
00251
00252 void ast_module_register(const struct ast_module_info *);
00253 void ast_module_unregister(const struct ast_module_info *);
00254
00255 struct ast_module_user *__ast_module_user_add(struct ast_module *, struct ast_channel *);
00256 void __ast_module_user_remove(struct ast_module *, struct ast_module_user *);
00257 void __ast_module_user_hangup_all(struct ast_module *);
00258
00259 #define ast_module_user_add(chan) __ast_module_user_add(ast_module_info->self, chan)
00260 #define ast_module_user_remove(user) __ast_module_user_remove(ast_module_info->self, user)
00261 #define ast_module_user_hangup_all() __ast_module_user_hangup_all(ast_module_info->self)
00262
00263 struct ast_module *ast_module_ref(struct ast_module *);
00264 void ast_module_unref(struct ast_module *);
00265
00266 #if defined(__cplusplus) || defined(c_plusplus)
00267 #define AST_MODULE_INFO(keystr, flags_to_set, desc, load_func, unload_func, reload_func, load_pri) \
00268 static struct ast_module_info __mod_info = { \
00269 NULL, \
00270 load_func, \
00271 reload_func, \
00272 unload_func, \
00273 NULL, \
00274 NULL, \
00275 AST_MODULE, \
00276 desc, \
00277 keystr, \
00278 flags_to_set, \
00279 AST_BUILDOPT_SUM, \
00280 load_pri, \
00281 }; \
00282 static void __attribute__((constructor)) __reg_module(void) \
00283 { \
00284 ast_module_register(&__mod_info); \
00285 } \
00286 static void __attribute__((destructor)) __unreg_module(void) \
00287 { \
00288 ast_module_unregister(&__mod_info); \
00289 } \
00290 static const __attribute__((unused)) struct ast_module_info *ast_module_info = &__mod_info
00291
00292 #define AST_MODULE_INFO_STANDARD(keystr, desc) \
00293 AST_MODULE_INFO(keystr, AST_MODFLAG_LOAD_ORDER, desc, \
00294 load_module, \
00295 unload_module, \
00296 NULL, \
00297 AST_MODPRI_DEFAULT \
00298 )
00299 #else
00300
00301
00302
00303
00304 static const __attribute__((unused)) struct ast_module_info *ast_module_info;
00305
00306 #if !defined(EMBEDDED_MODULE)
00307 #define __MODULE_INFO_SECTION
00308 #define __MODULE_INFO_GLOBALS
00309 #else
00310
00311
00312
00313
00314
00315
00316
00317 #define __MODULE_INFO_SECTION __attribute__((section(".embed_module")))
00318 #define __MODULE_INFO_GLOBALS .backup_globals = __backup_globals, .restore_globals = __restore_globals,
00319
00320 #define make_var_sub(mod, type) __ ## mod ## _ ## type
00321 #define make_var(mod, type) make_var_sub(mod, type)
00322
00323 extern void make_var(EMBEDDED_MODULE, bss_start);
00324 extern void make_var(EMBEDDED_MODULE, bss_end);
00325 extern void make_var(EMBEDDED_MODULE, data_start);
00326 extern void make_var(EMBEDDED_MODULE, data_end);
00327
00328 static void * __attribute__((section(".embed_module"))) __global_backup;
00329
00330 static int __backup_globals(void)
00331 {
00332 size_t data_size = & make_var(EMBEDDED_MODULE, data_end) - & make_var(EMBEDDED_MODULE, data_start);
00333
00334 if (__global_backup)
00335 return 0;
00336
00337 if (!data_size)
00338 return 0;
00339
00340 if (!(__global_backup = ast_malloc(data_size)))
00341 return -1;
00342
00343 memcpy(__global_backup, & make_var(EMBEDDED_MODULE, data_start), data_size);
00344
00345 return 0;
00346 }
00347
00348 static void __restore_globals(void)
00349 {
00350 size_t data_size = & make_var(EMBEDDED_MODULE, data_end) - & make_var(EMBEDDED_MODULE, data_start);
00351 size_t bss_size = & make_var(EMBEDDED_MODULE, bss_end) - & make_var(EMBEDDED_MODULE, bss_start);
00352
00353 if (bss_size)
00354 memset(& make_var(EMBEDDED_MODULE, bss_start), 0, bss_size);
00355
00356 if (!data_size || !__global_backup)
00357 return;
00358
00359 memcpy(& make_var(EMBEDDED_MODULE, data_start), __global_backup, data_size);
00360 }
00361 #undef make_var
00362 #undef make_var_sub
00363 #endif
00364
00365 #define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...) \
00366 static struct ast_module_info \
00367 __MODULE_INFO_SECTION \
00368 __mod_info = { \
00369 __MODULE_INFO_GLOBALS \
00370 .name = AST_MODULE, \
00371 .flags = flags_to_set, \
00372 .description = desc, \
00373 .key = keystr, \
00374 .buildopt_sum = AST_BUILDOPT_SUM, \
00375 fields \
00376 }; \
00377 static void __attribute__((constructor)) __reg_module(void) \
00378 { \
00379 ast_module_register(&__mod_info); \
00380 } \
00381 static void __attribute__((destructor)) __unreg_module(void) \
00382 { \
00383 ast_module_unregister(&__mod_info); \
00384 } \
00385 static const struct ast_module_info *ast_module_info = &__mod_info
00386
00387 #define AST_MODULE_INFO_STANDARD(keystr, desc) \
00388 AST_MODULE_INFO(keystr, AST_MODFLAG_LOAD_ORDER, desc, \
00389 .load = load_module, \
00390 .unload = unload_module, \
00391 .load_pri = AST_MODPRI_DEFAULT, \
00392 )
00393 #endif
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412 #define ast_register_application(app, execute, synopsis, description) ast_register_application2(app, execute, synopsis, description, ast_module_info->self)
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428 #define ast_register_application_xml(app, execute) ast_register_application(app, execute, NULL, NULL)
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449 int ast_register_application2(const char *app, int (*execute)(struct ast_channel *, const char *),
00450 const char *synopsis, const char *description, void *mod);
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462 int ast_unregister_application(const char *app);
00463
00464
00465 #if defined(__cplusplus) || defined(c_plusplus)
00466 }
00467 #endif
00468
00469 #endif