mirror of
https://github.com/logos-co/logos-protocol.git
synced 2026-08-27 12:01:15 +00:00
* 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.
86 lines
1.7 KiB
C++
86 lines
1.7 KiB
C++
#include "token_manager.h"
|
|
#include <QMutexLocker>
|
|
|
|
TokenManager& TokenManager::instance()
|
|
{
|
|
static TokenManager instance;
|
|
return instance;
|
|
}
|
|
|
|
TokenManager::TokenManager(QObject *parent)
|
|
: QObject(parent)
|
|
{
|
|
}
|
|
|
|
TokenManager::~TokenManager()
|
|
{
|
|
}
|
|
|
|
void TokenManager::saveToken(const QString& key, const QString& token)
|
|
{
|
|
QMutexLocker locker(&m_mutex);
|
|
m_tokens[key] = token;
|
|
emit tokenSaved(key);
|
|
}
|
|
|
|
void TokenManager::saveToken(const std::string& key, const std::string& token)
|
|
{
|
|
saveToken(QString::fromStdString(key), QString::fromStdString(token));
|
|
}
|
|
|
|
QString TokenManager::getToken(const QString& key) const
|
|
{
|
|
QMutexLocker locker(&m_mutex);
|
|
return m_tokens.value(key, QString());
|
|
}
|
|
|
|
std::string TokenManager::getToken(const std::string& key) const
|
|
{
|
|
return getToken(QString::fromStdString(key)).toStdString();
|
|
}
|
|
|
|
bool TokenManager::hasToken(const QString& key) const
|
|
{
|
|
QMutexLocker locker(&m_mutex);
|
|
return m_tokens.contains(key);
|
|
}
|
|
|
|
bool TokenManager::hasToken(const std::string& key) const
|
|
{
|
|
return hasToken(QString::fromStdString(key));
|
|
}
|
|
|
|
bool TokenManager::removeToken(const QString& key)
|
|
{
|
|
QMutexLocker locker(&m_mutex);
|
|
if (m_tokens.contains(key)) {
|
|
m_tokens.remove(key);
|
|
emit tokenRemoved(key);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TokenManager::removeToken(const std::string& key)
|
|
{
|
|
return removeToken(QString::fromStdString(key));
|
|
}
|
|
|
|
void TokenManager::clearAllTokens()
|
|
{
|
|
QMutexLocker locker(&m_mutex);
|
|
m_tokens.clear();
|
|
emit allTokensCleared();
|
|
}
|
|
|
|
QList<QString> TokenManager::getTokenKeys() const
|
|
{
|
|
QMutexLocker locker(&m_mutex);
|
|
return m_tokens.keys();
|
|
}
|
|
|
|
int TokenManager::tokenCount() const
|
|
{
|
|
QMutexLocker locker(&m_mutex);
|
|
return m_tokens.size();
|
|
}
|