分离 http依赖
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include "adminive/adminive.hpp"
|
||||
#include "adminive/adapters/magic_enum.hpp"
|
||||
#include "adminive/adapters/nlohmann_json.hpp"
|
||||
#include "adminive/http.hpp"
|
||||
#include "adminive/adapters/httplib.hpp"
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
|
||||
@@ -69,9 +69,10 @@ int main(int argc, char** argv) {
|
||||
Radio_Service_Config radio_service_config;
|
||||
Alert_Config alert_config;
|
||||
httplib::Server server;
|
||||
State_Resource state_resource("/admin/radio_states", std::move(initial), "/admin/status");
|
||||
State_Resource state_resource("/admin/radio_states", std::move(initial));
|
||||
Service_Config_Resource service_config_resource(radio_service_config, "/admin/config/radio");
|
||||
Alert_Config_Resource alert_config_resource(alert_config, "/admin/config/alerts");
|
||||
state_resource.register_overview_status<adminive::example::Server_Status>("/admin/status", 2000);
|
||||
state_resource.register_status<&Radio_State::status>(2000);
|
||||
state_resource.bind(server);
|
||||
service_config_resource.bind(server);
|
||||
@@ -89,7 +90,7 @@ int main(int argc, char** argv) {
|
||||
status.poll_sequence = poll_sequence.fetch_add(1, std::memory_order_relaxed) + 1;
|
||||
status.radio_state_count = state_resource.size();
|
||||
status.listen_port = port;
|
||||
adminive::write_http_json(response, Json{{"status", 0}, {"msg", ""}, {"data", adminive::to_frontend_json<Json>(status)}});
|
||||
adminive::write_http_json(response, Json{{"status", 0}, {"msg", ""}, {"data", adminive::to_status_json<Json>(status)}});
|
||||
});
|
||||
const std::filesystem::path frontend_dist = std::filesystem::path(ADMINIVE_FRONTEND_DIST_DIR).lexically_normal();
|
||||
if(!server.set_mount_point("/", frontend_dist.string())) {
|
||||
|
||||
@@ -12,11 +12,12 @@ Radio_State make_radio_state(Radio_Mode mode, int port, int buffer_count, int lo
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Server_App::Server_App(int port, std::filesystem::path frontend_dist, std::filesystem::path config_file) : port_(port), frontend_dist_(std::move(frontend_dist)), config_store_(std::move(config_file)), state_resource_("/admin/radio_states", make_radio_states(), "/admin/status"), service_config_resource_(config_store_.data().radio_service, "/admin/config/radio", [this](const Radio_Service_Config& value) {
|
||||
Server_App::Server_App(int port, std::filesystem::path frontend_dist, std::filesystem::path config_file) : port_(port), frontend_dist_(std::move(frontend_dist)), config_store_(std::move(config_file)), state_resource_("/admin/radio_states", make_radio_states()), service_config_resource_(config_store_.data().radio_service, "/admin/config/radio", [this](const Radio_Service_Config& value) {
|
||||
config_store_.persist_radio_service(value);
|
||||
}, &config_store_.mutex()), alert_config_resource_(config_store_.data().alerts, "/admin/config/alerts", [this](const Alert_Config& value) {
|
||||
config_store_.persist_alerts(value);
|
||||
}, &config_store_.mutex()), device_tables_(config_store_) {
|
||||
state_resource_.register_overview_status<Server_Status>("/admin/status", 2000);
|
||||
state_resource_.register_status<&Radio_State::status>(2000);
|
||||
bind_routes();
|
||||
}
|
||||
@@ -69,7 +70,7 @@ void Server_App::bind_routes() {
|
||||
status.poll_sequence = poll_sequence_.fetch_add(1, std::memory_order_relaxed) + 1;
|
||||
status.radio_state_count = state_resource_.size();
|
||||
status.listen_port = port_;
|
||||
write_http_json(response, Json{{"status", 0}, {"msg", ""}, {"data", to_frontend_json(status)}});
|
||||
write_http_json(response, Json{{"status", 0}, {"msg", ""}, {"data", to_status_json<Json>(status)}});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user