int icd_bridge_wait_ack(icd_caller * that)
{
struct ast_channel *chan = (ast_channel *) icd_caller__get_channel(that);
//int max_wait_ack = 10; /* TBD stick this in the agent config */
int max_wait_ack = icd_caller__get_timeout(that);
int result = 0;
int res = 0;
time_t start_time;
time_t now;
if (icd_debug) ast_log(LOG_DEBUG, "ICD Agent waiting for acknowledgment is ID %d\n", icd_caller__get_id(that));
time(&start_time);
for (;;) {
/* This is the wait loop for agents that requirement an acknowledgement b4 we bridge the call */
for (;;) {
if (!(icd_caller__get_state(that) == ICD_CALLER_STATE_GET_CHANNELS_AND_BRIDGE)) {
result = -1;
break;
}
/* Wait a second before checking again */
res = ast_waitfordigit(chan, 1000);
if (res) {
break;
}
time(&now);
if ((now - start_time) > max_wait_ack){
result = -1;
break;
}
}
if (result < 0) {
icd_caller__set_state(that, ICD_CALLER_STATE_BRIDGE_FAILED);
break;
}
/* If they hungup, return immediately */
if (res < 0) {
icd_caller__set_state(that, ICD_CALLER_STATE_BRIDGE_FAILED);
break;
}
break;
}
return res;
}