diff options
Diffstat (limited to 'server/src/api.cpp')
| -rw-r--r-- | server/src/api.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/server/src/api.cpp b/server/src/api.cpp index 8a986d4..c926955 100644 --- a/server/src/api.cpp +++ b/server/src/api.cpp | |||
| @@ -102,8 +102,16 @@ auto tag_invoke(json::value_from_tag, json::value& jv, sysinfo const& info) | |||
| 102 | handler::handler( | 102 | handler::handler( |
| 103 | log::logger const& l, std::shared_ptr<database::connection> dbc, | 103 | log::logger const& l, std::shared_ptr<database::connection> dbc, |
| 104 | datex2::situation_publication pub) | 104 | datex2::situation_publication pub) |
| 105 | : l_{l.sub("handler")}, dbc_{std::move(dbc)}, pub_{std::move(pub)} | 105 | : l_{l.sub("handler")}, dbc_{std::move(dbc)} |
| 106 | { | 106 | { |
| 107 | situation_publication(std::move(pub)); | ||
| 108 | } | ||
| 109 | |||
| 110 | indexed_pub::indexed_pub( | ||
| 111 | log::logger const& l, datex2::situation_publication pub) | ||
| 112 | : pub_{std::move(pub)} | ||
| 113 | { | ||
| 114 | auto l_ = l.sub("indexed_pub"); | ||
| 107 | auto const nsit = pub_.situations.size(); | 115 | auto const nsit = pub_.situations.size(); |
| 108 | auto progress_percent = | 116 | auto progress_percent = |
| 109 | [nsit](decltype(pub_.situations)::difference_type i) -> int | 117 | [nsit](decltype(pub_.situations)::difference_type i) -> int |
| @@ -146,12 +154,18 @@ handler::handler( | |||
| 146 | l_.info("BPE index size: {}", bpe_index_.size()); | 154 | l_.info("BPE index size: {}", bpe_index_.size()); |
| 147 | } | 155 | } |
| 148 | 156 | ||
| 157 | auto handler::situation_publication(datex2::situation_publication pub) -> void | ||
| 158 | { | ||
| 159 | ipub_.store(std::make_shared<indexed_pub>(l_, std::move(pub))); | ||
| 160 | } | ||
| 161 | |||
| 149 | auto handler::process_gpx( | 162 | auto handler::process_gpx( |
| 150 | trace::id trace_id, gpx::file&& gpx_file, | 163 | trace::id trace_id, gpx::file&& gpx_file, |
| 151 | time::period_seq<std::chrono::minutes> const& check_periods) | 164 | time::period_seq<std::chrono::minutes> const& check_periods) |
| 152 | -> std::optional<process_gpx_result> | 165 | -> std::optional<process_gpx_result> |
| 153 | { | 166 | { |
| 154 | auto l = l_.with("trace_id", trace_id.as_string()); | 167 | auto l = l_.with("trace_id", trace_id.as_string()); |
| 168 | auto const ipub = ipub_.load(); | ||
| 155 | 169 | ||
| 156 | // TODO: eliminate use of overlap segments | 170 | // TODO: eliminate use of overlap segments |
| 157 | auto segments = std::vector<geo::utm::zonable_wgs84_linestring>{}; | 171 | auto segments = std::vector<geo::utm::zonable_wgs84_linestring>{}; |
| @@ -178,7 +192,7 @@ auto handler::process_gpx( | |||
| 178 | auto part_box = geo::wgs84::box{}; | 192 | auto part_box = geo::wgs84::box{}; |
| 179 | bgeo::envelope(part, part_box); | 193 | bgeo::envelope(part, part_box); |
| 180 | 194 | ||
| 181 | for (auto const& rc : blse_index_.intersection(part_zone_lss)) | 195 | for (auto const& rc : ipub->blse_index().intersection(part_zone_lss)) |
| 182 | { | 196 | { |
| 183 | if (rc->validity | 197 | if (rc->validity |
| 184 | && rc->validity->intersect(check_periods).periods().empty()) | 198 | && rc->validity->intersect(check_periods).periods().empty()) |
| @@ -195,7 +209,7 @@ auto handler::process_gpx( | |||
| 195 | // relevant_road_closures.emplace(rc); | 209 | // relevant_road_closures.emplace(rc); |
| 196 | ls_checked++; | 210 | ls_checked++; |
| 197 | } | 211 | } |
| 198 | for (auto const& rc : bpe_index_.intersection(part_zone_lss)) | 212 | for (auto const& rc : ipub->bpe_index().intersection(part_zone_lss)) |
| 199 | { | 213 | { |
| 200 | if (rc->validity | 214 | if (rc->validity |
| 201 | && rc->validity->intersect(check_periods).periods().empty()) | 215 | && rc->validity->intersect(check_periods).periods().empty()) |
| @@ -278,10 +292,11 @@ auto handler::process_gpx( | |||
| 278 | 292 | ||
| 279 | auto handler::sysinfo() -> struct sysinfo | 293 | auto handler::sysinfo() -> struct sysinfo |
| 280 | { | 294 | { |
| 295 | auto const ipub = ipub_.load(); | ||
| 281 | return { | 296 | return { |
| 282 | .using_publication_of = pub_.publication_time, | 297 | .using_publication_of = ipub->pub().publication_time, |
| 283 | .blse_index_size = blse_index_.size(), | 298 | .blse_index_size = ipub->blse_index().size(), |
| 284 | .bpe_index_size = bpe_index_.size(), | 299 | .bpe_index_size = ipub->bpe_index().size(), |
| 285 | }; | 300 | }; |
| 286 | } | 301 | } |
| 287 | 302 | ||