diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index 66221b798578317e2e60723fc2e8e344d7fd8fe5..8b464931258446cf272a4e27d87f52620d6c42cc 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -44,7 +44,7 @@ #include <dlfcn.h> AccountMap IAXVoIPLink::iaxAccountMap_ = AccountMap(); -CallMap IAXVoIPLink::iaxCallMap_ = CallMap(); +IAXCallMap IAXVoIPLink::iaxCallMap_ = IAXCallMap(); ost::Mutex IAXVoIPLink::iaxCallMapMutex_ = ost::Mutex(); IAXVoIPLink::IAXVoIPLink(const std::string& accountID) : @@ -68,7 +68,7 @@ IAXVoIPLink::~IAXVoIPLink() handlingEvents_ = false; regSession_ = NULL; // shall not delete it // XXX: but why? terminate(); - clearCallMap(); + clearIaxCallMap(); } void @@ -95,8 +95,8 @@ IAXVoIPLink::terminate() ost::MutexLock m(iaxCallMapMutex_); - for (CallMap::iterator iter = iaxCallMap_.begin(); iter != iaxCallMap_.end(); ++iter) { - IAXCall *call = dynamic_cast<IAXCall*>(iter->second); + for (IAXCallMap::iterator iter = iaxCallMap_.begin(); iter != iaxCallMap_.end(); ++iter) { + IAXCall *call = static_cast<IAXCall*>(iter->second); if (call) { ost::MutexLock lock(mutexIAX_); @@ -153,8 +153,8 @@ IAXVoIPLink::getEvent() void IAXVoIPLink::sendAudioFromMic() { - for (CallMap::const_iterator iter = iaxCallMap_.begin(); iter != iaxCallMap_.end() ; ++iter) { - IAXCall *currentCall = dynamic_cast<IAXCall*>(iter->second); + for (IAXCallMap::const_iterator iter = iaxCallMap_.begin(); iter != iaxCallMap_.end() ; ++iter) { + IAXCall *currentCall = static_cast<IAXCall*>(iter->second); if (!currentCall or currentCall->getState() != Call::ACTIVE) continue; @@ -210,7 +210,7 @@ IAXVoIPLink::sendAudioFromMic() IAXCall* IAXVoIPLink::getIAXCall(const std::string& id) { - return dynamic_cast<IAXCall*>(getCall(id)); + return getIaxCall(id); } void @@ -263,7 +263,7 @@ IAXVoIPLink::newOutgoingCall(const std::string& id, const std::string& toUrl) iaxOutgoingInvite(call); call->setConnectionState(Call::PROGRESSING); call->setState(Call::ACTIVE); - addCall(call); + addIaxCall(call); return call; } @@ -300,7 +300,7 @@ IAXVoIPLink::hangup(const std::string& id) call->session = NULL; - removeCall(id); + removeIaxCall(id); } @@ -316,7 +316,7 @@ IAXVoIPLink::peerHungup(const std::string& id) call->session = NULL; - removeCall(id); + removeIaxCall(id); } @@ -387,7 +387,7 @@ IAXVoIPLink::refuse(const std::string& id) iax_reject(call->session, (char*) "Call rejected manually."); mutexIAX_.leave(); - removeCall(id); + removeIaxCall(id); } } @@ -420,11 +420,11 @@ IAXVoIPLink::sendTextMessage(const std::string& callID, #endif void -IAXVoIPLink::clearCallMap() +IAXVoIPLink::clearIaxCallMap() { ost::MutexLock m(iaxCallMapMutex_); - for (CallMap::const_iterator iter = iaxCallMap_.begin(); + for (IAXCallMap::const_iterator iter = iaxCallMap_.begin(); iter != iaxCallMap_.end(); ++iter) delete iter->second; @@ -433,16 +433,16 @@ IAXVoIPLink::clearCallMap() } void -IAXVoIPLink::addCall(Call* call) +IAXVoIPLink::addIaxCall(IAXCall* call) { - if (call and getCall(call->getCallId()) == NULL) { + if (call and getIaxCall(call->getCallId()) == NULL) { ost::MutexLock m(iaxCallMapMutex_); iaxCallMap_[call->getCallId()] = call; } } void -IAXVoIPLink::removeCall(const std::string& id) +IAXVoIPLink::removeIaxCall(const std::string& id) { ost::MutexLock m(iaxCallMapMutex_); @@ -452,10 +452,10 @@ IAXVoIPLink::removeCall(const std::string& id) iaxCallMap_.erase(id); } -Call* -IAXVoIPLink::getCall(const std::string& id) +IAXCall* +IAXVoIPLink::getIaxCall(const std::string& id) { - CallMap::iterator iter = iaxCallMap_.find(id); + IAXCallMap::iterator iter = iaxCallMap_.find(id); if (iter != iaxCallMap_.end()) @@ -474,7 +474,7 @@ IAXVoIPLink::getCurrentVideoCodecName(Call * /*call*/) const std::string IAXVoIPLink::getCurrentAudioCodecName(Call *c) const { - IAXCall *call = dynamic_cast<IAXCall*>(c); + IAXCall *call = static_cast<IAXCall*>(c); sfl::Codec *audioCodec = Manager::instance().audioCodecFactory.getCodec(call->getAudioCodec()); return audioCodec ? audioCodec->getMimeSubtype() : ""; } @@ -504,8 +504,8 @@ IAXVoIPLink::iaxFindCallBySession(iax_session* session) { ost::MutexLock m(iaxCallMapMutex_); - for (CallMap::const_iterator iter = iaxCallMap_.begin(); iter != iaxCallMap_.end(); ++iter) { - IAXCall* call = dynamic_cast<IAXCall*>(iter->second); + for (IAXCallMap::const_iterator iter = iaxCallMap_.begin(); iter != iaxCallMap_.end(); ++iter) { + IAXCall* call = static_cast<IAXCall*>(iter->second); if (call and call->session == session) return call; @@ -523,14 +523,14 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call) case IAX_EVENT_HANGUP: Manager::instance().peerHungupCall(id); - removeCall(id); + removeIaxCall(id); break; case IAX_EVENT_REJECT: call->setConnectionState(Call::CONNECTED); call->setState(Call::ERROR); Manager::instance().callFailure(id); - removeCall(id); + removeIaxCall(id); break; case IAX_EVENT_ACCEPT: @@ -565,7 +565,7 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call) call->setConnectionState(Call::CONNECTED); call->setState(Call::BUSY); Manager::instance().callBusy(id); - removeCall(id); + removeIaxCall(id); break; case IAX_EVENT_VOICE: @@ -691,7 +691,7 @@ void IAXVoIPLink::iaxHandlePrecallEvent(iax_event* event) iax_accept(event->session, format); iax_ring_announce(event->session); - addCall(call); + addIaxCall(call); call->format = format; break; @@ -699,7 +699,7 @@ void IAXVoIPLink::iaxHandlePrecallEvent(iax_event* event) case IAX_EVENT_HANGUP: id = iaxFindCallBySession(event->session)->getCallId(); Manager::instance().peerHungupCall(id); - removeCall(id); + removeIaxCall(id); break; case IAX_EVENT_TIMEOUT: // timeout for an unknown session diff --git a/daemon/src/iax/iaxvoiplink.h b/daemon/src/iax/iaxvoiplink.h index 0b2b1283c61ab208b5d9755779af32578d5f0c4a..726b0e80603423bf58487729eb4718bdce118e6f 100644 --- a/daemon/src/iax/iaxvoiplink.h +++ b/daemon/src/iax/iaxvoiplink.h @@ -52,6 +52,8 @@ class IAXAccount; class AudioCodec; class AudioLayer; +typedef std::map<std::string, IAXCall*> IAXCallMap; + /** * @file iaxvoiplink.h * @brief VoIPLink contains a thread that listen to external events @@ -176,10 +178,10 @@ class IAXVoIPLink : public VoIPLink { #if HAVE_INSTANT_MESSAGING virtual void sendTextMessage(const std::string& callID, const std::string& message, const std::string& from); #endif - virtual void clearCallMap(); - virtual void addCall(Call* call); - virtual Call* getCall(const std::string& id); - virtual void removeCall(const std::string &id); + static void clearIaxCallMap(); + static void addIaxCall(IAXCall* call); + static IAXCall* getIaxCall(const std::string& id); + static void removeIaxCall(const std::string &id); /** * Return the codec protocol used for this call @@ -197,7 +199,7 @@ class IAXVoIPLink : public VoIPLink { static AccountMap iaxAccountMap_; static ost::Mutex iaxCallMapMutex_; - static CallMap iaxCallMap_; + static IAXCallMap iaxCallMap_; /* * Decode the message count IAX send. diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index b8d6b47753e9a19feda2f0a8d38c35485ee42dba..b5f3e5e3ab7ce4b9ffb3088682a34e6dd2129ddd 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -44,8 +44,10 @@ #include "global.h" #include "fileutils.h" #include "sip/sipaccount.h" +#include "sip/sipcall.h" #include "im/instant_messaging.h" #include "iax/iaxaccount.h" +#include "iax/iaxcall.h" #include "numbercleaner.h" #include "config/yamlparser.h" #include "config/yamlemitter.h" @@ -377,7 +379,7 @@ void ManagerImpl::hangupCall(const std::string& callId) if (isIPToIP(callId)) { /* Direct IP to IP call */ try { - Call * call = SIPVoIPLink::instance()->getCall(callId); + Call * call = SIPVoIPLink::getSipCall(callId); if (call) { history_.addCall(call, preferences.getHistoryLimit()); SIPVoIPLink::instance()->hangup(callId); @@ -501,7 +503,7 @@ void ManagerImpl::offHoldCall(const std::string& callId) /* Classic call, attached to an account */ const std::string accountId(getAccountFromCall(callId)); DEBUG("Setting offhold, Account %s, callid %s", accountId.c_str(), callId.c_str()); - Call * call = getAccountLink(accountId)->getCall(callId); + Call * call = getCallFromCallID(callId); if (call) getAccountLink(accountId)->offhold(callId); @@ -869,8 +871,14 @@ void ManagerImpl::addMainParticipant(const std::string& conference_id) Call * ManagerImpl::getCallFromCallID(const std::string &callID) { - const std::string accountID(getAccountFromCall(callID)); - Call *call = getAccountLink(accountID)->getCall(callID); + Call *call = NULL; + + call = SIPVoIPLink::getSipCall(callID); + if(call != NULL) + return call; + + call = IAXVoIPLink::getIaxCall(callID); + return call; } @@ -1553,14 +1561,14 @@ void ManagerImpl::peerHungupCall(const std::string& call_id) /* Direct IP to IP call */ if (isIPToIP(call_id)) { - Call * call = SIPVoIPLink::instance()->getCall(call_id); + Call * call = SIPVoIPLink::getSipCall(call_id); history_.addCall(call, preferences.getHistoryLimit()); SIPVoIPLink::instance()->hangup(call_id); saveHistory(); } else { const std::string account_id(getAccountFromCall(call_id)); VoIPLink *link = getAccountLink(account_id); - Call * call = link->getCall(call_id); + Call * call = getCallFromCallID(call_id); history_.addCall(call, preferences.getHistoryLimit()); link->peerHungup(call_id); saveHistory(); @@ -1836,7 +1844,7 @@ std::string ManagerImpl::getCurrentAudioCodecName(const std::string& id) { std::string accountid = getAccountFromCall(id); VoIPLink* link = getAccountLink(accountid); - Call* call = link->getCall(id); + Call* call = getCallFromCallID(id); std::string codecName; if (call) { @@ -1984,7 +1992,7 @@ void ManagerImpl::setRecordingCall(const std::string& id) if (it == conferenceMap_.end()) { DEBUG("Set recording for call %s", id.c_str()); std::string accountid(getAccountFromCall(id)); - rec = getAccountLink(accountid)->getCall(id); + rec = getCallFromCallID(id); } else { DEBUG("Set recording for conference %s", id.c_str()); Conference *conf = it->second; @@ -2009,8 +2017,7 @@ void ManagerImpl::setRecordingCall(const std::string& id) bool ManagerImpl::isRecording(const std::string& id) { - const std::string accountid(getAccountFromCall(id)); - Recordable* rec = getAccountLink(accountid)->getCall(id); + Recordable* rec = getCallFromCallID(id); return rec and rec->isRecording(); } diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index f8fde08b8366038188f5f64e7beac01e647d6b09..ae40f58f8263c05ef4fb539b8d77892fd1b78f91 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -83,7 +83,7 @@ SIPVoIPLink *SIPVoIPLink::instance_ = 0; bool SIPVoIPLink::destroyed_ = false; AccountMap SIPVoIPLink::sipAccountMap_ = AccountMap(); -CallMap SIPVoIPLink::sipCallMap_ = CallMap(); +SipCallMap SIPVoIPLink::sipCallMap_ = SipCallMap(); ost::Mutex SIPVoIPLink::sipCallMapMutex_ = ost::Mutex(); namespace { @@ -408,7 +408,7 @@ pj_bool_t transaction_request_cb(pjsip_rx_data *rdata) call->setConnectionState(Call::RINGING); Manager::instance().incomingCall(*call, account_id); - Manager::instance().getAccountLink(account_id)->addCall(call); + SIPVoIPLink::addSipCall(call); } return PJ_FALSE; @@ -516,8 +516,7 @@ SIPVoIPLink::~SIPVoIPLink() pj_caching_pool_destroy(cp_); pj_shutdown(); - - clearCallMap(); + clearSipCallMap(); } SIPVoIPLink* SIPVoIPLink::instance() @@ -922,7 +921,7 @@ SIPVoIPLink::hangup(const std::string& id) inv->mod_data[mod_ua_.id] = NULL; stopRtpIfCurrent(id, *call); - removeCall(id); + removeSipCall(id); } void @@ -943,7 +942,7 @@ SIPVoIPLink::peerHungup(const std::string& id) call->inv->mod_data[mod_ua_.id ] = NULL; stopRtpIfCurrent(id, *call); - removeCall(id); + removeSipCall(id); } void @@ -1046,26 +1045,26 @@ void SIPVoIPLink::sendTextMessage(const std::string &callID, #endif // HAVE_INSTANT_MESSAGING void -SIPVoIPLink::clearCallMap() +SIPVoIPLink::clearSipCallMap() { ost::MutexLock m(sipCallMapMutex_); - for (CallMap::const_iterator iter = sipCallMap_.begin(); + for (SipCallMap::const_iterator iter = sipCallMap_.begin(); iter != sipCallMap_.end(); ++iter) delete iter->second; sipCallMap_.clear(); } -void SIPVoIPLink::addCall(Call* call) +void SIPVoIPLink::addSipCall(SIPCall* call) { - if (call and getCall(call->getCallId()) == NULL) { + if (call and getSipCall(call->getCallId()) == NULL) { ost::MutexLock m(sipCallMapMutex_); sipCallMap_[call->getCallId()] = call; } } -void SIPVoIPLink::removeCall(const std::string& id) +void SIPVoIPLink::removeSipCall(const std::string& id) { ost::MutexLock m(sipCallMapMutex_); @@ -1075,10 +1074,10 @@ void SIPVoIPLink::removeCall(const std::string& id) sipCallMap_.erase(id); } -Call* -SIPVoIPLink::getCall(const std::string& id) +SIPCall* +SIPVoIPLink::getSipCall(const std::string& id) { - CallMap::iterator iter = sipCallMap_.find(id); + SipCallMap::iterator iter = sipCallMap_.find(id); if (iter != sipCallMap_.end()) return iter->second; @@ -1199,13 +1198,13 @@ SIPVoIPLink::refuse(const std::string& id) // Make sure the pointer is NULL in callbacks call->inv->mod_data[mod_ua_.id] = NULL; - removeCall(id); + removeSipCall(id); } std::string SIPVoIPLink::getCurrentVideoCodecName(Call *call) const { - return dynamic_cast<SIPCall*>(call)->getLocalSDP()->getSessionVideoCodec(); + return static_cast<SIPCall*>(call)->getLocalSDP()->getSessionVideoCodec(); } std::string @@ -1371,7 +1370,7 @@ SIPVoIPLink::SIPStartCall(SIPCall *call) call->setConnectionState(Call::PROGRESSING); call->setState(Call::ACTIVE); - addCall(call); + addSipCall(call); return true; } @@ -1381,7 +1380,7 @@ SIPVoIPLink::SIPCallServerFailure(SIPCall *call) { std::string id(call->getCallId()); Manager::instance().callFailure(id); - removeCall(id); + removeSipCall(id); } void @@ -1392,7 +1391,7 @@ SIPVoIPLink::SIPCallClosed(SIPCall *call) stopRtpIfCurrent(id, *call); Manager::instance().peerHungupCall(id); - removeCall(id); + removeSipCall(id); } void @@ -1409,7 +1408,7 @@ SIPVoIPLink::SIPCallAnswered(SIPCall *call, pjsip_rx_data * /*rdata*/) SIPCall* SIPVoIPLink::getSIPCall(const std::string& id) { - SIPCall *result = dynamic_cast<SIPCall*>(getCall(id)); + SIPCall *result = dynamic_cast<SIPCall*>(getSipCall(id)); if (result == NULL) throw VoipLinkException("Could not find SIPCall " + id); @@ -2074,7 +2073,7 @@ void transfer_client_cb(pjsip_evsub *sub, pjsip_event *event) if (r_data->msg_info.cid) return; std::string transferID(r_data->msg_info.cid->id.ptr, r_data->msg_info.cid->id.slen); - SIPCall *call = dynamic_cast<SIPCall *>(link->getCall(transferCallID[transferID])); + SIPCall *call = SIPVoIPLink::getSipCall(transferCallID[transferID]); if (!call) return; diff --git a/daemon/src/sip/sipvoiplink.h b/daemon/src/sip/sipvoiplink.h index 29f8e0131337146079411e90870fb7b5c8444e02..8e8bdd0fa6017ea28fab884f767a6470ee4a5838 100644 --- a/daemon/src/sip/sipvoiplink.h +++ b/daemon/src/sip/sipvoiplink.h @@ -57,6 +57,7 @@ class SIPCall; class SIPAccount; +typedef std::map<std::string, SIPCall*> SipCallMap; /** * @file sipvoiplink.h * @brief Specific VoIPLink for SIP (SIP core for incoming and outgoing events). @@ -256,10 +257,10 @@ class SIPVoIPLink : public VoIPLink { const std::string& message, const std::string& from); #endif - virtual void clearCallMap(); - virtual void addCall(Call* call); - virtual Call* getCall(const std::string& id); - virtual void removeCall(const std::string &id); + static void clearSipCallMap(); + static void addSipCall(SIPCall* call); + static SIPCall* getSipCall(const std::string& id); + static void removeSipCall(const std::string &id); /** * Create the default UDP transport according ot Ip2Ip profile settings @@ -288,7 +289,7 @@ class SIPVoIPLink : public VoIPLink { static AccountMap sipAccountMap_; static ost::Mutex sipCallMapMutex_; - static CallMap sipCallMap_; + static SipCallMap sipCallMap_; /** * Start a SIP Call diff --git a/daemon/src/voiplink.h b/daemon/src/voiplink.h index a6659e2fc8c3b734ffbeb1c85be71494a30610a6..f7147da4bab002fd59eb7d59c72ca7fdd216f0b3 100644 --- a/daemon/src/voiplink.h +++ b/daemon/src/voiplink.h @@ -43,9 +43,6 @@ class Call; class Account; -/** Define a map that associate a Call object to a call identifier */ -typedef std::map<std::string, Call*> CallMap; - class VoipLinkException : public std::runtime_error { public: VoipLinkException(const std::string &str = "") : @@ -167,26 +164,6 @@ class VoIPLink { const std::string &message, const std::string &from) = 0; #endif - virtual void clearCallMap() = 0; - - /** Add a call to the call map (protected by mutex) - * @param call A call pointer with a unique pointer - * @return bool True if the call was unique and added - */ - virtual void addCall(Call* call) = 0; - - /** - * Get the call pointer from the call map (protected by mutex) - * @param id A Call ID - * @return Call* Call pointer or 0 - */ - virtual Call* getCall(const std::string &id) = 0; - - /** Remove a call from the call map (protected by mutex) - * @param id A Call ID - */ - virtual void removeCall(const std::string &id) = 0; - protected: bool handlingEvents_;