Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
iparser.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022-2024 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8
9#include "iparser.h"
10
11#include <abstractdata.h>
12#include <qaglobalutils.h>
13#include "abstractnode.h"
14
15namespace QH {
16
18 _node = parentNode;
19 debug_assert(_node, "All parsers shold be initialized with parent node");
20}
21
22QString iParser::pareseResultToString(const ParserResult &parseResult) {
23 switch (parseResult)
24 {
26 return "Processed";
28 return "NotProcessed";
29
30 default: return "Error";
31 }
32}
33
35 return _registeredTypes;
36}
37
38QSharedPointer<PKG::AbstractData> iParser::genPackage(unsigned short cmd) const {
39 return QSharedPointer<PKG::AbstractData>(_registeredTypes.value(cmd, [](){return nullptr;})());
40}
41
42bool iParser::checkCommand(unsigned short cmd) const {
43 return _registeredTypes.contains(cmd);
44}
45
47 return _node;
48}
49
50unsigned int iParser::sendData(const PKG::AbstractData *resp,
51 const HostAddress &address,
52 const Header *req) const{
53 return node()->sendData(resp, address, req);
54}
55
56unsigned int iParser::sendData(const PKG::AbstractData *resp,
57 const AbstractNodeInfo *dist,
58 const Header *req) const {
59 return node()->sendData(resp, dist, req);
60}
61
63 return _multiVersionPackages;
64}
65
67
68QString iParser::toString() const {
69 QString message = parserId() + " supports next commands:\n";
70
71 for (auto it = _registeredTypes.keyBegin(); it != _registeredTypes.keyEnd(); ++it) {
72 message += genPackage(*it)->cmdString() + " - " + QString::number(*it) + "\n";
73 }
74
75 return message;
76}
77
78}
The AbstractNodeInfo class contains information about client or server connection and tcp socket of n...
The AbstractNode class - Abstract implementation of node. this implementation have a methods for send...
virtual unsigned int sendData(const PKG::AbstractData *resp, const HostAddress &address, const Header *req=nullptr)
sendData This method send data object another to node
The Host Address class this is wrapper of QHostAddress. Contains the NetworkAddress and network port.
Definition hostaddress.h:22
The AbstractData class is provide base functions for transport data by network For create you own pac...
QString toString() const override
Definition iparser.cpp:68
virtual QString parserId() const =0
parserId This is id of the parsers. All parser will be synced betwin nodes by ids.
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
Definition iparser.cpp:50
void registerPackageType()
registerPackageType This method register package type T. This is need to prepare pacakge for parsing ...
Definition iparser.h:62
virtual void initSupportedCommands()
initSupportedCommands This method will be invoked before add a parser into parser's storage....
Definition iparser.cpp:66
static QString pareseResultToString(const ParserResult &parseResult)
pareseResultToString This method convert ParserResult value to string.
Definition iparser.cpp:22
bool checkCommand(unsigned short cmd) const
checkCommand This method check command are if registered type or not.
Definition iparser.cpp:42
const PackagesVersionData & multiVersionPackages() const
multiVersionPackages return list of the supported multiversions packages.
Definition iparser.cpp:62
QSharedPointer< PKG::AbstractData > genPackage(unsigned short cmd) const
genPackage This is factory method that generate data pacakge objects by command. All object should be...
Definition iparser.cpp:38
AbstractNode * node() const
Definition iparser.cpp:46
iParser(AbstractNode *parentNode)
Definition iparser.cpp:17
const PacksMap & registeredTypes() const
registeredTypes This method return list of registered command.
Definition iparser.cpp:34
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13
ParserResult
The ParserResult enum. Error - parser detect a errorob package. NotProcessed - the parser does not kn...
Definition iparser.h:35
@ NotProcessed
the parser does not know what to do with the package or has not finished processing it.
@ Processed
the parser finished processing correctly.
QHash< unsigned short, std::function< PKG::AbstractData *()> > PacksMap
PacksMap This is hash map where id is command of package and value is factory function.
Definition iparser.h:26
QHash< unsigned short, DistVersion > PackagesVersionData
PackagesVersionData This is some as VersionData but for int commands.
Definition distversion.h:78
The Header struct 32 bytes.
Definition header.h:19