This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-Qt/example/doric/engine/DoricBridgeExtension.cpp

35 lines
1.2 KiB
C++
Raw Normal View History

2021-02-04 16:59:58 +08:00
#include <QDebug>
2021-04-02 17:23:36 +08:00
#include <QJsonDocument>
#include <QJsonObject>
2021-02-04 16:59:58 +08:00
#include <QMetaObject>
#include "../DoricContextManager.h"
#include "DoricBridgeExtension.h"
DoricBridgeExtension::DoricBridgeExtension(QObject *parent) : QObject(parent) {}
void DoricBridgeExtension::callNative(QString contextId, QString module,
QString methodName, QString callbackId,
2021-04-02 17:23:36 +08:00
QString argument) {
2021-04-26 22:11:56 +08:00
qDebug() << "contextId: " + contextId << "module: " + module
<< "methodName: " + methodName << "callbackId: " + callbackId
<< "jsValue: " + argument;
2021-02-04 16:59:58 +08:00
DoricContext *context =
DoricContextManager::getInstance()->getContext(contextId);
2021-04-26 22:11:56 +08:00
if (context == nullptr) {
qCritical() << "cannot find context: " + contextId;
return;
}
2021-02-04 16:59:58 +08:00
bool classRegistered =
context->getDriver()->getRegistry()->acquirePluginInfo(module);
if (classRegistered) {
QObject *plugin = context->obtainPlugin(module);
2021-04-02 15:16:18 +08:00
QMetaObject::invokeMethod(plugin, methodName.toUtf8(), Qt::DirectConnection,
QGenericReturnArgument(),
2021-04-06 17:58:23 +08:00
Q_ARG(QString, argument),
2021-02-04 16:59:58 +08:00
Q_ARG(QString, callbackId));
}
}