mirror of
https://github.com/QuasarApp/Heart.git
synced 2025-05-08 07:29:42 +00:00
change macross system
This commit is contained in:
parent
88b1d5a620
commit
88f4e92ffd
HeartTests/units
src
@ -12,7 +12,7 @@
|
||||
#define LOCAL_TEST_PORT TEST_PORT + 4
|
||||
|
||||
class BigPackage: public QH::PKG::AbstractData {
|
||||
QH_PACKAGE_AUTO(BigPackage)
|
||||
QH_PACKAGE_AUTO("BigPackage")
|
||||
|
||||
public:
|
||||
BigPackage(){
|
||||
|
@ -48,7 +48,6 @@ public:
|
||||
void setApisVersions(const VersionData &newApisVersions);
|
||||
|
||||
protected:
|
||||
unsigned int localCode() const override {return typeid(APIVersion).hash_code();}
|
||||
QDataStream &fromStream(QDataStream &stream) override;
|
||||
QDataStream &toStream(QDataStream &stream) const override;
|
||||
|
||||
|
@ -33,7 +33,6 @@ public:
|
||||
|
||||
// StreamBase interface
|
||||
protected:
|
||||
unsigned int localCode() const override {return typeid(VersionIsReceived).hash_code();}
|
||||
QDataStream &fromStream(QDataStream &stream) override;
|
||||
QDataStream &toStream(QDataStream &stream) const override;
|
||||
};
|
||||
|
@ -24,12 +24,6 @@ bool AbstractData::toPackage(Package &package,
|
||||
unsigned short reqVersion,
|
||||
unsigned int triggerHash) const {
|
||||
|
||||
if (!checkCmd()) {
|
||||
QuasarAppUtils::Params::log("You try send pacakge without QH_PACKAGE macross. Please add QH_PACKAGE macros to this class.",
|
||||
QuasarAppUtils::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isValid()) {
|
||||
return false;
|
||||
}
|
||||
@ -53,11 +47,6 @@ bool AbstractData::toPackage(Package &package,
|
||||
return package.isValid();
|
||||
}
|
||||
|
||||
bool AbstractData::checkCmd() const {
|
||||
unsigned int code = typeid (*this).hash_code();
|
||||
return code == localCode();
|
||||
}
|
||||
|
||||
bool AbstractData::isValid() const {
|
||||
return true;
|
||||
}
|
||||
|
@ -24,10 +24,14 @@
|
||||
#define PROTOCKOL_VERSION_RECEIVED_COMMAND PROTOCKOL_VERSION_COMMAND - 1
|
||||
|
||||
/**
|
||||
* @brief QH_PACKAGE This macross prepare data to send and create a global id for package. For get global id use the cmd method.
|
||||
* @brief QH_PACKAGE This macross prepare data to send and create a global id for package.
|
||||
* For get global id use the cmd method.
|
||||
* For get quick access for global command use the ClassName::command() method. This method is static.
|
||||
* @arg S This is unique id of the pacakge. Shold be some on all your network devices.
|
||||
* @arg V This is version of the package If you do not use multople versions use 0 or QH_PACKAGE_AUTO instand QH_PACKAGE.
|
||||
|
||||
*/
|
||||
#define QH_PACKAGE(X, S, V) \
|
||||
#define QH_PACKAGE(S, V) \
|
||||
public: \
|
||||
static unsigned short command(){\
|
||||
QByteArray ba = QString(S).toLocal8Bit();\
|
||||
@ -35,29 +39,28 @@
|
||||
} \
|
||||
static QString commandText(){return S;} \
|
||||
static unsigned short version(){ return V; } \
|
||||
unsigned short cmd() const override {return X::command();} \
|
||||
unsigned short ver() const override {return X::version();}; \
|
||||
unsigned short cmd() const override {return command();} \
|
||||
unsigned short ver() const override {return V;} \
|
||||
\
|
||||
QString cmdString() const override {return X::commandText();} \
|
||||
protected: \
|
||||
unsigned int localCode() const override {return typeid(X).hash_code();} \
|
||||
\
|
||||
QString cmdString() const override {return S;} \
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief QH_PACKAGE_AUTO This macross prepare data to send and create a global id for package.
|
||||
* @arg X This is unique id of the pacakge. shold be some on all your network devices.
|
||||
* @arg S This is unique id of the pacakge. shold be some on all your network devices.
|
||||
* @note auto pacakge create a 0 version of your package.
|
||||
*/
|
||||
#define QH_PACKAGE_AUTO(X) QH_PACKAGE(X,#X, 0)
|
||||
#define QH_PACKAGE_AUTO(S) QH_PACKAGE(S, 0)
|
||||
|
||||
/**
|
||||
* @brief QH_PACKAGE_AUTO This macross prepare data to send and create a global id for package.
|
||||
* @arg X This is unique id of the pacakge. shold be some on all your network devices.
|
||||
* @arg V This is version of the yor pacakge.
|
||||
* @note auto pacakge create a 0 version of your package.
|
||||
* @brief QH_PACKAGE_ONLY_VERSION This macross can be used only if parrent class alredy has QH_PACKAGE macros and int is some pacakge but with new version.
|
||||
* @arg B This is new version of the package.
|
||||
*/
|
||||
#define QH_PACKAGE_AUTO_VER(X, V) QH_PACKAGE(X,#X, V)
|
||||
#define QH_PACKAGE_ONLY_VERSION(V) \
|
||||
public: \
|
||||
static unsigned short version(){ return V; } \
|
||||
unsigned short ver() const override {return V;} \
|
||||
private: \
|
||||
|
||||
namespace QH {
|
||||
namespace PKG {
|
||||
@ -190,23 +193,11 @@ protected:
|
||||
*/
|
||||
explicit AbstractData();
|
||||
|
||||
/**
|
||||
* @brief localCode This method return local code
|
||||
* @return local command of this class. used for check QH_PACKAGE macro before send pacakge.
|
||||
*/
|
||||
virtual unsigned int localCode() const = 0;
|
||||
|
||||
/**
|
||||
* @brief isOldPackage This method mark package as a old, old pacakges use the Package::calcHashOld method for calculation hash sum of packages.
|
||||
* @return true if the pacakge is old.
|
||||
*/
|
||||
virtual bool isOldPackage() const;
|
||||
private:
|
||||
/**
|
||||
* @brief checkCmd This method check QH_PACKAGE macross.
|
||||
* @return true if the QH_PACKAGE macross is enabled else fal.
|
||||
*/
|
||||
bool checkCmd() const;;
|
||||
|
||||
};
|
||||
|
||||
|
@ -33,7 +33,7 @@ struct ErrorData {
|
||||
*/
|
||||
class HEARTSHARED_EXPORT BadRequest : public AbstractData
|
||||
{
|
||||
QH_PACKAGE_AUTO(BadRequest)
|
||||
QH_PACKAGE_AUTO("BadRequest")
|
||||
public:
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,7 @@ namespace PKG {
|
||||
*/
|
||||
class HEARTSHARED_EXPORT BigDataBase: public AbstractData
|
||||
{
|
||||
QH_PACKAGE_AUTO(BigDataBase)
|
||||
QH_PACKAGE_AUTO("BigDataBase")
|
||||
|
||||
public:
|
||||
BigDataBase();
|
||||
|
@ -27,7 +27,7 @@ namespace PKG {
|
||||
*/
|
||||
class HEARTSHARED_EXPORT BigDataHeader : public BigDataBase
|
||||
{
|
||||
QH_PACKAGE_AUTO(BigDataHeader)
|
||||
QH_PACKAGE_AUTO("BigDataHeader")
|
||||
|
||||
public:
|
||||
BigDataHeader();
|
||||
|
@ -20,7 +20,7 @@ namespace PKG {
|
||||
*/
|
||||
class HEARTSHARED_EXPORT BigDataPart : public BigDataBase
|
||||
{
|
||||
QH_PACKAGE_AUTO(BigDataPart)
|
||||
QH_PACKAGE_AUTO("BigDataPart")
|
||||
|
||||
public:
|
||||
BigDataPart();
|
||||
|
@ -19,7 +19,7 @@ namespace PKG {
|
||||
*/
|
||||
class HEARTSHARED_EXPORT BigDataRequest: public BigDataBase
|
||||
{
|
||||
QH_PACKAGE_AUTO(BigDataRequest)
|
||||
QH_PACKAGE_AUTO("BigDataRequest")
|
||||
|
||||
public:
|
||||
BigDataRequest();
|
||||
|
@ -19,7 +19,7 @@ namespace PKG {
|
||||
*/
|
||||
class BigDataWraper: public AbstractData
|
||||
{
|
||||
QH_PACKAGE_AUTO(BigDataWraper)
|
||||
QH_PACKAGE_AUTO("BigDataWraper")
|
||||
|
||||
public:
|
||||
BigDataWraper() = default;
|
||||
|
@ -27,7 +27,7 @@ namespace PKG {
|
||||
*/
|
||||
class HEARTSHARED_EXPORT CloseConnection: public AbstractData
|
||||
{
|
||||
QH_PACKAGE_AUTO(CloseConnection)
|
||||
QH_PACKAGE_AUTO("CloseConnection")
|
||||
|
||||
public:
|
||||
CloseConnection();
|
||||
|
@ -8,8 +8,7 @@
|
||||
#ifndef DATAPACK_H
|
||||
#define DATAPACK_H
|
||||
|
||||
#include "universaldata.h"
|
||||
|
||||
#include <abstractdata.h>
|
||||
|
||||
namespace QH {
|
||||
namespace PKG {
|
||||
@ -25,7 +24,7 @@ namespace PKG {
|
||||
template<class Package>
|
||||
class DataPack final: public AbstractData
|
||||
{
|
||||
QH_PACKAGE(DataPack<Package>, Package::commandText() + "Pack", 0)
|
||||
QH_PACKAGE(Package::commandText() + "Pack", Package::version())
|
||||
|
||||
public:
|
||||
|
||||
@ -114,6 +113,15 @@ public:
|
||||
_data = newToken;
|
||||
}
|
||||
|
||||
bool toBytesAdaptiveWithVersion(QByteArray& outputArray, unsigned short version) const override {
|
||||
if (AbstractData::toBytesAdaptiveWithVersion(outputArray, version)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
version == ???
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
QDataStream &fromStream(QDataStream &stream) override {
|
||||
|
||||
|
@ -18,12 +18,6 @@ class QSqlQuery;
|
||||
namespace QH {
|
||||
namespace PKG {
|
||||
|
||||
/**
|
||||
* The ONLY_DATABASE_PACKAGE macross is base macros for all database objects that do not use stream and network functions.
|
||||
*/
|
||||
#define ONLY_DATABASE_PACKAGE QH_PACKAGE(DBObject, "DBObject", 0)
|
||||
|
||||
|
||||
/**
|
||||
* @brief The PrepareResult enum is result of work prepare sql query of dbobjects.
|
||||
*/
|
||||
@ -95,7 +89,7 @@ typedef QMap<QString, DBVariant> DBVariantMap;
|
||||
*/
|
||||
class HEARTSHARED_EXPORT DBObject : public AbstractData
|
||||
{
|
||||
QH_PACKAGE_AUTO(DBObject)
|
||||
QH_PACKAGE("DBObject", 0)
|
||||
|
||||
public:
|
||||
|
||||
|
@ -22,7 +22,7 @@ namespace PKG {
|
||||
*/
|
||||
class HEARTSHARED_EXPORT DBObjectSet: public DBObject
|
||||
{
|
||||
QH_PACKAGE_AUTO(DBObjectSet)
|
||||
QH_PACKAGE_AUTO("DBObjectSet")
|
||||
|
||||
public:
|
||||
DBObjectSet(const QString table);
|
||||
|
@ -25,7 +25,6 @@ namespace PKG {
|
||||
*/
|
||||
class HEARTSHARED_EXPORT DeleteObject: public DBObject, public IToken
|
||||
{
|
||||
QH_PACKAGE_AUTO(DeleteObject)
|
||||
|
||||
public:
|
||||
DeleteObject();
|
||||
|
@ -19,7 +19,6 @@ namespace PKG {
|
||||
*/
|
||||
class HEARTSHARED_EXPORT GetMaxIntegerId: public DBObject
|
||||
{
|
||||
QH_PACKAGE_AUTO(GetMaxIntegerId)
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -38,7 +38,6 @@ namespace PKG {
|
||||
*/
|
||||
class HEARTSHARED_EXPORT GetSingleValue final: public DBObject
|
||||
{
|
||||
QH_PACKAGE_AUTO(GetSingleValue)
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -20,7 +20,7 @@ namespace PKG {
|
||||
*/
|
||||
class HEARTSHARED_EXPORT Ping: public AbstractData
|
||||
{
|
||||
QH_PACKAGE_AUTO(Ping)
|
||||
QH_PACKAGE_AUTO("Ping")
|
||||
|
||||
public:
|
||||
Ping();
|
||||
|
@ -32,8 +32,6 @@ namespace PKG {
|
||||
*/
|
||||
class HEARTSHARED_EXPORT SetSingleValue final: public DBObject
|
||||
{
|
||||
QH_PACKAGE_AUTO(SetSingleValue)
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief SetSingleValue This is default constructor of the update query generator.
|
||||
|
Loading…
x
Reference in New Issue
Block a user