mirror of
https://github.com/logos-storage/logos-storage-app-skeleton.git
synced 2026-06-14 04:19:25 +00:00
Add to git
This commit is contained in:
parent
ded914c440
commit
d796ddf72a
97
plugin/src/StorageBackend.cpp
Normal file
97
plugin/src/StorageBackend.cpp
Normal 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);
|
||||
}
|
||||
48
plugin/src/StorageBackend.h
Normal file
48
plugin/src/StorageBackend.h
Normal 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;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user