mirror of
https://github.com/logos-co/logos-cpp-sdk.git
synced 2026-08-31 01:31:10 +00:00
support non-local remote transports (#57)
* support non-local remote transports * fix LogosResult * allow getting client over specific transport * fix ssl * investiage ssl error * pr comments * allow transport set configuration on any module * pr comments * add docs * pr comments * propagate only non-qt dependencies * restore ABI compatibility
This commit is contained in:
@@ -10,19 +10,51 @@
|
||||
#include <QDebug>
|
||||
#include <string>
|
||||
|
||||
LogosAPIProvider::LogosAPIProvider(const QString& module_name, QObject *parent)
|
||||
LogosAPIProvider::LogosAPIProvider(const QString& module_name,
|
||||
LogosTransportSet transports,
|
||||
QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_registryUrl(LogosInstance::id(module_name))
|
||||
, m_moduleProxy(nullptr)
|
||||
, m_qtProviderObject(nullptr)
|
||||
{
|
||||
m_transport = LogosTransportFactory::createHost(m_registryUrl);
|
||||
// Helper: defer-construct one host and only retain it if the
|
||||
// factory actually returned something. createHost() can return
|
||||
// nullptr — e.g. PlainTransportHost::start() failure (TCP bind,
|
||||
// SSL cert load) — and we don't want to leave a null entry that
|
||||
// would crash the publish/unpublish paths later.
|
||||
auto pushHost = [&](auto&& host, const char* label) {
|
||||
if (host) {
|
||||
m_transports.push_back(std::forward<decltype(host)>(host));
|
||||
} else {
|
||||
qWarning() << "LogosAPIProvider: createHost returned null"
|
||||
<< "for" << module_name << label
|
||||
<< "— transport disabled";
|
||||
}
|
||||
};
|
||||
|
||||
if (transports.empty()) {
|
||||
// Back-compat: one host, chosen by the global mode + transport config.
|
||||
pushHost(LogosTransportFactory::createHost(m_registryUrl), "(default)");
|
||||
} else {
|
||||
// One host per configured transport — lets a single provider serve
|
||||
// its object on several endpoints simultaneously (local-socket +
|
||||
// TCP, TCP + TCP+SSL, etc.).
|
||||
for (const auto& cfg : transports)
|
||||
pushHost(LogosTransportFactory::createHost(cfg, m_registryUrl), "(per-cfg)");
|
||||
}
|
||||
}
|
||||
|
||||
LogosAPIProvider::~LogosAPIProvider()
|
||||
{
|
||||
if (!m_registeredObjectName.isEmpty()) {
|
||||
m_transport->unpublishObject(m_registeredObjectName);
|
||||
// Defensive: m_transports should never contain nullptr (the
|
||||
// ctor filters them out via pushHost), but guard here too —
|
||||
// a future code path that pushes directly without going
|
||||
// through pushHost would otherwise crash on shutdown.
|
||||
for (auto& t : m_transports) {
|
||||
if (t) t->unpublishObject(m_registeredObjectName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +130,13 @@ bool LogosAPIProvider::publishProvider(const QString& name, LogosProviderObject*
|
||||
{
|
||||
m_moduleProxy = new ModuleProxy(provider, this);
|
||||
|
||||
bool success = m_transport->publishObject(name, m_moduleProxy);
|
||||
// Publish on every configured transport. Success = any transport
|
||||
// accepted the publish (follow-up: surface per-transport failures).
|
||||
bool success = false;
|
||||
for (auto& t : m_transports) {
|
||||
if (!t) continue; // see ~LogosAPIProvider — defensive null-skip.
|
||||
if (t->publishObject(name, m_moduleProxy)) success = true;
|
||||
}
|
||||
if (success) {
|
||||
m_registeredObjectName = name;
|
||||
qDebug() << "[LogosProviderObject] LogosAPIProvider: successfully published" << name;
|
||||
|
||||
Reference in New Issue
Block a user