Commit 8bad0be4 authored by Guillaume Roguez's avatar Guillaume Roguez

daemon: move refuse API to Call class

Refs #51555

Change-Id: I6e215358bb880b7c7c18c4611c502e8d7f943da0
parent 45062c37
......@@ -248,6 +248,11 @@ class Call : public Recordable {
*/
virtual void hangup(int reason) = 0;
/**
* Refuse incoming call
*/
virtual void refuse() = 0;
private:
bool validTransition(CallState newState);
......
......@@ -155,3 +155,14 @@ IAXCall::hangup(int reason UNUSED)
link_->removeIaxCall(getCallId());
}
void
IAXCall::refuse()
{
{
std::lock_guard<std::mutex> lock(IAXVoIPLink::mutexIAX);
iax_reject(session, (char*) "Call rejected manually.");
}
link_->removeIaxCall(getCallId());
}
......@@ -84,6 +84,8 @@ class IAXCall : public Call {
void hangup(int reason);
void refuse();
private:
NON_COPYABLE(IAXCall);
......
......@@ -395,23 +395,6 @@ IAXVoIPLink::attendedTransfer(const std::string& /*transferID*/, const std::stri
return false; // TODO
}
void
IAXVoIPLink::refuse(const std::string& id)
{
{
std::lock_guard<std::mutex> lock(iaxCallMapMutex_);
auto call = getIAXCall(id);
if (!call)
return;
{
std::lock_guard<std::mutex> lock(mutexIAX);
iax_reject(call->session, (char*) "Call rejected manually.");
}
}
removeIaxCall(id);
}
void
IAXVoIPLink::carryingDTMFdigits(const std::string& id, char code)
{
......
......@@ -164,12 +164,6 @@ class IAXVoIPLink : public VoIPLink {
*/
virtual bool attendedTransfer(const std::string& transferID, const std::string& targetID);
/**
* Refuse a call
* @param id The ID of the call
*/
virtual void refuse(const std::string& id);
/**
* Send DTMF
* @param id The ID of the call
......
......@@ -657,10 +657,10 @@ bool ManagerImpl::refuseCall(const std::string& id)
audiodriver_->stopStream();
}
std::string accountid = getAccountFromCall(id);
if (accountid.empty())
auto call = getCallFromCallID(id);
if (!call)
return false;
getAccountLink(accountid)->refuse(id);
call->refuse();
checkAudio();
......
......@@ -325,3 +325,27 @@ SIPCall::hangup(int reason)
siplink.removeSipCall(getCallId());
}
void
SIPCall::refuse()
{
if (!isIncoming() or getConnectionState() == Call::CONNECTED or !inv)
return;
getAudioRtp().stop();
pjsip_tx_data *tdata;
if (pjsip_inv_end_session(inv, PJSIP_SC_DECLINE, NULL, &tdata) != PJ_SUCCESS)
return;
if (pjsip_inv_send_msg(inv, tdata) != PJ_SUCCESS)
return;
auto& siplink = SIPVoIPLink::instance();
// Make sure the pointer is NULL in callbacks
inv->mod_data[siplink.getMod()->id] = NULL;
siplink.removeSipCall(getCallId());
}
......@@ -119,6 +119,8 @@ class SIPCall : public Call {
void hangup(int reason);
void refuse();
private:
// override of Call::createHistoryEntry
......
......@@ -1313,32 +1313,6 @@ bool SIPVoIPLink::attendedTransfer(const std::string& id, const std::string& /*t
return transferCommon(call.get(), &dst);
}
void
SIPVoIPLink::refuse(const std::string& id)
{
auto call = getSipCall(id);
if (!call)
return;
if (!call->isIncoming() or call->getConnectionState() == Call::CONNECTED or !call->inv)
return;
call->getAudioRtp().stop();
pjsip_tx_data *tdata;
if (pjsip_inv_end_session(call->inv, PJSIP_SC_DECLINE, NULL, &tdata) != PJ_SUCCESS)
return;
if (pjsip_inv_send_msg(call->inv, tdata) != PJ_SUCCESS)
return;
// Make sure the pointer is NULL in callbacks
call->inv->mod_data[mod_ua_.id] = NULL;
removeSipCall(id);
}
static void
sendSIPInfo(const SIPCall &call, const char *const body, const char *const subtype)
{
......
......@@ -199,12 +199,6 @@ class SIPVoIPLink : public VoIPLink {
*/
virtual bool attendedTransfer(const std::string&, const std::string&);
/**
* Refuse the call
* @param id The call identifier
*/
virtual void refuse(const std::string& id);
/**
* Send DTMF refering to account configuration
* @param id The call identifier
......
......@@ -128,12 +128,6 @@ class VoIPLink {
*/
virtual bool attendedTransfer(const std::string&, const std::string&) = 0;
/**
* Refuse incoming call
* @param id The call identifier
*/
virtual void refuse(const std::string &id) = 0;
/**
* Send DTMF
* @param id The call identifier
......
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