Commit d62caf5e authored by yanmorin's avatar yanmorin

VoIPLink integration inside account
getAccount() patch for managerimpl
Remove old voiplink vector in managerimpl
parent ee09fc14
......@@ -16,7 +16,7 @@ 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 sipaccount.cpp aixaccount.cpp accountcreator.cpp
account.cpp sipaccount.cpp aixaccount.cpp accountcreator.cpp aixvoiplink.cpp
sflphoned_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\" $(ZEROCONFFLAGS)
......@@ -40,4 +40,4 @@ 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 sipaccount.h aixaccount.h accountcreator.h
account.h sipaccount.h aixaccount.h accountcreator.h aixvoiplink.h
......@@ -22,6 +22,7 @@
Account::Account(const AccountID& accountID) : _accountID(accountID)
{
_link = 0;
_shouldInitOnStart = false;
_enabled = false;
_registered = false;
......
......@@ -46,6 +46,13 @@ public:
*/
virtual void initConfig(Conf::ConfigTree& config) = 0;
/**
* Get the voiplink pointer
* @return the pointer or 0
*/
inline VoIPLink* getVoIPLink() { return _link; }
/**
* Register the account
* @return false is an error occurs
......@@ -78,6 +85,12 @@ private:
*/
virtual bool createVoIPLink() = 0;
protected:
/**
* Account ID are assign in constructor and shall not changed
*/
AccountID _accountID;
/**
* Voice over IP Link contains a listener thread and calls
*/
......@@ -101,12 +114,6 @@ private:
*/
bool _registered;
protected:
/**
* Account ID are assign in constructor and shall not changed
*/
AccountID _accountID;
};
#endif
......@@ -17,10 +17,12 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "aixaccount.h"
#include "aixvoiplink.h"
AIXAccount::AIXAccount(const AccountID& accountID)
: Account(accountID)
{
createVoIPLink();
}
......@@ -32,30 +34,49 @@ AIXAccount::~AIXAccount()
bool
AIXAccount::createVoIPLink()
{
return false;
if (!_link) {
_link = new AIXVoIPLink();
}
return (_link != 0 ? true : false);
}
bool
AIXAccount::registerAccount()
{
return false;
if (_link && !_registered) {
_registered = (_link->setRegister() >= 0) ? true : false;
}
return _registered;
}
bool
AIXAccount::unregisterAccount()
{
return false;
if (_link && _registered) {
_registered = (_link->setUnregister() == 0) ? false : true;
}
return !_registered;
}
bool
AIXAccount::init()
{
if (_link && !_enabled) {
_link->init();
_enabled = true;
return true;
}
return false;
}
bool
AIXAccount::terminate()
{
if (_link && _enabled) {
_link->terminate();
_enabled = false;
return true;
}
return false;
}
......
......@@ -107,7 +107,8 @@ AudioRtpRTX::AudioRtpRTX (SipCall *sipcall, AudioLayer* driver, bool sym) {
#endif
// TODO: Change bind address according to user settings.
std::string localipConfig = _ca->getLocalIp();
// TODO: this should be the local ip not the external (router) IP
std::string localipConfig = "0.0.0.0"; // _ca->getLocalIp();
ost::InetHostAddress local_ip(localipConfig.c_str());
//_debug("AudioRtpRTX ctor : Local IP:port %s:%d\tsymmetric:%d\n", local_ip.getHostname(), _ca->getLocalAudioPort(), _sym);
......
......@@ -38,7 +38,6 @@
#include "audio/tonelist.h"
#include "accountcreator.h" // create new account
#include "sipvoiplink.h"
#include "voIPLink.h"
#include "call.h"
......@@ -158,8 +157,6 @@ ManagerImpl::init()
}
_debugInit("Adding new VoIP Link");
// Set a sip voip link by default
_voIPLinkVector.push_back(new SipVoIPLink());
// 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
......@@ -170,14 +167,7 @@ void ManagerImpl::terminate()
{
saveConfig();
_debug("Removing VoIP Links...\n");
for(VoIPLinkVector::iterator pos = _voIPLinkVector.begin();
pos != _voIPLinkVector.end();
pos++) {
delete *pos;
*pos = NULL;
}
_voIPLinkVector.clear();
unloadAccountMap();
_debug("Removing calls\n");
_mutex.enterMutex();
......@@ -189,8 +179,6 @@ void ManagerImpl::terminate()
_callVector.clear();
_mutex.leaveMutex();
unloadAccountMap();
_debug("Unload DTMF Key\n");
delete _dtmfKey;
......@@ -214,7 +202,8 @@ Call *
ManagerImpl::pushBackNewCall(CALLID id, Call::CallType type)
{
ost::MutexLock m(_mutex);
Call* call = new Call(id, type, _voIPLinkVector.at(DFT_VOIP_LINK));
Call* call = new Call(id, type, getAccountLink(ACCOUNT_SIP0));
// Set the wanted voip-link (first of the list)
_callVector.push_back(call);
return call;
......@@ -308,7 +297,7 @@ ManagerImpl::outgoingCall (const std::string& to)
bool
ManagerImpl::sendTextMessage(const std::string&, const std::string& to, const std::string& message)
{
return _voIPLinkVector.at(DFT_VOIP_LINK)->sendMessage(to, message);
return getAccountLink(ACCOUNT_SIP0)->sendMessage(to, message);
}
/**
......@@ -519,7 +508,7 @@ ManagerImpl::initRegisterVoIPLink()
int returnValue = true;
_debugInit("Initiate VoIP Link Registration\n");
if (_hasTriedToRegister == false) {
if ( _voIPLinkVector.at(DFT_VOIP_LINK)->init() ) {
if ( getAccount(ACCOUNT_SIP0)->init() ) {
// we call here, because it's long...
// If network is available and exosip is start..
if (getConfigInt(SIGNALISATION, AUTO_REGISTER) && _exist == 1) {
......@@ -544,8 +533,8 @@ ManagerImpl::registerVoIPLink (void)
{
_debug("Register VoIP Link\n");
int returnValue = false;
if (_voIPLinkVector.at(DFT_VOIP_LINK)->setRegister() >= 0) {
returnValue = true;
returnValue = getAccount(ACCOUNT_SIP0)->registerAccount();
if (returnValue) {
_registerState = REGISTERED;
} else {
_registerState = FAILED;
......@@ -561,11 +550,7 @@ bool
ManagerImpl::unregisterVoIPLink (void)
{
_debug("Unregister VoIP Link\n");
if (_voIPLinkVector.at(DFT_VOIP_LINK)->setUnregister() == 0) {
return true;
} else {
return false;
}
return getAccount(ACCOUNT_SIP0)->unregisterAccount();
}
/**
......@@ -579,7 +564,7 @@ ManagerImpl::sendDtmf (CALLID id, char code)
switch (sendType) {
case 0: // SIP INFO
playDtmf(code);
_voIPLinkVector.at(DFT_VOIP_LINK)->carryingDTMFdigits(id, code);
getAccountLink(ACCOUNT_SIP0)->carryingDTMFdigits(id, code);
returnValue = true;
break;
......@@ -920,10 +905,10 @@ ManagerImpl::displayErrorText (CALLID id, const std::string& message)
* for outgoing call, send by SipEvent
*/
void
ManagerImpl::displayError (const std::string& voIPError)
ManagerImpl::displayError (const std::string& error)
{
if(_gui) {
_gui->displayError(voIPError);
_gui->displayError(error);
}
}
......@@ -1870,7 +1855,7 @@ ManagerImpl::unloadAccountMap()
}
bool
ManagerImpl::accountExists(AccountID accountID)
ManagerImpl::accountExists(const AccountID& accountID)
{
AccountMap::iterator iter = _accountMap.find(accountID);
if ( iter == 0 || iter == _accountMap.end() ) {
......@@ -1880,7 +1865,7 @@ ManagerImpl::accountExists(AccountID accountID)
}
Account*
ManagerImpl::getAccount(AccountID accountID)
ManagerImpl::getAccount(const AccountID& accountID)
{
AccountMap::iterator iter = _accountMap.find(accountID);
if ( iter == 0 || iter == _accountMap.end() ) {
......@@ -1889,6 +1874,16 @@ ManagerImpl::getAccount(AccountID accountID)
return iter->second;
}
VoIPLink*
ManagerImpl::getAccountLink(const AccountID& accountID)
{
Account* acc = getAccount(accountID);
if ( acc ) {
return acc->getVoIPLink();
}
return 0;
}
void
ManagerImpl::initConfigAccount() {
AccountMap::iterator iter = _accountMap.begin();
......
......@@ -48,6 +48,7 @@ class GuiFramework;
class TelephoneTone;
class VoIPLink;
#ifdef USE_ZEROCONF
class DNSService;
#endif
......@@ -69,11 +70,6 @@ class DNSService;
*/
typedef std::vector< Call* > CallVector;
/*
* Define a type for a list of VoIPLink
*/
typedef std::vector< VoIPLink* > VoIPLinkVector;
/**
* Define a type for a CallID to AccountID Map inside ManagerImpl
*/
......@@ -105,8 +101,6 @@ public:
// it's multi-thread and use mutex internally
AudioLayer* getAudioDriver(void) const { return _audiodriverPA ;}
// Accessor to VoIPLinkVector
VoIPLinkVector* getVoIPLinkVector (void) {return &_voIPLinkVector;}
// Codec Descriptor
CodecDescriptorMap& getCodecDescriptorMap(void) {return _codecDescriptorMap;}
......@@ -328,8 +322,6 @@ private:
//
// Multithread variable with extern accessor and change only inside the main thread
//
/** Vector of VoIPLink */
VoIPLinkVector _voIPLinkVector;
/** Vector of CodecDescriptor */
CodecDescriptor* _codecBuilder;
......@@ -477,14 +469,21 @@ private:
* Tell if an account exists
* @param accountID account ID check
*/
bool accountExists(AccountID accountID);
bool accountExists(const AccountID& accountID);
/**
* Get an account pointer
* @param accountID account ID to get
* @param the account pointer or 0
*/
Account* getAccount(AccountID accountID);
Account* getAccount(const AccountID& accountID);
/**
* Get the voip link from the account pointer
* @param accountID account ID to get
* @param the voip link from the account pointer or 0
*/
VoIPLink* getAccountLink(const AccountID& accountID);
/**
* load default account variable for each protocol
......
......@@ -17,6 +17,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "sipaccount.h"
#include "sipvoiplink.h"
#define SIP_FULL_NAME "SIP.fullName"
#define SIP_USER_PART "SIP.userPart"
#define SIP_AUTH_USER_NAME "SIP.username"
......@@ -31,6 +33,7 @@
SIPAccount::SIPAccount(const AccountID& accountID)
: Account(accountID)
{
createVoIPLink();
}
......@@ -42,30 +45,49 @@ SIPAccount::~SIPAccount()
bool
SIPAccount::createVoIPLink()
{
return false;
if (!_link) {
_link = new SipVoIPLink();
}
return (_link != 0 ? true : false);
}
bool
SIPAccount::registerAccount()
{
return false;
if (_link && !_registered) {
_registered = (_link->setRegister() >= 0) ? true : false;
}
return _registered;
}
bool
SIPAccount::unregisterAccount()
{
return false;
if (_link && _registered) {
_registered = (_link->setUnregister() == 0) ? false : true;
}
return !_registered;
}
bool
SIPAccount::init()
{
if (_link && !_enabled) {
_link->init();
_enabled = true;
return true;
}
return false;
}
bool
SIPAccount::terminate()
{
if (_link && _enabled) {
_link->terminate();
_enabled = false;
return true;
}
return false;
}
......
......@@ -53,6 +53,7 @@ SipVoIPLink::SipVoIPLink() : VoIPLink()
_registrationSend = false;
_started = false;
_localIpAddress = "127.0.0.1"; // sipvoip require this value to check network
}
SipVoIPLink::~SipVoIPLink(void) {
......@@ -87,6 +88,10 @@ SipVoIPLink::checkNetwork (void)
bool
SipVoIPLink::init(void)
{
// TODO: should be inside the account
_fullname = Manager::instance().getConfigString(SIGNALISATION,FULL_NAME) ;
_hostname = Manager::instance().getConfigString(SIGNALISATION,HOST_PART);
if (0 != eXosip_init()) {
_debug("Could not initialize eXosip\n");
return false;
......
......@@ -26,25 +26,12 @@
VoIPLink::VoIPLink ()
{
initConstructor();
}
VoIPLink::~VoIPLink (void)
{
}
void
VoIPLink::setType (VoIPLinkType type)
{
_type = type;
}
VoIPLinkType
VoIPLink::getType (void)
{
return _type;
}
void
VoIPLink::setFullName (const std::string& fullname)
{
......@@ -80,15 +67,3 @@ VoIPLink::getLocalIpAddress (void)
{
return _localIpAddress;
}
void
VoIPLink::initConstructor(void)
{
_type = Sip;
// TODO: should be inside the account
_fullname =
Manager::instance().getConfigString(SIGNALISATION,FULL_NAME
) ;
_hostname = Manager::instance().getConfigString(SIGNALISATION,HOST_PART);
_localIpAddress = "127.0.0.1"; // sipvoip require this value to check network
}
......@@ -24,11 +24,6 @@
#include <string>
#include "call.h"
enum VoIPLinkType {
Sip = 0,
Iax
};
class AudioCodec;
class Call;
......@@ -58,8 +53,6 @@ public:
virtual AudioCodec* getAudioCodec (CALLID id) = 0;
virtual bool sendMessage(const std::string& to, const std::string& body) = 0;
void setType (VoIPLinkType type);
VoIPLinkType getType (void);
void setFullName (const std::string& fullname);
std::string getFullName (void);
void setHostName (const std::string& hostname);
......@@ -67,10 +60,8 @@ public:
void setLocalIpAddress (const std::string& ipAdress);
std::string getLocalIpAddress (void);
private:
void initConstructor(void);
protected:
VoIPLinkType _type;
std::string _fullname;
std::string _hostname;
std::string _localIpAddress;
......
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