context holder & generic

This commit is contained in:
王劲鹏 2021-02-05 18:12:25 +08:00 committed by osborn
parent 41640c1399
commit 24f7bb2498
9 changed files with 51 additions and 8 deletions

View File

@ -1,7 +1,9 @@
#include "DoricContext.h"
#include "DoricContextManager.h"
#include "DoricNativeDriver.h"
#include "utils/DoricConstant.h"
#include "utils/DoricContextHolder.h"
DoricContext::DoricContext(QString contextId, QString source, QString extra) {
this->mRootNode = new DoricRootNode();
@ -63,6 +65,7 @@ QObject *DoricContext::obtainPlugin(QString name) {
} else {
QObject *plugin =
getDriver()->getRegistry()->pluginInfoMap.createObject(name);
dynamic_cast<DoricContextHolder *>(plugin)->setContext(this);
mPluginMap.insert(name, plugin);
return plugin;
}

View File

@ -32,7 +32,8 @@ SOURCES += \
main.cpp \
plugin/DoricShaderPlugin.cpp \
shader/DoricRootNode.cpp \
utils/DoricConstant.cpp
utils/DoricConstant.cpp \
utils/DoricContextHolder.cpp
RESOURCES += qml.qrc
@ -67,10 +68,12 @@ HEADERS += \
engine/DoricNativeLog.h \
engine/DoricNativeRequire.h \
engine/DoricTimerExtension.h \
plugin/DoricNativePlugin.h \
plugin/DoricShaderPlugin.h \
shader/DoricRootNode.h \
template/DoricSingleton.h \
utils/DoricConstant.h \
utils/DoricContextHolder.h \
utils/DoricCountDownLatch.h \
utils/DoricObjectFactory.h \
utils/DoricUtils.h

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.11.1, 2021-02-04T16:22:10. -->
<!-- Written by QtCreator 4.11.1, 2021-02-05T15:58:19. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -19,7 +19,6 @@ void DoricBridgeExtension::callNative(QString contextId, QString module,
Qt::DirectConnection, QGenericReturnArgument(),
Q_ARG(QJSValue, jsValue),
Q_ARG(QString, callbackId));
qDebug() << plugin;
}
qDebug() << "contextId: " + contextId;
qDebug() << "module: " + module;

View File

@ -0,0 +1,11 @@
#ifndef DORICNATIVEPLUGIN_H
#define DORICNATIVEPLUGIN_H
#include "../utils/DoricContextHolder.h"
class DoricNativePlugin : public DoricContextHolder {
public:
using DoricContextHolder::DoricContextHolder;
};
#endif // DORICNATIVEPLUGIN_H

View File

@ -2,8 +2,6 @@
#include <QDebug>
DoricShaderPlugin::DoricShaderPlugin(QObject *parent) : QObject(parent) {}
void DoricShaderPlugin::render(QJSValue jsValue, QString callbackId) {
qDebug() << "";
qDebug() << getContext();
}

View File

@ -4,10 +4,12 @@
#include <QJSValue>
#include <QObject>
class DoricShaderPlugin : public QObject {
#include "DoricNativePlugin.h"
class DoricShaderPlugin : public DoricNativePlugin {
Q_OBJECT
public:
DoricShaderPlugin(QObject *parent);
using DoricNativePlugin::DoricNativePlugin;
Q_INVOKABLE void render(QJSValue jsValue, QString callbackId);
};

View File

@ -0,0 +1,9 @@
#include "DoricContextHolder.h"
DoricContextHolder::DoricContextHolder(QObject *parent) { mContext = NULL; }
void DoricContextHolder::setContext(DoricContext *context) {
mContext = context;
}
DoricContext *DoricContextHolder::getContext() { return mContext; }

View File

@ -0,0 +1,18 @@
#ifndef DORICCONTEXTHOLDER_H
#define DORICCONTEXTHOLDER_H
#include "../DoricContext.h"
class DoricContextHolder : public QObject {
protected:
DoricContext *mContext = NULL;
public:
explicit DoricContextHolder(QObject *parent = nullptr);
void setContext(DoricContext *context);
DoricContext *getContext();
};
#endif // DORICCONTEXTHOLDER_H