LCOV - code coverage report
Current view: top level - app/src/Com/http - staticSimulationJoinGet.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 16 0.0 %
Date: 2023-08-17 16:45:52 Functions: 0 1 0.0 %

          Line data    Source code
       1             : #include <spdlog/spdlog.h>
       2             : 
       3             : #include <nlohmann/json.hpp>
       4             : 
       5             : #include "Com/HTTPServer.hpp"
       6             : #include "GlobalState.hpp"
       7             : 
       8             : using namespace std;
       9             : using namespace Com;
      10             : 
      11             : using json = nlohmann::json;
      12             : 
      13             : /**yaml GET /static/simulation/{id}/join
      14             :  * summary: Wait for simulation to finish.
      15             :  * tags:
      16             :  *   - Static
      17             :  * parameters:
      18             :  *   - name: id
      19             :  *     in: path
      20             :  *     required: true
      21             :  *     description: ID of simulation
      22             :  *     schema:
      23             :  *       type: string
      24             :  *       pattern: '^[\w\-]+$'
      25             :  * responses:
      26             :  *   '200':
      27             :  *     description: Successfully waited for simulation
      28             :  */
      29           0 : void HTTPServer::staticSimulationJoinGet(const httplib::Request &req, httplib::Response &res) {
      30           0 :     const string &resourceID = req.matches[1];
      31           0 :     const string &taskID     = "task://" + resourceID;
      32             : 
      33           0 :     try {
      34           0 :         shared_future<GlobalState::TaskReturn> &future = GlobalState::tasks.get(taskID);
      35             : 
      36           0 :         GlobalState::TaskReturn ret = future.get();
      37             : 
      38           0 :         res.status = ret.status;
      39           0 :         res.set_content(ret.content, ret.content_type);
      40           0 :     } catch(const GlobalState::ResourceException &e) {
      41           0 :         res.status = 400;
      42           0 :         res.set_content("what(): "s + e.what(), "text/plain");
      43           0 :     } catch(const exception &e) {
      44           0 :         res.status = 500;
      45           0 :         res.set_content("what(): "s + e.what(), "text/plain");
      46           0 :         spdlog::error("Exception, what(): {}", e.what());
      47             :     }
      48           0 : }

Generated by: LCOV version 1.14