use hash insteat set
All checks were successful
buildbot/WindowsCMakeBuilder Build finished.

This commit is contained in:
Andrei Yankovich 2024-01-14 13:46:28 +01:00
parent e47bc4099e
commit d05de3b235
10 changed files with 36 additions and 35 deletions

View File

@ -29,7 +29,7 @@ public:
* For each command will invoke the IService::handleReceive method.
* @param data This is array of the incomming requests (commands)
*/
virtual void handleReceiveData(const QSet<Feature>& data) = 0;
virtual void handleReceiveData(const QHash<QString, Feature>& data) = 0;
/**
* @brief handleReceive This method invoked when service receive a request from terminal.
@ -37,6 +37,8 @@ public:
* @param data This is input data.
* @return This method should be return true if the @a data command is supported and processed successful.
* IF you return false then a negative message will be sent to a terminal app.
* @see ServiceBase::handleReceiveData
*/
virtual bool handleReceive(const Feature &data) = 0;

View File

@ -65,7 +65,7 @@ bool Controller::send() {
return d_ptr->pause();
}
QSet<Feature> sendData = {};
QHash<QString, Feature> sendData = {};
auto userParams = QuasarAppUtils::Params::getUserParamsMap();
for (auto val = userParams.begin(); val != userParams.end(); ++val) {
@ -75,7 +75,7 @@ bool Controller::send() {
continue;
}
sendData.insert(Feature{val.key(), val.value()});
sendData.insert(val.key(), Feature{val.key(), val.value()});
}
if (!d_ptr->sendCmd(sendData)) {

View File

@ -25,7 +25,6 @@ QString Feature::cmd() const {
void Feature::setCmd(const QString &cmd) {
_cmd = cmd;
_id = qHash(_cmd);
}
QString Feature::arg() const {
@ -59,10 +58,6 @@ QString Feature::toString() const {
return _cmd;
}
unsigned int Feature::id() const {
return _id;
}
QDataStream &operator<<(QDataStream &stream, const Feature &obj) {
stream << obj._cmd << obj._arg;
@ -78,12 +73,11 @@ QDataStream &operator>>(QDataStream &stream, Feature &obj) {
}
bool operator==(const Feature &left, const Feature &right) {
return left.id() == right.id();
return left.cmd() == right.cmd();
}
uint qHash(const Feature &feature) {
return feature.id();
return qHash(feature.cmd());
}
}

View File

@ -10,7 +10,7 @@
#include <QString>
#include <QVariant>
#include <QList>
#include <QHash>
#include <Patronum_global.h>
namespace Patronum {
@ -43,6 +43,11 @@ public:
* @return Argument value.
*/
QString arg() const;
/**
* @brief setArg This method sets arg value for this object.
* @param arg This is a new value.
*/
void setArg(const QString &arg);
PATRONUM_LIBRARYSHARED_EXPORT friend QDataStream& operator<<(QDataStream& stream, const Feature& obj);
@ -80,15 +85,8 @@ public:
*/
QString toString() const;
/**
* @brief id This method retun id of the feature. The id is qHash from command string.
* @return id of the feature.
*/
unsigned int id() const;
private:
unsigned int _id;
QString _cmd;
QString _description;
QString _example;

View File

@ -47,7 +47,7 @@ ServiceBase::~ServiceBase() {
}
}
void ServiceBase::handleReceiveData(const QSet<Feature> &data) {
void ServiceBase::handleReceiveData(const QHash<QString, Feature> &data) {
auto list = supportedFeatures();
QString commandList;

View File

@ -46,8 +46,10 @@ protected:
* @brief handleReceiveData - This method invoice when service receive new command from terminal of controller of this service.
* @param data - Is list of commands from controller.
* Default implementation send message about error, and invoke the.
* @note If you override this method the ServiceBase::handleReceive method wil not invoked wuthou base implementation of thism method.
* @see ServiceBase::handleReceive
*/
void handleReceiveData(const QSet<Feature> &data) override final;
void handleReceiveData(const QHash<QString, Feature> &data) override;
/**
* @brief supportedFeatures

View File

@ -48,7 +48,7 @@ bool ControllerPrivate::sendFeaturesRequest() {
return _socket->send(_parser->createPackage(Command::FeaturesRequest));
}
bool ControllerPrivate::sendCmd(const QSet<Feature> &result) {
bool ControllerPrivate::sendCmd(const QHash<QString, Feature> &result) {
if (!_socket->isValid()) {
QuasarAppUtils::Params::log("scoket is closed!",
QuasarAppUtils::Debug);
@ -64,16 +64,20 @@ bool ControllerPrivate::sendCmd(const QSet<Feature> &result) {
return false;
}
bool ControllerPrivate::sendCmd(const QString &cmd) {
return sendCmd({{cmd, Feature(cmd)}});
}
bool ControllerPrivate::stop() {
return sendCmd({Feature("stop")});
return sendCmd("stop");
}
bool ControllerPrivate::pause() {
return sendCmd({Feature("pause")});
return sendCmd("pause");
}
bool ControllerPrivate::resume() {
return sendCmd({Feature("resume")});
return sendCmd("resume");
}
QList<Feature> ControllerPrivate::features() const {

View File

@ -22,7 +22,8 @@ public:
ControllerPrivate(IController* controller = nullptr, QObject *parent = nullptr);
~ControllerPrivate();
bool sendFeaturesRequest();
bool sendCmd(const QSet<Feature> &result);
bool sendCmd(const QHash<QString, Feature> &result);
bool sendCmd(const QString &cmd);
bool stop();
bool pause();

View File

@ -156,7 +156,7 @@ bool ServicePrivate::startDeamon() {
return true;
}
bool ServicePrivate::handleStandartCmd(QSet<Feature> *cmds) {
bool ServicePrivate::handleStandartCmd(QHash<QString, Feature> *cmds) {
if (!cmds)
return false;
@ -164,17 +164,17 @@ bool ServicePrivate::handleStandartCmd(QSet<Feature> *cmds) {
if (!_service)
return false;
if (cmds->contains(Feature{"stop"})) {
if (cmds->contains("stop")) {
_service->onStop();
cmds->remove(Feature{"stop"});
cmds->remove("stop");
} else if (cmds->contains(Feature{"pause"})) {
} else if (cmds->contains("pause")) {
_service->onPause();
cmds->remove(Feature{"pause"});
cmds->remove("pause");
} else if (cmds->contains(Feature{"resume"})) {
} else if (cmds->contains("resume")) {
_service->onResume();
cmds->remove(Feature{"resume"});
cmds->remove("resume");
}
@ -239,7 +239,7 @@ void ServicePrivate::handleReceve(QByteArray data) {
QDataStream stream(pkg.data());
QSet<Feature> feature;
QHash<QString, Feature> feature;
stream >> feature;
handleStandartCmd(&feature);

View File

@ -88,7 +88,7 @@ private:
* @param cmds
* @return
*/
bool handleStandartCmd(QSet<Feature> *cmds);
bool handleStandartCmd(QHash<QString, Feature> *cmds);
/**
* @brief getServiceLauncher This method return path to launcher file.