2 * Asterisk -- A telephony toolkit for Linux.
6 * Copyright (C) 1999, Adtran Inc. and Linux Support Services, LLC
8 * Mark Spencer <markster@linux-support.net>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
14 #ifndef _ASTERISK_MODULE_H
15 #define _ASTERISK_MODULE_H
17 #if defined(__cplusplus) || defined(c_plusplus)
21 /* Every module must provide these functions */
23 int load_module(void); /* Initialize the module */
24 int unload_module(void); /* Cleanup all module structures,
26 int usecount(void); /* How many channels provided by this module are in use? */
27 char *description(void); /* Description of this module */
29 #define AST_MODULE_CONFIG "modules.conf" /* Module configuration file */
31 #define AST_FORCE_SOFT 0
32 #define AST_FORCE_FIRM 1
33 #define AST_FORCE_HARD 2
36 int ast_load_resource(char *resource_name);
38 /* Unload a module. Force unloading a module is not recommended. */
39 int ast_unload_resource(char *resource_name, int force);
41 /* Notify when usecount has been changed */
42 void ast_update_use_count(void);
44 /* Ask for a list of modules, descriptions, and use counts */
45 int ast_update_module_list(int (*modentry)(char *module, char *description, int usecnt));
47 /* Ask this procedure to be run with modules have been updated */
48 int ast_loader_register(int (*updater)(void));
50 /* No longer run me when modules are updated */
51 int ast_loader_unregister(int (*updater)(void));
53 /* Local user routines keep track of which channels are using a given module resource.
54 They can help make removing modules safer, particularly if they're in use at the time
55 they have been requested to be removed */
57 #define STANDARD_LOCAL_USER struct localuser { \
58 struct ast_channel *chan; \
59 struct localuser *next; \
62 #define LOCAL_USER_DECL static pthread_mutex_t localuser_lock = PTHREAD_MUTEX_INITIALIZER; \
63 static struct localuser *localusers = NULL; \
64 static int localusecnt = 0;
66 #define LOCAL_USER_ADD(u) { \
68 if (!(u=malloc(sizeof(struct localuser)))) { \
69 ast_log(LOG_WARNING, "Out of memory\n"); \
72 pthread_mutex_lock(&localuser_lock); \
74 u->next = localusers; \
77 pthread_mutex_unlock(&localuser_lock); \
78 ast_update_use_count(); \
81 #define LOCAL_USER_REMOVE(u) { \
82 struct localuser *uc, *ul = NULL; \
83 pthread_mutex_lock(&localuser_lock); \
88 ul->next = uc->next; \
90 localusers = uc->next; \
98 pthread_mutex_unlock(&localuser_lock); \
99 ast_update_use_count(); \
102 #define STANDARD_HANGUP_LOCALUSERS { \
103 struct localuser *u, *ul; \
104 pthread_mutex_lock(&localuser_lock); \
107 ast_softhangup(u->chan); \
112 pthread_mutex_unlock(&localuser_lock); \
116 #define STANDARD_USECOUNT(res) { \
117 pthread_mutex_lock(&localuser_lock); \
119 pthread_mutex_unlock(&localuser_lock); \
124 #if defined(__cplusplus) || defined(c_plusplus)