From 80cf4efd8d62f6683c4782a826015116ebf283f7 Mon Sep 17 00:00:00 2001 From: "NISHI, Takao" Date: Tue, 19 Mar 2024 16:32:50 +0000 Subject: [PATCH] WebUI listening addr can be configured separately from AES67 interface --- daemon/config.hpp | 8 +++++++- daemon/http_server.cpp | 8 ++++++-- daemon/main.cpp | 12 ++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/daemon/config.hpp b/daemon/config.hpp index f800b18..2d2d725 100644 --- a/daemon/config.hpp +++ b/daemon/config.hpp @@ -33,6 +33,7 @@ class Config { bool driver_restart); /* attributes retrieved from config json */ + const std::string& get_http_addr_str() const { return http_addr_str_; }; uint16_t get_http_port() const { return http_port_; }; uint16_t get_rtsp_port() const { return rtsp_port_; }; const std::string& get_http_base_dir() const { return http_base_dir_; }; @@ -69,6 +70,9 @@ class Config { return ptp_status_script_; } + void set_http_addr_str(std::string_view http_addr_str) { + http_addr_str_ = http_addr_str; + }; void set_http_port(uint16_t http_port) { http_port_ = http_port; }; void set_rtsp_port(uint16_t rtsp_port) { rtsp_port_ = rtsp_port; }; void set_http_base_dir(std::string_view http_base_dir) { @@ -129,7 +133,8 @@ class Config { void set_driver_restart(bool restart) { driver_restart_ = restart; } friend bool operator!=(const Config& lhs, const Config& rhs) { - return lhs.get_http_port() != rhs.get_http_port() || + return lhs.get_http_addr_str() != rhs.get_http_addr_str() || + lhs.get_http_port() != rhs.get_http_port() || lhs.get_rtsp_port() != rhs.get_rtsp_port() || lhs.get_http_base_dir() != rhs.get_http_base_dir() || lhs.get_log_severity() != rhs.get_log_severity() || @@ -157,6 +162,7 @@ class Config { private: /* from json */ + std::string http_addr_str_{""}; uint16_t http_port_{8080}; uint16_t rtsp_port_{8854}; std::string http_base_dir_{"../webui/dist"}; diff --git a/daemon/http_server.cpp b/daemon/http_server.cpp index 9aff992..1a33fb4 100644 --- a/daemon/http_server.cpp +++ b/daemon/http_server.cpp @@ -334,13 +334,17 @@ bool HttpServer::init() { }); /* start http server on a separate thread */ + auto http_addr=config_->get_http_addr_str(); + if(http_addr.empty()) + http_addr=config_->get_ip_addr_str(); + res_ = std::async(std::launch::async, [&]() { try { - svr_.listen(config_->get_ip_addr_str().c_str(), config_->get_http_port()); + svr_.listen(http_addr.c_str(), config_->get_http_port()); } catch (...) { BOOST_LOG_TRIVIAL(fatal) << "http_server:: " - << "failed to listen to " << config_->get_ip_addr_str() << ":" + << "failed to listen to " << http_addr << ":" << config_->get_http_port(); return false; } diff --git a/daemon/main.cpp b/daemon/main.cpp index a14466d..e9bfe14 100644 --- a/daemon/main.cpp +++ b/daemon/main.cpp @@ -61,10 +61,12 @@ int main(int argc, char* argv[]) { po::options_description desc("Options"); desc.add_options()("version,v", "Print daemon version and exit")( "config,c", po::value()->default_value("/etc/daemon.conf"), - "daemon configuration file")("http_port,p", po::value(), - "HTTP server port")("help,h", - "Print this help " - "message"); + "daemon configuration file")( + "http_addr,a",po::value(), + "HTTP server addr")("http_port,p", po::value(), + "HTTP server port")("help,h", + "Print this help " + "message"); int unix_style = postyle::unix_style | postyle::short_allow_next; bool driver_restart(true); @@ -124,6 +126,8 @@ int main(int argc, char* argv[]) { if (config == nullptr) { return EXIT_FAILURE; } + + config->set_http_addr_str(vm["http_addr"].as()); /* override configuration according to command line args */ if (vm.count("http_port")) { config->set_http_port(vm["http_port"].as());