Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
QH::iParser Class Referenceabstract

The iParser class This class provide functions for parsing income packages. For yousing just override the iParser::parsePackage method. More...

#include <iparser.h>

Inheritance diagram for QH::iParser:
Inheritance graph
Collaboration diagram for QH::iParser:
Collaboration graph

Public Member Functions

 iParser (AbstractNode *parentNode)
 
virtual ~iParser ()=default
 
template<class T >
void registerPackageType ()
 registerPackageType This method register package type T. This is need to prepare pacakge for parsing in the parsePackage method.
 
virtual ParserResult parsePackage (const QSharedPointer< PKG::AbstractData > &pkg, const Header &pkgHeader, AbstractNodeInfo *sender)=0
 parsePackage This is main method of all childs classes of an AbstractNode class. This method work on own thread. If you ovveride this method you need to create this than an example:
 
virtual int version () const =0
 version This method return version of parser object
 
template<class PackageClass , class HandlerType , class HandlerMethod >
ParserResult commandHandler (HandlerType handlerObject, HandlerMethod method, const QSharedPointer< QH::PKG::AbstractData > &pkg, QH::AbstractNodeInfo *sender, const QH::Header &pkgHeader)
 commandHandler This method it is simple wrapper for the handle pacakges in the AbstractNode::parsePackage method. Exmaple of use :
 
const PacksMapregisteredTypes () const
 registeredTypes This method return list of registered command.
 
QSharedPointer< PKG::AbstractDatagenPackage (unsigned short cmd) const
 genPackage This is factory method that generate data pacakge objects by command. All object should be registered before using this method.
 
bool checkCommand (unsigned short cmd) const
 checkCommand This method check command are if registered type or not.
 
virtual QString parserId () const =0
 parserId This is id of the parsers. All parser will be synced betwin nodes by ids.
 
virtual void initSupportedCommands ()
 initSupportedCommands This method will be invoked before add a parser into parser's storage. Use this method to register your command for this parser object. By default, this method does nothing, You still can register your command in the class constructor. But if you use inheritance between your APIs versions to you must use this method, because your constructors both all your commands, this broken API selector of your node.
 
QString toString () const override
 
const PackagesVersionDatamultiVersionPackages () const
 multiVersionPackages return list of the supported multiversions packages.
 

Static Public Member Functions

static QString pareseResultToString (const ParserResult &parseResult)
 pareseResultToString This method convert ParserResult value to string.
 

Protected Member Functions

AbstractNodenode () const
 
virtual unsigned int sendData (const PKG::AbstractData *resp, const HostAddress &address, const Header *req=nullptr) const
 sendData This method send data object another to node
 
virtual unsigned int sendData (const PKG::AbstractData *resp, const AbstractNodeInfo *node, const Header *req=nullptr) const
 sendData This method send data object another to node
 

Friends

class BigDataParserOld
 
class AbstractNodeParserOld
 
class AbstractNode
 

Detailed Description

The iParser class This class provide functions for parsing income packages. For yousing just override the iParser::parsePackage method.

See also
AbstractNode::parsePackage
AbstractNode

Definition at line 50 of file iparser.h.

Constructor & Destructor Documentation

◆ iParser()

QH::iParser::iParser ( AbstractNode parentNode)

Definition at line 17 of file iparser.cpp.

Here is the call graph for this function:

◆ ~iParser()

virtual QH::iParser::~iParser ( )
virtualdefault

Member Function Documentation

◆ checkCommand()

bool QH::iParser::checkCommand ( unsigned short  cmd) const

checkCommand This method check command are if registered type or not.

cmd This is command of a verifiable package.

Returns
True if the package is registered in a node.

Definition at line 42 of file iparser.cpp.

◆ commandHandler()

ParserResult QH::iParser::commandHandler ( HandlerType  handlerObject,
HandlerMethod  method,
const QSharedPointer< QH::PKG::AbstractData > &  pkg,
QH::AbstractNodeInfo sender,
const QH::Header pkgHeader 
)
inline

commandHandler This method it is simple wrapper for the handle pacakges in the AbstractNode::parsePackage method. Exmaple of use :

auto result = commandHandler<MyPackage>(this, &MyClass::processMyPackage, pkg, sender, pkgHeader);
return result;
}
...
void registerPackageType()
registerPackageType This method register package type T. This is need to prepare pacakge for parsing ...
Definition iparser.h:62
@ NotProcessed
the parser does not know what to do with the package or has not finished processing it.
Template Parameters
PackageClassThis is class name that you want handle. All classes mist be inhert of the QH::PKG::AbstractData class.
HandlerTypeThis is type of the handler object that will invoke HandlerMethod method.
HandlerMethodThis is name of the handler method. The handler method should be support next signature: bool Method(const QSharedPointer<QH::PKG::PackageClass> &, const QH::Header &pkgHeader, const QH::AbstractNodeInfo *sender).
Parameters
handlerObjectThis is pointer to handler object.
methodThis is handler method.
pkgThis is package data from the AbstractNode::parsePackage argumetns
pkgHeaderThis is header of an incomming package.
senderThis is socket object of a sender that send this package.
Returns
item of ParserResult. For more information see The ParserResult enum.
See also
iParser::parsePackage
ParserResult

Definition at line 167 of file iparser.h.

◆ genPackage()

QSharedPointer< PKG::AbstractData > QH::iParser::genPackage ( unsigned short  cmd) const

genPackage This is factory method that generate data pacakge objects by command. All object should be registered before using this method.

Parameters
cmdThis is command of pacakge see Header::command.
Returns
shared pointer to new data object.
See also
AbstractNode::registerPackageType
Header::command

Definition at line 38 of file iparser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initSupportedCommands()

void QH::iParser::initSupportedCommands ( )
virtual

initSupportedCommands This method will be invoked before add a parser into parser's storage. Use this method to register your command for this parser object. By default, this method does nothing, You still can register your command in the class constructor. But if you use inheritance between your APIs versions to you must use this method, because your constructors both all your commands, this broken API selector of your node.

See also
registerPackageType

Definition at line 66 of file iparser.cpp.

◆ multiVersionPackages()

const PackagesVersionData & QH::iParser::multiVersionPackages ( ) const

multiVersionPackages return list of the supported multiversions packages.

Returns
list of the supported multiversions packages.

Definition at line 62 of file iparser.cpp.

Here is the caller graph for this function:

◆ node()

AbstractNode * QH::iParser::node ( ) const
protected

Definition at line 46 of file iparser.cpp.

Here is the caller graph for this function:

◆ pareseResultToString()

QString QH::iParser::pareseResultToString ( const ParserResult parseResult)
static

pareseResultToString This method convert ParserResult value to string.

Returns
The String value of pareseresult.

Definition at line 22 of file iparser.cpp.

Here is the call graph for this function:

◆ parsePackage()

virtual ParserResult QH::iParser::parsePackage ( const QSharedPointer< PKG::AbstractData > &  pkg,
const Header pkgHeader,
AbstractNodeInfo sender 
)
pure virtual

parsePackage This is main method of all childs classes of an AbstractNode class. This method work on own thread. If you ovveride this method you need to create this than an example:

ParserResult DataBaseNode::parsePackage(PKG::AbstractData *pkg,
const Header& pkgHeader,
auto parentResult = AbstractNode::parsePackage(pkg, sender);
return parentResult;
}
// you can use parsing without the commandHandler method
if (MyCommand::command() == pkg->cmd()) {
...
}
...
}
// Or with the commandHandler method
auto result = commandHandler<MyPackage>(this, &MyClass::processMyPackage, pkg, sender, pkgHeader);
return result;
}
}
The AbstractNodeInfo class contains information about client or server connection and tcp socket of n...
The AbstractData class is provide base functions for transport data by network For create you own pac...
ParserResult
The ParserResult enum. Error - parser detect a errorob package. NotProcessed - the parser does not kn...
Definition iparser.h:35
@ Error
parser detect a errorob package.
@ Processed
the parser finished processing correctly.
The Header struct 32 bytes.
Definition header.h:19
Parameters
pkgThis is package with incomming data.
senderThis is sender this pacakge.
pkgHeaderThis is header of the incoming packet is used to create a response.
Returns
item of ParserResult. For more information see The ParserResult enum.
See also
AbstractNode::commandHandler
AbstractNode::sendData
AbstractNode::badRequest

Implemented in QH::AbstractNodeParser, QH::BigDataParser, and QH::APIVersionParser.

Here is the caller graph for this function:

◆ parserId()

virtual QString QH::iParser::parserId ( ) const
pure virtual

parserId This is id of the parsers. All parser will be synced betwin nodes by ids.

Returns
parser id.

Implemented in QH::AbstractNodeParser, QH::BigDataParser, and QH::APIVersionParser.

Here is the caller graph for this function:

◆ registeredTypes()

const PacksMap & QH::iParser::registeredTypes ( ) const

registeredTypes This method return list of registered command.

Returns
list of registered command.
See also
iParser::registerPackageType

Definition at line 34 of file iparser.cpp.

◆ registerPackageType()

template<class T >
void QH::iParser::registerPackageType ( )
inline

registerPackageType This method register package type T. This is need to prepare pacakge for parsing in the parsePackage method.

See also
initSupportedCommands

Definition at line 62 of file iparser.h.

Here is the caller graph for this function:

◆ sendData() [1/2]

unsigned int QH::iParser::sendData ( const PKG::AbstractData resp,
const AbstractNodeInfo node,
const Header req = nullptr 
) const
protectedvirtual

sendData This method send data object another to node

Parameters
respThis is pointer to sendet object.
addressThis is target addres for sending.
reqThis is header of request.
Returns
hash of the sendet package. If function is failed then return 0.
Note
This method is a just wraper of the AbstractNode::sendData method.

Definition at line 56 of file iparser.cpp.

Here is the call graph for this function:

◆ sendData() [2/2]

unsigned int QH::iParser::sendData ( const PKG::AbstractData resp,
const HostAddress address,
const Header req = nullptr 
) const
protectedvirtual

sendData This method send data object another to node

Parameters
respThis is pointer to sendet object.
addressThis is target addres for sending.
reqThis is header of request.
Returns
hash of the sendet package. If function is failed then return 0.
Note
This method is a just wraper of the AbstractNode::sendData method.

Definition at line 50 of file iparser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

QString QH::iParser::toString ( ) const
override

Definition at line 68 of file iparser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ version()

virtual int QH::iParser::version ( ) const
pure virtual

version This method return version of parser object

Returns
version of parsed object.

Implemented in QH::AbstractNodeParser, QH::BigDataParser, and QH::APIVersionParser.

Friends And Related Symbol Documentation

◆ AbstractNode

Definition at line 266 of file iparser.h.

◆ AbstractNodeParserOld

friend class AbstractNodeParserOld
friend

Definition at line 265 of file iparser.h.

◆ BigDataParserOld

friend class BigDataParserOld
friend

Definition at line 264 of file iparser.h.


The documentation for this class was generated from the following files: