Commit 3dcfcbc2 authored by Tristan Matthews's avatar Tristan Matthews

* #8409: each account stores its own voiplink pointer

This avoids casts and is cleaner.
parent e28002a1
......@@ -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)
......
......@@ -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.
......
......@@ -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_;
}
......@@ -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
......@@ -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_;
}
......@@ -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
......@@ -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;
......
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