logos-storage-app-skeleton/src/StorageBackend.h

88 lines
2.5 KiB
C
Raw Normal View History

2026-01-30 21:15:18 +04:00
#pragma once
#include "logos_api.h"
#include "logos_sdk.h"
#include <QObject>
#include <QString>
#include <QStringList>
#include <QTimer>
#include <QtQml/qqml.h>
static const int RET_OK = 0;
2026-02-10 13:27:11 +04:00
static const int RET_PROGRESS = 3;
2026-01-30 21:15:18 +04:00
class StorageBackend : public QObject {
Q_OBJECT
QML_ELEMENT
2026-02-10 13:27:11 +04:00
Q_PROPERTY(QString debugLogs READ debugLogs NOTIFY debugLogsChanged)
2026-02-13 20:16:27 +04:00
Q_PROPERTY(StorageStatus status READ status NOTIFY statusChanged)
Q_PROPERTY(QString cid READ cid NOTIFY cidChanged)
Q_PROPERTY(QString configJson READ configJson NOTIFY configJsonChanged)
2026-02-15 20:14:44 +04:00
Q_PROPERTY(int uploadProgress READ uploadProgress NOTIFY uploadProgressChanged)
Q_PROPERTY(QString uploadStatus READ uploadStatus NOTIFY uploadStatusChanged)
2026-01-30 21:15:18 +04:00
public:
enum StorageStatus { Stopped = 0, Starting, Running, Stopping, Destroyed };
Q_ENUM(StorageStatus)
2026-02-13 20:16:27 +04:00
QString cid() const;
2026-02-10 13:27:11 +04:00
QString debugLogs() const;
2026-02-13 20:16:27 +04:00
StorageStatus status() const;
QString configJson() const;
2026-02-15 20:14:44 +04:00
int uploadProgress() const;
QString uploadStatus() const;
2026-01-30 21:15:18 +04:00
explicit StorageBackend(LogosAPI* logosAPI = nullptr, QObject* parent = nullptr);
~StorageBackend();
public slots:
2026-02-13 20:16:27 +04:00
LogosResult start(const QString& configJson = "");
2026-01-30 21:15:18 +04:00
void destroy();
void stop();
2026-02-13 20:16:27 +04:00
void tryPeerConnect(const QString& peerId);
2026-02-10 13:27:11 +04:00
void tryDebug();
void tryUpload();
void tryUploadFinalize();
void exists(const QString& cid);
void remove(const QString& cid);
void fetch(const QString& cid);
void tryUploadFile(const QUrl& url);
void tryDownloadFile(const QString& cid, const QUrl& url);
void dataDir();
void version();
void spr();
void showPeerId();
void downloadManifest(const QString& cid);
void downloadManifests();
void space();
2026-02-13 20:16:27 +04:00
LogosResult init(const QString& configJson);
2026-02-10 13:27:11 +04:00
void updateLogLevel(const QString& logLevel);
2026-01-30 21:15:18 +04:00
signals:
void statusChanged();
2026-02-10 13:27:11 +04:00
void debugLogsChanged();
2026-01-30 21:15:18 +04:00
void stopped();
2026-02-13 20:16:27 +04:00
void cidChanged();
void configJsonChanged();
2026-02-15 20:14:44 +04:00
void uploadProgressChanged();
void uploadStatusChanged();
2026-01-30 21:15:18 +04:00
private slots:
private:
2026-02-13 20:16:27 +04:00
void setStatus(StorageStatus newStatus);
2026-02-10 13:27:11 +04:00
void peerConnect(const QString& peerId);
void debug(const QString& log);
2026-02-13 20:16:27 +04:00
void reloadIfChanged(const QString& configJson);
2026-01-30 21:15:18 +04:00
LogosAPI* m_logosAPI;
LogosModules* m_logos;
2026-02-13 20:16:27 +04:00
StorageStatus m_status;
2026-02-10 13:27:11 +04:00
QString m_debugLogs;
2026-02-13 20:16:27 +04:00
QString m_cid;
QString m_configJson;
2026-02-15 20:14:44 +04:00
int m_uploadProgress = 0;
QString m_uploadStatus = "";
qint64 m_uploadTotalBytes = 0;
qint64 m_uploadedBytes = 0;
2026-01-30 21:15:18 +04:00
};