From 1f9ea69737831f7a3ae18b9e16d9e526f24b3815 Mon Sep 17 00:00:00 2001 From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> Date: Wed, 16 Jul 2014 21:44:49 -0400 Subject: [PATCH] daemon: (core) add getVoIPLink() api to Call class And implement it in SIP/IAX Call. Refs #51555 Change-Id: Id206eb15bb66fd4ee2b5acb43a4ed2f95543c658 --- daemon/src/call.h | 4 ++++ daemon/src/iax/iaxcall.cpp | 10 ++++++++-- daemon/src/iax/iaxcall.h | 11 ++++++++++- daemon/src/iax/iaxvoiplink.cpp | 4 ++-- daemon/src/managerimpl.cpp | 13 +++++-------- daemon/src/sip/sipcall.cpp | 5 +++++ daemon/src/sip/sipcall.h | 2 ++ 7 files changed, 36 insertions(+), 13 deletions(-) diff --git a/daemon/src/call.h b/daemon/src/call.h index b9c7673397..eae06627d8 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 ca00091605..be14b9c58b 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 65dbdb8a7b..dd4be39ba7 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 982510535e..2c8276ed65 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 d84aa69d04..fe6a112c58 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 695ec23e36..ec383d602f 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 e3fcf1cb1e..2d7d9590e1 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 -- GitLab