mirror of
https://github.com/logos-co/logos-cpp-sdk.git
synced 2026-08-31 09:41:06 +00:00
* refactor: abstract connection/transport; and clearly separate qt remote obj and qt local into separate implementations * abstract qt remote registry * add mock implementation; these serves to further test the abstraction but also useful for testing modules later * use LogosObject instead of QObject * abstract provider side * updates to use new api * re-add async api back --------- Co-authored-by: Logos Workspace <logos@workspace.local>
102 lines
2.8 KiB
C++
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
|