Add to git

This commit is contained in:
Arnaud 2026-01-26 12:26:52 +04:00
parent ded914c440
commit d796ddf72a
No known key found for this signature in database
GPG Key ID: 20E40A5D3110766F
2 changed files with 145 additions and 0 deletions

View File

@ -0,0 +1,97 @@
#include "StorageBackend.h"
#include <QDebug>
#include <QDateTime>
#include <QLocale>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
StorageBackend::StorageBackend(LogosAPI* logosAPI, QObject* parent)
: QObject(parent),
m_status(NotStarted),
m_logosAPI(nullptr),
m_logos(nullptr)
{
qDebug() << "Initializing StorageBackend...";
if (logosAPI) {
m_logosAPI = logosAPI;
} else {
m_logosAPI = new LogosAPI("core", this);
}
m_logos = new LogosModules(m_logosAPI);
}
StorageBackend::~StorageBackend()
{
stopStorage();
}
void StorageBackend::setStatus(StorageStatus newStatus)
{
if (m_status != newStatus) {
m_status = newStatus;
emit statusChanged();
qDebug() << "StorageBackend: Status changed to" << m_status;
}
}
void StorageBackend::startStorage()
{
setStatus(Starting);
auto& storageModule = m_logos->storage_module;
QString configStr = R"({
})";
if (!storageModule.initStorage(configStr)) {
setStatus(Error);
return;
}
// Subscribe to connectedPeersResponse events
// if (!storageModule.on("connectedPeersResponse", [this](const QVariantList& data) {
// if (data.size() < 1) {
// qWarning() << "StorageBackend: connectedPeersResponse payload missing fields";
// return;
// }
// onConnectedPeersResponse(data);
// })) {
// qWarning() << "StorageBackend: failed to subscribe to connectedPeersResponse events";
// }
if (!storageModule.startStorage()) {
setStatus(Error);
return;
}
setStatus(Running);
// Refresh peers and metrics after a delay to allow Storage to fully start
// QTimer::singleShot(1000, this, [this]() {
// refreshPeers();
// refreshMetrics();
// });
}
void StorageBackend::stopStorage()
{
if (m_status != Running && m_status != Starting) {
return;
}
setStatus(Stopping);
auto& storageModule = m_logos->storage_module;
if (!storageModule.stopStorage()) {
qWarning() << "StorageBackend::stopStorage: stopStorage() returned false";
setStatus(Error);
return;
}
setStatus(Stopped);
}

View File

@ -0,0 +1,48 @@
#pragma once
#include <QObject>
#include <QString>
#include <QStringList>
#include <QTimer>
#include "logos_api.h"
#include "logos_api_client.h"
#include "logos_sdk.h"
class StorageBackend : public QObject {
Q_OBJECT
public:
enum StorageStatus {
NotStarted = 0,
Starting,
Running,
Stopping,
Stopped,
Error
};
Q_ENUM(StorageStatus)
Q_PROPERTY(StorageStatus status READ status NOTIFY statusChanged)
explicit StorageBackend(LogosAPI* logosAPI = nullptr, QObject* parent = nullptr);
~StorageBackend();
StorageStatus status() const { return m_status; }
public slots:
Q_INVOKABLE void startStorage();
Q_INVOKABLE void stopStorage();
signals:
void statusChanged();
private slots:
// void onConnectedPeersResponse(const QVariantList& data);
private:
void setStatus(StorageStatus newStatus);
StorageStatus m_status;
LogosAPI* m_logosAPI;
LogosModules* m_logos;
};