75 lines
2.1 KiB
C++
Raw Normal View History

2025-12-17 10:55:13 +01:00
#include "library.h"
#include <QtCore/QObject>
#include <QtCore/QDebug>
#include <core/interface.h>
class LogosBlockchainModule : public QObject, public LogosBlockchainModuleAPI {
Q_OBJECT
Q_PLUGIN_METADATA(IID LogosBlockchainModuleInterface_iid FILE "metadata.json")
Q_INTERFACES(LogosBlockchainModuleAPI PluginInterface)
public:
LogosBlockchainModule() : node(nullptr) {
}
virtual ~LogosBlockchainModule() {
if (node != nullptr) {
stop();
}
}
// PluginInterface implementation
QString name() const override { return "logos-blockchain-module"; }
QString version() const override { return "1.0.0"; }
void initLogos(LogosAPI* logosAPIInstance) {
logosAPI = logosAPIInstance;
// logos = new LogosModules(logosAPI); // generated wrappers aggregator
// logos->core_manager.setEventSource(this); // enable trigger() helper
}
Q_INVOKABLE void start(const QString &config_path) override {
if (node != nullptr) {
qWarning() << "Node already started";
return;
}
QByteArray configPathBytes = config_path.toUtf8();
InitializedNomosNodeResult result = start_nomos_node(configPathBytes.constData());
2025-12-18 09:14:40 +01:00
if (!is_ok(&result.error)) {
qCritical() << "Failed to start Nomos node. Error code:" << result.error;
2025-12-17 10:55:13 +01:00
return;
}
2025-12-18 09:14:40 +01:00
node = result.value;
2025-12-17 10:55:13 +01:00
qInfo() << "Nomos node started successfully";
}
Q_INVOKABLE void stop() override {
if (node == nullptr) {
qWarning() << "Node not running";
return;
}
2025-12-18 09:14:40 +01:00
OperationStatus status = stop_node(node);
2025-12-17 10:55:13 +01:00
2025-12-18 09:14:40 +01:00
if (is_ok(&status)) {
2025-12-17 10:55:13 +01:00
qInfo() << "Nomos node stopped successfully";
2025-12-18 09:14:40 +01:00
} else {
qCritical() << "Failed to stop Nomos node. Error code:" << status;
2025-12-17 10:55:13 +01:00
}
node = nullptr;
}
signals:
// Required for event forwarding between modules
void eventResponse(const QString &eventName, const QVariantList &data) {
}
private:
NomosNode *node;
};