diff --git a/doric-Qt/example/doric/Doric.h b/doric-Qt/example/doric/Doric.h new file mode 100644 index 00000000..b3fa6b94 --- /dev/null +++ b/doric-Qt/example/doric/Doric.h @@ -0,0 +1,13 @@ +#ifndef DORIC_H +#define DORIC_H + +#include "DoricLibrary.h" + +class Doric { +public: + static void registerLibrary(DoricLibrary *doricLibrary) { + DoricRegistry::getInstance()->registerLibrary(doricLibrary); + } +}; + +#endif // DORIC_H diff --git a/doric-Qt/example/doric/DoricLibrary.h b/doric-Qt/example/doric/DoricLibrary.h new file mode 100644 index 00000000..39d2ae69 --- /dev/null +++ b/doric-Qt/example/doric/DoricLibrary.h @@ -0,0 +1,11 @@ +#ifndef DORICLIBRARY_H +#define DORICLIBRARY_H + +#include "DoricRegistry.h" + +class DoricLibrary { +public: + virtual void load(DoricRegistry *registry) = 0; +}; + +#endif // DORICLIBRARY_H diff --git a/doric-Qt/example/doric/DoricRegistry.cpp b/doric-Qt/example/doric/DoricRegistry.cpp index cf12e60e..3cd10062 100644 --- a/doric-Qt/example/doric/DoricRegistry.cpp +++ b/doric-Qt/example/doric/DoricRegistry.cpp @@ -1,4 +1,5 @@ #include "DoricRegistry.h" +#include "DoricLibrary.h" #include "plugin/DoricModalPlugin.h" #include "plugin/DoricNetworkPlugin.h" @@ -41,3 +42,8 @@ bool DoricRegistry::acquirePluginInfo(QString name) { bool DoricRegistry::acquireNodeInfo(QString name) { return nodes.acquireClass(name); } + +void DoricRegistry::registerLibrary(DoricLibrary *doricLibrary) { + doricLibraries.insert(doricLibrary); + doricLibrary->load(this); +} diff --git a/doric-Qt/example/doric/DoricRegistry.h b/doric-Qt/example/doric/DoricRegistry.h index a054a538..71c93c5e 100644 --- a/doric-Qt/example/doric/DoricRegistry.h +++ b/doric-Qt/example/doric/DoricRegistry.h @@ -1,12 +1,27 @@ #ifndef REGISTRY_H #define REGISTRY_H +#include #include #include "utils/DoricObjectFactory.h" +class DoricLibrary; + class DoricRegistry { +private: + static DoricRegistry *local_instance; + + ~DoricRegistry() { qDebug() << "destructor"; } + public: + static DoricRegistry *getInstance() { + static DoricRegistry instance; + return &instance; + } + + QSet doricLibraries; + DoricObjectFactory plugins; DoricObjectFactory nodes; @@ -23,6 +38,8 @@ public: bool acquirePluginInfo(QString name); bool acquireNodeInfo(QString name); + + void registerLibrary(DoricLibrary *doricLibrary); }; #endif // REGISTRY_H diff --git a/doric-Qt/example/doric/doric.pro b/doric-Qt/example/doric/doric.pro index fae2c4aa..63f46d77 100644 --- a/doric-Qt/example/doric/doric.pro +++ b/doric-Qt/example/doric/doric.pro @@ -89,9 +89,11 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ + Doric.h \ DoricContext.h \ DoricContextManager.h \ DoricInterfaceDriver.h \ + DoricLibrary.h \ DoricNativeDriver.h \ DoricPanel.h \ DoricRegistry.h \ diff --git a/doric-Qt/example/doric/engine/DoricJSEngine.h b/doric-Qt/example/doric/engine/DoricJSEngine.h index c1606280..f8f3909c 100644 --- a/doric-Qt/example/doric/engine/DoricJSEngine.h +++ b/doric-Qt/example/doric/engine/DoricJSEngine.h @@ -11,7 +11,7 @@ class DoricJSEngine : public QObject { Q_OBJECT private: DoricInterfaceJSE *mJSE; - DoricRegistry *mRegistry = new DoricRegistry(); + DoricRegistry *mRegistry = DoricRegistry::getInstance(); void loadBuiltinJS(QString assetName); QString packageContextScript(QString contextId, QString content);