mirror of
https://github.com/QuasarApp/Heart.git
synced 2025-04-28 02:34:41 +00:00
simple fixes
This commit is contained in:
parent
f80eef1731
commit
f0bfabbe17
@ -140,6 +140,16 @@ bool AbstractNode::run(const QString &addres, unsigned short port) {
|
||||
return true;
|
||||
}
|
||||
|
||||
QSharedPointer<iParser> AbstractNode::selectParser(unsigned short cmd,
|
||||
AbstractNodeInfo *sender) {
|
||||
return _apiVersionParser->selectParser(cmd, sender);
|
||||
}
|
||||
|
||||
QSharedPointer<iParser> AbstractNode::selectParser(const QString &type,
|
||||
AbstractNodeInfo *sender) {
|
||||
return _apiVersionParser->selectParser(type, sender);
|
||||
}
|
||||
|
||||
void AbstractNode::stop() {
|
||||
close();
|
||||
|
||||
|
@ -153,6 +153,23 @@ public:
|
||||
*/
|
||||
virtual bool run(const QString& addres, unsigned short port);
|
||||
|
||||
/**
|
||||
* @brief selectParser This method select parser by command and sender.
|
||||
* @param cmd this is command that need to parse.
|
||||
* @param sender this is node that sent this command.
|
||||
* @return parser for the @a cmd command
|
||||
*/
|
||||
QSharedPointer<QH::iParser> selectParser(unsigned short cmd,
|
||||
AbstractNodeInfo *sender);
|
||||
|
||||
/**
|
||||
* @brief selectParser This method select parser by command and sender.
|
||||
* @param cmd this is command that need to parse.
|
||||
* @param sender this is node that sent this command.
|
||||
* @return parser for the @a cmd command
|
||||
*/
|
||||
QSharedPointer<QH::iParser> selectParser(const QString& type,
|
||||
AbstractNodeInfo *sender);
|
||||
|
||||
/**
|
||||
* @brief stop - Stopped this node and close all network connections.
|
||||
@ -750,7 +767,9 @@ private:
|
||||
TaskScheduler *_tasksheduller = nullptr;
|
||||
APIVersionParser *_apiVersionParser = nullptr;
|
||||
|
||||
QHash<NodeCoonectionStatus, QHash<HostAddress, std::function<void (QH::AbstractNodeInfo *)>>> _connectActions;
|
||||
QHash<NodeCoonectionStatus,
|
||||
QHash<HostAddress,
|
||||
std::function<void (QH::AbstractNodeInfo *)>>> _connectActions;
|
||||
|
||||
QSet<QFutureWatcher <bool>*> _workers;
|
||||
|
||||
|
@ -229,9 +229,18 @@ QSharedPointer<QH::iParser> AbstractNodeInfo::getParser(unsigned short cmd) {
|
||||
return _parsersMap.value(cmd, nullptr);
|
||||
}
|
||||
|
||||
QSharedPointer<iParser> AbstractNodeInfo::getParser(const QString &type) {
|
||||
return _parsersKeysMap.value(type, nullptr);
|
||||
}
|
||||
|
||||
void QH::AbstractNodeInfo::addParser(unsigned short cmd,
|
||||
QSharedPointer<QH::iParser> parser) {
|
||||
_parsersMap[cmd] = parser;
|
||||
_parsersKeysMap[parser->parserId()] = parser;
|
||||
}
|
||||
|
||||
void AbstractNodeInfo::addParser(QSharedPointer<iParser> parser) {
|
||||
_parsersKeysMap[parser->parserId()] = parser;
|
||||
}
|
||||
|
||||
uint qHash(NodeCoonectionStatus status) {
|
||||
|
@ -236,14 +236,27 @@ public:
|
||||
*/
|
||||
QSharedPointer<QH::iParser> getParser(unsigned short cmd);
|
||||
|
||||
/**
|
||||
* @brief getParser This method return parser of choosed command.
|
||||
* @param type This is type of api parser.
|
||||
* @return parser by type.
|
||||
*/
|
||||
QSharedPointer<QH::iParser> getParser(const QString& type);
|
||||
|
||||
/**
|
||||
* @brief addParser This method add to cache new parser for command .
|
||||
* @param cmd
|
||||
* @param parser
|
||||
* @param cmd This is any command that support this parser.
|
||||
* @param parser This is added parser.
|
||||
* @note All parsers will be removed after reconnect of this node.
|
||||
*/
|
||||
void addParser(unsigned short cmd, QSharedPointer<QH::iParser> parser);
|
||||
|
||||
/**
|
||||
* @brief addParser This method add to cache new parser for command .
|
||||
* @param parser This is added parser.
|
||||
* @note All parsers will be removed after reconnect of this node.
|
||||
*/
|
||||
void addParser(QSharedPointer<QH::iParser> parser);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
@ -318,6 +331,7 @@ private:
|
||||
bool _isLocal = false;
|
||||
|
||||
QHash<unsigned short, QSharedPointer<iParser>> _parsersMap;
|
||||
QHash<QString, QSharedPointer<iParser>> _parsersKeysMap;
|
||||
|
||||
VersionData _version;
|
||||
bool _fVersionReceived = false;
|
||||
|
@ -192,6 +192,16 @@ QSharedPointer<iParser> APIVersionParser::selectParser(unsigned short cmd,
|
||||
return parser;
|
||||
}
|
||||
|
||||
QSharedPointer<iParser> APIVersionParser::selectParser(const QString &parserKey,
|
||||
AbstractNodeInfo *sender) {
|
||||
auto parser = sender->getParser(parserKey);
|
||||
if (!parser) {
|
||||
parser = selectParserImpl(parserKey, sender);
|
||||
}
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
QSharedPointer<iParser> APIVersionParser::selectParserImpl(unsigned short cmd,
|
||||
AbstractNodeInfo *sender) {
|
||||
auto version = sender->version();
|
||||
@ -206,6 +216,13 @@ QSharedPointer<iParser> APIVersionParser::selectParserImpl(unsigned short cmd,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QSharedPointer<iParser> APIVersionParser::selectParserImpl(const QString &key, AbstractNodeInfo *sender) {
|
||||
auto version = sender->version();
|
||||
auto parser = selectParser(version).value(key);
|
||||
sender->addParser(parser);
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
unsigned short APIVersionParser::maximumApiVersion(const QString &apiKey) const {
|
||||
|
||||
|
@ -84,6 +84,15 @@ public:
|
||||
QSharedPointer<QH::iParser> selectParser(unsigned short cmd,
|
||||
AbstractNodeInfo *sender);
|
||||
|
||||
/**
|
||||
* @brief selectParser This method select parser by command and sender.
|
||||
* @param parserKey this is key of the parser type..
|
||||
* @param sender this is node that sent this command.
|
||||
* @return parser for the @a cmd command
|
||||
*/
|
||||
QSharedPointer<QH::iParser> selectParser(const QString& parserKey,
|
||||
AbstractNodeInfo *sender);
|
||||
|
||||
/**
|
||||
* @brief maximumApiVersion This method return maximum supported api version of this node.
|
||||
* @param apiKey This is api key.
|
||||
@ -119,6 +128,9 @@ private:
|
||||
QSharedPointer<QH::iParser>
|
||||
selectParserImpl(unsigned short cmd, AbstractNodeInfo *sender);
|
||||
|
||||
QSharedPointer<QH::iParser>
|
||||
selectParserImpl(const QString& key, AbstractNodeInfo *sender);
|
||||
|
||||
bool processAppVersion(const QSharedPointer<PKG::APIVersion> &message,
|
||||
AbstractNodeInfo *sender,
|
||||
const QH::Header &);
|
||||
|
Loading…
x
Reference in New Issue
Block a user