2021-02-04 16:59:58 +08:00
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
#include "DoricNativeDriver.h"
|
|
|
|
#include "async/DoricAsyncCall.h"
|
|
|
|
#include "utils/DoricConstant.h"
|
|
|
|
|
|
|
|
void DoricNativeDriver::invokeContextEntityMethod(QString contextId,
|
|
|
|
QString method,
|
|
|
|
QVariantList args) {
|
|
|
|
args.insert(0, QVariant(contextId));
|
|
|
|
args.insert(1, QVariant(method));
|
|
|
|
invokeDoricMethod(DoricConstant::DORIC_CONTEXT_INVOKE, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricNativeDriver::invokeDoricMethod(QString method, QVariantList args) {
|
|
|
|
return DoricAsyncCall::ensureRunInThreadPool(
|
|
|
|
&jsEngine.mJSThreadPool, [this, method, args] {
|
2021-04-02 17:23:36 +08:00
|
|
|
this->jsEngine.invokeDoricMethod(method, args);
|
2021-02-04 16:59:58 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-08 11:37:51 +08:00
|
|
|
DoricAsyncResult *DoricNativeDriver::asyncCall(std::function<void()> lambda,
|
2021-02-07 11:21:53 +08:00
|
|
|
DoricThreadMode mode) {
|
2021-02-08 11:37:51 +08:00
|
|
|
switch (mode) {
|
|
|
|
case UI:
|
2021-02-09 10:38:27 +08:00
|
|
|
DoricAsyncCall::ensureRunInMain(lambda);
|
2021-02-08 11:37:51 +08:00
|
|
|
break;
|
|
|
|
case JS:
|
|
|
|
DoricAsyncCall::ensureRunInThreadPool(&jsEngine.mJSThreadPool, lambda);
|
|
|
|
break;
|
|
|
|
}
|
2021-02-07 11:21:53 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-02-04 16:59:58 +08:00
|
|
|
void DoricNativeDriver::createContext(QString contextId, QString script,
|
|
|
|
QString source) {
|
|
|
|
DoricAsyncCall::ensureRunInThreadPool(
|
|
|
|
&jsEngine.mJSThreadPool, [this, contextId, script, source] {
|
|
|
|
this->jsEngine.prepareContext(contextId, script, source);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricNativeDriver::destroyContext(QString contextId) {}
|
|
|
|
|
|
|
|
DoricRegistry *DoricNativeDriver::getRegistry() {
|
|
|
|
return this->jsEngine.getRegistry();
|
|
|
|
}
|