Files
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

102 lines
2.8 KiB
C++

#ifndef LOGOS_MODE_H
#define LOGOS_MODE_H
#include <QDebug>
/**
* @brief LogosMode defines the communication mode for the SDK
*
* - Remote: Uses QRemoteObjects for inter-process communication (desktop apps)
* - Local: Uses in-process PluginRegistry (mobile apps, single process)
* - Mock: Uses in-memory mock transport for unit testing
*/
enum class LogosMode {
Remote, // Default: Use QRemoteObjects (IPC)
Local, // Use in-process PluginRegistry
Mock // Use in-memory mock transport for unit testing
};
/**
* @brief Timeout provides a strongly-typed wrapper for timeout values
*
* This prevents implicit conversion from int, avoiding ambiguity with
* QVariant parameters in method overloads.
*
* Example usage:
* invokeRemoteMethod("module", "method", arg1, arg2, Timeout(5000));
*/
struct Timeout {
int ms;
explicit Timeout(int milliseconds = 20000) : ms(milliseconds) {}
};
/**
* @brief LogosModeConfig provides global mode configuration
*
* Set the mode once at application startup before creating any LogosAPI instances.
*
* Example usage:
* LogosModeConfig::setMode(LogosMode::Local); // For mobile apps
* LogosAPI api("my_module"); // Will use local mode
*/
namespace LogosModeConfig {
/**
* @brief Get the current mode (internal storage)
* @return Reference to the static mode variable
*/
inline LogosMode& modeStorage() {
static LogosMode mode = LogosMode::Remote; // Default to Remote
return mode;
}
/**
* @brief Set the SDK communication mode
* @param mode The mode to use (Remote or Local)
*
* Call this before creating any LogosAPI instances.
*/
inline void setMode(LogosMode mode) {
modeStorage() = mode;
QString modeName = (mode == LogosMode::Local) ? "Local"
: (mode == LogosMode::Mock) ? "Mock"
: "Remote";
qDebug() << "LogosModeConfig: Mode set to" << modeName;
}
/**
* @brief Get the current SDK communication mode
* @return The current mode
*/
inline LogosMode getMode() {
return modeStorage();
}
/**
* @brief Check if the SDK is in Local mode
* @return true if Local mode, false if Remote mode
*/
inline bool isLocal() {
return modeStorage() == LogosMode::Local;
}
/**
* @brief Check if the SDK is in Remote mode
* @return true if Remote mode, false if Local mode
*/
inline bool isRemote() {
return modeStorage() == LogosMode::Remote;
}
/**
* @brief Check if the SDK is in Mock mode
* @return true if Mock mode, false otherwise
*/
inline bool isMock() {
return modeStorage() == LogosMode::Mock;
}
}
#endif // LOGOS_MODE_H