summaryrefslogtreecommitdiffstats
path: root/server/src/http/ext/gpx.cpp
diff options
context:
space:
mode:
authorRutger Broekhoff2026-11-30 21:27:55 +0100
committerRutger Broekhoff2026-11-30 21:27:55 +0100
commit7bba7176194c4d1d9c7066f8eda7a94491d924e6 (patch)
treea9a171e8608786e09d6342729ee13b8471c0c9c2 /server/src/http/ext/gpx.cpp
parent02475e05ccd1aa15c6a6163834f28bfebbef796f (diff)
downloadroutemon-7bba7176194c4d1d9c7066f8eda7a94491d924e6.tar.gz
routemon-7bba7176194c4d1d9c7066f8eda7a94491d924e6.zip
Cleanups and updates
Diffstat (limited to 'server/src/http/ext/gpx.cpp')
-rw-r--r--server/src/http/ext/gpx.cpp139
1 files changed, 139 insertions, 0 deletions
diff --git a/server/src/http/ext/gpx.cpp b/server/src/http/ext/gpx.cpp
new file mode 100644
index 0000000..c1f565f
--- /dev/null
+++ b/server/src/http/ext/gpx.cpp
@@ -0,0 +1,139 @@
1module;
2
3#include <boost/beast/core.hpp>
4
5module routemon:http.ext.gpx$impl;
6
7import :http.ext.gpx;
8
9namespace chrono = std::chrono;
10
11namespace routemon::http::ext::gpx {
12
13auto parse_error_category_impl::name() const noexcept -> char const*
14{
15 return "gpx_parse";
16}
17
18auto parse_error_category_impl::message(int condition) const noexcept
19 -> std::string
20{
21 std::ignore = condition;
22 return "failed to parse GPX file";
23}
24
25auto parse_error_category() noexcept -> parse_error_category_impl const&
26{
27 static auto const inst = parse_error_category_impl{};
28 return inst;
29}
30
31auto parse_error() noexcept -> std::error_code
32{
33 return std::error_code{1, parse_error_category()};
34}
35
36auto parse_result::set_exception(std::exception_ptr ex) noexcept -> void
37{
38 res_ = ex;
39}
40
41auto parse_result::set_gpx_file(routemon::gpx::file&& f) noexcept -> void
42{
43 res_ = std::move(f);
44}
45
46auto parse_result::init_parse_duration(
47 chrono::steady_clock::duration dur) noexcept -> void
48{
49 init_parse_dur_ = dur;
50}
51
52[[nodiscard]] auto parse_result::init_parse_duration() const noexcept
53 -> chrono::steady_clock::duration
54{
55 return init_parse_dur_;
56}
57
58auto parse_result::put_parse_duration(
59 chrono::steady_clock::duration dur) noexcept -> void
60{
61 put_parse_dur_ = dur;
62}
63
64[[nodiscard]] auto parse_result::put_parse_duration() const noexcept
65 -> chrono::steady_clock::duration
66{
67 return put_parse_dur_;
68}
69
70auto parse_result::finish_parse_duration(
71 chrono::steady_clock::duration dur) noexcept -> void
72{
73 finish_parse_dur_ = dur;
74}
75
76[[nodiscard]] auto parse_result::finish_parse_duration() const noexcept
77 -> chrono::steady_clock::duration
78{
79 return finish_parse_dur_;
80}
81
82auto parse_result::unwrap() -> routemon::gpx::file&&
83{
84 return std::visit(
85 util::overloaded{
86 [](std::exception_ptr ex) -> routemon::gpx::file&&
87 {
88 if (ex)
89 std::rethrow_exception(ex);
90 else
91 throw std::runtime_error{"no GPX file parse result available"};
92 },
93 [](routemon::gpx::file&& f) -> routemon::gpx::file&&
94 { return std::move(f); },
95 },
96 std::move(res_));
97}
98
99auto body::reader::init(
100 boost::optional<std::uint64_t> /* n */, beast::error_code& ec) noexcept
101 -> void
102{
103 auto const init_start = chrono::steady_clock::now();
104 try
105 {
106 r_.init();
107 ec = {};
108 }
109 catch (std::exception& ex)
110 {
111 res_->set_exception(std::current_exception());
112 ec = parse_error();
113 }
114 res_->init_parse_duration(chrono::steady_clock::now() - init_start);
115}
116
117auto body::reader::finish(beast::error_code& ec) noexcept -> void
118{
119 auto const finish_start = chrono::steady_clock::now();
120 try
121 {
122 if (buf_.size() > 0)
123 {
124 r_.put(std::string_view{buf_});
125 buf_.clear();
126 }
127
128 res_->set_gpx_file(r_.finish());
129 ec = {};
130 }
131 catch (std::exception& ex)
132 {
133 res_->set_exception(std::current_exception());
134 ec = parse_error();
135 }
136 res_->finish_parse_duration(chrono::steady_clock::now() - finish_start);
137}
138
139} // namespace routemon::http::ext::gpx