2025-09-30 14:56:47 -04:00
|
|
|
#include "module_proxy.h"
|
2026-03-23 11:45:25 -04:00
|
|
|
#include "logos_provider_object.h"
|
2025-09-30 14:56:47 -04:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
2026-03-23 11:45:25 -04:00
|
|
|
ModuleProxy::ModuleProxy(LogosProviderObject* provider, QObject* parent)
|
2025-09-30 14:56:47 -04:00
|
|
|
: QObject(parent)
|
2026-03-23 11:45:25 -04:00
|
|
|
, m_provider(provider)
|
2025-09-30 14:56:47 -04:00
|
|
|
{
|
2026-03-23 11:45:25 -04:00
|
|
|
if (m_provider) {
|
|
|
|
|
m_provider->setEventListener([this](const QString& eventName, const QVariantList& data) {
|
|
|
|
|
qDebug() << "[LogosProviderObject] ModuleProxy: forwarding event" << eventName << "as Qt signal";
|
2026-05-25 14:35:25 +01:00
|
|
|
// Events may be fired from any thread (e.g. a module's worker/FFI
|
|
|
|
|
// thread), but this object is the QtRemoteObjects source and must be
|
|
|
|
|
// driven from its own thread. Emitting directly from a foreign
|
|
|
|
|
// thread runs QtRO's source serialization there, racing the source
|
|
|
|
|
// socket against a reply being sent from the source thread, which
|
|
|
|
|
// can silently drop the reply. AutoConnection keeps same-thread
|
|
|
|
|
// callers synchronous (the common case) and only queues the
|
|
|
|
|
// emission when it arrives from another thread, so events and
|
|
|
|
|
// replies stay serialized on the thread QtRO expects to own the
|
|
|
|
|
// source. Passing `this` as the context also cancels a queued
|
|
|
|
|
// emission if this object is destroyed first.
|
|
|
|
|
QMetaObject::invokeMethod(this, [this, eventName, data]() {
|
|
|
|
|
emit eventResponse(eventName, data);
|
|
|
|
|
}, Qt::AutoConnection);
|
2026-03-23 11:45:25 -04:00
|
|
|
});
|
|
|
|
|
qDebug() << "[LogosProviderObject] ModuleProxy: created, wrapping LogosProviderObject"
|
|
|
|
|
<< m_provider->providerName();
|
2025-09-30 14:56:47 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModuleProxy::~ModuleProxy()
|
|
|
|
|
{
|
2026-03-23 11:45:25 -04:00
|
|
|
qDebug() << "ModuleProxy: destroyed";
|
2025-09-30 14:56:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ModuleProxy::saveToken(const QString& from_module_name, const QString& token)
|
|
|
|
|
{
|
|
|
|
|
if (from_module_name.isEmpty()) {
|
|
|
|
|
qWarning() << "ModuleProxy: Cannot save token with empty module name";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (token.isEmpty()) {
|
|
|
|
|
qWarning() << "ModuleProxy: Cannot save empty token for module:" << from_module_name;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_tokens[from_module_name] = token;
|
2026-03-23 11:45:25 -04:00
|
|
|
qDebug() << "ModuleProxy: Token saved for module:" << from_module_name;
|
2025-09-30 14:56:47 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant ModuleProxy::callRemoteMethod(const QString& authToken, const QString& methodName, const QVariantList& args)
|
|
|
|
|
{
|
2026-03-23 11:45:25 -04:00
|
|
|
if (!m_provider) {
|
|
|
|
|
qWarning() << "ModuleProxy: Cannot call method on null provider:" << methodName;
|
2025-09-30 14:56:47 -04:00
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (methodName.isEmpty()) {
|
|
|
|
|
qWarning() << "ModuleProxy: Method name cannot be empty";
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-02 13:21:05 -05:00
|
|
|
if (methodName == "getPluginMethods" && args.isEmpty()) {
|
|
|
|
|
return QVariant(getPluginMethods());
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 11:45:25 -04:00
|
|
|
qDebug() << "ModuleProxy: callRemoteMethod" << methodName << "args:" << args;
|
|
|
|
|
return m_provider->callMethod(methodName, args);
|
2025-09-30 14:56:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ModuleProxy::informModuleToken(const QString& authToken, const QString& moduleName, const QString& token)
|
|
|
|
|
{
|
2026-03-23 11:45:25 -04:00
|
|
|
Q_UNUSED(authToken)
|
2025-09-30 14:56:47 -04:00
|
|
|
|
2026-03-23 11:45:25 -04:00
|
|
|
if (!m_provider) {
|
|
|
|
|
qWarning() << "ModuleProxy: Cannot inform token on null provider";
|
2025-09-30 14:56:47 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 11:45:25 -04:00
|
|
|
return m_provider->informModuleToken(moduleName, token);
|
2025-09-30 14:56:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QJsonArray ModuleProxy::getPluginMethods()
|
|
|
|
|
{
|
2026-03-23 11:45:25 -04:00
|
|
|
if (!m_provider) return QJsonArray();
|
2025-09-30 14:56:47 -04:00
|
|
|
|
2026-03-23 11:45:25 -04:00
|
|
|
qDebug() << "[LogosProviderObject] ModuleProxy: calling LogosProviderObject::getMethods()";
|
|
|
|
|
return m_provider->getMethods();
|
2025-09-30 14:56:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "moc_module_proxy.cpp"
|