Commit 7d409663 authored by yanmorin's avatar yanmorin

parent 790d10cb
......@@ -15,7 +15,7 @@ SUBDIRS = audio config gui $(ZEROCONFDIR)
sflphoned_SOURCES = call.cpp eventthread.cpp main.cpp sipvoiplink.cpp voIPLink.cpp \
sipcall.cpp managerimpl.cpp \
observer.cpp
observer.cpp account.cpp
sflphoned_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\" $(ZEROCONFFLAGS)
......@@ -38,4 +38,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
call.h voIPLink.h sipcall.h account.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 "account.h"
#include "voIPLink.h"
Account::Account(const AccountID& accountID) : _accountID(accountID)
{
_link = 0;
_shouldInitOnStart = false;
_enabled = false;
_registered = false;
}
Account::~Account()
{
delete _link; _link = 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 ACCOUNT_H
#define ACCOUNT_H
#include <string>
class VoIPLink;
typedef std::string AccountID;
/**
@author Yan Morin
Class account is an interface to protocol account (sipaccount, aixaccount)
It can be enable on loading or activate after.
It contains account, configuration, VoIP Link and Calls (inside the VoIPLink)
*/
class Account{
public:
Account(const AccountID& accountID);
~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
*/
virtual bool registerAccount() = 0;
/**
* Unregister the account
* @return false is an error occurs
*/
virtual bool unregisterAccount() = 0;
/**
* Init the voiplink to run (event listener)
* @return false is an error occurs
*/
virtual bool init() = 0;
/**
* Stop the voiplink to run (event listener)
* @return false is an error occurs
*/
virtual bool terminate() = 0;
private:
/**
* Account ID are assign in constructor and shall not changed
*/
AccountID _accountID;
/**
* Voice over IP Link contains a listener thread and calls
*/
VoIPLink* _link;
/**
* Tells if the link should be start on loading or not
* Modified by the configuration
*/
bool _shouldInitOnStart;
/**
* Tells if the link is enabled or not
* Modified by init/terminate
*/
bool _enabled;
/**
* Tells if the link is registered or not
* Modified by unregister/register
*/
bool _registered;
};
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
/*
* Copyright (C) 2004-2006 Savoir-Faire Linux inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
* Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
*
......@@ -50,4 +50,5 @@ typedef short int16;
#define MONO 1
#define CHANNELS 2
#define SIZEBUF 1024*1024
#endif // __GLOBAL_H__
......@@ -105,6 +105,10 @@ ManagerImpl::~ManagerImpl (void)
void
ManagerImpl::init()
{
#ifdef TEST
testCallAccountMap();
#endif
initVolume();
if (_exist == 0) {
......@@ -1778,3 +1782,87 @@ ManagerImpl::setSwitch(const std::string& switchName) {
return false;
}
}
// ACCOUNT handling
bool
ManagerImpl::associateCallToAccount(CALLID callID, const AccountID& accountID)
{
if (getAccountFromCall(callID) == "") { // 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;
}
}
AccountID
ManagerImpl::getAccountFromCall(const CALLID callID)
{
ost::MutexLock m(_callAccountMapMutex);
CallAccountMap::iterator iter = _callAccountMap.find(callID);
if ( iter == 0 || iter == _callAccountMap.end()) {
return "";
} else {
return iter->second;
}
}
bool
ManagerImpl::removeCallAccount(CALLID callID)
{
ost::MutexLock m(_callAccountMapMutex);
if ( _callAccountMap.erase(callID) ) {
return true;
}
return false;
}
CALLID
ManagerImpl::getNewCallID()
{
CALLID random_id = (unsigned)rand();
// when it's not found, it return ""
while (getAccountFromCall(random_id) != "") {
random_id = rand();
}
return random_id;
}
#ifdef TEST
/**
* Test accountMap
*/
bool ManagerImpl::testCallAccountMap()
{
if ( getAccountFromCall(1) != "" ) {
_debug("TEST: getAccountFromCall with empty list failed\n");
}
if ( removeCallAccount(1) != false ) {
_debug("TEST: removeCallAccount with empty list failed\n");
}
CALLID newid = getNewCallID();
if ( associateCallToAccount(newid, "acc0") == false ) {
_debug("TEST: associateCallToAccount with new CallID empty list failed\n");
}
if ( associateCallToAccount(newid, "acc1") == true ) {
_debug("TEST: associateCallToAccount with a known CallID failed\n");
}
if ( getAccountFromCall( newid ) != "acc0" ) {
_debug("TEST: getAccountFromCall don't return the good account id\n");
}
CALLID secondnewid = getNewCallID();
if ( associateCallToAccount(secondnewid, "xxxx") == true ) {
_debug("TEST: associateCallToAccount with unknown account id failed\n");
}
if ( removeCallAccount( newid ) != true ) {
_debug("TEST: removeCallAccount don't remove the association\n");
}
return true;
}
#endif
......@@ -21,14 +21,18 @@
#ifndef __MANAGER_H__
#define __MANAGER_H__
//#define TEST
#include <string>
#include <vector>
#include <map>
#include <cc++/thread.h>
#include "stund/stun.h"
#include "call.h"
#include "observer.h"
#include "config/config.h"
#include "account.h"
//#include "audio/audiodevice.h"
#include "audio/tonelist.h" // for Tone::TONEID declaration
......@@ -70,6 +74,11 @@ typedef std::vector< Call* > CallVector;
*/
typedef std::vector< VoIPLink* > VoIPLinkVector;
/**
* Define a type for a CallID to AccountID Map inside ManagerImpl
*/
typedef std::map<CALLID, AccountID> CallAccountMap;
/**
* To send multiple string
*/
......@@ -411,6 +420,45 @@ private:
DNSService *_DNSService;
#endif
// CALLID
/** Map to associate a CallID to the good account */
CallAccountMap _callAccountMap;
/** Mutex to lock the call account map (main thread + voiplink thread) */
ost::Mutex _callAccountMapMutex;
/** Associate a new CallID to a AccountID
* Protected by mutex
* @param callID the new CallID not in the list yet
* @param accountID the known accountID present in accountMap
* @return true if the new association is create
*/
bool associateCallToAccount(CALLID callID, const AccountID& accountID);
/** Return the AccountID from a CallID
* Protected by mutex
* @param callID the CallID in the list
* @return the accountID associated or "" if the callID is not found
*/
AccountID getAccountFromCall(const CALLID callID);
/** Remove a CallID/AccountID association
* Protected by mutex
* @param callID the CallID to remove
* @return true if association is removed
*/
bool removeCallAccount(CALLID callID);
/** Return a new random callid that is not present in the list
* @return a brand new callid
*/
CALLID getNewCallID();
// bool accountExists(AccountID accountID);
#ifdef TEST
bool testCallAccountMap();
#endif
};
#endif // __MANAGER_H__
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