dxFeed Graal CXX API v4.2.0
Loading...
Searching...
No Matches
Handler.hpp
1// Copyright (c) 2025 Devexperts LLC.
2// SPDX-License-Identifier: MPL-2.0
3
4#pragma once
5
6#include "Conf.hpp"
7
9
10#include <deque>
11#include <functional>
12#include <future>
13#include <mutex>
14#include <unordered_map>
15#include <vector>
16
18
19/**
20 * A thread-safe class that allows to asynchronously notify listeners with a given signature.
21 * Listeners can be any callable entities.
22 * Listeners are placed in a future. Within one batch, listeners will be called sequentially. Futures are placed in
23 * a circular buffer and executed asynchronously.
24 *
25 * If you need synchronous execution of listeners, but it was possible to execute them in another thread, then limit
26 * the buffer size to one.
27 *
28 * @tparam Signature The arguments "signature" (example: `void(int, int)`)
29 */
30template <typename Signature> struct Handler;
31
32/**
33 * A thread-safe class that allows to asynchronously notify listeners with a given signature.
34 * Listeners can be any callable entities.
35 * Listeners are placed in a future. Within one batch, listeners will be called sequentially. Futures are placed in
36 * a circular buffer and executed asynchronously.
37 *
38 * If you need synchronous execution of listeners, but it was possible to execute them in another thread, then limit
39 * the buffer size to one.
40 *
41 * @tparam ArgTypes The arguments "signature" (example: `void(int, int)`)
42 */
43template <typename... ArgTypes> struct Handler<void(ArgTypes...)> final {
44 /// The listener type
45 using ListenerType = std::function<void(ArgTypes...)>;
46 static constexpr std::size_t FAKE_ID{static_cast<std::size_t>(-1)};
47
48 private:
49 static constexpr unsigned MAIN_FUTURES_DEFAULT_SIZE = 1;
50
51 std::recursive_mutex listenersMutex_{};
52 std::unordered_map<std::size_t, ListenerType> listeners_{};
53 std::unordered_map<std::size_t, ListenerType> lowPriorityListeners_{};
54
55 inline static std::atomic<std::size_t> lastId_{};
56
57 std::recursive_mutex mainFuturesMutex_{};
58 std::vector<std::shared_future<void>> mainFutures_{};
59 std::size_t mainFuturesCurrentIndex_{};
60 std::size_t mainFuturesSize_{};
61
62 std::shared_future<void> handleImpl(ArgTypes... args) {
63 return std::async(
64 std::launch::async,
65 [this](ArgTypes... args) {
66 std::lock_guard guard{listenersMutex_};
67
68 for (auto &listener : listeners_) {
69 listener.second(args...);
70 }
71
72 for (auto &listener : lowPriorityListeners_) {
73 listener.second(args...);
74 }
75 },
76 args...);
77 }
78
79 public:
80 /**
81 * Creates the new handler by specified size of circular buffer of futures
82 *
83 * @param mainFuturesSize The size of the circular buffer of futures
84 */
85 explicit Handler(std::size_t mainFuturesSize = MAIN_FUTURES_DEFAULT_SIZE) noexcept
86 : mainFuturesCurrentIndex_{0ULL}, mainFuturesSize_{mainFuturesSize} {
87 if (mainFuturesSize > 1) {
88 mainFutures_.reserve(mainFuturesSize);
89 }
90 }
91
92 Handler(const Handler &) = delete;
93
94 Handler(Handler &&other) noexcept {
95 std::scoped_lock lock(other.listenersMutex_, other.mainFuturesMutex_);
96
97 listeners_.swap(other.listeners_);
98 lowPriorityListeners_.swap(other.lowPriorityListeners_);
99 mainFutures_.swap(other.mainFutures_);
100 mainFuturesCurrentIndex_ = other.mainFuturesCurrentIndex_;
101 mainFuturesSize_ = other.mainFuturesSize_;
102 }
103
104 Handler &operator=(const Handler &) = delete;
105
106 Handler &operator=(Handler &&other) noexcept {
107 std::scoped_lock lock(listenersMutex_, mainFuturesMutex_, other.listenersMutex_, other.mainFuturesMutex_);
108
109 listeners_.swap(other.listeners_);
110 lowPriorityListeners_.swap(other.lowPriorityListeners_);
111 mainFutures_.swap(other.mainFutures_);
112 mainFuturesCurrentIndex_ = other.mainFuturesCurrentIndex_;
113 mainFuturesSize_ = other.mainFuturesSize_;
114
115 return *this;
116 }
117
118 /**
119 * Calls the listeners and pass the args to them
120 *
121 * @param args The listeners arguments
122 */
123 void handle(ArgTypes... args) {
124 auto f = handleImpl(args...);
125
126 if (mainFuturesSize_ <= 1) {
127 f.wait();
128 } else {
129 std::lock_guard guard{mainFuturesMutex_};
130
131 if (mainFutures_.size() < mainFuturesSize_) {
132 mainFutures_.emplace_back(f);
133 } else {
134 mainFuturesCurrentIndex_ %= mainFuturesSize_;
135 mainFutures_[mainFuturesCurrentIndex_].wait();
136 mainFutures_[mainFuturesCurrentIndex_] = f;
137 mainFuturesCurrentIndex_++;
138 }
139 }
140 }
141
142 /**
143 * Calls the listeners and pass the ars to them
144 *
145 * @param args The listeners arguments
146 */
147 void operator()(ArgTypes... args) {
148 return handle(args...);
149 }
150
151 /**
152 * Adds the listener to "main" group
153 *
154 * @param listener The listener
155 * @return The listener id
156 */
157 std::size_t add(ListenerType &&listener) {
158 std::lock_guard guard{listenersMutex_};
159
160 if (lastId_ >= FAKE_ID - 1) {
161 return FAKE_ID;
162 }
163
164 auto id = ++lastId_;
165
166 listeners_.emplace(id, std::forward<ListenerType>(listener));
167
168 return id;
169 }
170
171 /**
172 * Adds the low priority listener (to the "low priority" group)
173 * It will be called after the "main" listeners
174 *
175 * @param listener The listener
176 * @return The listener id
177 */
178 std::size_t addLowPriority(ListenerType &&listener) {
179 std::lock_guard guard{listenersMutex_};
180
181 if (lastId_ >= FAKE_ID - 1) {
182 return FAKE_ID;
183 }
184
185 auto id = ++lastId_;
186
187 lowPriorityListeners_.emplace(id, std::forward<ListenerType>(listener));
188
189 return id;
190 }
191
192 /**
193 * Adds the listener to "main" group
194 *
195 * @param listener The listener
196 * @return The listener id
197 */
198 std::size_t operator+=(ListenerType &&listener) {
199 return add(std::forward<ListenerType>(listener));
200 }
201
202 /**
203 * Adds the low priority listener (to the "low priority" group).
204 * It will be called after the "main" listeners
205 *
206 * @param listener The listener
207 * @return The listener id
208 */
209 std::size_t operator%=(ListenerType &&listener) {
210 return addLowPriority(std::forward<ListenerType>(listener));
211 }
212
213 /**
214 * Removes a listener by the id
215 *
216 * @param id The listener id
217 */
218 void remove(std::size_t id) {
219 std::lock_guard guard{listenersMutex_};
220
221 if (id == FAKE_ID) {
222 return;
223 }
224
225 if (listeners_.count(id) > 0) {
226 listeners_.erase(id);
227 } else if (lowPriorityListeners_.count(id) > 0) {
228 lowPriorityListeners_.erase(id);
229 }
230 }
231
232 /**
233 * Removes a listener by the id
234 *
235 * @param id The listener id
236 */
237 void operator-=(std::size_t id) {
238 return remove(id);
239 }
240};
241
242/**
243 * A thread-safe class that allows to asynchronously notify listeners with a given signature.
244 * Listeners can be any callable entities.
245 * Listeners are placed in one future without queues.
246 *
247 * @tparam Signature The arguments "signature" (example: `void(int, int)`)
248 */
249template <typename Signature> struct SimpleHandler;
250
251/**
252 * A thread-safe class that allows to asynchronously notify listeners with a given signature.
253 * Listeners can be any callable entities.
254 * Listeners are placed in one future without queues.
255 *
256 * @tparam ArgTypes The arguments "signature" (example: `void(int, int)`)
257 */
258template <typename... ArgTypes> struct SimpleHandler<void(ArgTypes...)> final {
259 using ListenerType = std::function<void(ArgTypes...)>;
260 static constexpr std::size_t FAKE_ID{static_cast<std::size_t>(-1)};
261
262 private:
263 std::recursive_mutex listenersMutex_{};
264 std::unordered_map<std::size_t, ListenerType> listeners_{};
265 std::unordered_map<std::size_t, ListenerType> lowPriorityListeners_{};
266
267 inline static std::atomic<std::size_t> lastId_{};
268
269 std::shared_future<void> handleImpl(ArgTypes... args) {
270 return std::async(
271 std::launch::async,
272 [this](ArgTypes... args) {
273 std::lock_guard guard{listenersMutex_};
274
275 for (auto &listener : listeners_) {
276 listener.second(args...);
277 }
278
279 for (auto &listener : lowPriorityListeners_) {
280 listener.second(args...);
281 }
282 },
283 args...);
284 }
285
286 public:
287 /**
288 * Creates the new handler
289 */
290 SimpleHandler() noexcept = default;
291 SimpleHandler(const SimpleHandler &) = delete;
292
293 SimpleHandler(SimpleHandler &&other) noexcept {
294 std::scoped_lock lock(other.listenersMutex_);
295
296 listeners_.swap(other.listeners_);
297 lowPriorityListeners_.swap(other.lowPriorityListeners_);
298 }
299
300 SimpleHandler &operator=(const SimpleHandler &) = delete;
301
302 SimpleHandler &operator=(SimpleHandler &&other) noexcept {
303 std::scoped_lock lock(listenersMutex_, other.listenersMutex_);
304
305 listeners_.swap(other.listeners_);
306 lowPriorityListeners_.swap(other.lowPriorityListeners_);
307
308 return *this;
309 }
310
311 /**
312 * Calls the listeners and pass the args to them
313 *
314 * @param args The listeners arguments
315 */
316 void handle(ArgTypes... args) {
317 auto f = handleImpl(args...);
318
319 f.wait();
320 }
321
322 /**
323 * Calls the listeners and pass the ars to them
324 *
325 * @param args The listeners arguments
326 */
327 void operator()(ArgTypes... args) {
328 return handle(args...);
329 }
330
331 /**
332 * Adds the listener to "main" group
333 *
334 * @param listener The listener
335 * @return The listener id
336 */
337 std::size_t add(ListenerType &&listener) {
338 std::lock_guard guard{listenersMutex_};
339
340 if (lastId_ >= FAKE_ID - 1) {
341 return FAKE_ID;
342 }
343
344 auto id = ++lastId_;
345
346 listeners_.emplace(id, std::forward<ListenerType>(listener));
347
348 return id;
349 }
350
351 /**
352 * Adds the low priority listener (to the "low priority" group)
353 * It will be called after the "main" listeners
354 *
355 * @param listener The listener
356 * @return The listener id
357 */
358 std::size_t addLowPriority(ListenerType &&listener) {
359 std::lock_guard guard{listenersMutex_};
360
361 if (lastId_ >= FAKE_ID - 1) {
362 return FAKE_ID;
363 }
364
365 auto id = ++lastId_;
366
367 lowPriorityListeners_.emplace(id, std::forward<ListenerType>(listener));
368
369 return id;
370 }
371
372 /**
373 * Adds the listener to "main" group
374 *
375 * @param listener The listener
376 * @return The listener id
377 */
378 std::size_t operator+=(ListenerType &&listener) {
379 return add(std::forward<ListenerType>(listener));
380 }
381
382 /**
383 * Adds the low priority listener (to the "low priority" group).
384 * It will be called after the "main" listeners
385 *
386 * @param listener The listener
387 * @return The listener id
388 */
389 std::size_t operator%=(ListenerType &&listener) {
390 return addLowPriority(std::forward<ListenerType>(listener));
391 }
392
393 /**
394 * Removes a listener by the id
395 *
396 * @param id The listener id
397 */
398 void remove(std::size_t id) {
399 std::lock_guard guard{listenersMutex_};
400
401 if (id == FAKE_ID) {
402 return;
403 }
404
405 if (listeners_.count(id) > 0) {
406 listeners_.erase(id);
407 } else if (lowPriorityListeners_.count(id) > 0) {
408 lowPriorityListeners_.erase(id);
409 }
410 }
411
412 /**
413 * Removes a listener by the id
414 *
415 * @param id The listener id
416 */
417 void operator-=(std::size_t id) {
418 return remove(id);
419 }
420};
421
423
#define DXFCXX_DISABLE_MSC_WARNINGS_POP()
Definition Conf.hpp:22
#define DXFCPP_END_NAMESPACE
Definition Conf.hpp:70
#define DXFCPP_BEGIN_NAMESPACE
Definition Conf.hpp:67
#define DXFCXX_DISABLE_GCC_WARNINGS_PUSH(warnings)
Definition Conf.hpp:38
#define DXFCXX_DISABLE_GCC_WARNINGS_POP()
Definition Conf.hpp:40
#define DXFCXX_DISABLE_MSC_WARNINGS_PUSH(warnings)
Definition Conf.hpp:21
#define DXFCPP_TRACE_ISOLATES
Definition Debug.hpp:19
#define DXFCPP_DEBUG
Definition Debug.hpp:15
#define DXFCPP_TRACE_LISTS
Definition Debug.hpp:22
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_properties(dxfc_dxendpoint_builder_t builder, const dxfc_dxendpoint_property_t **properties, size_t size)
Sets all supported properties from the provided properties object.
Definition DXEndpoint.cpp:700
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_password(dxfc_dxendpoint_t endpoint, const char *password)
Changes password for this endpoint.
Definition DXEndpoint.cpp:943
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_publisher(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxpublisher_t *publisher)
Definition DXEndpoint.cpp:1133
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_supports_property(dxfc_dxendpoint_builder_t builder, const char *key, DXFC_OUT int *supports)
Checks if a property is supported.
Definition DXEndpoint.cpp:727
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_add_state_change_listener(dxfc_dxendpoint_t endpoint, dxfc_dxendpoint_state_change_listener listener)
Adds listener that is notified about changes in state property.
Definition DXEndpoint.cpp:1079
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_disconnect(dxfc_dxendpoint_t endpoint)
Terminates all remote network connections.
Definition DXEndpoint.cpp:994
#define DXFCPP_EXPORT
Definition api.h:35
void * dxfc_dxendpoint_builder_t
The dxFeed endpoint's builder handle.
Definition api.h:207
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_close_and_await_termination(dxfc_dxendpoint_t endpoint)
Closes this endpoint and wait until all pending data processing tasks are completed.
Definition DXEndpoint.cpp:892
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_await_not_connected(dxfc_dxendpoint_t endpoint)
Waits while this endpoint state becomes NOT_CONNECTED or CLOSED.
Definition DXEndpoint.cpp:1045
dxfc_dxendpoint_state_t
Represents the current state of endpoint.
Definition api.h:149
@ DXFC_DXENDPOINT_STATE_CLOSED
Endpoint was closed.
Definition api.h:169
@ DXFC_DXENDPOINT_STATE_NOT_CONNECTED
Endpoint was created by is not connected to remote endpoints.
Definition api.h:153
@ DXFC_DXENDPOINT_STATE_CONNECTING
The connect function was called to establish connection to remove endpoint, but connection is not act...
Definition api.h:159
@ DXFC_DXENDPOINT_STATE_CONNECTED
The connection to remote endpoint is established.
Definition api.h:164
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_instance(void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Returns a default application-wide singleton instance of dxFeed endpoint with a FEED role.
Definition DXEndpoint.cpp:785
#define DXFC_OUT
Definition api.h:17
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_state(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxendpoint_state_t *state)
Returns the state of this endpoint.
Definition DXEndpoint.cpp:1062
void * dxfc_dxendpoint_t
The dxFeed endpoint handle.
Definition api.h:198
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_property(dxfc_dxendpoint_builder_t builder, const char *key, const char *value)
Sets the specified property.
Definition DXEndpoint.cpp:683
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_free(dxfc_dxendpoint_builder_t builder)
Removes a builder from the registry.
Definition DXEndpoint.cpp:773
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_connect(dxfc_dxendpoint_t endpoint, const char *address)
Connects to the specified remote address.
Definition DXEndpoint.cpp:960
dxfc_error_code_t
List of error codes.
Definition api.h:49
@ DXFC_EC_ERROR
The error returned if the current operation cannot be completed.
Definition api.h:60
@ DXFC_EC_SUCCESS
OK.
Definition api.h:53
@ DXFC_EC_G_ERR
dxFeed Graal Native API error.
Definition api.h:57
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_remove_state_change_listener(dxfc_dxendpoint_t endpoint, dxfc_dxendpoint_state_change_listener listener)
Removes listener that is notified about changes in state property.
Definition DXEndpoint.cpp:1105
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_name(dxfc_dxendpoint_builder_t builder, const char *name)
Changes name that is used to distinguish multiple endpoints in the same process (GraalVM Isolate) in ...
Definition DXEndpoint.cpp:667
DXFCPP_EXPORT dxfc_error_code_t dxfc_system_set_property(const char *key, const char *value)
Sets the system property indicated by the specified key.
Definition System.cpp:68
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_build(dxfc_dxendpoint_builder_t builder, void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Builds the new dxFeed endpoint instance.
Definition DXEndpoint.cpp:744
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_feed(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxfeed_t *feed)
Definition DXEndpoint.cpp:1128
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_await_processed(dxfc_dxendpoint_t endpoint)
Waits until this endpoint stops processing data (becomes quiescent).
Definition DXEndpoint.cpp:1028
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_close(dxfc_dxendpoint_t endpoint)
Closes this endpoint.
Definition DXEndpoint.cpp:875
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_new_builder(DXFC_OUT dxfc_dxendpoint_builder_t *builder)
Creates new dxFeed endpoint's builder instance.
Definition DXEndpoint.cpp:634
void(* dxfc_dxendpoint_state_change_listener)(dxfc_dxendpoint_state_t old_state, dxfc_dxendpoint_state_t new_state, void *user_data)
The endpoint current state change listener.
Definition api.h:178
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_reconnect(dxfc_dxendpoint_t endpoint)
Terminates all established network connections and initiates connecting again with the same address.
Definition DXEndpoint.cpp:977
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_role(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxendpoint_role_t *role)
Returns the role of this endpoint.
Definition DXEndpoint.cpp:909
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_user(dxfc_dxendpoint_t endpoint, const char *user)
Changes username for this endpoint.
Definition DXEndpoint.cpp:926
DXFCPP_EXPORT dxfc_error_code_t dxfc_system_get_property(const char *key, DXFC_OUT char *buffer, size_t buffer_size)
Gets the system property indicated by the specified key.
dxfc_dxendpoint_role_t
Represents the role of endpoint that was specified during its creation.
Definition api.h:89
@ DXFC_DXENDPOINT_ROLE_PUBLISHER
PUBLISHER endpoint connects to the remote publisher hub (also known as multiplexor) or creates a publ...
Definition api.h:127
@ DXFC_DXENDPOINT_ROLE_STREAM_FEED
STREAM_FEED endpoint is similar to DXFC_DXENDPOINT_ROLE_FEED and also connects to the remote data fee...
Definition api.h:116
@ DXFC_DXENDPOINT_ROLE_FEED
FEED endpoint connects to the remote data feed provider and is optimized for real-time or delayed dat...
Definition api.h:99
@ DXFC_DXENDPOINT_ROLE_STREAM_PUBLISHER
STREAM_PUBLISHER endpoint is similar to DXFC_DXENDPOINT_ROLE_PUBLISHER and also connects to the remot...
Definition api.h:136
@ DXFC_DXENDPOINT_ROLE_LOCAL_HUB
LOCAL_HUB endpoint is a local hub without ability to establish network connections.
Definition api.h:143
@ DXFC_DXENDPOINT_ROLE_ON_DEMAND_FEED
ON_DEMAND_FEED endpoint is similar to DXFC_DXENDPOINT_ROLE_FEED, but it is designed to be used with d...
Definition api.h:107
void * dxfc_dxpublisher_t
The dxFeed publisher handle.
Definition api.h:217
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_create(void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Creates an endpoint with FEED role.
Definition DXEndpoint.cpp:830
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_instance2(dxfc_dxendpoint_role_t role, void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Returns a default application-wide singleton instance of DXEndpoint for a specific role.
Definition DXEndpoint.cpp:807
void * dxfc_dxfeed_t
The dxFeed handle.
Definition api.h:212
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_role(dxfc_dxendpoint_builder_t builder, dxfc_dxendpoint_role_t role)
Sets role for the created dxFeed endpoint.
Definition DXEndpoint.cpp:650
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_create2(dxfc_dxendpoint_role_t role, void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Creates an endpoint with a specified role.
Definition DXEndpoint.cpp:852
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_free(dxfc_dxendpoint_t endpoint)
Removes the dxFeed endpoint from the registry.
Definition DXEndpoint.cpp:1138
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_disconnect_and_clear(dxfc_dxendpoint_t endpoint)
Terminates all remote network connections and clears stored data.
Definition DXEndpoint.cpp:1011
Base abstract class for all dxFeed C++ API entities.
Definition Entity.hpp:13
virtual ~Entity() noexcept=default
The default virtual d-tor.
Event type parametrized by a symbol.
Definition EventType.hpp:116
virtual const std::optional< Symbol > & getEventSymbolOpt() const &noexcept=0
Returns event symbol that identifies this event type in subscription.
virtual void setEventSymbol(const Symbol &eventSymbol) noexcept=0
Changes event symbol that identifies this event type in subscription.
virtual const Symbol & getEventSymbol() const &noexcept=0
Returns event symbol that identifies this event type in subscription.
Marks all event types that can be received via dxFeed API.
Definition EventType.hpp:31
std::string toString() const override
Returns a string representation of the current object.
Definition EventType.hpp:89
virtual std::int64_t getEventTime() const noexcept
Returns time when event was created or zero when time is not available.
Definition EventType.hpp:54
virtual void assign(std::shared_ptr< EventType > event)
Replaces the contents of the event.
Definition EventType.hpp:84
virtual void * toGraal() const =0
Allocates memory for the dxFeed Graal SDK structure (recursively if necessary).
virtual void setEventTime(std::int64_t) noexcept
Changes event creation time.
Definition EventType.hpp:66
void handle(ArgTypes... args)
Calls the listeners and pass the args to them.
Definition Handler.hpp:123
std::size_t add(ListenerType &&listener)
Adds the listener to "main" group.
Definition Handler.hpp:157
std::size_t operator%=(ListenerType &&listener)
Adds the low priority listener (to the "low priority" group).
Definition Handler.hpp:209
std::size_t operator+=(ListenerType &&listener)
Adds the listener to "main" group.
Definition Handler.hpp:198
void operator()(ArgTypes... args)
Calls the listeners and pass the ars to them.
Definition Handler.hpp:147
Handler(std::size_t mainFuturesSize=MAIN_FUTURES_DEFAULT_SIZE) noexcept
Creates the new handler by specified size of circular buffer of futures.
Definition Handler.hpp:85
void operator-=(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:237
std::size_t addLowPriority(ListenerType &&listener)
Adds the low priority listener (to the "low priority" group) It will be called after the "main" liste...
Definition Handler.hpp:178
void remove(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:218
A helper class needed to construct smart pointers to objects, and does not allow explicit constructio...
Definition SharedEntity.hpp:89
static auto createShared(Args &&...args)
Creates smart pointer to object.
Definition SharedEntity.hpp:103
Base abstract "shared entity" class. Has some helpers for dynamic polymorphism.
Definition SharedEntity.hpp:21
virtual std::string toString() const
Returns a string representation of the current object.
Definition SharedEntity.hpp:78
std::shared_ptr< T > sharedAs() const noexcept
Returns a pointer to the current object wrapped in a smart pointer to type T.
Definition SharedEntity.hpp:69
std::shared_ptr< T > sharedAs() noexcept
Returns a pointer to the current object wrapped in a smart pointer to type T.
Definition SharedEntity.hpp:56
bool is() const noexcept
Checks that pointer to the current type could be converted to type T* In other words: whether type T ...
Definition SharedEntity.hpp:35
std::size_t operator+=(ListenerType &&listener)
Adds the listener to "main" group.
Definition Handler.hpp:378
void remove(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:398
void handle(ArgTypes... args)
Calls the listeners and pass the args to them.
Definition Handler.hpp:316
void operator()(ArgTypes... args)
Calls the listeners and pass the ars to them.
Definition Handler.hpp:327
SimpleHandler() noexcept=default
Creates the new handler.
std::size_t addLowPriority(ListenerType &&listener)
Adds the low priority listener (to the "low priority" group) It will be called after the "main" liste...
Definition Handler.hpp:358
void operator-=(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:417
std::size_t operator%=(ListenerType &&listener)
Adds the low priority listener (to the "low priority" group).
Definition Handler.hpp:389
std::size_t add(ListenerType &&listener)
Adds the listener to "main" group.
Definition Handler.hpp:337
Universal functional object that allows searching std::unordered_map for string-like keys.
Definition Common.hpp:911
A simple wrapper around strings or something similar to strings to reduce the amount of code for meth...
Definition Common.hpp:794
The simple key-value structure that represents an endpoint's property.
Definition api.h:184
const char * key
The property's key.
Definition api.h:186
const char * value
The property's value.
Definition api.h:188