Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
abstractnodeparser.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
9#include "params.h"
10#include "abstractnode.h"
11#include "qaglobalutils.h"
12
13#include <badrequest.h>
14#include <bigdatarequest.h>
15#include <closeconnection.h>
16#include <ping.h>
17
18namespace QH {
19
21 debug_assert(parentNode, "Node object can't be null!");
22
26}
27
30
31ParserResult AbstractNodeParser::parsePackage(const QSharedPointer<PKG::AbstractData> &pkg,
32 const Header &pkgHeader,
33 AbstractNodeInfo *sender) {
34 auto nodePtr = node();
35 if (!nodePtr) {
37 }
38
39 if (!(sender)) {
40 QuasarAppUtils::Params::log("sender socket is not valid!",
41 QuasarAppUtils::Error);
43 }
44
45 if (!pkg->isValid()) {
46 QuasarAppUtils::Params::log("incomming package is not valid!",
47 QuasarAppUtils::Error);
48 nodePtr->changeTrust(sender->networkAddress(), CRITICAL_ERROOR);
50 }
51
52 if (PKG::Ping::command() == pkg->cmd()) {
53 auto cmd = pkg.staticCast<PKG::Ping>();
54 if (!cmd->ansver()) {
55 cmd->setAnsver(true);
56 nodePtr->sendData(cmd.data(), sender, &pkgHeader);
57 }
58
60
62 } else if (PKG::BadRequest::command() == pkg->cmd()) {
63 auto cmd = static_cast<PKG::BadRequest *>(pkg.data());
64
65 emit nodePtr->requestError(cmd->errCode(), cmd->err());
66
68
69 } else if (PKG::CloseConnection::command() == pkg->cmd()) {
70 if (sender->isLocal()) {
71 nodePtr->removeNode(sender->networkAddress());
72 }
74 }
75
77}
78
80 return 1;
81}
82
84 return "HeartLibAbstractAPI";
85}
86}
#define CRITICAL_ERROOR
The AbstractNodeInfo class contains information about client or server connection and tcp socket of n...
QString parserId() const override
parserId This is id of the parsers. All parser will be synced betwin nodes by ids.
AbstractNodeParser(AbstractNode *parentNode)
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 ...
void sigPingReceived(const QSharedPointer< QH::PKG::Ping > &ping)
sigPingReceived This method emited
int version() const override
version This method return version of parser object
The AbstractNode class - Abstract implementation of node. this implementation have a methods for send...
static unsigned int command()
command This static method that return glaball code of this object.
The BadRequest class send response about error to client.
Definition badrequest.h:35
The Ping class - test class for translate data on network.
Definition ping.h:22
void setAnsver(bool ansver)
setAnsver - Set the answer option.
Definition ping.cpp:31
The iParser class This class provide functions for parsing income packages. For yousing just override...
Definition iparser.h:51
void registerPackageType()
registerPackageType This method register package type T. This is need to prepare pacakge for parsing ...
Definition iparser.h:62
AbstractNode * node() const
Definition iparser.cpp:46
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.
@ Error
parser detect a errorob package.
@ Processed
the parser finished processing correctly.
The Header struct 32 bytes.
Definition header.h:19