Адаптация библиотеки для Redis

This commit is contained in:
Andrei Astafev 2020-03-30 12:42:41 +03:00
parent 4069aaf315
commit 44466b80de
13 changed files with 106 additions and 64 deletions

View File

@ -1,7 +1,9 @@
#include <client.hpp>
#include <client_p.hpp>
using namespace qxredis;
namespace myx {
namespace redis {
ClientPrivate::ClientPrivate( Client* client ) :
lexer ( &socket ),
@ -64,3 +66,7 @@ bool Client::waitForDisconnected( int msecs )
{
return( d->socket.waitForDisconnected( msecs ) );
}
} // namespace redis
} // namespace myx

View File

@ -1,5 +1,5 @@
#ifndef QXREDIS_CLIENT_HPP_
#define QXREDIS_CLIENT_HPP_
#ifndef MYX_REDIS_CLIENT_HPP_
#define MYX_REDIS_CLIENT_HPP_
#include <QObject>
#include <QScopedPointer>
@ -7,15 +7,16 @@
#include <config.hpp>
#include <request.hpp>
namespace qxredis
{
namespace myx {
class QXREDIS_EXPORT ClientPrivate;
namespace redis {
class MYX_REDIS_EXPORT ClientPrivate;
/**
* @brief Provides access to a Redis server
*/
class QXREDIS_EXPORT Client : public QObject
class MYX_REDIS_EXPORT Client : public QObject
{
Q_OBJECT
@ -103,8 +104,10 @@ public:
private:
const QScopedPointer< ClientPrivate > d;
}; // class QXREDIS_EXPORT
}; // class MYX_REDIS_EXPORT
} // namespace QXRedis
} // namespace redis
#endif // QXREDIS_CLIENT_HPP_
} // namespace myx
#endif // MYX_REDIS_CLIENT_HPP_

View File

@ -1,5 +1,5 @@
#ifndef QREDIS_CLIENT_P_H
#define QREDIS_CLIENT_P_H
#ifndef MYX_REDIS_CLIENT_P_HPP_
#define MYX_REDIS_CLIENT_P_HPP_
#include <QObject>
#include <QQueue>
@ -11,8 +11,9 @@
#include <lexer.hpp>
#include <parser.hpp>
namespace qxredis
{
namespace myx {
namespace redis {
class ClientPrivate : public QObject
{
@ -28,9 +29,10 @@ public:
Parser parser;
private:
Q_SLOT void sendReply(const qxredis::Reply & );
Q_SLOT void sendReply(const myx::redis::Reply & );
}; // class ClientPrivate
} // namespace QRedis
}
}
#endif // QREDIS_CLIENT_H
#endif // MYX_REDIS_CLIENT_P_HPP_

View File

@ -1,14 +1,14 @@
#ifndef QXREDIS_CONFIG_HPP_
#define QXREDIS_CONFIG_HPP_
#ifndef MYX_REDIS_CONFIG_HPP_
#define MYX_REDIS_CONFIG_HPP_
#include <QtCore/qglobal.h>
// #if defined( qredis_EXPORTS )
#define QXREDIS_EXPORT Q_DECL_EXPORT
#define MYX_REDIS_EXPORT Q_DECL_EXPORT
// #else
// #define QXREDIS_EXPORT Q_DECL_IMPORT
// #define MYX_REDIS_EXPORT Q_DECL_IMPORT
// #endif
#include "config_flags.hpp"
#endif // QXREDIS_CONFIG_HPP_
#endif // MYX_REDIS_CONFIG_HPP_

View File

@ -4,4 +4,3 @@
// #cmakedefine
#endif /* @CMLIB_PROJECT_NAME_CANONICAL@_CONFIG_FLAGS_HPP_ */

View File

@ -1,6 +1,8 @@
#include "lexer.hpp"
using namespace qxredis;
namespace myx {
namespace redis {
Lexer::Lexer( QIODevice* device, QObject* parent ) :
QObject ( parent ),
@ -113,3 +115,7 @@ bool Lexer::readSafeString()
m_state = DoingNothing;
return( true );
}
} // namespace redis
} // namespace myx

View File

@ -1,11 +1,12 @@
#ifndef QXREDIS_LEXER_HPP_
#define QXREDIS_LEXER_HPP_
#ifndef MYX_REDIS_LEXER_HPP_
#define MYX_REDIS_LEXER_HPP_
#include <QIODevice>
#include <QObject>
namespace qxredis
{
namespace myx {
namespace redis {
class Lexer : public QObject
{
@ -46,6 +47,8 @@ private:
int m_length;
}; // class Lexer
} // namespace QRedis
} // namespace redis
#endif // QREDIS_LEXER_H
} // namespace myx
#endif // MYX_REDIS_LEXER_HPP_

View File

@ -1,6 +1,8 @@
#include "parser.hpp"
using namespace qxredis;
namespace myx {
namespace redis {
Parser::Parser( Lexer* lexer, QObject* parent ) :
QObject( parent )
@ -74,3 +76,7 @@ void Parser::descend()
tos().reply.value().toList().append( QVariant::fromValue( r ) );
}
}
} // namespace redis
} // namespace myx

View File

@ -1,5 +1,5 @@
#ifndef QREDIS_PARSER_H
#define QREDIS_PARSER_H
#ifndef MYX_REDIS_PARSER_HPP_
#define MYX_REDIS_PARSER_HPP_
#include <QList>
#include <QObject>
@ -9,8 +9,9 @@
#include <reply.hpp>
#include <lexer.hpp>
namespace qxredis
{
namespace myx {
namespace redis {
class Parser : public QObject
{
@ -20,7 +21,7 @@ public:
Parser( Lexer*, QObject* = nullptr );
virtual ~Parser() = default;
Q_SIGNAL void reply( const qxredis::Reply& );
Q_SIGNAL void reply( const myx::redis::Reply& );
private:
Q_SLOT void readCharacter( const char );
@ -49,6 +50,8 @@ public:
Task& tos() { return( stack.last() ); }
}; // class Parser
} // namespace QRedis
} // namespace redis
#endif // QREDIS_PARSER_H
} // namespace myx
#endif // MYX_REDIS_PARSER_HPP_

View File

@ -1,17 +1,18 @@
#ifndef QXREDIS_REPLY_HPP_
#define QXREDIS_REPLY_HPP_
#ifndef MYX_REDIS_REPLY_HPP_
#define MYX_REDIS_REPLY_HPP_
#include <QVariant>
#include <config.hpp>
namespace qxredis
{
namespace myx {
namespace redis {
/**
* @brief Represents a Redis reply
*/
class QXREDIS_EXPORT Reply
class MYX_REDIS_EXPORT Reply
{
public:
@ -98,10 +99,12 @@ private:
Type _type;
QVariant _value;
}; // class QXREDIS_EXPORT Reply
}; // class MYX_REDIS_EXPORT Reply
} // namespace qxredis
} // namespace redis
Q_DECLARE_METATYPE( qxredis::Reply )
} // namespace myx
#endif // QXREDIS_REPLY_HPP_
Q_DECLARE_METATYPE( myx::redis::Reply )
#endif // MYX_REDIS_REPLY_HPP_

View File

@ -3,7 +3,9 @@
#include <request.hpp>
#include <request_p.hpp>
using namespace qxredis;
namespace myx {
namespace redis {
void RequestPrivate::quitEventLoop()
{
@ -34,3 +36,7 @@ bool Request::waitForReply( int msecs )
*/
return( ( d->loop.exec( QEventLoop::ExcludeUserInputEvents ) != 0 ) );
}
} // namespace redis
} // namespace myx

View File

@ -1,5 +1,5 @@
#ifndef QREDIS_REQUEST_H
#define QREDIS_REQUEST_H
#ifndef MYX_REDIS_REQUEST_HPP_
#define MYX_REDIS_REQUEST_HPP_
#include <QObject>
#include <QScopedPointer>
@ -7,15 +7,16 @@
#include <config.hpp>
#include <reply.hpp>
namespace qxredis
{
namespace myx {
class QXREDIS_EXPORT RequestPrivate;
namespace redis {
class MYX_REDIS_EXPORT RequestPrivate;
/**
* @brief Represents a Redis command and its response
*/
class QXREDIS_EXPORT Request : public QObject
class MYX_REDIS_EXPORT Request : public QObject
{
Q_OBJECT
@ -43,13 +44,15 @@ public:
* @brief Emitted when a reply is received
* @param reply the reply received
*/
Q_SIGNAL void reply( const qxredis::Reply& reply );
Q_SIGNAL void reply( const myx::redis::Reply& reply );
private:
const QScopedPointer< RequestPrivate > d;
}; // class QXREDIS_EXPORT
}; // class MYX_REDIS_EXPORT
} // namespace QRedis
} // namespace redis
#endif // QREDIS_REQUEST_H
} // namespace myx
#endif // MYX_REDIS_REQUEST_HPP_

View File

@ -1,11 +1,12 @@
#ifndef QREDIS_REQUEST_P_H
#define QREDIS_REQUEST_P_H
#ifndef MYX_REDIS_REQUEST_P_HPP_
#define MYX_REDIS_REQUEST_P_HPP_
#include <QEventLoop>
#include <QObject>
namespace qxredis
{
namespace myx {
namespace redis {
class RequestPrivate : public QObject
{
@ -18,6 +19,7 @@ public:
Q_SLOT void quitEventLoop();
};
} // namespace QRedis
}
#endif // QREDIS_REQUEST_P_H
}
#endif // MYX_REDIS_REQUEST_P_HPP_