diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index d14b43fcc31f1652a28c51431f90f85c56c141f3..1e973a039becc63529fc094d4ff260b40ca0676e 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -994,8 +994,6 @@ void ManagerImpl::addMainParticipant (const std::string& conference_id) void ManagerImpl::joinParticipant (const std::string& callId1, const std::string& callId2) { - bool isRec = false; - _debug ("Manager: Join participants %s, %s", callId1.c_str(), callId2.c_str()); std::map<std::string, std::string> call1Details = getCallDetails (callId1); @@ -1048,17 +1046,15 @@ void ManagerImpl::joinParticipant (const std::string& callId1, const std::string } else if (call1_state_str == "INCOMING") { conf->bindParticipant (callId1); answerCall (callId1); - } else if (call1_state_str == "CURRENT") { + } else if (call1_state_str == "CURRENT") conf->bindParticipant (callId1); - } else if (call1_state_str == "RECORD") { + else if (call1_state_str == "RECORD") conf->bindParticipant(callId1); - isRec = true; - } else if (call1_state_str == "INACTIVE") { + else if (call1_state_str == "INACTIVE") { conf->bindParticipant (callId1); answerCall (callId1); - } else { + } else _warn ("Manager: Call state not recognized"); - } // Process call2 according to its state std::string call2_state_str = call2Details.find ("CALL_STATE")->second; @@ -1070,17 +1066,15 @@ void ManagerImpl::joinParticipant (const std::string& callId1, const std::string } else if (call2_state_str == "INCOMING") { conf->bindParticipant (callId2); answerCall (callId2); - } else if (call2_state_str == "CURRENT") { + } else if (call2_state_str == "CURRENT") conf->bindParticipant (callId2); - } else if (call2_state_str == "RECORD") { + else if (call2_state_str == "RECORD") conf->bindParticipant (callId2); - isRec = true; - } else if (call2_state_str == "INACTIVE") { + else if (call2_state_str == "INACTIVE") { conf->bindParticipant (callId2); answerCall (callId2); - } else { + } else _warn ("Manager: Call state not recognized"); - } // Switch current call id to this conference switchCall (conf->getConfID()); @@ -1088,9 +1082,9 @@ void ManagerImpl::joinParticipant (const std::string& callId1, const std::string // set recording sampling rate audioLayerMutexLock(); - if (_audiodriver) { + if (_audiodriver) conf->setRecordingSmplRate(_audiodriver->getSampleRate()); - } + audioLayerMutexUnlock(); getMainBuffer()->stateInfo(); @@ -1098,25 +1092,21 @@ void ManagerImpl::joinParticipant (const std::string& callId1, const std::string void ManagerImpl::createConfFromParticipantList(const std::vector< std::string > &participantList) { - bool callSuccess; - int successCounter = 0; - - _debug("Manager: Create conference from participant list"); - // we must at least have 2 participant for a conference - if(participantList.size() <= 1) { + if (participantList.size() <= 1) { _error("Manager: Error: Participant number must be higher or equal to 2"); - return; + return; } Conference *conf = new Conference(); - for(unsigned int i = 0; i < participantList.size(); i++) { - std::string numberaccount = participantList[i]; - std::string tostr = numberaccount.substr(0, numberaccount.find(",")); - std::string account = numberaccount.substr(numberaccount.find(",")+1, numberaccount.size()); + int successCounter = 0; + for (size_t i = 0; i != participantList.size(); i++) { + std::string numberaccount(participantList[i]); + std::string tostr(numberaccount.substr(0, numberaccount.find(","))); + std::string account(numberaccount.substr(numberaccount.find(",")+1, numberaccount.size())); - std::string generatedCallID = getNewCallID(); + std::string generatedCallID(getNewCallID()); // Manager methods may behave differently if the call id particip to a conference conf->add(generatedCallID); @@ -1124,10 +1114,10 @@ void ManagerImpl::createConfFromParticipantList(const std::vector< std::string > switchCall(""); // Create call - callSuccess = outgoingCall(account, generatedCallID, tostr, conf->getConfID()); + bool callSuccess = outgoingCall(account, generatedCallID, tostr, conf->getConfID()); // If not able to create call remove this participant from the conference - if(!callSuccess) + if (!callSuccess) conf->remove(generatedCallID); else { _dbus.getCallManager()->newCallCreated(account, generatedCallID, tostr); @@ -1136,9 +1126,8 @@ void ManagerImpl::createConfFromParticipantList(const std::vector< std::string > } // Create the conference if and only if at least 2 calls have been successfully created - if(successCounter >= 2 ) { + if (successCounter >= 2 ) { _conferencemap.insert(std::pair<std::string, Conference *> (conf->getConfID(), conf)); - _dbus.getCallManager()->conferenceCreated (conf->getConfID()); audioLayerMutexLock(); @@ -1148,62 +1137,55 @@ void ManagerImpl::createConfFromParticipantList(const std::vector< std::string > audioLayerMutexUnlock(); getMainBuffer()->stateInfo(); - } else { + } else delete conf; - } - } void ManagerImpl::detachParticipant (const std::string& call_id, const std::string& current_id) { - _debug ("Manager: Detach participant %s (current id: %s)", call_id.c_str(), current_id.c_str()); - - std::string current_call_id = getCurrentCallId(); + std::string current_call_id(getCurrentCallId()); if (call_id != Call::DEFAULT_ID) { - std::string currentAccountId = getAccountFromCall (call_id); + std::string currentAccountId(getAccountFromCall (call_id)); Call *call = getAccountLink (currentAccountId)->getCall (call_id); - if(call == NULL) { + if (call == NULL) { _error("Manager: Error: Could not find call %s", call_id.c_str()); return; } // TODO: add conference_id as a second parameter - ConferenceMap::iterator iter = _conferencemap.find (call->getConfId()); + ConferenceMap::iterator iter = _conferencemap.find(call->getConfId()); - Conference *conf = getConferenceFromCallID (call_id); + Conference *conf = getConferenceFromCallID(call_id); if (conf == NULL) { _error ("Manager: Error: Call is not conferencing, cannot detach"); return; } - std::map<std::string, std::string> call_details = getCallDetails (call_id); - std::map<std::string, std::string>::iterator iter_details; - - iter_details = call_details.find ("CALL_STATE"); - if(iter_details == call_details.end()) { + std::map<std::string, std::string> call_details(getCallDetails(call_id)); + std::map<std::string, std::string>::iterator iter_details(call_details.find ("CALL_STATE")); + if (iter_details == call_details.end()) { _error ("Manager: Error: Could not find CALL_STATE"); return; } - if (iter_details->second == "RINGING") { + if (iter_details->second == "RINGING") removeParticipant (call_id); - } else { + else { onHoldCall (call_id); removeParticipant (call_id); processRemainingParticipant (current_call_id, conf); } } else { - _debug ("Manager: Unbind main participant from conference %d"); getMainBuffer()->unBindAll (Call::DEFAULT_ID); - if(!isConference(current_call_id)) { + if (!isConference(current_call_id)) { _error("Manager: Warning: Current call id (%s) is not a conference", current_call_id.c_str()); return; } @@ -1211,25 +1193,21 @@ void ManagerImpl::detachParticipant (const std::string& call_id, ConferenceMap::iterator iter = _conferencemap.find (current_call_id); Conference *conf = iter->second; - if(conf == NULL) { + if (conf == NULL) { _debug("Manager: Error: Conference is NULL"); return; } - if(conf->getState() == Conference::ACTIVE_ATTACHED) { + if (conf->getState() == Conference::ACTIVE_ATTACHED) conf->setState(Conference::ACTIVE_DETACHED); - } - else if(conf->getState() == Conference::ACTIVE_ATTACHED_REC) { + else if(conf->getState() == Conference::ACTIVE_ATTACHED_REC) conf->setState(Conference::ACTIVE_DETACHED_REC); - } - else { + else _warn("Manager: Warning: Undefined behavior, invalid conference state in detach participant"); - } _dbus.getCallManager()->conferenceChanged (conf->getConfID(), conf->getStateStr()); switchCall (""); - } } @@ -1237,15 +1215,9 @@ void ManagerImpl::removeParticipant (const std::string& call_id) { _debug ("Manager: Remove participant %s", call_id.c_str()); - // TODO: add conference_id as a second parameter - Conference* conf; - - std::string currentAccountId; - Call* call = NULL; - // this call is no more a conference participant - currentAccountId = getAccountFromCall (call_id); - call = getAccountLink (currentAccountId)->getCall (call_id); + const std::string currentAccountId(getAccountFromCall (call_id)); + Call *call = getAccountLink (currentAccountId)->getCall (call_id); ConferenceMap conf_map = _conferencemap; ConferenceMap::iterator iter = conf_map.find (call->getConfId()); @@ -1255,46 +1227,34 @@ void ManagerImpl::removeParticipant (const std::string& call_id) return; } - conf = iter->second; + Conference *conf = iter->second; _debug ("Manager: Remove participant %s", call_id.c_str()); - conf->remove (call_id); + conf->remove(call_id); call->setConfId (""); removeStream(call_id); - getMainBuffer()->stateInfo(); } -void ManagerImpl::processRemainingParticipant (std::string current_call_id, Conference *conf) +void ManagerImpl::processRemainingParticipant (const std::string ¤t_call_id, Conference *conf) { - _debug ("Manager: Process remaining %d participant(s) from conference %s", conf->getNbParticipants(), conf->getConfID().c_str()); if (conf->getNbParticipants() > 1) { - - ParticipantSet participants = conf->getParticipantList(); - ParticipantSet::iterator iter_participant = participants.begin(); + ParticipantSet participants(conf->getParticipantList()); // Reset ringbuffer's readpointers - iter_participant = participants.begin(); - - while (iter_participant != participants.end()) { - getMainBuffer()->flush (*iter_participant); - - iter_participant++; - } + for (ParticipantSet::const_iterator iter_p = participants.begin(); + iter_p != participants.end(); + ++iter_p) + getMainBuffer()->flush (*iter_p); getMainBuffer()->flush (Call::DEFAULT_ID); - } else if (conf->getNbParticipants() == 1) { - _debug ("Manager: Only one remaining participant"); - std::string currentAccountId; - Call* call = NULL; - ParticipantSet participants = conf->getParticipantList(); ParticipantSet::iterator iter_participant = participants.begin(); @@ -1302,86 +1262,66 @@ void ManagerImpl::processRemainingParticipant (std::string current_call_id, Conf if (iter_participant != participants.end()) { // this call is no more a conference participant - currentAccountId = getAccountFromCall (*iter_participant); - call = getAccountLink (currentAccountId)->getCall (*iter_participant); + std::string currentAccountId(getAccountFromCall (*iter_participant)); + Call *call = getAccountLink(currentAccountId)->getCall(*iter_participant); call->setConfId (""); // if we are not listening to this conference - - if (current_call_id != conf->getConfID()) { + if (current_call_id != conf->getConfID()) onHoldCall (call->getCallId()); - } else { + else switchCall (*iter_participant); - } } removeConference (conf->getConfID()); - } else { - _debug ("Manager: No remaining participant, remove conference"); - removeConference (conf->getConfID()); - switchCall (""); } - } void ManagerImpl::joinConference (const std::string& conf_id1, const std::string& conf_id2) { _debug ("Manager: Join conference %s, %s", conf_id1.c_str(), conf_id2.c_str()); + ConferenceMap::iterator iter(_conferencemap.find(conf_id1)); - ConferenceMap::iterator iter; - - Conference *conf1 = NULL; - Conference *conf2 = NULL; - - iter = _conferencemap.find (conf_id1); - - if (iter != _conferencemap.end()) { + Conference *conf1; + if (iter != _conferencemap.end()) conf1 = iter->second; - } else { + else { _error ("Manager: Error: Not a valid conference ID"); return; } iter = _conferencemap.find (conf_id2); - if (iter != _conferencemap.end()) { + Conference *conf2; + if (iter != _conferencemap.end()) conf2 = iter->second; - } else { + else { _error ("Manager: Error: Not a valid conference ID"); return; } - ParticipantSet participants = conf1->getParticipantList(); - - ParticipantSet::iterator iter_participant = participants.begin(); - - while (iter_participant != participants.end()) { - detachParticipant (*iter_participant, ""); - addParticipant (*iter_participant, conf_id2); + ParticipantSet participants(conf1->getParticipantList()); - iter_participant++; + for (ParticipantSet::const_iterator iter_p = participants.begin(); + iter_p != participants.end(); ++iter_p) { + detachParticipant (*iter_p, ""); + addParticipant (*iter_p, conf_id2); } - } void ManagerImpl::addStream (const std::string& call_id) { - _debug ("Manager: Add audio stream %s", call_id.c_str()); - std::string currentAccountId; - Call* call = NULL; - - currentAccountId = getAccountFromCall (call_id); - call = getAccountLink (currentAccountId)->getCall (call_id); - - if (participToConference (call_id)) { + std::string currentAccountId(getAccountFromCall(call_id)); + Call *call(getAccountLink(currentAccountId)->getCall(call_id)); + if (participToConference(call_id)) { _debug ("Manager: Add stream to conference"); // bind to conference participant @@ -1392,20 +1332,13 @@ void ManagerImpl::addStream (const std::string& call_id) conf->bindParticipant (call_id); - ParticipantSet participants = conf->getParticipantList(); + ParticipantSet participants(conf->getParticipantList()); // reset ring buffer for all conference participant - ParticipantSet::iterator iter_p = participants.begin(); - - while (iter_p != participants.end()) { - - // to avoid puting onhold the call - // switchCall(""); + for (ParticipantSet::const_iterator iter_p = participants.begin(); + iter_p != participants.end(); ++iter_p) getMainBuffer()->flush (*iter_p); - iter_p++; - } - getMainBuffer()->flush (Call::DEFAULT_ID); } @@ -1427,9 +1360,7 @@ void ManagerImpl::addStream (const std::string& call_id) void ManagerImpl::removeStream (const std::string& call_id) { _debug ("Manager: Remove audio stream %s", call_id.c_str()); - getMainBuffer()->unBindAll (call_id); - getMainBuffer()->stateInfo(); } @@ -1440,22 +1371,16 @@ void ManagerImpl::saveConfig (void) audioPreference.setVolumemic (getMicVolume()); audioPreference.setVolumespkr (getSpkrVolume()); - AccountMap::iterator iter = _accountMap.begin(); - try { // emitter = new Conf::YamlEmitter("sequenceEmitter.yml"); emitter = new Conf::YamlEmitter (_path.c_str()); - while (iter != _accountMap.end()) { - + for (AccountMap::iterator iter = _accountMap.begin(); iter != _accountMap.end(); ++iter) { // Skip the "" account ID (which refer to the IP2IP account) - if (iter->first == "") { - iter++; + if (iter->first.empty()) continue; - } - - iter->second->serialize (emitter); - iter++; + else + iter->second->serialize (emitter); } preferences.serialize (emitter); @@ -1484,23 +1409,17 @@ bool ManagerImpl::sendDtmf (const std::string& id, char code) //THREAD=Main | VoIPLink bool ManagerImpl::playDtmf (char code) { - int pulselen, layerType, size; - bool ret = false; - SFLDataFormat *buf; - stopTone(); - bool hasToPlayTone = voipPreferences.getPlayDtmf(); - - if (!hasToPlayTone) { + if (not voipPreferences.getPlayDtmf()) { _debug ("Manager: playDtmf: Do not have to play a tone..."); return false; } // length in milliseconds - pulselen = voipPreferences.getPulseLength(); + int pulselen = voipPreferences.getPulseLength(); - if (!pulselen) { + if (pulselen == 0) { _debug ("Manager: playDtmf: Pulse length is not set..."); return false; } @@ -1510,8 +1429,6 @@ bool ManagerImpl::playDtmf (char code) // numbers of int = length in milliseconds / 1000 (number of seconds) // = number of seconds * SAMPLING_RATE by SECONDS - layerType = _audiodriver->getLayerType(); - // fast return, no sound, so no dtmf if (_audiodriver == NULL || _dtmfKey == NULL) { _debug ("Manager: playDtmf: Error no audio layer..."); @@ -1523,11 +1440,11 @@ bool ManagerImpl::playDtmf (char code) // size (n sampling) = time_ms * sampling/s // --------------------- // ms/s - size = (int) ( (pulselen * (float) _audiodriver->getSampleRate()) / 1000); + int size = (int) ( (pulselen * (float) _audiodriver->getSampleRate()) / 1000); // this buffer is for mono // TODO <-- this should be global and hide if same size - buf = new SFLDataFormat[size]; + SFLDataFormat *buf = new SFLDataFormat[size]; // Handle dtmf _dtmfKey->startTone (code); @@ -1544,14 +1461,10 @@ bool ManagerImpl::playDtmf (char code) audioLayerMutexUnlock(); - ret = true; - // TODO Cache the DTMF delete[] buf; - buf = 0; - - return ret; + return true; } // Multi-thread @@ -1562,20 +1475,18 @@ bool ManagerImpl::incomingCallWaiting () void ManagerImpl::addWaitingCall (const std::string& id) { - _info ("Manager: Add waiting call %s (%d calls)", id.c_str(), _nbIncomingWaitingCall); - ost::MutexLock m (_waitingCallMutex); + ost::MutexLock m(_waitingCallMutex); _waitingCall.insert (id); _nbIncomingWaitingCall++; } void ManagerImpl::removeWaitingCall (const std::string& id) { - _info ("Manager: Remove waiting call %s (%d calls)", id.c_str(), _nbIncomingWaitingCall); - ost::MutexLock m (_waitingCallMutex); + ost::MutexLock m(_waitingCallMutex); // should return more than 1 if it erase a call if (_waitingCall.erase (id)) @@ -1584,12 +1495,7 @@ void ManagerImpl::removeWaitingCall (const std::string& id) bool ManagerImpl::isWaitingCall (const std::string& id) { - CallIDSet::iterator iter = _waitingCall.find (id); - - if (iter != _waitingCall.end()) - return false; - - return true; + return _waitingCall.find(id) != _waitingCall.end(); } /////////////////////////////////////////////////////////////////////////////// @@ -1599,7 +1505,6 @@ bool ManagerImpl::isWaitingCall (const std::string& id) bool ManagerImpl::incomingCall (Call* call, const std::string& accountId) { assert(call); - stopTone(); _debug ("Manager: Incoming call %s for account %s", call->getCallId().data(), accountId.c_str()); @@ -1614,9 +1519,9 @@ bool ManagerImpl::incomingCall (Call* call, const std::string& accountId) // when placing new call from history (if call is IAX, do nothing) std::string peerNumber(call->getPeerNumber()); - int startIndex = peerNumber.find ("sip:"); + size_t startIndex = peerNumber.find ("sip:"); - if (startIndex != (int) std::string::npos) { + if (startIndex != std::string::npos) { std::string strippedPeerNumber = peerNumber.substr (startIndex + 4); call->setPeerNumber (strippedPeerNumber); } @@ -1624,7 +1529,6 @@ bool ManagerImpl::incomingCall (Call* call, const std::string& accountId) if (!hasCurrentCall()) { _debug ("Manager: Has no current call start ringing"); - call->setConnectionState (Call::Ringing); ringtone (accountId); @@ -1651,11 +1555,10 @@ bool ManagerImpl::incomingCall (Call* call, const std::string& accountId) _debug ("Manager: From: %s, Number: %s, Display Name: %s", from.c_str(), number.c_str(), display_name.c_str()); std::string display(display_name); - display.append (" "); - display.append (from); - - _dbus.getCallManager()->incomingCall (accountId, call->getCallId(), display.c_str()); + display.append(" "); + display.append(from); + _dbus.getCallManager()->incomingCall(accountId, call->getCallId(), display); return true; } @@ -1671,15 +1574,15 @@ void ManagerImpl::incomingMessage (const std::string& callID, Conference *conf = getConferenceFromCallID (callID); ParticipantSet participants = conf->getParticipantList(); - for (ParticipantSet::const_iterator iter_participant = participants.begin(); - iter_participant != participants.end(); ++iter_participant) { + for (ParticipantSet::const_iterator iter_p = participants.begin(); + iter_p != participants.end(); ++iter_p) { - if (*iter_participant == callID) + if (*iter_p == callID) continue; - std::string accountId(getAccountFromCall (*iter_participant)); + std::string accountId(getAccountFromCall(*iter_p)); - _debug ("Manager: Send message to %s, (%s)", (*iter_participant).c_str(), accountId.c_str()); + _debug ("Manager: Send message to %s, (%s)", (*iter_p).c_str(), accountId.c_str()); Account *account = getAccount (accountId); @@ -1701,10 +1604,8 @@ void ManagerImpl::incomingMessage (const std::string& callID, //THREAD=VoIP bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string& message, const std::string& from) { - if (isConference (callID)) { _debug ("Manager: Is a conference, send instant message to everyone"); - ConferenceMap::iterator it = _conferencemap.find (callID); if (it == _conferencemap.end()) @@ -1717,10 +1618,10 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string& const ParticipantSet participants = conf->getParticipantList(); - for (ParticipantSet::const_iterator iter_participant = participants.begin(); - iter_participant != participants.end(); ++iter_participant) { + for (ParticipantSet::const_iterator iter_p = participants.begin(); + iter_p != participants.end(); ++iter_p) { - std::string accountId = getAccountFromCall (*iter_participant); + std::string accountId = getAccountFromCall (*iter_p); Account *account = getAccount (accountId); @@ -1729,7 +1630,7 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string& return false; } - account->getVoIPLink()->sendTextMessage (_imModule, *iter_participant, message, from); + account->getVoIPLink()->sendTextMessage (_imModule, *iter_p, message, from); } return true; @@ -1743,11 +1644,11 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string& if (!conf) return false; - const ParticipantSet participants = conf->getParticipantList(); - for (ParticipantSet::const_iterator iter_participant = participants.begin(); - iter_participant != participants.end(); ++iter_participant) { + const ParticipantSet participants(conf->getParticipantList()); + for (ParticipantSet::const_iterator iter_p = participants.begin(); + iter_p != participants.end(); ++iter_p) { - const std::string accountId(getAccountFromCall(*iter_participant)); + const std::string accountId(getAccountFromCall(*iter_p)); const Account *account = getAccount (accountId); @@ -1756,13 +1657,10 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string& return false; } - account->getVoIPLink()->sendTextMessage (_imModule, *iter_participant, message, from); + account->getVoIPLink()->sendTextMessage (_imModule, *iter_p, message, from); } } else { - - const std::string accountId(getAccountFromCall (callID)); - - const Account *account = getAccount (accountId); + const Account *account = getAccount (getAccountFromCall(callID)); if (!account) { _debug ("Manager: Failed to get account while sending instant message"); @@ -1781,7 +1679,7 @@ void ManagerImpl::peerAnsweredCall (const std::string& id) _debug ("Manager: Peer answered call %s", id.c_str()); // The if statement is usefull only if we sent two calls at the same time. - if (isCurrentCall (id)) + if (isCurrentCall(id)) stopTone(); // Connect audio streams @@ -1815,9 +1713,7 @@ void ManagerImpl::peerRingingCall (const std::string& id) void ManagerImpl::peerHungupCall (const std::string& call_id) { _debug ("Manager: Peer hungup call %s", call_id.c_str()); - if (participToConference (call_id)) { - Conference *conf = getConferenceFromCallID (call_id); if (conf != NULL) { @@ -1835,17 +1731,15 @@ void ManagerImpl::peerHungupCall (const std::string& call_id) if (getConfigFromCall (call_id) == Call::IPtoIP) SIPVoIPLink::instance ()->hangup (call_id); else { - std::string account_id = getAccountFromCall (call_id); - getAccountLink (account_id)->peerHungup (call_id); + const std::string account_id(getAccountFromCall (call_id)); + getAccountLink(account_id)->peerHungup(call_id); } /* Broadcast a signal over DBus */ _dbus.getCallManager()->callStateChanged (call_id, "HUNGUP"); removeWaitingCall (call_id); - removeCallAccount (call_id); - removeStream (call_id); if (getCallList().empty()) { @@ -1861,7 +1755,6 @@ void ManagerImpl::peerHungupCall (const std::string& call_id) void ManagerImpl::callBusy (const std::string& id) { _debug ("Manager: Call %s busy", id.c_str()); - _dbus.getCallManager()->callStateChanged (id, "BUSY"); if (isCurrentCall (id)) { @@ -1870,7 +1763,6 @@ void ManagerImpl::callBusy (const std::string& id) } removeCallAccount (id); - removeWaitingCall (id); } @@ -1878,16 +1770,13 @@ void ManagerImpl::callBusy (const std::string& id) void ManagerImpl::callFailure (const std::string& call_id) { _dbus.getCallManager()->callStateChanged (call_id, "FAILURE"); - if (isCurrentCall (call_id)) { playATone (Tone::TONE_BUSY); switchCall (""); } if (participToConference (call_id)) { - _debug ("Manager: Call %s participating to a conference failed", call_id.c_str()); - Conference *conf = getConferenceFromCallID (call_id); if (conf == NULL) { @@ -1897,15 +1786,11 @@ void ManagerImpl::callFailure (const std::string& call_id) // remove this participant removeParticipant (call_id); - processRemainingParticipant (getCurrentCallId(), conf); - } removeCallAccount (call_id); - removeWaitingCall (call_id); - } //THREAD=VoIP @@ -1926,11 +1811,7 @@ void ManagerImpl::connectionStatusNotification () */ bool ManagerImpl::playATone (Tone::TONEID toneId) { - bool hasToPlayTone; - - hasToPlayTone = voipPreferences.getPlayTones(); - - if (!hasToPlayTone) + if (not voipPreferences.getPlayTones()) return false; audioLayerMutexLock(); @@ -1958,9 +1839,7 @@ bool ManagerImpl::playATone (Tone::TONEID toneId) */ void ManagerImpl::stopTone () { - bool hasToPlayTone = voipPreferences.getPlayTones(); - - if (hasToPlayTone == false) + if (not voipPreferences.getPlayTones()) return; _toneMutex.enterMutex(); @@ -1969,7 +1848,7 @@ void ManagerImpl::stopTone () _telephoneTone->setCurrentTone (Tone::TONE_NULL); if (_audiofile) { - std::string filepath = _audiofile->getFilePath(); + std::string filepath(_audiofile->getFilePath()); _dbus.getCallManager()->recordPlaybackStopped(filepath); delete _audiofile; _audiofile = NULL; @@ -1983,7 +1862,7 @@ void ManagerImpl::stopTone () */ bool ManagerImpl::playTone () { - playATone (Tone::TONE_DIALTONE); + playATone(Tone::TONE_DIALTONE); return true; } @@ -2179,7 +2058,6 @@ std::string ManagerImpl::serialize (const std::vector<std::string> &v) std::string ManagerImpl::getCurrentCodecName (const std::string& id) { - std::string accountid = getAccountFromCall (id); VoIPLink* link = getAccountLink (accountid); Call* call = link->getCall (id); @@ -2187,9 +2065,8 @@ std::string ManagerImpl::getCurrentCodecName (const std::string& id) if (call) { Call::CallState state = call->getState(); - if (state == Call::Active or state == Call::Conferencing) { + if (state == Call::Active or state == Call::Conferencing) codecName = link->getCurrentCodecName(call); - } } return codecName; @@ -2200,7 +2077,6 @@ std::string ManagerImpl::getCurrentCodecName (const std::string& id) */ void ManagerImpl::setAudioPlugin (const std::string& audioPlugin) { - audioLayerMutexLock(); int layerType = _audiodriver -> getLayerType(); @@ -2217,7 +2093,6 @@ void ManagerImpl::setAudioPlugin (const std::string& audioPlugin) notifyErrClient (_audiodriver -> getErrorMessage()); } audioLayerMutexUnlock(); - } /** @@ -2226,7 +2101,6 @@ void ManagerImpl::setAudioPlugin (const std::string& audioPlugin) void ManagerImpl::setAudioDevice (const int index, int streamType) { _debug ("Manager: Set audio device: %d", index); - audioLayerMutexLock(); if(_audiodriver == NULL) { @@ -2285,15 +2159,14 @@ void ManagerImpl::setAudioDevice (const int index, int streamType) std::vector<std::string> ManagerImpl::getAudioOutputDeviceList (void) { _debug ("Manager: Get audio output device list"); - AlsaLayer *alsalayer; std::vector<std::string> devices; audioLayerMutexLock(); - alsalayer = dynamic_cast<AlsaLayer*> (_audiodriver); + AlsaLayer *alsalayer = dynamic_cast<AlsaLayer*>(_audiodriver); if (alsalayer) - devices = alsalayer -> getSoundCardsInfo (SFL_PCM_PLAYBACK); + devices = alsalayer->getSoundCardsInfo(SFL_PCM_PLAYBACK); audioLayerMutexUnlock(); @@ -2306,12 +2179,11 @@ std::vector<std::string> ManagerImpl::getAudioOutputDeviceList (void) */ std::vector<std::string> ManagerImpl::getAudioInputDeviceList (void) { - AlsaLayer *alsalayer; std::vector<std::string> devices; audioLayerMutexLock(); - alsalayer = dynamic_cast<AlsaLayer *> (_audiodriver); + AlsaLayer *alsalayer = dynamic_cast<AlsaLayer *>(_audiodriver); if (alsalayer == NULL) { _error("Manager: Error: Audio layer not initialized"); @@ -2369,7 +2241,6 @@ int ManagerImpl::isRingtoneEnabled (const std::string& id) void ManagerImpl::ringtoneEnabled (const std::string& id) { Account *account = getAccount (id); - if (!account) { _warn ("Manager: Warning: invalid account in ringtone enabled"); return; @@ -2406,11 +2277,11 @@ void ManagerImpl::setRecordingCall (const std::string& id) if (not isConference (id)) { _debug ("Manager: Set recording for call %s", id.c_str()); - std::string accountid = getAccountFromCall(id); - rec = getAccountLink (accountid)->getCall(id); + std::string accountid(getAccountFromCall(id)); + rec = getAccountLink(accountid)->getCall(id); } else { _debug ("Manager: Set recording for conference %s", id.c_str()); - ConferenceMap::iterator it = _conferencemap.find (id); + ConferenceMap::const_iterator it(_conferencemap.find(id)); Conference *conf = it->second; if (rec->isRecording()) conf->setState(Conference::ACTIVE_ATTACHED); @@ -2426,7 +2297,6 @@ void ManagerImpl::setRecordingCall (const std::string& id) } rec->setRecording(); - _dbus.getCallManager()->recordPlaybackFilepath(id, rec->getFileName()); } @@ -2439,8 +2309,6 @@ bool ManagerImpl::isRecording (const std::string& id) bool ManagerImpl::startRecordedFilePlayback(const std::string& filepath) { - int sampleRate; - _debug("Manager: Start recorded file playback %s", filepath.c_str()); audioLayerMutexLock(); @@ -2451,7 +2319,7 @@ bool ManagerImpl::startRecordedFilePlayback(const std::string& filepath) return false; } - sampleRate = _audiodriver->getSampleRate(); + int sampleRate = _audiodriver->getSampleRate(); audioLayerMutexUnlock(); @@ -2497,9 +2365,7 @@ void ManagerImpl::stopRecordedFilePlayback(const std::string& filepath) void ManagerImpl::setHistoryLimit (int days) { _debug ("Manager: Set history limit"); - preferences.setHistoryLimit (days); - saveConfig(); } @@ -2516,16 +2382,12 @@ int32_t ManagerImpl::getMailNotify (void) const void ManagerImpl::setMailNotify (void) { _debug ("Manager: Set mail notify"); - preferences.getNotifyMails() ? preferences.setNotifyMails (true) : preferences.setNotifyMails (false); - saveConfig(); } void ManagerImpl::setAudioManager (int32_t api) { - int layerType; - _debug ("Manager: Setting audio manager "); audioLayerMutexLock(); @@ -2535,7 +2397,7 @@ void ManagerImpl::setAudioManager (int32_t api) return; } - layerType = _audiodriver->getLayerType(); + int layerType = _audiodriver->getLayerType(); if (layerType == api) { _debug ("Manager: Audio manager chosen already in use. No changes made. "); @@ -2545,7 +2407,7 @@ void ManagerImpl::setAudioManager (int32_t api) audioLayerMutexUnlock(); - preferences.setAudioApi (api); + preferences.setAudioApi(api); switchAudioManager(); @@ -2561,12 +2423,11 @@ int32_t ManagerImpl::getAudioManager (void) const void ManagerImpl::notifyErrClient (int32_t errCode) { _debug ("Manager: NOTIFY ERR NUMBER %d" , errCode); - _dbus.getConfigurationManager() -> errorAlert (errCode); + _dbus.getConfigurationManager()->errorAlert(errCode); } int ManagerImpl::getAudioDeviceIndex (const std::string &name) { - AlsaLayer *alsalayer; int soundCardIndex = 0; audioLayerMutexLock(); @@ -2577,7 +2438,7 @@ int ManagerImpl::getAudioDeviceIndex (const std::string &name) return soundCardIndex; } - alsalayer = dynamic_cast<AlsaLayer *> (_audiodriver); + AlsaLayer *alsalayer = dynamic_cast<AlsaLayer *> (_audiodriver); if (alsalayer) soundCardIndex = alsalayer -> soundCardGetIndex (name); diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index 7c5ee305e5c203fc09fcfe62968d1acbdea431b3..f523c99d13826dd7f0b2733bb7eabc9efc2760d4 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -326,14 +326,6 @@ class ManagerImpl */ void removeParticipant (const std::string& call_id); - /** - * Process remaining participant given a conference and the current call id. - * Mainly called when a participant is detached or hagned up - * @param current call id - * @param conference pointer - */ - void processRemainingParticipant (std::string current_call_id, Conference *conf); - /** * Join two conference together into one unique conference */ @@ -360,12 +352,6 @@ class ManagerImpl */ bool sendDtmf (const std::string& id, char code); - /** - * Play the dtmf-associated sound - * @param code The pressed key - */ - bool playDtmf (char code); - /** * Play a ringtone * @return bool True on success @@ -973,6 +959,19 @@ class ManagerImpl */ std::vector<std::string> loadAccountOrder () const; private: + /** + * Play the dtmf-associated sound + * @param code The pressed key + */ + bool playDtmf (char code); + + /** + * Process remaining participant given a conference and the current call id. + * Mainly called when a participant is detached or hagned up + * @param current call id + * @param conference pointer + */ + void processRemainingParticipant (const std::string ¤t_call_id, Conference *conf); /** * Create config directory in home user and return configuration file path