refactor
This commit is contained in:
37
doric-Qt/doric/utils/constant.cpp
Normal file
37
doric-Qt/doric/utils/constant.cpp
Normal 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";
|
30
doric-Qt/doric/utils/constant.h
Normal file
30
doric-Qt/doric/utils/constant.h
Normal 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
|
27
doric-Qt/doric/utils/count_down_latch.h
Normal file
27
doric-Qt/doric/utils/count_down_latch.h
Normal 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
|
25
doric-Qt/doric/utils/utils.h
Normal file
25
doric-Qt/doric/utils/utils.h
Normal 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
|
Reference in New Issue
Block a user