Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
SubscriptionContext.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 "util/Taggable.hpp"
23#include "web/SubscriptionContextInterface.hpp"
24#include "web/interface/Concepts.hpp"
25#include "web/interface/ConnectionBase.hpp"
26
27#include <boost/signals2/variadic_signal.hpp>
28
29#include <atomic>
30#include <cstdint>
31#include <memory>
32#include <string>
33
34namespace web {
35
40 std::weak_ptr<ConnectionBase> connection_;
41 boost::signals2::signal<void(SubscriptionContextInterface*)> onDisconnect_;
47 std::atomic_uint32_t apiSubVersion_ = 0;
48
49public:
56 SubscriptionContext(util::TagDecoratorFactory const& factory, std::shared_ptr<ConnectionBase> connection);
57
61 ~SubscriptionContext() override;
62
69 void
70 send(std::shared_ptr<std::string> message) override;
71
77 void
78 onDisconnect(OnDisconnectSlot const& slot) override;
79
84 void
85 setApiSubversion(uint32_t value) override;
86
92 uint32_t
93 apiSubversion() const override;
94};
95
96} // namespace web
A factory for TagDecorator instantiation.
Definition Taggable.hpp:169
An interface to provide connection functionality for subscriptions.
Definition SubscriptionContextInterface.hpp:39
std::function< void(SubscriptionContextInterface *)> OnDisconnectSlot
Alias for on disconnect slot.
Definition SubscriptionContextInterface.hpp:57
A context of a WsBase connection for subscriptions.
Definition SubscriptionContext.hpp:39
void send(std::shared_ptr< std::string > message) override
Send message to the client.
Definition SubscriptionContext.cpp:47
SubscriptionContext(util::TagDecoratorFactory const &factory, std::shared_ptr< ConnectionBase > connection)
Construct a new Subscription Context object.
Definition SubscriptionContext.cpp:33
~SubscriptionContext() override
Destroy the Subscription Context object.
Definition SubscriptionContext.cpp:41
void setApiSubversion(uint32_t value) override
Set the API subversion.
Definition SubscriptionContext.cpp:60
void onDisconnect(OnDisconnectSlot const &slot) override
Connect a slot to onDisconnect connection signal.
Definition SubscriptionContext.cpp:54
uint32_t apiSubversion() const override
Get the API subversion.
Definition SubscriptionContext.cpp:66
This namespace implements the web server and related components.
Definition Types.hpp:43