Skip to content

Commit

Permalink
Keep a running command and a queued command instead of a running comm…
Browse files Browse the repository at this point in the history
…and and name/arguments
  • Loading branch information
jferris committed Mar 21, 2012
1 parent 354180a commit 67d5e3d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
21 changes: 11 additions & 10 deletions src/Connection.cpp
Expand Up @@ -14,7 +14,8 @@ Connection::Connection(QTcpSocket *socket, WebPage *page, QObject *parent) :
m_page = page;
m_commandParser = new CommandParser(socket, this);
m_commandFactory = new CommandFactory(page, this);
m_command = NULL;
m_runningCommand = NULL;
m_queuedCommand = NULL;
m_pageSuccess = true;
m_commandWaiting = false;
m_pageLoadingFromCommand = false;
Expand All @@ -26,9 +27,7 @@ Connection::Connection(QTcpSocket *socket, WebPage *page, QObject *parent) :


void Connection::commandReady(QString commandName, QStringList arguments) {
m_commandName = commandName;
m_arguments = arguments;

m_queuedCommand = m_commandFactory->createCommand(commandName.toAscii().constData(), arguments);
if (m_page->isLoading())
m_commandWaiting = true;
else
Expand All @@ -38,14 +37,14 @@ void Connection::commandReady(QString commandName, QStringList arguments) {
void Connection::startCommand() {
m_commandWaiting = false;
if (m_pageSuccess) {
m_command = m_commandFactory->createCommand(m_commandName.toAscii().constData(), m_arguments);
m_runningCommand = m_queuedCommand;
m_queuedCommand = NULL;
connect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
connect(m_command,
connect(m_runningCommand,
SIGNAL(finished(Response *)),
this,
SLOT(finishCommand(Response *)));
m_command->start();
m_commandName = QString();
m_runningCommand->start();
} else {
pageLoadFailed();
}
Expand Down Expand Up @@ -79,8 +78,10 @@ void Connection::pageLoadFailed() {

void Connection::finishCommand(Response *response) {
disconnect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
m_command->deleteLater();
m_command = NULL;
m_runningCommand->deleteLater();
m_runningCommand = NULL;
delete m_queuedCommand;
m_queuedCommand = NULL;
if (m_pageLoadingFromCommand)
m_pendingResponse = response;
else
Expand Down
5 changes: 2 additions & 3 deletions src/Connection.h
Expand Up @@ -26,9 +26,8 @@ class Connection : public QObject {
void pageLoadFailed();

QTcpSocket *m_socket;
QString m_commandName;
QStringList m_arguments;
Command *m_command;
Command *m_runningCommand;
Command *m_queuedCommand;
WebPage *m_page;
CommandParser *m_commandParser;
CommandFactory *m_commandFactory;
Expand Down

0 comments on commit 67d5e3d

Please sign in to comment.