From d796ddf72aec611da38bb7717511653a458cdd89 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 26 Jan 2026 12:26:52 +0400 Subject: [PATCH] Add to git --- plugin/src/StorageBackend.cpp | 97 +++++++++++++++++++++++++++++++++++ plugin/src/StorageBackend.h | 48 +++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 plugin/src/StorageBackend.cpp create mode 100644 plugin/src/StorageBackend.h diff --git a/plugin/src/StorageBackend.cpp b/plugin/src/StorageBackend.cpp new file mode 100644 index 0000000..02927b2 --- /dev/null +++ b/plugin/src/StorageBackend.cpp @@ -0,0 +1,97 @@ +#include "StorageBackend.h" +#include +#include +#include +#include +#include +#include + +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); +} diff --git a/plugin/src/StorageBackend.h b/plugin/src/StorageBackend.h new file mode 100644 index 0000000..a7fa226 --- /dev/null +++ b/plugin/src/StorageBackend.h @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include +#include +#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; +}; \ No newline at end of file