From ddb8ffceb74693db5237a18d9da8d96261075e26 Mon Sep 17 00:00:00 2001
From: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
Date: Thu, 18 Aug 2011 15:34:59 -0400
Subject: [PATCH] * #6655: more cleanup in managerimpl

---
 daemon/src/managerimpl.cpp | 508 +++++++++++--------------------------
 daemon/src/managerimpl.h   |  22 +-
 2 files changed, 165 insertions(+), 365 deletions(-)

diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp
index ed92262516..b5bb47a9d8 100644
--- a/daemon/src/managerimpl.cpp
+++ b/daemon/src/managerimpl.cpp
@@ -72,7 +72,8 @@ ManagerImpl::ManagerImpl (void) :
     _setupLoaded (false), _callAccountMap(),
     _callAccountMapMutex(), _callConfigMap(), _accountMap(),
     _directIpAccount (0), _cleaner (new NumberCleaner),
-    _history (new HistoryManager), _imModule(new sfl::InstantMessaging)
+    _history (new HistoryManager), _imModule(new sfl::InstantMessaging),
+    parser_(0)
 {
     // initialize random generator for call id
     srand (time (NULL));
@@ -262,9 +263,9 @@ bool ManagerImpl::outgoingCall (const std::string& account_id,
     Call *call = NULL;
     try {
         call = getAccountLink(account_id)->newOutgoingCall (call_id, to_cleaned);
-        
+
         switchCall (call_id);
-        
+
         call->setConfId(conf_id);
     } catch (const VoipLinkException &e) {
         callFailure (call_id);
@@ -798,7 +799,7 @@ void ManagerImpl::removeConference (const std::string& conference_id)
     // Then remove the conference from the conference map
     if (_conferencemap.erase (conference_id) == 1)
         _debug ("Manager: Conference %s removed successfully", conference_id.c_str());
-    else 
+    else
         _error ("Manager: Error: Cannot remove conference: %s", conference_id.c_str());
 
     delete conf;
@@ -1231,7 +1232,7 @@ void ManagerImpl::createConfFromParticipantList(const std::vector< std::string >
     } else {
 		delete conf;
     }
-    
+
 }
 
 void ManagerImpl::detachParticipant (const std::string& call_id,
@@ -1813,10 +1814,10 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string&
         if (!conf)
             return false;
 
-        ParticipantSet participants = conf->getParticipantList();
-        ParticipantSet::iterator iter_participant = participants.begin();
+        const ParticipantSet participants = conf->getParticipantList();
 
-        while (iter_participant != participants.end()) {
+        for (ParticipantSet::const_iterator iter_participant = participants.begin();
+                iter_participant != participants.end(); ++iter_participant) {
 
             std::string accountId = getAccountFromCall (*iter_participant);
 
@@ -1837,8 +1838,6 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string&
                 _debug ("Manager: Failed to get voip link while sending instant message");
                 return false;
             }
-
-            iter_participant++;
         }
 
         return true;
@@ -1852,14 +1851,13 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string&
         if (!conf)
             return false;
 
-        ParticipantSet participants = conf->getParticipantList();
-        ParticipantSet::iterator iter_participant = participants.begin();
+        const ParticipantSet participants = conf->getParticipantList();
+        for (ParticipantSet::const_iterator iter_participant = participants.begin();
+                iter_participant != participants.end(); ++iter_participant) {
 
-        while (iter_participant != participants.end()) {
+            const std::string accountId(getAccountFromCall(*iter_participant));
 
-            std::string accountId = getAccountFromCall (*iter_participant);
-
-            Account *account = getAccount (accountId);
+            const Account *account = getAccount (accountId);
 
             if (!account) {
                 _debug ("Manager: Failed to get account while sending instant message");
@@ -1874,15 +1872,12 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string&
                 _debug ("Manager: Failed to get voip link while sending instant message");
                 return false;
             }
-
-            iter_participant++;
         }
-
     } else {
 
-        std::string accountId = getAccountFromCall (callID);
+        const std::string accountId(getAccountFromCall (callID));
 
-        Account *account = getAccount (accountId);
+        const Account *account = getAccount (accountId);
 
         if (!account) {
             _debug ("Manager: Failed to get account while sending instant message");
@@ -1905,13 +1900,11 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string&
 //THREAD=VoIP CALL=Outgoing
 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
     addStream(id);
@@ -1924,7 +1917,8 @@ void ManagerImpl::peerAnsweredCall (const std::string& id)
     if (audioPreference.getIsAlwaysRecording()) {
     	setRecordingCall(id);
     	_dbus.getCallManager()->callStateChanged (id, "RECORD");
-    } else
+    }
+    else
     	_dbus.getCallManager()->callStateChanged(id, "CURRENT");
 }
 
@@ -1942,21 +1936,15 @@ void ManagerImpl::peerRingingCall (const std::string& id)
 //THREAD=VoIP Call=Outgoing/Ingoing
 void ManagerImpl::peerHungupCall (const std::string& call_id)
 {
-    std::string account_id;
-    bool returnValue;
-
     _debug ("Manager: Peer hungup call %s", call_id.c_str());
 
-    // store the current call id
-    std::string current_call_id = getCurrentCallId();
-
     if (participToConference (call_id)) {
 
         Conference *conf = getConferenceFromCallID (call_id);
 
         if (conf != NULL) {
             removeParticipant (call_id);
-            processRemainingParticipant (current_call_id, conf);
+            processRemainingParticipant (getCurrentCallId(), conf);
         }
     } else {
         if (isCurrentCall (call_id)) {
@@ -1966,12 +1954,11 @@ void ManagerImpl::peerHungupCall (const std::string& call_id)
     }
 
     /* Direct IP to IP call */
-    if (getConfigFromCall (call_id) == Call::IPtoIP) {
+    if (getConfigFromCall (call_id) == Call::IPtoIP)
         SIPVoIPLink::instance ()->hangup (call_id);
-    }
     else {
-        account_id = getAccountFromCall (call_id);
-        returnValue = getAccountLink (account_id)->peerHungup (call_id);
+        std::string account_id = getAccountFromCall (call_id);
+        getAccountLink (account_id)->peerHungup (call_id);
     }
 
     /* Broadcast a signal over DBus */
@@ -1981,14 +1968,10 @@ void ManagerImpl::peerHungupCall (const std::string& call_id)
 
     removeCallAccount (call_id);
 
-    removeStream(call_id);
-
-    int nbCalls = getCallList().size();
+    removeStream (call_id);
 
-    // stop streams
-
-    if (nbCalls <= 0) {
-        _debug ("Manager: Stop audio stream, ther is only %d call(s) remaining", nbCalls);
+    if (getCallList().empty()) {
+        _debug ("Manager: Stop audio stream, ther is only %d call(s) remaining", getCallList().size());
 
         audioLayerMutexLock();
         _audiodriver->stopStream();
@@ -2023,8 +2006,6 @@ void ManagerImpl::callFailure (const std::string& call_id)
         switchCall ("");
     }
 
-    std::string current_call_id = getCurrentCallId();
-
     if (participToConference (call_id)) {
 
         _debug ("Manager: Call %s participating to a conference failed", call_id.c_str());
@@ -2039,7 +2020,7 @@ void ManagerImpl::callFailure (const std::string& call_id)
         // remove this participant
         removeParticipant (call_id);
 
-        processRemainingParticipant (current_call_id, conf);
+        processRemainingParticipant (getCurrentCallId(), conf);
 
     }
 
@@ -2067,16 +2048,12 @@ void ManagerImpl::connectionStatusNotification ()
  */
 bool ManagerImpl::playATone (Tone::TONEID toneId)
 {
-
     bool hasToPlayTone;
 
-    // _debug ("Manager: Play tone %d", toneId);
-
     hasToPlayTone = voipPreferences.getPlayTones();
 
-    if (!hasToPlayTone) {
+    if (!hasToPlayTone)
         return false;
-    }
 
     audioLayerMutexLock();
 
@@ -2105,15 +2082,13 @@ void ManagerImpl::stopTone ()
 {
     bool hasToPlayTone = voipPreferences.getPlayTones();
 
-    if (hasToPlayTone == false) {
+    if (hasToPlayTone == false)
         return;
-    }
 
     _toneMutex.enterMutex();
 
-    if (_telephoneTone != NULL) {
+    if (_telephoneTone != NULL)
         _telephoneTone->setCurrentTone (Tone::TONE_NULL);
-    }
 
     if (_audiofile) {
 		std::string filepath = _audiofile->getFilePath();
@@ -2203,9 +2178,8 @@ void ManagerImpl::ringtone (const std::string& accountID)
 	}
 
 	try {
-		if (ringchoice.find (".wav") != std::string::npos) {
+		if (ringchoice.find (".wav") != std::string::npos)
 			_audiofile = new WaveFile(ringchoice, samplerate);
-		}
 		else {
 			sfl::Codec *codec;
 			if (ringchoice.find (".ul") != std::string::npos || ringchoice.find (".au") != std::string::npos)
@@ -2248,9 +2222,6 @@ ManagerImpl::getTelephoneFile ()
 
 void ManagerImpl::notificationIncomingCall (void)
 {
-    std::ostringstream frequency;
-    unsigned int sampleRate, nbSample;
-
     audioLayerMutexLock();
 
     if(_audiodriver == NULL) {
@@ -2263,10 +2234,10 @@ void ManagerImpl::notificationIncomingCall (void)
 
     // Enable notification only if more than one call
     if (hasCurrentCall()) {
-        sampleRate = _audiodriver->getSampleRate();
+        std::ostringstream frequency;
         frequency << "440/" << 160;
-        Tone tone (frequency.str(), sampleRate);
-        nbSample = tone.getSize();
+        Tone tone (frequency.str(), _audiodriver->getSampleRate());
+        unsigned int nbSample = tone.getSize();
         SFLDataFormat buf[nbSample];
         tone.getNext (buf, nbSample);
         /* Put the data in the urgent ring buffer */
@@ -2290,15 +2261,14 @@ std::string ManagerImpl::getConfigFile (void) const
 
     if (XDG_CONFIG_HOME != NULL) {
         std::string xdg_env = std::string (XDG_CONFIG_HOME);
-        if (xdg_env != "")
+        if (not xdg_env.empty())
         	configdir = xdg_env;
     }
 
     if (mkdir (configdir.data(), 0700) != 0) {
         // If directory	creation failed
-        if (errno != EEXIST) {
+        if (errno != EEXIST)
             _debug ("Cannot create directory: %m");
-        }
     }
 
     return configdir + DIR_SEPARATOR_STR + PROGNAME + ".yml";
@@ -2316,12 +2286,11 @@ void ManagerImpl::initConfigFile (std::string alternate)
     _debug ("Manager: configuration file path: %s", _path.c_str());
 
 
-    bool fileExist = true;
-    bool out = false;
+    bool fileExists = true;
 
     if (_path.empty()) {
         _error ("Manager: Error: XDG config file path is empty!");
-        fileExist = false;
+        fileExists = false;
     }
 
     std::fstream file;
@@ -2332,16 +2301,15 @@ void ManagerImpl::initConfigFile (std::string alternate)
 
         _debug ("Manager: File %s not opened, create new one", _path.c_str());
         file.open (_path.data(), std::fstream::out);
-        out = true;
 
         if (!file.is_open()) {
             _error ("Manager: Error: could not create empty configurationfile!");
-            fileExist = false;
+            fileExists = false;
         }
 
         file.close();
 
-        fileExist = false;
+        fileExists = false;
     }
 
     // get length of file:
@@ -2353,20 +2321,18 @@ void ManagerImpl::initConfigFile (std::string alternate)
     if (length <= 0) {
         _debug ("Manager: Configuration file length is empty", length);
         file.close();
-        fileExist = false; // should load config
+        fileExists = false; // should load config
     }
 
-    if (fileExist) {
+    if (fileExists) {
         try {
+            parser_ = new Conf::YamlParser (_path.c_str());
 
-            // parser = new Conf::YamlParser("sequenceParser.yml");
-            parser = new Conf::YamlParser (_path.c_str());
-
-            parser->serializeEvents();
+            parser_->serializeEvents();
 
-            parser->composeEvents();
+            parser_->composeEvents();
 
-            parser->constructNativeData();
+            parser_->constructNativeData();
 
             _setupLoaded = true;
 
@@ -2432,7 +2398,7 @@ std::string ManagerImpl::getCurrentCodecName (const std::string& id)
         }
     }
 
-    return codecName;	
+    return codecName;
 }
 
 /**
@@ -2465,9 +2431,6 @@ void ManagerImpl::setAudioPlugin (const std::string& audioPlugin)
  */
 void ManagerImpl::setAudioDevice (const int index, int streamType)
 {
-
-    AlsaLayer *alsalayer = NULL;
-    std::string alsaplugin;
     _debug ("Manager: Set audio device: %d", index);
 
     audioLayerMutexLock();
@@ -2480,12 +2443,16 @@ void ManagerImpl::setAudioDevice (const int index, int streamType)
 
     _audiodriver -> setErrorMessage (-1);
 
-    alsalayer = dynamic_cast<AlsaLayer*> (_audiodriver);
-    alsaplugin = alsalayer->getAudioPlugin();
+    AlsaLayer *alsaLayer = dynamic_cast<AlsaLayer*>(_audiodriver);
+    if (!alsaLayer) {
+        _error("Cannot set audio output for non-alsa device");
+        audioLayerMutexUnlock();
+        return ;
+    }
+    const std::string alsaplugin(alsaLayer->getAudioPlugin());
 
     _debug ("Manager: Set ALSA plugin: %s", alsaplugin.c_str());
 
-
     switch (streamType) {
         case SFL_PCM_PLAYBACK:
             _debug ("Manager: Set output device");
@@ -2512,12 +2479,10 @@ void ManagerImpl::setAudioDevice (const int index, int streamType)
             _warn ("Unknown stream type");
     }
 
-    if (_audiodriver -> getErrorMessage() != -1) {
+    if (_audiodriver -> getErrorMessage() != -1)
         notifyErrClient (_audiodriver -> getErrorMessage());
-    }
 
     audioLayerMutexUnlock();
-
 }
 
 /**
@@ -2533,9 +2498,9 @@ std::vector<std::string> ManagerImpl::getAudioOutputDeviceList (void)
 
     alsalayer = dynamic_cast<AlsaLayer*> (_audiodriver);
 
-    if (alsalayer) {
+    if (alsalayer)
         devices = alsalayer -> getSoundCardsInfo (SFL_PCM_PLAYBACK);
-    }
+
     audioLayerMutexUnlock();
 
     return devices;
@@ -2578,7 +2543,7 @@ std::vector<std::string> ManagerImpl::getCurrentAudioDevicesIndex ()
 
     std::vector<std::string> v;
 
-    if(_audiodriver == NULL) {
+    if (_audiodriver == NULL) {
     	_error("Manager: Error: Audio layer not initialized");
     	audioLayerMutexUnlock();
     	return v;
@@ -2697,31 +2662,27 @@ void ManagerImpl::setIsAlwaysRecording(bool isAlwaysRec)
 
 void ManagerImpl::setRecordingCall (const std::string& id)
 {
-    Call *call = NULL;
-    Conference *conf = NULL;
     Recordable* rec = NULL;
 
-    if (!isConference (id)) {
+    if (not isConference (id)) {
         _debug ("Manager: Set recording for call %s", id.c_str());
-        std::string accountid = getAccountFromCall (id);
-        call = getAccountLink (accountid)->getCall (id);
-        rec = static_cast<Recordable *>(call);
+        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);
-        conf = it->second;
-        if(conf->isRecording()) {
+        Conference *conf = it->second;
+        if (rec->isRecording())
         	conf->setState(Conference::ACTIVE_ATTACHED);
-        }
-        else {
+        else
         	conf->setState(Conference::ACTIVE_ATTACHED_REC);
-        }
-        rec = static_cast<Recordable *>(conf);
+
+        rec = conf;
     }
 
     if (rec == NULL) {
-	_error("Manager: Error: Could not find recordable instance %s", id.c_str());
-	return;
+        _error("Manager: Error: Could not find recordable instance %s", id.c_str());
+        return;
     }
 
     rec->setRecording();
@@ -2731,21 +2692,23 @@ void ManagerImpl::setRecordingCall (const std::string& id)
 
 bool ManagerImpl::isRecording (const std::string& id)
 {
-    std::string accountid = getAccountFromCall (id);
-    Recordable* rec = (Recordable*) getAccountLink (accountid)->getCall (id);
-    return rec && rec->isRecording();
+    const std::string accountid(getAccountFromCall (id));
+    Recordable* rec = getAccountLink (accountid)->getCall (id);
+    return rec and rec->isRecording();
 }
 
-bool ManagerImpl::startRecordedFilePlayback(const std::string& filepath) 
+bool ManagerImpl::startRecordedFilePlayback(const std::string& filepath)
 {
     int sampleRate;
- 
+
     _debug("Manager: Start recorded file playback %s", filepath.c_str());
 
     audioLayerMutexLock();
 
-    if(!_audiodriver) {
-	_error("Manager: Error: No audio layer in start recorded file playback");
+    if (!_audiodriver) {
+        _error("Manager: Error: No audio layer in start recorded file playback");
+        audioLayerMutexUnlock();
+        return false;
     }
 
     sampleRate = _audiodriver->getSampleRate();
@@ -2754,7 +2717,7 @@ bool ManagerImpl::startRecordedFilePlayback(const std::string& filepath)
 
     _toneMutex.enterMutex();
 
-    if(_audiofile) {
+    if (_audiofile) {
     	_dbus.getCallManager()->recordPlaybackStoped(_audiofile->getFilePath());
 		delete _audiofile;
 		_audiofile = NULL;
@@ -2763,7 +2726,7 @@ bool ManagerImpl::startRecordedFilePlayback(const std::string& filepath)
     try {
         _audiofile = new WaveFile(filepath, sampleRate);
     }
-    catch(const AudioFileException &e) {
+    catch (const AudioFileException &e) {
         _error("Manager: Exception: %s", e.what());
     }
 
@@ -2771,7 +2734,7 @@ bool ManagerImpl::startRecordedFilePlayback(const std::string& filepath)
 
     audioLayerMutexLock();
     _audiodriver->startStream();
-    audioLayerMutexUnlock(); 
+    audioLayerMutexUnlock();
 
     return true;
 }
@@ -2791,7 +2754,7 @@ void ManagerImpl::stopRecordedFilePlayback(const std::string& filepath)
     _toneMutex.leaveMutex();
 }
 
-void ManagerImpl::setHistoryLimit (const int& days)
+void ManagerImpl::setHistoryLimit (int days)
 {
     _debug ("Manager: Set history limit");
 
@@ -2819,9 +2782,8 @@ void ManagerImpl::setMailNotify (void)
     saveConfig();
 }
 
-void ManagerImpl::setAudioManager (const int32_t& api)
+void ManagerImpl::setAudioManager (int32_t api)
 {
-
     int layerType;
 
     _debug ("Manager: Setting audio manager ");
@@ -2848,7 +2810,6 @@ void ManagerImpl::setAudioManager (const int32_t& api)
     switchAudioManager();
 
     saveConfig();
-
 }
 
 int32_t ManagerImpl::getAudioManager (void) const
@@ -2857,7 +2818,7 @@ int32_t ManagerImpl::getAudioManager (void) const
 }
 
 
-void ManagerImpl::notifyErrClient (const int32_t& errCode)
+void ManagerImpl::notifyErrClient (int32_t errCode)
 {
 	_debug ("Manager: NOTIFY ERR NUMBER %d" , errCode);
 	_dbus.getConfigurationManager() -> errorAlert (errCode);
@@ -2880,9 +2841,8 @@ int ManagerImpl::getAudioDeviceIndex (const std::string &name)
 
     alsalayer = dynamic_cast<AlsaLayer *> (_audiodriver);
 
-    if (alsalayer) {
+    if (alsalayer)
         soundCardIndex = alsalayer -> soundCardGetIndex (name);
-    }
 
     audioLayerMutexUnlock();
 
@@ -2913,9 +2873,8 @@ void ManagerImpl::setNoiseSuppressState (const std::string &state)
 
     audioLayerMutexLock();
 
-    if (_audiodriver) {
+    if (_audiodriver)
         _audiodriver->setNoiseSuppressState (isEnabled);
-    }
 
     audioLayerMutexUnlock();
 }
@@ -2923,7 +2882,6 @@ void ManagerImpl::setNoiseSuppressState (const std::string &state)
 std::string ManagerImpl::getEchoCancelState() const
 {
 	// echo canceller disabled by default
-
 	return audioPreference.getEchoCancel() ? "enabled" : "disabled";
 }
 
@@ -2973,9 +2931,8 @@ bool ManagerImpl::initAudioDriver (void)
             preferences.setAudioApi (ALSA);
             _audiodriver->setMainBuffer (&_mainBuffer);
         }
-    } else {
+    } else
         _debug ("Error - Audio API unknown");
-    }
 
     if (_audiodriver == NULL) {
         _debug ("Manager: Init audio driver error");
@@ -3007,7 +2964,7 @@ void ManagerImpl::selectAudioDriver (void)
 
     audioLayerMutexLock();
 
-    if(_audiodriver == NULL) {
+    if (_audiodriver == NULL) {
     	_debug("Manager: Audio layer not initialized");
     	audioLayerMutexUnlock();
     	return;
@@ -3126,9 +3083,8 @@ void ManagerImpl::switchAudioManager (void)
 
     _debug ("Manager: Current device: %d ", type);
 
-    if (wasStarted) {
+    if (wasStarted)
         _audiodriver->startStream();
-    }
 
     audioLayerMutexUnlock();
 }
@@ -3240,22 +3196,16 @@ void ManagerImpl::initVolume ()
 
 void ManagerImpl::setSpkrVolume (unsigned short spkr_vol)
 {
-    PulseLayer *pulselayer = NULL;
-
     /* Set the manager sound volume */
     _spkr_volume = spkr_vol;
 
     audioLayerMutexLock();
 
     /* Only for PulseAudio */
-    pulselayer = dynamic_cast<PulseLayer*> (_audiodriver);
+    PulseLayer *pulselayer = dynamic_cast<PulseLayer*> (_audiodriver);
 
-    if (pulselayer) {
-        if (pulselayer->getLayerType() == PULSEAUDIO) {
-            if (pulselayer)
+    if (pulselayer and pulselayer->getLayerType() == PULSEAUDIO)
                 pulselayer->setPlaybackVolume (spkr_vol);
-        }
-    }
 
     audioLayerMutexUnlock();
 }
@@ -3272,113 +3222,6 @@ int ManagerImpl::getLocalIp2IpPort (void) const
 
 }
 
-// TODO: rewrite this
-/**
- * Main Thread
- */
-bool ManagerImpl::getCallStatus (const std::string& sequenceId UNUSED)
-{
-    ost::MutexLock m (_callAccountMapMutex);
-
-    CallAccountMap::iterator iter = _callAccountMap.begin();
-    TokenList tk;
-    std::string code;
-    std::string status;
-    std::string destination;
-    std::string number;
-
-    while (iter != _callAccountMap.end()) {
-        Call* call = getAccountLink (iter->second)->getCall (iter->first);
-        Call::ConnectionState state = call->getConnectionState();
-
-        if (state != Call::Connected) {
-            switch (state) {
-
-                case Call::Trying:
-                    code = "110";
-                    status = "Trying";
-                    break;
-
-                case Call::Ringing:
-                    code = "111";
-                    status = "Ringing";
-                    break;
-
-                case Call::Progressing:
-                    code = "125";
-                    status = "Progressing";
-                    break;
-
-                case Call::Disconnected:
-                    code = "125";
-                    status = "Disconnected";
-                    break;
-
-                default:
-                    code = "";
-                    status = "";
-            }
-        } else {
-            switch (call->getState()) {
-
-                case Call::Active:
-
-                case Call::Conferencing:
-                    code = "112";
-                    status = "Established";
-                    break;
-
-                case Call::Hold:
-                    code = "114";
-                    status = "Held";
-                    break;
-
-                case Call::Busy:
-                    code = "113";
-                    status = "Busy";
-                    break;
-
-                case Call::Refused:
-                    code = "125";
-                    status = "Refused";
-                    break;
-
-                case Call::Error:
-                    code = "125";
-                    status = "Error";
-                    break;
-
-                case Call::Inactive:
-                    code = "125";
-                    status = "Inactive";
-                    break;
-            }
-        }
-
-        // No Congestion
-        // No Wrong Number
-        // 116 <CSeq> <call-id> <acc> <destination> Busy
-        destination = call->getPeerName();
-
-        number = call->getPeerNumber();
-
-        if (number != "") {
-            destination.append (" <");
-            destination.append (number);
-            destination.append (">");
-        }
-
-        tk.push_back (iter->second);
-
-        tk.push_back (destination);
-        tk.push_back (status);
-        tk.clear();
-
-        iter++;
-    }
-
-    return true;
-}
 
 //THREAD=Main
 bool ManagerImpl::getConfig (const std::string& section,
@@ -3455,50 +3298,46 @@ void ManagerImpl::setAccountsOrder (const std::string& order)
 
 std::vector<std::string> ManagerImpl::getAccountList () const
 {
+    using std::vector;
+    using std::string;
     _debug ("Manager: Get account list");
-
-    std::vector<std::string> account_order(loadAccountOrder());
+    vector<string> account_order(loadAccountOrder());
 
     // The IP2IP profile is always available, and first in the list
-    AccountMap::const_iterator iter = _accountMap.find (IP2IP_PROFILE);
 
-    std::vector<std::string> v;
+    vector<string> v;
 
-    if (iter->second)
-        v.push_back (iter->second->getAccountID());
+    AccountMap::const_iterator ip2ip_iter = _accountMap.find (IP2IP_PROFILE);
+    if (ip2ip_iter->second)
+        v.push_back (ip2ip_iter->second->getAccountID());
     else
         _error ("Manager: could not find IP2IP profile in getAccount list");
 
     // If no order has been set, load the default one
     // ie according to the creation date.
 
-    if (account_order.size() == 0) {
+    if (account_order.empty()) {
         _debug ("Manager: account order is empty");
-        iter = _accountMap.begin();
-
-        while (iter != _accountMap.end()) {
-
-            if (iter->second != NULL && iter->first != IP2IP_PROFILE && iter->first != "") {
+        for (AccountMap::const_iterator iter = _accountMap.begin(); iter != _accountMap.end(); ++iter) {
+            if (iter->second != NULL and iter->first != IP2IP_PROFILE and not iter->first.empty()) {
                 _debug ("PUSHING BACK %s", iter->first.c_str());
                 v.push_back (iter->second->getAccountID());
             }
-
-            iter++;
         }
     }
-
-    // Otherelse, load the custom one
-    // ie according to the saved order
     else {
+        // otherwise, load the custom one
+        // ie according to the saved order
         _debug ("Manager: Load account list according to preferences");
 
-        for (size_t i = 0; i < account_order.size(); i++) {
+        for (vector<string>::const_iterator iter = account_order.begin(); iter != account_order.end(); ++iter) {
             // This account has not been loaded, so we ignore it
-            if ( (iter = _accountMap.find (account_order[i]))
-                    != _accountMap.end()) {
-                // If the account is valid
-                if (iter->second and iter->first not_eq IP2IP_PROFILE and not iter->first.empty())
-                    v.push_back (iter->second->getAccountID());
+            AccountMap::const_iterator account_iter = _accountMap.find (*iter);
+            if (account_iter != _accountMap.end()) {
+                if (account_iter->second and (account_iter->first not_eq IP2IP_PROFILE) and not account_iter->first.empty()) {
+                    // If the account is valid
+                    v.push_back (account_iter->second->getAccountID());
+                }
             }
         }
     }
@@ -3511,18 +3350,20 @@ std::map<std::string, std::string> ManagerImpl::getAccountDetails (
 {
     // Default account used to get default parameters if requested by client (to build new account)
     static const SIPAccount DEFAULT_ACCOUNT("default");
+
+    if (accountID.empty()) {
+        _debug ("Manager: Returning default account settings");
+        return DEFAULT_ACCOUNT.getAccountDetails();
+    }
+
     AccountMap::const_iterator iter = _accountMap.find(accountID);
     Account * account = 0;
     if (iter != _accountMap.end())
         account = iter->second;
 
-    if (accountID.empty()) {
-        _debug ("Manager: Returning default account settings");
-        // return a default map
-        return DEFAULT_ACCOUNT.getAccountDetails();
-    } else if (account) {
+    if (account)
         return account->getAccountDetails();
-    } else {
+    else {
         _debug ("Manager: Get account details on a non-existing accountID %s. Returning default", accountID.c_str());
         return DEFAULT_ACCOUNT.getAccountDetails();
     }
@@ -3534,7 +3375,6 @@ std::map<std::string, std::string> ManagerImpl::getAccountDetails (
 void ManagerImpl::setAccountDetails (const std::string& accountID,
                                      const std::map<std::string, std::string>& details)
 {
-
     _debug ("Manager: Set account details for %s", accountID.c_str());
 
     Account* account = getAccount(accountID);
@@ -3548,12 +3388,10 @@ void ManagerImpl::setAccountDetails (const std::string& accountID,
     // Serialize configuration to disk once it is done
     saveConfig();
 
-    if (account->isEnabled()) {
+    if (account->isEnabled())
         account->registerVoIPLink();
-    }
-    else {
+    else
         account->unregisterVoIPLink();
-    }
 
     // Update account details to the client side
     _dbus.getConfigurationManager()->accountsChanged();
@@ -3562,15 +3400,12 @@ void ManagerImpl::setAccountDetails (const std::string& accountID,
 std::string ManagerImpl::addAccount (
     const std::map<std::string, std::string>& details)
 {
-
     /** @todo Deal with both the _accountMap and the Configuration */
     std::string accountType, account_list;
-    Account* newAccount;
     std::stringstream accountID;
-    std::string newAccountID;
 
     accountID << "Account:" << time (NULL);
-    newAccountID = accountID.str();
+    std::string newAccountID(accountID.str());
 
     // Get the type
     accountType = (*details.find (CONFIG_ACCOUNT_TYPE)).second;
@@ -3579,6 +3414,7 @@ std::string ManagerImpl::addAccount (
 
     /** @todo Verify the uniqueness, in case a program adds accounts, two in a row. */
 
+    Account* newAccount;
     if (accountType == "SIP") {
         newAccount = AccountCreator::createAccount (AccountCreator::SIP_ACCOUNT,
                      newAccountID);
@@ -3587,7 +3423,8 @@ std::string ManagerImpl::addAccount (
         newAccount = AccountCreator::createAccount (AccountCreator::IAX_ACCOUNT,
                      newAccountID);
     } else {
-        _error ("Unknown %s param when calling addAccount(): %s", CONFIG_ACCOUNT_TYPE, accountType.c_str());
+        _error ("Unknown %s param when calling addAccount(): %s",
+                CONFIG_ACCOUNT_TYPE, accountType.c_str());
         return "";
     }
 
@@ -3598,11 +3435,10 @@ std::string ManagerImpl::addAccount (
     // Add the newly created account in the account order list
     account_list = preferences.getAccountOrder();
 
-    if (account_list != "") {
+    if (not account_list.empty()) {
         newAccountID += "/";
         // Prepend the new account
         account_list.insert (0, newAccountID);
-
         preferences.setAccountOrder (account_list);
     } else {
         newAccountID += "/";
@@ -3627,8 +3463,7 @@ std::string ManagerImpl::addAccount (
 void ManagerImpl::removeAccount (const std::string& accountID)
 {
     // Get it down and dying
-    Account* remAccount = NULL;
-    remAccount = getAccount (accountID);
+    Account* remAccount = getAccount (accountID);
 
     if (remAccount != NULL) {
         remAccount->unregisterVoIPLink();
@@ -3651,18 +3486,14 @@ void ManagerImpl::removeAccount (const std::string& accountID)
 bool ManagerImpl::associateCallToAccount (const std::string& callID,
         const std::string& accountID)
 {
-    if (getAccountFromCall (callID) == "") { // nothing with the same ID
-        if (accountExists (accountID)) { // account id exist in AccountMap
-            ost::MutexLock m (_callAccountMapMutex);
-            _callAccountMap[callID] = accountID;
-            _debug ("Manager: Associate Call %s with Account %s", callID.data(), accountID.data());
-            return true;
-        } else {
-            return false;
-        }
-    } else {
-        return false;
+    if (getAccountFromCall(callID).empty() and accountExists(accountID)) {
+        // account id exist in AccountMap
+        ost::MutexLock m (_callAccountMapMutex);
+        _callAccountMap[callID] = accountID;
+        _debug ("Manager: Associate Call %s with Account %s", callID.data(), accountID.data());
+        return true;
     }
+    return false;
 }
 
 std::string ManagerImpl::getAccountFromCall (const std::string& callID)
@@ -3670,36 +3501,23 @@ std::string ManagerImpl::getAccountFromCall (const std::string& callID)
     ost::MutexLock m (_callAccountMapMutex);
     CallAccountMap::iterator iter = _callAccountMap.find (callID);
 
-    if (iter == _callAccountMap.end()) {
+    if (iter == _callAccountMap.end())
         return "";
-    } else {
+    else
         return iter->second;
-    }
 }
 
 bool ManagerImpl::removeCallAccount (const std::string& callID)
 {
     ost::MutexLock m (_callAccountMapMutex);
 
-    if (_callAccountMap.erase (callID)) {
-        return true;
-    }
-
-    return false;
+    return _callAccountMap.erase (callID);
 }
 
 bool ManagerImpl::isValidCall(const std::string& callID)
 {
 	ost::MutexLock m(_callAccountMapMutex);
-	CallAccountMap::iterator iter = _callAccountMap.find (callID);
-
-	if(iter != _callAccountMap.end()) {
-		return true;
-	}
-	else {
-		return false;
-	}
-
+    return _callAccountMap.find (callID) != _callAccountMap.end();
 }
 
 std::string ManagerImpl::getNewCallID ()
@@ -3710,7 +3528,7 @@ std::string ManagerImpl::getNewCallID ()
     // when it's not found, it return ""
     // generate, something like s10000s20000s4394040
 
-    while (getAccountFromCall (random_id.str()) != "") {
+    while (not getAccountFromCall (random_id.str()).empty()) {
         random_id.clear();
         random_id << "s";
         random_id << (unsigned) rand();
@@ -3721,19 +3539,15 @@ std::string ManagerImpl::getNewCallID ()
 
 std::vector<std::string> ManagerImpl::loadAccountOrder (void) const
 {
-    std::string account_list;
-    std::vector<std::string> account_vect;
+    const std::string account_list(preferences.getAccountOrder());
 
-    account_list = preferences.getAccountOrder();
-
-    _debug ("Manager: Load sccount order %s", account_list.c_str());
+    _debug ("Manager: Load account order %s", account_list.c_str());
 
     return unserialize (account_list);
 }
 
 short ManagerImpl::buildConfiguration ()
 {
-
     _debug ("Manager: Loading account map");
 
     loadIptoipProfile();
@@ -3745,7 +3559,6 @@ short ManagerImpl::buildConfiguration ()
 
 void ManagerImpl::loadIptoipProfile()
 {
-
     _debug ("Manager: Create default \"account\" (used as default UDP transport)");
 
     // build a default IP2IP account with default parameters
@@ -3763,27 +3576,21 @@ void ManagerImpl::loadIptoipProfile()
 
         _debug ("Manager: Loading IP2IP profile preferences from config");
 
-        Conf::SequenceNode *seq = parser->getAccountSequence();
-
-        Conf::Sequence::iterator iterIP2IP = seq->getSequence()->begin();
-        std::string accID ("id");
+        Conf::SequenceNode *seq = parser_->getAccountSequence();
 
         // Iterate over every account maps
-        while (iterIP2IP != seq->getSequence()->end()) {
+        for (Conf::Sequence::const_iterator iterIP2IP = seq->getSequence()->begin(); iterIP2IP != seq->getSequence()->end(); ++iterIP2IP) {
 
             Conf::MappingNode *map = (Conf::MappingNode *) (*iterIP2IP);
 
-            // Get the account id
             std::string accountid;
-            map->getValue (accID, &accountid);
+            map->getValue ("id", &accountid);
 
             // if ID is IP2IP, unserialize
             if (accountid == "IP2IP") {
                 _directIpAccount->unserialize (map);
                 break;
             }
-
-            iterIP2IP++;
         }
     }
 
@@ -3804,7 +3611,6 @@ short ManagerImpl::loadAccountMap()
 {
     _debug ("Manager: Load account map");
 
-    // Conf::YamlParser *parser;
     int nbAccount = 0;
 
     if (!_setupLoaded) {
@@ -3813,14 +3619,14 @@ short ManagerImpl::loadAccountMap()
     }
 
     // build preferences
-    preferences.unserialize (parser->getPreferenceNode());
-    voipPreferences.unserialize (parser->getVoipPreferenceNode());
-    addressbookPreference.unserialize (parser->getAddressbookNode());
-    hookPreference.unserialize (parser->getHookNode());
-    audioPreference.unserialize (parser->getAudioNode());
-    shortcutPreferences.unserialize (parser->getShortcutNode());
+    preferences.unserialize (parser_->getPreferenceNode());
+    voipPreferences.unserialize (parser_->getVoipPreferenceNode());
+    addressbookPreference.unserialize (parser_->getAddressbookNode());
+    hookPreference.unserialize (parser_->getHookNode());
+    audioPreference.unserialize (parser_->getAudioNode());
+    shortcutPreferences.unserialize (parser_->getShortcutNode());
 
-    Conf::SequenceNode *seq = parser->getAccountSequence();
+    Conf::SequenceNode *seq = parser_->getAccountSequence();
 
     // Each element in sequence is a new account to create
     Conf::Sequence::iterator iterSeq;
@@ -3865,15 +3671,14 @@ short ManagerImpl::loadAccountMap()
     }
 
     try {
-        delete parser;
+        delete parser_;
     } catch (Conf::YamlParserException &e) {
         _error ("Manager: %s", e.what());
     }
 
-    parser = NULL;
+    parser_ = NULL;
 
     return nbAccount;
-
 }
 
 void ManagerImpl::unloadAccountMap ()
@@ -4127,7 +3932,7 @@ std::map<std::string, std::string> ManagerImpl::getCallDetails (const std::strin
 
 std::vector<std::string> ManagerImpl::getHistorySerialized(void) const
 {
-    _debug("Manager: Get history serialized"); 
+    _debug("Manager: Get history serialized");
 
     return _history->get_history_serialized();
 }
@@ -4142,7 +3947,7 @@ void ManagerImpl::setHistorySerialized(std::vector<std::string> history)
 }
 
 namespace {
-template <typename M, typename V> 
+template <typename M, typename V>
 void vectorFromMapKeys(const M &m, V &v)
 {
     for (typename M::const_iterator it = m.begin(); it != m.end(); ++it )
@@ -4153,7 +3958,7 @@ void vectorFromMapKeys(const M &m, V &v)
 std::vector<std::string> ManagerImpl::getCallList (void) const
 {
     std::vector<std::string> v;
-    vectorFromMapKeys(_callAccountMap, v); 
+    vectorFromMapKeys(_callAccountMap, v);
     return v;
 }
 
@@ -4165,12 +3970,9 @@ std::map<std::string, std::string> ManagerImpl::getConferenceDetails (
 
     iter_conf = _conferencemap.find (confID);
 
-    Conference* conf = NULL;
-
     if (iter_conf != _conferencemap.end()) {
-        conf = iter_conf->second;
         conf_details["CONFID"] = confID;
-        conf_details["CONF_STATE"] = conf->getStateStr();
+        conf_details["CONF_STATE"] = iter_conf->second->getStateStr();
     }
 
     return conf_details;
diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h
index 437db5c8ca..2e1b3181d6 100644
--- a/daemon/src/managerimpl.h
+++ b/daemon/src/managerimpl.h
@@ -478,8 +478,6 @@ class ManagerImpl
          */
         void sendRegister (const ::std::string& accountId , const int32_t& enable);
 
-        bool getCallStatus (const std::string& sequenceId);
-
         /**
          * Get account list
          * @return std::vector<std::string> A list of accoundIDs
@@ -491,12 +489,6 @@ class ManagerImpl
          */
         void setAccountsOrder (const std::string& order);
 
-        /**
-         * Load the accounts order set by the user from the sflphonedrc config file
-         * @return std::vector<std::string> A vector containing the account ID's
-         */
-        std::vector<std::string> loadAccountOrder () const;
-
         /**
          * Retrieve details about a given account
          * @param accountID	  The account identifier
@@ -736,7 +728,7 @@ class ManagerImpl
          * Set the maximum number of days to keep in the history
          * @param calls The number of days
          */
-        void setHistoryLimit (const int& days);
+        void setHistoryLimit (int days);
 
         /**
          * Get the maximum number of days to keep in the history
@@ -805,7 +797,7 @@ class ManagerImpl
         /**
          * Set the audio manager
          */
-        void setAudioManager (const int32_t& api);
+        void setAudioManager (int32_t api);
 
         void switchAudioManager (void);
 
@@ -832,7 +824,7 @@ class ManagerImpl
          * @param errCode The error code. Could be: ALSA_CAPTURE_ERROR
          *					       ALSA_PLAYBACK_ERROR
          */
-        void notifyErrClient (const int32_t& errCode);
+        void notifyErrClient (int32_t errCode);
 
         /**
          * Retrieve in the configuration tree the value of a parameter in a specific section
@@ -1057,7 +1049,13 @@ class ManagerImpl
          */
         void audioLayerMutexUnlock(void) { _audiolayerMutex.leaveMutex(); }
 
+        /**
+         * Load the accounts order set by the user from the sflphonedrc config file
+         * @return std::vector<std::string> A vector containing the account ID's
+         */
+        std::vector<std::string> loadAccountOrder () const;
     private:
+
         /**
          * Create config directory in home user and return configuration file path
          */
@@ -1362,7 +1360,7 @@ class ManagerImpl
          */
         void checkCallConfiguration (const std::string& id, const std::string& to, Call::CallConfiguration *callConfig);
 
-        Conf::YamlParser *parser;
+        Conf::YamlParser *parser_;
         Conf::YamlEmitter *emitter;
 
         friend class SIPTest;
-- 
GitLab