Skip to content
Snippets Groups Projects
Commit 2fac5754 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #6699: refactor/cleanup accounts

parent 449c8e38
Branches
Tags
No related merge requests found
...@@ -100,3 +100,23 @@ void Account::setActiveCodecs (const std::vector <std::string> &list) ...@@ -100,3 +100,23 @@ void Account::setActiveCodecs (const std::vector <std::string> &list)
// update the codec string according to new codec selection // update the codec string according to new codec selection
codecStr_ = ManagerImpl::serialize (list); 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];
}
...@@ -59,7 +59,7 @@ enum RegistrationState { ...@@ -59,7 +59,7 @@ enum RegistrationState {
ErrorHost, ErrorHost,
ErrorExistStun, ErrorExistStun,
ErrorConfStun, ErrorConfStun,
NumberOfState NumberOfStates
}; };
// Account identifier // Account identifier
...@@ -307,6 +307,7 @@ class Account : public Serializable ...@@ -307,6 +307,7 @@ class Account : public Serializable
void loadDefaultCodecs (void); void loadDefaultCodecs (void);
protected: protected:
static std::string mapStateNumberToString (RegistrationState state);
/** /**
* Account ID are assign in constructor and shall not changed * Account ID are assign in constructor and shall not changed
......
...@@ -32,11 +32,12 @@ ...@@ -32,11 +32,12 @@
#include "config.h" #include "config.h"
#include <configurationmanager.h> #include "configurationmanager.h"
#include <sstream> #include <sstream>
#include "config.h" #include "config.h"
#include "../manager.h" #include "../manager.h"
#include "sip/sipvoiplink.h" #include "sip/sipvoiplink.h"
#include "account.h"
#include "sip/sipaccount.h" #include "sip/sipaccount.h"
const char* ConfigurationManager::SERVER_PATH = const char* ConfigurationManager::SERVER_PATH =
...@@ -55,7 +56,7 @@ ConfigurationManager::ConfigurationManager (DBus::Connection& connection) : ...@@ -55,7 +56,7 @@ ConfigurationManager::ConfigurationManager (DBus::Connection& connection) :
std::map<std::string, std::string> ConfigurationManager::getIp2IpDetails (void) std::map<std::string, std::string> ConfigurationManager::getIp2IpDetails (void)
{ {
std::map<std::string, std::string> ip2ipAccountDetails; 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) { if (!sipaccount) {
_error ("ConfigurationManager: could not find account"); _error ("ConfigurationManager: could not find account");
return ip2ipAccountDetails; return ip2ipAccountDetails;
......
...@@ -137,7 +137,7 @@ std::map<std::string, std::string> IAXAccount::getAccountDetails() const ...@@ -137,7 +137,7 @@ std::map<std::string, std::string> IAXAccount::getAccountDetails() const
RegistrationState state(registrationState_); RegistrationState state(registrationState_);
a[REGISTRATION_STATUS] = Manager::instance().mapStateNumberToString (state); a[REGISTRATION_STATUS] = mapStateNumberToString (state);
a[USERAGENT] = userAgent_; a[USERAGENT] = userAgent_;
return a; return a;
......
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
*/ */
#include "iaxcall.h" #include "iaxcall.h"
#include "account.h"
#include "manager.h" #include "manager.h"
#include "global.h" // for _debug
IAXCall::IAXCall (const std::string& id, Call::CallType type) : Call (id, type), _session (NULL) IAXCall::IAXCall (const std::string& id, Call::CallType type) : Call (id, type), _session (NULL)
{ {
...@@ -85,25 +85,22 @@ IAXCall::setFormat (int format) ...@@ -85,25 +85,22 @@ IAXCall::setFormat (int format)
int int
IAXCall::getSupportedFormat (std::string accountID) IAXCall::getSupportedFormat (const std::string &accountID) const
{ {
CodecOrder map; CodecOrder map;
int format = 0;
unsigned int iter;
Account *account;
_info ("IAX get supported format: "); _info ("IAX get supported format: ");
account = Manager::instance().getAccount (accountID); Account *account = Manager::instance().getAccount (accountID);
if (account != NULL) { if (account)
map = account->getActiveCodecs(); map = account->getActiveCodecs();
} else { else
_error ("No IAx account could be found"); _error ("No IAx account could be found");
}
for (iter=0 ; iter < map.size() ; iter++) { int format = 0;
switch (map[iter]) { for (size_t i = 0; i != map.size() ; ++i) {
switch (map[i]) {
case PAYLOAD_CODEC_ULAW: case PAYLOAD_CODEC_ULAW:
_info ("PCMU "); _info ("PCMU ");
...@@ -136,20 +133,17 @@ IAXCall::getSupportedFormat (std::string accountID) ...@@ -136,20 +133,17 @@ IAXCall::getSupportedFormat (std::string accountID)
} }
return format; return format;
} }
int IAXCall::getFirstMatchingFormat (int needles, std::string accountID) int IAXCall::getFirstMatchingFormat (int needles, const std::string &accountID) const
{ {
Account *account;
CodecOrder map; CodecOrder map;
int format = 0; int format = 0;
unsigned int iter; unsigned int iter;
_debug ("IAX get first matching codec: "); _debug ("IAX get first matching codec: ");
account = Manager::instance().getAccount (accountID); Account *account = Manager::instance().getAccount (accountID);
if (account != NULL) { if (account != NULL) {
map = account->getActiveCodecs(); map = account->getActiveCodecs();
...@@ -159,7 +153,6 @@ int IAXCall::getFirstMatchingFormat (int needles, std::string accountID) ...@@ -159,7 +153,6 @@ int IAXCall::getFirstMatchingFormat (int needles, std::string accountID)
for (iter=0 ; iter < map.size() ; iter++) { for (iter=0 ; iter < map.size() ; iter++) {
switch (map[iter]) { switch (map[iter]) {
case PAYLOAD_CODEC_ULAW: case PAYLOAD_CODEC_ULAW:
_debug ("PCMU"); _debug ("PCMU");
format = AST_FORMAT_ULAW; format = AST_FORMAT_ULAW;
......
...@@ -34,13 +34,11 @@ ...@@ -34,13 +34,11 @@
#include "call.h" #include "call.h"
#include "audio/codecs/audiocodecfactory.h" #include "audio/codecs/audiocodecfactory.h"
#include <iax-client.h>
#include <frame.h>
/** /**
* @file: iaxcall.h * @file: iaxcall.h
* @brief IAXCall are IAX implementation of a normal Call * @brief IAXCall are IAX implementation of a normal Call
*/ */
class iax_session;
class IAXCall : public Call class IAXCall : public Call
{ {
...@@ -60,7 +58,7 @@ class IAXCall : public Call ...@@ -60,7 +58,7 @@ class IAXCall : public Call
/** /**
* @return iax_session* The session pointer or NULL * @return iax_session* The session pointer or NULL
*/ */
struct iax_session* getSession() { iax_session* getSession() const {
return _session; return _session;
} }
...@@ -68,7 +66,7 @@ class IAXCall : public Call ...@@ -68,7 +66,7 @@ class IAXCall : public Call
* Set the session pointer * Set the session pointer
* @param session the session pointer to assign * @param session the session pointer to assign
*/ */
void setSession (struct iax_session* session) { void setSession (iax_session* session) {
_session = session; _session = session;
} }
...@@ -84,7 +82,7 @@ class IAXCall : public Call ...@@ -84,7 +82,7 @@ class IAXCall : public Call
* Get format for the voice codec used * Get format for the voice codec used
* @return int Bitmask for codecs defined in iax/frame.h * @return int Bitmask for codecs defined in iax/frame.h
*/ */
int getFormat() { int getFormat() const {
return _format; return _format;
} }
...@@ -92,7 +90,7 @@ class IAXCall : public Call ...@@ -92,7 +90,7 @@ class IAXCall : public Call
/** /**
* @return int The bitwise list of supported formats * @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. * Return a format (int) with the first matching codec selected.
...@@ -107,7 +105,7 @@ class IAXCall : public Call ...@@ -107,7 +105,7 @@ class IAXCall : public Call
* @param needles The format(s) (bitwise) you are looking for to match * @param needles The format(s) (bitwise) you are looking for to match
* @return int The matching format, thus 0 if none matches * @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 // AUDIO
/** /**
...@@ -132,7 +130,7 @@ class IAXCall : public Call ...@@ -132,7 +130,7 @@ class IAXCall : public Call
private: private:
/** Each call is associated with an iax_session */ /** Each call is associated with an iax_session */
struct iax_session* _session; iax_session* _session;
/** /**
* Set the audio codec used. [not protected] * Set the audio codec used. [not protected]
......
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
#include "config/config.h" #include "config/config.h"
#include "account.h"
#include "call.h" #include "call.h"
#include "conference.h" #include "conference.h"
#include "numbercleaner.h" #include "numbercleaner.h"
...@@ -73,7 +72,7 @@ class DNSService; ...@@ -73,7 +72,7 @@ class DNSService;
#endif #endif
class HistoryManager; class HistoryManager;
class SIPAccount; class Account;
/** Define a type for a AccountMap container */ /** Define a type for a AccountMap container */
typedef std::map<std::string, Account*> AccountMap; typedef std::map<std::string, Account*> AccountMap;
...@@ -98,18 +97,6 @@ typedef std::map<std::string, Conference*> ConferenceMap; ...@@ -98,18 +97,6 @@ typedef std::map<std::string, Conference*> ConferenceMap;
static std::string default_conf = "conf"; 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 */ /** Manager (controller) of sflphone daemon */
class ManagerImpl class ManagerImpl
{ {
...@@ -824,18 +811,6 @@ class ManagerImpl ...@@ -824,18 +811,6 @@ class ManagerImpl
*/ */
bool setConfig (const std::string& section, const std::string& name, int value); 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 * Get a int from the configuration tree
* Throw an Conf::ConfigTreeItemException if not found * Throw an Conf::ConfigTreeItemException if not found
......
...@@ -468,7 +468,7 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const ...@@ -468,7 +468,7 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const
registrationStateDescription = registrationStateDetailed_.second; 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_CODE] = registrationStateCode;
a[REGISTRATION_STATE_DESCRIPTION] = registrationStateDescription; a[REGISTRATION_STATE_DESCRIPTION] = registrationStateDescription;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/HelperMacros.h>
#include <map> #include <map>
#include "account.h"
#include "accounttest.h" #include "accounttest.h"
#include "manager.h" #include "manager.h"
#include "logger.h" #include "logger.h"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment