Cleanup unload calls

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1850 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2003-12-09 23:55:17 +00:00
parent 23cfe10d94
commit 2f69b332d8
8 changed files with 390 additions and 360 deletions

View File

@@ -1051,103 +1051,7 @@ static int parse_gain_value(char *gain_type, char *value)
return (int)gain;
}
int load_module()
{
struct ast_config *cfg;
struct ast_variable *v;
struct phone_pvt *tmp;
int mode = MODE_IMMEDIATE;
int txgain = DEFAULT_GAIN, rxgain = DEFAULT_GAIN; /* default gain 1.0 */
cfg = ast_load(config);
/* We *must* have a config file otherwise stop immediately */
if (!cfg) {
ast_log(LOG_ERROR, "Unable to load config %s\n", config);
return -1;
}
if (ast_mutex_lock(&iflock)) {
/* It's a little silly to lock it, but we mind as well just to be sure */
ast_log(LOG_ERROR, "Unable to lock interface list???\n");
return -1;
}
v = ast_variable_browse(cfg, "interfaces");
while(v) {
/* Create the interface list */
if (!strcasecmp(v->name, "device")) {
tmp = mkif(v->value, mode, txgain, rxgain);
if (tmp) {
tmp->next = iflist;
iflist = tmp;
} else {
ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value);
ast_destroy(cfg);
ast_mutex_unlock(&iflock);
unload_module();
return -1;
}
} else if (!strcasecmp(v->name, "silencesupression")) {
silencesupression = ast_true(v->value);
} else if (!strcasecmp(v->name, "language")) {
strncpy(language, v->value, sizeof(language)-1);
} else if (!strcasecmp(v->name, "callerid")) {
strncpy(callerid, v->value, sizeof(callerid)-1);
} else if (!strcasecmp(v->name, "mode")) {
if (!strncasecmp(v->value, "di", 2))
mode = MODE_DIALTONE;
else if (!strncasecmp(v->value, "im", 2))
mode = MODE_IMMEDIATE;
else if (!strncasecmp(v->value, "fx", 2))
mode = MODE_FXO;
else
ast_log(LOG_WARNING, "Unknown mode: %s\n", v->value);
} else if (!strcasecmp(v->name, "context")) {
strncpy(context, v->value, sizeof(context)-1);
} else if (!strcasecmp(v->name, "format")) {
if (!strcasecmp(v->value, "g723.1")) {
prefformat = AST_FORMAT_G723_1;
} else if (!strcasecmp(v->value, "slinear")) {
prefformat = AST_FORMAT_SLINEAR;
} else if (!strcasecmp(v->value, "ulaw")) {
prefformat = AST_FORMAT_ULAW;
} else
ast_log(LOG_WARNING, "Unknown format '%s'\n", v->value);
} else if (!strcasecmp(v->name, "echocancel")) {
if (!strcasecmp(v->value, "off")) {
echocancel = AEC_OFF;
} else if (!strcasecmp(v->value, "low")) {
echocancel = AEC_LOW;
} else if (!strcasecmp(v->value, "medium")) {
echocancel = AEC_MED;
} else if (!strcasecmp(v->value, "high")) {
echocancel = AEC_HIGH;
} else
ast_log(LOG_WARNING, "Unknown echo cancellation '%s'\n", v->value);
} else if (!strcasecmp(v->name, "txgain")) {
txgain = parse_gain_value(v->name, v->value);
} else if (!strcasecmp(v->name, "rxgain")) {
rxgain = parse_gain_value(v->name, v->value);
}
v = v->next;
}
ast_mutex_unlock(&iflock);
/* Make sure we can register our Adtranphone channel type */
if (ast_channel_register(type, tdesc,
AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW, phone_request)) {
ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
ast_destroy(cfg);
unload_module();
return -1;
}
ast_destroy(cfg);
/* And start the monitor for the first time */
restart_monitor();
return 0;
}
int unload_module()
static int __unload_module(void)
{
struct phone_pvt *p, *pl;
/* First, take us out of the channel loop */
@@ -1200,6 +1104,105 @@ int unload_module()
return 0;
}
int unload_module(void)
{
return __unload_module();
}
int load_module()
{
struct ast_config *cfg;
struct ast_variable *v;
struct phone_pvt *tmp;
int mode = MODE_IMMEDIATE;
int txgain = DEFAULT_GAIN, rxgain = DEFAULT_GAIN; /* default gain 1.0 */
cfg = ast_load(config);
/* We *must* have a config file otherwise stop immediately */
if (!cfg) {
ast_log(LOG_ERROR, "Unable to load config %s\n", config);
return -1;
}
if (ast_mutex_lock(&iflock)) {
/* It's a little silly to lock it, but we mind as well just to be sure */
ast_log(LOG_ERROR, "Unable to lock interface list???\n");
return -1;
}
v = ast_variable_browse(cfg, "interfaces");
while(v) {
/* Create the interface list */
if (!strcasecmp(v->name, "device")) {
tmp = mkif(v->value, mode, txgain, rxgain);
if (tmp) {
tmp->next = iflist;
iflist = tmp;
} else {
ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value);
ast_destroy(cfg);
ast_mutex_unlock(&iflock);
__unload_module();
return -1;
}
} else if (!strcasecmp(v->name, "silencesupression")) {
silencesupression = ast_true(v->value);
} else if (!strcasecmp(v->name, "language")) {
strncpy(language, v->value, sizeof(language)-1);
} else if (!strcasecmp(v->name, "callerid")) {
strncpy(callerid, v->value, sizeof(callerid)-1);
} else if (!strcasecmp(v->name, "mode")) {
if (!strncasecmp(v->value, "di", 2))
mode = MODE_DIALTONE;
else if (!strncasecmp(v->value, "im", 2))
mode = MODE_IMMEDIATE;
else if (!strncasecmp(v->value, "fx", 2))
mode = MODE_FXO;
else
ast_log(LOG_WARNING, "Unknown mode: %s\n", v->value);
} else if (!strcasecmp(v->name, "context")) {
strncpy(context, v->value, sizeof(context)-1);
} else if (!strcasecmp(v->name, "format")) {
if (!strcasecmp(v->value, "g723.1")) {
prefformat = AST_FORMAT_G723_1;
} else if (!strcasecmp(v->value, "slinear")) {
prefformat = AST_FORMAT_SLINEAR;
} else if (!strcasecmp(v->value, "ulaw")) {
prefformat = AST_FORMAT_ULAW;
} else
ast_log(LOG_WARNING, "Unknown format '%s'\n", v->value);
} else if (!strcasecmp(v->name, "echocancel")) {
if (!strcasecmp(v->value, "off")) {
echocancel = AEC_OFF;
} else if (!strcasecmp(v->value, "low")) {
echocancel = AEC_LOW;
} else if (!strcasecmp(v->value, "medium")) {
echocancel = AEC_MED;
} else if (!strcasecmp(v->value, "high")) {
echocancel = AEC_HIGH;
} else
ast_log(LOG_WARNING, "Unknown echo cancellation '%s'\n", v->value);
} else if (!strcasecmp(v->name, "txgain")) {
txgain = parse_gain_value(v->name, v->value);
} else if (!strcasecmp(v->name, "rxgain")) {
rxgain = parse_gain_value(v->name, v->value);
}
v = v->next;
}
ast_mutex_unlock(&iflock);
/* Make sure we can register our Adtranphone channel type */
if (ast_channel_register(type, tdesc,
AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW, phone_request)) {
ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
ast_destroy(cfg);
__unload_module();
return -1;
}
ast_destroy(cfg);
/* And start the monitor for the first time */
restart_monitor();
return 0;
}
int usecount()
{
int res;