diff --git a/daemon/src/account.cpp b/daemon/src/account.cpp index 5501e3aa9423fb796202ab8670c909abefef8eb7..af0b0689d7505b4b951704dce1c1919a00c85029 100644 --- a/daemon/src/account.cpp +++ b/daemon/src/account.cpp @@ -38,7 +38,6 @@ Account::Account(const std::string& accountID, const std::string &type) : , username_() , hostname_() , alias_() - , link_(NULL) , enabled_(true) , type_(type) , registrationState_(Unregistered) diff --git a/daemon/src/account.h b/daemon/src/account.h index 76007b95f062ea114c0cc11bbd24d6cc99affc41..97af525490e95aa893736b41a4efb4de101b623b 100644 --- a/daemon/src/account.h +++ b/daemon/src/account.h @@ -188,9 +188,7 @@ class Account : public Serializable { * Get the voiplink pointer * @return VoIPLink* the pointer or 0 */ - VoIPLink* getVoIPLink() { - return link_; - } + virtual VoIPLink* getVoIPLink() = 0; /** * Register the underlying VoIPLink. Launch the event listener. @@ -324,11 +322,6 @@ class Account : public Serializable { */ std::string alias_; - /** - * Voice over IP Link contains a listener thread and calls - */ - VoIPLink* link_; - /** * Tells if the link is enabled, active. * This implies the link will be initialized on startup. diff --git a/daemon/src/iax/iaxaccount.cpp b/daemon/src/iax/iaxaccount.cpp index eda848c4a84fc6d5b72f6eb6cb8926f7786f69b7..5c653c037a5dee506c1df23e2cf296f55013e1b0 100644 --- a/daemon/src/iax/iaxaccount.cpp +++ b/daemon/src/iax/iaxaccount.cpp @@ -38,10 +38,9 @@ #include "manager.h" IAXAccount::IAXAccount(const std::string& accountID) - : Account(accountID, "iax2"), password_() -{ - link_ = new IAXVoIPLink(accountID); -} + : Account(accountID, "iax2"), password_(), + link_(new IAXVoIPLink(accountID)) +{} IAXAccount::~IAXAccount() @@ -160,7 +159,7 @@ IAXAccount::unregisterVoIPLink() { try { link_->sendUnregister(this); - dynamic_cast<IAXVoIPLink*>(link_)->terminate(); + link_->terminate(); } catch (const VoipLinkException &e) { ERROR("IAXAccount: %s", e.what()); } @@ -174,3 +173,8 @@ IAXAccount::loadConfig() enabled_ = false; #endif } + +VoIPLink* IAXAccount::getVoIPLink() +{ + return link_; +} diff --git a/daemon/src/iax/iaxaccount.h b/daemon/src/iax/iaxaccount.h index 60b9a1acee27eb704046dc45685460177534d457..7df121d90c36d5f0251546aa6819ff8e632ec51b 100644 --- a/daemon/src/iax/iaxaccount.h +++ b/daemon/src/iax/iaxaccount.h @@ -32,6 +32,9 @@ #define IAXACCOUNT_H #include "account.h" +#include "noncopyable.h" + +class IAXVoIPLink; /** * @file: iaxaccount.h @@ -64,8 +67,11 @@ class IAXAccount : public Account { } private: + NON_COPYABLE(IAXAccount); // Account login information: password std::string password_; + IAXVoIPLink *link_; + virtual VoIPLink* getVoIPLink(); }; #endif diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index 28359cdb5cbd4c157095e95bb9eedb325781b42d..fa252a5221b646a66883b475ac1f6e7a9b494c75 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -87,9 +87,8 @@ SIPAccount::SIPAccount(const std::string& accountID) , zrtpNotSuppWarning_(true) , registrationStateDetailed_() , keepAliveTimer_() -{ - link_ = SIPVoIPLink::instance(); -} + , link_(SIPVoIPLink::instance()) +{} SIPAccount::~SIPAccount() { @@ -241,7 +240,7 @@ void SIPAccount::serialize(Conf::YamlEmitter *emitter) delete node; } - + } void SIPAccount::unserialize(Conf::MappingNode *map) @@ -575,28 +574,27 @@ void SIPAccount::unregisterVoIPLink() } void SIPAccount::startKeepAliveTimer() { - pj_time_val keepAliveDelay_; if (isTlsEnabled()) return; + pj_time_val keepAliveDelay_; keepAliveTimer_.cb = &SIPAccount::keepAliveRegistrationCb; - keepAliveTimer_.user_data = (void *)this; + keepAliveTimer_.user_data = this; // expiration may no be determined when during the first registration request - if(registrationExpire_ == 0) { + if(registrationExpire_ == 0) keepAliveDelay_.sec = 60; - } - else { + else keepAliveDelay_.sec = registrationExpire_; - } + keepAliveDelay_.msec = 0; - reinterpret_cast<SIPVoIPLink *>(link_)->registerKeepAliveTimer(keepAliveTimer_, keepAliveDelay_); + link_->registerKeepAliveTimer(keepAliveTimer_, keepAliveDelay_); } void SIPAccount::stopKeepAliveTimer() { - reinterpret_cast<SIPVoIPLink *>(link_)->cancelKeepAliveTimer(keepAliveTimer_); + link_->cancelKeepAliveTimer(keepAliveTimer_); } pjsip_ssl_method SIPAccount::sslMethodStringToPjEnum(const std::string& method) @@ -771,8 +769,7 @@ std::string SIPAccount::getContactHeader() const // Else we determine this infor based on transport information std::string address, port; - SIPVoIPLink *siplink = dynamic_cast<SIPVoIPLink *>(link_); - siplink->findLocalAddressFromTransport(transport_, transportType_, address, port); + link_->findLocalAddressFromTransport(transport_, transportType_, address, port); // UDP does not require the transport specification if (transportType_ == PJSIP_TRANSPORT_TLS) { @@ -798,7 +795,7 @@ void SIPAccount::keepAliveRegistrationCb(UNUSED pj_timer_heap_t *th, pj_timer_en // send a new register request sipAccount->registerVoIPLink(); - // make sure the current timer is deactivated + // make sure the current timer is deactivated sipAccount->stopKeepAliveTimer(); // register a new timer @@ -1013,3 +1010,8 @@ void SIPAccount::setTlsSettings(const std::map<std::string, std::string>& detail set_opt(details, TLS_NEGOTIATION_TIMEOUT_SEC, tlsNegotiationTimeoutSec_); set_opt(details, TLS_NEGOTIATION_TIMEOUT_MSEC, tlsNegotiationTimeoutMsec_); } + +VoIPLink* SIPAccount::getVoIPLink() +{ + return link_; +} diff --git a/daemon/src/sip/sipaccount.h b/daemon/src/sip/sipaccount.h index 1ba3aadfb96a2b9829f3df95f303c3dfacbf1305..fcfc3fbbc5dd967bd17f9fb55c9122765856b779 100644 --- a/daemon/src/sip/sipaccount.h +++ b/daemon/src/sip/sipaccount.h @@ -672,6 +672,12 @@ class SIPAccount : public Account { */ pj_timer_entry keepAliveTimer_; + + /** + * Voice over IP Link contains a listener thread and calls + */ + SIPVoIPLink* link_; + virtual VoIPLink* getVoIPLink(); }; #endif diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index aac4a75a14412d9078ad977260db80676ee30903..f085c486c519f162cbe9f73be467517cc5131494 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -1669,8 +1669,6 @@ void registration_cb(struct pjsip_regc_cbparam *param) { SIPAccount *account = static_cast<SIPAccount *>(param->token); - ERROR("SipVoipLink: REGISTRATION CALLBACK"); - if (account == NULL) { ERROR("SipVoipLink: account does'nt exist in registration callback"); return;