diff --git a/include/qredis/reply.h b/include/qredis/reply.h index 8724f41..1fc3516 100644 --- a/include/qredis/reply.h +++ b/include/qredis/reply.h @@ -18,6 +18,7 @@ namespace QRedis * @brief Reply types */ enum Type { + /** * @brief A status reply * @@ -25,6 +26,7 @@ namespace QRedis * by the server as a QString. */ Status, + /** * @brief An error reply * @@ -32,6 +34,7 @@ namespace QRedis * the server as a QString. */ Error, + /** * @brief An integer reply * @@ -39,6 +42,7 @@ namespace QRedis * the server as a qlonglong. */ Integer, + /** * @brief A bulk reply * @@ -46,6 +50,7 @@ namespace QRedis * the server as a QByteArray. */ Bulk, + /** * @brief A multi-bulk reply * @@ -73,7 +78,7 @@ namespace QRedis * @brief Returns the value of the reply * @return the reply value */ - QVariant & value() const { return _value; } + const QVariant & value() const { return _value; } private: diff --git a/include/qredis/request.h b/include/qredis/request.h index 82564b7..e2577ef 100644 --- a/include/qredis/request.h +++ b/include/qredis/request.h @@ -5,6 +5,7 @@ #include #include +#include #include "qredis_export.h" namespace QRedis @@ -41,40 +42,10 @@ namespace QRedis Q_SIGNALS: /** - * @brief Emitted when a status reply is received - * @param message a descriptive status message + * @brief Emitted when a reply is received + * @param reply the reply received */ - void status(const QString & message); - - /** - * @brief Emitted when an error reply is received - * @param generic a generic error identifer - * @param specific a more specific error message - */ - void error(const QString & generic, const QString & specific); - - /** - * @brief Emitted when an integer reply is received - * @param value the integer value - */ - void integer(qlonglong value); - - /** - * @brief Emitted when a bulk reply is received - * @param value the value as a byte array - */ - void bulk(const QByteArray & value); - - /** - * @brief Emitted when a multi-bulk reply is received - * @param a list of bulk values - */ - void multiBulk(const QVariantList & values); - - /** - * @brief Emitted when any reply is received - */ - void reply(); + void reply(Reply & reply); private: diff --git a/src/client.cpp b/src/client.cpp index bd503a6..70666b8 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -8,37 +8,12 @@ ClientPrivate::ClientPrivate(Client * client) { connect(&socket, SIGNAL(connected()), client, SIGNAL(connected())); connect(&socket, SIGNAL(disconnected()), client, SIGNAL(disconnected())); - - connect(&parser, SIGNAL(status(QString)), SLOT(sendStatus(QString))); - connect(&parser, SIGNAL(error(QString,QString)), SLOT(sendError(QString,QString))); - connect(&parser, SIGNAL(integer(qlonglong)), SLOT(sendInteger(qlonglong))); - connect(&parser, SIGNAL(bulk(QByteArray)), SLOT(sendBulk(QByteArray))); - connect(&parser, SIGNAL(multiBulk(QVariantList)), SLOT(sendMultiBulk(QVariantList))); + connect(&parser, SIGNAL(reply(QRedis::Reply&)), SLOT(sendReply(Reply&))); } -void ClientPrivate::sendStatus(const QString & message) +void ClientPrivate::sendReply(Reply & reply) { - emit queue.dequeue()->status(message); -} - -void ClientPrivate::sendError(const QString & generic, const QString & specific) -{ - emit queue.dequeue()->error(generic, specific); -} - -void ClientPrivate::sendInteger(qlonglong value) -{ - emit queue.dequeue()->integer(value); -} - -void ClientPrivate::sendBulk(const QByteArray & value) -{ - emit queue.dequeue()->bulk(value); -} - -void ClientPrivate::sendMultiBulk(const QVariantList & values) -{ - emit queue.dequeue()->multiBulk(values); + emit queue.dequeue()->reply(reply); } Client::Client(QObject * parent) diff --git a/src/client_p.h b/src/client_p.h index 7bc7074..50b25af 100644 --- a/src/client_p.h +++ b/src/client_p.h @@ -6,6 +6,7 @@ #include #include +#include #include #include "lexer.h" #include "parser.h" @@ -28,11 +29,7 @@ namespace QRedis private Q_SLOTS: - void sendStatus(const QString &); - void sendError(const QString &, const QString &); - void sendInteger(qlonglong); - void sendBulk(const QByteArray &); - void sendMultiBulk(const QVariantList &); + void sendReply(Reply &); }; } diff --git a/src/parser.cpp b/src/parser.cpp index 695a1bc..db05d41 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -37,14 +37,14 @@ void Parser::readUnsafeString(const QString & value) stack.removeLast(); if(action == Task::ReadStatus) - emit status(value); + ;//emit status(value); else if(action == Task::ReadError) { int pos = value.indexOf(' '); - emit error(value.left(pos), value.right(pos + 1)); + ;//emit error(value.left(pos), value.right(pos + 1)); } else if(!stack.count()) - emit integer(value.toLongLong()); + ;//emit integer(value.toLongLong()); else { tos().value.toList().append(value); @@ -58,7 +58,7 @@ void Parser::readSafeString(const QByteArray & value) stack.removeLast(); if(!stack.count()) - emit bulk(value); + ;//emit bulk(value); else { tos().value.toList().append(value); @@ -75,7 +75,7 @@ void Parser::descend() if(stack.count() == 1) { - emit multiBulk(tos().value.toList()); + ;//emit multiBulk(tos().value.toList()); stack.removeLast(); break; } diff --git a/src/parser.h b/src/parser.h index 782d565..876ce0b 100644 --- a/src/parser.h +++ b/src/parser.h @@ -6,6 +6,7 @@ #include #include +#include #include "lexer.h" class Parser : public QObject @@ -19,11 +20,7 @@ class Parser : public QObject Q_SIGNALS: - void status(const QString &); - void error(const QString &, const QString &); - void integer(qlonglong); - void bulk(const QByteArray &); - void multiBulk(const QVariantList &); + void reply(QRedis::Reply &); private Q_SLOTS: diff --git a/src/request.cpp b/src/request.cpp index 8342f5e..f5aeff8 100644 --- a/src/request.cpp +++ b/src/request.cpp @@ -13,19 +13,7 @@ void RequestPrivate::quitEventLoop() Request::Request(QObject * parent) : QObject(parent), d(new RequestPrivate) { - /* - * Each of these signals also causes the generic reply() signal to be emitted. - */ - connect(this, SIGNAL(bulk(QByteArray)), SIGNAL(reply())); - connect(this, SIGNAL(error(QString,QString)), SIGNAL(reply())); - connect(this, SIGNAL(integer(qlonglong)), SIGNAL(reply())); - connect(this, SIGNAL(multiBulk(QVariantList)), SIGNAL(reply())); - connect(this, SIGNAL(status(QString)), SIGNAL(reply())); - - /* - * We also need to ensure that this object is deleted when the reply is received. - */ - connect(this, SIGNAL(reply()), SLOT(deleteLater())); + connect(this, SIGNAL(reply(Reply&)), SLOT(deleteLater())); } Request::~Request() @@ -38,8 +26,8 @@ bool Request::waitForReply(int msecs) timer.setInterval(msecs); timer.setSingleShot(true); - connect(&timer, SIGNAL(timeout()), &d->loop, SLOT(quit())); - connect(this, SIGNAL(reply()), d.data(), SLOT(quitEventLoop())); + connect(&timer, SIGNAL(timeout()), &d->loop, SLOT(quit())); + connect(this, SIGNAL(reply(Reply&)), d.data(), SLOT(quitEventLoop())); /* * If the timer fires, the return value will be 0.