17#include <qaglobalutils.h>
49 QuasarAppUtils::Params::log(
QString(
"Can't found requeried parser for versions"),
50 QuasarAppUtils::Warning);
67 return "APIVersionParser";
74 for (
const auto&
parser: _apiParsers) {
76 message +=
"ver: " + QString::number(
it.key()) +
" " +
it.value()->toString();
83QSharedPointer<PKG::AbstractData>
90 return QSharedPointer<PKG::APIVersion>::create();
92 return QSharedPointer<PKG::VersionIsReceived>::create();
104 QuasarAppUtils::Params::log(
QString(
"Internal Error with selection parasers."),
105 QuasarAppUtils::Error);
116QSharedPointer<iParser>
122bool QH::APIVersionParser::commandsValidation(
const QSharedPointer<iParser> &parserObject) {
124 auto types = QSet<unsigned short>{parserObject->registeredTypes().keyBegin(),
125 parserObject->registeredTypes().keyEnd()};
126 int typesSize = types.size();
128 for (
const auto &parsersMap : std::as_const(_apiParsers)) {
129 for (
const auto &parser: parsersMap) {
130 if (parser->parserId() == parserObject->parserId()) {
134 auto localTypes = QSet<unsigned short>{parser->registeredTypes().keyBegin(),
135 parser->registeredTypes().keyEnd()};
138 if (types.size() != typesSize) {
139 auto err = QString(
"Parser object can't be added. "
140 "Because commands of the %0_v%1 parser "
141 "already registered in the %2_v%3 parser. "
142 "Use the iParser::initSupportedCommands method to "
144 "See our documentation for get more inforamtion. "
145 "https://quasarapp.ddns.net:3031/docs/QuasarApp/Heart/latest/classQH_1_1iParser.html").
146 arg(parserObject->parserId()).
147 arg(parserObject->version()).
148 arg(parser->parserId()).
149 arg(parser->version());
151 QuasarAppUtils::Params::log(err, QuasarAppUtils::Error);
169 "Because its commands already registered "
170 "in the another parsers.");
177QHash<QString, QSharedPointer<iParser>>
195 return _apiParsers.size();
222 unsigned short version)
const {
234QSharedPointer<iParser> APIVersionParser::selectParserImpl(
unsigned short cmd,
239 if (
parser->checkCommand(cmd)) {
248QSharedPointer<iParser> APIVersionParser::selectParserImpl(
const QString &key,
249 AbstractNodeInfo *sender)
const{
280 for (
auto it = _apiParsers.begin();
it != _apiParsers.end(); ++
it) {
284 const auto packages =
api.value()->multiVersionPackages();
307bool APIVersionParser::processAppVersion(
const QSharedPointer<PKG::APIVersion> &message,
313 sender->setMultiVersionPackages(
message->packagesVersions());
321 QuasarAppUtils::Params::log(
QString(
"Can't found %0 parser for versions: %1-%2").
325 QuasarAppUtils::Error);
337 sender->setFVersionReceived(
true);
339 PKG::VersionIsReceived
result;
343bool APIVersionParser::versionDeliveredSuccessful(
const QSharedPointer<PKG::VersionIsReceived> &,
344 AbstractNodeInfo *sender,
346 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.