配置生成逻辑优化
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
#include <string_view>
|
||||
#include "../server/Global.h"
|
||||
#include "Database.h"
|
||||
std::shared_ptr<Data_Source> create_from_json(const JSON* that_json, bool not_exist_use_default_value) {
|
||||
std::shared_ptr<Data_Source> create_from_json(const JSON* that_json) {
|
||||
std::string type = that_json->get_string("type");
|
||||
std::shared_ptr<Data_Source> ret = create_data_source_from_type(type);
|
||||
ret->from_json(that_json, not_exist_use_default_value);
|
||||
ret->from_json(that_json);
|
||||
return ret;
|
||||
}
|
||||
std::shared_ptr<Data_Source> Data_Source::that() {
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Psc {
|
||||
class SM_RingBuffer;
|
||||
}
|
||||
class Data_Source;
|
||||
std::shared_ptr<Data_Source> create_from_json(const Psc::JSON* that_json, bool not_exist_use_default_value);
|
||||
std::shared_ptr<Data_Source> create_from_json(const Psc::JSON* that_json);
|
||||
class Input_Format {
|
||||
public:
|
||||
Input_Format() {
|
||||
@@ -82,11 +82,11 @@ public:
|
||||
ret.append({"map3d", map3d.to_base_json()});
|
||||
return ret;
|
||||
}
|
||||
void from_base_json(const Psc::JSON* that_json, bool not_exist_use_default_value) {
|
||||
void from_base_json(const Psc::JSON* that_json) {
|
||||
if (that_json == nullptr || that_json->valueType != Psc::Object)
|
||||
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), "map_display");
|
||||
map2d.from_base_json(that_json->get("map2d"), not_exist_use_default_value);
|
||||
map3d.from_base_json(that_json->get("map3d"), not_exist_use_default_value);
|
||||
map2d.from_base_json(that_json->get("map2d"));
|
||||
map3d.from_base_json(that_json->get("map3d"));
|
||||
}
|
||||
};
|
||||
class Data_Source_Data {
|
||||
@@ -104,9 +104,9 @@ public:
|
||||
Ret_J(base_station_has_valid_position) ret.append({"map_display", map_display.to_base_json()});
|
||||
Ret_J(lat) Ret_J(lon) Ret_J(alt) Ret_J(ignore_msg_time) Ret_J(update_form_gps) Ret_J(keep_mode) return ret;
|
||||
}
|
||||
void from_base_json(const Psc::JSON* that_json, bool not_exist_use_default_value) {
|
||||
void from_base_json(const Psc::JSON* that_json) {
|
||||
Get_J(base_station_has_valid_position)
|
||||
map_display.from_base_json(that_json->get("map_display"), not_exist_use_default_value);
|
||||
map_display.from_base_json(that_json->get("map_display"));
|
||||
Get_J(lat) Get_J(lon) Get_J(alt) Get_J(ignore_msg_time) Get_J(update_form_gps) Get_J(keep_mode)
|
||||
}
|
||||
};
|
||||
@@ -187,10 +187,10 @@ public:
|
||||
virtual Psc::JSON to_json() {
|
||||
return With_Loop_Coro::to_base_json() += settings.read([](const auto& value) { return value.to_base_json(); });
|
||||
}
|
||||
virtual void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) {
|
||||
With_Loop_Coro::from_base_json(that_json, not_exist_use_default_value);
|
||||
virtual void from_json(const Psc::JSON* that_json) {
|
||||
With_Loop_Coro::from_base_json(that_json);
|
||||
settings.write([&](auto& value) {
|
||||
value.from_base_json(that_json, not_exist_use_default_value);
|
||||
value.from_base_json(that_json);
|
||||
});
|
||||
}
|
||||
std::string buffer;
|
||||
@@ -248,10 +248,10 @@ public:
|
||||
Psc::JSON to_json() override {
|
||||
return Data_Source::to_json() += specific.read([](const auto& value) { return value.to_base_json(); });
|
||||
}
|
||||
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
|
||||
Data_Source::from_json(that_json, not_exist_use_default_value);
|
||||
void from_json(const Psc::JSON* that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
specific.write([&](auto& value) {
|
||||
value.from_base_json(that_json, not_exist_use_default_value);
|
||||
value.from_base_json(that_json);
|
||||
});
|
||||
}
|
||||
asio::awaitable<std::string> read_coro() override {
|
||||
@@ -322,10 +322,10 @@ public:
|
||||
Psc::JSON to_json() override {
|
||||
return Data_Source::to_json() += specific.read([](const auto& value) { return value.to_base_json(); });
|
||||
}
|
||||
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
|
||||
Data_Source::from_json(that_json, not_exist_use_default_value);
|
||||
void from_json(const Psc::JSON* that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
specific.write([&](auto& value) {
|
||||
value.from_base_json(that_json, not_exist_use_default_value);
|
||||
value.from_base_json(that_json);
|
||||
});
|
||||
}
|
||||
std::unique_ptr<Psc::serial::Serial_Coro> serial{};
|
||||
@@ -416,10 +416,10 @@ public:
|
||||
asio::awaitable<void> _close() override;
|
||||
asio::awaitable<void> _open() override;
|
||||
std::vector<std::string> readBinaryFileAsString(std::string_view filepath, size_t part_size);
|
||||
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
|
||||
Data_Source::from_json(that_json, not_exist_use_default_value);
|
||||
void from_json(const Psc::JSON* that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
specific.write([&](auto& value) {
|
||||
value.from_base_json(that_json, not_exist_use_default_value);
|
||||
value.from_base_json(that_json);
|
||||
});
|
||||
}
|
||||
Psc::JSON to_json() override {
|
||||
@@ -470,10 +470,10 @@ public:
|
||||
}
|
||||
~Dll_Data_Source() override = default;
|
||||
std::vector<std::uint8_t> buffer;
|
||||
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
|
||||
Data_Source::from_json(that_json, not_exist_use_default_value);
|
||||
void from_json(const Psc::JSON* that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
const auto buffer_size = specific.write([&](auto& value) {
|
||||
value.from_base_json(that_json, not_exist_use_default_value);
|
||||
value.from_base_json(that_json);
|
||||
return value.buffer_size;
|
||||
});
|
||||
buffer.resize(buffer_size);
|
||||
@@ -548,10 +548,10 @@ public:
|
||||
ret.append({"shared_memory_open", shared_memory_open.load()});
|
||||
return ret;
|
||||
}
|
||||
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
|
||||
Data_Source::from_json(that_json, not_exist_use_default_value);
|
||||
void from_json(const Psc::JSON* that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
specific.write([&](auto& value) {
|
||||
value.from_base_json(that_json, not_exist_use_default_value);
|
||||
value.from_base_json(that_json);
|
||||
});
|
||||
}
|
||||
Psc::JSON to_json() override {
|
||||
@@ -586,10 +586,14 @@ inline std::shared_ptr<Data_Source> create_data_source_from_type(std::string_vie
|
||||
struct Data_Source_Config {
|
||||
Ordered_Map<std::string, std::shared_ptr<Data_Source>> map;
|
||||
Data_Source_Config() = default;
|
||||
void init(const Psc::JSON* that_json, bool not_exist_use_default_value) {
|
||||
void init(const Psc::JSON* that_json) {
|
||||
if (that_json == nullptr || that_json->valueType != Psc::Object)
|
||||
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), "data_source");
|
||||
auto list = that_json->get("list");
|
||||
if (list == nullptr || list->valueType != Psc::Array)
|
||||
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), "data_source.list");
|
||||
for (auto& it : list->children) {
|
||||
auto ds = create_from_json(&it, not_exist_use_default_value);
|
||||
auto ds = create_from_json(&it);
|
||||
map.push_back(ds);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user