def serve(io)
begin
call = Adhearsion.receive_call_from io
ahn_log.agi "Handling call with variables #{call.variables.inspect}"
dialplan_manager = Adhearsion::DialPlan::Manager.new
dialplan_manager.handle call
rescue Adhearsion::DialPlan::Manager::NoContextError => e
ahn_log.agi e.message
call.hangup!
rescue Adhearsion::FailedExtensionCallException => failed_call
begin
ahn_log.agi "Received \"failed\" meta-call with :failed_reason => #{failed_call.call.failed_reason.inspect}. Executing OnFailedCall hooks."
Adhearsion::Hooks::OnFailedCall.trigger_hooks(failed_call.call)
call.hangup!
rescue => e
p e
end
rescue Adhearsion::UselessCallException
ahn_log.agi "Ignoring meta-AGI request"
call.hangup!
rescue => e
ahn_log.agi.error e.inspect
ahn_log.agi.error e.backtrace.map { |s| " " * 5 + s }.join("\n")
end
end