Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CommandParser accepts a CommandFactory and emits a Command

  • Loading branch information...
commit 1ed54b1d59e3e23edc181d8a6606f70a8b2a6385 1 parent 3ebe0fa
Joe Ferris jferris authored
18 src/CommandParser.cpp
View
@@ -1,11 +1,14 @@
#include "CommandParser.h"
+#include "CommandFactory.h"
+#include "Command.h"
#include <QIODevice>
-CommandParser::CommandParser(QIODevice *device, QObject *parent) :
+CommandParser::CommandParser(QIODevice *device, CommandFactory *commandFactory, QObject *parent) :
QObject(parent) {
m_device = device;
m_expectingDataSize = -1;
+ m_commandFactory = commandFactory;
connect(m_device, SIGNAL(readyRead()), this, SLOT(checkNext()));
}
@@ -60,9 +63,14 @@ void CommandParser::processArgument(const char *data) {
}
if (m_arguments.length() == m_argumentsExpected) {
- emit commandReady(m_commandName, m_arguments);
- m_commandName = QString();
- m_arguments.clear();
- m_argumentsExpected = -1;
+ Command *command = m_commandFactory->createCommand(m_commandName.toAscii().constData(), m_arguments);
+ emit commandReady(command);
+ reset();
}
}
+
+void CommandParser::reset() {
+ m_commandName = QString();
+ m_arguments.clear();
+ m_argumentsExpected = -1;
+}
8 src/CommandParser.h
View
@@ -2,28 +2,32 @@
#include <QStringList>
class QIODevice;
+class CommandFactory;
+class Command;
class CommandParser : public QObject {
Q_OBJECT
public:
- CommandParser(QIODevice *device, QObject *parent = 0);
+ CommandParser(QIODevice *device, CommandFactory *commandFactory, QObject *parent = 0);
public slots:
void checkNext();
signals:
- void commandReady(QString commandName, QStringList arguments);
+ void commandReady(Command *command);
private:
void readLine();
void readDataBlock();
void processNext(const char *line);
void processArgument(const char *data);
+ void reset();
QIODevice *m_device;
QString m_commandName;
QStringList m_arguments;
int m_argumentsExpected;
int m_expectingDataSize;
+ CommandFactory *m_commandFactory;
};
9 src/Connection.cpp
View
@@ -6,14 +6,13 @@
#include "Command.h"
#include <QTcpSocket>
-#include <iostream>
Connection::Connection(QTcpSocket *socket, WebPage *page, QObject *parent) :
QObject(parent) {
m_socket = socket;
m_page = page;
- m_commandParser = new CommandParser(socket, this);
m_commandFactory = new CommandFactory(page, this);
+ m_commandParser = new CommandParser(socket, m_commandFactory, this);
m_runningCommand = NULL;
m_queuedCommand = NULL;
m_pageSuccess = true;
@@ -21,12 +20,12 @@ Connection::Connection(QTcpSocket *socket, WebPage *page, QObject *parent) :
m_pageLoadingFromCommand = false;
m_pendingResponse = NULL;
connect(m_socket, SIGNAL(readyRead()), m_commandParser, SLOT(checkNext()));
- connect(m_commandParser, SIGNAL(commandReady(QString, QStringList)), this, SLOT(commandReady(QString, QStringList)));
+ connect(m_commandParser, SIGNAL(commandReady(Command *)), this, SLOT(commandReady(Command *)));
connect(m_page, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
}
-void Connection::commandReady(QString commandName, QStringList arguments) {
- m_queuedCommand = m_commandFactory->createCommand(commandName.toAscii().constData(), arguments);
+void Connection::commandReady(Command *command) {
+ m_queuedCommand = command;
if (m_page->isLoading())
m_commandWaiting = true;
else
2  src/Connection.h
View
@@ -15,7 +15,7 @@ class Connection : public QObject {
Connection(QTcpSocket *socket, WebPage *page, QObject *parent = 0);
public slots:
- void commandReady(QString commandName, QStringList arguments);
+ void commandReady(Command *command);
void finishCommand(Response *response);
void pendingLoadFinished(bool success);
void pageLoadingFromCommand();
Please sign in to comment.
Something went wrong with that request. Please try again.