17#include <qaglobalutils.h>
49 qWarning () <<
"Can't found requeried parser for versions";
66 return "APIVersionParser";
73 for (
const auto&
parser: _apiParsers) {
75 message +=
"ver: " + QString::number(
it.key()) +
" " +
it.value()->toString();
82QSharedPointer<PKG::AbstractData>
89 return QSharedPointer<PKG::APIVersion>::create();
91 return QSharedPointer<PKG::VersionIsReceived>::create();
103 qCritical() <<
"Internal Error with selection parasers.";
114QSharedPointer<iParser>
120bool QH::APIVersionParser::commandsValidation(
const QSharedPointer<iParser> &parserObject) {
122 auto types = QSet<unsigned short>{parserObject->registeredTypes().keyBegin(),
123 parserObject->registeredTypes().keyEnd()};
124 int typesSize = types.size();
126 for (
const auto &parsersMap : std::as_const(_apiParsers)) {
127 for (
const auto &parser: parsersMap) {
128 if (parser->parserId() == parserObject->parserId()) {
132 auto localTypes = QSet<unsigned short>{parser->registeredTypes().keyBegin(),
133 parser->registeredTypes().keyEnd()};
136 if (types.size() != typesSize) {
137 auto err = QString(
"Parser object can't be added. "
138 "Because commands of the %0_v%1 parser "
139 "already registered in the %2_v%3 parser. "
140 "Use the iParser::initSupportedCommands method to "
142 "See our documentation for get more inforamtion. "
143 "https://quasarapp.ddns.net:3031/docs/QuasarApp/Heart/latest/classQH_1_1iParser.html").
144 arg(parserObject->parserId()).
145 arg(parserObject->version()).
146 arg(parser->parserId()).
147 arg(parser->version());
167 "Because its commands already registered "
168 "in the another parsers.");
175QHash<QString, QSharedPointer<iParser>>
193 return _apiParsers.size();
220 unsigned short version)
const {
232QSharedPointer<iParser> APIVersionParser::selectParserImpl(
unsigned short cmd,
237 if (
parser->checkCommand(cmd)) {
246QSharedPointer<iParser> APIVersionParser::selectParserImpl(
const QString &key,
247 AbstractNodeInfo *sender)
const{
278 for (
auto it = _apiParsers.begin();
it != _apiParsers.end(); ++
it) {
282 const auto packages =
api.value()->multiVersionPackages();
305bool APIVersionParser::processAppVersion(
const QSharedPointer<PKG::APIVersion> &message,
311 sender->setMultiVersionPackages(
message->packagesVersions());
331 sender->setFVersionReceived(
true);
333 PKG::VersionIsReceived
result;
337bool APIVersionParser::versionDeliveredSuccessful(
const QSharedPointer<PKG::VersionIsReceived> &,
338 AbstractNodeInfo *sender,
340 sender->setFVersionDelivered(
true);
int version() const override
version This method return version of parser object
QSharedPointer< PKG::AbstractData > searchPackage(unsigned short cmd, AbstractNodeInfo *sender) const
searchPackage This method search package recursive in all registered pararsers. Searching will be in ...
unsigned short minimumApiVersion(const QString &apiKey) const
minimumApiVersion This method return minimum supported api version of this node.
QHash< QString, QSharedPointer< QH::iParser > > selectParser(const VersionData &distVersion) const
selectParser This method select api parser betwin nodes.
unsigned short maximumApiVersion(const QString &apiKey) const
maximumApiVersion This method return maximum supported api version of this node.
const QSharedPointer< QH::iParser > & addApiParser(const QSharedPointer< QH::iParser > &parserObject)
addApiParser This method add new Api parser for this node.
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 ...
APIVersionParser(AbstractNode *node)
void sigNoLongerSupport(const QString &ApiKey, unsigned short version)
sigNoLongerSupport This signal will be emit when node receive incomplite versions.
QSharedPointer< iParser > getSelectedApiParser(const QString &apiKey, QH::AbstractNodeInfo *node) const
getSelectedApiParser This method return apiParser for selected node
unsigned int parsersTypedCount() const
parsersTypedCount This method return count of the parsers types.
QString toString() const override
toString This method show all supported commands and them names.
QString parserId() const override
parserId This is id of the parsers. All parser will be synced betwin nodes by ids.
bool sendSupportedAPI(AbstractNodeInfo *dist) const
sendSupportedAPI This method sents all ainformation about suppported api.
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 DistVersion class This is information of supported versions of the destinations api.
void setMax(unsigned short newMax)
void setMin(unsigned short newMin)
The APIVersion class This is base pacakge class that send information about supported api version on ...
static unsigned short command()
void setApisVersions(const VersionData &newApisVersions)
static unsigned short command()
The iParser class This class provide functions for parsing income packages. For yousing just override...
QString toString() const override
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
void registerPackageType()
registerPackageType This method register package type T. This is need to prepare pacakge for parsing ...
const PackagesVersionData & multiVersionPackages() const
multiVersionPackages return list of the supported multiversions packages.
AbstractNode * node() const
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
ParserResult
The ParserResult enum. Error - parser detect a errorob package. NotProcessed - the parser does not kn...
@ NotProcessed
the parser does not know what to do with the package or has not finished processing it.
QHash< QString, DistVersion > VersionData
VersionData This is array of all available apis and supported its versions.
QHash< unsigned short, DistVersion > PackagesVersionData
PackagesVersionData This is some as VersionData but for int commands.