OPENZAP-226 --resolve Hunting direction is reversed in the API
Minor modifications on the original patch to use ftdm_hunting_direction_t everywhere instead of ftdm_direction_t or int Patched-by: Marc Olivier Chouinard
This commit is contained in:
parent
7d4c1aff81
commit
b6133ecc95
|
@ -1291,7 +1291,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
|||
int span_id = -1, group_id = -1, chan_id = 0;
|
||||
switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
||||
ftdm_status_t status;
|
||||
int direction = FTDM_TOP_DOWN;
|
||||
ftdm_hunt_direction_t direction = FTDM_HUNT_BOTTOM_UP;
|
||||
ftdm_caller_data_t caller_data = {{ 0 }};
|
||||
char *span_name = NULL;
|
||||
switch_event_header_t *h;
|
||||
|
@ -1348,14 +1348,14 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
|||
span_name = argv[0];
|
||||
}
|
||||
|
||||
if (*argv[1] == 'A') {
|
||||
direction = FTDM_BOTTOM_UP;
|
||||
} else if (*argv[1] == 'a') {
|
||||
direction = FTDM_TOP_DOWN;
|
||||
} else if (*argv[1] == 'r') {
|
||||
direction = FTDM_RR_DOWN;
|
||||
if (*argv[1] == 'a') {
|
||||
direction = FTDM_HUNT_BOTTOM_UP;
|
||||
} else if (*argv[1] == 'A') {
|
||||
direction = FTDM_HUNT_TOP_DOWN;
|
||||
} else if (*argv[1] == 'R') {
|
||||
direction = FTDM_RR_UP;
|
||||
direction = FTDM_HUNT_RR_DOWN;
|
||||
} else if (*argv[1] == 'r') {
|
||||
direction = FTDM_HUNT_RR_UP;
|
||||
} else {
|
||||
chan_id = atoi(argv[1]);
|
||||
}
|
||||
|
@ -1390,7 +1390,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
|||
}
|
||||
|
||||
if (group_id < 0 && chan_id < 0) {
|
||||
direction = FTDM_BOTTOM_UP;
|
||||
direction = FTDM_HUNT_BOTTOM_UP;
|
||||
chan_id = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1502,7 +1502,7 @@ static __inline__ int chan_voice_is_avail(ftdm_channel_t *check)
|
|||
}
|
||||
|
||||
static __inline__ int request_voice_channel(ftdm_channel_t *check, ftdm_channel_t **ftdmchan,
|
||||
ftdm_caller_data_t *caller_data, ftdm_direction_t direction)
|
||||
ftdm_caller_data_t *caller_data, ftdm_hunt_direction_t direction)
|
||||
{
|
||||
ftdm_status_t status;
|
||||
if (chan_voice_is_avail(check)) {
|
||||
|
@ -1589,13 +1589,13 @@ static ftdm_status_t __inline__ get_best_rated(ftdm_channel_t **fchan, ftdm_chan
|
|||
return FTDM_SUCCESS;
|
||||
}
|
||||
|
||||
static uint32_t __inline__ rr_next(uint32_t last, uint32_t min, uint32_t max, ftdm_direction_t direction)
|
||||
static uint32_t __inline__ rr_next(uint32_t last, uint32_t min, uint32_t max, ftdm_hunt_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) {
|
||||
if (direction == FTDM_HUNT_RR_UP) {
|
||||
next = (last >= max) ? min : ++last;
|
||||
} else {
|
||||
next = (last <= min) ? max : --last;
|
||||
|
@ -1615,7 +1615,7 @@ FT_DECLARE(int) ftdm_channel_get_availability(ftdm_channel_t *ftdmchan)
|
|||
return availability;
|
||||
}
|
||||
|
||||
static ftdm_status_t _ftdm_channel_open_by_group(uint32_t group_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan)
|
||||
static ftdm_status_t _ftdm_channel_open_by_group(uint32_t group_id, ftdm_hunt_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan)
|
||||
{
|
||||
ftdm_status_t status = FTDM_FAIL;
|
||||
ftdm_channel_t *check = NULL;
|
||||
|
@ -1645,9 +1645,9 @@ static ftdm_status_t _ftdm_channel_open_by_group(uint32_t group_id, ftdm_directi
|
|||
}
|
||||
|
||||
|
||||
if (direction == FTDM_TOP_DOWN) {
|
||||
if (direction == FTDM_HUNT_BOTTOM_UP) {
|
||||
i = 0;
|
||||
} else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) {
|
||||
} else if (direction == FTDM_HUNT_RR_DOWN || direction == FTDM_HUNT_RR_UP) {
|
||||
i = rr_next(group->last_used_index, 0, group->chan_count - 1, direction);
|
||||
first_channel = i;
|
||||
} else {
|
||||
|
@ -1664,7 +1664,7 @@ static ftdm_status_t _ftdm_channel_open_by_group(uint32_t group_id, ftdm_directi
|
|||
|
||||
if (request_voice_channel(check, ftdmchan, caller_data, direction)) {
|
||||
status = FTDM_SUCCESS;
|
||||
if (direction == FTDM_RR_UP || direction == FTDM_RR_DOWN) {
|
||||
if (direction == FTDM_HUNT_RR_UP || direction == FTDM_HUNT_RR_DOWN) {
|
||||
group->last_used_index = i;
|
||||
}
|
||||
break;
|
||||
|
@ -1672,12 +1672,12 @@ static ftdm_status_t _ftdm_channel_open_by_group(uint32_t group_id, ftdm_directi
|
|||
|
||||
calculate_best_rate(check, &best_rated, &best_rate);
|
||||
|
||||
if (direction == FTDM_TOP_DOWN) {
|
||||
if (direction == FTDM_HUNT_BOTTOM_UP) {
|
||||
if (i >= (group->chan_count - 1)) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
} else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) {
|
||||
} else if (direction == FTDM_HUNT_RR_DOWN || direction == FTDM_HUNT_RR_UP) {
|
||||
if (check == best_rated) {
|
||||
group->last_used_index = i;
|
||||
}
|
||||
|
@ -1701,7 +1701,7 @@ static ftdm_status_t _ftdm_channel_open_by_group(uint32_t group_id, ftdm_directi
|
|||
return status;
|
||||
}
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_hunt_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan)
|
||||
{
|
||||
ftdm_status_t status;
|
||||
status = _ftdm_channel_open_by_group(group_id, direction, caller_data, ftdmchan);
|
||||
|
@ -1734,7 +1734,7 @@ FT_DECLARE(ftdm_status_t) ftdm_span_channel_use_count(ftdm_span_t *span, uint32_
|
|||
}
|
||||
|
||||
/* Hunt a channel by span, if successful the channel is returned locked */
|
||||
static ftdm_status_t _ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan)
|
||||
static ftdm_status_t _ftdm_channel_open_by_span(uint32_t span_id, ftdm_hunt_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan)
|
||||
{
|
||||
ftdm_status_t status = FTDM_FAIL;
|
||||
ftdm_channel_t *check = NULL;
|
||||
|
@ -1773,9 +1773,9 @@ static ftdm_status_t _ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction
|
|||
|
||||
ftdm_mutex_lock(span->mutex);
|
||||
|
||||
if (direction == FTDM_TOP_DOWN) {
|
||||
if (direction == FTDM_HUNT_BOTTOM_UP) {
|
||||
i = 1;
|
||||
} else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) {
|
||||
} else if (direction == FTDM_HUNT_RR_DOWN || direction == FTDM_HUNT_RR_UP) {
|
||||
i = rr_next(span->last_used_index, 1, span->chan_count, direction);
|
||||
first_channel = i;
|
||||
} else {
|
||||
|
@ -1784,7 +1784,7 @@ static ftdm_status_t _ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction
|
|||
|
||||
for(;;) {
|
||||
|
||||
if (direction == FTDM_TOP_DOWN) {
|
||||
if (direction == FTDM_HUNT_BOTTOM_UP) {
|
||||
if (i > span->chan_count) {
|
||||
break;
|
||||
}
|
||||
|
@ -1801,7 +1801,7 @@ static ftdm_status_t _ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction
|
|||
|
||||
if (request_voice_channel(check, ftdmchan, caller_data, direction)) {
|
||||
status = FTDM_SUCCESS;
|
||||
if (direction == FTDM_RR_UP || direction == FTDM_RR_DOWN) {
|
||||
if (direction == FTDM_HUNT_RR_UP || direction == FTDM_HUNT_RR_DOWN) {
|
||||
span->last_used_index = i;
|
||||
}
|
||||
break;
|
||||
|
@ -1809,9 +1809,9 @@ static ftdm_status_t _ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction
|
|||
|
||||
calculate_best_rate(check, &best_rated, &best_rate);
|
||||
|
||||
if (direction == FTDM_TOP_DOWN) {
|
||||
if (direction == FTDM_HUNT_BOTTOM_UP) {
|
||||
i++;
|
||||
} else if (direction == FTDM_RR_DOWN || direction == FTDM_RR_UP) {
|
||||
} else if (direction == FTDM_HUNT_RR_DOWN || direction == FTDM_HUNT_RR_UP) {
|
||||
if (check == best_rated) {
|
||||
span->last_used_index = i;
|
||||
}
|
||||
|
@ -1833,7 +1833,7 @@ static ftdm_status_t _ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction
|
|||
return status;
|
||||
}
|
||||
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan)
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_hunt_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan)
|
||||
{
|
||||
ftdm_status_t status;
|
||||
status = _ftdm_channel_open_by_span(span_id, direction, caller_data, ftdmchan);
|
||||
|
|
|
@ -166,10 +166,21 @@ typedef enum {
|
|||
|
||||
/*! \brief Hunting direction (when hunting for free channels) */
|
||||
typedef enum {
|
||||
FTDM_TOP_DOWN,
|
||||
FTDM_HUNT_TOP_DOWN,
|
||||
FTDM_HUNT_BOTTOM_UP,
|
||||
FTDM_HUNT_RR_DOWN,
|
||||
FTDM_HUNT_RR_UP,
|
||||
} ftdm_hunt_direction_t;
|
||||
|
||||
/*! \brief Legacy Hunting direction (Top down and Bottom up were reversed), keep for source backwards compatibility of freetdm user applications
|
||||
* \deprecated
|
||||
* \see ftdm_hunt_direction_t
|
||||
*/
|
||||
typedef enum {
|
||||
FTDM_BOTTOM_UP,
|
||||
FTDM_RR_DOWN,
|
||||
FTDM_TOP_DOWN,
|
||||
FTDM_RR_UP,
|
||||
FTDM_RR_DOWN,
|
||||
} ftdm_direction_t;
|
||||
|
||||
/*! \brief I/O channel type */
|
||||
|
@ -404,13 +415,13 @@ typedef enum {
|
|||
/*! \brief Structure used for FTDM_HUNT_SPAN mode */
|
||||
typedef struct {
|
||||
uint32_t span_id;
|
||||
ftdm_direction_t direction;
|
||||
ftdm_hunt_direction_t direction;
|
||||
} ftdm_span_hunt_t;
|
||||
|
||||
/*! \brief Structure used for FTDM_HUNT_GROUP mode */
|
||||
typedef struct {
|
||||
uint32_t group_id;
|
||||
ftdm_direction_t direction;
|
||||
ftdm_hunt_direction_t direction;
|
||||
} ftdm_group_hunt_t;
|
||||
|
||||
/*! \brief Structure used for FTDM_HUNT_CHAN mode */
|
||||
|
@ -781,7 +792,7 @@ struct ftdm_memory_handler {
|
|||
|
||||
/*! \brief FreeTDM I/O layer interface argument macros
|
||||
* You don't need these unless your implementing an I/O interface module (most users don't) */
|
||||
#define FIO_CHANNEL_REQUEST_ARGS (ftdm_span_t *span, uint32_t chan_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan)
|
||||
#define FIO_CHANNEL_REQUEST_ARGS (ftdm_span_t *span, uint32_t chan_id, ftdm_hunt_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan)
|
||||
#define FIO_CHANNEL_OUTGOING_CALL_ARGS (ftdm_channel_t *ftdmchan)
|
||||
#define FIO_CHANNEL_INDICATE_ARGS (ftdm_channel_t *ftdmchan, ftdm_channel_indication_t indication)
|
||||
#define FIO_CHANNEL_SET_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t status)
|
||||
|
@ -1440,7 +1451,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_ph(uint32_t span_id, uint32_t chan_i
|
|||
* \retval FTDM_SUCCESS success (a suitable channel was found available)
|
||||
* \retval FTDM_FAIL failure (no suitable channel was found available)
|
||||
*/
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_hunt_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan);
|
||||
|
||||
/*!
|
||||
* \brief Hunts and opens a channel specifying group id
|
||||
|
@ -1458,7 +1469,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direc
|
|||
* \retval FTDM_SUCCESS success (a suitable channel was found available)
|
||||
* \retval FTDM_FAIL failure (no suitable channel was found available)
|
||||
*/
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan);
|
||||
FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_hunt_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan);
|
||||
|
||||
/*!
|
||||
* \brief Close a previously open channel
|
||||
|
|
|
@ -21,7 +21,7 @@ int main(int argc, char *argv[])
|
|||
printf("FreeTDM loaded\n");
|
||||
|
||||
top:
|
||||
//if (ftdm_channel_open_any("wanpipe", 0, FTDM_TOP_DOWN, &chan) == FTDM_SUCCESS) {
|
||||
//if (ftdm_channel_open_any("wanpipe", 0, FTDM_HUNT_BOTTOM_UP, &chan) == FTDM_SUCCESS) {
|
||||
if (ftdm_channel_open(1, 1, &chan) == FTDM_SUCCESS) {
|
||||
int x = 0;
|
||||
spanid = ftdm_channel_get_span_id(chan);
|
||||
|
|
Loading…
Reference in New Issue