Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
event.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
25#pragma once
26
27#include <concepts>
28#include <type_traits>
29#include <functional>
30#include <string>
31#include <chrono>
32
33namespace kcenon::common {
34namespace concepts {
35
51template<typename T>
52concept EventType = std::is_class_v<T> &&
53 std::is_copy_constructible_v<T>;
54
70template<typename H, typename E>
71concept EventHandler = std::invocable<H, const E&> &&
72 std::is_void_v<std::invoke_result_t<H, const E&>>;
73
92template<typename F, typename E>
93concept EventFilter = std::invocable<F, const E&> &&
94 std::convertible_to<std::invoke_result_t<F, const E&>, bool>;
95
112template<typename T>
113concept TimestampedEvent = EventType<T> && requires(const T t) {
114 { t.timestamp } -> std::convertible_to<std::chrono::steady_clock::time_point>;
115};
116
133template<typename T>
134concept NamedEvent = EventType<T> && requires(const T t) {
135 { t.module_name } -> std::convertible_to<std::string>;
136};
137
154template<typename T>
155concept ErrorEvent = EventType<T> && requires(const T t) {
156 { t.error_message } -> std::convertible_to<std::string>;
157 { t.error_code } -> std::convertible_to<int>;
158};
159
175template<typename T>
176concept MetricEvent = EventType<T> && requires(const T t) {
177 { t.name } -> std::convertible_to<std::string>;
178 { t.value } -> std::convertible_to<double>;
179 { t.unit } -> std::convertible_to<std::string>;
180};
181
197template<typename T>
199
216template<typename T>
218
234template<typename T>
236
251template<typename T>
252concept EventBusLike = requires(T t, uint64_t id) {
253 { t.start() } -> std::same_as<void>;
254 { t.stop() } -> std::same_as<void>;
255 { t.is_running() } -> std::convertible_to<bool>;
256 { t.unsubscribe(id) } -> std::same_as<void>;
257};
258
259} // namespace concepts
260} // namespace kcenon::common
An event type representing an error.
Definition event.h:155
A type that satisfies the event bus interface requirements.
Definition event.h:252
A callable that filters events based on criteria.
Definition event.h:93
A callable that can handle events of a specific type.
Definition event.h:71
A type that can be used as an event in the event bus.
Definition event.h:52
A complete error event with module, message, code, and timestamp.
Definition event.h:217
A complete metric event with timestamp.
Definition event.h:235
An event type representing a metric measurement.
Definition event.h:176
An event type representing module lifecycle changes.
Definition event.h:198
An event type that includes a module or source name.
Definition event.h:134
An event type that includes a timestamp.
Definition event.h:113
Core interfaces.
Definition adapter.h:21