diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/CMakeLists.txt | 5 | ||||
-rw-r--r-- | common/include/hwd/internal.h | 13 | ||||
-rw-r--r-- | common/src/internal.cpp | 27 |
3 files changed, 41 insertions, 4 deletions
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 5c4c9e1..a126620 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,6 +1,7 @@ project(common CXX) -add_library(${PROJECT_NAME} INTERFACE +add_library(${PROJECT_NAME} STATIC + src/internal.cpp ) target_include_directories(${PROJECT_NAME} - INTERFACE include + PUBLIC include ) diff --git a/common/include/hwd/internal.h b/common/include/hwd/internal.h index dab1e32..633c5a9 100644 --- a/common/include/hwd/internal.h +++ b/common/include/hwd/internal.h @@ -4,6 +4,15 @@ 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 new file mode 100644 index 0000000..de1e7b0 --- /dev/null +++ b/common/src/internal.cpp @@ -0,0 +1,27 @@ +#include "hwd/internal.h" + +#include <cstdlib> + + +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 |