mirror of
https://github.com/logos-storage/logos-storage-app-skeleton.git
synced 2026-06-18 14:29:32 +00:00
make into real app skeleton
This commit is contained in:
parent
2f82f37246
commit
06f99a5868
@ -63,11 +63,8 @@ find_library(LOGOS_SDK_LIB logos_sdk PATHS ${LOGOS_CPP_SDK_ROOT}/lib NO_DEFAULT_
|
||||
target_link_libraries(logos-common PUBLIC ${LOGOS_SDK_LIB})
|
||||
|
||||
# Create executables
|
||||
add_executable(logos-uploader uploader.cpp)
|
||||
target_link_libraries(logos-uploader PRIVATE logos-common)
|
||||
|
||||
add_executable(logos-downloader downloader.cpp)
|
||||
target_link_libraries(logos-downloader PRIVATE logos-common)
|
||||
add_executable(storage-app main.cpp)
|
||||
target_link_libraries(storage-app PRIVATE logos-common)
|
||||
|
||||
########### APP DEFINITION END ###########
|
||||
|
||||
@ -134,7 +131,7 @@ endif()
|
||||
########### RUNTIME LINKS ###########
|
||||
|
||||
# Set RPATH settings for each executable
|
||||
foreach(_target logos-uploader logos-downloader)
|
||||
foreach(_target storage-app)
|
||||
if(APPLE)
|
||||
set_target_properties(${_target} PROPERTIES
|
||||
INSTALL_RPATH "@executable_path/../lib"
|
||||
@ -153,7 +150,7 @@ endforeach()
|
||||
########### INSTALL ###########
|
||||
|
||||
# Install rules
|
||||
install(TARGETS logos-uploader logos-downloader
|
||||
install(TARGETS storage-app
|
||||
RUNTIME DESTINATION bin
|
||||
)
|
||||
|
||||
@ -22,20 +22,13 @@ void notify(QEventLoop* loop, bool successValue) {
|
||||
loop->exit(successValue ? 0 : 1);
|
||||
}
|
||||
|
||||
int app_main(LogosModules* modules, int argc, char* argv[]);
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " <upload|download> <arguments>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
QCoreApplication app(argc, argv);
|
||||
QCoreApplication::setOrganizationName("Logos");
|
||||
QCoreApplication::setApplicationName("LogosDownloader");
|
||||
QCoreApplication::setApplicationName("LogosUploader");
|
||||
|
||||
Logos logos(QCoreApplication::applicationDirPath() + "/../modules");
|
||||
if (!logos.init("LogosDownloader")) {
|
||||
if (!logos.init("LogosUploader")) {
|
||||
std::cerr << "Failed to initialize Logos" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
@ -46,17 +39,12 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
int app_main(LogosModules* modules, int argc, char* argv[]) {
|
||||
if (argc < 4) {
|
||||
std::cerr << "Usage: " << argv[0] << " <bootstrap-spr> <cid> <file>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const QString jsonConfig = "{"
|
||||
"\"listen-port\": 8001,"
|
||||
"\"disc-port\": 9001,"
|
||||
"\"nat\": \"none\","
|
||||
"\"data-dir\": \"./downloader-data\","
|
||||
"\"bootstrap-node\": [\"" + QString(argv[1]) + "\"]"
|
||||
"\"listen-addrs\": [\"/ip4/0.0.0.0/tcp/8000\"],"
|
||||
"\"disc-port\": 9000,"
|
||||
"\"data-dir\": \"./app-data\","
|
||||
"\"nat\": \"none\""
|
||||
"}";
|
||||
|
||||
if (!modules->storage_module.init(jsonConfig)) {
|
||||
@ -64,12 +52,8 @@ int app_main(LogosModules* modules, int argc, char* argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
QUrl url = QUrl::fromLocalFile(argv[3]);
|
||||
QString cid = argv[2];
|
||||
|
||||
{
|
||||
QEventLoop loop;
|
||||
|
||||
modules->storage_module.on("storageStart", [&loop](const QVariantList& data) {
|
||||
bool success = data[0].toBool();
|
||||
if (!success) {
|
||||
@ -83,26 +67,12 @@ int app_main(LogosModules* modules, int argc, char* argv[]) {
|
||||
if (!await(&loop, DEFAULT_TIMEOUT)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cerr << "Storage module started successfully" << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
QEventLoop loop;
|
||||
// Rest of the app goes here.
|
||||
|
||||
modules->storage_module.on("storageDownloadDone", [&loop](const QVariantList& data) {
|
||||
bool success = data[0].toBool();
|
||||
if (!success) {
|
||||
std::cerr << "Failed to download file: " << data[2].toString().toStdString() << std::endl;
|
||||
}
|
||||
notify(&loop, success);
|
||||
});
|
||||
|
||||
modules->storage_module.downloadToUrl(cid, url);
|
||||
|
||||
if (!await(&loop, DEFAULT_TIMEOUT)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "Download completed successfully." << std::endl;
|
||||
std::cerr << "Exiting..." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
12
app/metadata.json
Normal file
12
app/metadata.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "logos_storage_app",
|
||||
"version": "1.0.0",
|
||||
"description": "A simple application skeleton for a Logos Storage app on Logos Core",
|
||||
"author": "Logos Storage Team",
|
||||
"type": "app",
|
||||
"main": "storage-app",
|
||||
"dependencies": [
|
||||
"storage_module"
|
||||
],
|
||||
"capabilities": []
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
{
|
||||
"name": "logos_storage_cli",
|
||||
"version": "1.0.0",
|
||||
"description": "CLI workshop application for Logos Storage",
|
||||
"author": "Logos Core Team",
|
||||
"type": "cli",
|
||||
"main": "logos-storage-cli",
|
||||
"dependencies": [
|
||||
"storage_module"
|
||||
],
|
||||
"capabilities": []
|
||||
}
|
||||
120
cli/uploader.cpp
120
cli/uploader.cpp
@ -1,120 +0,0 @@
|
||||
#include "logos_manager.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QEventLoop>
|
||||
#include <QTimer>
|
||||
#include <iostream>
|
||||
|
||||
#define DEFAULT_TIMEOUT 10000
|
||||
|
||||
int app_main(LogosModules* modules, int argc, char* argv[]);
|
||||
|
||||
bool await(QEventLoop* loop, int timeoutMs) {
|
||||
QTimer::singleShot(timeoutMs, loop, [loop]() {
|
||||
std::cerr << "Call timed out." << std::endl;
|
||||
loop->exit(1);
|
||||
});
|
||||
return loop->exec() == 0;
|
||||
}
|
||||
|
||||
void notify(QEventLoop* loop, bool successValue) {
|
||||
loop->exit(successValue ? 0 : 1);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " <file path>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
QCoreApplication app(argc, argv);
|
||||
QCoreApplication::setOrganizationName("Logos");
|
||||
QCoreApplication::setApplicationName("LogosUploader");
|
||||
|
||||
Logos logos(QCoreApplication::applicationDirPath() + "/../modules");
|
||||
if (!logos.init("LogosUploader")) {
|
||||
std::cerr << "Failed to initialize Logos" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int result = app_main(logos.modules(), argc, argv);
|
||||
logos.cleanup();
|
||||
return result;
|
||||
}
|
||||
|
||||
int app_main(LogosModules* modules, int argc, char* argv[]) {
|
||||
|
||||
if (argc < 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " <file>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const QString jsonConfig = "{"
|
||||
"\"listen-port\": 8000,"
|
||||
"\"disc-port\": 9000,"
|
||||
"\"data-dir\": \"./uploader-data\","
|
||||
"\"nat\": \"none\""
|
||||
"}";
|
||||
|
||||
if (!modules->storage_module.init(jsonConfig)) {
|
||||
std::cerr << "Failed to initialize storage module" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
{
|
||||
QEventLoop loop;
|
||||
modules->storage_module.on("storageStart", [&loop](const QVariantList& data) {
|
||||
bool success = data[0].toBool();
|
||||
if (!success) {
|
||||
std::cerr << "Failed to start storage module: " << data[1].toString().toStdString() << std::endl;
|
||||
}
|
||||
notify(&loop, success);
|
||||
});
|
||||
|
||||
modules->storage_module.start();
|
||||
|
||||
if (!await(&loop, DEFAULT_TIMEOUT)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
LogosResult spr = modules->storage_module.spr();
|
||||
if (!spr.success) {
|
||||
std::cerr << "Failed to get SPR: " << spr.getValue<QString>().toStdString() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cerr << "SPR: " << spr.getValue<QString>().toStdString() << std::endl;
|
||||
|
||||
{
|
||||
QEventLoop loop;
|
||||
|
||||
// Uploads file.
|
||||
modules->storage_module.on("storageUploadDone", [&loop](const QVariantList& data) {
|
||||
bool success = data[0].toBool();
|
||||
if (!success) {
|
||||
std::cerr << "Failed to upload file: " << data[2].toString().toStdString() << std::endl;
|
||||
notify(&loop, false);
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "CID: " << data[2].toString().toStdString() << std::endl;
|
||||
notify(&loop, true);
|
||||
});
|
||||
|
||||
QUrl url = QUrl::fromLocalFile(argv[1]);
|
||||
LogosResult result = modules->storage_module.uploadUrl(url);
|
||||
if (!result.success) {
|
||||
std::cerr << "Failed to upload file: " << result.getValue<QString>().toStdString() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!await(&loop, DEFAULT_TIMEOUT)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Upload completed successfully. Type CTRL+C to exit." << std::endl;
|
||||
return QCoreApplication::exec();
|
||||
}
|
||||
@ -39,7 +39,7 @@
|
||||
};
|
||||
|
||||
# CLI package
|
||||
cli = import ./nix/cli.nix {
|
||||
app = import ./nix/app.nix {
|
||||
inherit pkgs common src logosLiblogos logosSdk logosStorageModule logosCapabilityModule;
|
||||
};
|
||||
|
||||
@ -47,10 +47,10 @@
|
||||
{
|
||||
# Individual outputs
|
||||
lib = lib;
|
||||
cli = cli;
|
||||
app = app;
|
||||
|
||||
# Default package
|
||||
default = cli;
|
||||
default = app;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# Builds the logos-storage-cli standalone CLI application
|
||||
# Builds the storage-app standalone CLI application
|
||||
{ pkgs, common, src, logosLiblogos, logosSdk, logosStorageModule, logosCapabilityModule }:
|
||||
|
||||
pkgs.stdenv.mkDerivation rec {
|
||||
@ -44,40 +44,40 @@ pkgs.stdenv.mkDerivation rec {
|
||||
preConfigure = ''
|
||||
runHook prePreConfigure
|
||||
|
||||
# Create generated_code directory for the CLI (cmake -S cli sets CMAKE_SOURCE_DIR=cli/)
|
||||
mkdir -p ./cli/generated_code
|
||||
# Create generated_code directory for the CLI (cmake -S app sets CMAKE_SOURCE_DIR=app/)
|
||||
mkdir -p ./app/generated_code
|
||||
|
||||
# Copy pre-generated API files from logos-storage-module
|
||||
echo "Copying include files from logos-storage-module..."
|
||||
if [ -d "${logosStorageModule}/include" ]; then
|
||||
cp -r "${logosStorageModule}/include"/* ./cli/generated_code/
|
||||
cp -r "${logosStorageModule}/include"/* ./app/generated_code/
|
||||
echo "Copied include files:"
|
||||
ls -la ./cli/generated_code/
|
||||
ls -la ./app/generated_code/
|
||||
else
|
||||
echo "Warning: No include directory found in logos-storage-module"
|
||||
fi
|
||||
|
||||
# Run logos-cpp-generator with cli/metadata.json and --general-only flag
|
||||
# Run logos-cpp-generator with app/metadata.json and --general-only flag
|
||||
# This generates logos_sdk.cpp which #includes storage_module_api.cpp
|
||||
echo "Running logos-cpp-generator for CLI..."
|
||||
logos-cpp-generator --metadata ${src}/cli/metadata.json --general-only --output-dir ./cli/generated_code
|
||||
echo "Running logos-cpp-generator for app..."
|
||||
logos-cpp-generator --metadata ${src}/app/metadata.json --general-only --output-dir ./app/generated_code
|
||||
|
||||
echo "Checking generated files in cli/generated_code:"
|
||||
ls -la ./cli/generated_code/
|
||||
echo "Checking generated files in app/generated_code:"
|
||||
ls -la ./app/generated_code/
|
||||
|
||||
# Move generated headers to include/ subdirectory (installed layout convention)
|
||||
if [ -f "./cli/generated_code/logos_sdk.h" ] || [ -f "./cli/generated_code/core_manager_api.h" ]; then
|
||||
if [ -f "./app/generated_code/logos_sdk.h" ] || [ -f "./app/generated_code/core_manager_api.h" ]; then
|
||||
echo "Creating include directory and moving generated files..."
|
||||
mkdir -p ./cli/generated_code/include
|
||||
for file in ./cli/generated_code/*.h; do
|
||||
[ -f "$file" ] && mv "$file" ./cli/generated_code/include/
|
||||
mkdir -p ./app/generated_code/include
|
||||
for file in ./app/generated_code/*.h; do
|
||||
[ -f "$file" ] && mv "$file" ./app/generated_code/include/
|
||||
done
|
||||
# Keep a copy of .cpp files in include/ so #include "storage_module_api.cpp" resolves
|
||||
for file in ./cli/generated_code/*.cpp; do
|
||||
[ -f "$file" ] && cp "$file" ./cli/generated_code/include/
|
||||
for file in ./app/generated_code/*.cpp; do
|
||||
[ -f "$file" ] && cp "$file" ./app/generated_code/include/
|
||||
done
|
||||
echo "Generated include directory:"
|
||||
ls -la ./cli/generated_code/include/
|
||||
ls -la ./app/generated_code/include/
|
||||
else
|
||||
echo "Warning: No header files generated by logos-cpp-generator"
|
||||
fi
|
||||
@ -88,7 +88,7 @@ pkgs.stdenv.mkDerivation rec {
|
||||
configurePhase = ''
|
||||
runHook preConfigure
|
||||
|
||||
echo "Configuring logos-storage-cli..."
|
||||
echo "Configuring storage-app..."
|
||||
echo "liblogos: ${logosLiblogos}"
|
||||
echo "cpp-sdk: ${logosSdk}"
|
||||
echo "storage-module: ${logosStorageModule}"
|
||||
@ -99,7 +99,7 @@ pkgs.stdenv.mkDerivation rec {
|
||||
test -d "${logosStorageModule}" || (echo "storage-module not found" && exit 1)
|
||||
test -d "${logosCapabilityModule}" || (echo "capability-module not found" && exit 1)
|
||||
|
||||
cmake -S cli -B build/cli \
|
||||
cmake -S app -B build/app \
|
||||
-GNinja \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE \
|
||||
@ -115,8 +115,8 @@ pkgs.stdenv.mkDerivation rec {
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
cmake --build build/cli
|
||||
echo "logos-storage-cli built successfully!"
|
||||
cmake --build build/app
|
||||
echo "logos-storage-app built successfully!"
|
||||
|
||||
runHook postBuild
|
||||
'';
|
||||
@ -126,14 +126,9 @@ pkgs.stdenv.mkDerivation rec {
|
||||
|
||||
mkdir -p $out/bin $out/lib $out/modules $out/generated_code
|
||||
|
||||
if [ -f "build/cli/bin/logos-uploader" ]; then
|
||||
cp build/cli/bin/logos-uploader "$out/bin/"
|
||||
echo "Installed uploader binary"
|
||||
fi
|
||||
|
||||
#if [ -f "build/cli/bin/logos-downloader" ]; then
|
||||
cp build/cli/bin/logos-downloader "$out/bin/"
|
||||
echo "Installed downloader binary"
|
||||
#if [ -f "build/app/bin/storage-app" ]; then
|
||||
cp build/app/bin/storage-app "$out/bin/"
|
||||
echo "Installed storage-app binary"
|
||||
#fi
|
||||
|
||||
# Copy the core binaries from liblogos
|
||||
@ -157,7 +152,7 @@ pkgs.stdenv.mkDerivation rec {
|
||||
fi
|
||||
|
||||
# Copy generated header files
|
||||
cp -R "./cli/generated_code" "$out/generated_code" || true
|
||||
cp -R "./app/generated_code" "$out/generated_code" || true
|
||||
|
||||
# Determine platform-specific plugin extension
|
||||
OS_EXT="so"
|
||||
Loading…
x
Reference in New Issue
Block a user