Added empty implementations of read*() methods.

This commit is contained in:
Nathan Osman 2013-07-01 10:26:38 -07:00
parent 4104a591e3
commit 3e49dc65f8
3 changed files with 94 additions and 4 deletions

View File

@ -34,7 +34,8 @@ set(QREDIS_SRC
# QRedis header files requiring MOC.
qt5_wrap_cpp(QREDIS_MOC
include/qredis/client.h
include/qredis/request.h)
include/qredis/request.h
src/client_p.h)
# Create the client library.
add_library(qredis SHARED

View File

@ -3,11 +3,75 @@
using namespace QRedis;
ClientPrivate::ClientPrivate(Client * client)
: q(client)
{
connect(&socket, &QTcpSocket::connected, q, &Client::connected);
connect(&socket, &QTcpSocket::disconnected, q, &Client::disconnected);
connect(&socket, &QTcpSocket::disconnected, this, &ClientPrivate::reset);
connect(&socket, &QTcpSocket::readyRead, this, &ClientPrivate::readReply);
}
bool ClientPrivate::readStatusOrError()
{
return false;
}
bool ClientPrivate::readInteger()
{
return false;
}
bool ClientPrivate::readBulk()
{
return false;
}
bool ClientPrivate::readMultiBulk()
{
return false;
}
void ClientPrivate::reset()
{
foreach(Request * request, queue)
request->deleteLater();
queue.clear();
}
// TODO: unrecognized replies in the switch should be handled.
void ClientPrivate::readReply()
{
buffer.append(socket.readAll());
while(!buffer.isEmpty())
{
bool finished;
switch(buffer[0])
{
case '+':
case '-':
finished = readStatusOrError();
break;
case ':':
finished = readInteger();
break;
case '$':
finished = readBulk();
break;
case '*':
finished = readMultiBulk();
break;
}
if(!finished)
break;
}
}
Client::Client(QObject * parent)
: QObject(parent), d(new ClientPrivate)
{
connect(&d->socket, &QTcpSocket::connected, this, &Client::connected);
connect(&d->socket, &QTcpSocket::disconnected, this, &Client::disconnected);
}
Client::~Client()
@ -26,6 +90,9 @@ void Client::disconnectFromHost()
Request * Client::sendCommand(const QString & command)
{
d->socket.write(QString("%1\r\n").arg(command).toUtf8());
Request * request = new Request(this);
d->queue.enqueue(request);
return request;
}

View File

@ -1,19 +1,41 @@
#ifndef QREDIS_CLIENT_P_H
#define QREDIS_CLIENT_P_H
#include <QObject>
#include <QQueue>
#include <QTcpSocket>
#include <qredis/client.h>
#include <qredis/request.h>
namespace QRedis
{
class ClientPrivate
class ClientPrivate : public QObject
{
Q_OBJECT
public:
ClientPrivate(Client *);
bool readStatusOrError();
bool readInteger();
bool readBulk();
bool readMultiBulk();
QTcpSocket socket;
QQueue<Request *> queue;
QByteArray buffer;
public slots:
void reset();
void readReply();
private:
Client * const q;
};
}