This commit is contained in:
王劲鹏
2021-01-28 17:06:40 +08:00
committed by osborn
parent 0be7a9679a
commit 93b7cc2457
53 changed files with 1020 additions and 774 deletions

View File

@@ -0,0 +1,37 @@
#include "constant.h"
const QString Constant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.js";
const QString Constant::DORIC_BUNDLE_LIB = "doric-lib.js";
const QString Constant::DORIC_MODULE_LIB = "doric";
const QString Constant::INJECT_ENVIRONMENT = "Environment";
const QString Constant::INJECT_LOG = "nativeLog";
const QString Constant::INJECT_EMPTY = "nativeEmpty";
const QString Constant::INJECT_REQUIRE = "nativeRequire";
const QString Constant::INJECT_TIMER_SET = "nativeSetTimer";
const QString Constant::INJECT_TIMER_CLEAR = "nativeClearTimer";
const QString Constant::INJECT_BRIDGE = "nativeBridge";
const QString Constant::TEMPLATE_CONTEXT_CREATE = QString("Reflect.apply(") +
"function(doric,context,Entry,require,exports){" + "\n" +
"%s1" + "\n" +
"},undefined,[" +
"undefined," +
"doric.jsObtainContext(\"%s2\")," +
"doric.jsObtainEntry(\"%s3\")," +
"doric.__require__" +
",{}" +
"])";
const QString Constant::TEMPLATE_MODULE = QString("Reflect.apply(doric.jsRegisterModule,this,[") +
"\"%s1\"," +
"Reflect.apply(function(__module){" +
"(function(module,exports,require){" + "\n" +
"%s2" + "\n" +
"})(__module,__module.exports,doric.__require__);" +
"\nreturn __module.exports;" +
"},this,[{exports:{}}])" +
"])";
const QString Constant::TEMPLATE_CONTEXT_DESTROY = QString("doric.jsReleaseContext(\"%s\")");
const QString Constant::GLOBAL_DORIC = "doric";
const QString Constant::DORIC_TIMER_CALLBACK = "jsCallbackTimer";

View File

@@ -0,0 +1,30 @@
#ifndef CONSTANT_H
#define CONSTANT_H
#include <QString>
class Constant {
public:
static const QString DORIC_BUNDLE_SANDBOX;
static const QString DORIC_BUNDLE_LIB;
static const QString DORIC_MODULE_LIB;
static const QString INJECT_ENVIRONMENT;
static const QString INJECT_LOG;
static const QString INJECT_EMPTY;
static const QString INJECT_REQUIRE;
static const QString INJECT_TIMER_SET;
static const QString INJECT_TIMER_CLEAR;
static const QString INJECT_BRIDGE;
static const QString TEMPLATE_CONTEXT_CREATE;
static const QString TEMPLATE_MODULE;
static const QString TEMPLATE_CONTEXT_DESTROY;
static const QString GLOBAL_DORIC;
static const QString DORIC_TIMER_CALLBACK;
};
#endif // CONSTANT_H

View File

@@ -0,0 +1,27 @@
#ifndef COUNTDOWNLATCH_H
#define COUNTDOWNLATCH_H
#include <climits>
#include <QSemaphore>
class CountDownLatch {
Q_DISABLE_COPY(CountDownLatch)
QSemaphore m_sem{INT_MAX};
public:
CountDownLatch() {}
~CountDownLatch() {
m_sem.acquire(INT_MAX);
m_sem.release(INT_MAX);
}
class Locker {
CountDownLatch * sem;
public:
Locker(const Locker & other) : sem{other.sem} { sem->m_sem.acquire(); }
Locker(Locker && other) : sem{other.sem} { other.sem = nullptr; }
Locker(CountDownLatch * sem) : sem{sem} { sem->m_sem.acquire(); }
~Locker() { if (sem) sem->m_sem.release(); }
};
Locker lock() { return Locker{this}; }
};
#endif // COUNTDOWNLATCH_H

View File

@@ -0,0 +1,25 @@
#ifndef UTILS_H
#define UTILS_H
#include <QString>
#include <QResource>
#include <QFile>
#include <QTextStream>
class Utils
{
public:
static QString readAssetFile(QString preffix, QString assetName) {
QResource resource(":" + preffix + "/" + assetName);
QFile *file = new QFile(resource.fileName());
file->open(QFile::ReadOnly | QFile::Text);
QTextStream in(file);
QString content = in.readAll();
file->close();
delete file;
return content;
}
};
#endif // UTILS_H