Commit 8add3e0c authored by jpbl's avatar jpbl
Browse files

Now we send a getevent each time we connect to sflphone

parent acef9a9f
......@@ -23,8 +23,8 @@
#include <list>
#include <string>
#include <qmutex.h>
#include <qwaitcondition.h>
#include <QMutex>
#include <QWaitCondition>
template< typename T >
class ObjectPool
......
......@@ -11,23 +11,57 @@
#include "PhoneLineManager.hpp"
PhoneLineManagerImpl::PhoneLineManagerImpl()
: mAccount(mSession.getDefaultAccount())
: mSession(NULL)
, mAccount(NULL)
, mCurrentLine(NULL)
, mIsInitialized(false)
{
EventFactory::instance().registerEvent< HangupEvent >("002");
EventFactory::instance().registerEvent< IncommingEvent >("001");
}
PhoneLineManagerImpl::~PhoneLineManagerImpl()
{
delete mSession;
delete mAccount;
for(std::vector< PhoneLine * >::iterator pos = mPhoneLines.begin();
pos != mPhoneLines.end();
pos++) {
delete *pos;
}
}
void
PhoneLineManagerImpl::initialize()
{
QMutexLocker guard(&mIsInitializedMutex);
mIsInitialized = true;
mSession = new Session();
mAccount = new Account(mSession->getDefaultAccount());
}
void PhoneLineManagerImpl::isInitialized()
{
QMutexLocker guard(&mIsInitializedMutex);
if(!mIsInitialized) {
throw std::logic_error("Trying to use PhoneLineManager without prior initialize.");
}
}
void
PhoneLineManagerImpl::start()
{
mSession.getEvents();
isInitialized();
mSession->getEvents();
}
PhoneLine *
PhoneLineManagerImpl::getCurrentLine()
{
isInitialized();
QMutexLocker guard(&mCurrentLineMutex);
return mCurrentLine;
}
......@@ -35,15 +69,19 @@ PhoneLineManagerImpl::getCurrentLine()
void
PhoneLineManagerImpl::setNbLines(unsigned int nb)
{
isInitialized();
mPhoneLines.clear();
for(unsigned int i = 0; i < nb; i++) {
mPhoneLines.push_back(new PhoneLine(mSession, i + 1));
mPhoneLines.push_back(new PhoneLine(*mSession, i + 1));
}
}
PhoneLine *
PhoneLineManagerImpl::getNextAvailableLine()
{
isInitialized();
PhoneLine *selectedLine = NULL;
QMutexLocker guard(&mPhoneLinesMutex);
......@@ -71,6 +109,8 @@ PhoneLineManagerImpl::getNextAvailableLine()
PhoneLine *
PhoneLineManagerImpl::selectNextAvailableLine()
{
isInitialized();
PhoneLine *selectedLine = getNextAvailableLine();
PhoneLineLocker guard(selectedLine, false);
......@@ -97,6 +137,8 @@ PhoneLineManagerImpl::selectNextAvailableLine()
PhoneLine *
PhoneLineManagerImpl::getPhoneLine(unsigned int line)
{
isInitialized();
QMutexLocker guard(&mPhoneLinesMutex);
if(mPhoneLines.size() <= line) {
throw std::runtime_error("Trying to get an invalid Line");
......@@ -108,6 +150,8 @@ PhoneLineManagerImpl::getPhoneLine(unsigned int line)
PhoneLine *
PhoneLineManagerImpl::getPhoneLine(const std::string &callId)
{
isInitialized();
PhoneLine *selectedLine = NULL;
QMutexLocker guard(&mPhoneLinesMutex);
......@@ -129,6 +173,8 @@ PhoneLineManagerImpl::getPhoneLine(const std::string &callId)
void
PhoneLineManagerImpl::sendKey(Qt::Key c)
{
isInitialized();
PhoneLine *selectedLine = getCurrentLine();
if(!selectedLine) {
......@@ -149,6 +195,8 @@ PhoneLineManagerImpl::sendKey(Qt::Key c)
void
PhoneLineManagerImpl::selectLine(unsigned int line)
{
isInitialized();
PhoneLine *selectedLine = NULL;
// getting the wanted line;
{
......@@ -174,7 +222,7 @@ PhoneLineManagerImpl::selectLine(unsigned int line)
PhoneLineLocker guard(selectedLine);
selectedLine->select();
if(selectedLine->isAvailable()) {
mSession.playTone();
mSession->playTone();
}
}
}
......@@ -273,7 +321,7 @@ PhoneLineManagerImpl::incomming(const std::string &,
PhoneLine *selectedLine = getNextAvailableLine();
PhoneLineLocker guard(selectedLine, false);
Call call(mSession, callId, true);
Call call(*mSession, callId, true);
if(selectedLine) {
selectedLine->incomming(call);
}
......
......@@ -22,7 +22,7 @@ class PhoneLineManagerImpl : public QObject
public:
PhoneLineManagerImpl();
~PhoneLineManagerImpl();
/**
* Will return the PhoneLine linked to the line
......@@ -46,6 +46,7 @@ signals:
void selected(unsigned int);
public slots:
void initialize();
void start();
void sendKey(Qt::Key c);
......@@ -123,14 +124,20 @@ public slots:
PhoneLine *selectNextAvailableLine();
private:
Session mSession;
Account mAccount;
void isInitialized();
private:
Session *mSession;
Account *mAccount;
std::vector< PhoneLine * > mPhoneLines;
QMutex mPhoneLinesMutex;
PhoneLine *mCurrentLine;
QMutex mCurrentLineMutex;
bool mIsInitialized;
QMutex mIsInitializedMutex;
};
......
......@@ -15,6 +15,7 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv)
: QApplication(argc, argv)
{
SessionIOFactory::instance().setCreator(new TCPSessionIOCreator(QString("localhost"), 3999));
PhoneLineManager::instance().initialize();
PhoneLineManager::instance().setNbLines(NB_PHONELINES);
Requester::instance().registerObject< Request >(std::string("playtone"));
Requester::instance().registerObject< Request >(std::string("playdtmf"));
......
......@@ -7,7 +7,7 @@ TARGET +=
DEPENDPATH += .
INCLUDEPATH += .
QT += network
CONFIG += debug
#CONFIG += debug
# Input
HEADERS += Account.hpp \
......
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