Heart
1.4.918.d927d9c
Heart is base back end library for your c++ Qt projects.
Toggle main menu visibility
Loading...
Searching...
No Matches
abstractnodeparser.cpp
Go to the documentation of this file.
1
//#
2
//# Copyright (C) 2022-2025 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
#include "
abstractnodeparser.h
"
9
#include "
abstractnode.h
"
10
#include "qaglobalutils.h"
11
12
#include <
badrequest.h
>
13
#include <
bigdatarequest.h
>
14
#include <
closeconnection.h
>
15
#include <
ping.h
>
16
17
namespace
QH
{
18
19
AbstractNodeParser::AbstractNodeParser
(
AbstractNode
* parentNode):
iParser
(parentNode) {
20
debug_assert(parentNode,
"Node object can't be null!"
);
21
22
registerPackageType<PKG::Ping>
();
23
registerPackageType<PKG::BadRequest>
();
24
registerPackageType<PKG::CloseConnection>
();
25
}
26
27
AbstractNodeParser::~AbstractNodeParser
() {
28
}
29
30
ParserResult
AbstractNodeParser::parsePackage
(
const
QSharedPointer<PKG::AbstractData> &pkg,
31
const
Header
&pkgHeader,
32
AbstractNodeInfo
*sender) {
33
auto
nodePtr =
node
();
34
if
(!nodePtr) {
35
return
ParserResult::NotProcessed
;
36
}
37
38
if
(!(sender)) {
39
qCritical() <<
"sender socket is not valid!"
;
40
return
ParserResult::Error
;
41
}
42
43
if
(!pkg->isValid()) {
44
qCritical() <<
"incomming package is not valid!"
;
45
46
nodePtr->changeTrust(sender->
networkAddress
(),
CRITICAL_ERROOR
);
47
return
ParserResult::Error
;
48
}
49
50
if
(
PKG::Ping::command
() == pkg->cmd()) {
51
auto
cmd = pkg.staticCast<
PKG::Ping
>();
52
if
(!cmd->ansver()) {
53
cmd->setAnsver(
true
);
54
nodePtr->sendData(cmd.data(), sender, &pkgHeader);
55
}
56
57
emit
sigPingReceived
(cmd);
58
59
return
ParserResult::Processed
;
60
}
else
if
(
PKG::BadRequest::command
() == pkg->cmd()) {
61
auto
cmd =
static_cast<
PKG::BadRequest
*
>
(pkg.data());
62
63
emit nodePtr->requestError(cmd->errCode(), cmd->err());
64
65
return
ParserResult::Processed
;
66
67
}
else
if
(
PKG::CloseConnection::command
() == pkg->cmd()) {
68
if
(sender->
isLocal
()) {
69
nodePtr->removeNode(sender->
networkAddress
());
70
}
71
return
ParserResult::Processed
;
72
}
73
74
return
ParserResult::NotProcessed
;
75
}
76
77
int
AbstractNodeParser::version
()
const
{
78
return
1;
79
}
80
81
QString
AbstractNodeParser::parserId
()
const
{
82
return
"HeartLibAbstractAPI"
;
83
}
84
}
abstractnode.h
CRITICAL_ERROOR
#define CRITICAL_ERROOR
Definition
abstractnode.h:80
abstractnodeparser.h
badrequest.h
bigdatarequest.h
QH::AbstractNodeInfo
The AbstractNodeInfo class contains information about client or server connection and tcp socket of n...
Definition
abstractnodeinfo.h:68
QH::AbstractNodeInfo::isLocal
bool isLocal() const
isLocal return true if connection opened on this node.
Definition
abstractnodeinfo.cpp:171
QH::AbstractNodeInfo::networkAddress
HostAddress networkAddress() const
networkAddress This method return network address of current node or client.
Definition
abstractnodeinfo.cpp:175
QH::AbstractNodeParser::parserId
QString parserId() const override
parserId This is id of the parsers. All parser will be synced betwin nodes by ids.
Definition
abstractnodeparser.cpp:81
QH::AbstractNodeParser::~AbstractNodeParser
~AbstractNodeParser() override
Definition
abstractnodeparser.cpp:27
QH::AbstractNodeParser::AbstractNodeParser
AbstractNodeParser(AbstractNode *parentNode)
Definition
abstractnodeparser.cpp:19
QH::AbstractNodeParser::parsePackage
ParserResult parsePackage(const QSharedPointer< PKG::AbstractData > &pkg, const Header &pkgHeader, AbstractNodeInfo *sender) override
parsePackage This is main method of all childs classes of an AbstractNode class. This method work on ...
Definition
abstractnodeparser.cpp:30
QH::AbstractNodeParser::sigPingReceived
void sigPingReceived(const QSharedPointer< QH::PKG::Ping > &ping)
sigPingReceived This method emited
QH::AbstractNodeParser::version
int version() const override
version This method return version of parser object
Definition
abstractnodeparser.cpp:77
QH::PKG::AbstractData::command
static unsigned int command()
command This static method that return glaball code of this object.
Definition
abstractdata.h:149
QH::PKG::BadRequest
The BadRequest class send response about error to client.
Definition
badrequest.h:35
QH::PKG::Ping
The Ping class - test class for translate data on network.
Definition
ping.h:22
QH::iParser::registerPackageType
void registerPackageType()
registerPackageType This method register package type T. This is need to prepare pacakge for parsing ...
Definition
iparser.h:62
QH::iParser::node
AbstractNode * node() const
Definition
iparser.cpp:46
QH::iParser::iParser
iParser(AbstractNode *parentNode)
Definition
iparser.cpp:17
QH::iParser::AbstractNode
friend class AbstractNode
Definition
iparser.h:266
closeconnection.h
QH
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition
heart.cpp:13
QH::ParserResult
ParserResult
The ParserResult enum. Error - parser detect a errorob package. NotProcessed - the parser does not kn...
Definition
iparser.h:35
QH::ParserResult::NotProcessed
@ NotProcessed
the parser does not know what to do with the package or has not finished processing it.
Definition
iparser.h:39
QH::ParserResult::Error
@ Error
parser detect a errorob package.
Definition
iparser.h:37
QH::ParserResult::Processed
@ Processed
the parser finished processing correctly.
Definition
iparser.h:41
ping.h
QH::Header
The Header struct 32 bytes.
Definition
header.h:19
src
private
abstractnodeparser.cpp
Generated by
1.18.0