Skip to content
Snippets Groups Projects
Commit 8cc05a3b authored by jpbl's avatar jpbl
Browse files

we can get the status now.

parent 1480d1d0
No related branches found
No related tags found
No related merge requests found
Showing
with 561 additions and 108 deletions
...@@ -41,7 +41,7 @@ class Call ...@@ -41,7 +41,7 @@ class Call
*/ */
bool isIncomming(); bool isIncomming();
std::string id() std::string id() const
{return mId;} {return mId;}
std::string call(const std::string &to); std::string call(const std::string &to);
......
#include "globals.h"
#include "CallStatus.hpp"
#include "PhoneLineManager.hpp"
CallStatus::CallStatus(const std::string &code,
const std::list< std::string > &args)
: CallRelatedEvent(code, args)
{
std::list< std::string > l = getUnusedArgs();
if(l.size() >= 3) {
mAccountId = *l.begin();
l.pop_front();
mDestination = *l.begin();
l.pop_front();
mStatus = *l.begin();
l.pop_front();
setUnusedArgs(l);
}
}
void
CallStatus::execute()
{
std::string id = getCallId();
if(id.size() > 0) {
_debug("%s status received for call ID: %s.\n",
mStatus.c_str(),
id.c_str());
PhoneLineManager::instance().addCall(mAccountId, getCallId(), mDestination, mStatus);
}
else {
_debug("Status invalid: %s\n", toString().c_str());
}
}
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@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 __CALLSTATUS_HPP__
#define __CALLSTATUS_HPP__
#include "Event.hpp"
class CallStatus : public CallRelatedEvent
{
public:
CallStatus(const std::string &code,
const std::list< std::string > &args);
void execute();
protected:
std::string mAccountId;
std::string mDestination;
std::string mStatus;
};
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@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 __CALLSTATUSFACTORY_HPP__
#define __CALLSTATUSFACTORY_HPP__
#include "EventFactory.hpp"
typedef utilspp::SingletonHolder< EventFactoryImpl< Event > > CallStatusFactory;
#endif
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include "Call.hpp" #include "Call.hpp"
#include "Event.hpp" #include "Event.hpp"
#include "PhoneLineManager.hpp"
Event::Event(const std::string &code, Event::Event(const std::string &code,
const std::list< std::string > &args) const std::list< std::string > &args)
...@@ -15,7 +14,7 @@ Event::Event(const std::string &code, ...@@ -15,7 +14,7 @@ Event::Event(const std::string &code,
void void
Event::execute() Event::execute()
{ {
_debug("Received: %s.\n", toString().c_str()); _debug("Received: %s\n", toString().c_str());
} }
std::string std::string
...@@ -48,48 +47,3 @@ CallRelatedEvent::getCallId() ...@@ -48,48 +47,3 @@ CallRelatedEvent::getCallId()
{ {
return mCallId; return mCallId;
} }
HangupEvent::HangupEvent(const std::string &code,
const std::list< std::string > &args)
: CallRelatedEvent(code, args)
{}
void
HangupEvent::execute()
{
std::string id = getCallId();
if(id.size() > 0) {
_debug("Hangup Event received for call ID: %s.\n", id.c_str());
PhoneLineManager::instance().hangup(id);
}
else {
_debug("Hangup Event invalid (missing call ID): %s\n", toString().c_str());
}
}
IncommingEvent::IncommingEvent(const std::string &code,
const std::list< std::string > &args)
: CallRelatedEvent(code, args)
{
std::list< std::string > l;
if(getUnusedArgs().size() >= 3) {
mAccountId = *l.begin();
l.pop_front();
mOrigin = *l.begin();
l.pop_front();
setUnusedArgs(l);
}
}
void
IncommingEvent::execute()
{
std::string id = getCallId();
if(id.size() > 0) {
_debug("Hangup Event received for call ID: %s.\n", id.c_str());
PhoneLineManager::instance().incomming(mAccountId, mOrigin, getCallId());
}
else {
_debug("Event invalid: %s\n", toString().c_str());
}
}
...@@ -59,27 +59,5 @@ private: ...@@ -59,27 +59,5 @@ private:
std::string mCallId; std::string mCallId;
}; };
class HangupEvent : public CallRelatedEvent
{
public:
HangupEvent(const std::string &code,
const std::list< std::string > &args);
virtual void execute();
};
class IncommingEvent : public CallRelatedEvent
{
public:
IncommingEvent(const std::string &code,
const std::list< std::string > &args);
virtual void execute();
private:
std::string mAccountId;
std::string mOrigin;
};
#endif #endif
...@@ -37,12 +37,13 @@ PhoneLine::unlock() ...@@ -37,12 +37,13 @@ PhoneLine::unlock()
} }
void void
PhoneLine::select() PhoneLine::select(bool hardselect)
{ {
if(!mSelected) { if(!mSelected) {
_debug("PhoneLine %d: I am selected.\n", mLine); _debug("PhoneLine %d: I am selected.\n", mLine);
mSelected = true; mSelected = true;
if(!hardselect) {
if(mCall) { if(mCall) {
if(mCall->isIncomming()) { if(mCall->isIncomming()) {
mCall->answer(); mCall->answer();
...@@ -51,19 +52,35 @@ PhoneLine::select() ...@@ -51,19 +52,35 @@ PhoneLine::select()
mCall->unhold(); mCall->unhold();
} }
} }
}
emit selected(); emit selected();
} }
} }
void void
PhoneLine::unselect() PhoneLine::disconnect()
{
mSelected = false;
_debug("PhoneLine %d: I am disconnected.\n", mLine);
if(mCall) {
delete mCall;
mCall = NULL;
}
emit unselected();
}
void
PhoneLine::unselect(bool hardselect)
{ {
if(mSelected) { if(mSelected) {
_debug("PhoneLine %d: I am unselected.\n", mLine); _debug("PhoneLine %d: I am unselected.\n", mLine);
mSelected = false; mSelected = false;
if(mCall) { if(mCall) {
if(!hardselect) {
mCall->hold(); mCall->hold();
}
emit backgrounded(); emit backgrounded();
} }
else { else {
...@@ -77,7 +94,7 @@ void ...@@ -77,7 +94,7 @@ void
PhoneLine::incomming(const Call &call) PhoneLine::incomming(const Call &call)
{ {
if(mCall) { if(mCall) {
_debug("PhoneLine %d: Trying to set an incomming call to an active call.\n", mLine); _debug("PhoneLine %d: Trying to set a phone line to an active call.\n", mLine);
} }
else { else {
mCall = new Call(call); mCall = new Call(call);
...@@ -173,3 +190,4 @@ PhoneLine::getCallId() ...@@ -173,3 +190,4 @@ PhoneLine::getCallId()
return id; return id;
} }
...@@ -64,12 +64,21 @@ public slots: ...@@ -64,12 +64,21 @@ public slots:
/** /**
* The user selected this line. * The user selected this line.
*/ */
void select(); void select(bool hardselect = false);
/** /**
* This phoneline is no longer selected. * This phoneline is no longer selected.
*/ */
void unselect(); void unselect(bool hardselect = false);
/**
* This will do a hard unselect. it means it
* will remove the call if there's one.
*/
void disconnect();
void setState(const std::string &){}
void setPeer(const std::string &){}
signals: signals:
......
...@@ -4,8 +4,9 @@ ...@@ -4,8 +4,9 @@
#include "globals.h" #include "globals.h"
#include "Call.hpp" #include "CallStatusFactory.hpp"
#include "Event.hpp" #include "SFLEvents.hpp"
#include "SFLCallStatus.hpp"
#include "PhoneLine.hpp" #include "PhoneLine.hpp"
#include "PhoneLineLocker.hpp" #include "PhoneLineLocker.hpp"
#include "PhoneLineManager.hpp" #include "PhoneLineManager.hpp"
...@@ -16,9 +17,22 @@ PhoneLineManagerImpl::PhoneLineManagerImpl() ...@@ -16,9 +17,22 @@ PhoneLineManagerImpl::PhoneLineManagerImpl()
, mCurrentLine(NULL) , mCurrentLine(NULL)
, mIsInitialized(false) , mIsInitialized(false)
{ {
EventFactory::instance().registerEvent< HangupEvent >("002");
EventFactory::instance().registerEvent< IncommingEvent >("001"); EventFactory::instance().registerEvent< IncommingEvent >("001");
EventFactory::instance().registerEvent< HangupEvent >("002");
EventFactory::instance().registerEvent< TryingStatus >("110");
EventFactory::instance().registerEvent< RingingStatus >("111");
EventFactory::instance().registerEvent< HoldStatus >("112");
EventFactory::instance().registerEvent< EstablishedStatus >("113");
EventFactory::instance().registerEvent< BusyStatus >("114");
EventFactory::instance().registerEvent< CongestionStatus >("115");
EventFactory::instance().registerEvent< WrongNumberStatus >("116");
QObject::connect(this, SIGNAL(disconnected()),
this, SLOT(closeSession()));
QObject::connect(this, SIGNAL(readyToHandleEvents),
this, SLOT(handleEvents()));
QObject::connect(this, SIGNAL(connected()), QObject::connect(this, SIGNAL(connected()),
this, SIGNAL(readyToSendStatus()));
QObject::connect(this, SIGNAL(readyToSendStatus()),
this, SLOT(startSession())); this, SLOT(startSession()));
} }
...@@ -72,10 +86,37 @@ PhoneLineManagerImpl::startSession() ...@@ -72,10 +86,37 @@ PhoneLineManagerImpl::startSession()
{ {
isInitialized(); isInitialized();
mSession->getCallStatus();
}
void
PhoneLineManagerImpl::handleEvents()
{
isInitialized();
mSession->getEvents(); mSession->getEvents();
} }
void
PhoneLineManagerImpl::closeSession()
{
isInitialized();
QMutexLocker guard(&mPhoneLinesMutex);
mCurrentLineMutex.lock();
mCurrentLine = NULL;
mCurrentLineMutex.unlock();
unsigned int i = 0;
while(i < mPhoneLines.size()) {
PhoneLineLocker guard(mPhoneLines[i]);
mPhoneLines[i]->disconnect();
i++;
}
}
PhoneLine * PhoneLine *
PhoneLineManagerImpl::getCurrentLine() PhoneLineManagerImpl::getCurrentLine()
{ {
...@@ -90,6 +131,7 @@ PhoneLineManagerImpl::setNbLines(unsigned int nb) ...@@ -90,6 +131,7 @@ PhoneLineManagerImpl::setNbLines(unsigned int nb)
{ {
isInitialized(); isInitialized();
QMutexLocker guard(&mPhoneLinesMutex);
mPhoneLines.clear(); mPhoneLines.clear();
for(unsigned int i = 0; i < nb; i++) { for(unsigned int i = 0; i < nb; i++) {
mPhoneLines.push_back(new PhoneLine(*mSession, i + 1)); mPhoneLines.push_back(new PhoneLine(*mSession, i + 1));
...@@ -209,12 +251,39 @@ PhoneLineManagerImpl::sendKey(Qt::Key c) ...@@ -209,12 +251,39 @@ PhoneLineManagerImpl::sendKey(Qt::Key c)
} }
void
PhoneLineManagerImpl::selectLine(const std::string &callId, bool hardselect)
{
isInitialized();
PhoneLine *selectedLine = NULL;
mPhoneLinesMutex.lock();
unsigned int line = 0;
while(!selectedLine && line < mPhoneLines.size()) {
if(mPhoneLines[line]->getCallId() == callId) {
selectedLine = mPhoneLines[line];
}
else {
line++;
}
}
mPhoneLinesMutex.unlock();
if(selectedLine) {
selectLine(line, hardselect);
}
else {
_debug("PhoneLineManager: Tried to selected line with call ID (%s), "
"which appears to be invalid.\n", callId.c_str());
}
}
/** /**
* Warning: This function might 'cause a problem if * Warning: This function might 'cause a problem if
* we select 2 line in a very short time. * we select 2 line in a very short time.
*/ */
void void
PhoneLineManagerImpl::selectLine(unsigned int line) PhoneLineManagerImpl::selectLine(unsigned int line, bool hardselect)
{ {
isInitialized(); isInitialized();
...@@ -237,18 +306,18 @@ PhoneLineManagerImpl::selectLine(unsigned int line) ...@@ -237,18 +306,18 @@ PhoneLineManagerImpl::selectLine(unsigned int line)
if(oldLine != selectedLine) { if(oldLine != selectedLine) {
if(oldLine != NULL) { if(oldLine != NULL) {
PhoneLineLocker guard(oldLine); PhoneLineLocker guard(oldLine);
oldLine->unselect(); oldLine->unselect(hardselect);
} }
PhoneLineLocker guard(selectedLine); PhoneLineLocker guard(selectedLine);
selectedLine->select(); selectedLine->select(hardselect);
if(selectedLine->isAvailable()) { if(selectedLine->isAvailable()) {
mSession->playTone(); mSession->playTone();
} }
} }
} }
else { else {
_debug("Tried to selected line %d, which appears to be invalid.\n", line); _debug("PhoneLineManager: Tried to selected line %d, which appears to be invalid.\n", line);
} }
} }
...@@ -336,19 +405,38 @@ PhoneLineManagerImpl::clear() ...@@ -336,19 +405,38 @@ PhoneLineManagerImpl::clear()
void void
PhoneLineManagerImpl::incomming(const std::string &, PhoneLineManagerImpl::incomming(const std::string &,
const std::string &, const std::string &peer,
const std::string &callId) const std::string &callId)
{
Call call(*mSession, callId, true);
addCall(call, peer, "Incomming");
}
void
PhoneLineManagerImpl::addCall(const std::string &,
const std::string &callId,
const std::string &peer,
const std::string &state)
{
addCall(Call(*mSession, callId), peer, state);
}
void
PhoneLineManagerImpl::addCall(Call call,
const std::string &peer,
const std::string &state)
{ {
PhoneLine *selectedLine = getNextAvailableLine(); PhoneLine *selectedLine = getNextAvailableLine();
PhoneLineLocker guard(selectedLine, false); PhoneLineLocker guard(selectedLine, false);
Call call(*mSession, callId, true);
if(selectedLine) { if(selectedLine) {
selectedLine->incomming(call); selectedLine->incomming(call);
selectedLine->setPeer(peer);
selectedLine->setState(state);
} }
else { else {
_debug("There's no available lines here for the incomming call ID: %s.\n", _debug("PhoneLineManager: There's no available lines here for the incomming call ID: %s.\n",
callId.c_str()); call.id().c_str());
call.notAvailable(); call.notAvailable();
} }
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
class PhoneLine; class PhoneLine;
#include "Account.hpp" #include "Account.hpp"
#include "Call.hpp"
#include "EventFactory.hpp" #include "EventFactory.hpp"
#include "Session.hpp" #include "Session.hpp"
...@@ -46,6 +47,9 @@ signals: ...@@ -46,6 +47,9 @@ signals:
void selected(unsigned int); void selected(unsigned int);
void connected(); void connected();
void disconnected(); void disconnected();
void readyToSendStatus();
void readyToHandleEvents();
void gotErrorOnCallStatus();
public slots: public slots:
/** /**
...@@ -106,10 +110,25 @@ public slots: ...@@ -106,10 +110,25 @@ public slots:
*/ */
void call(const QString &to); void call(const QString &to);
/**
* This function will add an incomming call
* on a phone line.
*/
void incomming(const std::string &accountId, void incomming(const std::string &accountId,
const std::string &origin, const std::string &callId,
const std::string &callId); const std::string &peer);
/**
* This function is used to add a call on a
* phone line.
*/
void addCall(Call call,
const std::string &peer,
const std::string &state);
void addCall(const std::string &accountId,
const std::string &callId,
const std::string &peer,
const std::string &state);
/** /**
* This function will make a call on the * This function will make a call on the
...@@ -124,7 +143,16 @@ public slots: ...@@ -124,7 +143,16 @@ public slots:
* This function will switch the lines. If the line * This function will switch the lines. If the line
* is invalid, it just do nothing. * is invalid, it just do nothing.
*/ */
void selectLine(unsigned int line); void selectLine(unsigned int line,
bool hardselect = false);
/**
* This function will switch the line to the line having
* the given call id. If the line is invalid, it just do
* nothing.
*/
void selectLine(const std::string &callId,
bool hardselect = false);
/** /**
* This function will clear the buffer of the active * This function will clear the buffer of the active
...@@ -144,6 +172,18 @@ public slots: ...@@ -144,6 +172,18 @@ public slots:
*/ */
PhoneLine *selectNextAvailableLine(); PhoneLine *selectNextAvailableLine();
/**
* This function will send the getevents request
* to the server.
*
* NOTE: This function MUST be called AFTER getcallstatus's
* completion.
*/
void handleEvents();
void errorOnCallStatus()
{emit gotErrorOnCallStatus();}
private slots: private slots:
/** /**
* This will send all the command needed when a * This will send all the command needed when a
...@@ -151,6 +191,13 @@ public slots: ...@@ -151,6 +191,13 @@ public slots:
*/ */
void startSession(); void startSession();
/**
* This function is called when we are disconnected
* from the server. This will unselect all phone lines.
*/
void closeSession();
private: private:
void isInitialized(); void isInitialized();
......
...@@ -32,6 +32,20 @@ Request::Request(const std::string &sequenceId, ...@@ -32,6 +32,20 @@ Request::Request(const std::string &sequenceId,
, mArgs(args) , mArgs(args)
{} {}
std::list< std::string >
Request::parseArgs(const std::string &message)
{
std::istringstream stream(message);
std::string s;
std::list< std::string > args;
while(stream.good()) {
stream >> s;
args.push_back(s);
}
return args;
}
void void
Request::onError(const std::string &code, const std::string &message) Request::onError(const std::string &code, const std::string &message)
{ {
......
...@@ -37,6 +37,12 @@ class Request ...@@ -37,6 +37,12 @@ class Request
virtual ~Request(){} virtual ~Request(){}
/**
* This function will parse the message and will cut the message
* in many arguments.
*/
static std::list< std::string > parseArgs(const std::string &message);
/** /**
* This function will be called when the request * This function will be called when the request
* receive its answer, if the request didn't successfully * receive its answer, if the request didn't successfully
...@@ -162,7 +168,6 @@ class AccountRequest : public Request ...@@ -162,7 +168,6 @@ class AccountRequest : public Request
const std::string &command, const std::string &command,
const std::list< std::string > &args); const std::list< std::string > &args);
/** /**
* This function will be called when the request * This function will be called when the request
* receive its answer, if the request didn't successfully * receive its answer, if the request didn't successfully
......
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@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 __SFLCALLSTATUS_HPP__
#define __SFLCALLSTATUS_HPP__
#include "CallStatus.hpp"
typedef CallStatus TryingStatus;
typedef CallStatus RingingStatus;
typedef CallStatus HoldStatus;
typedef CallStatus EstablishedStatus;
typedef CallStatus BusyStatus;
typedef CallStatus CongestionStatus;
typedef CallStatus WrongNumberStatus;
#endif
#include "globals.h"
#include "PhoneLineManager.hpp"
#include "SFLEvents.hpp"
HangupEvent::HangupEvent(const std::string &code,
const std::list< std::string > &args)
: CallRelatedEvent(code, args)
{}
void
HangupEvent::execute()
{
std::string id = getCallId();
if(id.size() > 0) {
_debug("Hangup Event received for call ID: %s.\n", id.c_str());
PhoneLineManager::instance().hangup(id);
}
else {
_debug("Hangup Event invalid (missing call ID): %s\n", toString().c_str());
}
}
IncommingEvent::IncommingEvent(const std::string &code,
const std::list< std::string > &args)
: CallRelatedEvent(code, args)
{
std::list< std::string > l = getUnusedArgs();
if(l.size() >= 3) {
mAccountId = *l.begin();
l.pop_front();
mOrigin = *l.begin();
l.pop_front();
setUnusedArgs(l);
}
}
void
IncommingEvent::execute()
{
std::string id = getCallId();
if(id.size() > 0) {
_debug("Incomming Event received for call ID: %s.\n", id.c_str());
PhoneLineManager::instance().incomming(mAccountId, getCallId(), mOrigin);
}
else {
_debug("Incomming Event invalid: %s\n", toString().c_str());
}
}
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@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 __SFLEVENTS_HPP__
#define __SFLEVENTS_HPP__
#include "Event.hpp"
class HangupEvent : public CallRelatedEvent
{
public:
HangupEvent(const std::string &code,
const std::list< std::string > &args);
virtual void execute();
};
class IncommingEvent : public CallRelatedEvent
{
public:
IncommingEvent(const std::string &code,
const std::list< std::string > &args);
virtual void execute();
private:
std::string mAccountId;
std::string mOrigin;
};
#endif
...@@ -20,6 +20,7 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv) ...@@ -20,6 +20,7 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv)
Requester::instance().registerObject< Request >(std::string("playtone")); Requester::instance().registerObject< Request >(std::string("playtone"));
Requester::instance().registerObject< Request >(std::string("playdtmf")); Requester::instance().registerObject< Request >(std::string("playdtmf"));
Requester::instance().registerObject< EventRequest >(std::string("getevents")); Requester::instance().registerObject< EventRequest >(std::string("getevents"));
Requester::instance().registerObject< CallStatusRequest >(std::string("getcallstatus"));
Requester::instance().registerObject< CallRelatedRequest >(std::string("answer")); Requester::instance().registerObject< CallRelatedRequest >(std::string("answer"));
Requester::instance().registerObject< CallRelatedRequest >(std::string("notavailable")); Requester::instance().registerObject< CallRelatedRequest >(std::string("notavailable"));
Requester::instance().registerObject< CallRelatedRequest >(std::string("refuse")); Requester::instance().registerObject< CallRelatedRequest >(std::string("refuse"));
...@@ -67,5 +68,11 @@ SFLPhoneApp::initConnections(SFLPhoneWindow *w) ...@@ -67,5 +68,11 @@ SFLPhoneApp::initConnections(SFLPhoneWindow *w)
w, SLOT(askReconnect())); w, SLOT(askReconnect()));
QObject::connect(w, SIGNAL(reconnectAsked()), QObject::connect(w, SIGNAL(reconnectAsked()),
&PhoneLineManager::instance(), SLOT(connect())); &PhoneLineManager::instance(), SLOT(connect()));
QObject::connect(&PhoneLineManager::instance(), SIGNAL(gotErrorOnCallStatus()),
w, SLOT(askResendStatus()));
QObject::connect(w, SIGNAL(resendStatusAsked),
&PhoneLineManager::instance(), SIGNAL(readyToSendStatus()));
} }
...@@ -107,7 +107,7 @@ SFLPhoneWindow::askReconnect() ...@@ -107,7 +107,7 @@ SFLPhoneWindow::askReconnect()
"Do you want to try to reconnect? If not, the application\n" "Do you want to try to reconnect? If not, the application\n"
"will close."), "will close."),
QMessageBox::Retry | QMessageBox::Default, QMessageBox::Retry | QMessageBox::Default,
QMessageBox::Cancel | QMessageBox::Escape); QMessageBox::No | QMessageBox::Escape);
if (ret == QMessageBox::Retry) { if (ret == QMessageBox::Retry) {
emit reconnectAsked(); emit reconnectAsked();
} }
...@@ -115,3 +115,21 @@ SFLPhoneWindow::askReconnect() ...@@ -115,3 +115,21 @@ SFLPhoneWindow::askReconnect()
close(); close();
} }
} }
void
SFLPhoneWindow::askResendStatus()
{
int ret = QMessageBox::critical(NULL,
tr("SFLPhone status error"),
tr("The server returned an error for the lines status.\n"
"Do you want to try to resend this command? If not,\n"
"the application will close."),
QMessageBox::Retry | QMessageBox::Default,
QMessageBox::No | QMessageBox::Escape);
if (ret == QMessageBox::Retry) {
emit resendStatusAsked();
}
else {
close();
}
}
...@@ -22,6 +22,7 @@ private: ...@@ -22,6 +22,7 @@ private:
signals: signals:
void keyPressed(Qt::Key); void keyPressed(Qt::Key);
void reconnectAsked(); void reconnectAsked();
void resendStatusAsked();
public slots: public slots:
/** /**
...@@ -30,6 +31,12 @@ signals: ...@@ -30,6 +31,12 @@ signals:
*/ */
void askReconnect(); void askReconnect();
/**
* This function will prompt a message box, to ask
* if the user want to resend the getcallstatus request.
*/
void askResendStatus();
protected: protected:
void keyPressEvent(QKeyEvent *e); void keyPressEvent(QKeyEvent *e);
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "globals.h" #include "globals.h"
#include "PhoneLineManager.hpp" #include "PhoneLineManager.hpp"
#include "SFLRequest.hpp" #include "SFLRequest.hpp"
#include "CallStatus.hpp"
#include "CallStatusFactory.hpp"
EventRequest::EventRequest(const std::string &sequenceId, EventRequest::EventRequest(const std::string &sequenceId,
const std::string &command, const std::string &command,
...@@ -16,25 +18,57 @@ EventRequest::EventRequest(const std::string &sequenceId, ...@@ -16,25 +18,57 @@ EventRequest::EventRequest(const std::string &sequenceId,
void void
EventRequest::onError(const std::string &code, const std::string &message) EventRequest::onError(const std::string &code, const std::string &message)
{ {
_debug("EventRequest error: (%s) %s", code.c_str(), message.c_str()); _debug("EventRequest error: (%s)%s\n", code.c_str(), message.c_str());
} }
void void
EventRequest::onEntry(const std::string &code, const std::string &message) EventRequest::onEntry(const std::string &code, const std::string &message)
{ {
std::istringstream stream(message); std::auto_ptr< Event >
std::string s; e(EventFactory::instance().create(code, Request::parseArgs(message)));
std::list< std::string > args;
while(stream.good()) {
stream >> s;
args.push_back(s);
}
std::auto_ptr< Event > e(EventFactory::instance().create(code, args));
e->execute(); e->execute();
} }
void void
EventRequest::onSuccess(const std::string &code, const std::string &message) EventRequest::onSuccess(const std::string &code, const std::string &message)
{ {
_debug("EventRequest success: (%s) %s", code.c_str(), message.c_str()); _debug("EventRequest success: (%s)%s\n", code.c_str(), message.c_str());
}
CallStatusRequest::CallStatusRequest(const std::string &sequenceId,
const std::string &command,
const std::list< std::string > &args)
: Request(sequenceId, command, args)
{}
void
CallStatusRequest::onError(const std::string &code, const std::string &message)
{
_debug("CallStatusRequest error: (%s)%s\n", code.c_str(), message.c_str());
PhoneLineManager::instance().errorOnCallStatus();
}
void
CallStatusRequest::onEntry(const std::string &code, const std::string &message)
{
std::auto_ptr< Event >
e(EventFactory::instance().create(code, Request::parseArgs(message)));
e->execute();
}
void
CallStatusRequest::onSuccess(const std::string &code, const std::string &message)
{
_debug("CallStatusRequest success: (%s)%s\n", code.c_str(), message.c_str());
if(code == "206") {
std::list< std::string > args = Request::parseArgs(message);
if(args.size() >= 2) {
PhoneLineManager::instance().selectLine(*args.begin());
}
else {
_debug("CallStatusRequest Error: cannot get current line.\n");
}
}
PhoneLineManager::instance().handleEvents();
} }
...@@ -41,4 +41,39 @@ public: ...@@ -41,4 +41,39 @@ public:
}; };
class CallStatusRequest : public Request
{
public:
CallStatusRequest(const std::string &sequenceId,
const std::string &command,
const std::list< std::string > &args);
virtual ~CallStatusRequest(){}
/**
* This function will be called when the request
* receive its answer, if the request didn't successfully
* ended. When we have an error on an EventRequest, we should
* quit the program.
*/
virtual void onError(const std::string &code, const std::string &message);
/**
* This function will be called when the request
* receive an answer, but there's other answers to come.
* This will be dispatched to the valid event.
*/
virtual void onEntry(const std::string &code, const std::string &message);
/**
* This function will be called when the request
* receive its answer, if the request successfully
* ended. The event handling is gone, so we should
* quit.
*/
virtual void onSuccess(const std::string &code, const std::string &message);
};
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment