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 {
isIPToIP_ = IPToIP;
}
virtual void answer() = 0;
/**
* Set my IP [not protected]
* @param ip The local IP address
......
......@@ -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);
}
......@@ -74,6 +74,7 @@ class IAXCall : public Call {
int format;
iax_session* session;
private:
virtual void answer();
NON_COPYABLE(IAXCall);
};
......
......@@ -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);
......
......@@ -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());
}
......
......@@ -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);
}
......@@ -89,6 +89,7 @@ class SIPCall : public Call {
pjsip_inv_session *inv;
private:
virtual void answer();
NON_COPYABLE(SIPCall);
......
......@@ -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
......
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