diff --git a/.gitignore b/.gitignore index dad7509..604d834 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ *.d build build-* +volumes +tmp # Compiled Object files *.slo diff --git a/cpp17/.devcontainer/devcontainer.json b/cpp17/.devcontainer/devcontainer.json index 3f326aa..11a9434 100644 --- a/cpp17/.devcontainer/devcontainer.json +++ b/cpp17/.devcontainer/devcontainer.json @@ -6,7 +6,8 @@ "customizations": { "vscode": { "settings": { - "terminal.integrated.defaultProfile.linux": "bash" + "terminal.integrated.defaultProfile.linux": "bash", + "cmake.useCMakePresets": "always" }, "extensions": [ "ms-vscode.cmake-tools", @@ -16,4 +17,4 @@ ] } } -} +} \ No newline at end of file diff --git a/cpp17/.devcontainer/docker-compose.yml b/cpp17/.devcontainer/docker-compose.yml index e335d98..a572fc5 100644 --- a/cpp17/.devcontainer/docker-compose.yml +++ b/cpp17/.devcontainer/docker-compose.yml @@ -7,6 +7,6 @@ services: dockerfile: .devcontainer/Dockerfile volumes: - ../:/workspace:cached + - ./volumes/vscode-server:/home/ubuntu/.vscode-server command: ["sleep", "infinity"] user: "1000:1000" - network_mode: host diff --git a/cpp17/CMakeLists.txt b/cpp17/CMakeLists.txt index 54cd8e3..7b8c37c 100644 --- a/cpp17/CMakeLists.txt +++ b/cpp17/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.20) project(AutoStore VERSION 1.0.0 LANGUAGES CXX) set(PROJECT_ROOT ${PROJECT_SOURCE_DIR}) @@ -6,8 +6,8 @@ set(PROJECT_ROOT ${PROJECT_SOURCE_DIR}) set(CTEST_OUTPUT_ON_FAILURE ON) enable_testing(true) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) -# add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/Lib") -add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/app") +add_subdirectory(lib) +add_subdirectory(app) diff --git a/cpp17/CMakePresets.json b/cpp17/CMakePresets.json new file mode 100644 index 0000000..910ec96 --- /dev/null +++ b/cpp17/CMakePresets.json @@ -0,0 +1,12 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "default", + "toolchainFile": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "TRUE" + } + } + ] +} diff --git a/cpp17/TODO.md b/cpp17/TODO.md new file mode 100644 index 0000000..6e4c52d --- /dev/null +++ b/cpp17/TODO.md @@ -0,0 +1,54 @@ +# C++17 AutoStore Implementation Plan + +This document outlines the steps to implement the C++17 version of the AutoStore application. Implemented classes should use `nxl::` namespace prefix. + +## Phase 1: Project Scaffolding & Build System + +- [x] Initialize a CMake project structure. +- [x] Set up the root `CMakeLists.txt` to manage the `app` and `lib` subdirectories. +- [x] Create the `lib` directory for the static library. +- [x] Create the `app` directory for the executable. +- [x] Configure `vcpkg` for dependency management and integrate it with CMake. +- [x] Add a dependency for an HTTP library (e.g., `cpp-httplib`) via `vcpkg`. +- [x] Add a dependency for a testing framework (e.g., `catch2`) via `vcpkg`. + +## Phase 2: Library (`lib`) - Dummy Implementation + +- [x] Create the directory structure for the library: `lib/src`, `lib/include`. +- [x] Create `lib/CMakeLists.txt` to build a static library. +- [x] In `lib/include/autostore`, define the public interface for the `App` to use. +- [x] Create a dummy `AutoStore` class in `lib/include/autostore/AutoStore.h` and a source file in `lib/src/AutoStore.cpp`. +- [ ] Define dummy classes for core domain and application logic inside the library (e.g., `ItemRepository`, `UserService`, etc.) to establish the architecture. These will be private to the library initially. + +## Phase 3: Application (`app`) - Dummy Implementation + +- [ ] Create the directory structure for the application: `app/src`. +- [x] Create `app/CMakeLists.txt` to build the executable. +- [ ] Link the `app` against the `lib` static library. +- [ ] Implement the main `App` class in `app/src/App.h` and `app/src/App.cpp`. +- [ ] The `App` class will have a constructor `App(int argc, char** argv)` and an `exec()` method. +- [ ] Implement signal handling (for `SIGINT`, `SIGTERM`) in the `App` class for graceful shutdown. +- [x] In `app/src/Main.cpp`, instantiate and run the `App` class. +- [ ] Ensure the project compiles and links successfully with the dummy implementations. + +## Phase 4: Core Logic Implementation + +- [ ] Implement the Domain layer in `lib/src/domain`. +- [ ] Implement the Application layer in `lib/src/application`. +- [ ] Implement the Infrastructure layer in `lib/src/infrastructure` (e.g., file-based persistence, HTTP client for ordering). +- [ ] Implement the Presentation layer (HTTP API) using the chosen HTTP library. +- [ ] Implement the startup logic to check for expired items. +- [ ] Implement a background mechanism (e.g., a thread) to periodically check for expired items. + +## Phase 5: Testing + +- [ ] Set up a `tests` directory. +- [ ] Create `tests/CMakeLists.txt` to build the test runner. +- [ ] Write unit tests for the Domain layer. +- [ ] Write unit tests for the Application layer, using mocks for infrastructure interfaces. +- [ ] Write integration tests for the Infrastructure layer. + +## Phase 6: Containerization + +- [x] Create a `Dockerfile` to build the C++ application in a container. +- [x] Create a `docker-compose.yml` file to easily build and run the application. \ No newline at end of file diff --git a/cpp17/app/CMakeLists.txt b/cpp17/app/CMakeLists.txt index f33b3e5..52fc0f2 100644 --- a/cpp17/app/CMakeLists.txt +++ b/cpp17/app/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.20) project(AutoStoreApp LANGUAGES CXX VERSION 0.1.0) set(TARGET_NAME AutoStore) @@ -6,14 +6,16 @@ set(TARGET_NAME AutoStore) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) - configure_file(src/Version.h.in ${CMAKE_BINARY_DIR}/Version.h) set(SOURCES src/Main.cpp + src/App.cpp + src/App.h ) -set (LIBRARIES + set (LIBRARIES + AutoStoreLib ) add_executable(${TARGET_NAME} ${SOURCES}) @@ -26,6 +28,6 @@ target_include_directories(${TARGET_NAME} # target_compile_options(${TARGET_NAME} PRIVATE -static-libgcc -static-libstdc++) # target_link_options(${TARGET_NAME} PRIVATE -static-libgcc -static-libstdc++) -target_link_libraries(${TARGET_NAME} ${LIBRARIES}) +target_link_libraries(${TARGET_NAME} PRIVATE ${LIBRARIES}) # add_subdirectory(tests/unit) diff --git a/cpp17/app/src/App.cpp b/cpp17/app/src/App.cpp new file mode 100644 index 0000000..333c014 --- /dev/null +++ b/cpp17/app/src/App.cpp @@ -0,0 +1,25 @@ +#include "App.h" +#include "autostore/AutoStore.h" +#include + +namespace nxl +{ + App::App(int argc, char **argv) + { + signal(SIGINT, App::handle_signal); + signal(SIGTERM, App::handle_signal); + } + + int App::exec() + { + nxl::AutoStore autostore; + autostore.run(); + return 0; + } + + void App::handle_signal(int signum) + { + std::cout << "\nCaught signal " << signum << ". Graceful shutdown." << std::endl; + exit(signum); + } +} \ No newline at end of file diff --git a/cpp17/app/src/App.h b/cpp17/app/src/App.h new file mode 100644 index 0000000..39b048b --- /dev/null +++ b/cpp17/app/src/App.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace nxl +{ + class App + { + public: + App(int argc, char **argv); + int exec(); + + private: + static void handle_signal(int signum); + }; +} \ No newline at end of file diff --git a/cpp17/app/src/Main.cpp b/cpp17/app/src/Main.cpp index 1535e1f..07d46d7 100644 --- a/cpp17/app/src/Main.cpp +++ b/cpp17/app/src/Main.cpp @@ -1,8 +1,10 @@ +#include "App.h" #include "Version.h" #include -int main() +int main(int argc, char **argv) { std::cout << "AutoStore v" << nxl::getVersionString() << std::endl; - return 0; + nxl::App app(argc, argv); + return app.exec(); } diff --git a/cpp17/docker/Dockerfile b/cpp17/docker/Dockerfile index 28500a5..c70024b 100644 --- a/cpp17/docker/Dockerfile +++ b/cpp17/docker/Dockerfile @@ -10,4 +10,4 @@ RUN cmake -DCMAKE_TOOLCHAIN_FILE:STRING=${VCPKG_ROOT}/scripts/buildsystems/vcpkg -H/workspace -B/workspace/build -G Ninja RUN cmake --build /workspace/build --config Release --target all -j 6 -- -CMD ["/workspace/build/autostore"] +CMD ["/workspace/build/bin/AutoStore"] diff --git a/cpp17/lib/CMakeLists.txt b/cpp17/lib/CMakeLists.txt new file mode 100644 index 0000000..f687ee9 --- /dev/null +++ b/cpp17/lib/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.20) +project(AutoStoreLib) +set(TARGET_NAME AutoStoreLib) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + + +add_library(${TARGET_NAME} STATIC + src/AutoStore.cpp +) + +target_include_directories(${TARGET_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include +) + +# Find dependencies +find_package(httplib CONFIG REQUIRED) +find_package(Catch2 CONFIG REQUIRED) + +target_link_libraries(${TARGET_NAME} + PUBLIC + httplib::httplib + Catch2::Catch2WithMain +) \ No newline at end of file diff --git a/cpp17/lib/include/autostore/AutoStore.h b/cpp17/lib/include/autostore/AutoStore.h new file mode 100644 index 0000000..0338ad9 --- /dev/null +++ b/cpp17/lib/include/autostore/AutoStore.h @@ -0,0 +1,11 @@ +#pragma once + +namespace nxl +{ + class AutoStore + { + public: + AutoStore(); + void run(); + }; +} // namespace nxl diff --git a/cpp17/lib/src/AutoStore.cpp b/cpp17/lib/src/AutoStore.cpp new file mode 100644 index 0000000..8e7f14b --- /dev/null +++ b/cpp17/lib/src/AutoStore.cpp @@ -0,0 +1,15 @@ +#include "autostore/AutoStore.h" +#include + +namespace nxl +{ + AutoStore::AutoStore() + { + std::cout << "AutoStore library initialized." << std::endl; + } + + void AutoStore::run() + { + std::cout << "AutoStore library is running." << std::endl; + } +} // namespace nxl \ No newline at end of file diff --git a/cpp17/vcpkg.json b/cpp17/vcpkg.json new file mode 100644 index 0000000..4b8aba5 --- /dev/null +++ b/cpp17/vcpkg.json @@ -0,0 +1,8 @@ +{ + "name": "autostore", + "version-string": "1.0.0", + "dependencies": [ + "cpp-httplib", + "catch2" + ] +}