Skip to content
Snippets Groups Projects
Commit ee09fc14 authored by yanmorin's avatar yanmorin
Browse files

First Account-based save/load implementation
parent 2c74a005
No related branches found
No related tags found
No related merge requests found
...@@ -32,5 +32,3 @@ Account::~Account() ...@@ -32,5 +32,3 @@ Account::~Account()
{ {
delete _link; _link = 0; delete _link; _link = 0;
} }
...@@ -20,10 +20,14 @@ ...@@ -20,10 +20,14 @@
#define ACCOUNT_H #define ACCOUNT_H
#include <string> #include <string>
#include "config/config.h"
class VoIPLink; class VoIPLink;
typedef std::string AccountID; typedef std::string AccountID;
#define AccountNULL "" #define AccountNULL ""
#define CONFIG_ACCOUNT_TYPE "Account.type"
#define CONFIG_ACCOUNT_ENABLE "Account.enable"
/** /**
@author Yan Morin @author Yan Morin
...@@ -37,6 +41,11 @@ public: ...@@ -37,6 +41,11 @@ public:
~Account(); ~Account();
/**
* Load the default properties for the account
*/
virtual void initConfig(Conf::ConfigTree& config) = 0;
/** /**
* Register the account * Register the account
* @return false is an error occurs * @return false is an error occurs
...@@ -69,10 +78,6 @@ private: ...@@ -69,10 +78,6 @@ private:
*/ */
virtual bool createVoIPLink() = 0; virtual bool createVoIPLink() = 0;
/**
* Account ID are assign in constructor and shall not changed
*/
AccountID _accountID;
/** /**
* Voice over IP Link contains a listener thread and calls * Voice over IP Link contains a listener thread and calls
*/ */
...@@ -95,6 +100,13 @@ private: ...@@ -95,6 +100,13 @@ private:
* Modified by unregister/register * Modified by unregister/register
*/ */
bool _registered; bool _registered;
protected:
/**
* Account ID are assign in constructor and shall not changed
*/
AccountID _accountID;
}; };
#endif #endif
...@@ -59,4 +59,16 @@ AIXAccount::terminate() ...@@ -59,4 +59,16 @@ AIXAccount::terminate()
return false; return false;
} }
void
AIXAccount::initConfig(Conf::ConfigTree& config)
{
std::string section(_accountID);
std::string type_str("string");
std::string type_int("int");
config.addConfigTreeItem(section, Conf::ConfigTreeItem(CONFIG_ACCOUNT_TYPE, "AIX", type_str));
config.addConfigTreeItem(section, Conf::ConfigTreeItem(CONFIG_ACCOUNT_ENABLE, "1", type_int));
config.addConfigTreeItem(section, Conf::ConfigTreeItem("AIX.Proxy", "", type_str));
}
...@@ -33,6 +33,7 @@ public: ...@@ -33,6 +33,7 @@ public:
~AIXAccount(); ~AIXAccount();
/* virtual Account function implementation */ /* virtual Account function implementation */
void initConfig(Conf::ConfigTree& config);
bool registerAccount(); bool registerAccount();
bool unregisterAccount(); bool unregisterAccount();
bool init(); bool init();
......
...@@ -89,6 +89,16 @@ ManagerImpl::ManagerImpl (void) ...@@ -89,6 +89,16 @@ ManagerImpl::ManagerImpl (void)
_hasTriedToRegister = false; _hasTriedToRegister = false;
// initialize random generator for call id // initialize random generator for call id
srand (time(NULL)); srand (time(NULL));
#ifdef TEST
testAccountMap();
loadAccountMap();
testCallAccountMap();
unloadAccountMap();
#endif
// should be call before initConfigFile
loadAccountMap();
} }
// never call if we use only the singleton... // never call if we use only the singleton...
...@@ -106,12 +116,6 @@ ManagerImpl::~ManagerImpl (void) ...@@ -106,12 +116,6 @@ ManagerImpl::~ManagerImpl (void)
void void
ManagerImpl::init() ManagerImpl::init()
{ {
#ifdef TEST
testAccountMap();
loadAccountMap();
testCallAccountMap();
unloadAccountMap();
#endif
initVolume(); initVolume();
if (_exist == 0) { if (_exist == 0) {
...@@ -157,7 +161,6 @@ ManagerImpl::init() ...@@ -157,7 +161,6 @@ ManagerImpl::init()
// Set a sip voip link by default // Set a sip voip link by default
_voIPLinkVector.push_back(new SipVoIPLink()); _voIPLinkVector.push_back(new SipVoIPLink());
loadAccountMap();
// initRegisterVoIP was here, but we doing it after the gui loaded... // initRegisterVoIP was here, but we doing it after the gui loaded...
// the stun detection is long, so it's a better idea to do it after getEvents // the stun detection is long, so it's a better idea to do it after getEvents
initZeroconf(); initZeroconf();
...@@ -1270,6 +1273,8 @@ ManagerImpl::initConfigFile (void) ...@@ -1270,6 +1273,8 @@ ManagerImpl::initConfigFile (void)
fill_config_str(VOICEMAIL_NUM, DFT_VOICEMAIL); fill_config_str(VOICEMAIL_NUM, DFT_VOICEMAIL);
fill_config_int(CONFIG_ZEROCONF, CONFIG_ZEROCONF_DEFAULT_STR); fill_config_int(CONFIG_ZEROCONF, CONFIG_ZEROCONF_DEFAULT_STR);
initConfigAccount();
_exist = createSettingsPath(); _exist = createSettingsPath();
_setupLoaded = (_exist == 2 ) ? false : true; _setupLoaded = (_exist == 2 ) ? false : true;
} }
...@@ -1839,22 +1844,15 @@ ManagerImpl::getNewCallID() ...@@ -1839,22 +1844,15 @@ ManagerImpl::getNewCallID()
return random_id; return random_id;
} }
AccountMap _accountMap;
short short
ManagerImpl::loadAccountMap() ManagerImpl::loadAccountMap()
{ {
short nbAccount = 0; short nbAccount = 0;
_accountMap[ACCOUNT_SIP0] = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, ACCOUNT_SIP0);
AccountID accID = "acc0";
_accountMap[accID] = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, accID);
nbAccount++; nbAccount++;
accID = "acc1"; _accountMap[ACCOUNT_AIX0] = AccountCreator::createAccount(AccountCreator::AIX_ACCOUNT, ACCOUNT_AIX0);
_accountMap[accID] = AccountCreator::createAccount(AccountCreator::AIX_ACCOUNT, accID);
nbAccount++; nbAccount++;
return nbAccount; return nbAccount;
...@@ -1891,6 +1889,17 @@ ManagerImpl::getAccount(AccountID accountID) ...@@ -1891,6 +1889,17 @@ ManagerImpl::getAccount(AccountID accountID)
return iter->second; return iter->second;
} }
void
ManagerImpl::initConfigAccount() {
AccountMap::iterator iter = _accountMap.begin();
while ( iter != _accountMap.end() ) {
if (iter!=0 && iter->second!=0) {
iter->second->initConfig(_config);
}
iter++;
}
}
#ifdef TEST #ifdef TEST
/** /**
* Test accountMap * Test accountMap
......
...@@ -486,6 +486,12 @@ private: ...@@ -486,6 +486,12 @@ private:
*/ */
Account* getAccount(AccountID accountID); Account* getAccount(AccountID accountID);
/**
* load default account variable for each protocol
*/
void initConfigAccount();
#ifdef TEST #ifdef TEST
bool testCallAccountMap(); bool testCallAccountMap();
bool testAccountMap(); bool testAccountMap();
......
...@@ -17,6 +17,16 @@ ...@@ -17,6 +17,16 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include "sipaccount.h" #include "sipaccount.h"
#define SIP_FULL_NAME "SIP.fullName"
#define SIP_USER_PART "SIP.userPart"
#define SIP_AUTH_USER_NAME "SIP.username"
#define SIP_PASSWORD "SIP.password"
#define SIP_HOST_PART "SIP.hostPart"
#define SIP_PROXY "SIP.proxy"
#define SIP_AUTO_REGISTER "SIP.autoregister"
#define SIP_STUN_SERVER "STUN.STUNserver"
#define SIP_USE_STUN "STUN.useStun"
SIPAccount::SIPAccount(const AccountID& accountID) SIPAccount::SIPAccount(const AccountID& accountID)
: Account(accountID) : Account(accountID)
...@@ -59,3 +69,21 @@ SIPAccount::terminate() ...@@ -59,3 +69,21 @@ SIPAccount::terminate()
return false; return false;
} }
void
SIPAccount::initConfig(Conf::ConfigTree& config)
{
std::string section(_accountID);
std::string type_str("string");
std::string type_int("int");
config.addConfigTreeItem(section, Conf::ConfigTreeItem(CONFIG_ACCOUNT_TYPE, "SIP", type_str));
config.addConfigTreeItem(section, Conf::ConfigTreeItem(CONFIG_ACCOUNT_ENABLE,"1", type_int));
config.addConfigTreeItem(section, Conf::ConfigTreeItem(SIP_FULL_NAME, "", type_str));
config.addConfigTreeItem(section, Conf::ConfigTreeItem(SIP_USER_PART, "", type_str));
config.addConfigTreeItem(section, Conf::ConfigTreeItem(SIP_AUTH_USER_NAME, "", type_str));
config.addConfigTreeItem(section, Conf::ConfigTreeItem(SIP_PROXY, "", type_str));
config.addConfigTreeItem(section, Conf::ConfigTreeItem(SIP_AUTO_REGISTER, "1", type_int));
config.addConfigTreeItem(section, Conf::ConfigTreeItem(SIP_STUN_SERVER, "stun.fwdnet.net:3478", type_str));
config.addConfigTreeItem(section, Conf::ConfigTreeItem(SIP_USE_STUN, "0", type_int));
}
...@@ -33,6 +33,7 @@ public: ...@@ -33,6 +33,7 @@ public:
~SIPAccount(); ~SIPAccount();
/* virtual Account function implementation */ /* virtual Account function implementation */
void initConfig(Conf::ConfigTree& config);
bool registerAccount(); bool registerAccount();
bool unregisterAccount(); bool unregisterAccount();
bool init(); bool init();
......
...@@ -37,6 +37,10 @@ ...@@ -37,6 +37,10 @@
#define NETWORK "Network" #define NETWORK "Network"
#define PREFERENCES "Preferences" #define PREFERENCES "Preferences"
#define ACCOUNT_SIP0 "SIP0"
#define ACCOUNT_AIX0 "AIX0"
// Fields to fill // Fields to fill
#define VOIP_LINK_ID "VoIPLink.index" #define VOIP_LINK_ID "VoIPLink.index"
#define SYMMETRIC "VoIPLink.symmetric" #define SYMMETRIC "VoIPLink.symmetric"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment