ZAP_COMMAND_FLUSH_RX_BUFFERS,
ZAP_COMMAND_FLUSH_BUFFERS,
ZAP_COMMAND_SET_PRE_BUFFER_SIZE,
+ ZAP_COMMAND_ENABLE_LOOP,
+ ZAP_COMMAND_DISABLE_LOOP,
ZAP_COMMAND_COUNT
} zap_command_t;
ZAP_CHANNEL_STATE_CANCEL,
ZAP_CHANNEL_STATE_HANGUP,
ZAP_CHANNEL_STATE_HANGUP_COMPLETE,
+ ZAP_CHANNEL_STATE_IN_LOOP,
ZAP_CHANNEL_STATE_INVALID
} zap_channel_state_t;
#define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \
}
+static void handle_call_loop_start(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
+{
+ zap_status_t res = ZAP_FAIL;
+ zap_channel_t *zchan;
+
+ if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) {
+ zap_log(ZAP_LOG_CRIT, "CANNOT START LOOP, CHAN NOT AVAILABLE %d:%d\n", event->span+1,event->chan+1);
+ return;
+ }
+
+ if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
+ zap_log(ZAP_LOG_CRIT, "CANNOT START LOOP, CANT OPEN CHAN %d:%d\n", event->span+1,event->chan+1);
+ return;
+ }
+
+ zap_set_state_r(zchan, ZAP_CHANNEL_STATE_IN_LOOP, 0, res);
+ if (res != ZAP_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);
+ /* FIXME: do we need to send an error? */
+ return;
+ }
+ zap_channel_command(zchan, ZAP_COMMAND_ENABLE_LOOP, NULL);
+}
+
+static void handle_call_loop_stop(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
+{
+ zap_channel_t *zchan;
+ zap_status_t res = ZAP_FAIL;
+ if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 1))) {
+ zap_log(ZAP_LOG_CRIT, "CANNOT STOP LOOP, INVALID CHAN REQUESTED %d:%d\n", event->span+1,event->chan+1);
+ return;
+ }
+ if (zchan->state != ZAP_CHANNEL_STATE_IN_LOOP) {
+ zap_log(ZAP_LOG_ERROR, "Got stop loop request in a channel that is not in loop, ignoring ...\n");
+ /* FIXME: do we need to send an error? */
+ return;
+ }
+ zap_channel_command(zchan, ZAP_COMMAND_DISABLE_LOOP, NULL);
+ zap_set_state_r(zchan, ZAP_CHANNEL_STATE_DOWN, 0, res);
+}
+
/**
* \brief Handler for heartbeat event
* \param mcon sangoma boost connection
nack_map[event->call_setup_id] = 0;
break;
case SIGBOOST_EVENT_INSERT_CHECK_LOOP:
- //handle_call_loop_start(event);
+ handle_call_loop_start(span, mcon, event);
break;
case SIGBOOST_EVENT_REMOVE_CHECK_LOOP:
- //handle_call_stop(event);
+ handle_call_loop_stop(span, mcon, event);
break;
case SIGBOOST_EVENT_SYSTEM_RESTART_ACK:
handle_restart_ack(mcon, span, event);
status = zap_span_send_signal(zchan->span, &sig);
}
break;
+ case ZAP_CHANNEL_STATE_IN_LOOP:
+ {
+ /* nothing to do, we sent the ZAP_COMMAND_ENABLE_LOOP command in handle_call_loop_start() right away */
+ }
+ break;
default:
break;
}
{ZAP_CHANNEL_STATE_RESTART, ZAP_END},
{ZAP_CHANNEL_STATE_DOWN, ZAP_END}
},
+ {
+ ZSD_INBOUND,
+ ZSM_UNACCEPTABLE,
+ {ZAP_CHANNEL_STATE_DOWN},
+ {ZAP_CHANNEL_STATE_IN_LOOP, ZAP_END}
+ },
+ {
+ ZSD_INBOUND,
+ ZSM_UNACCEPTABLE,
+ {ZAP_CHANNEL_STATE_IN_LOOP},
+ {ZAP_CHANNEL_STATE_DOWN, ZAP_END}
+ },
{
ZSD_INBOUND,
ZSM_UNACCEPTABLE,