缩减代码

This commit is contained in:
2026-08-09 22:00:30 +08:00
parent 11e7affc75
commit 256c41fa9c
28 changed files with 157 additions and 1024 deletions
+32 -73
View File
@@ -1,5 +1,6 @@
#ifndef CONFIG_H_H
#define CONFIG_H_H
#include <array>
#include <fstream>
#include <map>
#include <vector>
@@ -13,25 +14,37 @@
#include "adminive/managed.hpp"
inline bool delete_log = false;
extern std::string default_config_directory;
std::string get_config_directory();
#define ECAP_CONFIG_SECTION_LIST(X) \
X(version) \
X(dsp) \
X(drogon) \
X(http_monitor) \
X(mlat) \
X(web_server) \
X(map_resources) \
X(map_view) \
X(map_models) \
X(mode_acs) \
X(log) \
X(console) \
X(external_database) \
X(cesium_graphics)
enum class Config_Section {
version,
dsp,
drogon,
http_monitor,
mlat,
web_server,
map_resources,
map_view,
map_models,
device,
mode_acs,
log,
console,
external_database,
cesium_graphics,
#define ECAP_CONFIG_SECTION_ENUM(name) name,
ECAP_CONFIG_SECTION_LIST(ECAP_CONFIG_SECTION_ENUM)
#undef ECAP_CONFIG_SECTION_ENUM
count
};
inline constexpr std::array config_section_names = {
#define ECAP_CONFIG_SECTION_NAME(name) std::string_view{#name},
ECAP_CONFIG_SECTION_LIST(ECAP_CONFIG_SECTION_NAME)
#undef ECAP_CONFIG_SECTION_NAME
};
#undef ECAP_CONFIG_SECTION_LIST
static_assert(config_section_names.size() == static_cast<std::size_t>(Config_Section::count));
inline constexpr std::string_view config_section_name(Config_Section section) {
return config_section_names[static_cast<std::size_t>(section)];
}
struct Log_Config {
~Log_Config() {
if (delete_log)
@@ -50,8 +63,6 @@ struct Console_Config {
}
bool record_playback;
bool mode_s_console;
bool post_request;
bool mlat_server;
PSC_USE_JSON
};
struct Http_Monitor_Config {
@@ -65,7 +76,6 @@ struct Mode_ACS_Config_Data {
SSR::CPR::D max_speed_m_s{};
SSR::CPR::D air_pos_timeout = 8;
SSR::CPR::D surface_pos_timeout = 32;
std::size_t read_milliseconds{};
bool wait_process_msg{};
bool time_space_filter{};
bool speed_filter{};
@@ -78,7 +88,6 @@ struct Mode_ACS_Config_Data {
bool aircraft_change_list_adsb_range_filter = true;
double aircraft_change_list_adsb_range_factor = 1.2;
double adsb_theoretical_target_altitude_meters = 10000.0;
bool ignore_df_11{};
bool monitor_msg_live{};
PSC_USE_JSON
};
@@ -92,7 +101,6 @@ struct Type_Descriptor<Mode_ACS_Config_Data> {
ADMINIVE_FIELD_LABEL(T, max_speed_m_s, "飞机最大速度(m/s").editable().required().number_input(),
ADMINIVE_FIELD_LABEL(T, air_pos_timeout, "空中 CPR 超时(秒)").editable().required().number_input(),
ADMINIVE_FIELD_LABEL(T, surface_pos_timeout, "地面 CPR 超时(秒)").editable().required().number_input(),
ADMINIVE_FIELD_LABEL(T, read_milliseconds, "读取数据源延时(毫秒)").editable().required().number_input(),
ADMINIVE_FIELD_LABEL(T, wait_process_msg, "等待处理消息").editable().boolean_input(),
ADMINIVE_FIELD_LABEL(T, time_space_filter, "时空过滤").editable().boolean_input(),
ADMINIVE_FIELD_LABEL(T, speed_filter, "速度过滤").editable().boolean_input(),
@@ -105,7 +113,6 @@ struct Type_Descriptor<Mode_ACS_Config_Data> {
ADMINIVE_FIELD_LABEL(T, aircraft_change_list_adsb_range_filter, "基站理论范围过滤").editable().boolean_input(),
ADMINIVE_FIELD_LABEL(T, aircraft_change_list_adsb_range_factor, "范围过滤系数").editable().required().number_input(),
ADMINIVE_FIELD_LABEL(T, adsb_theoretical_target_altitude_meters, "理论目标高度(米)").editable().required().number_input(),
ADMINIVE_FIELD_LABEL(T, ignore_df_11, "忽略 DF11").editable().boolean_input(),
ADMINIVE_FIELD_LABEL(T, monitor_msg_live, "监控 Mode ACS 消息").editable().boolean_input());
}
};
@@ -145,8 +152,10 @@ struct Web_Server_Config {
[[nodiscard]] std::string get_true_webapp() const {
return Psc::get_abs_path(webapp);
}
PSC_USE_JSON
std::string webapp;
std::uint16_t listen_port = 9081;
[[nodiscard]] Psc::JSON to_base_json() const;
void from_base_json(const Psc::JSON* that_json, bool not_exist_use_default_value);
};
enum class Map_Tile_File_Format { directory, mbtiles, online };
enum class Map_Tile_Y_Axis { xyz, tms };
@@ -436,58 +445,11 @@ struct Type_Descriptor<Map_Model_Config> {
}
};
}
struct Net_Config {
std::string key{};
std::string ip{};
std::uint16_t port{};
std::string netmask{};
std::string gateway{};
PSC_USE_JSON
};
struct Device_Config {
Ordered_Map<std::string, Net_Config*> list;
~Device_Config() {
if (delete_log)
std::cout << "~Device_Config()" << std::endl;
for (auto it : list.list()) {
delete it;
}
list.clear();
}
Psc::JSON to_base_json() {
Psc::JSON ret = Psc::JSON::object();
Psc::JSON net = Psc::JSON::array();
for (auto& li : list.list()) {
net.append(li->to_base_json());
}
ret.append({"net", net});
return ret;
}
Device_Config() = default;
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) {
for (auto& li : that_json->get("net")->children) {
auto cur = new Net_Config();
cur->from_base_json(&li, not_exist_use_default_value);
list.push_back(cur);
}
}
Psc::JSON to_net_json() {
Psc::JSON ret = Psc::JSON::object();
Psc::JSON net = Psc::JSON::array();
for (auto& li : list.list()) {
net.append(li->to_base_json());
}
ret.append({"net", net});
return ret;
}
void server(Global* g);
};
class Config {
public:
Config() = default;
DELETE_COPY(Config)
MLAT_Config mlat;
Device_Config device_config;
Web_Server_Config web_server_config;
adminive::Managed_Value<Map_Resources_Config> map_resources_config;
adminive::Managed_Value<Map_View_Config> map_view_config;
@@ -515,7 +477,6 @@ public:
map_model_config.write([&](auto& value) {
value.from_base_json(that_json->get("map_models"), not_exist_use_default_value);
});
device_config.from_json(that_json->get("device"), not_exist_use_default_value);
mode_acs.from_json(that_json->get("mode_acs"), not_exist_use_default_value);
console_config.from_base_json(that_json->get("console"), not_exist_use_default_value);
dsp_config.from_json(that_json->get("dsp"), not_exist_use_default_value);
@@ -534,9 +495,7 @@ public:
{"map_resources", map_resources_config.read([](const auto& value) { return value.to_base_json(); })},
{"map_view", map_view_config.read([](const auto& value) { return value.to_base_json(); })},
{"map_models", map_model_config.read([](const auto& value) { return value.to_base_json(); })},
{"device", device_config.to_base_json()},
{"mode_acs", mode_acs.to_base_json()},
//{"ais", ais.to_json()},
{"log", log_config.to_base_json()},
{"console", console_config.to_base_json()},
{"external_database", external_resources_manager.to_base_json()},