summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-10-21 19:42:58 +0200
committerAki <please@ignore.pl>2021-10-21 19:42:58 +0200
commit17f3ab464da4832861fc16b3886c098c424ed5dd (patch)
treeb34576ccb3623ec3d3a4e8c7c7ce37e36d6c816b
parent395da4b6861540fcad778cfa0b9ec1f7c16274d6 (diff)
downloadhwd-17f3ab464da4832861fc16b3886c098c424ed5dd.zip
hwd-17f3ab464da4832861fc16b3886c098c424ed5dd.tar.gz
hwd-17f3ab464da4832861fc16b3886c098c424ed5dd.tar.bz2
Added client/server config with env variables
-rw-r--r--common/CMakeLists.txt5
-rw-r--r--common/include/hwd/internal.h13
-rw-r--r--common/src/internal.cpp27
-rw-r--r--daemon/src/daemon.cpp2
-rw-r--r--library/src/library.cpp2
5 files changed, 43 insertions, 6 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
diff --git a/daemon/src/daemon.cpp b/daemon/src/daemon.cpp
index 449292d..9c841f8 100644
--- a/daemon/src/daemon.cpp
+++ b/daemon/src/daemon.cpp
@@ -9,7 +9,7 @@
int main(int, char **)
{
- rpc::server server(hwd::internal::default_port);
+ rpc::server server(hwd::internal::port());
Gpio gpio;
Assembly assembly {server};
assembly.add("gpio", gpio);
diff --git a/library/src/library.cpp b/library/src/library.cpp
index d5c51c7..18c3cff 100644
--- a/library/src/library.cpp
+++ b/library/src/library.cpp
@@ -7,7 +7,7 @@ namespace hwd
static rpc::client & get_client()
{
- static rpc::client c("127.0.0.1", hwd::internal::default_port);
+ static rpc::client c(hwd::internal::host(), hwd::internal::port());
return c;
}