Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
QH Namespace Reference

The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart library. More...

Namespaces

namespace  ErrorCodes
 ErrorCodes This namesapce contains all error codes of the Heart Library.
 
namespace  PKG
 The PKG namesapce - this namespace contains all default packages of the Heart library. If you want create a pool request for Heart Library with own implemented packages you need to create a new package into a PKG namesapce.
 

Classes

class  AbstractKey
 The Abstractkey class is provide general hash function for all keys of Heart library. This class using for generate a hash code of any keyObject. More...
 
class  AbstractNode
 The AbstractNode class - Abstract implementation of node. this implementation have a methods for send and receive data messages, and work with crypto method for create a security connections betwin nodes. AbstractNode - is thread save class. More...
 
class  AbstractNodeInfo
 The AbstractNodeInfo class contains information about client or server connection and tcp socket of node. All node Info classes must be initialized in the AbstractNode::createNodeInfo methods. This implementation of nodeInf contains only trust of node and network socket. More...
 
class  AbstractNodeParser
 The AbstractNodeParser class is main parser of the abstract level of the hear lib. More...
 
class  AbstractTask
 The AbstractTask class. All tasks executed on separate thread. More...
 
class  AccessToken
 The AccessToken class contains information duration of the access. Token are byte array for validation access users or another network member on nodes. In usually cases toke add permissions for database objects. More...
 
class  APIVersionParser
 The APIVersionParser class This is main parser forthe main command. This parsers work only with the APIVersion packge;. More...
 
class  Async
 The Async class This is bundle of async templates and async wrappers. More...
 
class  AsyncLauncher
 The AsyncLauncher class is wraper of the Async class for support moving invokes to thread of the current object. More...
 
class  AsyncSqlDBWriter
 The AsyncSqlDbWriter class is some as SqlDBWriter but run all command in own thread. This class is thread save. More...
 
class  BigDataParser
 The BigDataParser class is main manager for control big data packages. More...
 
class  DataBase
 The DataBase class is DataBase base implementation. This implementation contains methods for work with database. DataBaseNode is thread save class. More...
 
class  DataSender
 The DataSender class this class create a queue for sendet data to network. More...
 
class  DbAddress
 The DbAddress class use to work with database addresses. Database Address it is structure with 2 values. More...
 
class  DbAddressKey
 The DbAddressKey class is implementation for calc hash key of DbAddress objects. More...
 
struct  DBPatch
 DBPatch This is function that should be upgrade database. More...
 
class  DistVersion
 The DistVersion class This is information of supported versions of the destinations api. More...
 
struct  Header
 The Header struct 32 bytes. More...
 
class  HostAddress
 The Host Address class this is wrapper of QHostAddress. Contains the NetworkAddress and network port. More...
 
class  iObjectProvider
 The iObjectProvider class is base interface for work with database objects. Using on database writers and database caches. More...
 
class  iParser
 The iParser class This class provide functions for parsing income packages. For yousing just override the iParser::parsePackage method. More...
 
class  ISqlDB
 The ISqlDB class it is db cache and bridge for DbWriters. Work Scheme of the database cache: More...
 
class  IToken
 The IToken classes interface for the validation user packages and user dates. More...
 
struct  PackaData
 The PackaData struct - private data of packages. More...
 
class  Package
 The Package struct. This is base structure for transporting data by network between QH nodes. The Package contains a 32 bytes header and Package::data array. The size on the header should be equals size of Package::data array. More...
 
class  PackageManager
 The PakcageManager class contains all processed packages. Working like a cache of packages. More...
 
struct  PoolData
 
struct  ReceiveData
 The ReceiveData struct This is private structure for contains informaton for parse packages. More...
 
class  Request
 The Request class is base interface for working with requests commands. More...
 
class  SoftDelete
 The SoftDelete class povide the soft delete functionality. All child classes of this class must be deleted using the softDelete method for preparring for delete. IF you delete object without prepare then destructor invoke the abort function in debug mode. For release mode destructor print error message only. More...
 
class  SqlDB
 The SqlDB class This is base implementation fo datatbase. The SqlDB do not use caches, all request run on the sqlwtiter class. More...
 
class  SqlDBWriter
 The SqlDBWriter class. This class write and read objects from database (hard level). Before working with database you need to initialize it. The SqlDBWriter support a any sql databases, For list of supported drivers see the Qt Docummentation https://doc.qt.io/qt-5/sql-driver.html For initialize a custom database driver you need to set an own params see the SqlDBWriter::initDb metthod. This class work only on own thread. For change working thread use the Qt method moveToThread. More...
 
class  StreamBase
 The StreamBase class add support streaming data for all children classes. For correctly working all serializations functions you need to override fromStream and toStream methods. All implementations of overridden method should be contains a invoke of method of base class. More...
 
class  StreamMultiversion
 The StreamMultiversion class this parser works with simple multiversion packages. More...
 
class  TaskScheduler
 The TaskScheduler class This class contains queue of all shedule tasks. More...
 
class  TcpSocket
 The AbstractSocket class This class is wraper of the QAbstract socket with slot implementation of the disconnect from host method. More...
 
class  WorkState
 The WorkState class is simple class with data of work state of node. More...
 

Typedefs

typedef QMap< unsigned short, QMap< unsigned short, DBPatch > > DBPatchMap
 DBPatchMap This is 2 depch map of the DBPatch structure when the first key it is version (from) and second key is version to.
 
typedef QHash< QString, DistVersionVersionData
 VersionData This is array of all available apis and supported its versions.
 
typedef QHash< unsigned short, DistVersionPackagesVersionData
 PackagesVersionData This is some as VersionData but for int commands.
 
using PacksMap = QHash< unsigned short, std::function< PKG::AbstractData *()> >
 PacksMap This is hash map where id is command of package and value is factory function.
 

Enumerations

enum class  SslMode { NoSSL }
 The SslMode enum This enum contatins options for set ssl mode of node (server). For more information see AbstractNode::useSelfSignedSslConfiguration AbstractNode::useSystemSslConfiguration and AbstractNode::disableSSL methods. More...
 
enum class  AddNodeError { UnknownError , HostNotFound , RegisterSocketFailed }
 The AddNodeError enum contains error code that can be occured after invoke the AbstractNode::addNode mehod. More...
 
enum class  TrustNode : unsigned char { Undefined = 0xFF , Default = 100 , Restore = 20 , Baned = 0 }
 The TrustNode enum contains cases for trust of the client or nodes. More...
 
enum class  NodeCoonectionStatus : int { NotConnected , Connected , Confirmed }
 The AbstractNodeState enum - This is status of the known nodes or clients. More...
 
enum class  ScheduleMode : int { SingleWork , Repeat , TimePoint }
 The ScheduleMode enum contails list of the shedule modes. More...
 
enum class  ParserResult { Error = 0 , NotProcessed = 1 , Processed = 2 }
 The ParserResult enum. Error - parser detect a errorob package. NotProcessed - the parser does not know what to do with the package or has not finished processing it. Processed - the parser finished processing correctly. More...
 
enum class  SqlDBCasheWriteMode : int { Default = 0x0 , On_New_Thread = 0x1 , Force = 0x2 }
 The SqlDBCasheWriteMode enum contains list of available modes of write data into database. More...
 
enum class  CacheAction : int { None , Insert , Update , Delete }
 The CacheAction enum contains types of database cache actions. The any database caches save all changes in to hardware database. For saving all changes it use hash map with objects and its actions. Every type invokes own method for running an action of object. More...
 

Functions

bool init ()
 init This method initialize default resources of the Heart Library.
 
QString heartLibVersion ()
 heartLibVersion This method return version of library in format : major.commit.hash
 
uint qHash (NodeCoonectionStatus status)
 qHash - Simple hash function of NodeCoonectionStatus
 
qint64 qHash (const DbAddress &address)
 qHash This functions calls int 32 hash of address.
 
bool operator== (const DbAddress &left, const DbAddress &other)
 
bool operator!= (const DbAddress &left, const DbAddress &other)
 
QDataStream & operator>> (QDataStream &stream, HostAddress &address)
 
QDataStream & operator<< (QDataStream &stream, const HostAddress &address)
 
bool operator== (const HostAddress &left, const HostAddress &right)
 
bool operator!= (const HostAddress &left, const HostAddress &right)
 
uint qHash (const HostAddress &address)
 
constexpr uint qHash (CacheAction action)
 qHash calc hash of the CacheAction enum.
 
QDataStream & operator<< (QDataStream &stream, const StreamBase &obj)
 
QDataStream & operator>> (QDataStream &stream, StreamBase &obj)
 

Detailed Description

The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart library.

Usage:

  1. First one, you need to create a package for transporting data between server and client. For this you need to do Inheritance with the QF::PKG::AbstrcatData class.

Example: The package for transporting text data.

class MyPackage: public QH::AbstractData
{
public:
MyPackage();
// override this method for validation your package class
bool isValid() const {
return AbstractData::isValid();
}; /
// your data for for server of client
std::string _data = "";
protected:
// StreamBase interface override this methods for serialization your package
QDataStream &fromStream(QDataStream &stream) {
stream >> _data;
return stream;
}
QDataStream &toStream(QDataStream &stream) const {
stream << _data;
return stream;
}
};
The AbstractData class is provide base functions for transport data by network For create you own pac...
  1. You need to create a ApiParserClass - The API parser class should be inherited of the iParser class and implement all business logics of your client - server app.

Example:

class MyParser: public QH::iParser {
public:
MyParser(QH::AbstractNode* parentNode): QH::iParser(parentNode) {
registerPackageType<MyPackage>();
data = new BigPackage();
}
// iParser interface
public:
// override this method for processed received data.
ParserResult parsePackage(const Package &pkg,
const AbstractNodeInfo *sender) {
auto parentResult = AbstractNode::parsePackage(pkg, sender);
if (parentResult != ParserResult::NotProcessed) {
return parentResult;
}
auto result = commandHandler<MyPackage>(this, &MyClass::processMyPackage, pkg, sender, pkgHeader);
return result;
}
return ParserResult::NotProcessed;
}
bool processMyPackage(const QSharedPointer<MyPackage> &cardrequest,
const QH::AbstractNodeInfo *sender, const QH::Header &hdr) {
BaseId requesterId = getSender(sender, &cardrequest);
if (!cardrequest.isValid()) {
badRequest(sender->networkAddress(), hdr);
return ParserResult::Error;
}
cardrequest._data = "responce for client "
// responce only for servers.
sendData(cardrequest, sender->networkAddress(), &pkg.hdr);
return ParserResult::Processed;
}
// This vesion of the parser (any digital value.) .
int version() const override {return 0;};
QString parserId() const override {return "MyParser";};
};
The AbstractNodeInfo class contains information about client or server connection and tcp socket of n...
HostAddress networkAddress() const
networkAddress This method return network address of current node or client.
The AbstractNode class - Abstract implementation of node. this implementation have a methods for send...
@ Server
This is node can works only as a public server.
The iParser class This class provide functions for parsing income packages. For yousing just override...
Definition iparser.h:51
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13
@ NotProcessed
the parser does not know what to do with the package or has not finished processing it.
The Header struct 32 bytes.
Definition header.h:19
  1. You need to create a Server class. For this, you need to do Inheritance with the QF::AbstrcatData class

Example:

class TestingServer: public QH::AbstractNode {
Q_OBJECT
public:
TestingServer() {
addApiParser<MyParser>();
}
QH::AbstractNode::NodeType nodeType() const override {
}
};
NodeType
The NodeType enum contains types of the node. By default node contains only 3 types.

This is a simple echo server for our client - server application. For Run this serve use method QF::AbstrcatData::run

int main () {
TestingServer testServer();
testServer.run("127.0.0.1", 7777)
}
  1. Create a client application class. Client and server must be inheritance from QF::AbstrcatData class to support parsing packages.
    class TestingClient: public QH::AbstractNode {
    public:
    TestingClient() {
    addApiParser<MyParser>();
    }
    QH::AbstractNode::NodeType nodeType() const override {
    }
    };
    @ Client
    Node with this type is general clints nodes.

The basic principle of the library.

Node - it is the server or client implementation of any AbstractNode child's classes.

  • The node receives raw data from another network connection.
  • After parsing a raw data, the node converts a bytes array to QH::Package.
  • The Package creates a new thread for working with received request, so, all working of package working in own threads.
  • Next, the Node invokes a QH::iParser::parsePackage method of selected parsers. This method must be return QH::ParserResult.
  • IF you need to send response then use a unsigned int sendData(PKG::AbstractData *resp, const HostAddress& addere, const Header *req = nullptr).

About parsers

The Parser it is an object that works with your packages. You can create multiple version's parser for compatibility between node versions. Node will select most actually version that known both nodes. For example, server known parsers with version 1, 2 and 3 but client can work only with 1 and 2, so nodes choose parser v2 because all nodes known about this parser version.

You can create multiple types of the parsers. For example, you want to create an absolute new API and add it to the node. You need override Example:

TestingClient() {
}
void registerPackageType()
registerPackageType This method register package type T. This is need to prepare pacakge for parsing ...
Definition iparser.h:62

Typedef Documentation

◆ DBPatchMap

typedef QMap<unsigned short, QMap<unsigned short, DBPatch> > QH::DBPatchMap

DBPatchMap This is 2 depch map of the DBPatch structure when the first key it is version (from) and second key is version to.

See also
DataBaseNode::dbPatch
DBPatchMap

Definition at line 49 of file dbpatch.h.

◆ PackagesVersionData

typedef QHash<unsigned short, DistVersion> QH::PackagesVersionData

PackagesVersionData This is some as VersionData but for int commands.

Definition at line 78 of file distversion.h.

◆ PacksMap

using QH::PacksMap = typedef QHash<unsigned short, std::function<PKG::AbstractData *()> >

PacksMap This is hash map where id is command of package and value is factory function.

Definition at line 26 of file iparser.h.

◆ VersionData

typedef QHash<QString, DistVersion> QH::VersionData

VersionData This is array of all available apis and supported its versions.

Definition at line 73 of file distversion.h.

Enumeration Type Documentation

◆ AddNodeError

enum class QH::AddNodeError
strong

The AddNodeError enum contains error code that can be occured after invoke the AbstractNode::addNode mehod.

See also
AbstractNode::addNode
AbstractNode::addNodeFailed
AbstractNode::nodeAddedSucessful
Enumerator
UnknownError 

unknown error

HostNotFound 

This error ocurred when DNS server not responce to node or node can't find the server ip address by host.

RegisterSocketFailed 

This error ocurred when you try add baned node or server is overrload.

Definition at line 71 of file abstractnode.h.

◆ CacheAction

enum class QH::CacheAction : int
strong

The CacheAction enum contains types of database cache actions. The any database caches save all changes in to hardware database. For saving all changes it use hash map with objects and its actions. Every type invokes own method for running an action of object.

Enumerator
None 

Do nothing.

Insert 

Invoke the SqlDBWriter::insertObject method of a private database writer implementation.

Update 

Invoke the SqlDBWriter::updateObject method of a private database writer implementation.

Delete 

Invoke the SqlDBWriter::deleteObject method of a private database writer implementation.

Definition at line 44 of file isqldb.h.

◆ NodeCoonectionStatus

enum class QH::NodeCoonectionStatus : int
strong

The AbstractNodeState enum - This is status of the known nodes or clients.

Enumerator
NotConnected 

This node not sent data about its envirement and status of node socket is disconnected.

Connected 

The node with this status has socket status is connected.

Confirmed 

The node confirmed. Node with it status sent a information. requirement for confirm in to this node object.

Definition at line 45 of file abstractnodeinfo.h.

◆ ParserResult

enum class QH::ParserResult
strong

The ParserResult enum. Error - parser detect a errorob package. NotProcessed - the parser does not know what to do with the package or has not finished processing it. Processed - the parser finished processing correctly.

Enumerator
Error 

parser detect a errorob package.

NotProcessed 

the parser does not know what to do with the package or has not finished processing it.

Processed 

the parser finished processing correctly.

Definition at line 35 of file iparser.h.

◆ ScheduleMode

enum class QH::ScheduleMode : int
strong

The ScheduleMode enum contails list of the shedule modes.

Enumerator
SingleWork 

In this mode AbstractTask will be executed after time msecunds from the moment of adding this task.

Repeat 

In this mode AbstractTask will be executed task every time from the moment of adding this task.

TimePoint 

In this mode AbstractTask will be executed int time msecunds by Unix time.

Definition at line 20 of file abstracttask.h.

◆ SqlDBCasheWriteMode

enum class QH::SqlDBCasheWriteMode : int
strong

The SqlDBCasheWriteMode enum contains list of available modes of write data into database.

Enumerator
Default 

This is default mode. The database is written to the database with each function call no more often than the specified update interval. The recording is done in thread in which this function was called.

On_New_Thread 

This mode write a changes into another thread.

Force 

This mode writes all changes to the database as soon as they come to the cache.

Definition at line 29 of file isqldb.h.

◆ SslMode

enum class QH::SslMode
strong

The SslMode enum This enum contatins options for set ssl mode of node (server). For more information see AbstractNode::useSelfSignedSslConfiguration AbstractNode::useSystemSslConfiguration and AbstractNode::disableSSL methods.

Enumerator
NoSSL 

This is not secure connection without ssl encription. It is default value of new any node see AbstractNode(SslMode mode = SslMode::NoSSL, QObject * ptr = nullptr).

Definition at line 53 of file abstractnode.h.

◆ TrustNode

enum class QH::TrustNode : unsigned char
strong

The TrustNode enum contains cases for trust of the client or nodes.

Enumerator
Undefined 

Undefined node.

Default 

General trust of the node or client.

Restore 

This trusted of unbanned nodes or clients. Recomended trust of unbanned client. For more informations see method AbstrcatData::unBan

Baned 

Node with this trust value is forbidden.

Definition at line 27 of file abstractnodeinfo.h.

Function Documentation

◆ heartLibVersion()

HEARTSHARED_EXPORT QString QH::heartLibVersion ( )

heartLibVersion This method return version of library in format : major.commit.hash

Returns

Definition at line 20 of file heart.cpp.

◆ init()

bool HEARTSHARED_EXPORT QH::init ( )

init This method initialize default resources of the Heart Library.

Warning
Do not Forget invoke this method before using library.

Example :

#include <heart.h>
int main() {
if (!QH::init()) {
return 1;
}
// some code
return 0
}
bool init()
init This method initialize default resources of the Heart Library.
Definition heart.cpp:15
Returns
true if all resources initialize successful.

Definition at line 15 of file heart.cpp.

Here is the call graph for this function:

◆ operator!=() [1/2]

bool QH::operator!= ( const DbAddress left,
const DbAddress other 
)

Definition at line 50 of file dbaddress.cpp.

◆ operator!=() [2/2]

bool QH::operator!= ( const HostAddress left,
const HostAddress right 
)

Definition at line 100 of file hostaddress.cpp.

Here is the call graph for this function:

◆ operator<<() [1/2]

QDataStream & QH::operator<< ( QDataStream &  stream,
const HostAddress address 
)

Definition at line 87 of file hostaddress.cpp.

◆ operator<<() [2/2]

QDataStream & QH::operator<< ( QDataStream &  stream,
const StreamBase obj 
)
Parameters
streamThis is qt data stream object.
objThis is serialized object.
Returns
stream object.

Definition at line 67 of file streambase.cpp.

◆ operator==() [1/2]

bool QH::operator== ( const DbAddress left,
const DbAddress other 
)

Definition at line 27 of file dbaddress.cpp.

◆ operator==() [2/2]

bool QH::operator== ( const HostAddress left,
const HostAddress right 
)

Definition at line 96 of file hostaddress.cpp.

Here is the call graph for this function:

◆ operator>>() [1/2]

QDataStream & QH::operator>> ( QDataStream &  stream,
HostAddress address 
)

Definition at line 80 of file hostaddress.cpp.

◆ operator>>() [2/2]

QDataStream & QH::operator>> ( QDataStream &  stream,
StreamBase obj 
)
Parameters
streamThis is qt data stream object.
objThis is serialized object.
Returns
stream object.

Definition at line 71 of file streambase.cpp.

◆ qHash() [1/4]

constexpr uint QH::qHash ( CacheAction  action)
inlineconstexpr

qHash calc hash of the CacheAction enum.

Parameters
actioninput data
Returns
hash value of the action.

Definition at line 278 of file isqldb.h.

◆ qHash() [2/4]

qint64 QH::qHash ( const DbAddress address)

qHash This functions calls int 32 hash of address.

Parameters
addressThis is input address.
Returns
unsigned int 32 hash value.

Definition at line 16 of file dbaddress.cpp.

Here is the call graph for this function:

◆ qHash() [3/4]

uint QH::qHash ( const HostAddress address)

Definition at line 104 of file hostaddress.cpp.

Here is the call graph for this function:

◆ qHash() [4/4]

uint QH::qHash ( NodeCoonectionStatus  status)

qHash - Simple hash function of NodeCoonectionStatus

Parameters
status- Input data.
Returns
crc32 hash code

Definition at line 270 of file abstractnodeinfo.cpp.

Here is the caller graph for this function: