2019-12-14 11:30:12 +08:00
|
|
|
#include <QDebug>
|
|
|
|
|
2019-12-06 19:47:59 +08:00
|
|
|
#include "stdarg.h"
|
|
|
|
|
2019-12-04 15:51:46 +08:00
|
|
|
#include "native_driver.h"
|
2019-12-06 19:47:59 +08:00
|
|
|
#include "utility/utility.h"
|
2019-12-04 15:51:46 +08:00
|
|
|
|
2019-12-14 10:04:17 +08:00
|
|
|
NativeDriver::NativeDriver() {
|
|
|
|
qDebug() << "NativeDriver constructor";
|
|
|
|
}
|
|
|
|
|
2019-12-04 15:51:46 +08:00
|
|
|
NativeDriver::~NativeDriver() {
|
|
|
|
qDebug() << "NativeDriver destructor";
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeDriver::createContext(int contextId, QString *script) {
|
|
|
|
jsEngine->prepareContext(contextId, script);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeDriver::destroyContext(int contextId) {
|
|
|
|
jsEngine->destroyContext(contextId);
|
|
|
|
}
|
2019-12-04 16:44:30 +08:00
|
|
|
|
2019-12-13 17:48:37 +08:00
|
|
|
void NativeDriver::invokeContextEntityMethod(int contextId, QString *method, ...) {
|
|
|
|
QJSValueList *arguments = new QJSValueList();
|
2019-12-06 19:47:59 +08:00
|
|
|
arguments->append(QJSValue(QString::number(contextId)));
|
|
|
|
arguments->append(QJSValue(*method));
|
|
|
|
|
|
|
|
va_list vaList;
|
|
|
|
va_start(vaList, method);
|
|
|
|
auto argument = va_arg(vaList, QVariant*);
|
|
|
|
while (argument != nullptr) {
|
|
|
|
if (QString(typeid(QJsonObject).name()).contains(QString(argument->typeName()))) {
|
2019-12-13 17:48:37 +08:00
|
|
|
QJsonObject *jsonObject = static_cast<QJsonObject*>(argument->data());
|
|
|
|
QJsonValue *jsonValue = new QJsonValue(*jsonObject);
|
2019-12-06 19:47:59 +08:00
|
|
|
QJSValue jsValue = Utility::convert(jsEngine->engine, *jsonValue);
|
|
|
|
delete jsonValue;
|
|
|
|
arguments->append(jsValue);
|
|
|
|
}
|
|
|
|
argument = va_arg(vaList, QVariant*);
|
|
|
|
}
|
|
|
|
va_end(vaList);
|
|
|
|
|
|
|
|
QJSValue result = jsEngine->engine->globalObject()
|
|
|
|
.property(Constant::GLOBAL_DORIC)
|
|
|
|
.property(Constant::DORIC_CONTEXT_INVOKE)
|
|
|
|
.call(*arguments);
|
2019-12-12 16:10:01 +08:00
|
|
|
qDebug() << "invokeContextEntityMethod: " + result.toString();
|
2019-12-06 19:47:59 +08:00
|
|
|
delete arguments;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeDriver::invokeDoricMethod(QString *method, ...) {
|
2019-12-04 16:44:30 +08:00
|
|
|
|
|
|
|
}
|
2019-12-14 11:30:12 +08:00
|
|
|
|
|
|
|
Registry* NativeDriver::getRegistry() {
|
|
|
|
return jsEngine->registry;
|
|
|
|
}
|