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-*/ /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

@ -36,6 +36,10 @@ public:
context->driver->createContext(contextId, script); context->driver->createContext(contextId, script);
return context; return context;
} }
Context *getContext(int contextId) {
return contextMap->take(contextId);
}
}; };
#endif // CONTEXT_MANAGER_H #endif // CONTEXT_MANAGER_H

View File

@ -16,7 +16,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \ SOURCES += \
constant.cpp \ constant.cpp \
driver/native_driver.cpp \ driver/native_driver.cpp \
main.cpp main.cpp \
native/native_bridge.cpp
RESOURCES += qml.qrc RESOURCES += qml.qrc
@ -34,6 +35,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
HEADERS += \ HEADERS += \
constant.h \ constant.h \
context.h \ context.h \
context_holder.h \
context_manager.h \ context_manager.h \
driver/driver.h \ driver/driver.h \
driver/native_driver.h \ driver/native_driver.h \
@ -42,5 +44,7 @@ HEADERS += \
native/native_empty.h \ native/native_empty.h \
native/native_log.h \ native/native_log.h \
native/native_timer.h \ native/native_timer.h \
plugin/shader_plugin.h \
registry.h \
template/singleton.h \ template/singleton.h \
utility/utility.h utility/utility.h

View File

@ -2,8 +2,8 @@
#define JS_ENGINE_H #define JS_ENGINE_H
#include <QFile> #include <QFile>
#include <QObject>
#include <QJSEngine> #include <QJSEngine>
#include <QObject>
#include <QResource> #include <QResource>
#include "constant.h" #include "constant.h"

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: public:
NativeBridge(QObject *parent = nullptr) : QObject(parent) {} NativeBridge(QObject *parent = nullptr) : QObject(parent) {}
Q_INVOKABLE void function(int contextId, QString module, QString methodName, QString callbackId, QJSValue jsValue) { 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();
}
}; };
#endif // NATIVE_BRIDGE_H #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