return FTDM_SUCCESS;
}
+static uint32_t __inline__ rr_next(uint32_t last, uint32_t min, uint32_t max, ftdm_direction_t direction)
+{
+ uint32_t next = min;
+
+ ftdm_log(FTDM_LOG_DEBUG, "last = %d, min = %d, max = %d\n", last, min, max);
+
+ if (direction == FTDM_RR_DOWN) {
+ next = (last >= max) ? min : ++last;
+ } else {
+ next = (last <= min) ? max : --last;
+ }
+ return next;
+}
+
+
FT_DECLARE(int) ftdm_channel_get_availability(ftdm_channel_t *ftdmchan)
{
int availability = -1;
if (direction == FTDM_TOP_DOWN) {
i = 0;
+ } else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) {
+ i = rr_next(group->last_used_index, 0, group->chan_count - 1, direction);
} else {
i = group->chan_count-1;
}
if (request_voice_channel(check, ftdmchan, caller_data, direction)) {
status = FTDM_SUCCESS;
+ if (direction == FTDM_RR_UP || direction == FTDM_RR_DOWN) {
+ group->last_used_index = i;
+ }
break;
}
calculate_best_rate(check, &best_rated, &best_rate);
if (direction == FTDM_TOP_DOWN) {
- if (i >= group->chan_count) {
+ if (i >= (group->chan_count - 1)) {
break;
}
i++;
+ } else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) {
+ if (check == best_rated) {
+ group->last_used_index = i;
+ }
+ i = rr_next(i, 0, group->chan_count - 1, direction);
} else {
if (i == 0) {
break;
if (direction == FTDM_TOP_DOWN) {
i = 1;
+ } else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) {
+ i = rr_next(span->last_used_index, 1, span->chan_count, direction);
} else {
i = span->chan_count;
}
if (i > span->chan_count) {
break;
}
+ } else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) {
+ if (i == span->last_used_index) {
+ break;
+ }
} else {
if (i == 0) {
break;
if (request_voice_channel(check, ftdmchan, caller_data, direction)) {
status = FTDM_SUCCESS;
+ if (direction == FTDM_RR_UP || direction == FTDM_RR_DOWN) {
+ span->last_used_index = i;
+ }
break;
}
if (direction == FTDM_TOP_DOWN) {
i++;
+ } else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) {
+ if (check == best_rated) {
+ span->last_used_index = i;
+ }
+ i = rr_next(i, 1, span->chan_count, direction);
} else {
i--;
}