diff --git a/daemon/src/account.cpp b/daemon/src/account.cpp index 95f82c493818264855cc16b5f3280d6ffb26a433..2f67a497ad851cb7e38a052aa5bb2e0fa4e8d778 100644 --- a/daemon/src/account.cpp +++ b/daemon/src/account.cpp @@ -100,3 +100,23 @@ void Account::setActiveCodecs (const std::vector <std::string> &list) // update the codec string according to new codec selection codecStr_ = ManagerImpl::serialize (list); } + +std::string Account::mapStateNumberToString(RegistrationState state) +{ + static const char * mapStateToChar[] = { + "UNREGISTERED", + "TRYING", + "REGISTERED", + "ERROR", + "ERRORAUTH", + "ERRORNETWORK", + "ERRORHOST", + "ERROREXISTSTUN", + "ERRORCONFSTUN" + }; + + if (state > NumberOfStates) + return "ERROR"; + + return mapStateToChar[state]; +} diff --git a/daemon/src/account.h b/daemon/src/account.h index f2898227cde8e857d81975418f68f7893c4da967..0af1ca207bc98c2955e7edd2ab2fbf81e10fb8e1 100644 --- a/daemon/src/account.h +++ b/daemon/src/account.h @@ -59,7 +59,7 @@ enum RegistrationState { ErrorHost, ErrorExistStun, ErrorConfStun, - NumberOfState + NumberOfStates }; // Account identifier @@ -307,6 +307,7 @@ class Account : public Serializable void loadDefaultCodecs (void); protected: + static std::string mapStateNumberToString (RegistrationState state); /** * Account ID are assign in constructor and shall not changed diff --git a/daemon/src/dbus/configurationmanager.cpp b/daemon/src/dbus/configurationmanager.cpp index ae379c092aa4f679e42ddb1aad7be4c4db17978b..495e63dea6cc94e1926316394fa0b13ca4e5777d 100644 --- a/daemon/src/dbus/configurationmanager.cpp +++ b/daemon/src/dbus/configurationmanager.cpp @@ -32,11 +32,12 @@ #include "config.h" -#include <configurationmanager.h> +#include "configurationmanager.h" #include <sstream> #include "config.h" #include "../manager.h" #include "sip/sipvoiplink.h" +#include "account.h" #include "sip/sipaccount.h" const char* ConfigurationManager::SERVER_PATH = @@ -55,7 +56,7 @@ ConfigurationManager::ConfigurationManager (DBus::Connection& connection) : std::map<std::string, std::string> ConfigurationManager::getIp2IpDetails (void) { std::map<std::string, std::string> ip2ipAccountDetails; - SIPAccount *sipaccount = (SIPAccount *) Manager::instance().getAccount (IP2IP_PROFILE); + SIPAccount *sipaccount = static_cast<SIPAccount *>(Manager::instance().getAccount (IP2IP_PROFILE)); if (!sipaccount) { _error ("ConfigurationManager: could not find account"); return ip2ipAccountDetails; diff --git a/daemon/src/iax/iaxaccount.cpp b/daemon/src/iax/iaxaccount.cpp index 71ddb8d68a24b58df77cd27cc1dff1ea48ff54c4..16d1619baa715ac26ca0999c8efc9f6519c66ac4 100644 --- a/daemon/src/iax/iaxaccount.cpp +++ b/daemon/src/iax/iaxaccount.cpp @@ -137,7 +137,7 @@ std::map<std::string, std::string> IAXAccount::getAccountDetails() const RegistrationState state(registrationState_); - a[REGISTRATION_STATUS] = Manager::instance().mapStateNumberToString (state); + a[REGISTRATION_STATUS] = mapStateNumberToString (state); a[USERAGENT] = userAgent_; return a; diff --git a/daemon/src/iax/iaxcall.cpp b/daemon/src/iax/iaxcall.cpp index 72d4741cd1ba5aacdee9635210cdca148f37a112..9c743fc74a84fcc83e141728fb396ac6c21ba6e6 100644 --- a/daemon/src/iax/iaxcall.cpp +++ b/daemon/src/iax/iaxcall.cpp @@ -30,8 +30,8 @@ */ #include "iaxcall.h" +#include "account.h" #include "manager.h" -#include "global.h" // for _debug IAXCall::IAXCall (const std::string& id, Call::CallType type) : Call (id, type), _session (NULL) { @@ -85,25 +85,22 @@ IAXCall::setFormat (int format) int -IAXCall::getSupportedFormat (std::string accountID) +IAXCall::getSupportedFormat (const std::string &accountID) const { CodecOrder map; - int format = 0; - unsigned int iter; - Account *account; _info ("IAX get supported format: "); - account = Manager::instance().getAccount (accountID); + Account *account = Manager::instance().getAccount (accountID); - if (account != NULL) { + if (account) map = account->getActiveCodecs(); - } else { + else _error ("No IAx account could be found"); - } - for (iter=0 ; iter < map.size() ; iter++) { - switch (map[iter]) { + int format = 0; + for (size_t i = 0; i != map.size() ; ++i) { + switch (map[i]) { case PAYLOAD_CODEC_ULAW: _info ("PCMU "); @@ -136,20 +133,17 @@ IAXCall::getSupportedFormat (std::string accountID) } return format; - } -int IAXCall::getFirstMatchingFormat (int needles, std::string accountID) +int IAXCall::getFirstMatchingFormat (int needles, const std::string &accountID) const { - - Account *account; CodecOrder map; int format = 0; unsigned int iter; _debug ("IAX get first matching codec: "); - account = Manager::instance().getAccount (accountID); + Account *account = Manager::instance().getAccount (accountID); if (account != NULL) { map = account->getActiveCodecs(); @@ -159,7 +153,6 @@ int IAXCall::getFirstMatchingFormat (int needles, std::string accountID) for (iter=0 ; iter < map.size() ; iter++) { switch (map[iter]) { - case PAYLOAD_CODEC_ULAW: _debug ("PCMU"); format = AST_FORMAT_ULAW; diff --git a/daemon/src/iax/iaxcall.h b/daemon/src/iax/iaxcall.h index 30d75ee2b89c95020ed1660f3bb8b77f13d1b72c..432d3588ffaca9d510cc1458aafb354cfd6e5a92 100644 --- a/daemon/src/iax/iaxcall.h +++ b/daemon/src/iax/iaxcall.h @@ -34,13 +34,11 @@ #include "call.h" #include "audio/codecs/audiocodecfactory.h" -#include <iax-client.h> -#include <frame.h> - /** * @file: iaxcall.h * @brief IAXCall are IAX implementation of a normal Call */ +class iax_session; class IAXCall : public Call { @@ -60,7 +58,7 @@ class IAXCall : public Call /** * @return iax_session* The session pointer or NULL */ - struct iax_session* getSession() { + iax_session* getSession() const { return _session; } @@ -68,7 +66,7 @@ class IAXCall : public Call * Set the session pointer * @param session the session pointer to assign */ - void setSession (struct iax_session* session) { + void setSession (iax_session* session) { _session = session; } @@ -84,7 +82,7 @@ class IAXCall : public Call * Get format for the voice codec used * @return int Bitmask for codecs defined in iax/frame.h */ - int getFormat() { + int getFormat() const { return _format; } @@ -92,7 +90,7 @@ class IAXCall : public Call /** * @return int The bitwise list of supported formats */ - int getSupportedFormat (std::string accountID); + int getSupportedFormat (const std::string &accountID) const; /** * Return a format (int) with the first matching codec selected. @@ -107,7 +105,7 @@ class IAXCall : public Call * @param needles The format(s) (bitwise) you are looking for to match * @return int The matching format, thus 0 if none matches */ - int getFirstMatchingFormat (int needles, std::string accountID); + int getFirstMatchingFormat (int needles, const std::string &accountID) const; // AUDIO /** @@ -132,7 +130,7 @@ class IAXCall : public Call private: /** Each call is associated with an iax_session */ - struct iax_session* _session; + iax_session* _session; /** * Set the audio codec used. [not protected] diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index d5077d3c06d2a90b48610e827956899e6f0f5d76..3dabaf6e1f698c99b40a957c5974fd82386cf3d3 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -44,7 +44,6 @@ #include "config/config.h" -#include "account.h" #include "call.h" #include "conference.h" #include "numbercleaner.h" @@ -73,7 +72,7 @@ class DNSService; #endif class HistoryManager; -class SIPAccount; +class Account; /** Define a type for a AccountMap container */ typedef std::map<std::string, Account*> AccountMap; @@ -98,18 +97,6 @@ typedef std::map<std::string, Conference*> ConferenceMap; static std::string default_conf = "conf"; -static char * mapStateToChar[] = { - (char*) "UNREGISTERED", - (char*) "TRYING", - (char*) "REGISTERED", - (char*) "ERROR", - (char*) "ERRORAUTH", - (char*) "ERRORNETWORK", - (char*) "ERRORHOST", - (char*) "ERROREXISTSTUN", - (char*) "ERRORCONFSTUN" -}; - /** Manager (controller) of sflphone daemon */ class ManagerImpl { @@ -824,18 +811,6 @@ class ManagerImpl */ bool setConfig (const std::string& section, const std::string& name, int value); - std::string mapStateNumberToString (RegistrationState state) const { - std::string stringRepresentation; - - if (state > NumberOfState) { - stringRepresentation = "ERROR"; - return stringRepresentation; - } - - stringRepresentation = mapStateToChar[state]; - return stringRepresentation; - } - /** * Get a int from the configuration tree * Throw an Conf::ConfigTreeItemException if not found diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index 9bc7c808d44995ecb8d8e66ea161491fe13c81fb..324582022d69dd359b9af3cbd494d23f4f1ccfad 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -468,7 +468,7 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const registrationStateDescription = registrationStateDetailed_.second; } - a[REGISTRATION_STATUS] = (accountID_ == IP2IP_PROFILE) ? "READY": Manager::instance().mapStateNumberToString (state); + a[REGISTRATION_STATUS] = (accountID_ == IP2IP_PROFILE) ? "READY": mapStateNumberToString (state); a[REGISTRATION_STATE_CODE] = registrationStateCode; a[REGISTRATION_STATE_DESCRIPTION] = registrationStateDescription; diff --git a/daemon/test/accounttest.cpp b/daemon/test/accounttest.cpp index 1acc7f0d013dc3ed1bf0c262a0a22d8914228092..c75eeaf8a4dc19c10314d4c052742478183892fb 100644 --- a/daemon/test/accounttest.cpp +++ b/daemon/test/accounttest.cpp @@ -30,6 +30,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <map> +#include "account.h" #include "accounttest.h" #include "manager.h" #include "logger.h"