Collapsed individual reply signals to single reply signal that emits reference to Reply.
This commit is contained in:
parent
d42dc66f4e
commit
fa702fbe15
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <QScopedPointer>
|
||||
#include <QVariantList>
|
||||
|
||||
#include <qredis/reply.h>
|
||||
#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:
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <QTcpSocket>
|
||||
|
||||
#include <qredis/client.h>
|
||||
#include <qredis/reply.h>
|
||||
#include <qredis/request.h>
|
||||
#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 &);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <QVariant>
|
||||
#include <QVariantList>
|
||||
|
||||
#include <qredis/reply.h>
|
||||
#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:
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue