commit 4689ed7374a8167ec213816b551db60d30433ba6
Author: codeboss <2422523675@qq.com>
Date: Mon Nov 11 16:29:59 2024 +0800
init
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3ecab47
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+x64/
+PenetrateBasic/x64/
+.vs/
diff --git a/PenetrateBasic.sln b/PenetrateBasic.sln
new file mode 100644
index 0000000..1f5301c
--- /dev/null
+++ b/PenetrateBasic.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.10.35122.118
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PenetrateBasic", "PenetrateBasic\PenetrateBasic.vcxproj", "{D8292764-1B3E-401E-858B-BBBD8F07BEC5}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Release|x64 = Release|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {D8292764-1B3E-401E-858B-BBBD8F07BEC5}.Debug|x64.ActiveCfg = Debug|x64
+ {D8292764-1B3E-401E-858B-BBBD8F07BEC5}.Debug|x64.Build.0 = Debug|x64
+ {D8292764-1B3E-401E-858B-BBBD8F07BEC5}.Release|x64.ActiveCfg = Release|x64
+ {D8292764-1B3E-401E-858B-BBBD8F07BEC5}.Release|x64.Build.0 = Release|x64
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {B111E4D7-F1F3-45C3-A97D-75752139749D}
+ EndGlobalSection
+EndGlobal
diff --git a/PenetrateBasic/PenetrateBasic.vcxproj b/PenetrateBasic/PenetrateBasic.vcxproj
new file mode 100644
index 0000000..253f6dc
--- /dev/null
+++ b/PenetrateBasic/PenetrateBasic.vcxproj
@@ -0,0 +1,110 @@
+
+
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ {D8292764-1B3E-401E-858B-BBBD8F07BEC5}
+ QtVS_v304
+ 10.0
+ 10.0
+ $(MSBuildProjectDirectory)\QtMsBuild
+
+
+
+ Application
+ v143
+ true
+ Unicode
+
+
+ Application
+ v143
+ false
+ true
+ Unicode
+
+
+
+
+
+
+ 5.12.11_msvc2017_64
+ core
+ debug
+
+
+ 5.12.11_msvc2017_64
+ core
+ release
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ Level3
+ true
+ true
+
+
+ Console
+ true
+
+
+
+
+ true
+ Level3
+ true
+ true
+ true
+ true
+
+
+ Console
+ false
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/PenetrateBasic/PenetrateBasic.vcxproj.filters b/PenetrateBasic/PenetrateBasic.vcxproj.filters
new file mode 100644
index 0000000..b76a98c
--- /dev/null
+++ b/PenetrateBasic/PenetrateBasic.vcxproj.filters
@@ -0,0 +1,47 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ qml;cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;hm;inl;inc;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+ {99349809-55BA-4b9d-BF79-8FDBB0286EB3}
+ ui
+
+
+ {639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}
+ ts
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+
\ No newline at end of file
diff --git a/PenetrateBasic/PenetrateBasic.vcxproj.user b/PenetrateBasic/PenetrateBasic.vcxproj.user
new file mode 100644
index 0000000..41a709a
--- /dev/null
+++ b/PenetrateBasic/PenetrateBasic.vcxproj.user
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/PenetrateBasic/cmds.h b/PenetrateBasic/cmds.h
new file mode 100644
index 0000000..06a9e67
--- /dev/null
+++ b/PenetrateBasic/cmds.h
@@ -0,0 +1,47 @@
+#pragma once
+#include "dispatch.h"
+#include "cmds_basic.h"
+
+namespace cmds {
+ template struct T;
+ template struct T {
+ public:
+ template func> struct Cmd {
+ private:
+ dispatch::Dispatch* _core_bind;
+ QString _name_value;
+
+ public:
+ Cmd(dispatch::Dispatch* core, const QString& name)
+ : _core_bind(core), _name_value(name) {
+ auto inst = Inlet::CmdsImpl<(void*) func, Ret, Args...>::global();
+ core->registerCmd(inst->address(), inst, name);
+ }
+
+ Ret operator()(Args... args) {
+ Inlet::CmdsImpl<(void*) func, Ret, Args...> new_inst(args...);
+ _core_bind->runWith(&new_inst);
+ return new_inst.result();
+ }
+ };
+
+ template func> struct Event {
+ private:
+ dispatch::Dispatch* _core_bind;
+ QString _name_value;
+
+ public:
+ Event(dispatch::Dispatch* core, const QString& name)
+ : _core_bind(core), _name_value(name) {
+ auto inst = Inlet::EventsImpl<(void*) func, Ret, Args...>::global();
+ core->registerEvent(inst->address(), inst, name);
+ }
+
+ void operator()(Args... args) {
+ Inlet::EventsImpl<(void*)func, Ret, Args...> new_inst(args...);
+ _core_bind->notifyWith(&new_inst);
+ }
+ };
+ };
+
+}
diff --git a/PenetrateBasic/cmds_basic.h b/PenetrateBasic/cmds_basic.h
new file mode 100644
index 0000000..cd5fdc7
--- /dev/null
+++ b/PenetrateBasic/cmds_basic.h
@@ -0,0 +1,168 @@
+#pragma once
+
+#include
+#include
+#include "data_types.h"
+
+namespace Inlet {
+ template struct SignatureImpl;
+ template<> struct SignatureImpl<> {
+ public:
+ SignatureImpl() { }
+
+ void execute(std::function unit) {
+ unit();
+ }
+ void result() const { }
+
+ void saveTo(int index, datas::IDataObject &object) { }
+ void loadFrom(int index, datas::IDataObject &object) { }
+ };
+ template struct SignatureImpl {
+ private:
+ Ret _result;
+
+ public:
+ SignatureImpl() : _result(Ret()) { }
+
+ Ret execute(std::function unit) {
+ _result = unit();
+ return _result;
+ }
+
+ Ret result() const {
+ return _result;
+ }
+
+ void saveTo(int index, datas::IDataObject &object) {
+ datas::dataSet(object, u8"RetValue", _result);
+ }
+ void loadFrom(int index, datas::IDataObject &object) {
+ _result = datas::dataGet(object, u8"RetValue");
+ }
+ };
+ template
+ struct SignatureImpl : public SignatureImpl {
+ private:
+ First _args_value;
+
+ public:
+ SignatureImpl() : SignatureImpl(), _args_value(First()) { }
+ SignatureImpl(First a0, Args... args) :SignatureImpl(args...), _args_value(a0) { }
+
+ Ret execute(std::function unit) {
+ auto unit_wrap = [&](Args... args) {
+ return unit(_args_value, args...);
+ };
+ return SignatureImpl::execute(unit_wrap);
+ }
+
+
+ void saveTo(int index, datas::IDataObject &object) {
+ datas::dataSet(object, QString(u8"Args_%1").arg(index), _args_value);
+ SignatureImpl::saveTo(index + 1, object);
+ }
+ void loadFrom(int index, datas::IDataObject &object) {
+ _args_value = datas::dataGet(object, QString(u8"Args_%1").arg(index));
+ SignatureImpl::loadFrom(index + 1, object);
+ }
+ };
+
+
+
+
+ class IRunbase {
+ public:
+ virtual ~IRunbase() = default;
+
+ virtual quint64 address() const = 0;
+ virtual void run() = 0;
+
+ virtual void saveTo(datas::IDataObject& object) = 0;
+ virtual void loadFrom(datas::IDataObject& object) = 0;
+ };
+
+ template using Callable = Ret(*)(Args...);
+
+ template struct CmdsImpl : public IRunbase {
+ private:
+ Callable _func = (Callable)addr;
+ SignatureImpl _args_value;
+
+ static CmdsImpl* _global_inst;
+
+ public:
+ CmdsImpl() : _args_value() { }
+ CmdsImpl(Args... args) :_args_value(args...) { }
+
+ static CmdsImpl* global() {
+ if (!_global_inst) {
+ _global_inst = new CmdsImpl();
+ }
+ return _global_inst;
+ }
+
+ Ret execute(Args... args) {
+ _args_value = SignatureImpl(args...);
+ return _args_value.execute(_func);
+ }
+
+ Ret result() const {
+ return _args_value.result();
+ }
+
+ // IRunbase
+ quint64 address() const {
+ return (quint64) addr;
+ }
+ void run() {
+ _args_value.execute(_func);
+ }
+ virtual void saveTo(datas::IDataObject &object) {
+ _args_value.saveTo(0, object);
+ }
+ virtual void loadFrom(datas::IDataObject &object) {
+ _args_value.loadFrom(0, object);
+ }
+ };
+ template CmdsImpl* CmdsImpl::_global_inst = nullptr;
+
+
+ template struct EventsImpl : public IRunbase {
+ private:
+ Callable _func = (Callable)addr;
+ SignatureImpl _args_value;
+
+ static EventsImpl* _global_inst;
+
+ public:
+ EventsImpl() : _args_value() { }
+ EventsImpl(Args... args) : _args_value(args...) { }
+
+ static EventsImpl* global() {
+ if (!_global_inst) {
+ _global_inst = new EventsImpl();
+ }
+ return _global_inst;
+ }
+
+ void execute(Args... args) {
+ _args_value = SignatureImpl(args...);
+ }
+
+ // IRunbase
+ quint64 address() const {
+ return (quint64) addr;
+ }
+ void run() {
+ _args_value.execute(_func);
+ }
+ virtual void saveTo(datas::IDataObject &object) {
+ _args_value.saveTo(0, object);
+ }
+ virtual void loadFrom(datas::IDataObject &object) {
+ _args_value.loadFrom(0, object);
+ }
+ };
+ template EventsImpl* EventsImpl::_global_inst = nullptr;
+}
diff --git a/PenetrateBasic/data_types.h b/PenetrateBasic/data_types.h
new file mode 100644
index 0000000..c6ca2fb
--- /dev/null
+++ b/PenetrateBasic/data_types.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#include
+
+namespace datas {
+
+ class IDataArray;
+ class IDataObject {
+ public:
+ virtual ~IDataObject() = default;
+
+ virtual bool isArray() const = 0;
+
+ virtual bool getBool(const QString& key) = 0;
+ virtual double getDouble(const QString& key) = 0;
+ virtual int32_t getInt32(const QString& key) = 0;
+ virtual int64_t getInt64(const QString& key) = 0;
+ virtual QString getString(const QString& key) = 0;
+ virtual IDataObject getObject(const QString& key) = 0;
+ virtual IDataArray toArray() = 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 setString(const QString& key, const QString& value) = 0;
+ virtual void setObject(const QString& key, IDataObject value) = 0;
+ };
+ class IDataArray : public IDataObject {
+ public:
+ virtual ~IDataArray() = default;
+
+ virtual int32_t size() const = 0;
+ virtual IDataObject get(int index) = 0;
+ virtual void insert(int index, IDataObject value) = 0;
+ virtual void append(IDataObject value) = 0;
+ };
+
+
+ template void dataSet(IDataObject& object, const QString& key, T value);
+ template T dataGet(IDataObject& object, const QString& key);
+
+}
diff --git a/PenetrateBasic/dispatch.cpp b/PenetrateBasic/dispatch.cpp
new file mode 100644
index 0000000..e7773cc
--- /dev/null
+++ b/PenetrateBasic/dispatch.cpp
@@ -0,0 +1,24 @@
+#include "dispatch.h"
+
+using namespace dispatch;
+using namespace Inlet;
+
+QList Dispatch::allCmds() const {
+ return _cmds_map.keys();
+}
+
+void Dispatch::registerCmd(quint64 addr, IRunbase* unit, const QString& alias) {
+ _cmds_map[addr] = std::make_pair(alias, unit);
+}
+
+QString Dispatch::getCmdAlias(quint64 addr) const {
+ return _cmds_map[addr].first;
+}
+
+QString Dispatch::getCmdDefault(quint64 addr) const {
+ return "";
+}
+
+void Dispatch::runWith(IRunbase* unit) {
+ unit->run();
+}
diff --git a/PenetrateBasic/dispatch.h b/PenetrateBasic/dispatch.h
new file mode 100644
index 0000000..24d3e25
--- /dev/null
+++ b/PenetrateBasic/dispatch.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include
+#include
+#include "cmds_basic.h"
+
+namespace dispatch {
+
+ class IOutput {
+ public:
+ virtual ~IOutput() = default;
+
+ virtual void write(const QString &title, const QString& desc) = 0;
+ };
+
+ class Dispatch {
+ private:
+ QHash> _cmds_map;
+ QHash> _events_map;
+
+ QList _output_list;
+
+ public:
+ QList allCmds() const;
+ void registerCmd(quint64 addr, Inlet::IRunbase* unit, const QString& alias);
+ QString getCmdAlias(quint64 addr) const;
+ QString getCmdDefault(quint64 addr) const;
+ void runWith(Inlet::IRunbase* unit);
+
+ QList allEvents() const;
+ void registerEvent(quint64 addr, Inlet::IRunbase* unit, const QString& alias);
+ QString getEventAlias(quint64 addr) const;
+ QString getEventDefault(quint64 addr) const;
+ QString notifyWith(Inlet::IRunbase* unit);
+
+ };
+}
diff --git a/PenetrateBasic/main.cpp b/PenetrateBasic/main.cpp
new file mode 100644
index 0000000..50237d8
--- /dev/null
+++ b/PenetrateBasic/main.cpp
@@ -0,0 +1,50 @@
+#include
+#include
+
+#include "cmds_basic.h"
+#include "dispatch.h"
+#include "cmds.h"
+
+dispatch::Dispatch c;
+
+
+int vp(int c) {
+ qDebug() << c;
+ return c;
+}
+cmds::T::Cmd entry(&c, "hello");
+
+namespace xproc {
+ int xmp(int arg) {
+ qDebug() << "xmp";
+ return 3;
+ }
+
+ cmds::T::Cmd xvv(&c, "sfaf");
+}
+
+
+using namespace Inlet;
+int main(int argc, char* argv[]) {
+ QCoreApplication a(argc, argv);
+
+ SignatureImpl v(3);
+ v.execute(vp);
+
+ Callable vptr = vp;
+
+ CmdsImpl<(void*) vp, int, int> exec;
+ exec.execute(5);
+
+ entry(50);
+
+ xproc::xvv(2);
+
+
+ return a.exec();
+}
+
+template<> void datas::dataSet(IDataObject& object, const QString& key, int value) { }
+template<> int datas::dataGet(IDataObject& object, const QString& key) {
+ return 0;
+}