fix header circular deps

This commit is contained in:
王劲鹏 2021-01-28 20:31:06 +08:00 committed by osborn
parent 21b3353e18
commit 3b72ab56aa
6 changed files with 21 additions and 22 deletions

View File

@ -1,5 +1,6 @@
#include "context.h" #include "context.h"
#include "native_driver.h" #include "native_driver.h"
#include "context_manager.h"
Context::Context(QString contextId, QString source, QString extra) Context::Context(QString contextId, QString source, QString extra)
{ {
@ -8,6 +9,13 @@ Context::Context(QString contextId, QString source, QString extra)
this->extra = extra; this->extra = extra;
} }
Context* Context::create(QString script, QString source, QString extra)
{
Context *context = ContextManager::getInstance()->createContext(script, source, extra);
context->script = script;
return context;
}
InterfaceDriver* Context::getDriver() InterfaceDriver* Context::getDriver()
{ {
if (driver == NULL) if (driver == NULL)

View File

@ -17,10 +17,7 @@ private:
public: public:
Context(QString contextId, QString source, QString extra); Context(QString contextId, QString source, QString extra);
static Context* create(QString script, QString source, QString extra) static Context* create(QString script, QString source, QString extra);
{
return NULL;
}
InterfaceDriver* getDriver(); InterfaceDriver* getDriver();
}; };

View File

@ -0,0 +1,10 @@
#include "context_manager.h"
Context *ContextManager::createContext(QString script, QString source, QString extra)
{
int contextId = counter->fetchAndAddOrdered(1);
Context *context = new Context(QString::number(contextId), source, extra);
contextMap->insert(QString::number(contextId), context);
context->getDriver()->createContext(QString::number(contextId), script, source);
return context;
}

View File

@ -29,13 +29,7 @@ public:
return &instance; return &instance;
} }
Context *createContext(QString script, QString source, QString extra) { Context *createContext(QString script, QString source, QString extra);
int contextId = counter->fetchAndAddOrdered(1);
Context *context = new Context(QString::number(contextId), source, extra);
contextMap->insert(QString::number(contextId), context);
context->getDriver()->createContext(QString::number(contextId), script, source);
return context;
}
}; };
#endif // CONTEXTMANAGER_H #endif // CONTEXTMANAGER_H

View File

@ -17,6 +17,7 @@ SOURCES += \
async/async_result.cpp \ async/async_result.cpp \
async/settable_future.cpp \ async/settable_future.cpp \
context.cpp \ context.cpp \
context_manager.cpp \
engine/bridge_extension.cpp \ engine/bridge_extension.cpp \
engine/js_engine.cpp \ engine/js_engine.cpp \
engine/native_empty.cpp \ engine/native_empty.cpp \

View File

@ -1,11 +1,5 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QDebug>
#include "engine/js_engine.h"
#include "async/async_result.h"
#include "context_manager.h"
#include "utils/utils.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -22,10 +16,5 @@ int main(int argc, char *argv[])
}, Qt::QueuedConnection); }, Qt::QueuedConnection);
engine.load(url); engine.load(url);
JSEngine jsEngine;
QString script = Utils::readAssetFile("doric", "Snake.js");
ContextManager::getInstance()->createContext(script, "", "");
return app.exec(); return app.exec();
} }