mirror of
https://github.com/logos-co/logos-plugin-qt.git
synced 2026-08-27 08:51:07 +00:00
This repo was the Qt plugin BUILD backend — pure Nix functions plus a CMake
module, with no C++ target at all. But the two things a Qt host actually needs
at runtime lived in logos-qt-sdk, where they are neither a language wrapper over
the protocol C API nor codegen:
LogosAPI / LogosAPIProvider owns a LogosTransportHost per transport,
constructs ModuleProxy / ModuleHandshakeProxy,
publishes the handshake surface, seeds trust
anchors, injects the token validator
LogosProviderBase the base every generated provider derives
PluginInterface the Qt plugin loading contract
the cdylib->Qt glue generator the emitter that wraps a language-neutral
cdylib in a Qt plugin
They move here, so "swap the plugin technology" is a one-repo change.
ADDITIVE: the sources are COPIED and logos-qt-sdk is untouched. Removing them
there now would turn nine downstream masters red at once; that comes later,
after consumers are repointed.
qt_provider_object (and logos_qt_arg_decode, which its QMetaObject dispatch
needs) is carried deliberately even though it is legacy: logos_api_provider
falls back to wrapping a plain QObject in it, and the modules that rely on that
have not been migrated yet. It goes once they are.
The generator links Qt Core and logos-lidl only — never logos-cpp-sdk. It needed
exactly one helper from that SDK's shared frontend, lidlToPascalCase (~12
lines), which is inlined instead, the same way logos-view-module does it. It
also REFUSES `--backend <anything but cdylib>` rather than ignoring the flag:
callers are migrating from a tool where --backend was required and dispatched
on, so silently treating `--backend qt` as cdylib would emit confidently wrong
artifacts with a zero exit.
`rawLib`, `lib` and `cmake-module` deliberately do not reference the new
derivations, so a consumer that only wants the Nix build functions never
realises a Qt/protocol build. Proven, not assumed: with both new inputs
overridden to a bogus flake, cmake-module and rawLib still evaluate while
logos-qt-host fails — so the override bites and the cheap outputs really never
touch it.
Behaviour preservation is the whole claim of a relocation, so it is measured:
the emitted glue is BYTE-IDENTICAL to logos-qt-generator --backend cdylib over
every one of the 20 .lidl contracts in the workspace, in both single and
concurrency:multi mode (40 pairs, exit codes included), and single vs multi do
differ from each other, so both code paths were really exercised. The built
liblogos_qt_host.a is byte-identical to liblogos_qt_sdk.a, exporting the same
390 symbols.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
119 lines
4.3 KiB
C++
119 lines
4.3 KiB
C++
#include "logos_api.h"
|
|
#include "logos_api_client.h"
|
|
#include "logos_api_provider.h"
|
|
#include "logos_thread_marshal.h"
|
|
#include "token_manager.h"
|
|
#include <QVariant>
|
|
#include <string>
|
|
|
|
LogosAPI::LogosAPI(const QString& module_name, QObject *parent)
|
|
: LogosAPI(module_name, LogosTransportSet{}, parent)
|
|
{
|
|
}
|
|
|
|
LogosAPI::LogosAPI(const QString& module_name,
|
|
LogosTransportSet transports,
|
|
QObject *parent)
|
|
: QObject(parent)
|
|
, m_module_name(module_name)
|
|
, m_provider(nullptr)
|
|
, m_token_manager(nullptr)
|
|
{
|
|
m_provider = new LogosAPIProvider(m_module_name, std::move(transports), this);
|
|
m_token_manager = &TokenManager::instance();
|
|
qRegisterMetaType<LogosResult>("LogosResult");
|
|
}
|
|
|
|
LogosAPI::LogosAPI(const std::string& module_name, QObject *parent)
|
|
: LogosAPI(QString::fromStdString(module_name), parent)
|
|
{
|
|
}
|
|
|
|
LogosAPI::~LogosAPI()
|
|
{
|
|
// Provider and client will be automatically deleted as child objects
|
|
// Token manager is a singleton, so we don't delete it
|
|
|
|
|
|
}
|
|
|
|
LogosAPIProvider* LogosAPI::getProvider() const
|
|
{
|
|
return m_provider;
|
|
}
|
|
|
|
LogosAPIClient* LogosAPI::getClient(const QString& target_module) const
|
|
{
|
|
// The no-transport overload is just shorthand for "use the
|
|
// process-global default" — the explicit-transport overload below
|
|
// is the single resolution path. Mode-awareness lives in the
|
|
// factory, so this delegation preserves Mock/Local semantics.
|
|
return getClient(target_module, LogosTransportConfigGlobal::getDefault());
|
|
}
|
|
|
|
LogosAPIClient* LogosAPI::getClient(const std::string& target_module) const
|
|
{
|
|
return getClient(QString::fromStdString(target_module));
|
|
}
|
|
|
|
LogosAPIClient* LogosAPI::getClient(const QString& target_module,
|
|
const LogosTransportConfig& transport) const
|
|
{
|
|
// Create the client (and its consumers + transport replicas) on this
|
|
// LogosAPI's owner thread — the module's main/event-loop thread — even when
|
|
// called from a worker thread (e.g. an HTTP handler). Qt Remote Objects
|
|
// replicas only work on the thread that created them, so construction (and
|
|
// the cache it populates) must happen there. invokeRemoteMethod() then
|
|
// marshals calls back to the same thread. See logos_thread_marshal.h.
|
|
return logos::runOnOwnerThread(const_cast<LogosAPI*>(this),
|
|
[&]() -> LogosAPIClient* {
|
|
// Single cache, single construction path. Key composition mirrors
|
|
// the factory's resolution rule (see LogosAPIClientCacheKey in
|
|
// logos_api.h):
|
|
// - Mock/Local mode: every cfg collapses to one cache slot per
|
|
// target — switching cfg returns the same MockTransport-backed
|
|
// client instead of allocating a duplicate.
|
|
// - Remote mode: every distinguishing field of cfg matters, so
|
|
// two callers with different TLS/codec settings get separate
|
|
// clients (no risk of silently reusing an insecure transport).
|
|
//
|
|
// The capability_module transport — used by the client's
|
|
// auto-`requestModule` flow — falls back to the registered
|
|
// override (if any) or the global default. Two-arg getClient
|
|
// intentionally doesn't expose a second transport here; callers
|
|
// that care register the capability_module transport once via
|
|
// setCapabilityModuleTransport() and the rest is plumbing.
|
|
const LogosAPIClientCacheKey key{
|
|
target_module, LogosModeConfig::getMode(), transport};
|
|
auto it = m_clients.constFind(key);
|
|
if (it != m_clients.constEnd()) return it.value();
|
|
|
|
const LogosTransportConfig capabilityTransport =
|
|
m_capabilityModuleTransport.has_value()
|
|
? *m_capabilityModuleTransport
|
|
: LogosTransportConfigGlobal::getDefault();
|
|
|
|
LogosAPIClient* client = new LogosAPIClient(
|
|
target_module, m_module_name, m_token_manager,
|
|
transport, capabilityTransport,
|
|
const_cast<LogosAPI*>(this));
|
|
m_clients.insert(key, client);
|
|
return client;
|
|
});
|
|
}
|
|
|
|
TokenManager* LogosAPI::getTokenManager() const
|
|
{
|
|
return m_token_manager;
|
|
}
|
|
|
|
void LogosAPI::setCapabilityModuleTransport(const LogosTransportConfig& transport)
|
|
{
|
|
m_capabilityModuleTransport = transport;
|
|
}
|
|
|
|
bool LogosAPI::setProperty(const char* name, const std::string& value)
|
|
{
|
|
return QObject::setProperty(name, QVariant(QString::fromStdString(value)));
|
|
}
|