From e150513ea9a5b8b5004a65d51b15f9b237127849 Mon Sep 17 00:00:00 2001 From: chodak166 Date: Sun, 3 Aug 2025 11:11:43 +0200 Subject: [PATCH] WIP: cpp17 --- cpp17/app/src/App.cpp | 20 +++++++++++- cpp17/app/src/App.h | 5 +++ cpp17/lib/CMakeLists.txt | 2 ++ cpp17/lib/include/autostore/AutoStore.h | 31 ++++++++++++++++++ cpp17/lib/src/AutoStore.cpp | 43 +++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 cpp17/lib/include/autostore/AutoStore.h create mode 100644 cpp17/lib/src/AutoStore.cpp diff --git a/cpp17/app/src/App.cpp b/cpp17/app/src/App.cpp index 289b258..b14adb4 100644 --- a/cpp17/app/src/App.cpp +++ b/cpp17/app/src/App.cpp @@ -1,5 +1,6 @@ #include "App.h" #include +#include namespace nxl { @@ -11,15 +12,32 @@ App::App(int argc, char** argv) { signal(SIGINT, App::handleSignal); signal(SIGTERM, App::handleSignal); + + std::filesystem::create_directories("data"); + autoStore = std::make_unique("data"); + + if (!autoStore->initialize()) { + std::cerr << "Failed to initialize AutoStore" << std::endl; + throw std::runtime_error("Failed to initialize AutoStore"); + } } +App::~App() = default; + int App::exec() { - // TODO: start application services when implemented + if (!autoStore->start()) { + std::cerr << "Failed to start AutoStore services" << std::endl; + return 1; + } + + std::cout << "AutoStore is running. Press Ctrl+C to stop." << std::endl; std::unique_lock lock(mtx); exitCv.wait(lock, [] { return shouldExit; }); + autoStore->stop(); + return 0; } diff --git a/cpp17/app/src/App.h b/cpp17/app/src/App.h index 29fab1d..1b98090 100644 --- a/cpp17/app/src/App.h +++ b/cpp17/app/src/App.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include namespace nxl { @@ -12,6 +14,7 @@ class App { public: App(int argc, char** argv); + ~App(); int exec(); private: @@ -19,6 +22,8 @@ private: static std::condition_variable exitCv; static std::mutex mtx; static bool shouldExit; + + std::unique_ptr autoStore; }; } // namespace nxl \ No newline at end of file diff --git a/cpp17/lib/CMakeLists.txt b/cpp17/lib/CMakeLists.txt index 0a9b243..0e62e19 100644 --- a/cpp17/lib/CMakeLists.txt +++ b/cpp17/lib/CMakeLists.txt @@ -7,6 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) add_library(${TARGET_NAME} STATIC + src/AutoStore.cpp src/infrastructure/repositories/FileUserRepository.cpp src/infrastructure/repositories/FileItemRepository.cpp ) @@ -21,6 +22,7 @@ target_sources(${TARGET_NAME} FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include FILES + include/autostore/AutoStore.h include/autostore/domain/entities/User.h include/autostore/domain/entities/Item.h include/autostore/application/interfaces/IUserRepository.h diff --git a/cpp17/lib/include/autostore/AutoStore.h b/cpp17/lib/include/autostore/AutoStore.h new file mode 100644 index 0000000..6b701ba --- /dev/null +++ b/cpp17/lib/include/autostore/AutoStore.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include + +namespace nxl { +namespace autostore { + +class AutoStore +{ +public: + explicit AutoStore(std::string_view dataPath); + ~AutoStore() = default; + + // Initialize the application + bool initialize(); + + // Start the application services + bool start(); + + // Stop the application services + void stop(); + +private: + std::string dataPath; + bool initialized; +}; + +} // namespace autostore +} // namespace nxl \ No newline at end of file diff --git a/cpp17/lib/src/AutoStore.cpp b/cpp17/lib/src/AutoStore.cpp new file mode 100644 index 0000000..b57139e --- /dev/null +++ b/cpp17/lib/src/AutoStore.cpp @@ -0,0 +1,43 @@ +#include "autostore/AutoStore.h" +#include + +namespace nxl { +namespace autostore { + +AutoStore::AutoStore(std::string_view dataPath) + : dataPath(dataPath), initialized(false) +{} + +bool AutoStore::initialize() +{ + // TODO: Initialize repositories and services + std::cout << "Initializing AutoStore with data path: " << dataPath + << std::endl; + + // For now, just mark as initialized + initialized = true; + return true; +} + +bool AutoStore::start() +{ + if (!initialized) { + std::cerr << "AutoStore not initialized. Call initialize() first." + << std::endl; + return false; + } + + // TODO: Start background services, HTTP server, etc. + std::cout << "Starting AutoStore services..." << std::endl; + + return true; +} + +void AutoStore::stop() +{ + // TODO: Stop all services + std::cout << "Stopping AutoStore services..." << std::endl; +} + +} // namespace autostore +} // namespace nxl \ No newline at end of file