ORE Studio 0.0.4
Loading...
Searching...
No Matches
event_channel_registry.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_EVENTING_SERVICE_EVENT_CHANNEL_REGISTRY_HPP
21#define ORES_EVENTING_SERVICE_EVENT_CHANNEL_REGISTRY_HPP
22
23#include <mutex>
24#include <vector>
25#include <string>
26#include <unordered_map>
27#include "ores.eventing/domain/event_channel_info.hpp"
28#include "ores.eventing/domain/event_traits.hpp"
29
31
55public:
56 event_channel_registry() = default;
57 ~event_channel_registry() = default;
58
60 event_channel_registry& operator=(const event_channel_registry&) = delete;
63
72 template<domain::has_event_traits Event>
73 void register_channel(const std::string& description) {
74 using traits = domain::event_traits<Event>;
75 register_channel(std::string{traits::name}, description);
76 }
77
84 void register_channel(const std::string& name, const std::string& description);
85
91 [[nodiscard]] std::vector<domain::event_channel_info> get_channels() const;
92
99 [[nodiscard]] bool is_registered(const std::string& name) const;
100
106 [[nodiscard]] std::size_t size() const;
107
108private:
109 mutable std::mutex mutex_;
110 std::unordered_map<std::string, domain::event_channel_info> channels_;
111};
112
113}
114
115#endif
Event bus and related services.
Definition event_bus.hpp:33
Traits template for mapping event types to their logical names.
Definition event_traits.hpp:44
Registry of available event channels.
Definition event_channel_registry.hpp:54
void register_channel(const std::string &description)
Register a channel for a typed event.
Definition event_channel_registry.hpp:73
std::vector< domain::event_channel_info > get_channels() const
Get all registered channels.
Definition event_channel_registry.cpp:32
std::size_t size() const
Get the number of registered channels.
Definition event_channel_registry.cpp:53
bool is_registered(const std::string &name) const
Check if a channel is registered.
Definition event_channel_registry.cpp:48