Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions engine/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
#error "Unsupported platform!"
#endif

void RunServer(std::optional<int> port, bool ignore_cout) {
void RunServer(std::optional<std::string> host, std::optional<int> port,
bool ignore_cout) {
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
signal(SIGINT, SIG_IGN);
#elif defined(_WIN32)
Expand All @@ -62,16 +63,24 @@ void RunServer(std::optional<int> port, bool ignore_cout) {
reinterpret_cast<PHANDLER_ROUTINE>(console_ctrl_handler), true);
#endif
auto config = file_manager_utils::GetCortexConfig();
if (port.has_value() && *port != std::stoi(config.apiServerPort)) {
if (host.has_value() || port.has_value()) {
if (host.has_value() && *host != config.apiServerHost) {
config.apiServerHost = *host;
}

if (port.has_value() && *port != std::stoi(config.apiServerPort)) {
config.apiServerPort = std::to_string(*port);
}

auto config_path = file_manager_utils::GetConfigurationPath();
config.apiServerPort = std::to_string(*port);
auto result =
config_yaml_utils::CortexConfigMgr::GetInstance().DumpYamlConfig(
config, config_path.string());
if (result.has_error()) {
CTL_ERR("Error update " << config_path.string() << result.error());
}
}

if (!ignore_cout) {
std::cout << "Host: " << config.apiServerHost
<< " Port: " << config.apiServerPort << "\n";
Expand Down Expand Up @@ -283,6 +292,7 @@ int main(int argc, char* argv[]) {
// avoid printing logs to terminal
is_server = true;

std::optional<std::string> server_host;
std::optional<int> server_port;
bool ignore_cout_log = false;
#if defined(_WIN32)
Expand All @@ -296,6 +306,8 @@ int main(int argc, char* argv[]) {
std::wstring v = argv[i + 1];
file_manager_utils::cortex_data_folder_path =
cortex::wc::WstringToUtf8(v);
} else if (command == L"--host") {
server_host = cortex::wc::WstringToUtf8(argv[i + 1]);
} else if (command == L"--port") {
server_port = std::stoi(argv[i + 1]);
} else if (command == L"--ignore_cout") {
Expand All @@ -312,6 +324,8 @@ int main(int argc, char* argv[]) {
file_manager_utils::cortex_config_file_path = argv[i + 1];
} else if (strcmp(argv[i], "--data_folder_path") == 0) {
file_manager_utils::cortex_data_folder_path = argv[i + 1];
} else if (strcmp(argv[i], "--host") == 0) {
server_host = argv[i + 1];
} else if (strcmp(argv[i], "--port") == 0) {
server_port = std::stoi(argv[i + 1]);
} else if (strcmp(argv[i], "--ignore_cout") == 0) {
Expand Down Expand Up @@ -367,6 +381,6 @@ int main(int argc, char* argv[]) {
}
}

RunServer(server_port, ignore_cout_log);
RunServer(server_host, server_port, ignore_cout_log);
return 0;
}