pars 0.2.1
Loading...
Searching...
No Matches
event.h
Go to the documentation of this file.
1/*
2Copyright (c) 2025 Giuseppe Roberti.
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without modification,
6are permitted provided that the following conditions are met:
7
81. Redistributions of source code must retain the above copyright notice, this
9list of conditions and the following disclaimer.
10
112. Redistributions in binary form must reproduce the above copyright notice,
12this list of conditions and the following disclaimer in the documentation and/or
13other materials provided with the distribution.
14
153. Neither the name of the copyright holder nor the names of its contributors
16may be used to endorse or promote products derived from this software without
17specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*/
30#pragma once
31
32#include "pars/ev/klass.h"
33#include "pars/fmt/stl.h"
34#include "pars/net/dir.h"
35
36#include "clev/err.h"
37
38#include <cereal/types/vector.hpp>
39
40#include <chrono>
41#include <format>
42
43namespace pars::ev
44{
45
47{
48 auto format_to(std::format_context& ctx) const -> decltype(ctx.out())
49 {
50 return std::format_to(ctx.out(), "creating_pipe()");
51 }
52};
53
54template<>
55struct klass<creating_pipe> : base_klass<creating_pipe>
56{
57 static constexpr std::string_view uuid =
58 "adf2e44f-b005-449b-b849-e2b46377c122";
59};
60
62{
63 auto format_to(std::format_context& ctx) const -> decltype(ctx.out())
64 {
65 return std::format_to(ctx.out(), "pipe_created()");
66 }
67};
68
69template<>
70struct klass<pipe_created> : base_klass<pipe_created>
71{
72 static constexpr std::string_view uuid =
73 "2410aea6-ce8e-46d7-b3c4-0ef8ab598ef9";
74};
75
77{
78 auto format_to(std::format_context& ctx) const -> decltype(ctx.out())
79 {
80 return std::format_to(ctx.out(), "pipe_removed()");
81 }
82};
83
84template<>
85struct klass<pipe_removed> : base_klass<pipe_removed>
86{
87 static constexpr std::string_view uuid =
88 "5fe36da8-c46a-4ef4-872d-5f11d610eaeb";
89};
90
92{
93 std::error_code error;
95
96 auto format_to(std::format_context& ctx) const -> decltype(ctx.out())
97 {
98 return std::format_to(ctx.out(), "network_error({}, {})", error,
99 (dir == net::dir::out ? "out" : "in"));
100 }
101};
102
103template<>
104struct klass<network_error> : base_klass<network_error>
105{
106 static constexpr std::string_view uuid =
107 "53b44f06-c5b3-400f-8e7e-522cb39c1168";
108};
109
111{
112 std::exception_ptr eptr;
113
114 std::string str() const
115 {
116 try
117 {
118 std::rethrow_exception(eptr);
119 }
120 catch (clev::exception& e)
121 {
122 return std::format("{}", e.what());
123 }
124 catch (std::exception& e)
125 {
126 return std::format("{}", e.what());
127 }
128 catch (...)
129 {
130 return "Unknown!";
131 }
132 return "<empty-exception>";
133 }
134
135 auto format_to(std::format_context& ctx) const -> decltype(ctx.out())
136 {
137 return std::format_to(ctx.out(), "{}", str());
138 }
139};
140
141template<>
142struct klass<exception> : base_klass<exception>
143{
144 static constexpr std::string_view uuid =
145 "25d02d6b-38d1-414b-a5ff-60d93c7746c9";
146
147 static constexpr bool requires_network = false;
148};
149
150struct init
151{
152 auto format_to(std::format_context& ctx) const -> decltype(ctx.out())
153 {
154 return std::format_to(ctx.out(), "init({})", creation_time);
155 }
156
157private:
158 std::chrono::system_clock::time_point creation_time =
159 std::chrono::system_clock::now();
160};
161
162template<>
163struct klass<init> : base_klass<init>
164{
165 static constexpr std::string_view uuid =
166 "bacffaf3-3f6a-4859-8495-c3b821ec69d5";
167
168 static constexpr bool requires_network = false;
169};
170
172{
173 auto format_to(std::format_context& ctx) const -> decltype(ctx.out())
174 {
175 return std::format_to(ctx.out(), "shutdown({})", creation_time);
176 }
177
178private:
179 std::chrono::system_clock::time_point creation_time =
180 std::chrono::system_clock::now();
181};
182
183template<>
184struct klass<shutdown> : base_klass<shutdown>
185{
186 static constexpr std::string_view uuid =
187 "47c543bb-ba37-4442-a5bd-4b2dcfbf1e02";
188
189 static constexpr bool requires_network = false;
190};
191
192} // namespace pars::ev
auto format_to(std::format_context &ctx) const -> decltype(ctx.out())
Definition event.h:48
std::string str() const
Definition event.h:114
std::exception_ptr eptr
Definition event.h:112
auto format_to(std::format_context &ctx) const -> decltype(ctx.out())
Definition event.h:135
auto format_to(std::format_context &ctx) const -> decltype(ctx.out())
Definition event.h:152
static constexpr std::string_view uuid
Definition event.h:57
static constexpr std::string_view uuid
Definition event.h:144
static constexpr bool requires_network
Definition event.h:147
static constexpr bool requires_network
Definition event.h:168
static constexpr std::string_view uuid
Definition event.h:165
static constexpr std::string_view uuid
Definition event.h:106
static constexpr std::string_view uuid
Definition event.h:72
static constexpr std::string_view uuid
Definition event.h:87
static constexpr std::string_view uuid
Definition event.h:186
static constexpr bool requires_network
Definition event.h:189
auto format_to(std::format_context &ctx) const -> decltype(ctx.out())
Definition event.h:96
std::error_code error
Definition event.h:93
auto format_to(std::format_context &ctx) const -> decltype(ctx.out())
Definition event.h:63
auto format_to(std::format_context &ctx) const -> decltype(ctx.out())
Definition event.h:78
auto format_to(std::format_context &ctx) const -> decltype(ctx.out())
Definition event.h:173