private void CallLegCompleted()
{
try
{
if (!m_callAnswered && !m_commandCancelled)
{
if (m_switchCalls.Count > 0 || m_delayedCalls.Count > 0)
{
// There are still calls on this leg in progress.
// If there are no current calls then start the next delayed one.
if (m_switchCalls.Count == 0)
{
SIPCallDescriptor nextCall = null;
lock (m_delayedCalls)
{
foreach (SIPCallDescriptor call in m_delayedCalls)
{
if (nextCall == null || nextCall.DelaySeconds > call.DelaySeconds)
{
nextCall = call;
}
}
}
if (nextCall != null)
{
nextCall.DelayMRE.Set();
}
}
}
else if (m_priorityCallsQueue.Count != 0 && !m_callAnswered)
{
List<SIPCallDescriptor> nextPrioritycalls = m_priorityCallsQueue.Dequeue();
Start(nextPrioritycalls);
}
else if (CallFailed != null)
{
// No more call legs to attempt, or call has already been answered or cancelled.
if (m_lastFailureStatus != SIPResponseStatusCodesEnum.None)
{
CallFailed(m_lastFailureStatus, m_lastFailureReason, null);
}
else
{
CallFailed(SIPResponseStatusCodesEnum.TemporarilyUnavailable, "All forwards failed.", null);
}
}
}
}
catch (Exception excp)
{
logger.Error("Exception CallLegCompleted. " + excp);
}
}