提交 23766e36 authored 作者: Moises Silva's avatar Moises Silva

openzap: handle loop requests

上级 5bdf8bcc
......@@ -360,7 +360,8 @@ typedef enum {
} zap_channel_state_t;
#define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \
"RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \
"RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "CANCEL", "HANGUP", "HANGUP_COMPLETE", "INVALID"
"RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "CANCEL", \
"HANGUP", "HANGUP_COMPLETE", "IN_LOOP", "INVALID"
ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t)
typedef enum {
......
......@@ -903,11 +903,12 @@ static void handle_call_loop_start(zap_span_t *span, sangomabc_connection_t *mco
}
zap_set_state_r(zchan, ZAP_CHANNEL_STATE_IN_LOOP, 0, res);
if (res != ZAP_SUCCESS) {
if (res != ZAP_STATE_CHANGE_SUCCESS) {
zap_log(ZAP_LOG_CRIT, "yay, could not set the state of the channel to IN_LOOP, loop will fail\n");
zap_channel_done(zchan);
return;
}
zap_log(ZAP_LOG_DEBUG, "%d:%d starting loop\n", zchan->span_id, zchan->chan_id);
zap_channel_command(zchan, ZAP_COMMAND_ENABLE_LOOP, NULL);
}
......@@ -927,6 +928,9 @@ static void handle_call_loop_stop(zap_span_t *span, sangomabc_connection_t *mcon
/* even when we did not sent a msg we set this flag to avoid sending call stop in the DOWN state handler */
zap_set_flag(zchan, SFLAG_SENT_FINAL_MSG);
zap_set_state_r(zchan, ZAP_CHANNEL_STATE_DOWN, 0, res);
if (res != ZAP_STATE_CHANGE_SUCCESS) {
zap_log(ZAP_LOG_CRIT, "yay, could not set the state of the channel from IN_LOOP to DOWN\n");
}
}
/**
......@@ -1163,33 +1167,35 @@ static __inline__ void state_advance(zap_channel_t *zchan)
switch (zchan->state) {
case ZAP_CHANNEL_STATE_DOWN:
{
/* Always try to clear the GRID */
release_request_id_span_chan(zchan->physical_span_id-1, zchan->physical_chan_id-1);
if (!zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) {
zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG);
if (zchan->call_data && ((uint32_t)(intptr_t)zchan->call_data == SIGBOOST_EVENT_CALL_START_NACK)) {
sangomabc_exec_command(mcon,
zchan->physical_span_id-1,
zchan->physical_chan_id-1,
0,
SIGBOOST_EVENT_CALL_START_NACK_ACK,
0, 0);
} else {
sangomabc_exec_command(mcon,
zchan->physical_span_id-1,
zchan->physical_chan_id-1,
0,
SIGBOOST_EVENT_CALL_STOPPED_ACK,
0, 0);
if (zchan->last_state == ZAP_CHANNEL_STATE_IN_LOOP) {
/* nothing to do after a loop */
zap_log(ZAP_LOG_DEBUG, "%d:%d terminating loop\n", zchan->span_id, zchan->chan_id);
} else {
/* Always try to clear the GRID */
release_request_id_span_chan(zchan->physical_span_id-1, zchan->physical_chan_id-1);
if (!zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) {
zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG);
if (zchan->call_data && ((uint32_t)(intptr_t)zchan->call_data == SIGBOOST_EVENT_CALL_START_NACK)) {
sangomabc_exec_command(mcon,
zchan->physical_span_id-1,
zchan->physical_chan_id-1,
0,
SIGBOOST_EVENT_CALL_START_NACK_ACK,
0, 0);
} else {
sangomabc_exec_command(mcon,
zchan->physical_span_id-1,
zchan->physical_chan_id-1,
0,
SIGBOOST_EVENT_CALL_STOPPED_ACK,
0, 0);
}
}
}
if (zchan->extra_id) {
zchan->extra_id = 0;
}
}
zchan->extra_id = 0;
zchan->sflags = 0;
zchan->call_data = NULL;
zap_channel_done(zchan);
......
......@@ -609,6 +609,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command)
}
#endif
}
break;
case ZAP_COMMAND_DISABLE_LOOP:
{
#ifdef WP_API_FEATURE_LOOP
......@@ -619,6 +620,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command)
}
#endif
}
break;
case ZAP_COMMAND_SET_INTERVAL:
{
err=sangoma_tdm_set_usr_period(zchan->sockfd, &tdm_api, ZAP_COMMAND_OBJ_INT);
......
......@@ -948,11 +948,15 @@ OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel
int ok = 1;
if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) {
zap_log(ZAP_LOG_ERROR, "%d:%d Cannot set state in channel that is not ready\n",
zchan->span_id, zchan->chan_id);
return ZAP_FAIL;
}
if (zap_test_flag(zchan->span, ZAP_SPAN_SUSPENDED)) {
if (state != ZAP_CHANNEL_STATE_RESTART && state != ZAP_CHANNEL_STATE_DOWN) {
zap_log(ZAP_LOG_ERROR, "%d:%d Cannot set state in channel that is suspended\n",
zchan->span_id, zchan->chan_id);
return ZAP_FAIL;
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论