add context holder & registry & bridge

This commit is contained in:
王劲鹏 2019-12-13 17:45:27 +08:00
parent 64fb425f01
commit 3fdedb6240
11 changed files with 85 additions and 18 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/build-doric-*/
.DS_Store

17
doric/context_holder.h Normal file
View 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

View File

@ -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

View File

@ -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

View File

@ -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;
};

View File

@ -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

View File

@ -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)

View 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);
}

View File

@ -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

View 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
View 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