Skip to content

Commit

Permalink
Merge pull request #156 from zophos/separate_webui_addr
Browse files Browse the repository at this point in the history
WebUI listening addr can be configured separately from AES67 interface
  • Loading branch information
bondagit authored Mar 23, 2024
2 parents 78a7902 + 80cf4ef commit 0a450cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 7 additions & 1 deletion daemon/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_; };
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() ||
Expand Down Expand Up @@ -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"};
Expand Down
8 changes: 6 additions & 2 deletions daemon/http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 8 additions & 4 deletions daemon/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>()->default_value("/etc/daemon.conf"),
"daemon configuration file")("http_port,p", po::value<int>(),
"HTTP server port")("help,h",
"Print this help "
"message");
"daemon configuration file")(
"http_addr,a",po::value<std::string>(),
"HTTP server addr")("http_port,p", po::value<int>(),
"HTTP server port")("help,h",
"Print this help "
"message");
int unix_style = postyle::unix_style | postyle::short_allow_next;
bool driver_restart(true);

Expand Down Expand Up @@ -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<std::string>());
/* override configuration according to command line args */
if (vm.count("http_port")) {
config->set_http_port(vm["http_port"].as<int>());
Expand Down

0 comments on commit 0a450cc

Please sign in to comment.