improve
This commit is contained in:
parent
df5325db4c
commit
3d19695090
|
@ -118,6 +118,7 @@ namespace Inlet {
|
|||
_args_value.execute(_func);
|
||||
}
|
||||
virtual void saveTo(datas::IDataObject& object) {
|
||||
object.setUInt64(u8"Address", (quint64)addr);
|
||||
_args_value.saveTo(0, object);
|
||||
}
|
||||
virtual void loadFrom(datas::IDataObject& object) {
|
||||
|
@ -144,6 +145,7 @@ namespace Inlet {
|
|||
}
|
||||
void run() { }
|
||||
virtual void saveTo(datas::IDataObject& object) {
|
||||
object.setUInt64(u8"Address", (quint64) addr);
|
||||
_args_value.saveTo(0, object);
|
||||
}
|
||||
virtual void loadFrom(datas::IDataObject& object) {
|
||||
|
|
|
@ -69,12 +69,14 @@ namespace datas {
|
|||
virtual double getDouble(const QString& key) const = 0;
|
||||
virtual int32_t getInt32(const QString& key) const = 0;
|
||||
virtual int64_t getInt64(const QString& key) const = 0;
|
||||
virtual uint64_t getUInt64(const QString& key) const = 0;
|
||||
virtual QString getString(const QString& key) const = 0;
|
||||
|
||||
virtual void setBool(const QString& key, bool value) = 0;
|
||||
virtual void setDouble(const QString& key, double value) = 0;
|
||||
virtual void setInt32(const QString& key, int32_t value) = 0;
|
||||
virtual void setInt64(const QString& key, int64_t value) = 0;
|
||||
virtual void setUInt64(const QString& key, uint64_t value) = 0;
|
||||
virtual void setString(const QString& key, const QString& value) = 0;
|
||||
|
||||
virtual QString toText() const = 0;
|
||||
|
|
|
@ -9,7 +9,7 @@ Dispatch* dispatch::Dispatch::unique() {
|
|||
return _unique_inst;
|
||||
}
|
||||
|
||||
void dispatch::Dispatch::loadOutput(std::shared_ptr<IOutput> out_ins) {
|
||||
void dispatch::Dispatch::loadOutput(std::shared_ptr<logs::LogsPort> out_ins) {
|
||||
this->_output_list << out_ins;
|
||||
}
|
||||
|
||||
|
@ -46,16 +46,25 @@ void Dispatch::runWith(IRunbase* unit) {
|
|||
depict::ValidateDocObject obj;
|
||||
|
||||
auto addrs = unit->address();
|
||||
auto alias_name = _cmds_map[addrs].first;
|
||||
if (_cmds_validators.contains(addrs) && !_cmds_validators[addrs]->doValidate(unit)) {
|
||||
unit->saveTo(obj);
|
||||
obj.setString(u8"CmdAlias", alias_name);
|
||||
auto args_content = obj.toText();
|
||||
std::for_each(_output_list.begin(), _output_list.end(), [&](std::shared_ptr<IOutput> ins) {
|
||||
ins->write(u8"命令校验信息", u8"命令执行参数校验失败", args_content);
|
||||
ins->flush();
|
||||
std::for_each(_output_list.begin(), _output_list.end(), [&](std::shared_ptr<logs::LogsPort> ins) {
|
||||
ins->write(u8"命令校验", u8"命令执行参数校验失败", args_content);
|
||||
ins->flush(true);
|
||||
});
|
||||
return;
|
||||
}
|
||||
unit->run();
|
||||
unit->saveTo(obj);
|
||||
obj.setString(u8"CmdAlias", alias_name);
|
||||
auto args_content = obj.toText();
|
||||
std::for_each(_output_list.begin(), _output_list.end(), [&](std::shared_ptr<logs::LogsPort> ins) {
|
||||
ins->write(u8"命令执行", u8"命令执行上下文", args_content);
|
||||
ins->flush();
|
||||
});
|
||||
}
|
||||
|
||||
void dispatch::Dispatch::getValidateDepict(datas::IDataObject& object) const {
|
||||
|
|
|
@ -5,16 +5,9 @@
|
|||
#include <memory>
|
||||
#include "cmds_basic.h"
|
||||
#include "validate_basic.h"
|
||||
#include "logs_port.h"
|
||||
|
||||
namespace dispatch {
|
||||
class IOutput {
|
||||
public:
|
||||
virtual ~IOutput() = default;
|
||||
|
||||
virtual void write(const QString &type, const QString& title, const QString& desc) = 0;
|
||||
virtual void flush() = 0;
|
||||
};
|
||||
|
||||
|
||||
class Dispatch {
|
||||
private:
|
||||
|
@ -22,14 +15,14 @@ namespace dispatch {
|
|||
QHash<quint64, validate::IValidatorTemplet*> _cmds_validators;
|
||||
QHash<quint64, std::pair<QString, Inlet::IRunbase*>> _events_map;
|
||||
|
||||
QList<std::shared_ptr<IOutput>> _output_list;
|
||||
QList<std::shared_ptr<logs::LogsPort>> _output_list;
|
||||
|
||||
static Dispatch* _unique_inst;
|
||||
|
||||
public:
|
||||
static Dispatch* unique();
|
||||
|
||||
void loadOutput(std::shared_ptr<IOutput> out_ins);
|
||||
void loadOutput(std::shared_ptr<logs::LogsPort> out_ins);
|
||||
|
||||
QList<quint64> allCmds() const;
|
||||
void registerCmd(quint64 addr, Inlet::IRunbase* unit);
|
||||
|
|
|
@ -8,14 +8,11 @@
|
|||
#include "validate_impl.h"
|
||||
#include "validate_depict.h"
|
||||
|
||||
int vp(int c) {
|
||||
qDebug() << c;
|
||||
return c;
|
||||
}
|
||||
int vp(int c);
|
||||
cmds::T<int(int)>::Cmd<vp> entry("hello");
|
||||
verify::T<int(int)>::Validate<vp> vp_check;
|
||||
auto args0 = vp_check.pos<0>() & new impls::Int32Limit<true, true>(u8"Hello World", 0, 3);
|
||||
|
||||
cmds::T<int(int)>::Cmd<vp> entry("hello");
|
||||
|
||||
|
||||
namespace xproc {
|
||||
|
@ -26,9 +23,14 @@ namespace xproc {
|
|||
}
|
||||
cmds::T<int(int)>::Cmd<xproc::xmp> xvv("sfaf");
|
||||
|
||||
template<> void datas::dataSet<int>(IDataObject& object, const QString& key, int value) { }
|
||||
template<> void datas::dataSet<int>(IDataObject& object, const QString& key, int value) {
|
||||
auto argx = object.newObject();
|
||||
argx->setString(u8"Type", u8"int");
|
||||
argx->setInt32(u8"Value", value);
|
||||
object.setChild(key, argx);
|
||||
}
|
||||
template<> int datas::dataGet<int>(IDataObject& object, const QString& key) {
|
||||
return 0;
|
||||
return object.getInt32(key);
|
||||
}
|
||||
|
||||
#include "logs_port.h"
|
||||
|
@ -36,6 +38,9 @@ using namespace Inlet;
|
|||
int main(int argc, char* argv[]) {
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
auto logs = std::make_shared<logs::LogsOutput>(QDir(u8"./"));
|
||||
dispatch::Dispatch::unique()->loadOutput(logs);
|
||||
|
||||
SignatureImpl<int, int> v(3);
|
||||
v.execute(vp);
|
||||
|
||||
|
@ -54,5 +59,12 @@ int main(int argc, char* argv[]) {
|
|||
dispatch::Dispatch::unique()->getValidateDepict(doc);
|
||||
qDebug().noquote() << doc.toText();
|
||||
|
||||
logs->flush(true);
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
|
||||
int vp(int c) {
|
||||
qDebug() << c;
|
||||
return c;
|
||||
}
|
|
@ -69,6 +69,10 @@ int64_t ValidateDocObject::getInt64(const QString& key) const {
|
|||
return _object_bind.value(key).toVariant().toLongLong();
|
||||
}
|
||||
|
||||
uint64_t depict::ValidateDocObject::getUInt64(const QString& key) const {
|
||||
return _object_bind.value(key).toVariant().toULongLong();
|
||||
}
|
||||
|
||||
QString ValidateDocObject::getString(const QString& key) const {
|
||||
return _object_bind.value(key).toString();
|
||||
}
|
||||
|
@ -85,6 +89,10 @@ void ValidateDocObject::setInt32(const QString& key, int32_t value) {
|
|||
_object_bind[key] = value;
|
||||
}
|
||||
|
||||
void depict::ValidateDocObject::setUInt64(const QString& key, uint64_t value) {
|
||||
_object_bind[key] = QJsonValue::fromVariant(QVariant(value));
|
||||
}
|
||||
|
||||
void ValidateDocObject::setInt64(const QString& key, int64_t value) {
|
||||
_object_bind[key] = value;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ namespace depict {
|
|||
|
||||
int64_t getInt64(const QString& key) const override;
|
||||
|
||||
uint64_t getUInt64(const QString &key) const override;
|
||||
|
||||
QString getString(const QString& key) const override;
|
||||
|
||||
void setBool(const QString& key, bool value) override;
|
||||
|
@ -48,6 +50,8 @@ namespace depict {
|
|||
|
||||
void setInt32(const QString& key, int32_t value) override;
|
||||
|
||||
void setUInt64(const QString &key, uint64_t value) override;
|
||||
|
||||
void setInt64(const QString& key, int64_t value) override;
|
||||
|
||||
void setString(const QString& key, const QString& value) override;
|
||||
|
|
Loading…
Reference in New Issue