forked from Mirrors/freeswitch
freetdm: fix libpri mod
This commit is contained in:
parent
00207cede3
commit
b96f854803
@ -1793,7 +1793,6 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open(uint32_t span_id, uint32_t chan_id,
|
||||
ftdm_channel_t *best_rated = NULL;
|
||||
ftdm_status_t status = FTDM_FAIL;
|
||||
int best_rate = 0;
|
||||
int may_be_available = 0;
|
||||
|
||||
*ftdmchan = NULL;
|
||||
|
||||
@ -1828,40 +1827,55 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open(uint32_t span_id, uint32_t chan_id,
|
||||
|
||||
ftdm_mutex_lock(check->mutex);
|
||||
|
||||
/* The following if's and gotos replace a big if (this || this || this || this) else { nothing; } */
|
||||
|
||||
/* if it is not a voice channel, nothing else to check to open it */
|
||||
if (!FTDM_IS_VOICE_CHANNEL(check)) {
|
||||
goto openchan;
|
||||
}
|
||||
|
||||
/* if it's an FXS device with a call active and has callwaiting enabled, we allow to open it twice */
|
||||
if (check->type == FTDM_CHAN_TYPE_FXS
|
||||
&& check->token_count == 1
|
||||
&& ftdm_channel_test_feature(check, FTDM_CHANNEL_FEATURE_CALLWAITING)) {
|
||||
goto openchan;
|
||||
}
|
||||
|
||||
/* if channel is available, time to open it */
|
||||
if (chan_is_avail(check)) {
|
||||
goto openchan;
|
||||
}
|
||||
|
||||
/* not available, but still might be available ... */
|
||||
calculate_best_rate(check, &best_rated, &best_rate);
|
||||
if (best_rated) {
|
||||
may_be_available = 1;
|
||||
goto openchan;
|
||||
}
|
||||
|
||||
/* the channel is only allowed to be open if not in use, or, for FXS devices with a call with call waiting enabled */
|
||||
if (
|
||||
(check->type == FTDM_CHAN_TYPE_FXS
|
||||
&& check->token_count == 1
|
||||
&& ftdm_channel_test_feature(check, FTDM_CHANNEL_FEATURE_CALLWAITING))
|
||||
||
|
||||
chan_is_avail(check)
|
||||
||
|
||||
(check->type == FTDM_CHAN_TYPE_DQ921 && ftdm_test_flag(check, FTDM_CHANNEL_CONFIGURED) && ftdm_test_flag(check, FTDM_CHANNEL_READY))
|
||||
||
|
||||
may_be_available) {
|
||||
if (!ftdm_test_flag(check, FTDM_CHANNEL_OPEN)) {
|
||||
status = check->fio->open(check);
|
||||
if (status == FTDM_SUCCESS) {
|
||||
ftdm_set_flag(check, FTDM_CHANNEL_OPEN);
|
||||
}
|
||||
} else {
|
||||
status = FTDM_SUCCESS;
|
||||
/* channel is unavailable, do not open the channel */
|
||||
goto unlockchan;
|
||||
|
||||
openchan:
|
||||
if (!ftdm_test_flag(check, FTDM_CHANNEL_OPEN)) {
|
||||
status = check->fio->open(check);
|
||||
if (status == FTDM_SUCCESS) {
|
||||
ftdm_set_flag(check, FTDM_CHANNEL_OPEN);
|
||||
}
|
||||
ftdm_set_flag(check, FTDM_CHANNEL_INUSE);
|
||||
ftdm_set_flag(check, FTDM_CHANNEL_OUTBOUND);
|
||||
*ftdmchan = check;
|
||||
} else {
|
||||
status = FTDM_SUCCESS;
|
||||
}
|
||||
ftdm_set_flag(check, FTDM_CHANNEL_INUSE);
|
||||
ftdm_set_flag(check, FTDM_CHANNEL_OUTBOUND);
|
||||
*ftdmchan = check;
|
||||
|
||||
unlockchan:
|
||||
ftdm_mutex_unlock(check->mutex);
|
||||
|
||||
done:
|
||||
|
||||
ftdm_mutex_unlock(globals.mutex);
|
||||
if (status != FTDM_SUCCESS) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Failed to open channel %d:%d\n", span_id, chan_id);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
@ -1087,10 +1087,17 @@ static void *ftdm_libpri_run(ftdm_thread_t *me, void *obj)
|
||||
got_d = 1;
|
||||
x++;
|
||||
break;
|
||||
} else {
|
||||
ftdm_log(FTDM_LOG_ERROR, "failed to open d-channel #%d %d:%d\n", x, span->channels[i]->span_id, span->channels[i]->chan_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!got_d) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Failed to get a D-channel in span %d\n", span->span_id);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (lpwrap_init_pri(&isdn_data->spri,
|
||||
@ -1149,7 +1156,7 @@ static void *ftdm_libpri_run(ftdm_thread_t *me, void *obj)
|
||||
ftdm_sleep(5000);
|
||||
}
|
||||
|
||||
ftdm_log(FTDM_LOG_DEBUG, "PRI thread ended on span %d\n", isdn_data->spri.span->span_id);
|
||||
ftdm_log(FTDM_LOG_DEBUG, "PRI thread ended on span %d\n", span->span_id);
|
||||
|
||||
ftdm_clear_flag(span, FTDM_SPAN_IN_THREAD);
|
||||
ftdm_clear_flag(isdn_data, FTMOD_LIBPRI_RUNNING);
|
||||
|
Loading…
Reference in New Issue
Block a user