From b9e96d1b28eb5fa69f5c8e572e13695669354b23 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 7 Jun 2022 16:54:43 +0200 Subject: Renamed internal common to config --- CMakeLists.txt | 2 +- common/CMakeLists.txt | 7 ------- common/include/hwd/internal.h | 18 ------------------ common/src/internal.cpp | 27 --------------------------- config/CMakeLists.txt | 7 +++++++ config/include/hwd/config.h | 18 ++++++++++++++++++ config/src/config.cpp | 27 +++++++++++++++++++++++++++ daemon/CMakeLists.txt | 2 +- daemon/src/daemon.cpp | 4 ++-- library/CMakeLists.txt | 2 +- library/src/client.cpp | 4 ++-- 11 files changed, 59 insertions(+), 59 deletions(-) delete mode 100644 common/CMakeLists.txt delete mode 100644 common/include/hwd/internal.h delete mode 100644 common/src/internal.cpp create mode 100644 config/CMakeLists.txt create mode 100644 config/include/hwd/config.h create mode 100644 config/src/config.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 20d0f18..25ce8e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_EXTENSIONS No) find_package(Threads REQUIRED) find_package(rpclib 2 REQUIRED) -add_subdirectory(common) +add_subdirectory(config) add_subdirectory(daemon) add_subdirectory(library) add_subdirectory(examples) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt deleted file mode 100644 index a126620..0000000 --- a/common/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -project(common CXX) -add_library(${PROJECT_NAME} STATIC - src/internal.cpp - ) -target_include_directories(${PROJECT_NAME} - PUBLIC include - ) diff --git a/common/include/hwd/internal.h b/common/include/hwd/internal.h deleted file mode 100644 index 633c5a9..0000000 --- a/common/include/hwd/internal.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -namespace hwd -{ -namespace internal -{ - -constexpr int default_port = 4236; -constexpr const char * default_host = "127.0.0.1"; - -constexpr const char * port_variable = "HWDPORT"; -constexpr const char * host_variable = "HWDHOST"; - -int port(); -const char * host(); - -} // namespace internal -} // namespace hwd diff --git a/common/src/internal.cpp b/common/src/internal.cpp deleted file mode 100644 index de1e7b0..0000000 --- a/common/src/internal.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "hwd/internal.h" - -#include - - -namespace hwd -{ -namespace internal -{ - -int port() -{ - if (const char * from_env = std::getenv(port_variable)) - if (int port_number = std::atoi(from_env)) - return port_number; - return default_port; -} - -const char * host() -{ - if (const char * from_env = std::getenv(host_variable)) - return from_env; - return default_host; -} - -} // namespace internal -} // namespace hwd diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt new file mode 100644 index 0000000..7fbe117 --- /dev/null +++ b/config/CMakeLists.txt @@ -0,0 +1,7 @@ +project(config CXX) +add_library(${PROJECT_NAME} STATIC + src/config.cpp + ) +target_include_directories(${PROJECT_NAME} + PUBLIC include + ) diff --git a/config/include/hwd/config.h b/config/include/hwd/config.h new file mode 100644 index 0000000..7f42cb5 --- /dev/null +++ b/config/include/hwd/config.h @@ -0,0 +1,18 @@ +#pragma once + +namespace hwd +{ +namespace config +{ + +constexpr int default_port = 4236; +constexpr const char * default_host = "127.0.0.1"; + +constexpr const char * port_variable = "HWDPORT"; +constexpr const char * host_variable = "HWDHOST"; + +int port(); +const char * host(); + +} // namespace config +} // namespace hwd diff --git a/config/src/config.cpp b/config/src/config.cpp new file mode 100644 index 0000000..8895a24 --- /dev/null +++ b/config/src/config.cpp @@ -0,0 +1,27 @@ +#include "hwd/config.h" + +#include + + +namespace hwd +{ +namespace config +{ + +int port() +{ + if (const char * from_env = std::getenv(port_variable)) + if (int port_number = std::atoi(from_env)) + return port_number; + return default_port; +} + +const char * host() +{ + if (const char * from_env = std::getenv(host_variable)) + return from_env; + return default_host; +} + +} // namespace config +} // namespace hwd diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index 6a01e15..2f4c259 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -9,7 +9,7 @@ add_executable(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE rpclib::rpc PRIVATE Threads::Threads - PRIVATE common + PRIVATE config ) set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME hwd diff --git a/daemon/src/daemon.cpp b/daemon/src/daemon.cpp index 1b9dcab..aa34757 100644 --- a/daemon/src/daemon.cpp +++ b/daemon/src/daemon.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include "Assembly.h" #include "Gpio.h" @@ -16,7 +16,7 @@ static Sinewave sinewave; int main(int, char **) { - rpc::server server(hwd::internal::port()); + rpc::server server(hwd::config::port()); Assembly assembly {server}; assembly.add("gpio", gpio); assembly.add("memory", memory); diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index a454186..71ed16c 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -8,7 +8,7 @@ add_library(${PROJECT_NAME} SHARED target_link_libraries(${PROJECT_NAME} PUBLIC rpclib::rpc PUBLIC Threads::Threads - PRIVATE common + PRIVATE config ) target_include_directories(${PROJECT_NAME} PUBLIC "$" diff --git a/library/src/client.cpp b/library/src/client.cpp index 187f36e..d58e411 100644 --- a/library/src/client.cpp +++ b/library/src/client.cpp @@ -2,11 +2,11 @@ #include -#include +#include rpc::client & get_client() { - static rpc::client c(hwd::internal::host(), hwd::internal::port()); + static rpc::client c(hwd::config::host(), hwd::config::port()); return c; } -- cgit v1.1