add context holder & registry & bridge
This commit is contained in:
parent
64fb425f01
commit
3fdedb6240
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/build-doric-*/
|
||||
.DS_Store
|
17
doric/context_holder.h
Normal file
17
doric/context_holder.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef CONTEXT_HOLDER_H
|
||||
#define CONTEXT_HOLDER_H
|
||||
|
||||
#include "context.h"
|
||||
|
||||
class ContextHolder {
|
||||
|
||||
public:
|
||||
Context *_context;
|
||||
|
||||
public:
|
||||
ContextHolder(Context *context) {
|
||||
this->_context = context;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CONTEXT_HOLDER_H
|
@ -29,13 +29,17 @@ public:
|
||||
return &locla_s;
|
||||
}
|
||||
|
||||
Context* createContext(QString* script, QString* source) {
|
||||
Context *createContext(QString *script, QString *source) {
|
||||
int contextId = counter->fetchAndAddOrdered(1);
|
||||
Context* context = new Context(contextId, source);
|
||||
Context *context = new Context(contextId, source);
|
||||
contextMap->insert(contextId, context);
|
||||
context->driver->createContext(contextId, script);
|
||||
return context;
|
||||
}
|
||||
|
||||
Context *getContext(int contextId) {
|
||||
return contextMap->take(contextId);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CONTEXT_MANAGER_H
|
||||
|
@ -16,7 +16,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
SOURCES += \
|
||||
constant.cpp \
|
||||
driver/native_driver.cpp \
|
||||
main.cpp
|
||||
main.cpp \
|
||||
native/native_bridge.cpp
|
||||
|
||||
RESOURCES += qml.qrc
|
||||
|
||||
@ -34,6 +35,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||
HEADERS += \
|
||||
constant.h \
|
||||
context.h \
|
||||
context_holder.h \
|
||||
context_manager.h \
|
||||
driver/driver.h \
|
||||
driver/native_driver.h \
|
||||
@ -42,5 +44,7 @@ HEADERS += \
|
||||
native/native_empty.h \
|
||||
native/native_log.h \
|
||||
native/native_timer.h \
|
||||
plugin/shader_plugin.h \
|
||||
registry.h \
|
||||
template/singleton.h \
|
||||
utility/utility.h
|
||||
|
@ -6,11 +6,11 @@
|
||||
class Driver {
|
||||
|
||||
public:
|
||||
virtual void createContext(int contextId, QString* script) = 0;
|
||||
virtual void createContext(int contextId, QString *script) = 0;
|
||||
virtual void destroyContext(int contextId) = 0;
|
||||
|
||||
virtual void invokeContextEntityMethod(int contextId, QString* method, ...) = 0;
|
||||
virtual void invokeDoricMethod(QString* method, ...) = 0;
|
||||
virtual void invokeContextEntityMethod(int contextId, QString *method, ...) = 0;
|
||||
virtual void invokeDoricMethod(QString *method, ...) = 0;
|
||||
|
||||
virtual ~Driver() = default;
|
||||
};
|
||||
|
@ -28,8 +28,8 @@ public:
|
||||
void createContext(int contextId, QString *script) override;
|
||||
void destroyContext(int contextId) override;
|
||||
|
||||
void invokeContextEntityMethod(int contextId, QString* method, ...) override;
|
||||
void invokeDoricMethod(QString* method, ...) override;
|
||||
void invokeContextEntityMethod(int contextId, QString *method, ...) override;
|
||||
void invokeDoricMethod(QString *method, ...) override;
|
||||
};
|
||||
|
||||
#endif // NATIVE_DRIVER_H
|
||||
|
@ -2,8 +2,8 @@
|
||||
#define JS_ENGINE_H
|
||||
|
||||
#include <QFile>
|
||||
#include <QObject>
|
||||
#include <QJSEngine>
|
||||
#include <QObject>
|
||||
#include <QResource>
|
||||
|
||||
#include "constant.h"
|
||||
@ -24,7 +24,7 @@ public:
|
||||
initDoricRuntime();
|
||||
}
|
||||
|
||||
void prepareContext(int contextId, QString* script) {
|
||||
void prepareContext(int contextId, QString *script) {
|
||||
QString contextIdString = QString::number(contextId);
|
||||
QString source = QString(Constant::TEMPLATE_CONTEXT_CREATE)
|
||||
.replace("%s1", *script)
|
||||
|
11
doric/native/native_bridge.cpp
Normal file
11
doric/native/native_bridge.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "context_manager.h"
|
||||
#include "native_bridge.h"
|
||||
|
||||
Q_INVOKABLE void NativeBridge::function(int contextId, QString module, QString methodName, QString callbackId, QJSValue jsValue) {
|
||||
qDebug() << "contextId: " + QString::number(contextId) + ", " +
|
||||
"module: " + module + ", " +
|
||||
"methodName: " + methodName + ", " +
|
||||
"callbackId: " + callbackId + ", " +
|
||||
"arguments: " + jsValue.toString();
|
||||
Context* context = ContextManager::getInstance()->getContext(contextId);
|
||||
}
|
@ -11,13 +11,7 @@ class NativeBridge : public QObject {
|
||||
public:
|
||||
NativeBridge(QObject *parent = nullptr) : QObject(parent) {}
|
||||
|
||||
Q_INVOKABLE void function(int contextId, QString module, QString methodName, QString callbackId, QJSValue jsValue) {
|
||||
qDebug() << "contextId: " + QString::number(contextId) + ", " +
|
||||
"module: " + module + ", " +
|
||||
"methodName: " + methodName + ", " +
|
||||
"callbackId: " + callbackId + ", " +
|
||||
"arguments: " + jsValue.toString();
|
||||
}
|
||||
Q_INVOKABLE void function(int contextId, QString module, QString methodName, QString callbackId, QJSValue jsValue);
|
||||
};
|
||||
|
||||
#endif // NATIVE_BRIDGE_H
|
||||
|
12
doric/plugin/shader_plugin.h
Normal file
12
doric/plugin/shader_plugin.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef SHADER_PLUGIN_H
|
||||
#define SHADER_PLUGIN_H
|
||||
|
||||
#include "context_holder.h"
|
||||
|
||||
class ShaderPlugin : public ContextHolder {
|
||||
|
||||
public:
|
||||
ShaderPlugin(Context* context) : ContextHolder(context) {}
|
||||
};
|
||||
|
||||
#endif // SHADER_PLUGIN_H
|
24
doric/registry.h
Normal file
24
doric/registry.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef REGISTRY_H
|
||||
#define REGISTRY_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
|
||||
#include "plugin/shader_plugin.h"
|
||||
|
||||
class Registry {
|
||||
|
||||
private:
|
||||
QMap<QString, QString> pluginInfoMap;
|
||||
|
||||
public:
|
||||
Registry() {
|
||||
registerNativePlugin(typeid(ShaderPlugin).name());
|
||||
}
|
||||
|
||||
void registerNativePlugin(QString name) {
|
||||
qDebug() << name;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // REGISTRY_H
|
Reference in New Issue
Block a user