ORE Studio 0.0.4
Loading...
Searching...
No Matches
registrar.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_REGISTRAR_HPP
21#define ORES_EVENTING_SERVICE_REGISTRAR_HPP
22
23#include "ores.logging/make_logger.hpp"
24#include "ores.eventing/domain/event_traits.hpp"
25#include "ores.eventing/service/postgres_event_source.hpp"
26#include "ores.eventing/service/event_channel_registry.hpp"
27
29
43class registrar {
44private:
45 [[nodiscard]] static auto& lg() {
46 using namespace ores::logging;
47 static auto instance = make_logger("ores.eventing.service.registrar");
48 return instance;
49 }
50
51public:
60 template<typename Event>
62 const std::string& entity_name,
63 const std::string& channel_name) {
64 BOOST_LOG_SEV(lg(), logging::info)
65 << "Registering event mapping: " << entity_name
66 << " -> " << channel_name;
67 source.register_mapping<Event>(entity_name, channel_name);
68 }
69
83 template<domain::has_event_traits Event>
85 const std::string& entity_name,
86 const std::string& channel_name,
87 event_channel_registry& registry,
88 const std::string& description) {
89 BOOST_LOG_SEV(lg(), logging::info)
90 << "Registering event mapping: " << entity_name
91 << " -> " << channel_name;
92 source.register_mapping<Event>(entity_name, channel_name);
93 registry.register_channel<Event>(description);
94 }
95};
96
97}
98
99#endif
Event bus and related services.
Definition event_bus.hpp:33
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
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
Event source that bridges PostgreSQL LISTEN/NOTIFY to the event bus.
Definition postgres_event_source.hpp:57
void register_mapping(const std::string &entity_name, const std::string &channel_name)
Register a mapping from entity name to typed domain event.
Definition postgres_event_source.hpp:106
Helper class for registering entity-to-event mappings.
Definition registrar.hpp:43
static void register_mapping(postgres_event_source &source, const std::string &entity_name, const std::string &channel_name)
Register a single entity-to-event mapping.
Definition registrar.hpp:61
static void register_mapping(postgres_event_source &source, const std::string &entity_name, const std::string &channel_name, event_channel_registry &registry, const std::string &description)
Register a single entity-to-event mapping with channel registry.
Definition registrar.hpp:84