diff --git a/src/gui/qt/EventAccount.cpp b/src/gui/qt/EventAccount.cpp index 73ae1b140fe85bb495b4ae15d7066797c425697c..802caa3dbad6ccbc696a68ce176d165b2707b467 100644 --- a/src/gui/qt/EventAccount.cpp +++ b/src/gui/qt/EventAccount.cpp @@ -28,7 +28,7 @@ AccountItemEvent::AccountItemEvent(const QString &code, : Event(code, args) { std::list< QString > l = getUnusedArgs(); - if(l.size() >= 3) { + if(l.size() >= 2) { mAccountId = *l.begin(); l.pop_front(); mStatus = *l.begin(); @@ -44,7 +44,7 @@ AccountItemEvent::execute() if (getCode() == "130") { isEnabled = true; } - // PhoneLineManager::instance().addAccount(mAccountId, isEnabled); + PhoneLineManager::instance().addAccount(mAccountId, isEnabled); } diff --git a/src/gui/qt/PhoneLine.cpp b/src/gui/qt/PhoneLine.cpp index 17d0f116d1b20cffb6657dab25fc808245c119cc..6acb259e44066a8956555d9a1131ea4b73715e63 100644 --- a/src/gui/qt/PhoneLine.cpp +++ b/src/gui/qt/PhoneLine.cpp @@ -25,8 +25,9 @@ #include "DebugOutput.hpp" #include "PhoneLine.hpp" #include "Request.hpp" +#include "Session.hpp" -PhoneLine::PhoneLine(const Session &session, +PhoneLine::PhoneLine(Session *session, unsigned int line) : mSession(session) , mCall(NULL) @@ -47,6 +48,7 @@ PhoneLine::PhoneLine(const Session &session, PhoneLine::~PhoneLine() { clearCall(); + mSession = 0; } void @@ -272,7 +274,7 @@ PhoneLine::sendKey(Qt::Key c) if (QChar(c).isDigit() || c == Qt::Key_Asterisk || c == Qt::Key_NumberSign) { if(!mCall) { - mSession.playDtmf(c); + mSession->playDtmf(c); } else { mCall->sendDtmf(c); @@ -296,8 +298,8 @@ PhoneLine::call(const QString &to) if(!mCall) { setLineStatus(tr("Calling %1...").arg(to)); Call *call; - const Account* account = mSession.getSelectedAccount(); - if (account) { + const Account* account = mSession->getSelectedAccount(); + if (account!=0) { Request *r = account->createCall(call, to); // entry connect(r, SIGNAL(entry(QString, QString)), @@ -311,6 +313,8 @@ PhoneLine::call(const QString &to) setCall(call); clear(); + } else { + DebugOutput::instance() << tr("Phone Line has no active account to make a call\n"); } } } diff --git a/src/gui/qt/PhoneLine.hpp b/src/gui/qt/PhoneLine.hpp index 7496dedf2864d5ea234201f0a7c3fc7f479e25e1..2b5cbc396800a98abdb8eedfe659e2494af76f27 100644 --- a/src/gui/qt/PhoneLine.hpp +++ b/src/gui/qt/PhoneLine.hpp @@ -24,17 +24,14 @@ #include <qtimer.h> #include <qdatetime.h> -#include "Account.hpp" -#include "Session.hpp" - class Call; - +class Session; class PhoneLine : public QObject { Q_OBJECT public: - PhoneLine(const Session &session, + PhoneLine(Session *session, unsigned int line); ~PhoneLine(); @@ -163,7 +160,7 @@ private: void setCall(const Call &call); void clearCall(); - Session mSession; + Session *mSession; Call *mCall; unsigned int mLine; diff --git a/src/gui/qt/PhoneLineManagerImpl.cpp b/src/gui/qt/PhoneLineManagerImpl.cpp index a831aa9a7136b21834e81713a7753656fa4eb999..1976b6f6757f46d4073ee18e1529b5f9b2eef1bf 100644 --- a/src/gui/qt/PhoneLineManagerImpl.cpp +++ b/src/gui/qt/PhoneLineManagerImpl.cpp @@ -47,8 +47,7 @@ PhoneLineManagerImpl::PhoneLineManagerImpl() , mLastNumber("") { EventFactory::instance().registerDefaultEvent< DefaultEvent >(); - // TODO: 000 - EventFactory::instance().registerEvent< CallRelatedEvent >("000"); + EventFactory::instance().registerEvent< GetEventEvent >("000"); EventFactory::instance().registerEvent< IncommingEvent >("001"); EventFactory::instance().registerEvent< HangupEvent >("002"); @@ -72,11 +71,15 @@ PhoneLineManagerImpl::PhoneLineManagerImpl() EventFactory::instance().registerEvent< AccountItemEvent >("130"); EventFactory::instance().registerEvent< AccountItemEvent >("131"); + // if TCPSessionIO::!connected! -> this::!connected! -> handleEvents (getEvents) + // if this::!getEventReady! -> this->readyToGetAccount -> startSession() -> getAccountList + // if this::!readyToGetStatus! -> getCallStatus() + // if this::!readyToShow! -> ... QObject::connect(this, SIGNAL(disconnected()), this, SLOT(closeSession())); - QObject::connect(this, SIGNAL(readyToHandleEvents()), this, SLOT(handleEvents())); - QObject::connect(this, SIGNAL(connected()), this, SIGNAL(readyToSendStatus())); - QObject::connect(this, SIGNAL(readyToSendStatus()), this, SLOT(startSession())); - + QObject::connect(this, SIGNAL(connected()), this, SLOT(handleEvents())); + QObject::connect(this, SIGNAL(readyToGetAccount()), this, SLOT(startSession())); + QObject::connect(this, SIGNAL(readyToGetCallStatus()),this, SLOT(getCallStatus())); + QObject::connect(this, SIGNAL(readyToShow()), this, SLOT(slotPreShow())); } PhoneLineManagerImpl::~PhoneLineManagerImpl() @@ -174,6 +177,11 @@ PhoneLineManagerImpl::slotSoundDriverFailed(QString message, QString /* code */) emit testSoundDriverReturn(true, message); } +void +PhoneLineManagerImpl::slotHasEnabledAccount(bool /* enable */) +{ + emit readyToGetCallStatus(); +} void PhoneLineManagerImpl::stop() @@ -198,16 +206,28 @@ PhoneLineManagerImpl::startSession() closeSession(); mIsConnected = true; + emit globalStatusSet(QString(tr("Trying to get account status...."))); + mSession->getAccountList(); +} + +void +PhoneLineManagerImpl::getCallStatus() +{ emit globalStatusSet(QString(tr("Trying to get line status..."))); mSession->getCallStatus(); } +void +PhoneLineManagerImpl::slotPreShow() +{ + emit globalStatusSet(QString(tr("Welcome to SFLPhone"))); +} + void PhoneLineManagerImpl::handleEvents() { isInitialized(); - emit globalStatusSet(QString(tr("Welcome to SFLPhone"))); mSession->getEvents(); Request *r; @@ -288,7 +308,7 @@ PhoneLineManagerImpl::setNbLines(unsigned int nb) mPhoneLines.clear(); for(unsigned int i = 0; i < nb; i++) { - PhoneLine *p = new PhoneLine(*mSession, i + 1); + PhoneLine *p = new PhoneLine(mSession, i + 1); QObject::connect(p, SIGNAL(lineStatusChanged(QString)), this, SIGNAL(unselectedLineStatusSet(QString))); mPhoneLines.push_back(p); @@ -795,7 +815,7 @@ PhoneLineManagerImpl::setMicVolume(int volume) mSession->micVolume(volume); updateMicVolume(volume); } -} + } void PhoneLineManagerImpl::incomingMessageText(const QString& message) @@ -805,4 +825,11 @@ PhoneLineManagerImpl::incomingMessageText(const QString& message) messageBox.exec(); } +void +PhoneLineManagerImpl::addAccount(const QString& name, bool isEnabled) +{ + if (mSession!=0) { + mSession->addAccount(name, isEnabled); + } +} diff --git a/src/gui/qt/PhoneLineManagerImpl.hpp b/src/gui/qt/PhoneLineManagerImpl.hpp index a15c30c36ed3d0b5cd7a2dfb5bbbb91961a6c8f8..b9b41da8b6f473f625d1a8fa0ce320463712d8eb 100644 --- a/src/gui/qt/PhoneLineManagerImpl.hpp +++ b/src/gui/qt/PhoneLineManagerImpl.hpp @@ -64,14 +64,17 @@ public: void setNbLines(unsigned int line); bool isConnected() { return mIsConnected; } - + void emitReadyAccount() { emit readyToGetAccount(); } + void emitReadyToShow() { emit readyToShow(); } + void addAccount(const QString& name, bool isEnabled); signals: void unselected(unsigned int); void selected(unsigned int); void connected(); void disconnected(); - void readyToSendStatus(); - void readyToHandleEvents(); + void readyToGetAccount(); + void readyToGetCallStatus(); + void readyToShow(); void handleEventsSent(); void gotErrorOnGetEvents(QString); void gotErrorOnCallStatus(QString); @@ -102,6 +105,9 @@ public slots: void slotReloadSoundDriver(); void slotSoundDriverFailed(QString, QString); void slotSoundDriverSucceed(QString, QString); + void slotHasEnabledAccount(bool); + void getCallStatus(); + void slotPreShow(); /** * You need to call this function once. It must be @@ -333,7 +339,7 @@ private: */ void isInitialized(); void select(PhoneLine *line, bool hardselect = false); - + private: Session *mSession; diff --git a/src/gui/qt/SFLEvents.cpp b/src/gui/qt/SFLEvents.cpp index c1d52729acb03c532ff1102fbc20b17ea04c6268..52304fc699bc7d1723c5ac934267bfe1ab972881 100644 --- a/src/gui/qt/SFLEvents.cpp +++ b/src/gui/qt/SFLEvents.cpp @@ -36,6 +36,10 @@ DefaultEvent::execute() DebugOutput::instance() << QObject::tr("DefaultEvent: We don't handle: %1\n").arg(toString()); } +void GetEventEvent::execute() +{ + PhoneLineManager::instance().emitReadyAccount(); +} HangupEvent::HangupEvent(const QString &code, const std::list< QString > &args) diff --git a/src/gui/qt/SFLEvents.hpp b/src/gui/qt/SFLEvents.hpp index a853eee34674255b372489e77c2289640c5686e2..1b2ec2d6173e2c008388edcda31414aa7e39df7b 100644 --- a/src/gui/qt/SFLEvents.hpp +++ b/src/gui/qt/SFLEvents.hpp @@ -34,6 +34,15 @@ public: virtual void execute(); }; +class GetEventEvent : public Event +{ +public: + GetEventEvent(const QString &code, + const std::list< QString > &args) : Event(code, args) {} + + virtual void execute(); +}; + class HangupEvent : public CallRelatedEvent { public: diff --git a/src/gui/qt/SFLPhoneApp.cpp b/src/gui/qt/SFLPhoneApp.cpp index 844f2680077a4f71f1e8d32f5de43126b210bec5..ee0679b08d818846d87aa0750ac0d09713822720 100644 --- a/src/gui/qt/SFLPhoneApp.cpp +++ b/src/gui/qt/SFLPhoneApp.cpp @@ -209,8 +209,7 @@ SFLPhoneApp::initConnections(SFLPhoneWindow *w) w, SLOT(askReconnect())); QObject::connect(&PhoneLineManager::instance(), SIGNAL(disconnected()), w, SLOT(show())); - QObject::connect(&PhoneLineManager::instance(), SIGNAL(connected()), - w, SLOT(show())); + QObject::connect(&PhoneLineManager::instance(), SIGNAL(readyToShow()), w, SLOT(show())); QObject::connect(w, SIGNAL(reconnectAsked()), &PhoneLineManager::instance(), SLOT(connect())); QObject::connect(&PhoneLineManager::instance(), SIGNAL(stopped()), @@ -231,7 +230,7 @@ SFLPhoneApp::initConnections(SFLPhoneWindow *w) QObject::connect(&PhoneLineManager::instance(), SIGNAL(gotErrorOnGetEvents(QString)), w, SLOT(askResendStatus(QString))); QObject::connect(w, SIGNAL(resendStatusAsked()), - &PhoneLineManager::instance(), SIGNAL(readyToSendStatus())); + &PhoneLineManager::instance(), SLOT(getCallStatus())); //Configuration events. diff --git a/src/gui/qt/SFLRequest.cpp b/src/gui/qt/SFLRequest.cpp index c113c9309f461c74d8161f608227aea8a18ca442..0f84dd17fad69e30244cd94a299394282b343d1d 100644 --- a/src/gui/qt/SFLRequest.cpp +++ b/src/gui/qt/SFLRequest.cpp @@ -28,7 +28,7 @@ #include "CallManager.hpp" #include "CallStatus.hpp" #include "CallStatusFactory.hpp" -#include "RequestAccount.hpp" +#include "EventAccount.hpp" #include "ConfigurationManager.hpp" #include "PhoneLine.hpp" #include "PhoneLineLocker.hpp" @@ -107,7 +107,7 @@ CallStatusRequest::onSuccess(const QString &code, const QString &message) DebugOutput::instance() << QObject::tr("CallStatusRequest Error: cannot get current line.\n"); } } - PhoneLineManager::instance().handleEvents(); + PhoneLineManager::instance().emitReadyToShow(); } AccountStatusRequest::AccountStatusRequest(const QString &sequenceId, @@ -119,15 +119,16 @@ AccountStatusRequest::AccountStatusRequest(const QString &sequenceId, void AccountStatusRequest::onError(const QString &code, const QString &message) { - DebugOutput::instance() << QObject::tr("CallStatusRequest error: (%1) %1\n") + DebugOutput::instance() << QObject::tr("AccountStatusRequest error: (%1) %1\n") .arg(code) .arg(message); - //PhoneLineManager::instance().errorOnCallStatus(message); + PhoneLineManager::instance().slotHasEnabledAccount(false); } void AccountStatusRequest::onEntry(const QString &code, const QString &message) { + DebugOutput::instance() << "AccountStatusRequest: " << code << " : " << message << "\n"; std::auto_ptr< Event > e(EventFactory::instance().create(code, Request::parseArgs(message))); e->execute(); @@ -137,7 +138,7 @@ void AccountStatusRequest::onSuccess(const QString &code, const QString &message) { DebugOutput::instance() << QObject::tr("AccountStatusRequest success: (%1) %1\n").arg(code).arg(message); - //PhoneLineManager::instance().handleEvents(); + PhoneLineManager::instance().slotHasEnabledAccount(true); } diff --git a/src/gui/qt/Session.cpp b/src/gui/qt/Session.cpp index ad632eb7dbeeb7c68bb2150d895310241b28bff3..46b4e2488f7d04148b3532ae12af904f88afe871 100644 --- a/src/gui/qt/Session.cpp +++ b/src/gui/qt/Session.cpp @@ -27,12 +27,11 @@ #include "Requester.hpp" #include "SessionIOFactory.hpp" #include "globals.h" - +#include "DebugOutput.hpp" Session::Session(const QString &id) - : mId(id), mSelectedAccountId(ACCOUNT_DEFAULT_NAME) + : mId(id), mSelectedAccountId("") { - mAccountMap[mSelectedAccountId] = new Account(mId, mSelectedAccountId); } Session::Session() @@ -195,20 +194,18 @@ Session::switchAudioDriver() const return Requester::instance().send(mId, "switch", args); } -Account -Session::getAccount(const QString &name) const -{ - return Account(mId, name); -} - -Account -Session::getDefaultAccount() const +Account* +Session::getSelectedAccount() { - return Account(mId, QString(ACCOUNT_DEFAULT_NAME)); + std::map< QString, Account* >::iterator iter = mAccountMap.find(mSelectedAccountId); + if (iter!=mAccountMap.end()) { + return iter->second; + } + return 0; } Account* -Session::getSelectedAccount() +Session::getAccount(const QString& name) { std::map< QString, Account* >::iterator iter = mAccountMap.find(mSelectedAccountId); if (iter!=mAccountMap.end()) { @@ -216,3 +213,17 @@ Session::getSelectedAccount() } return 0; } + +void +Session::addAccount(const QString& name, bool isEnabled) +{ + std::map<QString, Account* >::iterator iter = mAccountMap.find(name); + if (iter == mAccountMap.end()) { + mAccountMap[name] = new Account(mId, name); + // select account is the first enabled + if (mSelectedAccountId.isEmpty() && isEnabled) { + DebugOutput::instance() << "Default account is " << name << "\n"; + mSelectedAccountId = name; + } + } +} diff --git a/src/gui/qt/Session.hpp b/src/gui/qt/Session.hpp index 00893ea504c0f1b5890158659cb1cbc0931f3c89..ddd6867e733a5624dafed300507de0dbe7f34e73 100644 --- a/src/gui/qt/Session.hpp +++ b/src/gui/qt/Session.hpp @@ -37,16 +37,15 @@ class Session /** * retreive the account identified by name. */ - Account getAccount(const QString &name) const; - - Account getDefaultAccount() const; + Account* getAccount(const QString &name); /** * Return the first or selected account object * or 0 if not found */ Account* getSelectedAccount(); - + void addAccount(const QString& name, bool isEnabled); + /** * Set Selected Account ID * @param accountID account id diff --git a/src/gui/qt/main.cpp b/src/gui/qt/main.cpp index 3069b276393d4a0aa57dcdd054f0c613e093b429..4292889603cc318466d083d38714ea99e1257f5c 100644 --- a/src/gui/qt/main.cpp +++ b/src/gui/qt/main.cpp @@ -60,11 +60,10 @@ int main(int argc, char **argv) PhoneLineManager::instance().connect(); //splash->finish(sfl); //sfl->show(); - QObject::connect(&PhoneLineManager::instance(), SIGNAL(connected()), - splash, SLOT(hide())); + QObject::connect(&PhoneLineManager::instance(), SIGNAL(readyToShow()), splash, SLOT(hide())); // we connect this app to connected() signal, to handle argument - QObject::connect(&PhoneLineManager::instance(), SIGNAL(handleEventsSent()), &app, SLOT(handleArg())); + QObject::connect(&PhoneLineManager::instance(), SIGNAL(readyToShow()), &app, SLOT(handleArg())); diff --git a/src/gui/server/requestconfig.cpp b/src/gui/server/requestconfig.cpp index 45cce8ecf7102ea3829e0b90051ed958e6eb64f5..f89ca0330834b8cae47e5f2599a561d760e37891 100644 --- a/src/gui/server/requestconfig.cpp +++ b/src/gui/server/requestconfig.cpp @@ -63,7 +63,7 @@ RequestZeroconfEvent::update() ResponseMessage RequestCallStatus::execute() { - GUIServer::instance().sendGetEventsEnd(); + //GUIServer::instance().sendGetEventsEnd(); TokenList tk; tk.push_back(_("OK")); std::string code = "206"; diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 8352fb93d49150fc0ff5cbb57baf849ebda08f73..c73c8dbf9bef7db78c6e82466432421dd5be4f0a 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -1399,6 +1399,10 @@ bool ManagerImpl::getAudioDeviceList(const std::string& sequenceId, int ioDeviceMask) { bool returnValue = false; + AudioLayer* audiolayer = getAudioDriver(); + if (audiolayer == 0) { + return false; + } try { // TODO: test when there is an error on initializing... TokenList tk; @@ -1406,13 +1410,37 @@ ManagerImpl::getAudioDeviceList(const std::string& sequenceId, int ioDeviceMask) const char *hostApiName; const char *deviceName; + int deviceIsSupported = false; + int deviceRate = audiolayer->getSampleRate(); for (int index = 0; index < sys.deviceCount(); index++ ) { portaudio::Device& device = sys.deviceByIndex(index); - - if ((ioDeviceMask == AudioLayer::InputDevice && !device.isOutputOnlyDevice()) || - (ioDeviceMask == AudioLayer::OutputDevice && !device.isInputOnlyDevice() ) || - device.isFullDuplexDevice()) { + deviceIsSupported = false; + // TODO, put this code into AudioDriver() + if (ioDeviceMask == AudioLayer::InputDevice && !device.isOutputOnlyDevice()) { + //portaudio::DirectionSpecificStreamParameters inputParameters(device, device.maxInputChannels(), portaudio::INT16, true, 0.0, NULL); + //portaudio::DirectionSpecificStreamParameters outputParameters = portaudio::DirectionSpecificStreamParameters::null(); + //portaudio::StreamParameters tmp = portaudio::StreamParameters(inputParameters, outputParameters, deviceRate, 0, paNoFlag); + //if (tmp.isSupported()) { + deviceIsSupported = true; + //} + + } else if (ioDeviceMask == AudioLayer::OutputDevice && !device.isInputOnlyDevice()) { + //portaudio::DirectionSpecificStreamParameters inputParameters = portaudio::DirectionSpecificStreamParameters::null(); + //portaudio::DirectionSpecificStreamParameters outputParameters(device, device.maxOutputChannels(), portaudio::INT16, true, 0.0, NULL); + //portaudio::StreamParameters tmp = portaudio::StreamParameters(inputParameters, outputParameters, deviceRate, 0, paNoFlag); + //if (tmp.isSupported()) { + deviceIsSupported = true; + //} + } else if (device.isFullDuplexDevice()) { + //portaudio::DirectionSpecificStreamParameters inputParameters(device, device.maxInputChannels(), portaudio::INT16, true, 0.0, NULL); + //portaudio::DirectionSpecificStreamParameters outputParameters(device, device.maxOutputChannels(), portaudio::INT16, true, 0.0, NULL); + //portaudio::StreamParameters tmp = portaudio::StreamParameters(inputParameters, outputParameters, deviceRate, 0, paNoFlag); + //if (tmp.isSupported()) { + deviceIsSupported = true; + //} + } + if (deviceIsSupported) { hostApiName = device.hostApi().name(); deviceName = device.name(); @@ -1428,6 +1456,8 @@ ManagerImpl::getAudioDeviceList(const std::string& sequenceId, int ioDeviceMask) returnValue = false; } + audiolayer->startStream(); + return returnValue; } @@ -1493,16 +1523,19 @@ ManagerImpl::getAccountList(const std::string& sequenceId) AccountMap::iterator iter = _accountMap.begin(); while ( iter != _accountMap.end() ) { - tk.push_back(iter->first); - if ( iter->second->isEnabled() ) { - tk.push_back("Active"); - _gui->sendMessage("130", sequenceId, tk); - oneActive = true; - } else { - tk.push_back("Inactive"); - _gui->sendMessage("131", sequenceId, tk); + if ( iter->second != 0 ) { + _debug("Account List: %s\n", iter->first.data()); + tk.push_back(iter->first); + if ( iter->second->isEnabled() ) { + tk.push_back("Active"); + _gui->sendMessage("130", sequenceId, tk); + oneActive = true; + } else { + tk.push_back("Inactive"); + _gui->sendMessage("131", sequenceId, tk); + } + tk.clear(); } - tk.clear(); iter++; } @@ -1618,23 +1651,33 @@ short ManagerImpl::loadAccountMap() { short nbAccount = 0; - + Account* tmpAccount; + // SIP Loading X account... short nbAccountSIP = ACCOUNT_SIP_COUNT_DEFAULT; for (short iAccountSIP = 0; iAccountSIP<nbAccountSIP; iAccountSIP++) { - std::ostringstream accountName; - accountName << "SIP" << iAccountSIP; - _accountMap[accountName.str()] = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, accountName.str()); - nbAccount++; + std::ostringstream accountName; + accountName << "SIP" << iAccountSIP; + + tmpAccount = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, accountName.str()); + if (tmpAccount!=0) { + _debug("Adding Account: %s\n", accountName.str().data()); + _accountMap[accountName.str()] = tmpAccount; + nbAccount++; + } } // IAX Loading X account... short nbAccountIAX = ACCOUNT_IAX_COUNT_DEFAULT; for (short iAccountIAX = 0; iAccountIAX<nbAccountIAX; iAccountIAX++) { - std::ostringstream accountName; - accountName << "IAX" << iAccountIAX; - _accountMap[accountName.str()] = AccountCreator::createAccount(AccountCreator::IAX_ACCOUNT, accountName.str()); - nbAccount++; + std::ostringstream accountName; + accountName << "IAX" << iAccountIAX; + tmpAccount = AccountCreator::createAccount(AccountCreator::IAX_ACCOUNT, accountName.str()); + if (tmpAccount!=0) { + _debug("Adding Account: %s\n", accountName.str().data()); + _accountMap[accountName.str()] = tmpAccount; + nbAccount++; + } } return nbAccount;