mirror of
https://github.com/logos-storage/logos-storage-app-skeleton.git
synced 2026-06-14 04:19:25 +00:00
use LogosModules object to match API tutorial
This commit is contained in:
parent
b554cc7bb2
commit
f8d52f171f
@ -37,7 +37,8 @@ bool Logos::init()
|
||||
}
|
||||
std::cout << "Successfully loaded storage_module plugin" << std::endl;
|
||||
|
||||
m_api = std::make_unique<LogosAPI>("cli");
|
||||
m_api = new LogosAPI("cli");
|
||||
m_modules = new LogosModules(m_api);
|
||||
m_initialized = true;
|
||||
return true;
|
||||
}
|
||||
@ -50,13 +51,14 @@ void Logos::cleanup()
|
||||
|
||||
qDebug() << "Logos: cleanup...";
|
||||
|
||||
m_api.reset();
|
||||
delete m_modules;
|
||||
delete m_api;
|
||||
logos_core_cleanup();
|
||||
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
LogosAPI* Logos::api() const
|
||||
LogosModules* Logos::modules()
|
||||
{
|
||||
return m_api.get();
|
||||
return m_modules;
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include <QString>
|
||||
#include <memory>
|
||||
|
||||
#include "logos_sdk.h"
|
||||
#include "logos_api.h"
|
||||
|
||||
// Logos manages the lifecycle of the Logos Core and its plugins.
|
||||
@ -28,12 +29,11 @@ public:
|
||||
// Cleanup the Logos Core. Called automatically in destructor.
|
||||
void cleanup();
|
||||
|
||||
// Access to the LogosAPI instance for use with module APIs (e.g. StorageModule).
|
||||
// Returns nullptr if init() has not been called successfully.
|
||||
LogosAPI* api() const;
|
||||
LogosModules* modules();
|
||||
|
||||
private:
|
||||
QString m_pluginsDir;
|
||||
bool m_initialized = false;
|
||||
std::unique_ptr<LogosAPI> m_api;
|
||||
LogosAPI* m_api = nullptr;
|
||||
LogosModules* m_modules = nullptr;
|
||||
};
|
||||
|
||||
33
cli/main.cpp
33
cli/main.cpp
@ -3,38 +3,29 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "storage_module_api.h"
|
||||
int app_main(LogosModules* modules, int argc, char* argv[]);
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
QCoreApplication::setOrganizationName("Logos");
|
||||
QCoreApplication::setApplicationName("LogosStorageCLI");
|
||||
|
||||
// Set the plugins directory
|
||||
QString pluginsDir = QDir::cleanPath(QCoreApplication::applicationDirPath() + "/../modules");
|
||||
|
||||
// Initialize Logos Core and load required plugins
|
||||
Logos logos(pluginsDir);
|
||||
Logos logos(QCoreApplication::applicationDirPath() + "/../modules");
|
||||
if (!logos.init()) {
|
||||
std::cerr << "Failed to initialize Logos" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Use the Storage Module
|
||||
StorageModule storage(logos.api());
|
||||
|
||||
// Echo: get version (does not require the node to be started)
|
||||
LogosResult result = storage.version();
|
||||
if (result.success) {
|
||||
std::cout << "Storage version: " << result.getString().toStdString() << std::endl;
|
||||
} else {
|
||||
std::cerr << "Failed to get storage version: " << result.getError().toStdString() << std::endl;
|
||||
}
|
||||
|
||||
int result = app_main(logos.modules(), argc, argv);
|
||||
logos.cleanup();
|
||||
|
||||
// logos destructor calls cleanup() automatically
|
||||
return 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
int app_main(LogosModules* modules, int argc, char* argv[]) {
|
||||
// Your CLI application logic here
|
||||
std::cout << "Running app" << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
return 0;
|
||||
}
|
||||
@ -124,7 +124,7 @@ pkgs.stdenv.mkDerivation rec {
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
mkdir -p $out/bin $out/lib $out/modules
|
||||
mkdir -p $out/bin $out/lib $out/modules $out/generated_code
|
||||
|
||||
# Install CLI binary
|
||||
if [ -f "build/cli/bin/logos-storage-cli" ]; then
|
||||
@ -152,6 +152,9 @@ pkgs.stdenv.mkDerivation rec {
|
||||
cp -L "${logosSdk}/lib/"liblogos_sdk.* "$out/lib/" || true
|
||||
fi
|
||||
|
||||
# Copy generated header files
|
||||
cp -R "./cli/generated_code" "$out/generated_code" || true
|
||||
|
||||
# Determine platform-specific plugin extension
|
||||
OS_EXT="so"
|
||||
case "$(uname -s)" in
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user