Browse Source

WIP: cpp17

cpp17-init-dingo-fail
chodak166 5 months ago
parent
commit
e150513ea9
  1. 20
      cpp17/app/src/App.cpp
  2. 5
      cpp17/app/src/App.h
  3. 2
      cpp17/lib/CMakeLists.txt
  4. 31
      cpp17/lib/include/autostore/AutoStore.h
  5. 43
      cpp17/lib/src/AutoStore.cpp

20
cpp17/app/src/App.cpp

@ -1,5 +1,6 @@
#include "App.h"
#include <iostream>
#include <filesystem>
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<nxl::autostore::AutoStore>("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<std::mutex> lock(mtx);
exitCv.wait(lock, [] { return shouldExit; });
autoStore->stop();
return 0;
}

5
cpp17/app/src/App.h

@ -5,6 +5,8 @@
#include <csignal>
#include <mutex>
#include <thread>
#include <memory>
#include <autostore/AutoStore.h>
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<nxl::autostore::AutoStore> autoStore;
};
} // namespace nxl

2
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

31
cpp17/lib/include/autostore/AutoStore.h

@ -0,0 +1,31 @@
#pragma once
#include <memory>
#include <string>
#include <string_view>
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

43
cpp17/lib/src/AutoStore.cpp

@ -0,0 +1,43 @@
#include "autostore/AutoStore.h"
#include <iostream>
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
Loading…
Cancel
Save