linux 编译
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
"version": 4,
|
||||
"include": [
|
||||
"toolchain/vs2022.json",
|
||||
"toolchain/vs2019.json"
|
||||
"toolchain/vs2019.json",
|
||||
"D:\\ae\\env\\win_ubuntu\\win_ubuntu2004_15.1.0\\releases_gcc-15.1.0_x86_64-w64-mingw32\\preset.json"
|
||||
]
|
||||
}
|
||||
+28
-5
@@ -1,6 +1,10 @@
|
||||
get_filename_component(name ${CMAKE_CURRENT_LIST_DIR} NAME)
|
||||
set(rely libarchive SQLiteCpp)
|
||||
rcl_load_dependency_environment(drogon ${rely})
|
||||
|
||||
#message("222222222 LibArchive_SUB_LIBRARIES {${LibArchive_SUB_LIBRARIES}}")
|
||||
|
||||
|
||||
find_package(Drogon)
|
||||
find_package(SQLiteCpp CONFIG REQUIRED)
|
||||
set(Core Core_Static)
|
||||
@@ -9,7 +13,7 @@ if (1)
|
||||
if (WIN32)
|
||||
set(cfg_dir ${CMAKE_CURRENT_LIST_DIR}/config)
|
||||
else ()
|
||||
set(cfg_dir ${CMAKE_CURRENT_LIST_DIR}/config/x86_linux)
|
||||
set(cfg_dir ${CMAKE_CURRENT_LIST_DIR}/config)
|
||||
endif ()
|
||||
_create("dll" dll_source)
|
||||
_create("exe" data_process)
|
||||
@@ -43,23 +47,42 @@ if (1)
|
||||
target_link_libraries(ecap_server PRIVATE
|
||||
LibArchive::LibArchive
|
||||
${LibArchive_SUB_LIBRARIES}
|
||||
|
||||
)
|
||||
target_compile_definitions(ecap_server PRIVATE LIBARCHIVE_STATIC)
|
||||
|
||||
|
||||
_attach_source_file(ecap_server "${md}/Local_Server_main.cpp")
|
||||
_attach_post_build_file(ecap_server ${cfg_dir}/config.json)
|
||||
if (MSVC)
|
||||
|
||||
target_compile_options(ecap_server PRIVATE /fsanitize=address /Zi)
|
||||
|
||||
target_link_options(ecap_server PRIVATE /INCREMENTAL:NO /DEBUG)
|
||||
|
||||
else ()
|
||||
|
||||
# target_compile_options(ecap_server PRIVATE -fsanitize=address -fno-omit-frame-pointer -g)
|
||||
#
|
||||
# target_link_options(ecap_server PRIVATE -fsanitize=address)
|
||||
|
||||
endif ()
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
|
||||
|
||||
# 添加进程间通信系统库
|
||||
target_compile_options(ecap_server PRIVATE -g -gstrict-dwarf -gdwarf-4 -fvar-tracking-assignments)
|
||||
set(CMAKE_FOLDER "lzy")
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lzy ${CMAKE_BINARY_DIR}/lzy)
|
||||
unset(CMAKE_FOLDER)
|
||||
# set(CMAKE_FOLDER "lzy")
|
||||
# add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lzy ${CMAKE_BINARY_DIR}/lzy)
|
||||
# unset(CMAKE_FOLDER)
|
||||
set(ver v1.0.4)
|
||||
set(WEB_DIR "${CMAKE_CURRENT_LIST_DIR}/webapp")
|
||||
set(publish_root_dir "${CMAKE_CURRENT_LIST_DIR}/ver")
|
||||
set(publish_dir "${publish_root_dir}/${ver}")
|
||||
set(WEB_OUT_DIR "${publish_dir}/wwwroot")
|
||||
set(PACKAGE_ZIP "${publish_dir}.zip")
|
||||
set(NODE_DIR "C:/Users/wyc/AppData/Roaming/JetBrains/CLion2026.1/node/versions/24.15.0")
|
||||
set(NODE_DIR "C:/Users/wyc/AppData/Roaming/JetBrains/WebStorm2026.1/node/versions/24.15.0")
|
||||
set(NPM_EXECUTABLE "${NODE_DIR}/npm.cmd")
|
||||
if (NOT EXISTS "${NODE_DIR}/node.exe")
|
||||
message(FATAL_ERROR "node.exe not found: ${NODE_DIR}/node.exe")
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
#include "Local_Server/server/Global.h"
|
||||
#include <string_view>
|
||||
using namespace Psc;
|
||||
|
||||
std::shared_ptr<Data_Source> ds(Data_Source_Handler *dsh) {
|
||||
return dynamic_cast<Data_Source *>(dsh)->that();
|
||||
}
|
||||
|
||||
std::shared_ptr<SSR::Msg> Data_Source_Handler::create_msg(std::string_view packet) {
|
||||
auto source = ds(this);
|
||||
if (packet[0] != 0x1a) {
|
||||
@@ -90,10 +92,17 @@ std::shared_ptr<SSR::Msg> Data_Source_Handler::create_msg(std::string_view packe
|
||||
rotating_log("unknown_type", mem2hex(std::string(packet)));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t Data_Source_Handler::process_mode_acs_data(std::string_view origin_data) {
|
||||
// 先读取原始数据 注意多复制了一遍
|
||||
std::string mode_data(origin_data);
|
||||
origin_data_transform_mode_data(mode_data);
|
||||
static Value_Growth_Multi_T mt;
|
||||
auto t = key;
|
||||
if (mt.test(key, mode_data.size())) {
|
||||
std::cout << VAR_STR_2(key, mode_data.size()) << " 数据增长过快,可能内存积压" << std::endl;
|
||||
}
|
||||
|
||||
size_t ret = 0;
|
||||
if (mode_data.empty()) {
|
||||
return ret;
|
||||
@@ -113,6 +122,10 @@ size_t Data_Source_Handler::process_mode_acs_data(std::string_view origin_data)
|
||||
std::cout << source->key + " read:[mode_s_serial]:" << mem2hex(mode_data)
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
SSR::Binary_Format_handle_buffer(
|
||||
source->buffer, mode_data, [this, source, &ret](std::string &packet) {
|
||||
ret++;
|
||||
@@ -123,20 +136,19 @@ size_t Data_Source_Handler::process_mode_acs_data(std::string_view origin_data)
|
||||
bool mode_s = mt == SSR::Msg::S7 || mt == SSR::Msg::S14;
|
||||
if (mt == SSR::Msg::HULC_Status) {
|
||||
source->handle_HULC(packet);
|
||||
}
|
||||
else if (mt == SSR::Msg::Radarcape_status) {
|
||||
} else if (mt == SSR::Msg::Radarcape_status) {
|
||||
auto radarcape_msg = SSR::create_Radarcape_STATUS_Message(packet);
|
||||
std::cout << radarcape_msg.toJson().to_json_string() << std::endl;
|
||||
SSR::mode_s_logger->debug("Radarcape_status/radarcape", {},
|
||||
radarcape_msg.toJson().to_json_string());
|
||||
}
|
||||
else if (mode_s) {
|
||||
} else if (mode_s) {
|
||||
// 拓展点
|
||||
handle_mode_s(std::dynamic_pointer_cast<SSR::Mode_S_Msg>(msg));
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Data_Source_Handler::handle_mode_s(std::shared_ptr<SSR::Mode_S_Msg> mode_s_msg) {
|
||||
auto source = ds(this);
|
||||
std::string t = mode_s_msg->mlat_timestamp.to_memory() +
|
||||
@@ -219,6 +231,7 @@ void Data_Source_Handler::handle_mode_s(std::shared_ptr<SSR::Mode_S_Msg> mode_s_
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Data_Source_Handler::handle_HULC(std::string_view packet) {
|
||||
std::uint8_t len = SSR::get_len(packet);
|
||||
std::uint8_t id = SSR::get_id(packet);
|
||||
@@ -235,21 +248,22 @@ void Data_Source_Handler::handle_HULC(std::string_view packet) {
|
||||
auto status_msg = SSR::create_HULC_Status_Message(packet);
|
||||
bool gps_ok = status_msg.GPS_device_detected() && status_msg.GPS_valid() &&
|
||||
status_msg.GPS_has_valid_fix();
|
||||
if (gps_ok) {}
|
||||
if (gps_ok) {
|
||||
}
|
||||
auto g = Global::instance();
|
||||
base_station.set_msg(status_msg);
|
||||
Log_Type type({}, {{"msg", std::string(msg)}});
|
||||
SSR::mode_s_logger->debug("HULC/status", type,
|
||||
status_msg.toJson().to_json_string());
|
||||
if (gps_ok) {}
|
||||
if (gps_ok) {
|
||||
}
|
||||
else if (id == 24) {
|
||||
} else if (id == 24) {
|
||||
SSR::mode_s_logger->debug("HULC/reply", {}, msg);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
SSR::mode_s_logger->debug("HULC/unknown_id", {}, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void Data_Source_Handler::refresh_data_feed_key_list() {
|
||||
// std::cout << key << " refresh_data_feed_key_list" << std::endl;
|
||||
std::vector<std::string> tmp;
|
||||
@@ -263,8 +277,7 @@ void Data_Source_Handler::refresh_data_feed_key_list() {
|
||||
if (t->source_key == this->key) {
|
||||
tmp.push_back(t->feed_key);
|
||||
}
|
||||
}
|
||||
else if (relation->type == "First_Source_To_All_Feed_Relation") {
|
||||
} else if (relation->type == "First_Source_To_All_Feed_Relation") {
|
||||
auto t =
|
||||
dynamic_cast<First_Source_To_All_Feed_Relation *>(relation.get());
|
||||
std::shared_ptr<Data_Source> first = nullptr;
|
||||
@@ -306,8 +319,7 @@ void Data_Source_Handler::refresh_data_feed_key_list() {
|
||||
}) == tmp_info.end()) {
|
||||
// 如果当前元素在 tmp 中找不到,删除它
|
||||
it = cached_data_feed_key_list.erase(it);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
@@ -327,6 +339,7 @@ void Data_Source_Handler::refresh_data_feed_key_list() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::string> convert_to_send_format(Data_Source_Handler *ds,
|
||||
const std::shared_ptr<Data_Feed> &feed,
|
||||
const std::shared_ptr<SSR::Msg> &msg) {
|
||||
@@ -351,15 +364,13 @@ std::optional<std::string> convert_to_send_format(Data_Source_Handler *ds,
|
||||
output_format == Output_Data_Format::BIN_ID) {
|
||||
send_msg = SSR::packet_to_escape_format(data->packet);
|
||||
}
|
||||
}
|
||||
else if (type == SSR::Msg::Radarcape_status) {
|
||||
} else if (type == SSR::Msg::Radarcape_status) {
|
||||
auto data = static_cast<SSR::Msg *>(msg.get());
|
||||
if (output_format == Output_Data_Format::BIN ||
|
||||
output_format == Output_Data_Format::BIN_ID) {
|
||||
send_msg = SSR::packet_to_escape_format(data->packet);
|
||||
}
|
||||
}
|
||||
else if (type == SSR::Msg::AC) {
|
||||
} else if (type == SSR::Msg::AC) {
|
||||
if (!use_mode_ac) return std::nullopt;
|
||||
auto data = static_cast<SSR::Mode_AC_Msg *>(msg.get());
|
||||
std::string &msg_hex = data->msg_hex;
|
||||
@@ -369,23 +380,19 @@ std::optional<std::string> convert_to_send_format(Data_Source_Handler *ds,
|
||||
// send_msg = create_Binary_Format_memory(msg_hex, signal_level,
|
||||
// &mlat_timestamp);
|
||||
send_msg = SSR::packet_to_escape_format(msg->packet);
|
||||
}
|
||||
else if (output_format == Output_Data_Format::BIN_ID) {
|
||||
} else if (output_format == Output_Data_Format::BIN_ID) {
|
||||
// std::uint32_t id;
|
||||
// {
|
||||
// id = Global::instance()->mlat_server.id;
|
||||
// }
|
||||
// auto bin_id_packet = mode_s_msg_packet_to_server_packet(id,
|
||||
// data->packet); send_msg = packet_to_escape_format(bin_id_packet);
|
||||
}
|
||||
else if (output_format == Output_Data_Format::AVR) {
|
||||
} else if (output_format == Output_Data_Format::AVR) {
|
||||
send_msg = SSR::create_AVR_format(msg_hex);
|
||||
}
|
||||
else if (output_format == Output_Data_Format::AVR_MLAT) {
|
||||
} else if (output_format == Output_Data_Format::AVR_MLAT) {
|
||||
send_msg = create_MLAT_AVR_format(msg_hex, &mlat_timestamp);
|
||||
}
|
||||
}
|
||||
else if (type == SSR::Msg::S7 || type == SSR::Msg::S14) {
|
||||
} else if (type == SSR::Msg::S7 || type == SSR::Msg::S14) {
|
||||
auto s_msg = static_cast<SSR::Mode_S_Msg *>(msg.get());
|
||||
std::string &icao = s_msg->icao;
|
||||
SSR::Downlink_Format &df = s_msg->df;
|
||||
@@ -405,8 +412,7 @@ std::optional<std::string> convert_to_send_format(Data_Source_Handler *ds,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (feed->sbs_flm.test(s_msg->icao)) {
|
||||
sbs_out_put = true;
|
||||
}
|
||||
@@ -440,22 +446,18 @@ std::optional<std::string> convert_to_send_format(Data_Source_Handler *ds,
|
||||
send_msg = SSR::packet_to_escape_format(s_msg->packet);
|
||||
// send_msg = create_Binary_Format_memory(msg_hex, signal_level,
|
||||
// &mlat_timestamp);
|
||||
}
|
||||
else if (output_format == Output_Data_Format::BIN_ID) {
|
||||
} else if (output_format == Output_Data_Format::BIN_ID) {
|
||||
// std::uint32_t id;
|
||||
// {
|
||||
// id = Global::instance()->mlat_server.id;
|
||||
// }
|
||||
// auto bin_id_packet = mode_s_msg_packet_to_server_packet(id,
|
||||
// data->packet); send_msg = packet_to_escape_format(bin_id_packet);
|
||||
}
|
||||
else if (output_format == Output_Data_Format::AVR) {
|
||||
} else if (output_format == Output_Data_Format::AVR) {
|
||||
send_msg = SSR::create_AVR_format(msg_hex);
|
||||
}
|
||||
else if (output_format == Output_Data_Format::AVR_MLAT) {
|
||||
} else if (output_format == Output_Data_Format::AVR_MLAT) {
|
||||
send_msg = create_MLAT_AVR_format(msg_hex, &mlat_timestamp);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
std::cerr << "Unknown output format " << VAR_STR_1(output_format)
|
||||
<< std::endl;
|
||||
return std::nullopt;
|
||||
@@ -463,6 +465,7 @@ std::optional<std::string> convert_to_send_format(Data_Source_Handler *ds,
|
||||
}
|
||||
return send_msg;
|
||||
}
|
||||
|
||||
void Data_Source_Handler::push_to_feed(const std::shared_ptr<SSR::Msg> &msg) {
|
||||
if (need_refresh_data_feed_key_list) {
|
||||
refresh_data_feed_key_list();
|
||||
@@ -491,16 +494,13 @@ void Data_Source_Handler::push_to_feed(const std::shared_ptr<SSR::Msg>& msg) {
|
||||
// }
|
||||
if (feed->msg_buffer.mode_s_msg_num > s_size) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
++feed->msg_buffer.mode_s_msg_num;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (feed->msg_buffer.mode_other_msg_num > other_size) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
++feed->msg_buffer.mode_other_msg_num;
|
||||
}
|
||||
}
|
||||
@@ -510,6 +510,7 @@ void Data_Source_Handler::push_to_feed(const std::shared_ptr<SSR::Msg>& msg) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Psc::JSON Data_Source_Handler::get_all_connect_feed_status() {
|
||||
Psc::JSON ret = Psc::JSON::object();
|
||||
std::vector<Cached_Source_Info> list;
|
||||
@@ -531,6 +532,7 @@ Psc::JSON Data_Source_Handler::get_all_connect_feed_status() {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Psc::JSON Data_Source_Handler::get_all_connect_feed() {
|
||||
Psc::JSON ret = Psc::JSON::array();
|
||||
std::vector<Cached_Source_Info> list;
|
||||
|
||||
@@ -130,8 +130,7 @@ bool External_Resources::fetch(const std::filesystem::path &cache_pos,
|
||||
return true;
|
||||
}
|
||||
|
||||
External_Resource_Status External_Resources::update(
|
||||
SQLite::Database &db, const std::filesystem::path &cache_pos,
|
||||
External_Resource_Status External_Resources::update(SQLite::Database &db, const std::filesystem::path &cache_pos,
|
||||
const bool force_download, const bool only_when_empty) {
|
||||
create_table(db);
|
||||
External_Resource_Status result{name, row_count(db), false, false, ""};
|
||||
@@ -139,7 +138,9 @@ External_Resource_Status External_Resources::update(
|
||||
result.message = "table already populated";
|
||||
return result;
|
||||
}
|
||||
|
||||
if (cache_pos.empty()) {
|
||||
throw std::invalid_argument("cache_pos is empty");
|
||||
}
|
||||
std::filesystem::create_directories(cache_pos);
|
||||
result.downloaded = fetch(cache_pos, force_download);
|
||||
if (cache_file_name.empty()) {
|
||||
@@ -273,7 +274,8 @@ void External_Resources_Manager::init(const Psc::JSON *that_json) {
|
||||
Psc::JSON External_Resources_Manager::to_base_json() const {
|
||||
std::lock_guard lock(mtx_);
|
||||
auto ret = Psc::JSON::object();
|
||||
Ret_J(ecap_sqlite_path) auto list = Psc::JSON::array();
|
||||
Ret_J(ecap_sqlite_path)
|
||||
auto list = Psc::JSON::array();
|
||||
for (const std::unique_ptr<External_Resources> &resource: resources_) {
|
||||
list.children.emplace_back(resource->to_json());
|
||||
}
|
||||
@@ -291,7 +293,9 @@ void External_Resources_Manager::load_sqlite_db(std::string_view path) {
|
||||
|
||||
db_->exec("PRAGMA journal_mode=WAL;");
|
||||
db_->exec("PRAGMA synchronous=NORMAL;");
|
||||
initialize(*db_, std::filesystem::path(path).parent_path());
|
||||
auto pos = std::filesystem::path(path).parent_path();
|
||||
// std::cout << "path" << path << " " << pos;
|
||||
initialize(*db_, pos);
|
||||
sync_missing(*db_);
|
||||
}
|
||||
|
||||
@@ -644,7 +648,8 @@ void External_Resources_Manager::server(Global *g) {
|
||||
}
|
||||
const auto row = co_await Ecap_Coro::to_drogon(
|
||||
query_external_database_coro(name, std::move(primary_key_values)));
|
||||
res->setBody(row ? warp(row->to_json()).to_json_string()
|
||||
res->setBody(row
|
||||
? warp(row->to_json()).to_json_string()
|
||||
: Psc::JSON(nullptr).to_json_string());
|
||||
co_return;
|
||||
});
|
||||
@@ -837,17 +842,20 @@ External_Resources_Manager::update_all(SQLite::Database &db,
|
||||
std::lock_guard lock(mtx_);
|
||||
std::vector<External_Resource_Status> result;
|
||||
for (const auto &resource: resources_) {
|
||||
External_Resource_Status status;
|
||||
try {
|
||||
auto status =
|
||||
status =
|
||||
resource->update(db, cache_pos_, force_download, only_when_empty);
|
||||
std::cout << "External database [" << status.name << "] "
|
||||
<< status.message << ", rows=" << status.row_count << std::endl;
|
||||
result.push_back(std::move(status));
|
||||
} catch (const std::exception &error) {
|
||||
std::cerr << "External database [" << resource->name
|
||||
<< "] update failed: " << error.what() << std::endl;
|
||||
result.push_back({resource->name, resource->row_count(db), false, false,
|
||||
error.what()});
|
||||
<< "] update failed: [" << error.what() << "]" << " status.message:" << status.message << std::endl;
|
||||
result.push_back({
|
||||
resource->name, resource->row_count(db), false, false,
|
||||
error.what()
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
#include "With_Loop_Coro.h"
|
||||
#include "io_coro.h"
|
||||
#include <string_view>
|
||||
|
||||
With_Loop_Coro::~With_Loop_Coro() = default;
|
||||
|
||||
void With_Loop_Coro::async_stop() {
|
||||
std::string name = type + ":" + key;
|
||||
set_state(State::Force_Quit, std::format("任务正常收到请求,等待退出 {}!\n", name).c_str());
|
||||
loop_running = false;
|
||||
}
|
||||
|
||||
void With_Loop_Coro::sync_wait() {
|
||||
std::string name = type + ":" + key;
|
||||
if (!loop_task) {
|
||||
@@ -19,61 +22,65 @@ void With_Loop_Coro::sync_wait() {
|
||||
}
|
||||
std::cout << std::format("{}退出成功! \n", name);
|
||||
}
|
||||
|
||||
bool With_Loop_Coro::running() const {
|
||||
return loop_running;
|
||||
}
|
||||
|
||||
void With_Loop_Coro::set_state(State state, std::string_view action) {
|
||||
if (!action.empty()) {
|
||||
std::string name = type + "_" + key;
|
||||
std::cout << std::format("{} {} {} ==> {} \n", name, action, Psc::to_string(this->state), Psc::to_string(state));
|
||||
std::cout << std::format("{} {} {} ==> {} \n", name, action, Psc::to_string(this->state),
|
||||
Psc::to_string(state));
|
||||
}
|
||||
this->state = state;
|
||||
}
|
||||
With_Loop_Coro::With_Loop_Coro() : stop(0.1) {}
|
||||
|
||||
With_Loop_Coro::With_Loop_Coro() : stop(0.1) {
|
||||
}
|
||||
|
||||
asio::awaitable<void> With_Loop_Coro::run_loop_coro() {
|
||||
loop_running.store(true, std::memory_order_release);
|
||||
try {
|
||||
co_await loop_coro();
|
||||
loop_running.store(false, std::memory_order_release);
|
||||
co_return;
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
loop_running.store(false, std::memory_order_release);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
asio::awaitable<void> With_Loop_Coro::tick() {
|
||||
std::string name = type + ":" + key;
|
||||
if (state == State::Force_Quit) {
|
||||
static Frequency_Limit_Multi flm;
|
||||
if (flm.test(name)) {
|
||||
std::cout << std::format("{} 正在强制退出!\n", name);
|
||||
}
|
||||
}
|
||||
if (state == State::Start) {
|
||||
if (enable) {
|
||||
set_state(State::Before_Request_Start_Loop);
|
||||
}
|
||||
}
|
||||
else if (state == State::Before_Request_Start_Loop) {
|
||||
} else if (state == State::Before_Request_Start_Loop) {
|
||||
co_await this->_open();
|
||||
loop_running = enable;
|
||||
loop_task = Coro::instance()->spawn(run_loop_coro());
|
||||
set_state(State::Waiting_Loop_Start, "开始启动任务");
|
||||
}
|
||||
else if (state == State::Waiting_Loop_Start) {
|
||||
} else if (state == State::Waiting_Loop_Start) {
|
||||
if (running()) {
|
||||
set_state(State::Loop_Running, "启动任务成功!");
|
||||
}
|
||||
}
|
||||
else if (state == State::Loop_Running) {
|
||||
} else if (state == State::Loop_Running) {
|
||||
if (enable && !running()) {
|
||||
std::cout << std::format("任务未知原因已经退出 {}!\n", name);
|
||||
try {
|
||||
loop_task->get();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
} catch (const std::exception &e) {
|
||||
std::cout << std::format("任务异常退出 {}! {}\n", name, e.what());
|
||||
loop_running = false;
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cout << std::format("任务未知异常退出 {}!\n", name);
|
||||
loop_running = false;
|
||||
}
|
||||
@@ -84,12 +91,10 @@ asio::awaitable<void> With_Loop_Coro::tick() {
|
||||
if (!enable) {
|
||||
set_state(State::Before_Request_Stop_Loop, std::format("{} 检测到 enable变化 异步退出开始!", name));
|
||||
}
|
||||
}
|
||||
else if (state == State::Before_Request_Stop_Loop) {
|
||||
} else if (state == State::Before_Request_Stop_Loop) {
|
||||
loop_running = false;
|
||||
set_state(State::Waiting_Stop_Loop, "退出变量已设置 等待退出");
|
||||
}
|
||||
else if (state == State::Waiting_Stop_Loop) {
|
||||
} else if (state == State::Waiting_Stop_Loop) {
|
||||
if (!running()) {
|
||||
loop_task.reset();
|
||||
co_await this->_close();
|
||||
|
||||
@@ -14,11 +14,13 @@
|
||||
#include <format>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
static std::string thread_id_str() {
|
||||
std::ostringstream oss;
|
||||
oss << std::this_thread::get_id();
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<With_Loop_Coro> > get_all() {
|
||||
auto g = Global::instance();
|
||||
std::vector<std::shared_ptr<With_Loop_Coro> > ret;
|
||||
@@ -32,6 +34,7 @@ std::vector<std::shared_ptr<With_Loop_Coro>> get_all() {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Coro::has_running_loop_tasks() {
|
||||
auto list = get_all();
|
||||
for (auto &li: list) {
|
||||
@@ -41,6 +44,7 @@ bool Coro::has_running_loop_tasks() {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Coro::start() {
|
||||
std::cout << "start_io_coro" << std::endl;
|
||||
running.store(true, std::memory_order_release);
|
||||
@@ -55,8 +59,7 @@ void Coro::start() {
|
||||
auto other_need = std::max<unsigned int>(2, n / 2);
|
||||
if (n > other_need) {
|
||||
n -= other_need;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
n = n / 2;
|
||||
}
|
||||
n = std::max<unsigned int>(1, n);
|
||||
@@ -64,12 +67,14 @@ void Coro::start() {
|
||||
std::cout << std::format("协程已经启动 process_data concurrency: 在n个线程上{}\n", n);
|
||||
data_feed_thread_task = std::make_unique<std::future<void> >(asio::co_spawn(io, coro_thread(), asio::use_future));
|
||||
}
|
||||
|
||||
asio::awaitable<void> Coro::sleep_for(std::chrono::milliseconds ms) {
|
||||
auto executor = co_await asio::this_coro::executor;
|
||||
asio::steady_timer timer(executor, ms);
|
||||
co_await timer.async_wait(asio::use_awaitable);
|
||||
co_return;
|
||||
}
|
||||
|
||||
void Coro::stop() {
|
||||
std::cout << "stop_io_coro begin" << std::endl;
|
||||
auto list = get_all();
|
||||
@@ -85,7 +90,8 @@ void Coro::stop() {
|
||||
}
|
||||
// 停止状态更新状态机
|
||||
running = false;
|
||||
asio::post(io, [] {});
|
||||
asio::post(io, [] {
|
||||
});
|
||||
if (data_feed_thread_task) {
|
||||
std::cout << "等待 coro_thread 退出" << std::endl;
|
||||
data_feed_thread_task->get();
|
||||
@@ -107,6 +113,7 @@ void Coro::stop() {
|
||||
}
|
||||
std::cout << "stop_io_coro end" << std::endl;
|
||||
}
|
||||
|
||||
asio::awaitable<void> Coro::coro_thread() {
|
||||
while (running.load(std::memory_order_acquire)) {
|
||||
auto list = get_all();
|
||||
@@ -117,7 +124,9 @@ asio::awaitable<void> Coro::coro_thread() {
|
||||
}
|
||||
co_return;
|
||||
}
|
||||
|
||||
bool data_feed_debug = false;
|
||||
|
||||
asio::awaitable<void> Data_Feed::loop_coro() {
|
||||
auto feed = this;
|
||||
auto co = Coro::instance();
|
||||
@@ -181,12 +190,16 @@ asio::awaitable<void> Data_Feed::loop_coro() {
|
||||
std::cout << std::format("{} feed loop exit {}\n", key, thread_id_str());
|
||||
co_return;
|
||||
}
|
||||
|
||||
bool data_source_debug = false;
|
||||
bool wait = false;
|
||||
// 不开启wait 性能巨差 数据积压
|
||||
bool wait = true;
|
||||
|
||||
asio::awaitable<void> Data_Source::loop_coro() {
|
||||
auto source = this;
|
||||
auto co = Coro::instance();
|
||||
auto process_strand = std::make_shared<asio::strand<asio::thread_pool::executor_type>>(co->process_data->get_executor());
|
||||
auto process_strand = std::make_shared<asio::strand<asio::thread_pool::executor_type> >(
|
||||
co->process_data->get_executor());
|
||||
while (source->running()) {
|
||||
if (data_source_debug) {
|
||||
std::cout << std::format("{} source loop begin {}\n", key, thread_id_str());
|
||||
@@ -224,8 +237,7 @@ asio::awaitable<void> Data_Source::loop_coro() {
|
||||
if (num == 0) {
|
||||
std::cout << std::format("{} 没解析到数据睡眠10ms {} {}\n", name, num, thread_id_str());
|
||||
ask_sleep = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
std::cout << std::format("{} 解析到数据 {} {}\n", name, num, thread_id_str());
|
||||
}
|
||||
}
|
||||
@@ -233,8 +245,7 @@ asio::awaitable<void> Data_Source::loop_coro() {
|
||||
co_await co->sleep_for(std::chrono::milliseconds(10));
|
||||
ask_sleep = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
asio::post(*process_strand, [this, source, process_strand, mode_data = std::move(mode_data)]() mutable {
|
||||
try {
|
||||
if (data_source_debug) {
|
||||
@@ -250,16 +261,13 @@ asio::awaitable<void> Data_Source::loop_coro() {
|
||||
if (num == 0) {
|
||||
std::cout << std::format("{} 没解析到数据 {} {}\n", name, num, thread_id_str());
|
||||
ask_sleep = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
std::cout << std::format("{} 解析到数据 {} {}\n", name, num, thread_id_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
} catch (const std::exception &e) {
|
||||
std::cout << std::format("{} process exception: {}\n", source->key, e.what());
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cout << std::format("{} process unknown exception\n", source->key);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -328,10 +328,10 @@ void Global::init_web_server() {
|
||||
&&cb) {
|
||||
|
||||
#ifdef __linux__
|
||||
std::string_view root_dir = Psc::get_exe_dir() + "/..";
|
||||
std::string root_dir = Psc::get_exe_dir() + "/..";
|
||||
|
||||
std::string_view log_file = fmt::format("{}/restart_device.log", root_dir);
|
||||
std::string_view cmd = fmt::format(
|
||||
std::string log_file = fmt::format("{}/restart_device.log", root_dir);
|
||||
std::string cmd = fmt::format(
|
||||
R"(systemd-run --scope --slice=system.slice sudo bash "{}/restart_device.bash" > {} 2>&1 &)",
|
||||
root_dir, log_file);
|
||||
std::cout << "Generated Command: " << cmd << std::endl;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user