diff --git a/daemon/src/conference.cpp b/daemon/src/conference.cpp index c1382bc0a1ec56ee1ee4aa707d72eb341e829590..87e88614386d2a50a7d19ba4d4b7d006cea274f5 100644 --- a/daemon/src/conference.cpp +++ b/daemon/src/conference.cpp @@ -61,7 +61,7 @@ Conference::~Conference() { #ifdef SFL_VIDEO for (const auto &participant_id : participants_) { - SIPCall *call = SIPVoIPLink::instance()->getSipCall(participant_id); + SIPCall *call = SIPVoIPLink::instance().getSipCall(participant_id); if (call) call->getVideoRtp().exitConference(); } @@ -82,7 +82,7 @@ void Conference::add(const std::string &participant_id) { if (participants_.insert(participant_id).second) { #ifdef SFL_VIDEO - SIPCall *call = SIPVoIPLink::instance()->getSipCall(participant_id); + SIPCall *call = SIPVoIPLink::instance().getSipCall(participant_id); if (call) call->getVideoRtp().enterConference(this); #endif // SFL_VIDEO @@ -93,7 +93,7 @@ void Conference::remove(const std::string &participant_id) { if (participants_.erase(participant_id)) { #ifdef SFL_VIDEO - SIPCall *call = SIPVoIPLink::instance()->getSipCall(participant_id); + SIPCall *call = SIPVoIPLink::instance().getSipCall(participant_id); if (call) call->getVideoRtp().exitConference(); #endif // SFL_VIDEO diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index d0bedb7d65c6b6e0a955605520406cea8ac7bf54..1615e92ab41ca7d452de94d73c3bd5daa7da5550 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -134,7 +134,7 @@ namespace { namespace { void loadDefaultAccountMap() { - SIPVoIPLink::instance()->loadIP2IPSettings(); + SIPVoIPLink::instance().loadIP2IPSettings(); } } @@ -485,10 +485,10 @@ bool ManagerImpl::hangupCall(const std::string& callId) if (isIPToIP(callId)) { /* Direct IP to IP call */ try { - Call * call = SIPVoIPLink::instance()->getSipCall(callId); + Call * call = SIPVoIPLink::instance().getSipCall(callId); if (call) { history_.addCall(call, preferences.getHistoryLimit()); - SIPVoIPLink::instance()->hangup(callId, 0); + SIPVoIPLink::instance().hangup(callId, 0); checkAudio(); saveHistory(); } @@ -547,7 +547,7 @@ bool ManagerImpl::onHoldCall(const std::string& callId) try { if (isIPToIP(callId)) { - SIPVoIPLink::instance()->onhold(callId); + SIPVoIPLink::instance().onhold(callId); } else { /* Classic call, attached to an account */ std::string account_id(getAccountFromCall(callId)); @@ -602,7 +602,7 @@ bool ManagerImpl::offHoldCall(const std::string& callId) try { if (isIPToIP(callId)) - SIPVoIPLink::instance()->offhold(callId); + SIPVoIPLink::instance().offhold(callId); else { /* Classic call, attached to an account */ Call * call = getCallFromCallID(callId); @@ -643,7 +643,7 @@ bool ManagerImpl::transferCall(const std::string& callId, const std::string& to) // Direct IP to IP call if (isIPToIP(callId)) { - SIPVoIPLink::instance()->transfer(callId, to); + SIPVoIPLink::instance().transfer(callId, to); } else { std::string accountID(getAccountFromCall(callId)); @@ -673,7 +673,7 @@ void ManagerImpl::transferSucceeded() bool ManagerImpl::attendedTransfer(const std::string& transferID, const std::string& targetID) { if (isIPToIP(transferID)) - return SIPVoIPLink::instance()->attendedTransfer(transferID, targetID); + return SIPVoIPLink::instance().attendedTransfer(transferID, targetID); // Classic call, attached to an account std::string accountid(getAccountFromCall(transferID)); @@ -700,7 +700,7 @@ bool ManagerImpl::refuseCall(const std::string& id) /* Direct IP to IP call */ if (isIPToIP(id)) - SIPVoIPLink::instance()->refuse(id); + SIPVoIPLink::instance().refuse(id); else { /* Classic call, attached to an account */ std::string accountid = getAccountFromCall(id); @@ -992,7 +992,7 @@ ManagerImpl::getCallFromCallID(const std::string &callID) { Call *call = nullptr; - call = SIPVoIPLink::instance()->getSipCall(callID); + call = SIPVoIPLink::instance().getSipCall(callID); #if HAVE_IAX if (call != nullptr) return call; @@ -1355,7 +1355,7 @@ void ManagerImpl::saveConfig() try { Conf::YamlEmitter emitter(path_.c_str()); - for (auto &item : SIPVoIPLink::instance()->getAccounts()) + for (auto &item : SIPVoIPLink::instance().getAccounts()) item.second->serialize(emitter); #if HAVE_IAX @@ -1665,10 +1665,10 @@ void ManagerImpl::peerHungupCall(const std::string& call_id) /* Direct IP to IP call */ if (isIPToIP(call_id)) { - Call * call = SIPVoIPLink::instance()->getSipCall(call_id); + Call * call = SIPVoIPLink::instance().getSipCall(call_id); if (call) { history_.addCall(call, preferences.getHistoryLimit()); - SIPVoIPLink::instance()->hangup(call_id, 0); + SIPVoIPLink::instance().hangup(call_id, 0); saveHistory(); } } else { @@ -2423,7 +2423,7 @@ ManagerImpl::addAccount(const std::map<std::string, std::string>& details) if (accountType == "SIP") { newAccount = new SIPAccount(newAccountID, true); - SIPVoIPLink::instance()->getAccounts()[newAccountID] = newAccount; + SIPVoIPLink::instance().getAccounts()[newAccountID] = newAccount; } #if HAVE_IAX else if (accountType == "IAX") { @@ -2463,7 +2463,7 @@ void ManagerImpl::removeAccount(const std::string& accountID) if (remAccount != nullptr) { remAccount->unregisterVoIPLink(); - SIPVoIPLink::instance()->getAccounts().erase(accountID); + SIPVoIPLink::instance().getAccounts().erase(accountID); #if HAVE_IAX IAXVoIPLink::getAccounts().erase(accountID); #endif @@ -2617,7 +2617,7 @@ int ManagerImpl::loadAccountMap(Conf::YamlParser &parser) const std::string accountOrder = preferences.getAccountOrder(); - AccountMap &sipAccounts = SIPVoIPLink::instance()->getAccounts(); + AccountMap &sipAccounts = SIPVoIPLink::instance().getAccounts(); #if HAVE_IAX AccountMap &iaxAccounts = IAXVoIPLink::getAccounts(); for (auto &s : *seq) @@ -2628,14 +2628,14 @@ int ManagerImpl::loadAccountMap(Conf::YamlParser &parser) #endif // This must happen after account is loaded - SIPVoIPLink::instance()->loadIP2IPSettings(); + SIPVoIPLink::instance().loadIP2IPSettings(); return errorCount; } void ManagerImpl::registerAllAccounts() { - for (auto &a : SIPVoIPLink::instance()->getAccounts()) + for (auto &a : SIPVoIPLink::instance().getAccounts()) registerAccount(a); #if HAVE_IAX for (auto &a : IAXVoIPLink::getAccounts()) @@ -2645,7 +2645,7 @@ void ManagerImpl::registerAllAccounts() void ManagerImpl::unregisterAllAccounts() { - for (auto &a : SIPVoIPLink::instance()->getAccounts()) + for (auto &a : SIPVoIPLink::instance().getAccounts()) unregisterAccount(a); #if HAVE_IAX for (auto &a : IAXVoIPLink::getAccounts()) @@ -2657,7 +2657,7 @@ bool ManagerImpl::accountExists(const std::string &accountID) { bool ret = false; - ret = SIPVoIPLink::instance()->getAccounts().find(accountID) != SIPVoIPLink::instance()->getAccounts().end(); + ret = SIPVoIPLink::instance().getAccounts().find(accountID) != SIPVoIPLink::instance().getAccounts().end(); #if HAVE_IAX if (ret) return ret; @@ -2671,8 +2671,8 @@ bool ManagerImpl::accountExists(const std::string &accountID) SIPAccount* ManagerImpl::getIP2IPAccount() const { - AccountMap::const_iterator iter = SIPVoIPLink::instance()->getAccounts().find(SIPAccount::IP2IP_PROFILE); - if (iter == SIPVoIPLink::instance()->getAccounts().end()) + AccountMap::const_iterator iter = SIPVoIPLink::instance().getAccounts().find(SIPAccount::IP2IP_PROFILE); + if (iter == SIPVoIPLink::instance().getAccounts().end()) return nullptr; return static_cast<SIPAccount *>(iter->second); @@ -2699,8 +2699,8 @@ ManagerImpl::getAccount(const std::string& accountID) const SIPAccount * ManagerImpl::getSipAccount(const std::string& accountID) const { - AccountMap::const_iterator iter = SIPVoIPLink::instance()->getAccounts().find(accountID); - if (iter != SIPVoIPLink::instance()->getAccounts().end()) + AccountMap::const_iterator iter = SIPVoIPLink::instance().getAccounts().find(accountID); + if (iter != SIPVoIPLink::instance().getAccounts().end()) return static_cast<SIPAccount *>(iter->second); return nullptr; @@ -2722,7 +2722,7 @@ AccountMap ManagerImpl::getAllAccounts() const { AccountMap all; - all.insert(SIPVoIPLink::instance()->getAccounts().begin(), SIPVoIPLink::instance()->getAccounts().end()); + all.insert(SIPVoIPLink::instance().getAccounts().begin(), SIPVoIPLink::instance().getAccounts().end()); #if HAVE_IAX all.insert(IAXVoIPLink::getAccounts().begin(), IAXVoIPLink::getAccounts().end()); #endif @@ -2768,7 +2768,7 @@ std::vector<std::map<std::string, std::string> > ManagerImpl::getHistory() std::vector<std::string> ManagerImpl::getCallList() const { - std::vector<std::string> v(SIPVoIPLink::instance()->getCallIDs()); + std::vector<std::string> v(SIPVoIPLink::instance().getCallIDs()); #if HAVE_IAX const std::vector<std::string> iaxCalls(IAXVoIPLink::getCallIDs()); v.insert(v.end(), iaxCalls.begin(), iaxCalls.end()); @@ -2865,14 +2865,14 @@ VoIPLink* ManagerImpl::getAccountLink(const std::string& accountID) Account *account = getAccount(accountID); if (account == nullptr) { DEBUG("Could not find account for account %s, returning sip voip", accountID.c_str()); - return SIPVoIPLink::instance(); + return &SIPVoIPLink::instance(); } if (not accountID.empty()) return account->getVoIPLink(); else { DEBUG("Account id is empty for voip link, returning sip voip"); - return SIPVoIPLink::instance(); + return &SIPVoIPLink::instance(); } } diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index 403c8cf357756de3df5e378d72cb7b670cc1bdb7..b3ff73e437dbc4bbc4f4954934b09bd1f04d64ff 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -976,7 +976,7 @@ void SIPAccount::startKeepAliveTimer() keepAliveTimerActive_ = true; - link_->registerKeepAliveTimer(keepAliveTimer_, keepAliveDelay_); + link_.registerKeepAliveTimer(keepAliveTimer_, keepAliveDelay_); } void SIPAccount::stopKeepAliveTimer() @@ -984,7 +984,7 @@ void SIPAccount::stopKeepAliveTimer() if (keepAliveTimerActive_) { DEBUG("Stop keep alive timer %d for account %s", keepAliveTimer_.id, getAccountID().c_str()); keepAliveTimerActive_ = false; - link_->cancelKeepAliveTimer(keepAliveTimer_); + link_.cancelKeepAliveTimer(keepAliveTimer_); } } @@ -1230,7 +1230,7 @@ SIPAccount::getContactHeader() std::string address; pj_uint16_t port; - link_->sipTransport->findLocalAddressFromTransport(transport_, transportType, address, port); + link_.sipTransport->findLocalAddressFromTransport(transport_, transportType, address, port); if (not publishedSameasLocal_) { address = publishedIpAddress_; @@ -1286,7 +1286,7 @@ SIPAccount::getHostPortFromSTUN(pj_pool_t *pool) { std::string addr; pj_uint16_t port; - link_->sipTransport->findLocalAddressFromSTUN(transport_, &stunServerName_, stunPort_, addr, port); + link_.sipTransport->findLocalAddressFromSTUN(transport_, &stunServerName_, stunPort_, addr, port); pjsip_host_port result; pj_strdup2(pool, &result.host, addr.c_str()); result.host.slen = addr.length(); @@ -1522,7 +1522,7 @@ void SIPAccount::setTlsSettings(const std::map<std::string, std::string>& detail VoIPLink* SIPAccount::getVoIPLink() { - return link_; + return &link_; } bool SIPAccount::isIP2IP() const @@ -1791,7 +1791,7 @@ SIPAccount::checkNATAddress(pjsip_regc_cbparam *param, pj_pool_t *pool) if (contactRewriteMethod_ == 1) { /* Unregister current contact */ - link_->sendUnregister(this); + link_.sendUnregister(*this); destroyRegistrationInfo(); } @@ -1851,7 +1851,7 @@ SIPAccount::checkNATAddress(pjsip_regc_cbparam *param, pj_pool_t *pool) //pjsua_acc_set_registration(acc->index, PJ_TRUE); /* Perform new registration */ try { - link_->sendRegister(this); + link_.sendRegister(*this); } catch (const VoipLinkException &e) { ERROR("%s", e.what()); } @@ -1864,7 +1864,7 @@ SIPAccount::checkNATAddress(pjsip_regc_cbparam *param, pj_pool_t *pool) void SIPAccount::autoReregTimerCb(pj_timer_heap_t * /*th*/, pj_timer_entry *te) { - std::pair<SIPAccount *, pjsip_endpoint *> *context = static_cast<std::pair<SIPAccount *, pjsip_endpoint *> *>(te->user_data); + auto context = static_cast<std::pair<SIPAccount *, pjsip_endpoint *> *>(te->user_data); SIPAccount *acc = context->first; pjsip_endpoint *endpt = context->second; @@ -1880,7 +1880,7 @@ SIPAccount::autoReregTimerCb(pj_timer_heap_t * /*th*/, pj_timer_entry *te) /* Start re-registration */ acc->auto_rereg_.attempt_cnt++; try { - acc->link_->sendRegister(acc); + acc->link_.sendRegister(*acc); } catch (const VoipLinkException &e) { ERROR("%s", e.what()); acc->scheduleReregistration(endpt); diff --git a/daemon/src/sip/sipaccount.h b/daemon/src/sip/sipaccount.h index b8d0ff6584360c88e780d752649dde0b43be253c..accf25b2ff17a4363fff55039bf7fe7366627add 100644 --- a/daemon/src/sip/sipaccount.h +++ b/daemon/src/sip/sipaccount.h @@ -826,7 +826,7 @@ class SIPAccount : public Account { /** * Voice over IP Link contains a listener thread and calls */ - SIPVoIPLink* link_; + SIPVoIPLink& link_; /** * Optional: "received" parameter from VIA header diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index ddabbb8de760556b5ec75a11076c5d573676c305..3667186ad46c579c489644a8b4edbc09606d230a 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -243,7 +243,7 @@ pj_bool_t transaction_request_cb(pjsip_rx_data *rdata) std::string userName(sip_to_uri->user.ptr, sip_to_uri->user.slen); std::string server(sip_from_uri->host.ptr, sip_from_uri->host.slen); - std::string account_id(SIPVoIPLink::instance()->guessAccountIdFromNameAndServer(userName, server)); + std::string account_id(SIPVoIPLink::instance().guessAccountIdFromNameAndServer(userName, server)); std::string displayName(sip_utils::parseDisplayName(rdata->msg_info.msg_buf)); @@ -360,7 +360,7 @@ pj_bool_t transaction_request_cb(pjsip_rx_data *rdata) } if (account->isStunEnabled()) - updateSDPFromSTUN(*call, *account, *SIPVoIPLink::instance()->sipTransport); + updateSDPFromSTUN(*call, *account, *SIPVoIPLink::instance().sipTransport); if (body and body->len > 0 and call->getAudioRtp().isSdesEnabled()) { std::string sdpOffer(static_cast<const char*>(body->data), body->len); @@ -411,9 +411,9 @@ pj_bool_t transaction_request_cb(pjsip_rx_data *rdata) pjsip_dialog *dialog = 0; - if (pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, NULL, &dialog) != PJ_SUCCESS) { + if (pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, nullptr, &dialog) != PJ_SUCCESS) { delete call; - pjsip_endpt_respond_stateless(endpt_, rdata, PJSIP_SC_INTERNAL_SERVER_ERROR, NULL, NULL, NULL); + pjsip_endpt_respond_stateless(endpt_, rdata, PJSIP_SC_INTERNAL_SERVER_ERROR, nullptr, nullptr, nullptr); return PJ_FALSE; } @@ -504,7 +504,7 @@ pj_bool_t transaction_request_cb(pjsip_rx_data *rdata) call->setConnectionState(Call::RINGING); - SIPVoIPLink::instance()->addSipCall(call); + SIPVoIPLink::instance().addSipCall(call); Manager::instance().incomingCall(*call, account_id); } @@ -643,14 +643,14 @@ SIPVoIPLink::~SIPVoIPLink() pj_shutdown(); } -SIPVoIPLink* SIPVoIPLink::instance() +SIPVoIPLink& SIPVoIPLink::instance() { if (!instance_) { DEBUG("creating SIPVoIPLink instance"); instance_ = new SIPVoIPLink; } - return instance_; + return *instance_; } void SIPVoIPLink::destroy() @@ -1017,7 +1017,7 @@ Call *SIPVoIPLink::newRegisteredAccountCall(const std::string& id, const std::st call->getAudioRtp().initSession(); if (account->isStunEnabled()) - updateSDPFromSTUN(*call, *account, *SIPVoIPLink::instance()->sipTransport); + updateSDPFromSTUN(*call, *account, *SIPVoIPLink::instance().sipTransport); call->getAudioRtp().initLocalCryptoInfo(); call->getAudioRtp().start(audioCodecs); @@ -1060,7 +1060,7 @@ SIPVoIPLink::answer(Call *call) sdp_create_offer_cb(sipCall->inv, &dummy); if (account->isStunEnabled()) - updateSDPFromSTUN(*sipCall, *account, *SIPVoIPLink::instance()->sipTransport); + updateSDPFromSTUN(*sipCall, *account, *SIPVoIPLink::instance().sipTransport); } ERROR("answer getContactHeader"); @@ -1248,7 +1248,7 @@ SIPVoIPLink::offhold(const std::string& id) SIPAccount *account = Manager::instance().getSipAccount(account_id); if (account and account->isStunEnabled()) - updateSDPFromSTUN(*call, *account, *SIPVoIPLink::instance()->sipTransport); + updateSDPFromSTUN(*call, *account, *SIPVoIPLink::instance().sipTransport); call->getAudioRtp().restoreLocalContext(); call->getAudioRtp().initLocalCryptoInfoOnOffHold(); @@ -1589,7 +1589,7 @@ SIPVoIPLink::requestKeyframe(const std::string &callID) const int tries = 10; for (int i = 0; !call and i < tries; ++i) - call = SIPVoIPLink::instance()->tryGetSIPCall(callID); + call = SIPVoIPLink::instance().tryGetSIPCall(callID); if (!call) return; @@ -1779,14 +1779,14 @@ void invite_session_state_changed_cb(pjsip_inv_session *inv, pjsip_event *ev) } } - SIPVoIPLink *link = SIPVoIPLink::instance(); + SIPVoIPLink& link = SIPVoIPLink::instance(); if (inv->state == PJSIP_INV_STATE_EARLY and ev and ev->body.tsx_state.tsx and ev->body.tsx_state.tsx->role == PJSIP_ROLE_UAC) { makeCallRing(*call); } else if (inv->state == PJSIP_INV_STATE_CONFIRMED and ev) { // After we sent or received a ACK - The connection is established - link->SIPCallAnswered(call, ev->body.tsx_state.src.rdata); + link.SIPCallAnswered(call, ev->body.tsx_state.src.rdata); } else if (inv->state == PJSIP_INV_STATE_DISCONNECTED) { std::string accId(call->getAccountId()); @@ -1794,7 +1794,7 @@ void invite_session_state_changed_cb(pjsip_inv_session *inv, pjsip_event *ev) // The call terminates normally - BYE / CANCEL case PJSIP_SC_OK: case PJSIP_SC_REQUEST_TERMINATED: - link->SIPCallClosed(call); + link.SIPCallClosed(call); break; case PJSIP_SC_DECLINE: @@ -1811,7 +1811,7 @@ void invite_session_state_changed_cb(pjsip_inv_session *inv, pjsip_event *ev) case PJSIP_SC_REQUEST_PENDING: case PJSIP_SC_ADDRESS_INCOMPLETE: default: - link->SIPCallServerFailure(call); + link.SIPCallServerFailure(call); break; } } @@ -1890,7 +1890,7 @@ void sdp_media_update_cb(pjsip_inv_session *inv, pj_status_t status) WARN("Could not negotiate offer"); const std::string callID(call->getCallId()); - SIPVoIPLink::instance()->hangup(callID, reason); + SIPVoIPLink::instance().hangup(callID, reason); // call is now a dangling pointer after calling hangup call = 0; Manager::instance().callFailure(callID); @@ -2021,7 +2021,7 @@ void sdp_media_update_cb(pjsip_inv_session *inv, pj_status_t status) call->getAudioRtp().initSession(); if (sipaccount->isStunEnabled()) - updateSDPFromSTUN(*call, *sipaccount, *SIPVoIPLink::instance()->sipTransport); + updateSDPFromSTUN(*call, *sipaccount, *SIPVoIPLink::instance().sipTransport); } } @@ -2370,7 +2370,7 @@ void onCallTransfered(pjsip_inv_session *inv, pjsip_rx_data *rdata) } try { - SIPVoIPLink::instance()->newOutgoingCall(Manager::instance().getNewCallID(), + SIPVoIPLink::instance().newOutgoingCall(Manager::instance().getNewCallID(), std::string(refer_to->hvalue.ptr, refer_to->hvalue.slen), currentCall->getAccountId()); Manager::instance().hangupCall(currentCall->getCallId()); } catch (const VoipLinkException &e) { @@ -2429,7 +2429,7 @@ void transfer_client_cb(pjsip_evsub *sub, pjsip_event *event) return; std::string transferID(r_data->msg_info.cid->id.ptr, r_data->msg_info.cid->id.slen); - SIPCall *call = SIPVoIPLink::instance()->getSipCall(transferCallID[transferID]); + SIPCall *call = SIPVoIPLink::instance().getSipCall(transferCallID[transferID]); if (!call) return; diff --git a/daemon/src/sip/sipvoiplink.h b/daemon/src/sip/sipvoiplink.h index dadcd945445a09c8ca749466b535cddff50eafae..a5ab87401eed052d578110a4c91c1e66025feea4 100644 --- a/daemon/src/sip/sipvoiplink.h +++ b/daemon/src/sip/sipvoiplink.h @@ -77,7 +77,7 @@ class SIPVoIPLink : public VoIPLink { * Singleton method. Enable to retrieve the unique static instance * @return SIPVoIPLink* A pointer on the object */ - static SIPVoIPLink* instance(); + static SIPVoIPLink& instance(); /** * Destroy the singleton instance diff --git a/daemon/src/voiplink.cpp b/daemon/src/voiplink.cpp index f5658ca3c5a1e3a71f87860af0daea074d130155..0f9d8cbe5af0e3afe2ba3118ceccebf0c89ba508 100644 --- a/daemon/src/voiplink.cpp +++ b/daemon/src/voiplink.cpp @@ -43,6 +43,6 @@ void VoIPLink::unloadAccount(std::pair<const std::string, Account*> &item) // avoid deleting a nameless account twice if (not item.first.empty()) { delete item.second; - item.second = 0; + item.second = nullptr; } }