diff options
Diffstat (limited to 'server/src/api.cppm')
| -rw-r--r-- | server/src/api.cppm | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/server/src/api.cppm b/server/src/api.cppm new file mode 100644 index 0000000..caeb44c --- /dev/null +++ b/server/src/api.cppm | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | module; | ||
| 2 | |||
| 3 | #include <boost/geometry.hpp> | ||
| 4 | #include <boost/json.hpp> | ||
| 5 | |||
| 6 | export module routemon:api; | ||
| 7 | |||
| 8 | import std; | ||
| 9 | import :datex2; | ||
| 10 | import :geo; | ||
| 11 | import :gpx; | ||
| 12 | import :log; | ||
| 13 | import :time; | ||
| 14 | import :trace; | ||
| 15 | |||
| 16 | namespace { | ||
| 17 | |||
| 18 | namespace chrono = std::chrono; | ||
| 19 | namespace json = boost::json; | ||
| 20 | namespace views = std::views; | ||
| 21 | |||
| 22 | } // namespace <anonymous> | ||
| 23 | |||
| 24 | export | ||
| 25 | namespace routemon::api { | ||
| 26 | |||
| 27 | struct relevant_road_closure { | ||
| 28 | std::vector<geo::linestring> relevant_lss; | ||
| 29 | }; | ||
| 30 | auto tag_invoke(json::value_from_tag, json::value& jv, relevant_road_closure const& clo) -> void; | ||
| 31 | |||
| 32 | struct relevant_situation { | ||
| 33 | std::string id; | ||
| 34 | std::optional<geo::point> location; | ||
| 35 | std::vector<std::string> comments; | ||
| 36 | std::vector<relevant_road_closure> relevant_road_closures; | ||
| 37 | }; | ||
| 38 | auto tag_invoke(json::value_from_tag, json::value& jv, relevant_situation const& sit) -> void; | ||
| 39 | |||
| 40 | struct track_segment { | ||
| 41 | geo::linestring points; | ||
| 42 | }; | ||
| 43 | auto tag_invoke(json::value_from_tag, json::value& jv, track_segment const& seg) -> void; | ||
| 44 | |||
| 45 | struct track { | ||
| 46 | std::vector<track_segment> segments; | ||
| 47 | }; | ||
| 48 | auto tag_invoke(json::value_from_tag, json::value& jv, track const& track) -> void; | ||
| 49 | |||
| 50 | struct process_gpx_result { | ||
| 51 | std::vector<track> tracks; | ||
| 52 | std::vector<relevant_situation> relevant_situations; | ||
| 53 | }; | ||
| 54 | auto tag_invoke(json::value_from_tag, json::value& jv, process_gpx_result const& res) -> void; | ||
| 55 | |||
| 56 | struct sysinfo { | ||
| 57 | time::timestamp using_publication_of; | ||
| 58 | }; | ||
| 59 | auto tag_invoke(json::value_from_tag, json::value& jv, sysinfo const& info) -> void; | ||
| 60 | |||
| 61 | class handler { | ||
| 62 | using lse_index_value = std::tuple<geo::box, std::shared_ptr<geo::linestring>, std::shared_ptr<datex2::road_closure>>; | ||
| 63 | using p_index_value = std::pair<geo::point, std::shared_ptr<datex2::road_closure>>; | ||
| 64 | using lse_index = bgeo::index::rtree<lse_index_value, bgeo::index::quadratic<16>>; | ||
| 65 | using p_index = bgeo::index::rtree<p_index_value, bgeo::index::quadratic<16>>; | ||
| 66 | |||
| 67 | log::logger l_; | ||
| 68 | datex2::situation_publication pub_; | ||
| 69 | lse_index lse_index_; | ||
| 70 | p_index p_index_; | ||
| 71 | |||
| 72 | public: | ||
| 73 | explicit handler(log::logger const& l, datex2::situation_publication pub); | ||
| 74 | |||
| 75 | auto process_gpx(gpx::file&& gpx_file) -> std::optional<process_gpx_result>; | ||
| 76 | auto sysinfo() -> sysinfo; | ||
| 77 | }; | ||
| 78 | |||
| 79 | } // namespace routemon::api | ||