Commit 2c74a005 authored by yanmorin's avatar yanmorin

Add AccountCreator and AccountMap handling
New empty AixAccount/SipAccount
Next step is internal account configuration
parent 7d409663
......@@ -15,7 +15,8 @@ SUBDIRS = audio config gui $(ZEROCONFDIR)
sflphoned_SOURCES = call.cpp eventthread.cpp main.cpp sipvoiplink.cpp voIPLink.cpp \
sipcall.cpp managerimpl.cpp \
observer.cpp account.cpp
observer.cpp \
account.cpp sipaccount.cpp aixaccount.cpp accountcreator.cpp
sflphoned_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\" $(ZEROCONFFLAGS)
......@@ -38,4 +39,5 @@ libsflphone_la_SOURCES =
noinst_LTLIBRARIES = libsflphone.la
noinst_HEADERS = managerimpl.h manager.h global.h observer.h eventthread.h sipvoiplink.h user_cfg.h \
call.h voIPLink.h sipcall.h account.h
call.h voIPLink.h sipcall.h \
account.h sipaccount.h aixaccount.h accountcreator.h
......@@ -23,6 +23,7 @@
class VoIPLink;
typedef std::string AccountID;
#define AccountNULL ""
/**
@author Yan Morin
......@@ -36,13 +37,6 @@ public:
~Account();
/**
* Create a unique voIPLink() depending on the protocol
* Multiple call to this function do nothing (if the voiplink pointer is 0)
* @return false if an error occurs
*/
virtual bool createVoIPLink() = 0;
/**
* Register the account
* @return false is an error occurs
......@@ -68,6 +62,13 @@ public:
virtual bool terminate() = 0;
private:
/**
* Create a unique voIPLink() depending on the protocol
* Multiple call to this function do nothing (if the voiplink pointer is 0)
* @return false if an error occurs
*/
virtual bool createVoIPLink() = 0;
/**
* Account ID are assign in constructor and shall not changed
*/
......
/*
* Copyright (C) 2006 Savoir-Faire Linux inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "accountcreator.h"
#include "sipaccount.h"
#include "aixaccount.h"
AccountCreator::AccountCreator()
{
}
AccountCreator::~AccountCreator()
{
}
Account*
AccountCreator::createAccount(AccountType type, AccountID accountID)
{
switch(type) {
case SIP_ACCOUNT:
return new SIPAccount(accountID);
break;
case AIX_ACCOUNT:
return new AIXAccount(accountID);
break;
}
return 0;
}
/*
* Copyright (C) 2006 Savoir-Faire Linux inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef ACCOUNTCREATOR_H
#define ACCOUNTCREATOR_H
#include "account.h"
class Account;
/**
@author Yan Morin <yan.morin@gmail.com>
AccountCreator create Protocol-specific Account
*/
class AccountCreator{
public:
~AccountCreator();
/**
* Public account type
*/
enum AccountType {SIP_ACCOUNT, AIX_ACCOUNT };
/**
* Create a new account or null
* @param type type of the account
* @param accountID accountID (must be unique for each account)
*/
static Account* createAccount(AccountType type, AccountID accountID);
private:
/** Hidden creator */
AccountCreator();
};
#endif
/*
* Copyright (C) 2006 Savoir-Faire Linux inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "aixaccount.h"
AIXAccount::AIXAccount(const AccountID& accountID)
: Account(accountID)
{
}
AIXAccount::~AIXAccount()
{
}
/* virtual Account function implementation */
bool
AIXAccount::createVoIPLink()
{
return false;
}
bool
AIXAccount::registerAccount()
{
return false;
}
bool
AIXAccount::unregisterAccount()
{
return false;
}
bool
AIXAccount::init()
{
return false;
}
bool
AIXAccount::terminate()
{
return false;
}
/*
* Copyright (C) 2006 Savoir-Faire Linux inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef AIXACCOUNT_H
#define AIXACCOUNT_H
#include "account.h"
/**
@author Yan Morin <yan.morin@gmail.com>
An AIX Account specify AIX specific functions and objects (AIXCall/AIXVoIPLink)
*/
class AIXAccount : public Account
{
public:
AIXAccount(const AccountID& accountID);
~AIXAccount();
/* virtual Account function implementation */
bool registerAccount();
bool unregisterAccount();
bool init();
bool terminate();
private:
/* virtual Account function implementation */
bool createVoIPLink();
};
#endif
......@@ -37,6 +37,7 @@
#include "audio/audiocodec.h"
#include "audio/tonelist.h"
#include "accountcreator.h" // create new account
#include "sipvoiplink.h"
#include "voIPLink.h"
#include "call.h"
......@@ -106,9 +107,11 @@ void
ManagerImpl::init()
{
#ifdef TEST
testAccountMap();
loadAccountMap();
testCallAccountMap();
unloadAccountMap();
#endif
initVolume();
if (_exist == 0) {
......@@ -154,6 +157,7 @@ ManagerImpl::init()
// Set a sip voip link by default
_voIPLinkVector.push_back(new SipVoIPLink());
loadAccountMap();
// 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
initZeroconf();
......@@ -182,6 +186,8 @@ void ManagerImpl::terminate()
_callVector.clear();
_mutex.leaveMutex();
unloadAccountMap();
_debug("Unload DTMF Key\n");
delete _dtmfKey;
......@@ -1787,14 +1793,14 @@ ManagerImpl::setSwitch(const std::string& switchName) {
bool
ManagerImpl::associateCallToAccount(CALLID callID, const AccountID& accountID)
{
if (getAccountFromCall(callID) == "") { // nothing with the same ID
//if ( accountExists(accountID) ) { // account id exist in AccountMap
if (getAccountFromCall(callID) == AccountNULL) { // nothing with the same ID
if ( accountExists(accountID) ) { // account id exist in AccountMap
ost::MutexLock m(_callAccountMapMutex);
_callAccountMap[callID] = accountID;
return true;
//} else {
// return false;
//}
} else {
return false;
}
} else {
return false;
}
......@@ -1806,7 +1812,7 @@ ManagerImpl::getAccountFromCall(const CALLID callID)
ost::MutexLock m(_callAccountMapMutex);
CallAccountMap::iterator iter = _callAccountMap.find(callID);
if ( iter == 0 || iter == _callAccountMap.end()) {
return "";
return AccountNULL;
} else {
return iter->second;
}
......@@ -1827,19 +1833,71 @@ ManagerImpl::getNewCallID()
{
CALLID random_id = (unsigned)rand();
// when it's not found, it return ""
while (getAccountFromCall(random_id) != "") {
while (getAccountFromCall(random_id) != AccountNULL) {
random_id = rand();
}
return random_id;
}
AccountMap _accountMap;
short
ManagerImpl::loadAccountMap()
{
short nbAccount = 0;
AccountID accID = "acc0";
_accountMap[accID] = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, accID);
nbAccount++;
accID = "acc1";
_accountMap[accID] = AccountCreator::createAccount(AccountCreator::AIX_ACCOUNT, accID);
nbAccount++;
return nbAccount;
}
void
ManagerImpl::unloadAccountMap()
{
AccountMap::iterator iter = _accountMap.begin();
while ( iter != _accountMap.end() ) {
delete iter->second; iter->second = 0;
iter++;
}
_accountMap.clear();
}
bool
ManagerImpl::accountExists(AccountID accountID)
{
AccountMap::iterator iter = _accountMap.find(accountID);
if ( iter == 0 || iter == _accountMap.end() ) {
return false;
}
return true;
}
Account*
ManagerImpl::getAccount(AccountID accountID)
{
AccountMap::iterator iter = _accountMap.find(accountID);
if ( iter == 0 || iter == _accountMap.end() ) {
return 0;
}
return iter->second;
}
#ifdef TEST
/**
* Test accountMap
*/
bool ManagerImpl::testCallAccountMap()
{
if ( getAccountFromCall(1) != "" ) {
if ( getAccountFromCall(1) != AccountNULL ) {
_debug("TEST: getAccountFromCall with empty list failed\n");
}
if ( removeCallAccount(1) != false ) {
......@@ -1865,4 +1923,31 @@ bool ManagerImpl::testCallAccountMap()
return true;
}
/**
* Test AccountMap
*/
bool ManagerImpl::testAccountMap()
{
if (loadAccountMap() != 2) {
_debug("TEST: loadAccountMap didn't load 2 account\n");
}
if (accountExists("acc0") == false) {
_debug("TEST: accountExists didn't find acc0\n");
}
if (accountExists("accZ") != false) {
_debug("TEST: accountExists found an unknown account\n");
}
if (getAccount("acc0") == 0) {
_debug("TEST: getAccount didn't find acc0\n");
}
if (getAccount("accZ") != 0) {
_debug("TEST: getAccount found an unknown account\n");
}
unloadAccountMap();
if ( accountExists("acc0") == true ) {
_debug("TEST: accountExists found an account after unloadAccount\n");
}
return true;
}
#endif
......@@ -78,6 +78,11 @@ typedef std::vector< VoIPLink* > VoIPLinkVector;
* Define a type for a CallID to AccountID Map inside ManagerImpl
*/
typedef std::map<CALLID, AccountID> CallAccountMap;
/**
* Define a type for a AccountMap container
*/
typedef std::map<AccountID, Account*> AccountMap;
/**
* To send multiple string
......@@ -454,11 +459,38 @@ private:
*/
CALLID getNewCallID();
// bool accountExists(AccountID accountID);
/** Contains a list of account (sip, aix, etc) and their respective voiplink/calls */
AccountMap _accountMap;
/**
* Load the account from configuration
* @return number of account
*/
short loadAccountMap();
/**
* Unload the account (delete them)
*/
void unloadAccountMap();
/**
* Tell if an account exists
* @param accountID account ID check
*/
bool accountExists(AccountID accountID);
/**
* Get an account pointer
* @param accountID account ID to get
* @param the account pointer or 0
*/
Account* getAccount(AccountID accountID);
#ifdef TEST
bool testCallAccountMap();
bool testAccountMap();
#endif
};
#endif // __MANAGER_H__
/*
* Copyright (C) 2006 Savoir-Faire Linux inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "sipaccount.h"
SIPAccount::SIPAccount(const AccountID& accountID)
: Account(accountID)
{
}
SIPAccount::~SIPAccount()
{
}
/* virtual Account function implementation */
bool
SIPAccount::createVoIPLink()
{
return false;
}
bool
SIPAccount::registerAccount()
{
return false;
}
bool
SIPAccount::unregisterAccount()
{
return false;
}
bool
SIPAccount::init()
{
return false;
}
bool
SIPAccount::terminate()
{
return false;
}
/*
* Copyright (C) 2006 Savoir-Faire Linux inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SIPACCOUNT_H
#define SIPACCOUNT_H
#include "account.h"
/**
@author Yan Morin <yan.morin@gmail.com>
A Sip Account specify SIP specific functions and object (SIPCall/SIPVoIPLink)
*/
class SIPAccount : public Account
{
public:
SIPAccount(const AccountID& accountID);
~SIPAccount();
/* virtual Account function implementation */
bool registerAccount();
bool unregisterAccount();
bool init();
bool terminate();
private:
/* virtual Account function implementation */
bool createVoIPLink();
};
#endif
Markdown is supported
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