fix hunting groups to include only voice channels

git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1010 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
Moises Silva 2010-01-29 19:06:21 +00:00
parent 558ca085de
commit b7b263e1ce
2 changed files with 20 additions and 13 deletions

View File

@ -1121,8 +1121,8 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_dir
ftdm_group_find(group_id, &group); ftdm_group_find(group_id, &group);
} }
if (!group ) { if (!group) {
ftdm_log(FTDM_LOG_CRIT, "GROUP NOT DEFINED!\n"); ftdm_log(FTDM_LOG_ERROR, "Group %d not defined!\n", group_id);
*ftdmchan = NULL; *ftdmchan = NULL;
return FTDM_FAIL; return FTDM_FAIL;
} }
@ -1130,7 +1130,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_dir
ftdm_group_channel_use_count(group, &count); ftdm_group_channel_use_count(group, &count);
if (count >= group->chan_count) { if (count >= group->chan_count) {
ftdm_log(FTDM_LOG_CRIT, "All circuits are busy.\n"); ftdm_log(FTDM_LOG_ERROR, "All circuits are busy (%d channels used out of %d available).\n", count, group->chan_count);
*ftdmchan = NULL; *ftdmchan = NULL;
return FTDM_FAIL; return FTDM_FAIL;
} }
@ -1163,9 +1163,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_dir
!ftdm_test_flag(check, FTDM_CHANNEL_INUSE) && !ftdm_test_flag(check, FTDM_CHANNEL_INUSE) &&
!ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) && !ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) &&
check->state == FTDM_CHANNEL_STATE_DOWN && check->state == FTDM_CHANNEL_STATE_DOWN &&
check->type != FTDM_CHAN_TYPE_DQ921 && FTDM_IS_VOICE_CHANNEL(check)
check->type != FTDM_CHAN_TYPE_DQ931
) { ) {
ftdm_span_t* span = NULL; ftdm_span_t* span = NULL;
ftdm_span_find(check->span_id, &span); ftdm_span_find(check->span_id, &span);
@ -1282,9 +1280,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direc
!ftdm_test_flag(check, FTDM_CHANNEL_INUSE) && !ftdm_test_flag(check, FTDM_CHANNEL_INUSE) &&
!ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) && !ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) &&
check->state == FTDM_CHANNEL_STATE_DOWN && check->state == FTDM_CHANNEL_STATE_DOWN &&
check->type != FTDM_CHAN_TYPE_DQ921 && FTDM_IS_VOICE_CHANNEL(check)
check->type != FTDM_CHAN_TYPE_DQ931
) { ) {
if (span && span->channel_request) { if (span && span->channel_request) {
@ -3189,6 +3185,8 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_add_to_group(const char* name, ftdm_chann
ftdm_mutex_lock(globals.group_mutex); ftdm_mutex_lock(globals.group_mutex);
ftdm_assert_return(ftdmchan != NULL, FTDM_FAIL, "Cannot add a null channel to a group\n");
if (ftdm_group_find_by_name(name, &group) != FTDM_SUCCESS) { if (ftdm_group_find_by_name(name, &group) != FTDM_SUCCESS) {
ftdm_log(FTDM_LOG_DEBUG, "Creating new group:%s\n", name); ftdm_log(FTDM_LOG_DEBUG, "Creating new group:%s\n", name);
ftdm_group_create(&group, name); ftdm_group_create(&group, name);
@ -3200,12 +3198,16 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_add_to_group(const char* name, ftdm_chann
group->channels[i]->physical_chan_id == ftdmchan->physical_chan_id) { group->channels[i]->physical_chan_id == ftdmchan->physical_chan_id) {
ftdm_mutex_unlock(globals.group_mutex); ftdm_mutex_unlock(globals.group_mutex);
ftdm_log(FTDM_LOG_DEBUG, "Channel %d:%d is already added to group %s\n",
group->channels[i]->physical_span_id,
group->channels[i]->physical_chan_id,
name);
return FTDM_SUCCESS; return FTDM_SUCCESS;
} }
} }
if (group->chan_count >= FTDM_MAX_CHANNELS_GROUP) { if (group->chan_count >= FTDM_MAX_CHANNELS_GROUP) {
ftdm_log(FTDM_LOG_CRIT, "Max number of channels exceeded (max:%d)\n", FTDM_MAX_CHANNELS_GROUP); ftdm_log(FTDM_LOG_ERROR, "Max number of channels exceeded (max:%d)\n", FTDM_MAX_CHANNELS_GROUP);
ftdm_mutex_unlock(globals.group_mutex); ftdm_mutex_unlock(globals.group_mutex);
return FTDM_FAIL; return FTDM_FAIL;
} }
@ -3256,9 +3258,12 @@ static ftdm_status_t ftdm_group_add_channels(const char* name, ftdm_span_t* span
return FTDM_SUCCESS; return FTDM_SUCCESS;
} }
for (chan_index = (span->chan_count - currindex); chan_index <= span->chan_count; chan_index++) { for (chan_index = currindex+1; chan_index <= span->chan_count; chan_index++) {
if (!FTDM_IS_VOICE_CHANNEL(span->channels[chan_index])) {
continue;
}
if (ftdm_channel_add_to_group(name, span->channels[chan_index])) { if (ftdm_channel_add_to_group(name, span->channels[chan_index])) {
ftdm_log(FTDM_LOG_CRIT, "Failed to add chan:%d to group:%s\n", chan_index, name); ftdm_log(FTDM_LOG_ERROR, "Failed to add chan:%d to group:%s\n", chan_index, name);
} }
} }
return FTDM_SUCCESS; return FTDM_SUCCESS;
@ -3345,7 +3350,7 @@ FT_DECLARE(ftdm_status_t) ftdm_group_create(ftdm_group_t **group, const char *na
*group = new_group; *group = new_group;
status = FTDM_SUCCESS; status = FTDM_SUCCESS;
} else { } else {
ftdm_log(FTDM_LOG_CRIT, "Group %s was not added, we exceeded the max number of groups\n", name); ftdm_log(FTDM_LOG_ERROR, "Group %s was not added, we exceeded the max number of groups\n", name);
} }
ftdm_mutex_unlock(globals.mutex); ftdm_mutex_unlock(globals.mutex);
return status; return status;

View File

@ -338,6 +338,8 @@ typedef enum {
FTDM_CHAN_TYPE_COUNT FTDM_CHAN_TYPE_COUNT
} ftdm_chan_type_t; } ftdm_chan_type_t;
#define FTDM_IS_VOICE_CHANNEL(ftdm_chan) ((ftdm_chan)->type != FTDM_CHAN_TYPE_DQ921 && (ftdm_chan)->type != FTDM_CHAN_TYPE_DQ931)
#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "INVALID" #define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "INVALID"
FTDM_STR2ENUM_P(ftdm_str2ftdm_chan_type, ftdm_chan_type2str, ftdm_chan_type_t) FTDM_STR2ENUM_P(ftdm_str2ftdm_chan_type, ftdm_chan_type2str, ftdm_chan_type_t)