Files
logos-protocol/cpp/implementations/mock/mock_transport.h
Dario Lipicar 29afbac532 Extract the Logos protocol layer from logos-cpp-sdk (lp_* C ABI + protocol semver) (#2)
* Extract the Logos protocol layer from logos-cpp-sdk

Transports (plain TCP/TLS, qt_local, qt_remote/QRO, mock), token manager,
consumer core (LogosAPIClient/LogosAPIConsumer incl. the capability
auto-requestModule flow), ModuleProxy, the abstract LogosProviderObject
interface, and the canonical QVariant<->JSON conversion — now behind the
language-neutral lp_* C ABI (logos_protocol.h) carrying the protocol
semver (LOGOS_PROTOCOL_VERSION_*, lp_protocol_version()).

Bytes crossing the ABI use the lossless {"_bytes": base64url} tagging
(NUL-safe), matching the plain wire encoding.

Provider lp_* surface is compiled groundwork; serving lands with module
authoring.

* consumer: typed requestModule for the capability flow

Port of logos-cpp-sdk master f5a127dd ('use updated capability module',
cpp-sdk#85, Iuri Matias) — the touched files (logos_api_client.cpp,
logos_api_consumer.{h,cpp}) moved into this repo in the P1 extraction.
The capability auto-requestModule path now calls a typed std::string
helper on the consumer (which acquires the capability object directly)
instead of a stringly invokeRemoteMethod round-trip. 111/111 tests.
2026-06-12 18:59:01 -03:00

99 lines
3.0 KiB
C++

#ifndef MOCK_TRANSPORT_H
#define MOCK_TRANSPORT_H
#include "../../logos_transport.h"
#include "../../logos_object.h"
#include "mock_store.h"
#include <QString>
#include <QList>
#include <QTimer>
/**
* @brief LogosObject implementation for mock mode.
*
* Stores the module name and delegates callMethod to MockStore.
* Event operations are no-ops in mock mode.
*/
class MockLogosObject : public LogosObject {
public:
explicit MockLogosObject(const QString& moduleName)
: m_moduleName(moduleName) {}
const QString& moduleName() const { return m_moduleName; }
QVariant callMethod(const QString& /*authToken*/,
const QString& methodName,
const QVariantList& args,
int /*timeoutMs*/) override
{
return MockStore::instance().recordAndReturn(m_moduleName, methodName, args);
}
void callMethodAsync(const QString& /*authToken*/,
const QString& methodName,
const QVariantList& args,
int /*timeoutMs*/,
AsyncResultCallback callback) override
{
if (!callback) return;
QString mod = m_moduleName;
QTimer::singleShot(0, [mod, methodName, args, callback]() {
QVariant result = MockStore::instance().recordAndReturn(mod, methodName, args);
callback(result);
});
}
bool informModuleToken(const QString& /*authToken*/,
const QString& moduleName,
const QString& /*token*/,
int /*timeoutMs*/) override
{
Q_UNUSED(moduleName)
return true;
}
void onEvent(const QString& /*eventName*/, EventCallback /*callback*/) override {}
void disconnectEvents() override {}
void emitEvent(const QString& /*eventName*/, const QVariantList& /*data*/) override {}
QJsonArray getMethods() override { return QJsonArray(); }
void release() override
{
MockStore::instance().incrementMockObjectReleaseProbeIfSet();
delete this;
}
quintptr id() const override { return reinterpret_cast<quintptr>(this); }
private:
QString m_moduleName;
};
/**
* @brief No-op provider-side transport for mock mode.
*
* publishObject / unpublishObject succeed silently; there is no real
* IPC endpoint and no object needs to be made available.
*/
class MockTransportHost : public LogosTransportHost {
public:
bool publishObject(const QString& name, QObject* object) override;
void unpublishObject(const QString& name) override;
};
/**
* @brief Consumer-side transport for mock mode.
*
* requestObject returns a MockLogosObject tagged with the module name.
*/
class MockTransportConnection : public LogosTransportConnection {
public:
bool connectToHost() override;
bool isConnected() const override;
bool reconnect() override;
LogosObject* requestObject(const QString& objectName, int timeoutMs) override;
};
#endif // MOCK_TRANSPORT_H