From 2640812649a0031d49f5ff55254d0d7f7fd9a8db Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Fri, 2 Mar 2012 19:06:07 -0500 Subject: [PATCH] call: push answer logic into call classes --- daemon/src/call.h | 2 ++ daemon/src/iax/iaxcall.cpp | 8 ++++++ daemon/src/iax/iaxcall.h | 1 + daemon/src/iax/iaxvoiplink.cpp | 6 ++--- daemon/src/managerimpl.cpp | 2 +- daemon/src/sip/sipcall.cpp | 13 +++++++++ daemon/src/sip/sipcall.h | 1 + daemon/src/sip/sipvoiplink.cpp | 49 +++++++++++----------------------- 8 files changed, 44 insertions(+), 38 deletions(-) diff --git a/daemon/src/call.h b/daemon/src/call.h index da702a7e31..b6d4ce59c6 100644 --- a/daemon/src/call.h +++ b/daemon/src/call.h @@ -174,6 +174,8 @@ class Call : public Recordable { isIPToIP_ = IPToIP; } + virtual void answer() = 0; + /** * Set my IP [not protected] * @param ip The local IP address diff --git a/daemon/src/iax/iaxcall.cpp b/daemon/src/iax/iaxcall.cpp index a1eb21ec93..2b09b4944f 100644 --- a/daemon/src/iax/iaxcall.cpp +++ b/daemon/src/iax/iaxcall.cpp @@ -29,6 +29,9 @@ * as that of the covered work. */ +#include <cstring> +#include <sys/socket.h> +#include <iax-client.h> #include "iaxcall.h" #include "iax2/frame.h" #include "account.h" @@ -115,3 +118,8 @@ int IAXCall::getAudioCodec() const return -1; } } + +void IAXCall::answer() +{ + iax_answer(session); +} diff --git a/daemon/src/iax/iaxcall.h b/daemon/src/iax/iaxcall.h index b282252039..d97b838d35 100644 --- a/daemon/src/iax/iaxcall.h +++ b/daemon/src/iax/iaxcall.h @@ -74,6 +74,7 @@ class IAXCall : public Call { int format; iax_session* session; private: + virtual void answer(); NON_COPYABLE(IAXCall); }; diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index 1b4cf25c76..17b11d52a8 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -255,14 +255,12 @@ IAXVoIPLink::newOutgoingCall(const std::string& id, const std::string& toUrl) void -IAXVoIPLink::answer(Call *c) +IAXVoIPLink::answer(Call *call) { - IAXCall* call = dynamic_cast<IAXCall*>(c); - Manager::instance().addStream(call->getCallId()); mutexIAX_.enter(); - iax_answer(call->session); + call->answer(); mutexIAX_.leave(); call->setState(Call::ACTIVE); diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 7ace5bc58a..4c1e8cbc4f 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -292,7 +292,7 @@ bool ManagerImpl::answerCall(const std::string& call_id) try { getAccountLink(account_id)->answer(call); - } catch (const VoipLinkException &e) { + } catch (const std::runtime_error &e) { ERROR("Manager: Error: %s", e.what()); } diff --git a/daemon/src/sip/sipcall.cpp b/daemon/src/sip/sipcall.cpp index dd31f3bdc3..9c5c9d5840 100644 --- a/daemon/src/sip/sipcall.cpp +++ b/daemon/src/sip/sipcall.cpp @@ -53,3 +53,16 @@ SIPCall::~SIPCall() delete local_sdp_; pj_pool_release(pool_); } + +void SIPCall::answer() +{ + pjsip_tx_data *tdata; + if (pjsip_inv_answer(inv, PJSIP_SC_OK, NULL, NULL, &tdata) != PJ_SUCCESS) + throw std::runtime_error("Could not init invite request answer (200 OK)"); + + if (pjsip_inv_send_msg(inv, tdata) != PJ_SUCCESS) + throw std::runtime_error("Could not send invite request answer (200 OK)"); + + setConnectionState(CONNECTED); + setState(ACTIVE); +} diff --git a/daemon/src/sip/sipcall.h b/daemon/src/sip/sipcall.h index dab99795a7..249d3b7976 100644 --- a/daemon/src/sip/sipcall.h +++ b/daemon/src/sip/sipcall.h @@ -89,6 +89,7 @@ class SIPCall : public Call { pjsip_inv_session *inv; private: + virtual void answer(); NON_COPYABLE(SIPCall); diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 9415cbe46f..dfd8f6a503 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -651,29 +651,24 @@ void SIPVoIPLink::sendUnregister(Account *a) account->setRegister(false); } -void SIPVoIPLink::registerKeepAliveTimer(pj_timer_entry& timer, pj_time_val& delay) +void SIPVoIPLink::registerKeepAliveTimer(pj_timer_entry &timer, pj_time_val &delay) { - pj_status_t status; - - DEBUG("UserAgent: Registering keep alive timer"); - - if(timer.id == -1) { + if (timer.id == -1) WARN("UserAgent: Timer already scheduled"); - } - - status = pjsip_endpt_schedule_timer(endpt_, &timer, &delay); - if (status != PJ_SUCCESS) { - ERROR("UserAgent: Could not schedule new timer in pjsip endpoint"); - } - if(status == PJ_EINVAL) { - ERROR("UserAgent: Invalid timer or delay entry"); - } - - if(status == PJ_EINVALIDOP) { - ERROR("Invalid timer entry, maybe already scheduled"); + switch (pjsip_endpt_schedule_timer(endpt_, &timer, &delay)) { + case PJ_SUCCESS: + break; + default: + ERROR("UserAgent: Could not schedule new timer in pjsip endpoint"); + /* fallthrough */ + case PJ_EINVAL: + ERROR("UserAgent: Invalid timer or delay entry"); + break; + case PJ_EINVALIDOP: + ERROR("Invalid timer entry, maybe already scheduled"); + break; } - } void SIPVoIPLink::cancelKeepAliveTimer(pj_timer_entry& timer) @@ -749,23 +744,11 @@ Call *SIPVoIPLink::newOutgoingCall(const std::string& id, const std::string& toU } void -SIPVoIPLink::answer(Call *c) +SIPVoIPLink::answer(Call *call) { - SIPCall *call = dynamic_cast<SIPCall*>(c); - if (!call) return; - - pjsip_tx_data *tdata; - - if (pjsip_inv_answer(call->inv, PJSIP_SC_OK, NULL, NULL, &tdata) != PJ_SUCCESS) - throw VoipLinkException("Could not init invite request answer (200 OK)"); - - if (pjsip_inv_send_msg(call->inv, tdata) != PJ_SUCCESS) - throw VoipLinkException("Could not send invite request answer (200 OK)"); - - call->setConnectionState(Call::CONNECTED); - call->setState(Call::ACTIVE); + call->answer(); } void -- GitLab