From 6c33ce8deb629fc4a5b751deb0b90cc1bb9ff739 Mon Sep 17 00:00:00 2001 From: oxmox Date: Fri, 3 Feb 2023 23:33:37 +0100 Subject: [PATCH] create cmake project structure and c++ test app --- CMakeLists.txt | 12 ++++++ external/CMakeLists.txt | 8 ++++ src/CMakeLists.txt | 8 ++++ src/doompanning.cc | 95 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 external/CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 src/doompanning.cc diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..81bd120 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.12) + +project(doompanning) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +## Create binaries in the root of the build directory +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +set(CMAKE_VERBOSE_MAKEFILE ON) + +add_subdirectory(external) +add_subdirectory(src) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt new file mode 100644 index 0000000..79d13bd --- /dev/null +++ b/external/CMakeLists.txt @@ -0,0 +1,8 @@ +option(NNG_SETSTACKSIZE "Use rlimit for thread stack size" ON) +set(NNG_TESTS OFF) +set(NNG_ENABLE_NNGCAT OFF) +add_subdirectory(nng) + +option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF) +option(SPDLOG_INSTALL "Generate the install target" ON) +add_subdirectory(spdlog) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..d6233c1 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,8 @@ +find_package(nng CONFIG REQUIRED) +find_package(Threads) +add_executable(doompanning doompanning.cc) +target_link_libraries(doompanning + PRIVATE nng::nng + PRIVATE spdlog::spdlog + ) +target_compile_features(doompanning PRIVATE cxx_std_17) diff --git a/src/doompanning.cc b/src/doompanning.cc new file mode 100644 index 0000000..ad26ae3 --- /dev/null +++ b/src/doompanning.cc @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include +#include +#include + +void dp_nng_fatal(const std::string &msg, int rv) +{ + spdlog::error("{}: {}", msg, nng_strerror(rv)); + abort(); +} + +void dp_errno_fatal(const std::string &msg) +{ + spdlog::error("{}: {}", msg, strerror(errno)); + abort(); +} + +nng_socket make_ctrl_pub(const char *url) +{ + nng_socket sock; + + if (auto res = nng_pub0_open(&sock)) + dp_nng_fatal("make_ctrl_pub/nng_pub0_open", res); + + if (auto res = nng_listen(sock, url, nullptr, 0)) + dp_nng_fatal("make_ctrl_pub/nng_listen", res); + + return sock; +} + +nng_socket make_ctrl_sub(const char *url) +{ + nng_socket sock; + + if (auto res = nng_sub0_open(&sock)) + dp_nng_fatal("make_ctrl_pub/nng_sub0_open", res); + + if (auto res = nng_listen(sock, url, nullptr, 0)) + dp_nng_fatal("make_ctrl_sub/nng_listen", res); + + return sock; +} + +nng_socket make_doom_pub(const char *url) +{ +} + +nng_socket make_doom_sub(const char *url) +{ +} + +static const char *CtrlUrl = "ipc://666_ctrl.socket"; +static const char *DoomUrl = "ipc://666_doom.socket"; +static const size_t NumDooms = 2; + +int run_doom(size_t id) +{ + spdlog::debug("doom#{} running", id); + return 0; +} + +int main(int argc, char *argv[]) +{ + spdlog::set_level(spdlog::level::debug); + spdlog::set_pattern("[%H:%M:%S.%e] [pid=%P] [%^%l%$] %v"); + spdlog::info("Hello, doomed world!"); + + for (size_t i=0; i