From a19443a026099c3045ecd5d2d0d87c41f61a3406 Mon Sep 17 00:00:00 2001 From: leonarski_f Date: Mon, 23 Mar 2026 21:30:30 +0100 Subject: [PATCH] jfjoch_broker: Move to cpp-httplib work in progress (not working) --- CMakeLists.txt | 9 +- broker/CMakeLists.txt | 6 +- broker/JFJochBrokerHttp.cpp | 963 +++++++++----- broker/JFJochBrokerHttp.h | 391 +++--- broker/gen/api/ApiBase.cpp | 22 - broker/gen/api/ApiBase.h | 51 - broker/gen/api/DefaultApi.cpp | 2279 --------------------------------- broker/gen/api/DefaultApi.h | 634 --------- broker/jfjoch_broker.cpp | 93 +- update_version.sh | 1 - 10 files changed, 906 insertions(+), 3543 deletions(-) delete mode 100644 broker/gen/api/ApiBase.cpp delete mode 100644 broker/gen/api/ApiBase.h delete mode 100644 broker/gen/api/DefaultApi.cpp delete mode 100644 broker/gen/api/DefaultApi.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 21df66a5..828e3ed4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,13 +103,6 @@ FetchContent_Declare( EXCLUDE_FROM_ALL ) -FetchContent_Declare( - pistache_http - GIT_REPOSITORY https://github.com/fleon-psi/pistache - GIT_TAG 0393f6c - EXCLUDE_FROM_ALL -) - FetchContent_Declare( zstd GIT_REPOSITORY https://github.com/facebook/zstd @@ -148,7 +141,7 @@ FetchContent_Declare( GIT_TAG v0.38.0 ) -FetchContent_MakeAvailable(pistache_http zstd sls_detector_package catch2 hdf5 spdlog httplib) +FetchContent_MakeAvailable(zstd sls_detector_package catch2 hdf5 spdlog httplib) ADD_SUBDIRECTORY(jungfrau) ADD_SUBDIRECTORY(compression) diff --git a/broker/CMakeLists.txt b/broker/CMakeLists.txt index fe51bf6a..8a87b41a 100644 --- a/broker/CMakeLists.txt +++ b/broker/CMakeLists.txt @@ -15,8 +15,8 @@ ADD_LIBRARY(JFJochBroker STATIC TARGET_LINK_LIBRARIES(JFJochBroker JFJochReceiver JFJochDetector JFJochCommon JFJochAPI JFJochPreview) -ADD_EXECUTABLE(jfjoch_broker jfjoch_broker.cpp JFJochBrokerHttp.cpp JFJochBrokerHttp.h - gen/api/DefaultApi.cpp gen/api/DefaultApi.h gen/api/ApiBase.h gen/api/ApiBase.cpp) -TARGET_LINK_LIBRARIES(jfjoch_broker JFJochBroker pistache_static ${CMAKE_DL_LIBS}) +ADD_EXECUTABLE(jfjoch_broker jfjoch_broker.cpp JFJochBrokerHttp.cpp JFJochBrokerHttp.h) + +TARGET_LINK_LIBRARIES(jfjoch_broker JFJochBroker httplib::httplib ${CMAKE_DL_LIBS}) TARGET_INCLUDE_DIRECTORIES(jfjoch_broker PUBLIC gen/api) INSTALL(TARGETS jfjoch_broker RUNTIME COMPONENT jfjoch) diff --git a/broker/JFJochBrokerHttp.cpp b/broker/JFJochBrokerHttp.cpp index 459e630f..5f1da746 100644 --- a/broker/JFJochBrokerHttp.cpp +++ b/broker/JFJochBrokerHttp.cpp @@ -2,26 +2,67 @@ // SPDX-License-Identifier: GPL-3.0-only // Using OpenAPI licensed with Apache License 2.0 -#include #include "JFJochBrokerHttp.h" + +#include +#include +#include +#include +#include + #include "gen/model/Error_message.h" #include "../common/GitInfo.h" #include "OpenAPIConvert.h" #include "../preview/JFJochTIFF.h" -JFJochBrokerHttp::JFJochBrokerHttp(const DiffractionExperiment &experiment, - const SpotFindingSettings& spot_finding_settings, - std::shared_ptr &rtr) - : DefaultApi(rtr), - state_machine(experiment, services, logger, spot_finding_settings) { - Pistache::Rest::Routes::Get(*rtr, "/", Pistache::Rest::Routes::bind(&JFJochBrokerHttp::GetStaticFile, this)); - Pistache::Rest::Routes::Get(*rtr, "/frontend", Pistache::Rest::Routes::bind(&JFJochBrokerHttp::GetStaticFile, this)); - Pistache::Rest::Routes::Get(*rtr, "/frontend/*", Pistache::Rest::Routes::bind(&JFJochBrokerHttp::GetStaticFile, this)); - Pistache::Rest::Routes::Get(*rtr, "/frontend/assets/*", Pistache::Rest::Routes::bind(&JFJochBrokerHttp::GetStaticFile, this)); +using namespace org::openapitools::server::model; - init(); +namespace { + template + std::optional query_optional(const httplib::Request& req, const char* name) { + if (!req.has_param(name)) + return std::nullopt; + T v{}; + if (fromStringValue(req.get_param_value(name), v)) + return v; + return std::nullopt; + } + + inline std::optional query_optional_string(const httplib::Request& req, const char* name) { + if (!req.has_param(name)) + return std::nullopt; + return req.get_param_value(name); + } + + inline std::string mime_from_path(const std::string& path) { + if (path.ends_with(".js")) return "text/javascript"; + if (path.ends_with(".css")) return "text/css"; + if (path.ends_with(".html")) return "text/html"; + if (path.ends_with(".json")) return "application/json"; + if (path.ends_with(".cbor")) return "application/cbor"; + if (path.ends_with(".jpeg") || path.ends_with(".jpg")) return "image/jpeg"; + if (path.ends_with(".tiff") || path.ends_with(".tif")) return "image/tiff"; + if (path.ends_with(".png")) return "image/png"; + if (path.ends_with(".svg")) return "image/svg+xml"; + if (path.ends_with(".bin")) return "application/octet-stream"; + return "application/octet-stream"; + } + + inline bool read_file_to_string(const std::string& path, std::string& out) { + std::ifstream f(path, std::ios::binary); + if (!f) + return false; + std::ostringstream ss; + ss << f.rdbuf(); + out = ss.str(); + return true; + } } +JFJochBrokerHttp::JFJochBrokerHttp(const DiffractionExperiment &experiment, + const SpotFindingSettings& spot_finding_settings) + : state_machine(experiment, services, logger, spot_finding_settings) {} + void JFJochBrokerHttp::AddDetectorSetup(const DetectorSetup &setup) { state_machine.AddDetectorSetup(setup); logger.Info("Added detector {}", setup.GetDescription()); @@ -31,42 +72,278 @@ JFJochServices &JFJochBrokerHttp::Services() { return services; } -void JFJochBrokerHttp::cancel_post(Pistache::Http::ResponseWriter &response) { +JFJochBrokerHttp &JFJochBrokerHttp::FrontendDirectory(const std::string &directory) { + frontend_directory = directory; + return *this; +} + +std::pair JFJochBrokerHttp::handleParsingException(const std::exception &ex) const noexcept { + try { + throw; + } catch (nlohmann::detail::exception &e) { + return {400, e.what()}; + } catch (ValidationException &e) { + return {400, e.what()}; + } catch (std::exception &e) { + return {500, e.what()}; + } +} + +std::pair JFJochBrokerHttp::handleOperationException(const std::exception &ex) const noexcept { + try { + throw; + } catch (const WrongDAQStateException &) { + Error_message msg; + msg.setMsg(ex.what()); + msg.setReason("WrongDAQState"); + nlohmann::json j; + to_json(j, msg); + return {500, j.dump()}; + } catch (const std::exception &) { + Error_message msg; + msg.setMsg(ex.what()); + msg.setReason("Other"); + nlohmann::json j; + to_json(j, msg); + return {500, j.dump()}; + } +} + +void JFJochBrokerHttp::attach(httplib::Server& server) { + register_routes(server); + server.set_error_handler([](const httplib::Request &, httplib::Response &res) { + res.status = 404; + res.set_content("The requested method does not exist", "text/plain"); + }); +} + +void JFJochBrokerHttp::register_routes(httplib::Server& server) { + auto bind_noarg = [this](auto method) { + return [this, method](const httplib::Request&, httplib::Response& res) { + try { + (this->*method)(res); + } catch (const std::exception& e) { + auto [c, s] = handleOperationException(e); + res.status = c; + res.set_content(s, "text/plain"); + } + }; + }; + + auto bind_json = [this](auto method, auto model_tag) { + return [this, method](const httplib::Request& req, httplib::Response& res) { + using Model = decltype(model_tag); + try { + Model v; + nlohmann::json::parse(req.body).get_to(v); + v.validate(); + (this->*method)(v, res); + } catch (const std::exception& e) { + auto [c, s] = handleParsingException(e); + res.status = c; + res.set_content(s, "text/plain"); + } + }; + }; + + auto bind_req = [this](auto method) { + return [this, method](const httplib::Request& req, httplib::Response& res) { + try { + (this->*method)(req, res); + } catch (const std::exception& e) { + auto [c, s] = handleOperationException(e); + res.status = c; + res.set_content(s, "text/plain"); + } + }; + }; + + server.Post("/cancel", bind_noarg(&JFJochBrokerHttp::cancel_post)); + server.Get("/config/azim_int", bind_noarg(&JFJochBrokerHttp::config_azim_int_get)); + server.Put("/config/azim_int", bind_json(&JFJochBrokerHttp::config_azim_int_put, Azim_int_settings{})); + server.Get("/config/dark_mask", bind_noarg(&JFJochBrokerHttp::config_dark_mask_get)); + server.Put("/config/dark_mask", bind_json(&JFJochBrokerHttp::config_dark_mask_put, Dark_mask_settings{})); + server.Get("/config/detector", bind_noarg(&JFJochBrokerHttp::config_detector_get)); + server.Put("/config/detector", bind_json(&JFJochBrokerHttp::config_detector_put, Detector_settings{})); + server.Get("/config/file_writer", bind_noarg(&JFJochBrokerHttp::config_file_writer_get)); + server.Put("/config/file_writer", bind_json(&JFJochBrokerHttp::config_file_writer_put, File_writer_settings{})); + server.Post("/config/image_format/conversion", bind_noarg(&JFJochBrokerHttp::config_image_format_conversion_post)); + server.Get("/config/image_format", bind_noarg(&JFJochBrokerHttp::config_image_format_get)); + server.Put("/config/image_format", bind_json(&JFJochBrokerHttp::config_image_format_put, Image_format_settings{})); + server.Post("/config/image_format/raw", bind_noarg(&JFJochBrokerHttp::config_image_format_raw_post)); + server.Get("/config/indexing", bind_noarg(&JFJochBrokerHttp::config_indexing_get)); + server.Put("/config/indexing", bind_json(&JFJochBrokerHttp::config_indexing_put, Indexing_settings{})); + server.Get("/config/instrument", bind_noarg(&JFJochBrokerHttp::config_instrument_get)); + server.Put("/config/instrument", bind_json(&JFJochBrokerHttp::config_instrument_put, Instrument_metadata{})); + server.Put("/config/internal_generator_image", bind_req(&JFJochBrokerHttp::config_internal_generator_image_put)); + server.Put("/config/internal_generator_image.tiff", bind_req(&JFJochBrokerHttp::config_internal_generator_image_tiff_put)); + server.Get("/config/mask", bind_noarg(&JFJochBrokerHttp::config_mask_get)); + server.Get("/config/mask.tiff", bind_noarg(&JFJochBrokerHttp::config_mask_tiff_get)); + server.Get("/config/roi", bind_noarg(&JFJochBrokerHttp::config_roi_get)); + server.Put("/config/roi", bind_json(&JFJochBrokerHttp::config_roi_put, Roi_definitions{})); + server.Get("/config/select_detector", bind_noarg(&JFJochBrokerHttp::config_select_detector_get)); + server.Put("/config/select_detector", bind_json(&JFJochBrokerHttp::config_select_detector_put, Detector_selection{})); + server.Get("/config/spot_finding", bind_noarg(&JFJochBrokerHttp::config_spot_finding_get)); + server.Put("/config/spot_finding", bind_json(&JFJochBrokerHttp::config_spot_finding_put, Spot_finding_settings{})); + server.Get("/config/user_mask", bind_noarg(&JFJochBrokerHttp::config_user_mask_get)); + server.Put("/config/user_mask", bind_req(&JFJochBrokerHttp::config_user_mask_put)); + server.Get("/config/user_mask.tiff", bind_noarg(&JFJochBrokerHttp::config_user_mask_tiff_get)); + server.Put("/config/user_mask.tiff", bind_req(&JFJochBrokerHttp::config_user_mask_tiff_put)); + server.Get("/config/zeromq_metadata", bind_noarg(&JFJochBrokerHttp::config_zeromq_metadata_get)); + server.Put("/config/zeromq_metadata", bind_json(&JFJochBrokerHttp::config_zeromq_metadata_put, Zeromq_metadata_settings{})); + server.Get("/config/zeromq_preview", bind_noarg(&JFJochBrokerHttp::config_zeromq_preview_get)); + server.Put("/config/zeromq_preview", bind_json(&JFJochBrokerHttp::config_zeromq_preview_put, Zeromq_preview_settings{})); + server.Post("/deactivate", bind_noarg(&JFJochBrokerHttp::deactivate_post)); + server.Get("/detector/status", bind_noarg(&JFJochBrokerHttp::detector_status_get)); + server.Get("/fpga_status", bind_noarg(&JFJochBrokerHttp::fpga_status_get)); + server.Post("/image_buffer/clear", bind_noarg(&JFJochBrokerHttp::image_buffer_clear_post)); + server.Get("/image_buffer/image.cbor", [this](const httplib::Request& req, httplib::Response& res) { + try { + image_buffer_image_cbor_get(query_optional(req, "id"), res); + } catch (const std::exception& e) { + auto [c, s] = handleOperationException(e); + res.status = c; + res.set_content(s, "text/plain"); + } + }); + server.Get("/image_buffer/image.jpeg", [this](const httplib::Request& req, httplib::Response& res) { + try { + image_buffer_image_jpeg_get( + query_optional(req, "id"), + query_optional(req, "show_user_mask"), + query_optional(req, "show_roi"), + query_optional(req, "show_spots"), + query_optional(req, "show_beam_center"), + query_optional(req, "saturation"), + query_optional(req, "jpeg_quality"), + query_optional(req, "show_res_ring"), + query_optional_string(req, "color"), + query_optional(req, "show_res_est"), + res + ); + } catch (const std::exception& e) { + auto [c, s] = handleOperationException(e); + res.status = c; + res.set_content(s, "text/plain"); + } + }); + server.Get("/image_buffer/image.tiff", [this](const httplib::Request& req, httplib::Response& res) { + try { + image_buffer_image_tiff_get(query_optional(req, "id"), res); + } catch (const std::exception& e) { + auto [c, s] = handleOperationException(e); + res.status = c; + res.set_content(s, "text/plain"); + } + }); + server.Get("/image_buffer/start.cbor", bind_noarg(&JFJochBrokerHttp::image_buffer_start_cbor_get)); + server.Get("/image_buffer/status", bind_noarg(&JFJochBrokerHttp::image_buffer_status_get)); + server.Get("/image_pusher/status", bind_noarg(&JFJochBrokerHttp::image_pusher_status_get)); + server.Post("/initialize", bind_noarg(&JFJochBrokerHttp::initialize_post)); + server.Post("/pedestal", bind_noarg(&JFJochBrokerHttp::pedestal_post)); + server.Get("/preview/pedestal.tiff", [this](const httplib::Request& req, httplib::Response& res) { + try { + preview_pedestal_tiff_get(query_optional(req, "gain_level"), + query_optional(req, "sc"), res); + } catch (const std::exception& e) { + auto [c, s] = handleOperationException(e); + res.status = c; + res.set_content(s, "text/plain"); + } + }); + server.Get("/preview/plot.bin", [this](const httplib::Request& req, httplib::Response& res) { + try { + preview_plot_bin_get(query_optional_string(req, "type"), + query_optional_string(req, "roi"), + res); + } catch (const std::exception& e) { + auto [c, s] = handleOperationException(e); + res.status = c; + res.set_content(s, "text/plain"); + } + }); + server.Get("/preview/plot", [this](const httplib::Request& req, httplib::Response& res) { + try { + preview_plot_get(query_optional_string(req, "type"), + query_optional(req, "binning"), + query_optional(req, "compression"), + query_optional(req, "fill"), + query_optional(req, "experimental_coord"), + query_optional_string(req, "azint_unit"), + res); + } catch (const std::exception& e) { + auto [c, s] = handleOperationException(e); + res.status = c; + res.set_content(s, "text/plain"); + } + }); + server.Get("/result/scan", bind_noarg(&JFJochBrokerHttp::result_scan_get)); + server.Post("/start", bind_json(&JFJochBrokerHttp::start_post, Dataset_settings{})); + server.Get("/statistics/calibration", bind_noarg(&JFJochBrokerHttp::statistics_calibration_get)); + server.Get("/statistics/data_collection", bind_noarg(&JFJochBrokerHttp::statistics_data_collection_get)); + server.Get("/statistics", [this](const httplib::Request& req, httplib::Response& res) { + try { + statistics_get(query_optional(req, "compression"), res); + } catch (const std::exception& e) { + auto [c, s] = handleOperationException(e); + res.status = c; + res.set_content(s, "text/plain"); + } + }); + server.Get("/status", bind_noarg(&JFJochBrokerHttp::status_get)); + server.Post("/trigger", bind_noarg(&JFJochBrokerHttp::trigger_post)); + server.Get("/version", bind_noarg(&JFJochBrokerHttp::version_get)); + server.Post("/wait_till_done", [this](const httplib::Request& req, httplib::Response& res) { + try { + wait_till_done_post(query_optional(req, "timeout"), res); + } catch (const std::exception& e) { + auto [c, s] = handleOperationException(e); + res.status = c; + res.set_content(s, "text/plain"); + } + }); + server.Get("/xfel/event_code", bind_noarg(&JFJochBrokerHttp::xfel_event_code_get)); + server.Get("/xfel/pulse_id", bind_noarg(&JFJochBrokerHttp::xfel_pulse_id_get)); + + server.Get("/", [this](const httplib::Request& req, httplib::Response& res) { GetStaticFile(req, res); }); + server.Get("/frontend", [this](const httplib::Request& req, httplib::Response& res) { GetStaticFile(req, res); }); + server.Get("/frontend/*", [this](const httplib::Request& req, httplib::Response& res) { GetStaticFile(req, res); }); + server.Get("/frontend/assets/*", [this](const httplib::Request& req, httplib::Response& res) { GetStaticFile(req, res); }); +} + +void JFJochBrokerHttp::cancel_post(httplib::Response &response) { state_machine.Cancel(); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::deactivate_post(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::deactivate_post(httplib::Response &response) { state_machine.Deactivate(); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::initialize_post(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::initialize_post(httplib::Response &response) { state_machine.Initialize(); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::start_post(const org::openapitools::server::model::Dataset_settings &datasetSettings, - Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::start_post(const Dataset_settings &datasetSettings, httplib::Response &response) { nlohmann::json j = datasetSettings; logger.Info("Start {}", j.dump()); state_machine.Start(Convert(datasetSettings)); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::status_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::status_get(httplib::Response &response) { ProcessOutput(Convert(state_machine.GetStatus()), response); } - - void JFJochBrokerHttp::wait_till_done_post(const std::optional &timeout, - Pistache::Http::ResponseWriter &response) { + httplib::Response &response) { BrokerStatus status; if (!timeout) status = state_machine.WaitTillMeasurementDone(std::chrono::minutes(1)); else if ((timeout.value() > 3600) || (timeout.value() < 0)) { - response.send(Pistache::Http::Code::Bad_Request); + response.status = 400; return; } else if (timeout.value() == 0) status = state_machine.GetStatus(); @@ -75,321 +352,128 @@ void JFJochBrokerHttp::wait_till_done_post(const std::optional &timeout switch (status.state) { case JFJochState::Idle: - response.send(Pistache::Http::Code::Ok); + response.status = 200; break; case JFJochState::Inactive: - response.send(Pistache::Http::Code::Bad_Gateway); + response.status = 502; break; case JFJochState::Error: throw WrongDAQStateException(status.message.value_or("Unknown error")); case JFJochState::Measuring: case JFJochState::Busy: case JFJochState::Calibration: - response.send(Pistache::Http::Code::Gateway_Timeout); + response.status = 504; break; } } -void JFJochBrokerHttp::trigger_post(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::trigger_post(httplib::Response &response) { state_machine.Trigger(); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::pedestal_post(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::pedestal_post(httplib::Response &response) { state_machine.Pedestal(); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::config_detector_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_detector_get(httplib::Response &response) { ProcessOutput(Convert(state_machine.GetDetectorSettings()), response); } -void JFJochBrokerHttp::config_detector_put(const org::openapitools::server::model::Detector_settings &detectorSettings, - Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_detector_put(const Detector_settings &detectorSettings, + httplib::Response &response) { state_machine.LoadDetectorSettings(Convert(detectorSettings)); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::config_azim_int_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_azim_int_get(httplib::Response &response) { ProcessOutput(Convert(state_machine.GetRadialIntegrationSettings()), response); } -void JFJochBrokerHttp::config_azim_int_put(const org::openapitools::server::model::Azim_int_settings &radIntSettings, - Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_azim_int_put(const Azim_int_settings &radIntSettings, + httplib::Response &response) { state_machine.SetRadialIntegrationSettings(Convert(radIntSettings)); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::config_select_detector_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_select_detector_get(httplib::Response &response) { ProcessOutput(Convert(state_machine.GetDetectorsList()), response); } -void JFJochBrokerHttp::config_select_detector_put( - const org::openapitools::server::model::Detector_selection &detectorSelection, - Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_select_detector_put(const Detector_selection &detectorSelection, + httplib::Response &response) { state_machine.SelectDetector(detectorSelection.getId()); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::config_spot_finding_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_spot_finding_get(httplib::Response &response) { ProcessOutput(Convert(state_machine.GetSpotFindingSettings()), response); } -void JFJochBrokerHttp::config_spot_finding_put( - const org::openapitools::server::model::Spot_finding_settings &spotFindingSettings, - Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_spot_finding_put(const Spot_finding_settings &spotFindingSettings, + httplib::Response &response) { state_machine.SetSpotFindingSettings(Convert(spotFindingSettings)); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::statistics_calibration_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::statistics_calibration_get(httplib::Response &response) { nlohmann::json j; for (const auto &d: Convert(state_machine.GetCalibrationStatistics())) j.push_back(d); - response.send(Pistache::Http::Code::Ok, j.dump(), MIME(Application, Json)); + response.set_content(j.dump(), "application/json"); + response.status = 200; } -void JFJochBrokerHttp::statistics_data_collection_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::statistics_data_collection_get(httplib::Response &response) { auto stats = state_machine.GetMeasurementStatistics(); if (stats) { ProcessOutput(Convert(stats.value()), response); } else { - response.send(Pistache::Http::Code::Not_Found); + response.status = 404; } } -std::pair -JFJochBrokerHttp::handleOperationException(const std::exception &ex) const noexcept { - try { - throw; - } catch (const WrongDAQStateException &e) { - org::openapitools::server::model::Error_message msg; - msg.setMsg(ex.what()); - msg.setReason("WrongDAQState"); - nlohmann::json j; - to_json(j, msg); - return std::make_pair(Pistache::Http::Code::Internal_Server_Error, j.dump()); - } catch (const std::exception &e) { - org::openapitools::server::model::Error_message msg; - msg.setMsg(ex.what()); - msg.setReason("Other"); - nlohmann::json j; - to_json(j, msg); - return std::make_pair(Pistache::Http::Code::Internal_Server_Error, j.dump()); - } +void JFJochBrokerHttp::config_file_writer_get(httplib::Response &response) { + ProcessOutput(Convert(state_machine.GetFileWriterSettings()), response); } -void JFJochBrokerHttp::GetStaticFile(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) { - if (!frontend_directory.empty()) { - logger.Info("Requesting static resource {} from {}", request.resource(), frontend_directory); - if (request.resource().find("../") != std::string::npos) - response.send(Pistache::Http::Code::Forbidden); - try { - if ((request.resource() == "/") - || (request.resource() == "/frontend") - || (request.resource() == "/frontend/")) - Pistache::Http::serveFile(response, frontend_directory + "/index.html", MIME(Text, Html)); - else if (request.resource().starts_with("/frontend/")) { - if (request.resource().ends_with(".js")) - Pistache::Http::serveFile(response, frontend_directory + "/" + request.resource().substr(10), - MIME(Text,Javascript)); - else if (request.resource().ends_with(".css")) - Pistache::Http::serveFile(response, frontend_directory + "/" + request.resource().substr(10), - MIME(Text,Css)); - else if (request.resource().ends_with(".html")) - Pistache::Http::serveFile(response, frontend_directory + "/" + request.resource().substr(10), - MIME(Text,Html)); - else - Pistache::Http::serveFile(response, frontend_directory + "/" + request.resource().substr(10)); - - } - else response.send(Pistache::Http::Code::Not_Found); - } catch (const std::exception &e) { - logger.Error(e.what()); - response.send(Pistache::Http::Code::Not_Found); - } - } else response.send(Pistache::Http::Code::Not_Found); +void JFJochBrokerHttp::config_file_writer_put(const File_writer_settings &fileWriterSettings, + httplib::Response &response) { + state_machine.LoadFileWriterSettings(Convert(fileWriterSettings)); + response.status = 200; } -JFJochBrokerHttp &JFJochBrokerHttp::FrontendDirectory(const std::string &directory) { - frontend_directory = directory; - return *this; -} - -void JFJochBrokerHttp::detector_status_get(Pistache::Http::ResponseWriter &response) { - auto out = state_machine.GetDetectorStatus(); - if (out) - ProcessOutput(Convert(out.value()), response); - else - response.send(Pistache::Http::Code::Not_Found); -} - - -void JFJochBrokerHttp::config_internal_generator_image_put(const Pistache::Rest::Request &request, - Pistache::Http::ResponseWriter &response) { - int64_t image_number = 0; - auto number_query = request.query().get("id"); - if (number_query) - image_number = std::stoi(number_query.value()); - - if ((image_number < 0) || (image_number > 127)) - throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "id must be in range 0-127"); - - state_machine.LoadInternalGeneratorImage(request.body().data(), request.body().size(), image_number); - logger.Info("Internal generator image #{} loaded", image_number); - response.send(Pistache::Http::Code::Ok); -} - - -void JFJochBrokerHttp::config_internal_generator_image_tiff_put(const Pistache::Rest::Request &request, - Pistache::Http::ResponseWriter &response) { - int64_t image_number = 0; - auto number_query = request.query().get("id"); - if (number_query) - image_number = std::stoi(number_query.value()); - - if ((image_number < 0) || (image_number > 127)) - throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "id must be in range 0-127"); - - state_machine.LoadInternalGeneratorImageTIFF(request.body(), image_number); - response.send(Pistache::Http::Code::Ok); -} - -void JFJochBrokerHttp::config_roi_get(Pistache::Http::ResponseWriter &response) { - ProcessOutput(Convert(state_machine.GetROIDefintion()), response); -} - -void JFJochBrokerHttp::config_roi_put(const org::openapitools::server::model::Roi_definitions &roiDefinitions, - -Pistache::Http::ResponseWriter &response) { - state_machine.SetROIDefinition(Convert(roiDefinitions)); - response.send(Pistache::Http::Code::Ok); -} - -void JFJochBrokerHttp::xfel_event_code_get(Pistache::Http::ResponseWriter &response) { - auto array = state_machine.GetXFELEventCode(); - if (array.empty()) - response.send(Pistache::Http::Code::Not_Found); - nlohmann::json j = array; - response.send(Pistache::Http::Code::Ok, j.dump(), MIME(Application, Json)); -} - -void JFJochBrokerHttp::xfel_pulse_id_get(Pistache::Http::ResponseWriter &response) { - auto array = state_machine.GetXFELPulseID(); - if (array.empty()) - response.send(Pistache::Http::Code::Not_Found); - nlohmann::json j = array; - response.send(Pistache::Http::Code::Ok, j.dump(), MIME(Application, Json)); -} - -void JFJochBrokerHttp::preview_pedestal_tiff_get(const std::optional &gainLevel, - const std::optional &sc, - Pistache::Http::ResponseWriter &response) { - if (!gainLevel) - response.send(Pistache::Http::Code::Bad_Request); - std::string s = state_machine.GetPedestalTIFF(gainLevel.value(), sc ? sc.value() : 0); - if (!s.empty()) - response.send(Pistache::Http::Code::Ok, s, Pistache::Http::Mime::MediaType::fromString("image/tiff")); - else - response.send(Pistache::Http::Code::Not_Found); -} - -void JFJochBrokerHttp::config_mask_tiff_get(Pistache::Http::ResponseWriter &response) { - auto s = state_machine.GetFullPixelMaskTIFF(); - response.send(Pistache::Http::Code::Ok, s, Pistache::Http::Mime::MediaType::fromString("image/tiff")); -} - -void JFJochBrokerHttp::config_user_mask_tiff_get(Pistache::Http::ResponseWriter &response) { - auto s = state_machine.GetUserPixelMaskTIFF(); - response.send(Pistache::Http::Code::Ok, s, Pistache::Http::Mime::MediaType::fromString("image/tiff")); -} - -void JFJochBrokerHttp::config_user_mask_tiff_put(const Pistache::Rest::Request &request, - Pistache::Http::ResponseWriter &response) { - uint32_t cols, lines; - auto v = ReadTIFFFromString32(request.body(), cols, lines); - state_machine.SetUserPixelMask(v); - response.send(Pistache::Http::Code::Ok); -} - -void JFJochBrokerHttp::config_mask_get(Pistache::Http::ResponseWriter &response) { - const auto v = state_machine.GetFullPixelMask(); - response.send(Pistache::Http::Code::Ok, - reinterpret_cast(v.data()), - v.size() * sizeof(uint32_t), - Pistache::Http::Mime::MediaType::fromString("application/octet-stream")); -} - -void JFJochBrokerHttp::config_user_mask_get(Pistache::Http::ResponseWriter &response) { - const auto v = state_machine.GetUserPixelMask(); - response.send(Pistache::Http::Code::Ok, - reinterpret_cast(v.data()), - v.size() * sizeof(uint32_t), - Pistache::Http::Mime::MediaType::fromString("application/octet-stream")); -} - -void JFJochBrokerHttp::config_user_mask_put(const Pistache::Rest::Request &request, - Pistache::Http::ResponseWriter &response) { - if (request.body().empty()) { - response.send(Pistache::Http::Code::Bad_Request, "Request body cannot be empty"); - return; - } - - if (request.body().size() % 4 != 0) { - response.send(Pistache::Http::Code::Bad_Request, "Request has to be 32-bit"); - return; - } - - std::vector v(request.body().size() / 4); - memcpy(v.data(), request.body().data(), request.body().size()); - state_machine.SetUserPixelMask(v); - response.send(Pistache::Http::Code::Ok); -} - -void JFJochBrokerHttp::version_get(Pistache::Http::ResponseWriter &response) { - response.send(Pistache::Http::Code::Ok, jfjoch_version(), MIME(Text, Plain)); -} - -void JFJochBrokerHttp::config_instrument_get(Pistache::Http::ResponseWriter &response) { - ProcessOutput(Convert(state_machine.GetInstrumentMetadata()), response); -} - -void JFJochBrokerHttp::config_instrument_put(const org::openapitools::server::model::Instrument_metadata - &instrumentMetadata,Pistache::Http::ResponseWriter &response) { - state_machine.LoadInstrumentMetadata(Convert(instrumentMetadata)); - response.send(Pistache::Http::Code::Ok); -} - -void JFJochBrokerHttp::config_image_format_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_image_format_get(httplib::Response &response) { ProcessOutput(Convert(state_machine.GetImageFormatSettings()), response); } -void JFJochBrokerHttp::config_image_format_put( - const org::openapitools::server::model::Image_format_settings &imageFormatSettings, - Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_image_format_put(const Image_format_settings &imageFormatSettings, + httplib::Response &response) { state_machine.LoadImageFormatSettings(Convert(imageFormatSettings)); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::config_image_format_conversion_post(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_image_format_conversion_post(httplib::Response &response) { state_machine.ConvImageFormatSettings(); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::config_image_format_raw_post(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_image_format_raw_post(httplib::Response &response) { state_machine.RawImageFormatSettings(); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::fpga_status_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::fpga_status_get(httplib::Response &response) { nlohmann::json j; for (const auto &d: Convert(state_machine.GetDeviceStatus())) j.push_back(d); - response.send(Pistache::Http::Code::Ok, j.dump(), MIME(Application, Json)); + response.set_content(j.dump(), "application/json"); + response.status = 200; } -void JFJochBrokerHttp::statistics_get(const std::optional &compression, Pistache::Http::ResponseWriter &response) { - org::openapitools::server::model::Jfjoch_statistics statistics; +void JFJochBrokerHttp::statistics_get(const std::optional &compression, httplib::Response &response) { + Jfjoch_statistics statistics; auto data_collection_statistics = state_machine.GetMeasurementStatistics(); if (data_collection_statistics) @@ -427,49 +511,47 @@ void JFJochBrokerHttp::statistics_get(const std::optional &compression, Pi nlohmann::json j = statistics; if (!compression.has_value() || compression.value()) - response.setCompression(Pistache::Http::Header::Encoding::Deflate); + response.set_header("Content-Encoding", "deflate"); - response.send(Pistache::Http::Code::Ok, j.dump(), MIME(Application, Json)); + response.set_content(j.dump(), "application/json"); + response.status = 200; } -void JFJochBrokerHttp::config_zeromq_preview_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_zeromq_preview_get(httplib::Response &response) { ProcessOutput(Convert(state_machine.GetPreviewSocketSettings()), response); } -void JFJochBrokerHttp::config_zeromq_preview_put( - const org::openapitools::server::model::Zeromq_preview_settings &zeromqPreviewSettings, - Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_zeromq_preview_put(const Zeromq_preview_settings &zeromqPreviewSettings, + httplib::Response &response) { state_machine.SetPreviewSocketSettings(Convert(zeromqPreviewSettings)); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::config_zeromq_metadata_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_zeromq_metadata_get(httplib::Response &response) { ProcessOutput(Convert(state_machine.GetMetadataSocketSettings()), response); } -void JFJochBrokerHttp::config_zeromq_metadata_put( - const org::openapitools::server::model::Zeromq_metadata_settings &zeromqMetadataSettings, - Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_zeromq_metadata_put(const Zeromq_metadata_settings &zeromqMetadataSettings, + httplib::Response &response) { state_machine.SetMetadataSocketSettings(Convert(zeromqMetadataSettings)); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } -void JFJochBrokerHttp::image_buffer_clear_post(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::image_buffer_clear_post(httplib::Response &response) { state_machine.ClearImageBuffer(); - response.send(Pistache::Http::Code::Ok); + response.status = 200; } void JFJochBrokerHttp::image_buffer_image_cbor_get(const std::optional &imageNumber, - Pistache::Http::ResponseWriter &response) { + httplib::Response &response) { std::vector tmp_vector; state_machine.GetImageFromBuffer(tmp_vector, imageNumber.value_or(-1)); - std::string s = std::string((char *) tmp_vector.data(), tmp_vector.size()); + std::string s(reinterpret_cast(tmp_vector.data()), tmp_vector.size()); if (!s.empty()) - response.send(Pistache::Http::Code::Ok, s, - Pistache::Http::Mime::MediaType::fromString("application/cbor")); + response.set_content(s, "application/cbor"); else - response.send(Pistache::Http::Code::Not_Found); + response.status = 404; } void JFJochBrokerHttp::image_buffer_image_jpeg_get(const std::optional &id, @@ -482,7 +564,7 @@ void JFJochBrokerHttp::image_buffer_image_jpeg_get(const std::optional const std::optional &showResRing, const std::optional &color, const std::optional &showResEst, - Pistache::Http::ResponseWriter &response) { + httplib::Response &response) { int64_t image_id = id.value_or(ImageBuffer::MaxImage); PreviewImageSettings settings{}; @@ -501,57 +583,190 @@ void JFJochBrokerHttp::image_buffer_image_jpeg_get(const std::optional settings.scale = ConvertColorScale(color); settings.show_beam_center = showBeamCenter.value_or(true); settings.format = PreviewImageFormat::JPEG; + std::string s = state_machine.GetPreviewJPEG(settings, image_id); if (!s.empty()) - response.send(Pistache::Http::Code::Ok, s, Pistache::Http::Mime::MediaType::fromString("image/jpeg")); + response.set_content(s, "image/jpeg"); else - response.send(Pistache::Http::Code::Not_Found); + response.status = 404; } -void -JFJochBrokerHttp::image_buffer_image_tiff_get(const std::optional &id, Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::image_buffer_image_tiff_get(const std::optional &id, + httplib::Response &response) { int64_t image_id = ImageBuffer::MaxImage; if (id.has_value()) image_id = id.value(); std::string s = state_machine.GetPreviewTIFF(image_id); if (!s.empty()) - response.send(Pistache::Http::Code::Ok, s, Pistache::Http::Mime::MediaType::fromString("image/tiff")); + response.set_content(s, "image/tiff"); else - response.send(Pistache::Http::Code::Not_Found); + response.status = 404; } -void JFJochBrokerHttp::image_buffer_start_cbor_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::image_buffer_start_cbor_get(httplib::Response &response) { std::vector tmp_vector; state_machine.GetStartMessageFromBuffer(tmp_vector); - std::string s = std::string((char *) tmp_vector.data(), tmp_vector.size()); + std::string s(reinterpret_cast(tmp_vector.data()), tmp_vector.size()); if (!s.empty()) - response.send(Pistache::Http::Code::Ok, s, - Pistache::Http::Mime::MediaType::fromString("application/cbor")); + response.set_content(s, "application/cbor"); else - response.send(Pistache::Http::Code::Not_Found); + response.status = 404; } -void JFJochBrokerHttp::image_buffer_status_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::image_buffer_status_get(httplib::Response &response) { ProcessOutput(Convert(state_machine.GetImageBufferStatus()), response); } -void JFJochBrokerHttp::config_file_writer_get(Pistache::Http::ResponseWriter &response) { - ProcessOutput(Convert(state_machine.GetFileWriterSettings()), response); +void JFJochBrokerHttp::image_pusher_status_get(httplib::Response &response) { + ProcessOutput(Convert(state_machine.GetImagePusherStatus()), response); } -void JFJochBrokerHttp::config_file_writer_put( - const org::openapitools::server::model::File_writer_settings &fileWriterSettings, - Pistache::Http::ResponseWriter &response) { - state_machine.LoadFileWriterSettings(Convert(fileWriterSettings)); - response.send(Pistache::Http::Code::Ok); +void JFJochBrokerHttp::config_mask_tiff_get(httplib::Response &response) { + auto s = state_machine.GetFullPixelMaskTIFF(); + response.set_content(s, "image/tiff"); + response.status = 200; } -void JFJochBrokerHttp::preview_plot_get(const std::optional &type, const std::optional &binning, - const std::optional &compression, const std::optional &fill, - const std::optional &experimentalCoord, - const std::optional &azintUnit, Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_user_mask_tiff_get(httplib::Response &response) { + auto s = state_machine.GetUserPixelMaskTIFF(); + response.set_content(s, "image/tiff"); + response.status = 200; +} + +void JFJochBrokerHttp::config_user_mask_tiff_put(const httplib::Request &request, + httplib::Response &response) { + uint32_t cols, lines; + auto v = ReadTIFFFromString32(request.body, cols, lines); + state_machine.SetUserPixelMask(v); + response.status = 200; +} + +void JFJochBrokerHttp::config_mask_get(httplib::Response &response) { + const auto v = state_machine.GetFullPixelMask(); + response.set_content(reinterpret_cast(v.data()), + v.size() * sizeof(uint32_t), + "application/octet-stream"); + response.status = 200; +} + +void JFJochBrokerHttp::config_user_mask_get(httplib::Response &response) { + const auto v = state_machine.GetUserPixelMask(); + response.set_content(reinterpret_cast(v.data()), + v.size() * sizeof(uint32_t), + "application/octet-stream"); + response.status = 200; +} + +void JFJochBrokerHttp::config_user_mask_put(const httplib::Request &request, + httplib::Response &response) { + if (request.body.empty()) { + response.status = 400; + response.set_content("Request body cannot be empty", "text/plain"); + return; + } + + if (request.body.size() % 4 != 0) { + response.status = 400; + response.set_content("Request has to be 32-bit", "text/plain"); + return; + } + + std::vector v(request.body.size() / 4); + std::memcpy(v.data(), request.body.data(), request.body.size()); + state_machine.SetUserPixelMask(v); + response.status = 200; +} + +void JFJochBrokerHttp::version_get(httplib::Response &response) { + response.set_content(jfjoch_version(), "text/plain"); + response.status = 200; +} + +void JFJochBrokerHttp::config_instrument_get(httplib::Response &response) { + ProcessOutput(Convert(state_machine.GetInstrumentMetadata()), response); +} + +void JFJochBrokerHttp::config_instrument_put(const Instrument_metadata &instrumentMetadata, + httplib::Response &response) { + state_machine.LoadInstrumentMetadata(Convert(instrumentMetadata)); + response.status = 200; +} + +void JFJochBrokerHttp::config_indexing_get(httplib::Response &response) { + ProcessOutput(Convert(state_machine.GetIndexingSettings()), response); +} + +void JFJochBrokerHttp::config_indexing_put(const Indexing_settings &indexingSettings, + httplib::Response &response) { + state_machine.SetIndexingSettings(Convert(indexingSettings)); + response.status = 200; +} + +void JFJochBrokerHttp::result_scan_get(httplib::Response &response) { + auto ret = state_machine.GetScanResult(); + if (ret.has_value()) + ProcessOutput(Convert(ret.value()), response, true); + else + response.status = 404; +} + +void JFJochBrokerHttp::config_dark_mask_put(const Dark_mask_settings &darkMaskSettings, + httplib::Response &response) { + state_machine.SetDarkMaskSettings(Convert(darkMaskSettings)); + response.status = 200; +} + +void JFJochBrokerHttp::config_dark_mask_get(httplib::Response &response) { + ProcessOutput(Convert(state_machine.GetDarkMaskSettings()), response); +} + +void JFJochBrokerHttp::detector_status_get(httplib::Response &response) { + auto out = state_machine.GetDetectorStatus(); + if (out) + ProcessOutput(Convert(out.value()), response); + else + response.status = 404; +} + +void JFJochBrokerHttp::preview_pedestal_tiff_get(const std::optional &gainLevel, + const std::optional &sc, + httplib::Response &response) { + if (!gainLevel) { + response.status = 400; + return; + } + + std::string s = state_machine.GetPedestalTIFF(gainLevel.value(), sc ? sc.value() : 0); + if (!s.empty()) + response.set_content(s, "image/tiff"); + else + response.status = 404; +} + +void JFJochBrokerHttp::preview_plot_bin_get(const std::optional &type, + const std::optional &roi, + httplib::Response &response) { + std::vector ret; + state_machine.GetPlotRaw(ret, ConvertPlotType(type), roi.value_or("")); + + if (ret.empty()) + response.status = 200; + else + response.set_content(reinterpret_cast(ret.data()), + ret.size() * sizeof(float), + "application/octet-stream"); + response.status = 200; +} + +void JFJochBrokerHttp::preview_plot_get(const std::optional &type, + const std::optional &binning, + const std::optional &compression, + const std::optional &fill, + const std::optional &experimentalCoord, + const std::optional &azintUnit, + httplib::Response &response) { PlotAzintUnit unit = PlotAzintUnit::Q_recipA; if (azintUnit.has_value()) { if (azintUnit == "Q_recipA" || azintUnit == "q_recipa") @@ -576,52 +791,122 @@ void JFJochBrokerHttp::preview_plot_get(const std::optional &type, "Binning must be positive number or zero"); req.binning = binning.value(); } + auto plot = state_machine.GetPlots(req); ProcessOutput(Convert(plot), response, compression.value_or(false)); } -void JFJochBrokerHttp::preview_plot_bin_get(const std::optional &type, - const std::optional &roi, - Pistache::Http::ResponseWriter &response) { - std::vector ret; - state_machine.GetPlotRaw(ret, ConvertPlotType(type), roi.value_or("")); - - if (ret.empty()) - response.send(Pistache::Http::Code::Ok); - else - response.send(Pistache::Http::Code::Ok, - reinterpret_cast(ret.data()), - ret.size() * sizeof(float), - Pistache::Http::Mime::MediaType::fromString("application/octet-stream")); +void JFJochBrokerHttp::config_roi_get(httplib::Response &response) { + ProcessOutput(Convert(state_machine.GetROIDefintion()), response); } -void JFJochBrokerHttp::config_indexing_get(Pistache::Http::ResponseWriter &response) { - ProcessOutput(Convert(state_machine.GetIndexingSettings()), response); +void JFJochBrokerHttp::config_roi_put(const Roi_definitions &roiDefinitions, + httplib::Response &response) { + state_machine.SetROIDefinition(Convert(roiDefinitions)); + response.status = 200; } -void JFJochBrokerHttp::config_indexing_put(const org::openapitools::server::model::Indexing_settings &indexingSettings, - Pistache::Http::ResponseWriter &response) { - state_machine.SetIndexingSettings(Convert(indexingSettings)); - response.send(Pistache::Http::Code::Ok); +void JFJochBrokerHttp::xfel_event_code_get(httplib::Response &response) { + auto array = state_machine.GetXFELEventCode(); + if (array.empty()) { + response.status = 404; + return; + } + nlohmann::json j = array; + response.set_content(j.dump(), "application/json"); + response.status = 200; } -void JFJochBrokerHttp::result_scan_get(Pistache::Http::ResponseWriter &response) { - auto ret = state_machine.GetScanResult(); - if (ret.has_value()) - ProcessOutput(Convert(ret.value()), response, true); - else - response.send(Pistache::Http::Code::Not_Found); +void JFJochBrokerHttp::xfel_pulse_id_get(httplib::Response &response) { + auto array = state_machine.GetXFELPulseID(); + if (array.empty()) { + response.status = 404; + return; + } + nlohmann::json j = array; + response.set_content(j.dump(), "application/json"); + response.status = 200; } -void JFJochBrokerHttp::config_dark_mask_put(const org::openapitools::server::model::Dark_mask_settings &darkMaskSettings, Pistache::Http::ResponseWriter &response) { - state_machine.SetDarkMaskSettings(Convert(darkMaskSettings)); - response.send(Pistache::Http::Code::Ok); +void JFJochBrokerHttp::config_zeromq_preview_put(const Zeromq_preview_settings &zeromqPreviewSettings, + httplib::Response &response) { + state_machine.SetPreviewSocketSettings(Convert(zeromqPreviewSettings)); + response.status = 200; } -void JFJochBrokerHttp::config_dark_mask_get(Pistache::Http::ResponseWriter &response) { - ProcessOutput(Convert(state_machine.GetDarkMaskSettings()), response); +void JFJochBrokerHttp::config_zeromq_metadata_put(const Zeromq_metadata_settings &zeromqMetadataSettings, + httplib::Response &response) { + state_machine.SetMetadataSocketSettings(Convert(zeromqMetadataSettings)); + response.status = 200; } -void JFJochBrokerHttp::image_pusher_status_get(Pistache::Http::ResponseWriter &response) { +void JFJochBrokerHttp::config_zeromq_preview_get(httplib::Response &response) { + ProcessOutput(Convert(state_machine.GetPreviewSocketSettings()), response); +} + +void JFJochBrokerHttp::config_zeromq_metadata_get(httplib::Response &response) { + ProcessOutput(Convert(state_machine.GetMetadataSocketSettings()), response); +} + +void JFJochBrokerHttp::image_buffer_clear_post(httplib::Response &response) { + state_machine.ClearImageBuffer(); + response.status = 200; +} + +void JFJochBrokerHttp::config_file_writer_get(httplib::Response &response) { + ProcessOutput(Convert(state_machine.GetFileWriterSettings()), response); +} + +void JFJochBrokerHttp::config_file_writer_put(const File_writer_settings &fileWriterSettings, + httplib::Response &response) { + state_machine.LoadFileWriterSettings(Convert(fileWriterSettings)); + response.status = 200; +} + +void JFJochBrokerHttp::image_pusher_status_get(httplib::Response &response) { ProcessOutput(Convert(state_machine.GetImagePusherStatus()), response); } + +void JFJochBrokerHttp::image_buffer_status_get(httplib::Response &response) { + ProcessOutput(Convert(state_machine.GetImageBufferStatus()), response); +} + +void JFJochBrokerHttp::GetStaticFile(const httplib::Request &request, httplib::Response &response) { + if (frontend_directory.empty()) { + response.status = 404; + return; + } + + logger.Info("Requesting static resource {} from {}", request.path, frontend_directory); + + if (request.path.find("../") != std::string::npos) { + response.status = 403; + return; + } + + std::string rel; + if (request.path == "/" || request.path == "/frontend" || request.path == "/frontend/") + rel = "index.html"; + else if (request.path.starts_with("/frontend/")) + rel = request.path.substr(std::string("/frontend/").size()); + else { + response.status = 404; + return; + } + + const std::string full = frontend_directory + "/" + rel; + + try { + std::string body; + if (!read_file_to_string(full, body)) { + response.status = 404; + return; + } + + response.set_content(std::move(body), mime_from_path(full)); + response.status = 200; + } catch (const std::exception &e) { + logger.Error(e.what()); + response.status = 404; + } +} diff --git a/broker/JFJochBrokerHttp.h b/broker/JFJochBrokerHttp.h index d68b7e96..e5fd6d11 100644 --- a/broker/JFJochBrokerHttp.h +++ b/broker/JFJochBrokerHttp.h @@ -2,207 +2,286 @@ // SPDX-License-Identifier: GPL-3.0-only // Using OpenAPI licensed with Apache License 2.0 -#ifndef JUNGFRAUJOCH_JFJOCHBROKERHTTP_H -#define JUNGFRAUJOCH_JFJOCHBROKERHTTP_H +#pragma once -#include -#include -#include -#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include #include "../common/Logger.h" #include "JFJochStateMachine.h" -#include "gen/api/DefaultApi.h" +#include "JFJochServices.h" +#include "OpenAPIConvert.h" + +#include "gen/model/Azim_int_settings.h" +#include "gen/model/Broker_status.h" +#include "gen/model/Calibration_statistics_inner.h" +#include "gen/model/Dark_mask_settings.h" +#include "gen/model/Dataset_settings.h" +#include "gen/model/Detector_list.h" +#include "gen/model/Detector_selection.h" +#include "gen/model/Detector_settings.h" +#include "gen/model/Detector_status.h" +#include "gen/model/Error_message.h" +#include "gen/model/File_writer_settings.h" +#include "gen/model/Fpga_status_inner.h" +#include "gen/model/Image_buffer_status.h" +#include "gen/model/Image_format_settings.h" +#include "gen/model/Image_pusher_status.h" +#include "gen/model/Indexing_settings.h" +#include "gen/model/Instrument_metadata.h" +#include "gen/model/Jfjoch_statistics.h" +#include "gen/model/Measurement_statistics.h" +#include "gen/model/Plots.h" +#include "gen/model/Roi_definitions.h" +#include "gen/model/Scan_result.h" +#include "gen/model/Spot_finding_settings.h" +#include "gen/model/Zeromq_metadata_settings.h" +#include "gen/model/Zeromq_preview_settings.h" -class JFJochBrokerHttp : public org::openapitools::server::api::DefaultApi { +class JFJochBrokerHttp { Logger logger{"JFJochBroker"}; - JFJochServices services {logger}; - - void config_image_format_get(Pistache::Http::ResponseWriter &response) override; - - void config_image_format_put(const org::openapitools::server::model::Image_format_settings &imageFormatSettings, - Pistache::Http::ResponseWriter &response) override; - - void fpga_status_get(Pistache::Http::ResponseWriter &response) override; - + JFJochServices services{logger}; JFJochStateMachine state_machine; std::string frontend_directory; - void config_detector_get(Pistache::Http::ResponseWriter &response) override; + template + static void send_plain(httplib::Response &res, int code, const T &body) { + res.status = code; + res.set_content(body, "text/plain"); + } - void config_detector_put(const org::openapitools::server::model::Detector_settings &detectorSettings, - Pistache::Http::ResponseWriter &response) override; + template + static void send_json(httplib::Response &res, int code, const T &body) { + res.status = code; + res.set_content(body, "application/json"); + } - void config_azim_int_get(Pistache::Http::ResponseWriter &response) override; + template + static std::optional parse_query_value(const httplib::Request &req, const char *name) { + if (!req.has_param(name)) return std::nullopt; + T v{}; + if (fromStringValue(req.get_param_value(name), v)) return v; + return std::nullopt; + } - void config_azim_int_put(const org::openapitools::server::model::Azim_int_settings &radIntSettings, - Pistache::Http::ResponseWriter &response) override; - - void config_select_detector_get(Pistache::Http::ResponseWriter &response) override; - - void config_select_detector_put(const org::openapitools::server::model::Detector_selection &detectorSelection, - Pistache::Http::ResponseWriter &response) override; - - void detector_status_get(Pistache::Http::ResponseWriter &response) override; - - void config_spot_finding_get(Pistache::Http::ResponseWriter &response) override; - - void config_spot_finding_put(const org::openapitools::server::model::Spot_finding_settings &spotFindingSettings, - Pistache::Http::ResponseWriter &response) override; - - void statistics_calibration_get(Pistache::Http::ResponseWriter &response) override; - - void statistics_data_collection_get(Pistache::Http::ResponseWriter &response) override; - - void cancel_post(Pistache::Http::ResponseWriter &response) override; - - void deactivate_post(Pistache::Http::ResponseWriter &response) override; - - void initialize_post(Pistache::Http::ResponseWriter &response) override; - - void start_post(const org::openapitools::server::model::Dataset_settings &datasetSettings, - Pistache::Http::ResponseWriter &response) override; - - void status_get(Pistache::Http::ResponseWriter &response) override; - - void wait_till_done_post(const std::optional &timeoutMs, Pistache::Http::ResponseWriter &response) override; - void trigger_post(Pistache::Http::ResponseWriter &response) override; - void pedestal_post(Pistache::Http::ResponseWriter &response) override; - - void preview_pedestal_tiff_get(const std::optional &gainLevel, - const std::optional &sc, - Pistache::Http::ResponseWriter &response) override; - - void config_roi_get(Pistache::Http::ResponseWriter &response) override; - void config_roi_put(const org::openapitools::server::model::Roi_definitions &roiDefinitions, - Pistache::Http::ResponseWriter &response) override; - - void config_internal_generator_image_put(const Pistache::Rest::Request &request, - Pistache::Http::ResponseWriter &response) override; - - void xfel_event_code_get(Pistache::Http::ResponseWriter &response) override; - void xfel_pulse_id_get(Pistache::Http::ResponseWriter &response) override; - - void config_mask_tiff_get(Pistache::Http::ResponseWriter &response) override; - - void config_user_mask_tiff_get(Pistache::Http::ResponseWriter &response) override; - - void config_user_mask_tiff_put(const Pistache::Rest::Request &request, - Pistache::Http::ResponseWriter &response) override; - - void config_internal_generator_image_tiff_put(const Pistache::Rest::Request &request, - Pistache::Http::ResponseWriter &response) override; - - void config_instrument_get(Pistache::Http::ResponseWriter &response) override; - - void config_instrument_put(const org::openapitools::server::model::Instrument_metadata &instrumentMetadata, - Pistache::Http::ResponseWriter &response) override; - - void GetStaticFile(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - std::pair handleOperationException(const std::exception &ex) const noexcept override; - - template - void ProcessOutput(const T& output, Pistache::Http::ResponseWriter &response, bool compression = false) { - std::stringstream s; - if(!output.validate(s)) { - logger.Error(s.str()); - response.send(Pistache::Http::Code::Internal_Server_Error, s.str(), MIME(Text, Plain)); - } else { - nlohmann::json j = output; - if (compression) - response.setCompression(Pistache::Http::Header::Encoding::Deflate); - response.send(Pistache::Http::Code::Ok, j.dump(), MIME(Application, Json)); + template + void with_json_body(const httplib::Request &req, httplib::Response &res, Fn &&fn) { + try { + Model v; + nlohmann::json::parse(req.body).get_to(v); + v.validate(); + std::forward(fn)(v, res); + } catch (const std::exception &e) { + auto [c, s] = handleParsingException(e); + send_plain(res, c, s); } } - void version_get(Pistache::Http::ResponseWriter &response) override; + template + void with_no_body(const httplib::Request &, httplib::Response &res, Fn &&fn) { + try { + std::forward(fn)(res); + } catch (const std::exception &e) { + auto [c, s] = handleOperationException(e); + send_plain(res, c, s); + } + } - void config_image_format_conversion_post(Pistache::Http::ResponseWriter &response) override; + template + void with_request(const httplib::Request &req, httplib::Response &res, Fn &&fn) { + try { + std::forward(fn)(req, res); + } catch (const std::exception &e) { + auto [c, s] = handleOperationException(e); + send_plain(res, c, s); + } + } - void config_image_format_raw_post(Pistache::Http::ResponseWriter &response) override; + std::pair handleParsingException(const std::exception &ex) const noexcept; - void statistics_get(const std::optional &compression, Pistache::Http::ResponseWriter &response) override; + std::pair handleOperationException(const std::exception &ex) const noexcept; - void config_zeromq_preview_get(Pistache::Http::ResponseWriter &response) override; + void register_routes(httplib::Server &server); - void - config_zeromq_preview_put(const org::openapitools::server::model::Zeromq_preview_settings &zeromqPreviewSettings, - Pistache::Http::ResponseWriter &response) override; + void cancel_post(httplib::Response &response); - void config_zeromq_metadata_get(Pistache::Http::ResponseWriter &response) override; + void deactivate_post(httplib::Response &response); + + void initialize_post(httplib::Response &response); + + void start_post(const org::openapitools::server::model::Dataset_settings &datasetSettings, + httplib::Response &response); + + void status_get(httplib::Response &response); + + void wait_till_done_post(const std::optional &timeout, httplib::Response &response); + + void trigger_post(httplib::Response &response); + + void pedestal_post(httplib::Response &response); + + void config_detector_get(httplib::Response &response); + + void config_detector_put(const org::openapitools::server::model::Detector_settings &detectorSettings, + httplib::Response &response); + + void config_azim_int_get(httplib::Response &response); + + void config_azim_int_put(const org::openapitools::server::model::Azim_int_settings &azimIntSettings, + httplib::Response &response); + + void config_file_writer_get(httplib::Response &response); + + void config_file_writer_put(const org::openapitools::server::model::File_writer_settings &fileWriterSettings, + httplib::Response &response); + + void config_image_format_get(httplib::Response &response); + + void config_image_format_put(const org::openapitools::server::model::Image_format_settings &imageFormatSettings, + httplib::Response &response); + + void config_image_format_conversion_post(httplib::Response &response); + + void config_image_format_raw_post(httplib::Response &response); + + void config_indexing_get(httplib::Response &response); + + void config_indexing_put(const org::openapitools::server::model::Indexing_settings &indexingSettings, + httplib::Response &response); + + void config_instrument_get(httplib::Response &response); + + void config_instrument_put(const org::openapitools::server::model::Instrument_metadata &instrumentMetadata, + httplib::Response &response); + + void config_select_detector_get(httplib::Response &response); + + void config_select_detector_put(const org::openapitools::server::model::Detector_selection &detectorSelection, + httplib::Response &response); + + void config_spot_finding_get(httplib::Response &response); + + void config_spot_finding_put(const org::openapitools::server::model::Spot_finding_settings &spotFindingSettings, + httplib::Response &response); + + void config_dark_mask_get(httplib::Response &response); + + void config_dark_mask_put(const org::openapitools::server::model::Dark_mask_settings &darkMaskSettings, + httplib::Response &response); + + void config_zeromq_metadata_get(httplib::Response &response); void config_zeromq_metadata_put( - const org::openapitools::server::model::Zeromq_metadata_settings &zeromqMetadataSettings, - Pistache::Http::ResponseWriter &response) override; + const org::openapitools::server::model::Zeromq_metadata_settings &zeromqMetadataSettings, + httplib::Response &response); - void config_mask_get(Pistache::Http::ResponseWriter &response) override; + void config_zeromq_preview_get(httplib::Response &response); - void config_user_mask_get(Pistache::Http::ResponseWriter &response) override; + void config_zeromq_preview_put( + const org::openapitools::server::model::Zeromq_preview_settings &zeromqPreviewSettings, + httplib::Response &response); - void config_user_mask_put(const Pistache::Rest::Request &request, - Pistache::Http::ResponseWriter &response) override; + void config_roi_get(httplib::Response &response); - void image_buffer_clear_post(Pistache::Http::ResponseWriter &response) override; + void config_roi_put(const org::openapitools::server::model::Roi_definitions &roiDefinitions, + httplib::Response &response); - void image_buffer_image_cbor_get(const std::optional &id, - Pistache::Http::ResponseWriter &response) override; + void config_mask_get(httplib::Response &response); - void image_buffer_image_jpeg_get(const std::optional &id, - const std::optional &showUserMask, - const std::optional &showRoi, - const std::optional &showSpots, - const std::optional &showBeamCenter, - const std::optional &saturation, - const std::optional &jpegQuality, - const std::optional &showResRing, - const std::optional &color, - const std::optional &showResEst, - Pistache::Http::ResponseWriter &response) override; + void config_mask_tiff_get(httplib::Response &response); - void image_buffer_image_tiff_get(const std::optional &id, Pistache::Http::ResponseWriter &response) override; + void config_user_mask_get(httplib::Response &response); - void image_buffer_start_cbor_get(Pistache::Http::ResponseWriter &response) override; + void config_user_mask_put(const httplib::Request &request, httplib::Response &response); + + void config_user_mask_tiff_get(httplib::Response &response); + + void config_user_mask_tiff_put(const httplib::Request &request, httplib::Response &response); + + void image_buffer_clear_post(httplib::Response &response); + + void image_buffer_image_cbor_get(const std::optional &id, httplib::Response &response); + + void image_buffer_image_jpeg_get(const std::optional &id, const std::optional &showUserMask, + const std::optional &showRoi, const std::optional &showSpots, + const std::optional &showBeamCenter, const std::optional &saturation, + const std::optional &jpegQuality, const std::optional &showResRing, + const std::optional &color, const std::optional &showResEst, + httplib::Response &response); + + void image_buffer_image_tiff_get(const std::optional &id, httplib::Response &response); + + void image_buffer_start_cbor_get(httplib::Response &response); + + void image_buffer_status_get(httplib::Response &response); + + void image_pusher_status_get(httplib::Response &response); + + void detector_status_get(httplib::Response &response); + + void fpga_status_get(httplib::Response &response); + + void statistics_calibration_get(httplib::Response &response); + + void statistics_data_collection_get(httplib::Response &response); + + void statistics_get(const std::optional &compression, httplib::Response &response); + + void result_scan_get(httplib::Response &response); + + void version_get(httplib::Response &response); + + void preview_pedestal_tiff_get(const std::optional &gainLevel, const std::optional &sc, + httplib::Response &response); + + void preview_plot_bin_get(const std::optional &type, const std::optional &roi, + httplib::Response &response); - void image_buffer_status_get(Pistache::Http::ResponseWriter &response) override; void preview_plot_get(const std::optional &type, const std::optional &binning, const std::optional &compression, const std::optional &fill, const std::optional &experimentalCoord, const std::optional &azintUnit, - Pistache::Http::ResponseWriter &response) override; + httplib::Response &response); - void preview_plot_bin_get(const std::optional &type, const std::optional &roi, - Pistache::Http::ResponseWriter &response) override; + void xfel_event_code_get(httplib::Response &response); - void config_indexing_get(Pistache::Http::ResponseWriter &response) override; + void xfel_pulse_id_get(httplib::Response &response); - void config_indexing_put(const org::openapitools::server::model::Indexing_settings &indexingSettings, - Pistache::Http::ResponseWriter &response) override; - - void result_scan_get(Pistache::Http::ResponseWriter &response) override; - - void config_dark_mask_get(Pistache::Http::ResponseWriter &response) override; - void config_dark_mask_put(const org::openapitools::server::model::Dark_mask_settings &darkMaskSettings, - Pistache::Http::ResponseWriter &response) override; - void image_pusher_status_get(Pistache::Http::ResponseWriter &response) override; + template + void ProcessOutput(const T &output, httplib::Response &response, bool compression = false) { + std::stringstream s; + if (!output.validate(s)) { + logger.Error(s.str()); + response.status = 500; + response.set_content(s.str(), "text/plain"); + } else { + nlohmann::json j = output; + if (compression) + response.set_header("Content-Encoding", "deflate"); + response.status = 200; + response.set_content(j.dump(), "application/json"); + } + } public: - JFJochBrokerHttp(const DiffractionExperiment& experiment, - const SpotFindingSettings &spot_finding_settings, - std::shared_ptr &rtr); + JFJochBrokerHttp(const DiffractionExperiment &experiment, + const SpotFindingSettings &spot_finding_settings); void AddDetectorSetup(const DetectorSetup &setup); - JFJochServices& Services(); - JFJochBrokerHttp& FrontendDirectory(const std::string &directory); + JFJochServices &Services(); - ~JFJochBrokerHttp() override = default; + JFJochBrokerHttp &FrontendDirectory(const std::string &directory); -private: - void config_file_writer_get(Pistache::Http::ResponseWriter &response) override; + void attach(httplib::Server &server); - void config_file_writer_put(const org::openapitools::server::model::File_writer_settings &fileWriterSettings, - Pistache::Http::ResponseWriter &response) override; + ~JFJochBrokerHttp() = default; }; - - -#endif //JUNGFRAUJOCH_JFJOCHBROKERHTTP_H diff --git a/broker/gen/api/ApiBase.cpp b/broker/gen/api/ApiBase.cpp deleted file mode 100644 index 28074574..00000000 --- a/broker/gen/api/ApiBase.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/** -* Jungfraujoch -* API to control Jungfraujoch developed by the Paul Scherrer Institute (Switzerland). Jungfraujoch is a data acquisition and analysis system for pixel array detectors, primarly PSI JUNGFRAU. Jungfraujoch uses FPGA boards to acquire data at high data rates. # License Clarification While this API definition is licensed under GPL-3.0, **the GPL copyleft provisions do not apply** when this file is used solely to generate OpenAPI clients or when implementing applications that interact with the API. Generated client code and applications using this API definition are not subject to the GPL license requirements and may be distributed under terms of your choosing. This exception is similar in spirit to the Linux Kernel's approach to userspace API headers and the GCC Runtime Library Exception. The Linux Kernel developers have explicitly stated that user programs that merely use the kernel interfaces (syscalls, ioctl definitions, etc.) are not derivative works of the kernel and are not subject to the terms of the GPL. This exception is intended to allow wider use of this API specification without imposing GPL requirements on applications that merely interact with the API, regardless of whether they communicate through network calls or other mechanisms. -* -* The version of the OpenAPI document: 1.0.0-rc.132 -* Contact: filip.leonarski@psi.ch -* -* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). -* https://openapi-generator.tech -* Do not edit the class manually. -*/ -#include "ApiBase.h" - -namespace org::openapitools::server::api -{ - -ApiBase::ApiBase(const std::shared_ptr& rtr) : router(rtr) -{ -} - - -} // Namespace org::openapitools::server::api diff --git a/broker/gen/api/ApiBase.h b/broker/gen/api/ApiBase.h deleted file mode 100644 index 5a44dff3..00000000 --- a/broker/gen/api/ApiBase.h +++ /dev/null @@ -1,51 +0,0 @@ -/** -* Jungfraujoch -* API to control Jungfraujoch developed by the Paul Scherrer Institute (Switzerland). Jungfraujoch is a data acquisition and analysis system for pixel array detectors, primarly PSI JUNGFRAU. Jungfraujoch uses FPGA boards to acquire data at high data rates. # License Clarification While this API definition is licensed under GPL-3.0, **the GPL copyleft provisions do not apply** when this file is used solely to generate OpenAPI clients or when implementing applications that interact with the API. Generated client code and applications using this API definition are not subject to the GPL license requirements and may be distributed under terms of your choosing. This exception is similar in spirit to the Linux Kernel's approach to userspace API headers and the GCC Runtime Library Exception. The Linux Kernel developers have explicitly stated that user programs that merely use the kernel interfaces (syscalls, ioctl definitions, etc.) are not derivative works of the kernel and are not subject to the terms of the GPL. This exception is intended to allow wider use of this API specification without imposing GPL requirements on applications that merely interact with the API, regardless of whether they communicate through network calls or other mechanisms. -* -* The version of the OpenAPI document: 1.0.0-rc.132 -* Contact: filip.leonarski@psi.ch -* -* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). -* https://openapi-generator.tech -* Do not edit the class manually. -*/ -/* - * ApiBase.h - * - * Generalization of the Api classes - */ - -#ifndef ApiBase_H_ -#define ApiBase_H_ - -#include -#include - -namespace org::openapitools::server::api -{ - - - - - -class ApiBase { -public: - explicit ApiBase(const std::shared_ptr& rtr); - virtual ~ApiBase() = default; - virtual void init() = 0; - - - - - -protected: - const std::shared_ptr router; - - - - -}; - -} // namespace org::openapitools::server::api - -#endif /* ApiBase_H_ */ diff --git a/broker/gen/api/DefaultApi.cpp b/broker/gen/api/DefaultApi.cpp deleted file mode 100644 index 8582287a..00000000 --- a/broker/gen/api/DefaultApi.cpp +++ /dev/null @@ -1,2279 +0,0 @@ -/** -* Jungfraujoch -* API to control Jungfraujoch developed by the Paul Scherrer Institute (Switzerland). Jungfraujoch is a data acquisition and analysis system for pixel array detectors, primarly PSI JUNGFRAU. Jungfraujoch uses FPGA boards to acquire data at high data rates. # License Clarification While this API definition is licensed under GPL-3.0, **the GPL copyleft provisions do not apply** when this file is used solely to generate OpenAPI clients or when implementing applications that interact with the API. Generated client code and applications using this API definition are not subject to the GPL license requirements and may be distributed under terms of your choosing. This exception is similar in spirit to the Linux Kernel's approach to userspace API headers and the GCC Runtime Library Exception. The Linux Kernel developers have explicitly stated that user programs that merely use the kernel interfaces (syscalls, ioctl definitions, etc.) are not derivative works of the kernel and are not subject to the terms of the GPL. This exception is intended to allow wider use of this API specification without imposing GPL requirements on applications that merely interact with the API, regardless of whether they communicate through network calls or other mechanisms. -* -* The version of the OpenAPI document: 1.0.0-rc.132 -* Contact: filip.leonarski@psi.ch -* -* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). -* https://openapi-generator.tech -* Do not edit the class manually. -*/ - -#include "DefaultApi.h" -#include "Helpers.h" - -namespace org::openapitools::server::api -{ - -using namespace org::openapitools::server::helpers; -using namespace org::openapitools::server::model; - -const std::string DefaultApi::base = ""; - -DefaultApi::DefaultApi(const std::shared_ptr& rtr) - : ApiBase(rtr) -{} - -void DefaultApi::init() { - setupRoutes(); -} - -void DefaultApi::setupRoutes() { - using namespace Pistache::Rest; - - Routes::Post(*router, base + "/cancel", Routes::bind(&DefaultApi::cancel_post_handler, this)); - Routes::Get(*router, base + "/config/azim_int", Routes::bind(&DefaultApi::config_azim_int_get_handler, this)); - Routes::Put(*router, base + "/config/azim_int", Routes::bind(&DefaultApi::config_azim_int_put_handler, this)); - Routes::Get(*router, base + "/config/dark_mask", Routes::bind(&DefaultApi::config_dark_mask_get_handler, this)); - Routes::Put(*router, base + "/config/dark_mask", Routes::bind(&DefaultApi::config_dark_mask_put_handler, this)); - Routes::Get(*router, base + "/config/detector", Routes::bind(&DefaultApi::config_detector_get_handler, this)); - Routes::Put(*router, base + "/config/detector", Routes::bind(&DefaultApi::config_detector_put_handler, this)); - Routes::Get(*router, base + "/config/file_writer", Routes::bind(&DefaultApi::config_file_writer_get_handler, this)); - Routes::Put(*router, base + "/config/file_writer", Routes::bind(&DefaultApi::config_file_writer_put_handler, this)); - Routes::Post(*router, base + "/config/image_format/conversion", Routes::bind(&DefaultApi::config_image_format_conversion_post_handler, this)); - Routes::Get(*router, base + "/config/image_format", Routes::bind(&DefaultApi::config_image_format_get_handler, this)); - Routes::Put(*router, base + "/config/image_format", Routes::bind(&DefaultApi::config_image_format_put_handler, this)); - Routes::Post(*router, base + "/config/image_format/raw", Routes::bind(&DefaultApi::config_image_format_raw_post_handler, this)); - Routes::Get(*router, base + "/config/indexing", Routes::bind(&DefaultApi::config_indexing_get_handler, this)); - Routes::Put(*router, base + "/config/indexing", Routes::bind(&DefaultApi::config_indexing_put_handler, this)); - Routes::Get(*router, base + "/config/instrument", Routes::bind(&DefaultApi::config_instrument_get_handler, this)); - Routes::Put(*router, base + "/config/instrument", Routes::bind(&DefaultApi::config_instrument_put_handler, this)); - Routes::Put(*router, base + "/config/internal_generator_image", Routes::bind(&DefaultApi::config_internal_generator_image_put_handler, this)); - Routes::Put(*router, base + "/config/internal_generator_image.tiff", Routes::bind(&DefaultApi::config_internal_generator_image_tiff_put_handler, this)); - Routes::Get(*router, base + "/config/mask", Routes::bind(&DefaultApi::config_mask_get_handler, this)); - Routes::Get(*router, base + "/config/mask.tiff", Routes::bind(&DefaultApi::config_mask_tiff_get_handler, this)); - Routes::Get(*router, base + "/config/roi", Routes::bind(&DefaultApi::config_roi_get_handler, this)); - Routes::Put(*router, base + "/config/roi", Routes::bind(&DefaultApi::config_roi_put_handler, this)); - Routes::Get(*router, base + "/config/select_detector", Routes::bind(&DefaultApi::config_select_detector_get_handler, this)); - Routes::Put(*router, base + "/config/select_detector", Routes::bind(&DefaultApi::config_select_detector_put_handler, this)); - Routes::Get(*router, base + "/config/spot_finding", Routes::bind(&DefaultApi::config_spot_finding_get_handler, this)); - Routes::Put(*router, base + "/config/spot_finding", Routes::bind(&DefaultApi::config_spot_finding_put_handler, this)); - Routes::Get(*router, base + "/config/user_mask", Routes::bind(&DefaultApi::config_user_mask_get_handler, this)); - Routes::Put(*router, base + "/config/user_mask", Routes::bind(&DefaultApi::config_user_mask_put_handler, this)); - Routes::Get(*router, base + "/config/user_mask.tiff", Routes::bind(&DefaultApi::config_user_mask_tiff_get_handler, this)); - Routes::Put(*router, base + "/config/user_mask.tiff", Routes::bind(&DefaultApi::config_user_mask_tiff_put_handler, this)); - Routes::Get(*router, base + "/config/zeromq_metadata", Routes::bind(&DefaultApi::config_zeromq_metadata_get_handler, this)); - Routes::Put(*router, base + "/config/zeromq_metadata", Routes::bind(&DefaultApi::config_zeromq_metadata_put_handler, this)); - Routes::Get(*router, base + "/config/zeromq_preview", Routes::bind(&DefaultApi::config_zeromq_preview_get_handler, this)); - Routes::Put(*router, base + "/config/zeromq_preview", Routes::bind(&DefaultApi::config_zeromq_preview_put_handler, this)); - Routes::Post(*router, base + "/deactivate", Routes::bind(&DefaultApi::deactivate_post_handler, this)); - Routes::Get(*router, base + "/detector/status", Routes::bind(&DefaultApi::detector_status_get_handler, this)); - Routes::Get(*router, base + "/fpga_status", Routes::bind(&DefaultApi::fpga_status_get_handler, this)); - Routes::Post(*router, base + "/image_buffer/clear", Routes::bind(&DefaultApi::image_buffer_clear_post_handler, this)); - Routes::Get(*router, base + "/image_buffer/image.cbor", Routes::bind(&DefaultApi::image_buffer_image_cbor_get_handler, this)); - Routes::Get(*router, base + "/image_buffer/image.jpeg", Routes::bind(&DefaultApi::image_buffer_image_jpeg_get_handler, this)); - Routes::Get(*router, base + "/image_buffer/image.tiff", Routes::bind(&DefaultApi::image_buffer_image_tiff_get_handler, this)); - Routes::Get(*router, base + "/image_buffer/start.cbor", Routes::bind(&DefaultApi::image_buffer_start_cbor_get_handler, this)); - Routes::Get(*router, base + "/image_buffer/status", Routes::bind(&DefaultApi::image_buffer_status_get_handler, this)); - Routes::Get(*router, base + "/image_pusher/status", Routes::bind(&DefaultApi::image_pusher_status_get_handler, this)); - Routes::Post(*router, base + "/initialize", Routes::bind(&DefaultApi::initialize_post_handler, this)); - Routes::Post(*router, base + "/pedestal", Routes::bind(&DefaultApi::pedestal_post_handler, this)); - Routes::Get(*router, base + "/preview/pedestal.tiff", Routes::bind(&DefaultApi::preview_pedestal_tiff_get_handler, this)); - Routes::Get(*router, base + "/preview/plot.bin", Routes::bind(&DefaultApi::preview_plot_bin_get_handler, this)); - Routes::Get(*router, base + "/preview/plot", Routes::bind(&DefaultApi::preview_plot_get_handler, this)); - Routes::Get(*router, base + "/result/scan", Routes::bind(&DefaultApi::result_scan_get_handler, this)); - Routes::Post(*router, base + "/start", Routes::bind(&DefaultApi::start_post_handler, this)); - Routes::Get(*router, base + "/statistics/calibration", Routes::bind(&DefaultApi::statistics_calibration_get_handler, this)); - Routes::Get(*router, base + "/statistics/data_collection", Routes::bind(&DefaultApi::statistics_data_collection_get_handler, this)); - Routes::Get(*router, base + "/statistics", Routes::bind(&DefaultApi::statistics_get_handler, this)); - Routes::Get(*router, base + "/status", Routes::bind(&DefaultApi::status_get_handler, this)); - Routes::Post(*router, base + "/trigger", Routes::bind(&DefaultApi::trigger_post_handler, this)); - Routes::Get(*router, base + "/version", Routes::bind(&DefaultApi::version_get_handler, this)); - Routes::Post(*router, base + "/wait_till_done", Routes::bind(&DefaultApi::wait_till_done_post_handler, this)); - Routes::Get(*router, base + "/xfel/event_code", Routes::bind(&DefaultApi::xfel_event_code_get_handler, this)); - Routes::Get(*router, base + "/xfel/pulse_id", Routes::bind(&DefaultApi::xfel_pulse_id_get_handler, this)); - - // Default handler, called when a route is not found - router->addCustomHandler(Routes::bind(&DefaultApi::default_api_default_handler, this)); -} - -void DefaultApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { - std::pair codeAndError = handleParsingException(ex); - response.send(codeAndError.first, codeAndError.second); -} - -std::pair DefaultApi::handleParsingException(const std::exception& ex) const noexcept { - try { - throw; - } catch (nlohmann::detail::exception &e) { - return std::make_pair(Pistache::Http::Code::Bad_Request, e.what()); - } catch (org::openapitools::server::helpers::ValidationException &e) { - return std::make_pair(Pistache::Http::Code::Bad_Request, e.what()); - } catch (std::exception &e) { - return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what()); - } -} - -void DefaultApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { - std::pair codeAndError = handleOperationException(ex); - response.send(codeAndError.first, codeAndError.second); -} - -std::pair DefaultApi::handleOperationException(const std::exception& ex) const noexcept { - return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what()); -} - -void DefaultApi::cancel_post_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->cancel_post(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_azim_int_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_azim_int_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_azim_int_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - // Getting the body param - - Azim_int_settings azimIntSettings; - - - - - - try { - nlohmann::json::parse(request.body()).get_to(azimIntSettings); - azimIntSettings.validate(); - } catch (std::exception& e) { - this->handleParsingException(e, response); - return; - } - - try { - - - - - - this->config_azim_int_put(azimIntSettings, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_dark_mask_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_dark_mask_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_dark_mask_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - // Getting the body param - - Dark_mask_settings darkMaskSettings; - - - - - - try { - nlohmann::json::parse(request.body()).get_to(darkMaskSettings); - darkMaskSettings.validate(); - } catch (std::exception& e) { - this->handleParsingException(e, response); - return; - } - - try { - - - - - - this->config_dark_mask_put(darkMaskSettings, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_detector_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_detector_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_detector_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - // Getting the body param - - Detector_settings detectorSettings; - - - - - - try { - nlohmann::json::parse(request.body()).get_to(detectorSettings); - detectorSettings.validate(); - } catch (std::exception& e) { - this->handleParsingException(e, response); - return; - } - - try { - - - - - - this->config_detector_put(detectorSettings, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_file_writer_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_file_writer_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_file_writer_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - // Getting the body param - - File_writer_settings fileWriterSettings; - - - - - - try { - nlohmann::json::parse(request.body()).get_to(fileWriterSettings); - fileWriterSettings.validate(); - } catch (std::exception& e) { - this->handleParsingException(e, response); - return; - } - - try { - - - - - - this->config_file_writer_put(fileWriterSettings, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_image_format_conversion_post_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_image_format_conversion_post(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_image_format_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_image_format_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_image_format_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - // Getting the body param - - Image_format_settings imageFormatSettings; - - - - - - try { - nlohmann::json::parse(request.body()).get_to(imageFormatSettings); - imageFormatSettings.validate(); - } catch (std::exception& e) { - this->handleParsingException(e, response); - return; - } - - try { - - - - - - this->config_image_format_put(imageFormatSettings, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_image_format_raw_post_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_image_format_raw_post(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_indexing_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_indexing_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_indexing_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - // Getting the body param - - Indexing_settings indexingSettings; - - - - - - try { - nlohmann::json::parse(request.body()).get_to(indexingSettings); - indexingSettings.validate(); - } catch (std::exception& e) { - this->handleParsingException(e, response); - return; - } - - try { - - - - - - this->config_indexing_put(indexingSettings, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_instrument_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_instrument_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_instrument_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - // Getting the body param - - Instrument_metadata instrumentMetadata; - - - - - - try { - nlohmann::json::parse(request.body()).get_to(instrumentMetadata); - instrumentMetadata.validate(); - } catch (std::exception& e) { - this->handleParsingException(e, response); - return; - } - - try { - - - - - - this->config_instrument_put(instrumentMetadata, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_internal_generator_image_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - try { - this->config_internal_generator_image_put(request, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_internal_generator_image_tiff_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - try { - this->config_internal_generator_image_tiff_put(request, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_mask_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_mask_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_mask_tiff_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_mask_tiff_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_roi_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_roi_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_roi_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - // Getting the body param - - Roi_definitions roiDefinitions; - - - - - - try { - nlohmann::json::parse(request.body()).get_to(roiDefinitions); - roiDefinitions.validate(); - } catch (std::exception& e) { - this->handleParsingException(e, response); - return; - } - - try { - - - - - - this->config_roi_put(roiDefinitions, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_select_detector_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_select_detector_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_select_detector_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - // Getting the body param - - Detector_selection detectorSelection; - - - - - - try { - nlohmann::json::parse(request.body()).get_to(detectorSelection); - detectorSelection.validate(); - } catch (std::exception& e) { - this->handleParsingException(e, response); - return; - } - - try { - - - - - - this->config_select_detector_put(detectorSelection, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_spot_finding_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_spot_finding_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_spot_finding_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - // Getting the body param - - Spot_finding_settings spotFindingSettings; - - - - - - try { - nlohmann::json::parse(request.body()).get_to(spotFindingSettings); - spotFindingSettings.validate(); - } catch (std::exception& e) { - this->handleParsingException(e, response); - return; - } - - try { - - - - - - this->config_spot_finding_put(spotFindingSettings, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_user_mask_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_user_mask_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_user_mask_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - try { - this->config_user_mask_put(request, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_user_mask_tiff_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_user_mask_tiff_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_user_mask_tiff_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - try { - this->config_user_mask_tiff_put(request, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_zeromq_metadata_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_zeromq_metadata_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_zeromq_metadata_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - // Getting the body param - - Zeromq_metadata_settings zeromqMetadataSettings; - - - - - - try { - nlohmann::json::parse(request.body()).get_to(zeromqMetadataSettings); - zeromqMetadataSettings.validate(); - } catch (std::exception& e) { - this->handleParsingException(e, response); - return; - } - - try { - - - - - - this->config_zeromq_metadata_put(zeromqMetadataSettings, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_zeromq_preview_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->config_zeromq_preview_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::config_zeromq_preview_put_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - // Getting the body param - - Zeromq_preview_settings zeromqPreviewSettings; - - - - - - try { - nlohmann::json::parse(request.body()).get_to(zeromqPreviewSettings); - zeromqPreviewSettings.validate(); - } catch (std::exception& e) { - this->handleParsingException(e, response); - return; - } - - try { - - - - - - this->config_zeromq_preview_put(zeromqPreviewSettings, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::deactivate_post_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->deactivate_post(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::detector_status_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->detector_status_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::fpga_status_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->fpga_status_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::image_buffer_clear_post_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->image_buffer_clear_post(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::image_buffer_image_cbor_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - // Getting the query params - auto idQuery = request.query().get("id"); - std::optional id; - if (idQuery.has_value()) { - int64_t valueQuery_instance; - if (fromStringValue(idQuery.value(), valueQuery_instance)) { - id = valueQuery_instance; - } - } - - - - try { - - - - - - this->image_buffer_image_cbor_get(id, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::image_buffer_image_jpeg_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - // Getting the query params - auto idQuery = request.query().get("id"); - std::optional id; - if (idQuery.has_value()) { - int64_t valueQuery_instance; - if (fromStringValue(idQuery.value(), valueQuery_instance)) { - id = valueQuery_instance; - } - } - auto showUserMaskQuery = request.query().get("show_user_mask"); - std::optional showUserMask; - if (showUserMaskQuery.has_value()) { - bool valueQuery_instance; - if (fromStringValue(showUserMaskQuery.value(), valueQuery_instance)) { - showUserMask = valueQuery_instance; - } - } - auto showRoiQuery = request.query().get("show_roi"); - std::optional showRoi; - if (showRoiQuery.has_value()) { - bool valueQuery_instance; - if (fromStringValue(showRoiQuery.value(), valueQuery_instance)) { - showRoi = valueQuery_instance; - } - } - auto showSpotsQuery = request.query().get("show_spots"); - std::optional showSpots; - if (showSpotsQuery.has_value()) { - bool valueQuery_instance; - if (fromStringValue(showSpotsQuery.value(), valueQuery_instance)) { - showSpots = valueQuery_instance; - } - } - auto showBeamCenterQuery = request.query().get("show_beam_center"); - std::optional showBeamCenter; - if (showBeamCenterQuery.has_value()) { - bool valueQuery_instance; - if (fromStringValue(showBeamCenterQuery.value(), valueQuery_instance)) { - showBeamCenter = valueQuery_instance; - } - } - auto saturationQuery = request.query().get("saturation"); - std::optional saturation; - if (saturationQuery.has_value()) { - float valueQuery_instance; - if (fromStringValue(saturationQuery.value(), valueQuery_instance)) { - saturation = valueQuery_instance; - } - } - auto jpegQualityQuery = request.query().get("jpeg_quality"); - std::optional jpegQuality; - if (jpegQualityQuery.has_value()) { - int64_t valueQuery_instance; - if (fromStringValue(jpegQualityQuery.value(), valueQuery_instance)) { - jpegQuality = valueQuery_instance; - } - } - auto showResRingQuery = request.query().get("show_res_ring"); - std::optional showResRing; - if (showResRingQuery.has_value()) { - float valueQuery_instance; - if (fromStringValue(showResRingQuery.value(), valueQuery_instance)) { - showResRing = valueQuery_instance; - } - } - auto colorQuery = request.query().get("color"); - std::optional color; - if (colorQuery.has_value()) { - std::string valueQuery_instance; - if (fromStringValue(colorQuery.value(), valueQuery_instance)) { - color = valueQuery_instance; - } - } - auto showResEstQuery = request.query().get("show_res_est"); - std::optional showResEst; - if (showResEstQuery.has_value()) { - bool valueQuery_instance; - if (fromStringValue(showResEstQuery.value(), valueQuery_instance)) { - showResEst = valueQuery_instance; - } - } - - - - try { - - - - - - this->image_buffer_image_jpeg_get(id, showUserMask, showRoi, showSpots, showBeamCenter, saturation, jpegQuality, showResRing, color, showResEst, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::image_buffer_image_tiff_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - // Getting the query params - auto idQuery = request.query().get("id"); - std::optional id; - if (idQuery.has_value()) { - int64_t valueQuery_instance; - if (fromStringValue(idQuery.value(), valueQuery_instance)) { - id = valueQuery_instance; - } - } - - - - try { - - - - - - this->image_buffer_image_tiff_get(id, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::image_buffer_start_cbor_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->image_buffer_start_cbor_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::image_buffer_status_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->image_buffer_status_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::image_pusher_status_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->image_pusher_status_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::initialize_post_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->initialize_post(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::pedestal_post_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->pedestal_post(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::preview_pedestal_tiff_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - // Getting the query params - auto gainLevelQuery = request.query().get("gain_level"); - std::optional gainLevel; - if (gainLevelQuery.has_value()) { - int32_t valueQuery_instance; - if (fromStringValue(gainLevelQuery.value(), valueQuery_instance)) { - gainLevel = valueQuery_instance; - } - } - auto scQuery = request.query().get("sc"); - std::optional sc; - if (scQuery.has_value()) { - int32_t valueQuery_instance; - if (fromStringValue(scQuery.value(), valueQuery_instance)) { - sc = valueQuery_instance; - } - } - - - - try { - - - - - - this->preview_pedestal_tiff_get(gainLevel, sc, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::preview_plot_bin_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - // Getting the query params - auto typeQuery = request.query().get("type"); - std::optional type; - if (typeQuery.has_value()) { - std::string valueQuery_instance; - if (fromStringValue(typeQuery.value(), valueQuery_instance)) { - type = valueQuery_instance; - } - } - auto roiQuery = request.query().get("roi"); - std::optional roi; - if (roiQuery.has_value()) { - std::string valueQuery_instance; - if (fromStringValue(roiQuery.value(), valueQuery_instance)) { - roi = valueQuery_instance; - } - } - - - - try { - - - - - - this->preview_plot_bin_get(type, roi, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::preview_plot_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - // Getting the query params - auto binningQuery = request.query().get("binning"); - std::optional binning; - if (binningQuery.has_value()) { - int32_t valueQuery_instance; - if (fromStringValue(binningQuery.value(), valueQuery_instance)) { - binning = valueQuery_instance; - } - } - auto compressionQuery = request.query().get("compression"); - std::optional compression; - if (compressionQuery.has_value()) { - bool valueQuery_instance; - if (fromStringValue(compressionQuery.value(), valueQuery_instance)) { - compression = valueQuery_instance; - } - } - auto typeQuery = request.query().get("type"); - std::optional type; - if (typeQuery.has_value()) { - std::string valueQuery_instance; - if (fromStringValue(typeQuery.value(), valueQuery_instance)) { - type = valueQuery_instance; - } - } - auto fillQuery = request.query().get("fill"); - std::optional fill; - if (fillQuery.has_value()) { - float valueQuery_instance; - if (fromStringValue(fillQuery.value(), valueQuery_instance)) { - fill = valueQuery_instance; - } - } - auto experimentalCoordQuery = request.query().get("experimental_coord"); - std::optional experimentalCoord; - if (experimentalCoordQuery.has_value()) { - bool valueQuery_instance; - if (fromStringValue(experimentalCoordQuery.value(), valueQuery_instance)) { - experimentalCoord = valueQuery_instance; - } - } - auto azintUnitQuery = request.query().get("azint_unit"); - std::optional azintUnit; - if (azintUnitQuery.has_value()) { - std::string valueQuery_instance; - if (fromStringValue(azintUnitQuery.value(), valueQuery_instance)) { - azintUnit = valueQuery_instance; - } - } - - - - try { - - - - - - this->preview_plot_get(type, binning, compression, fill, experimentalCoord, azintUnit, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::result_scan_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->result_scan_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::start_post_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - // Getting the body param - - Dataset_settings datasetSettings; - - - - - - try { - nlohmann::json::parse(request.body()).get_to(datasetSettings); - datasetSettings.validate(); - } catch (std::exception& e) { - this->handleParsingException(e, response); - return; - } - - try { - - - - - - this->start_post(datasetSettings, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::statistics_calibration_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->statistics_calibration_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::statistics_data_collection_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->statistics_data_collection_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::statistics_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - // Getting the query params - auto compressionQuery = request.query().get("compression"); - std::optional compression; - if (compressionQuery.has_value()) { - bool valueQuery_instance; - if (fromStringValue(compressionQuery.value(), valueQuery_instance)) { - compression = valueQuery_instance; - } - } - - - - try { - - - - - - this->statistics_get(compression, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::status_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->status_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::trigger_post_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->trigger_post(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::version_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->version_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::wait_till_done_post_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - // Getting the query params - auto timeoutQuery = request.query().get("timeout"); - std::optional timeout; - if (timeoutQuery.has_value()) { - int32_t valueQuery_instance; - if (fromStringValue(timeoutQuery.value(), valueQuery_instance)) { - timeout = valueQuery_instance; - } - } - - - - try { - - - - - - this->wait_till_done_post(timeout, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::xfel_event_code_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->xfel_event_code_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - -void DefaultApi::xfel_pulse_id_get_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { - try { - - - - - - - try { - - - - - - this->xfel_pulse_id_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - - -} - - -void DefaultApi::default_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) { - response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist"); -} - -} // namespace org::openapitools::server::api - diff --git a/broker/gen/api/DefaultApi.h b/broker/gen/api/DefaultApi.h deleted file mode 100644 index 2e6fac0c..00000000 --- a/broker/gen/api/DefaultApi.h +++ /dev/null @@ -1,634 +0,0 @@ -/** -* Jungfraujoch -* API to control Jungfraujoch developed by the Paul Scherrer Institute (Switzerland). Jungfraujoch is a data acquisition and analysis system for pixel array detectors, primarly PSI JUNGFRAU. Jungfraujoch uses FPGA boards to acquire data at high data rates. # License Clarification While this API definition is licensed under GPL-3.0, **the GPL copyleft provisions do not apply** when this file is used solely to generate OpenAPI clients or when implementing applications that interact with the API. Generated client code and applications using this API definition are not subject to the GPL license requirements and may be distributed under terms of your choosing. This exception is similar in spirit to the Linux Kernel's approach to userspace API headers and the GCC Runtime Library Exception. The Linux Kernel developers have explicitly stated that user programs that merely use the kernel interfaces (syscalls, ioctl definitions, etc.) are not derivative works of the kernel and are not subject to the terms of the GPL. This exception is intended to allow wider use of this API specification without imposing GPL requirements on applications that merely interact with the API, regardless of whether they communicate through network calls or other mechanisms. -* -* The version of the OpenAPI document: 1.0.0-rc.132 -* Contact: filip.leonarski@psi.ch -* -* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). -* https://openapi-generator.tech -* Do not edit the class manually. -*/ -/* - * DefaultApi.h - * - * - */ - -#ifndef DefaultApi_H_ -#define DefaultApi_H_ - - -#include "ApiBase.h" - -#include -#include -#include - -#include -#include - -#include "Azim_int_settings.h" -#include "Broker_status.h" -#include "Calibration_statistics_inner.h" -#include "Dark_mask_settings.h" -#include "Dataset_settings.h" -#include "Detector_list.h" -#include "Detector_selection.h" -#include "Detector_settings.h" -#include "Detector_status.h" -#include "Error_message.h" -#include "File_writer_settings.h" -#include "Fpga_status_inner.h" -#include "Image_buffer_status.h" -#include "Image_format_settings.h" -#include "Image_pusher_status.h" -#include "Indexing_settings.h" -#include "Instrument_metadata.h" -#include "Jfjoch_statistics.h" -#include "Measurement_statistics.h" -#include "Plots.h" -#include "Roi_definitions.h" -#include "Scan_result.h" -#include "Spot_finding_settings.h" -#include "Zeromq_metadata_settings.h" -#include "Zeromq_preview_settings.h" -#include -#include - -namespace org::openapitools::server::api -{ - -class DefaultApi : public ApiBase { -public: - explicit DefaultApi(const std::shared_ptr& rtr); - ~DefaultApi() override = default; - void init() override; - - static const std::string base; - -private: - void setupRoutes(); - - void cancel_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_azim_int_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_azim_int_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_dark_mask_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_dark_mask_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_detector_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_detector_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_file_writer_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_file_writer_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_image_format_conversion_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_image_format_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_image_format_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_image_format_raw_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_indexing_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_indexing_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_instrument_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_instrument_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_internal_generator_image_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_internal_generator_image_tiff_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_mask_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_mask_tiff_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_roi_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_roi_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_select_detector_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_select_detector_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_spot_finding_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_spot_finding_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_user_mask_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_user_mask_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_user_mask_tiff_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_user_mask_tiff_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_zeromq_metadata_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_zeromq_metadata_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_zeromq_preview_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void config_zeromq_preview_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void deactivate_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void detector_status_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void fpga_status_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void image_buffer_clear_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void image_buffer_image_cbor_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void image_buffer_image_jpeg_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void image_buffer_image_tiff_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void image_buffer_start_cbor_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void image_buffer_status_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void image_pusher_status_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void initialize_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void pedestal_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void preview_pedestal_tiff_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void preview_plot_bin_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void preview_plot_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void result_scan_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void start_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void statistics_calibration_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void statistics_data_collection_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void statistics_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void status_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void trigger_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void version_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void wait_till_done_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void xfel_event_code_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void xfel_pulse_id_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void default_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - - /// - /// Helper function to handle unexpected Exceptions during Parameter parsing and validation. - /// May be overridden to return custom error formats. This is called inside a catch block. - /// Important: When overriding, do not call `throw ex;`, but instead use `throw;`. - /// - virtual void handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept; - - /// - /// Helper function to handle unexpected Exceptions during Parameter parsing and validation. - /// May be overridden to return custom error formats. This is called inside a catch block. - /// Important: When overriding, do not call `throw ex;`, but instead use `throw;`. - /// - virtual std::pair handleParsingException(const std::exception& ex) const noexcept; - - /// - /// Helper function to handle unexpected Exceptions during processing of the request in handler functions. - /// May be overridden to return custom error formats. This is called inside a catch block. - /// Important: When overriding, do not call `throw ex;`, but instead use `throw;`. - /// - virtual void handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept; - - /// - /// Helper function to handle unexpected Exceptions during processing of the request in handler functions. - /// May be overridden to return custom error formats. This is called inside a catch block. - /// Important: When overriding, do not call `throw ex;`, but instead use `throw;`. - /// - virtual std::pair handleOperationException(const std::exception& ex) const noexcept; - - /// - /// Cancel running data collection - /// - /// - /// Command will inform FPGA network card to stop pedestal or data collection at the current stage. Any frame that is currently being processed by CPU will be finished and sent to writer. Given the command is making sure to gracefully stop data acquisition and detector, it might take some time to switch back after command finished to `Idle` state. If data collection is not running, the command has no effect. - /// - virtual void cancel_post( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get azimuthal integration configuration - /// - /// - /// Can be done anytime - /// - virtual void config_azim_int_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Configure azimuthal integration - /// - /// - /// Can be done when detector is Inactive or Idle - /// - /// (optional) - virtual void config_azim_int_put( const org::openapitools::server::model::Azim_int_settings &azimIntSettings, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get settings for dark data collection to calculate mask - /// - /// - /// - /// - virtual void config_dark_mask_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Set configuration for dark data collection to calculate mask - /// - /// - /// This is only possible when operating DECTRIS detectors at the moment; it will be also available for PSI EIGER at some point. This can only be done when detector is `Idle`, `Error` or `Inactive` states. - /// - /// (optional) - virtual void config_dark_mask_put( const org::openapitools::server::model::Dark_mask_settings &darkMaskSettings, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get detector configuration - /// - /// - /// Can be done anytime - /// - virtual void config_detector_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Change detector configuration - /// - /// - /// Detector settings are ones that have effect on calibration, i.e., pedestal has to be collected again after changing these settings. This can only be done when detector is `Idle`, `Error` or `Inactive` states. If detector is in `Idle` state , pedestal procedure will be executed automatically - there must be no X-rays on the detector during the operation. If detector is in `Inactive` or `Error` states, new settings will be saved, but no calibration will be executed. - /// - /// (optional) - virtual void config_detector_put( const org::openapitools::server::model::Detector_settings &detectorSettings, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get file writer settings - /// - /// - /// Can be done anytime - /// - virtual void config_file_writer_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Change file writer settings - /// - /// - /// This can only be done when detector is `Idle`, `Error` or `Inactive` states. - /// - /// (optional) - virtual void config_file_writer_put( const org::openapitools::server::model::File_writer_settings &fileWriterSettings, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Configure format for data collection with full conversion - /// - /// - /// This can only be done when detector is `Idle`, `Error` or `Inactive` states. - /// - virtual void config_image_format_conversion_post( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get image output format - /// - /// - /// Can be done anytime - /// - virtual void config_image_format_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Change image output format - /// - /// - /// This can only be done when detector is `Idle`, `Error` or `Inactive` states. - /// - /// (optional) - virtual void config_image_format_put( const org::openapitools::server::model::Image_format_settings &imageFormatSettings, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Configure format for raw data collection - /// - /// - /// This can only be done when detector is `Idle`, `Error` or `Inactive` states. - /// - virtual void config_image_format_raw_post( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get indexing configuration - /// - /// - /// Can be done anytime - /// - virtual void config_indexing_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Change indexing algorithm settings - /// - /// - /// This can only be done when detector is `Idle`, `Error` or `Inactive` states. - /// - /// (optional) - virtual void config_indexing_put( const org::openapitools::server::model::Indexing_settings &indexingSettings, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get instrument metadata - /// - /// - /// Can be done anytime - /// - virtual void config_instrument_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Change instrument metadata - /// - /// - /// This can only be done when detector is `Idle`, `Error` or `Inactive` states. - /// - /// (optional) - virtual void config_instrument_put( const org::openapitools::server::model::Instrument_metadata &instrumentMetadata, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Load binary image for internal FPGA generator - /// - /// - /// Load image for internal FPGA generator. This can only happen in Idle state of the detector. Requires binary blob with 16-bit integer numbers of size of detector in raw/converted coordinates (depending on detector settings). - /// - virtual void config_internal_generator_image_put(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Load TIFF image for internal FPGA generator - /// - /// - /// Load image for internal FPGA generator. This can only happen in Idle state of the detector. Requires TIFF with 16-bit integer numbers of size of detector in raw/converted coordinates (depending on detector settings). - /// - virtual void config_internal_generator_image_tiff_put(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get mask of the detector (binary) - /// - /// - /// Detector must be Initialized. Get full pixel mask of the detector. See NXmx standard for meaning of pixel values. - /// - virtual void config_mask_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get mask of the detector (TIFF) - /// - /// - /// Should be in `Idle` state. Get full pixel mask of the detector See NXmx standard for meaning of pixel values - /// - virtual void config_mask_tiff_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get ROI definitions - /// - /// - /// - /// - virtual void config_roi_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Upload ROI definitions - /// - /// - /// - /// - /// (optional) - virtual void config_roi_put( const org::openapitools::server::model::Roi_definitions &roiDefinitions, Pistache::Http::ResponseWriter &response) = 0; - /// - /// List available detectors - /// - /// - /// Configured detectors that can be selected by used - /// - virtual void config_select_detector_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Select detector - /// - /// - /// Jungfraujoch allows to control multiple detectors and/or region-of-interests. The command allows to choose one detector from the list (ID has to be consistent with one provided by GET response). Changing detector will set detector to `Inactive` state and will require reinitialization. - /// - /// (optional) - virtual void config_select_detector_put( const org::openapitools::server::model::Detector_selection &detectorSelection, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get data processing configuration - /// - /// - /// Can be done anytime - /// - virtual void config_spot_finding_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Configure spot finding - /// - /// - /// Can be done anytime, also while data collection is running - /// - /// (optional) - virtual void config_spot_finding_put( const org::openapitools::server::model::Spot_finding_settings &spotFindingSettings, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Detector must be Initialized. Get user mask of the detector (binary) - /// - /// - /// Get user pixel mask of the detector in the actual detector coordinates: 0 - good pixel, 1 - masked - /// - virtual void config_user_mask_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Upload user mask of the detector (binary) - /// - /// - /// Should be in `Idle` state. Upload user mask of the detector - this is for example to account for beam stop shadow or misbehaving regions. If detector is conversion mode the mask can be both in raw (1024x512; stacked modules) or converted coordinates. In the latter case - module gaps are ignored and don't need to be assigned value. Mask is expected as binary array (4-byte; unsigned). 0 - good pixel, other value - masked User mask is stored in NXmx pixel mask (bit 8), as well as used in spot finding and azimuthal integration. - /// - virtual void config_user_mask_put(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Detector must be Initialized. Get user mask of the detector (TIFF) - /// - /// - /// Get user pixel mask of the detector in the actual detector coordinates: 0 - good pixel, 1 - masked - /// - virtual void config_user_mask_tiff_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Upload user mask of the detector - /// - /// - /// Should be in `Idle` state. Upload user mask of the detector - this is for example to account for beam stop shadow or misbehaving regions. If detector is conversion mode the mask can be both in raw (1024x512; stacked modules) or converted coordinates. In the latter case - module gaps are ignored and don't need to be assigned value. Mask is expected as TIFF (4-byte; unsigned). 0 - good pixel, other value - masked User mask is stored in NXmx pixel mask (bit 8), as well as used in spot finding and azimuthal integration. User mask is not automatically applied - i.e. pixels with user mask will have a valid pixel value in the images. - /// - virtual void config_user_mask_tiff_put(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get ZeroMQ metadata socket settings - /// - /// - /// - /// - virtual void config_zeromq_metadata_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Set ZeroMQ metadata settings - /// - /// - /// Jungfraujoch can generate metadata message stream on ZeroMQ PUB socket. This stream covers all images. Here settings of the socket can be adjusted. While the data structure contains also socket_address, this cannot be changed via HTTP and is ignore in PUT request. - /// - /// (optional) - virtual void config_zeromq_metadata_put( const org::openapitools::server::model::Zeromq_metadata_settings &zeromqMetadataSettings, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get ZeroMQ preview settings - /// - /// - /// - /// - virtual void config_zeromq_preview_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Set ZeroMQ preview settings - /// - /// - /// Jungfraujoch can generate preview message stream on ZeroMQ SUB socket. Here settings of the socket can be adjusted. While the data structure contains also socket_address, this cannot be changed via HTTP and is ignore in PUT request. Options set with this PUT request have no effect on HTTP based preview. - /// - /// (optional) - virtual void config_zeromq_preview_put( const org::openapitools::server::model::Zeromq_preview_settings &zeromqPreviewSettings, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Prepare detector to turn off - /// - /// - /// Should be in `Idle` or `Error` state. Command deactivates data acquisition and turns off detector high voltage and ASIC. Should be used always before turning off power from the detector. - /// - virtual void deactivate_post( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get detector status - /// - /// - /// Status of the JUNGFRAU detector - /// - virtual void detector_status_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get status of FPGA devices - /// - /// - /// - /// - virtual void fpga_status_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Clear image buffer - /// - /// - /// Turns off image buffer for the last data collection. Can be only run when Jungfraujoch is not collecting data. - /// - virtual void image_buffer_clear_post( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get image message in CBOR format - /// - /// - /// Contains full image data and metadata. The image must come from the latest data collection. - /// - /// Image ID in the image buffer. Special values: -1 - last image in the buffer, -2: last indexed image in the buffer (optional, default to -1L) - virtual void image_buffer_image_cbor_get( const std::optional &id, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get preview image in JPEG format using custom settings - /// - /// - /// - /// - /// Image ID in the image buffer. Special values: -1 - last image in the buffer, -2: last indexed image in the buffer (optional, default to -1L) - /// Show user mask (optional, default to false) - /// Show ROI areas on the image (optional, default to false) - /// Show spot finding results on the image (optional, default to true) - /// Show beam center on the image (optional, default to true) - /// Saturation value to set contrast in the preview image; if not provided, then autocontrast procedure is used (optional, default to 0.0f) - /// Quality of JPEG image (100 - highest; 0 - lowest) (optional, default to 100L) - /// Show resolution ring, provided in Angstrom (optional, default to 0.1f) - /// Color scale for preview image (optional, default to "indigo") - /// Show resolution estimation as a ring (optional, default to false) - virtual void image_buffer_image_jpeg_get( const std::optional &id, const std::optional &showUserMask, const std::optional &showRoi, const std::optional &showSpots, const std::optional &showBeamCenter, const std::optional &saturation, const std::optional &jpegQuality, const std::optional &showResRing, const std::optional &color, const std::optional &showResEst, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get preview image in TIFF format - /// - /// - /// - /// - /// Image ID in the image buffer. Special values: -1 - last image in the buffer, -2: last indexed image in the buffer (optional, default to -1L) - virtual void image_buffer_image_tiff_get( const std::optional &id, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get Start message in CBOR format - /// - /// - /// Contains metadata for a dataset (e.g., experimental geometry) - /// - virtual void image_buffer_start_cbor_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get status of the image buffers - /// - /// - /// Can be run at any stage of Jungfraujoch operation, including during data collection. The status of the image buffer is volatile during data collection - if data collection goes for more images than available buffer slots, then image might be replaced in the buffer between calling /images and /image.cbor. - /// - virtual void image_buffer_status_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get status of image pusher - /// - /// - /// - /// - virtual void image_pusher_status_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Initialize detector and data acquisition - /// - /// - /// Should be used in two cases: - Detector is in `Inactive` state - Detector is in `Error` state X-ray shutter must be closed. This operation will reconfigure network interface of the detector. During operation of the detector it is recommended to use the `POST /pedestal` operation instead. If storage cells are used, the execution time might be few minutes. This is async function - one needs to use `POST /wait_till_done` to ensure operation is done. - /// - virtual void initialize_post( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Collect dark current for the detector - /// - /// - /// Updates calibration of the JUNGFRAU detector. Must be in `Idle` state. X-ray shutter must be closed. Recommended to run once per hour for long integration times (> 100 us). This is async function - one needs to use `POST /wait_till_done` to ensure operation is done. - /// - virtual void pedestal_post( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get pedestal in TIFF format - /// - /// - /// - /// - /// Gain level (0, 1, 2) - /// Storage cell number (optional, default to 0) - virtual void preview_pedestal_tiff_get( const std::optional &gainLevel, const std::optional &sc, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Generate 1D plot from Jungfraujoch and send in raw binary format. Data are provided as (32-bit) float binary array. This format doesn't transmit information about X-axis, only values, so it is of limited use for azimuthal integration. - /// - /// - /// - /// - /// Type of requested plot - /// Name of ROI for which plot is requested (optional, default to "") - virtual void preview_plot_bin_get( const std::optional &type, const std::optional &roi, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Generate 1D plot from Jungfraujoch - /// - /// - /// - /// - /// Type of requested plot - /// Binning of frames for the plot (0 = default binning) (optional, default to 1) - /// Enable DEFLATE compression of output data. (optional, default to false) - /// Fill value for elements that were missed during data collection (optional, default to 0.0f) - /// If measurement has goniometer axis defined, plot X-axis will represent rotation angle If measurement has grid scan defined, plot X-axis and Y-axis will represent grid position, Z will be used as the final value For still measurement the number is ignored (optional, default to false) - /// Unit used for azim int. (optional, default to "Q_recipA") - virtual void preview_plot_get( const std::optional &type, const std::optional &binning, const std::optional &compression, const std::optional &fill, const std::optional &experimentalCoord, const std::optional &azintUnit, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get full scan result - /// - /// - /// - /// - virtual void result_scan_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Start detector - /// - /// - /// Start data acquisition. Detector must be in `Idle` state. Doesn't run calibration procedure. When the function returns, detector is ready to accept soft/TTL triggers. - /// - /// (optional) - virtual void start_post( const org::openapitools::server::model::Dataset_settings &datasetSettings, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get calibration statistics - /// - /// - /// Statistics are provided for each module/storage cell separately - /// - virtual void statistics_calibration_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get data collection statistics - /// - /// - /// Results of the last data collection - /// - virtual void statistics_data_collection_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get general statistics - /// - /// - /// - /// - /// Enable DEFLATE compression of output data. (optional, default to false) - virtual void statistics_get( const std::optional &compression, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get Jungfraujoch status - /// - /// - /// Status of the data acquisition - /// - virtual void status_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Send soft trigger to the detector - /// - /// - /// Generate soft trigger - /// - virtual void trigger_post( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get Jungfraujoch version of jfjoch_broker - /// - /// - /// - /// - virtual void version_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Wait for acquisition done - /// - /// - /// Block execution of external script till initialization, data collection or pedestal is finished. Running this command does not affect (cancel) running data collection, it is only to ensure synchronous execution of other software. To not block web server for a indefinite period of time, the procedure is provided with a timeout. Extending timeout is possible, but requires to ensure safety that client will not close the connection and retry the connection. - /// - /// Timeout in seconds (0 == immediate response) (optional, default to 60) - virtual void wait_till_done_post( const std::optional &timeout, Pistache::Http::ResponseWriter &response) = 0; - /// - /// Return XFEL event codes for the current data acquisition - /// - /// - /// Return array of XFEL event codes - /// - virtual void xfel_event_code_get( Pistache::Http::ResponseWriter &response) = 0; - /// - /// Return XFEL pulse IDs for the current data acquisition - /// - /// - /// Return array of XFEL pulse IDs - (-1) if image not recorded - /// - virtual void xfel_pulse_id_get( Pistache::Http::ResponseWriter &response) = 0; - -}; - -} // namespace org::openapitools::server::api - -#endif /* DefaultApi_H_ */ - diff --git a/broker/jfjoch_broker.cpp b/broker/jfjoch_broker.cpp index 90d84809..a10fb39b 100644 --- a/broker/jfjoch_broker.cpp +++ b/broker/jfjoch_broker.cpp @@ -2,33 +2,35 @@ // SPDX-License-Identifier: GPL-3.0-only // Using OpenAPI licensed with Apache License 2.0 -#include #include #include +#include +#include + #include #include "../common/Logger.h" - -#include "JFJochBrokerHttp.h" - -#include "JFJochBrokerParser.h" -#include "../writer/HDF5Objects.h" #include "../common/print_license.h" #include "../detector_control/DectrisSimplonClient.h" +#include "../writer/HDF5Objects.h" -static Pistache::Http::Endpoint *httpEndpoint; +#include "JFJochBrokerHttp.h" +#include "JFJochBrokerParser.h" -static void sigHandler [[noreturn]] (int sig){ - switch(sig){ +static httplib::Server *httpServer = nullptr; + +static void sigHandler [[noreturn]] (int sig) { + switch (sig) { case SIGINT: case SIGQUIT: case SIGTERM: case SIGHUP: default: - httpEndpoint->shutdown(); + if (httpServer) + httpServer->stop(); break; } - exit(0); + std::exit(0); } static void setUpUnixSignals(std::vector quitSignals) { @@ -39,30 +41,28 @@ static void setUpUnixSignals(std::vector quitSignals) { struct sigaction sa; sa.sa_handler = sigHandler; - sa.sa_mask = blocking_mask; - sa.sa_flags = 0; + sa.sa_mask = blocking_mask; + sa.sa_flags = 0; for (auto sig : quitSignals) sigaction(sig, &sa, nullptr); } -int main (int argc, char **argv) { +int main(int argc, char **argv) { RegisterHDF5Filter(); - print_license("jfjoch_broker"); if ((argc == 1) || (argc > 3)) { std::cout << "Usage ./jfjoch_broker {}" << std::endl; - exit(EXIT_FAILURE); + return EXIT_FAILURE; } uint16_t http_port = 5232; - if (argc >= 3) http_port = atoi(argv[2]); + if (argc >= 3) http_port = static_cast(std::atoi(argv[2])); Logger logger("jfjoch_broker"); org::openapitools::server::model::Jfjoch_settings settings; - std::ifstream file(argv[1]); try { nlohmann::json input = nlohmann::json::parse(file); @@ -71,7 +71,7 @@ int main (int argc, char **argv) { logger.Info("JSON configuration file read properly"); } catch (const std::exception &e) { logger.Error("Error reading JSON configuration file: " + std::string(e.what())); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (settings.verboseIsSet() && settings.isVerbose()) @@ -80,7 +80,6 @@ int main (int argc, char **argv) { logger.Verbose(false); std::unique_ptr image_pusher = ParseImagePusher(settings); - if (image_pusher) logger.Info(image_pusher->PrintSetup()); @@ -90,7 +89,7 @@ int main (int argc, char **argv) { if (det_setup.empty()) { logger.Error("At least one detector need to be defined in the config file"); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } DiffractionExperiment experiment(det_setup[0]); @@ -100,36 +99,14 @@ int main (int argc, char **argv) { AcquisitionDeviceGroup aq_devices; ParseAcquisitionDeviceGroup(settings, aq_devices); - experiment.DataStreams(aq_devices.size()); int32_t send_buffer_size_MiB = settings.getImageBufferMiB(); - std::unique_ptr receiver - = std::make_unique(aq_devices, logger, *image_pusher, send_buffer_size_MiB); + std::unique_ptr receiver = + std::make_unique(aq_devices, logger, *image_pusher, send_buffer_size_MiB); ParseReceiverSettings(settings, *receiver); - Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(http_port)); - - httpEndpoint = new Pistache::Http::Endpoint((addr)); - - auto router = std::make_shared(); - - auto opts = Pistache::Http::Endpoint::options().threads(8).maxRequestSize(64*1024*1024); - opts.flags(Pistache::Tcp::Options::ReuseAddr); - - httpEndpoint->init(opts); - - if (settings.sslIsSet()) { - auto ssl = settings.getSsl(); - httpEndpoint->useSSL(ssl.getCertificate(), ssl.getKey(), true); - // We allow compression. While this introduces certain vulnerabilities, but risk is so small we ignore this. - } - - signal(SIGPIPE, SIG_IGN); - std::vector sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP}; - setUpUnixSignals(sigs); - - JFJochBrokerHttp broker(experiment, spot_finding_settings, router); + JFJochBrokerHttp broker(experiment, spot_finding_settings); broker.FrontendDirectory(settings.getFrontendDirectory()); for (const auto &d: det_setup) @@ -138,8 +115,24 @@ int main (int argc, char **argv) { if (receiver) broker.Services().Receiver(receiver.get()); - httpEndpoint->setHandler(router->handler()); - httpEndpoint->serve(); + httplib::Server server; + httpServer = &server; - httpEndpoint->shutdown(); -} \ No newline at end of file + if (settings.sslIsSet()) { + auto ssl = settings.getSsl(); + server.ssl_context(ssl.getCertificate().c_str(), ssl.getKey().c_str()); + } + + signal(SIGPIPE, SIG_IGN); + std::vector sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP}; + setUpUnixSignals(sigs); + + broker.attach(server); + + if (!server.listen("0.0.0.0", http_port)) { + logger.Error("Failed to start HTTP server"); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/update_version.sh b/update_version.sh index 7d59978d..8ec2e0d3 100644 --- a/update_version.sh +++ b/update_version.sh @@ -38,7 +38,6 @@ git rm broker/gen/model/*.cpp broker/gen/model/*.h frontend/src/openapi/models/* java -jar openapi-generator-cli.jar generate -i broker/jfjoch_api.yaml -o python-client/ -g python --git-host=git.psi.ch --git-repo-id jungfraujoch --git-user-id jungfraujoch --additional-properties=packageName=jfjoch_client,packageVersion=$VERSION java -jar openapi-generator-cli.jar generate -i broker/jfjoch_api.yaml -o broker/gen -g cpp-pistache-server -java -jar openapi-generator-cli.jar generate -i broker/jfjoch_api.yaml -o broker/httplib-server -g cpp-httplib-server cd frontend sed -i s/\".*\"/\"$VERSION\"/g src/version.ts