Commit 2fac5754 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #6699: refactor/cleanup accounts

parent 449c8e38
......@@ -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];
}
......@@ -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
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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]
......
......@@ -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
......
......@@ -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;
......
......@@ -30,6 +30,7 @@
#include <cppunit/extensions/HelperMacros.h>
#include <map>
#include "account.h"
#include "accounttest.h"
#include "manager.h"
#include "logger.h"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment