diff --git a/daemon/src/call.h b/daemon/src/call.h index b9c7673397cb99254c3c12cbe5d4cd5e2cedec7a..eae06627d809466fb6025db30419ad8cae4191b1 100644 --- a/daemon/src/call.h +++ b/daemon/src/call.h @@ -41,6 +41,8 @@ #include <map> #include <sstream> +class VoIPLink; + /* * @file call.h * @brief A call is the base class for protocol-based calls @@ -235,6 +237,8 @@ class Call : public Recordable { virtual bool toggleRecording(); + virtual VoIPLink* getVoIPLink() const = 0; + private: bool validTransition(CallState newState); diff --git a/daemon/src/iax/iaxcall.cpp b/daemon/src/iax/iaxcall.cpp index ca00091605237f4fa5a8a90a31f00bfacf982df6..be14b9c58bdf88f167cff4a27ad48421a8d021ab 100644 --- a/daemon/src/iax/iaxcall.cpp +++ b/daemon/src/iax/iaxcall.cpp @@ -38,6 +38,7 @@ #include "logger.h" #include "account.h" #include "manager.h" +#include "iaxvoiplink.h" static int codecToASTFormat(int c) @@ -60,8 +61,9 @@ codecToASTFormat(int c) } } -IAXCall::IAXCall(const std::string& id, Call::CallType type, const std::string &account_id) : Call(id, type, account_id), - format(0), session(NULL) +IAXCall::IAXCall(const std::string& id, Call::CallType type, + const std::string& account_id, IAXVoIPLink* link) : + Call(id, type, account_id), format(0), session(NULL), link_(link) {} int IAXCall::getSupportedFormat(const std::string &accountID) const @@ -126,3 +128,7 @@ void IAXCall::answer() { iax_answer(session); } + +VoIPLink* +IAXCall::getVoIPLink() const +{ return link_; } diff --git a/daemon/src/iax/iaxcall.h b/daemon/src/iax/iaxcall.h index 65dbdb8a7b52df977b7d106d6f32707e74100b03..dd4be39ba755137cf84d6833ee0bbe9e19c904b8 100644 --- a/daemon/src/iax/iaxcall.h +++ b/daemon/src/iax/iaxcall.h @@ -34,6 +34,9 @@ #include "call.h" #include "noncopyable.h" +class VoIPLink; +class IAXVoIPLink; + /** * @file: iaxcall.h * @brief IAXCall are IAX implementation of a normal Call @@ -47,7 +50,8 @@ class IAXCall : public Call { * @param id The unique ID of the call * @param type The type of the call */ - IAXCall(const std::string& id, Call::CallType type, const std::string &account_id); + IAXCall(const std::string& id, Call::CallType type, + const std::string& account_id, IAXVoIPLink* link); /** * @return int The bitwise list of supported formats @@ -73,10 +77,15 @@ class IAXCall : public Call { int format; iax_session* session; + + VoIPLink* getVoIPLink() const; + private: void answer(); NON_COPYABLE(IAXCall); + + IAXVoIPLink* link_; }; #endif diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index 982510535e451e9476e112b98988fa9cce0262a9..2c8276ed653e7c83801c8da647fe0199cbd35aff 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -300,7 +300,7 @@ IAXVoIPLink::sendUnregister(Account& a, std::function<void(bool)> cb) std::shared_ptr<Call> IAXVoIPLink::newOutgoingCall(const std::string& id, const std::string& toUrl, const std::string &account_id) { - std::shared_ptr<IAXCall> call(new IAXCall(id, Call::OUTGOING, account_id)); + auto call = std::make_shared<IAXCall>(id, Call::OUTGOING, account_id, this); call->setPeerNumber(toUrl); call->initRecFilename(toUrl); @@ -785,7 +785,7 @@ void IAXVoIPLink::iaxHandlePrecallEvent(iax_event* event) case IAX_EVENT_CONNECT: id = Manager::instance().getNewCallID(); - call = std::make_shared<IAXCall>(id, Call::INCOMING, accountID_); + call = std::make_shared<IAXCall>(id, Call::INCOMING, accountID_, this); call->session = event->session; call->setConnectionState(Call::PROGRESSING); diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index d84aa69d0447cc7084faf240abf838a533185010..fe6a112c58e53ca6138e0435c66f8c34b9421b43 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -228,7 +228,7 @@ void ManagerImpl::init(const std::string &config_file) } void ManagerImpl::setPath(const std::string &path) { - history_.setPath(path); + history_.setPath(path); } int ManagerImpl::run() @@ -418,9 +418,7 @@ bool ManagerImpl::answerCall(const std::string& call_id) } try { - VoIPLink *link = getAccountLink(call->getAccountId()); - if (link) - link->answer(call.get()); + call->getVoIPLink()->answer(call.get()); } catch (const std::runtime_error &e) { ERROR("%s", e.what()); result = false; @@ -489,8 +487,7 @@ bool ManagerImpl::hangupCall(const std::string& callId) try { if (auto call = getCallFromCallID(callId)) { history_.addCall(call.get(), preferences.getHistoryLimit()); - auto link = getAccountLink(call->getAccountId()); - link->hangup(callId, 0); + call->getVoIPLink()->hangup(callId, 0); checkAudio(); saveHistory(); } @@ -586,7 +583,7 @@ bool ManagerImpl::offHoldCall(const std::string& callId) try { if (auto call = getCallFromCallID(callId)) - getAccountLink(call->getAccountId())->offhold(callId); + call->getVoIPLink()->offhold(callId); else result = false; } catch (const VoipLinkException &e) { @@ -1611,7 +1608,7 @@ void ManagerImpl::peerHungupCall(const std::string& call_id) if (auto call = getCallFromCallID(call_id)) { history_.addCall(call.get(), preferences.getHistoryLimit()); - getAccountLink(call->getAccountId())->peerHungup(call_id); + call->getVoIPLink()->peerHungup(call_id); saveHistory(); } diff --git a/daemon/src/sip/sipcall.cpp b/daemon/src/sip/sipcall.cpp index 695ec23e3680be4a22747d6451b9d7080f32f195..ec383d602f78d9b224f949a60a97fae161b56666 100644 --- a/daemon/src/sip/sipcall.cpp +++ b/daemon/src/sip/sipcall.cpp @@ -46,6 +46,7 @@ getSettings() return videoman->getSettings(videoman->getDefaultDevice()); } #endif +#include "sipvoiplink.h" static const int INITIAL_SIZE = 16384; static const int INCREMENT_SIZE = INITIAL_SIZE; @@ -220,3 +221,7 @@ SIPCall::onhold() if (SIPSessionReinvite(this) != PJ_SUCCESS) WARN("Reinvite failed"); } + +VoIPLink* +SIPCall::getVoIPLink() const +{ return &SIPVoIPLink::instance(); } diff --git a/daemon/src/sip/sipcall.h b/daemon/src/sip/sipcall.h index e3fcf1cb1ea1666ee84ed6d15d80a27c75a34dd4..2d7d9590e1ea25fe9992bf03852b44f402c1bccd 100644 --- a/daemon/src/sip/sipcall.h +++ b/daemon/src/sip/sipcall.h @@ -115,6 +115,8 @@ class SIPCall : public Call { void onhold(); void offhold(const std::function<void()> &SDPUpdateFunc); + VoIPLink* getVoIPLink() const; + private: // override of Call::createHistoryEntry