Permalink
Browse files

CommandFactory handles unknown commands by returning a NullCommand

  • Loading branch information...
jferris committed Mar 21, 2012
1 parent 85dcc72 commit 354180acb59dc8e5f20953ff8ef707e906fa7d1e
Showing with 34 additions and 13 deletions.
  1. +4 −1 src/CommandFactory.cpp
  2. +6 −11 src/Connection.cpp
  3. +1 −1 src/Connection.h
  4. +10 −0 src/NullCommand.cpp
  5. +11 −0 src/NullCommand.h
  6. +2 −0 src/webkit_server.pro
View
@@ -1,4 +1,5 @@
#include "CommandFactory.h"
+#include "NullCommand.h"
#include "Visit.h"
#include "Find.h"
#include "Command.h"
@@ -28,5 +29,7 @@ CommandFactory::CommandFactory(WebPage *page, QObject *parent) : QObject(parent)
Command *CommandFactory::createCommand(const char *name, QStringList &arguments) {
#include "find_command.h"
- return NULL;
+ arguments.clear();
+ arguments.append(QString(name));
+ return new NullCommand(m_page, arguments);
}
View
@@ -39,17 +39,12 @@ void Connection::startCommand() {
m_commandWaiting = false;
if (m_pageSuccess) {
m_command = m_commandFactory->createCommand(m_commandName.toAscii().constData(), m_arguments);
- if (m_command) {
- connect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
- connect(m_command,
- SIGNAL(finished(Response *)),
- this,
- SLOT(finishCommand(Response *)));
- m_command->start();
- } else {
- QString failure = QString("[Capybara WebKit] Unknown command: ") + m_commandName + "\n";
- writeResponse(new Response(false, failure));
- }
+ connect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
+ connect(m_command,
+ SIGNAL(finished(Response *)),
+ this,
+ SLOT(finishCommand(Response *)));
+ m_command->start();
m_commandName = QString();
} else {
pageLoadFailed();
View
@@ -27,8 +27,8 @@ class Connection : public QObject {
QTcpSocket *m_socket;
QString m_commandName;
- Command *m_command;
QStringList m_arguments;
+ Command *m_command;
WebPage *m_page;
CommandParser *m_commandParser;
CommandFactory *m_commandFactory;
View
@@ -0,0 +1,10 @@
+#include "NullCommand.h"
+#include "WebPage.h"
+
+NullCommand::NullCommand(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
+
+void NullCommand::start() {
+ QString failure = QString("[Capybara WebKit] Unknown command: ") + arguments()[0] + "\n";
+ emit finished(new Response(false, failure));
+}
+
View
@@ -0,0 +1,11 @@
+#include "Command.h"
+
+class WebPage;
+
+class NullCommand : public Command {
+ Q_OBJECT
+
+ public:
+ NullCommand(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
View
@@ -34,6 +34,7 @@ HEADERS = \
CommandParser.h \
CommandFactory.h \
SetProxy.h \
+ NullCommand.h \
SOURCES = \
CurrentUrl.cpp \
@@ -69,6 +70,7 @@ SOURCES = \
CommandParser.cpp \
CommandFactory.cpp \
SetProxy.cpp \
+ NullCommand.cpp \
RESOURCES = webkit_server.qrc
QT += network webkit

0 comments on commit 354180a

Please sign in to comment.