Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
SingleFeedBase.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "feed/Types.hpp"
23#include "feed/impl/TrackableSignal.hpp"
24#include "util/async/AnyExecutionContext.hpp"
25#include "util/async/AnyStrand.hpp"
26#include "util/log/Logger.hpp"
27#include "util/prometheus/Gauge.hpp"
28
29#include <boost/asio/io_context.hpp>
30#include <boost/asio/strand.hpp>
31
32#include <cstdint>
33#include <functional>
34#include <memory>
35#include <string>
36
37namespace feed::impl {
38
44 std::reference_wrapper<util::prometheus::GaugeInt> subCount_;
46 util::Logger logger_{"Subscriptions"};
47 std::string name_;
48
49public:
55 SingleFeedBase(util::async::AnyExecutionContext& executionCtx, std::string const& name);
56
61 void
62 sub(SubscriberSharedPtr const& subscriber);
63
68 void
69 unsub(SubscriberSharedPtr const& subscriber);
70
75 void
76 pub(std::string msg);
77
81 std::uint64_t
82 count() const;
83
84private:
85 void
86 unsubInternal(SubscriberPtr subscriber);
87};
88} // namespace feed::impl
Base class for single feed.
Definition SingleFeedBase.hpp:42
void unsub(SubscriberSharedPtr const &subscriber)
Unsubscribe the feed.
Definition SingleFeedBase.cpp:59
std::uint64_t count() const
Get the count of subscribers.
Definition SingleFeedBase.cpp:74
void pub(std::string msg)
Publishes the feed in strand.
Definition SingleFeedBase.cpp:65
SingleFeedBase(util::async::AnyExecutionContext &executionCtx, std::string const &name)
Construct a new Single Feed Base object.
Definition SingleFeedBase.cpp:35
void sub(SubscriberSharedPtr const &subscriber)
Subscribe the feed.
Definition SingleFeedBase.cpp:41
A thread-safe class to manage a signal and its tracking connections.
Definition TrackableSignal.hpp:44
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:110
A type-erased execution context.
Definition AnyExecutionContext.hpp:41
A type-erased execution context.
Definition AnyStrand.hpp:40
An interface to provide connection functionality for subscriptions.
Definition SubscriptionContextInterface.hpp:39