diff --git a/doric-Qt/doric/context.cpp b/doric-Qt/doric/context.cpp index 94468793..6b6c5105 100644 --- a/doric-Qt/doric/context.cpp +++ b/doric-Qt/doric/context.cpp @@ -1,5 +1,6 @@ #include "context.h" #include "native_driver.h" +#include "context_manager.h" Context::Context(QString contextId, QString source, QString extra) { @@ -8,6 +9,13 @@ Context::Context(QString contextId, QString source, QString 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() { if (driver == NULL) diff --git a/doric-Qt/doric/context.h b/doric-Qt/doric/context.h index 1cfd6117..0cbaaa27 100644 --- a/doric-Qt/doric/context.h +++ b/doric-Qt/doric/context.h @@ -17,10 +17,7 @@ private: public: Context(QString contextId, QString source, QString extra); - static Context* create(QString script, QString source, QString extra) - { - return NULL; - } + static Context* create(QString script, QString source, QString extra); InterfaceDriver* getDriver(); }; diff --git a/doric-Qt/doric/context_manager.cpp b/doric-Qt/doric/context_manager.cpp new file mode 100644 index 00000000..c74e6362 --- /dev/null +++ b/doric-Qt/doric/context_manager.cpp @@ -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; +} diff --git a/doric-Qt/doric/context_manager.h b/doric-Qt/doric/context_manager.h index 374b71c7..e5b8e25c 100644 --- a/doric-Qt/doric/context_manager.h +++ b/doric-Qt/doric/context_manager.h @@ -29,13 +29,7 @@ public: return &instance; } - 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; - } + Context *createContext(QString script, QString source, QString extra); }; #endif // CONTEXTMANAGER_H diff --git a/doric-Qt/doric/doric.pro b/doric-Qt/doric/doric.pro index acb21499..74a6081a 100644 --- a/doric-Qt/doric/doric.pro +++ b/doric-Qt/doric/doric.pro @@ -17,6 +17,7 @@ SOURCES += \ async/async_result.cpp \ async/settable_future.cpp \ context.cpp \ + context_manager.cpp \ engine/bridge_extension.cpp \ engine/js_engine.cpp \ engine/native_empty.cpp \ diff --git a/doric-Qt/doric/main.cpp b/doric-Qt/doric/main.cpp index e3a7a0cf..db8d3b83 100644 --- a/doric-Qt/doric/main.cpp +++ b/doric-Qt/doric/main.cpp @@ -1,11 +1,5 @@ #include #include -#include - -#include "engine/js_engine.h" -#include "async/async_result.h" -#include "context_manager.h" -#include "utils/utils.h" int main(int argc, char *argv[]) { @@ -22,10 +16,5 @@ int main(int argc, char *argv[]) }, Qt::QueuedConnection); engine.load(url); - JSEngine jsEngine; - - QString script = Utils::readAssetFile("doric", "Snake.js"); - ContextManager::getInstance()->createContext(script, "", ""); - return app.exec(); }