Added empty implementations of read*() methods.
This commit is contained in:
parent
4104a591e3
commit
3e49dc65f8
|
|
@ -34,7 +34,8 @@ set(QREDIS_SRC
|
||||||
# QRedis header files requiring MOC.
|
# QRedis header files requiring MOC.
|
||||||
qt5_wrap_cpp(QREDIS_MOC
|
qt5_wrap_cpp(QREDIS_MOC
|
||||||
include/qredis/client.h
|
include/qredis/client.h
|
||||||
include/qredis/request.h)
|
include/qredis/request.h
|
||||||
|
src/client_p.h)
|
||||||
|
|
||||||
# Create the client library.
|
# Create the client library.
|
||||||
add_library(qredis SHARED
|
add_library(qredis SHARED
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,75 @@
|
||||||
|
|
||||||
using namespace QRedis;
|
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)
|
Client::Client(QObject * parent)
|
||||||
: QObject(parent), d(new ClientPrivate)
|
: QObject(parent), d(new ClientPrivate)
|
||||||
{
|
{
|
||||||
connect(&d->socket, &QTcpSocket::connected, this, &Client::connected);
|
|
||||||
connect(&d->socket, &QTcpSocket::disconnected, this, &Client::disconnected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Client::~Client()
|
Client::~Client()
|
||||||
|
|
@ -26,6 +90,9 @@ void Client::disconnectFromHost()
|
||||||
|
|
||||||
Request * Client::sendCommand(const QString & command)
|
Request * Client::sendCommand(const QString & command)
|
||||||
{
|
{
|
||||||
|
d->socket.write(QString("%1\r\n").arg(command).toUtf8());
|
||||||
|
|
||||||
Request * request = new Request(this);
|
Request * request = new Request(this);
|
||||||
d->queue.enqueue(request);
|
d->queue.enqueue(request);
|
||||||
|
return request;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,41 @@
|
||||||
#ifndef QREDIS_CLIENT_P_H
|
#ifndef QREDIS_CLIENT_P_H
|
||||||
#define QREDIS_CLIENT_P_H
|
#define QREDIS_CLIENT_P_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
#include <QQueue>
|
#include <QQueue>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
|
|
||||||
|
#include <qredis/client.h>
|
||||||
#include <qredis/request.h>
|
#include <qredis/request.h>
|
||||||
|
|
||||||
namespace QRedis
|
namespace QRedis
|
||||||
{
|
{
|
||||||
class ClientPrivate
|
class ClientPrivate : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
ClientPrivate(Client *);
|
||||||
|
|
||||||
|
bool readStatusOrError();
|
||||||
|
bool readInteger();
|
||||||
|
bool readBulk();
|
||||||
|
bool readMultiBulk();
|
||||||
|
|
||||||
QTcpSocket socket;
|
QTcpSocket socket;
|
||||||
|
|
||||||
QQueue<Request *> queue;
|
QQueue<Request *> queue;
|
||||||
|
QByteArray buffer;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
void readReply();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Client * const q;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue