Commit 26408126 authored by Tristan Matthews's avatar Tristan Matthews

call: push answer logic into call classes

parent eed62d3a
...@@ -174,6 +174,8 @@ class Call : public Recordable { ...@@ -174,6 +174,8 @@ class Call : public Recordable {
isIPToIP_ = IPToIP; isIPToIP_ = IPToIP;
} }
virtual void answer() = 0;
/** /**
* Set my IP [not protected] * Set my IP [not protected]
* @param ip The local IP address * @param ip The local IP address
......
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
* as that of the covered work. * as that of the covered work.
*/ */
#include <cstring>
#include <sys/socket.h>
#include <iax-client.h>
#include "iaxcall.h" #include "iaxcall.h"
#include "iax2/frame.h" #include "iax2/frame.h"
#include "account.h" #include "account.h"
...@@ -115,3 +118,8 @@ int IAXCall::getAudioCodec() const ...@@ -115,3 +118,8 @@ int IAXCall::getAudioCodec() const
return -1; return -1;
} }
} }
void IAXCall::answer()
{
iax_answer(session);
}
...@@ -74,6 +74,7 @@ class IAXCall : public Call { ...@@ -74,6 +74,7 @@ class IAXCall : public Call {
int format; int format;
iax_session* session; iax_session* session;
private: private:
virtual void answer();
NON_COPYABLE(IAXCall); NON_COPYABLE(IAXCall);
}; };
......
...@@ -255,14 +255,12 @@ IAXVoIPLink::newOutgoingCall(const std::string& id, const std::string& toUrl) ...@@ -255,14 +255,12 @@ IAXVoIPLink::newOutgoingCall(const std::string& id, const std::string& toUrl)
void void
IAXVoIPLink::answer(Call *c) IAXVoIPLink::answer(Call *call)
{ {
IAXCall* call = dynamic_cast<IAXCall*>(c);
Manager::instance().addStream(call->getCallId()); Manager::instance().addStream(call->getCallId());
mutexIAX_.enter(); mutexIAX_.enter();
iax_answer(call->session); call->answer();
mutexIAX_.leave(); mutexIAX_.leave();
call->setState(Call::ACTIVE); call->setState(Call::ACTIVE);
......
...@@ -292,7 +292,7 @@ bool ManagerImpl::answerCall(const std::string& call_id) ...@@ -292,7 +292,7 @@ bool ManagerImpl::answerCall(const std::string& call_id)
try { try {
getAccountLink(account_id)->answer(call); getAccountLink(account_id)->answer(call);
} catch (const VoipLinkException &e) { } catch (const std::runtime_error &e) {
ERROR("Manager: Error: %s", e.what()); ERROR("Manager: Error: %s", e.what());
} }
......
...@@ -53,3 +53,16 @@ SIPCall::~SIPCall() ...@@ -53,3 +53,16 @@ SIPCall::~SIPCall()
delete local_sdp_; delete local_sdp_;
pj_pool_release(pool_); 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);
}
...@@ -89,6 +89,7 @@ class SIPCall : public Call { ...@@ -89,6 +89,7 @@ class SIPCall : public Call {
pjsip_inv_session *inv; pjsip_inv_session *inv;
private: private:
virtual void answer();
NON_COPYABLE(SIPCall); NON_COPYABLE(SIPCall);
......
...@@ -651,29 +651,24 @@ void SIPVoIPLink::sendUnregister(Account *a) ...@@ -651,29 +651,24 @@ void SIPVoIPLink::sendUnregister(Account *a)
account->setRegister(false); 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; if (timer.id == -1)
DEBUG("UserAgent: Registering keep alive timer");
if(timer.id == -1) {
WARN("UserAgent: Timer already scheduled"); 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) { switch (pjsip_endpt_schedule_timer(endpt_, &timer, &delay)) {
ERROR("UserAgent: Invalid timer or delay entry"); case PJ_SUCCESS:
} break;
default:
if(status == PJ_EINVALIDOP) { ERROR("UserAgent: Could not schedule new timer in pjsip endpoint");
ERROR("Invalid timer entry, maybe already scheduled"); /* 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) void SIPVoIPLink::cancelKeepAliveTimer(pj_timer_entry& timer)
...@@ -749,23 +744,11 @@ Call *SIPVoIPLink::newOutgoingCall(const std::string& id, const std::string& toU ...@@ -749,23 +744,11 @@ Call *SIPVoIPLink::newOutgoingCall(const std::string& id, const std::string& toU
} }
void void
SIPVoIPLink::answer(Call *c) SIPVoIPLink::answer(Call *call)
{ {
SIPCall *call = dynamic_cast<SIPCall*>(c);
if (!call) if (!call)
return; return;
call->answer();
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);
} }
void void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment