From ac8ed2f7c7ffa505428acba40196a96dc2d0fb21 Mon Sep 17 00:00:00 2001 From: ttldtor Date: Thu, 4 Apr 2024 22:48:03 +0300 Subject: [PATCH 1/2] Message --- CMakeLists.txt | 6 +- .../api/osub/WildcardSymbol.hpp | 7 + .../event/IndexedEventSource.hpp | 44 ++-- .../event/candle/Candle.hpp | 41 ++-- .../event/candle/CandleSymbol.hpp | 7 + .../event/market/AnalyticOrder.hpp | 28 ++- .../event/market/OptionSale.hpp | 42 ++-- .../event/market/Order.hpp | 30 +-- .../event/market/OtcMarketsOrder.hpp | 9 +- .../event/market/Profile.hpp | 30 +-- .../event/market/Quote.hpp | 42 ++-- .../event/market/SpreadOrder.hpp | 30 +-- .../event/market/Summary.hpp | 28 ++- .../event/market/TimeAndSale.hpp | 42 ++-- .../event/market/Trade.hpp | 28 ++- .../event/market/TradeETH.hpp | 28 ++- .../event/misc/Message.hpp | 194 +++++++++++++++++- .../event/option/Greeks.hpp | 42 ++-- .../event/option/Series.hpp | 42 ++-- .../event/option/TheoPrice.hpp | 42 ++-- .../event/option/Underlying.hpp | 42 ++-- .../internal/detail/Formatter.hpp | 29 +++ .../internal/utils/StringUtils.hpp | 2 +- .../ipf/InstrumentProfile.hpp | 38 +++- .../symbols/StringSymbol.hpp | 7 + .../symbols/SymbolWrapper.hpp | 7 + src/event/EventMapper.cpp | 15 +- src/event/EventTypeEnum.cpp | 2 +- src/event/misc/Message.cpp | 121 +++++++++++ src/internal/utils/StringUtils.cpp | 6 +- tests/CMakeLists.txt | 3 +- tests/api/DataIntegrityTest.cpp | 110 ++++++++++ 32 files changed, 876 insertions(+), 268 deletions(-) create mode 100644 include/dxfeed_graal_cpp_api/internal/detail/Formatter.hpp create mode 100644 src/event/misc/Message.cpp create mode 100644 tests/api/DataIntegrityTest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e564f9759..b4a4c1f73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -286,6 +286,10 @@ set(dxFeedGraalCxxApi_EventOption_Sources src/event/option/Series.cpp ) +set(dxFeedGraalCxxApi_EventMisc_Sources + src/event/misc/Message.cpp +) + set(dxFeedGraalCxxApi_Schedule_Sources src/schedule/SessionFilter.cpp src/schedule/SessionType.cpp @@ -311,7 +315,7 @@ set(dxFeedGraalCxxApi_Sources ${dxFeedGraalCxxApi_EventCandle_Sources} ${dxFeedGraalCxxApi_EventMarket_Sources} ${dxFeedGraalCxxApi_EventOption_Sources} - ${dxFeedGraalCxxApi_EventOption_Sources} + ${dxFeedGraalCxxApi_EventMisc_Sources} ${dxFeedGraalCxxApi_Schedule_Sources} ) diff --git a/include/dxfeed_graal_cpp_api/api/osub/WildcardSymbol.hpp b/include/dxfeed_graal_cpp_api/api/osub/WildcardSymbol.hpp index c4a8f6c7b..2dc46089d 100644 --- a/include/dxfeed_graal_cpp_api/api/osub/WildcardSymbol.hpp +++ b/include/dxfeed_graal_cpp_api/api/osub/WildcardSymbol.hpp @@ -76,6 +76,13 @@ struct DXFCPP_EXPORT WildcardSymbol final { */ static void freeGraal(void *graalNative); + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ static const WildcardSymbol &fromGraal(void *graalNative); /** diff --git a/include/dxfeed_graal_cpp_api/event/IndexedEventSource.hpp b/include/dxfeed_graal_cpp_api/event/IndexedEventSource.hpp index 2315af62a..875a40e8e 100644 --- a/include/dxfeed_graal_cpp_api/event/IndexedEventSource.hpp +++ b/include/dxfeed_graal_cpp_api/event/IndexedEventSource.hpp @@ -27,6 +27,32 @@ class DXFCPP_EXPORT IndexedEventSource { */ static const IndexedEventSource DEFAULT; + + /** + * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). + * Fills the dxFeed Graal SDK structure's fields by the data of the current entity (recursively if necessary). + * Returns the pointer to the filled structure. + * + * @return The pointer to the filled dxFeed Graal SDK structure + */ + virtual void *toGraal() const; + + /** + * Releases the memory occupied by the dxFeed Graal SDK structure (recursively if necessary). + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + */ + static void freeGraal(void *graalNative); + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static IndexedEventSource fromGraal(void *graalNative); + IndexedEventSource() noexcept = default; virtual ~IndexedEventSource() noexcept = default; @@ -73,24 +99,6 @@ class DXFCPP_EXPORT IndexedEventSource { auto operator<(const IndexedEventSource &indexedEventSource) const { return id_ < indexedEventSource.id_; } - - /** - * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). - * Fills the dxFeed Graal SDK structure's fields by the data of the current entity (recursively if necessary). - * Returns the pointer to the filled structure. - * - * @return The pointer to the filled dxFeed Graal SDK structure - */ - virtual void *toGraal() const; - - /** - * Releases the memory occupied by the dxFeed Graal SDK structure (recursively if necessary). - * - * @param graalNative The pointer to the dxFeed Graal SDK structure. - */ - static void freeGraal(void *graalNative); - - static IndexedEventSource fromGraal(void *graalNative); }; DXFCPP_END_NAMESPACE diff --git a/include/dxfeed_graal_cpp_api/event/candle/Candle.hpp b/include/dxfeed_graal_cpp_api/event/candle/Candle.hpp index 8ddff4f47..7fc0b642b 100644 --- a/include/dxfeed_graal_cpp_api/event/candle/Candle.hpp +++ b/include/dxfeed_graal_cpp_api/event/candle/Candle.hpp @@ -105,7 +105,30 @@ class DXFCPP_EXPORT Candle final : public EventTypeWithSymbol, static void freeGraalData(void *graalNative) noexcept; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the Candle object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the Candle object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Maximum allowed sequence value. + * + * @see Candle::setSequence() + */ + static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -123,22 +146,6 @@ class DXFCPP_EXPORT Candle final : public EventTypeWithSymbol, */ static void freeGraal(void *graalNative); - /** - * Maximum allowed sequence value. - * - * @see Candle::setSequence() - */ - static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; - - /// The alias to a type of shared pointer to the Candle object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the Candle object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /** * Creates new candle with default values. */ diff --git a/include/dxfeed_graal_cpp_api/event/candle/CandleSymbol.hpp b/include/dxfeed_graal_cpp_api/event/candle/CandleSymbol.hpp index 86c8d4c87..ba0b26a54 100644 --- a/include/dxfeed_graal_cpp_api/event/candle/CandleSymbol.hpp +++ b/include/dxfeed_graal_cpp_api/event/candle/CandleSymbol.hpp @@ -276,6 +276,13 @@ struct DXFCPP_EXPORT CandleSymbol { */ static void freeGraal(void *graalNative); + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ static CandleSymbol fromGraal(void *graalNative); /** diff --git a/include/dxfeed_graal_cpp_api/event/market/AnalyticOrder.hpp b/include/dxfeed_graal_cpp_api/event/market/AnalyticOrder.hpp index bed5e1239..e7b1ac59a 100644 --- a/include/dxfeed_graal_cpp_api/event/market/AnalyticOrder.hpp +++ b/include/dxfeed_graal_cpp_api/event/market/AnalyticOrder.hpp @@ -75,7 +75,23 @@ class DXFCPP_EXPORT AnalyticOrder final : public Order { void fillGraalData(void *graalNative) const noexcept override; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the AnalyticOrder object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the AnalyticOrder object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -93,16 +109,6 @@ class DXFCPP_EXPORT AnalyticOrder final : public Order { */ static void freeGraal(void *graalNative); - public: - /// The alias to a type of shared pointer to the AnalyticOrder object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the AnalyticOrder object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new analytic order event with default values. AnalyticOrder() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/event/market/OptionSale.hpp b/include/dxfeed_graal_cpp_api/event/market/OptionSale.hpp index dc3df43ea..61875ceb9 100644 --- a/include/dxfeed_graal_cpp_api/event/market/OptionSale.hpp +++ b/include/dxfeed_graal_cpp_api/event/market/OptionSale.hpp @@ -86,7 +86,30 @@ class DXFCPP_EXPORT OptionSale final : public MarketEvent, public IndexedEvent { static void freeGraalData(void *graalNative) noexcept; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the OptionSale object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the OptionSale object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Maximum allowed sequence value. + * + * @see OptionSale::setSequence() + */ + static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -104,23 +127,6 @@ class DXFCPP_EXPORT OptionSale final : public MarketEvent, public IndexedEvent { */ static void freeGraal(void *graalNative); - public: - /** - * Maximum allowed sequence value. - * - * @see OptionSale::setSequence() - */ - static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; - - /// The alias to a type of shared pointer to the OptionSale object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the OptionSale object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new option sale event with default values. OptionSale() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/event/market/Order.hpp b/include/dxfeed_graal_cpp_api/event/market/Order.hpp index 6ffd400b2..53450ee6b 100644 --- a/include/dxfeed_graal_cpp_api/event/market/Order.hpp +++ b/include/dxfeed_graal_cpp_api/event/market/Order.hpp @@ -10,8 +10,8 @@ DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251) #include #include #include -#include #include +#include #include "../../internal/Common.hpp" #include "../EventTypeEnum.hpp" @@ -107,7 +107,23 @@ class DXFCPP_EXPORT Order : public OrderBase { static void freeGraalData(void *graalNative) noexcept; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the Order object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the Order object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -125,16 +141,6 @@ class DXFCPP_EXPORT Order : public OrderBase { */ static void freeGraal(void *graalNative); - public: - /// The alias to a type of shared pointer to the Order object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the Order object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new order event with default values. Order() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/event/market/OtcMarketsOrder.hpp b/include/dxfeed_graal_cpp_api/event/market/OtcMarketsOrder.hpp index 10d53443d..4c13f2de9 100644 --- a/include/dxfeed_graal_cpp_api/event/market/OtcMarketsOrder.hpp +++ b/include/dxfeed_graal_cpp_api/event/market/OtcMarketsOrder.hpp @@ -151,7 +151,14 @@ class DXFCPP_EXPORT OtcMarketsOrder final : public Order { /// Type identifier and additional information about the current event class. static const EventTypeEnum &TYPE; - static OtcMarketsOrder::Ptr fromGraal(void *graalNative); + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). diff --git a/include/dxfeed_graal_cpp_api/event/market/Profile.hpp b/include/dxfeed_graal_cpp_api/event/market/Profile.hpp index 0121f268d..6a3c5cc4f 100644 --- a/include/dxfeed_graal_cpp_api/event/market/Profile.hpp +++ b/include/dxfeed_graal_cpp_api/event/market/Profile.hpp @@ -9,8 +9,8 @@ DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251) #include #include -#include #include +#include #include "../../internal/Common.hpp" #include "../EventTypeEnum.hpp" @@ -73,7 +73,23 @@ class DXFCPP_EXPORT Profile final : public MarketEvent, public LastingEvent { static void freeGraalData(void *graalNative) noexcept; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the Profile object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the Profile object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -91,16 +107,6 @@ class DXFCPP_EXPORT Profile final : public MarketEvent, public LastingEvent { */ static void freeGraal(void *graalNative); - public: - /// The alias to a type of shared pointer to the Profile object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the Profile object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new profile event with default values. Profile() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/event/market/Quote.hpp b/include/dxfeed_graal_cpp_api/event/market/Quote.hpp index 74d4f4975..9badcaa5d 100644 --- a/include/dxfeed_graal_cpp_api/event/market/Quote.hpp +++ b/include/dxfeed_graal_cpp_api/event/market/Quote.hpp @@ -59,7 +59,30 @@ class DXFCPP_EXPORT Quote final : public MarketEvent, public LastingEvent { void fillGraalData(void *graalNative) const noexcept override; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the Quote object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the Quote object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Maximum allowed sequence value. + * + * @see Quote::setSequence() + */ + static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -77,23 +100,6 @@ class DXFCPP_EXPORT Quote final : public MarketEvent, public LastingEvent { */ static void freeGraal(void *graalNative); - public: - /** - * Maximum allowed sequence value. - * - * @see Quote::setSequence() - */ - static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; - - /// The alias to a type of shared pointer to the Quote object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the Quote object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new quote event with default values. Quote() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/event/market/SpreadOrder.hpp b/include/dxfeed_graal_cpp_api/event/market/SpreadOrder.hpp index 890ae517d..31929dfbd 100644 --- a/include/dxfeed_graal_cpp_api/event/market/SpreadOrder.hpp +++ b/include/dxfeed_graal_cpp_api/event/market/SpreadOrder.hpp @@ -10,8 +10,8 @@ DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251) #include #include #include -#include #include +#include #include "../../internal/Common.hpp" #include "../EventTypeEnum.hpp" @@ -106,7 +106,23 @@ class DXFCPP_EXPORT SpreadOrder : public OrderBase { static void freeGraalData(void *graalNative) noexcept; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the SpreadOrder object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the SpreadOrder object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -124,16 +140,6 @@ class DXFCPP_EXPORT SpreadOrder : public OrderBase { */ static void freeGraal(void *graalNative); - public: - /// The alias to a type of shared pointer to the SpreadOrder object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the SpreadOrder object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new spread order event with default values. SpreadOrder() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/event/market/Summary.hpp b/include/dxfeed_graal_cpp_api/event/market/Summary.hpp index 7426c9c42..52246c22b 100644 --- a/include/dxfeed_graal_cpp_api/event/market/Summary.hpp +++ b/include/dxfeed_graal_cpp_api/event/market/Summary.hpp @@ -64,7 +64,23 @@ class DXFCPP_EXPORT Summary final : public MarketEvent, public LastingEvent { void fillGraalData(void *graalNative) const noexcept override; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the Summary object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the Summary object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -82,16 +98,6 @@ class DXFCPP_EXPORT Summary final : public MarketEvent, public LastingEvent { */ static void freeGraal(void *graalNative); - public: - /// The alias to a type of shared pointer to the Summary object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the Summary object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new summary event with default values. Summary() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/event/market/TimeAndSale.hpp b/include/dxfeed_graal_cpp_api/event/market/TimeAndSale.hpp index 3851a7c55..fda727bce 100644 --- a/include/dxfeed_graal_cpp_api/event/market/TimeAndSale.hpp +++ b/include/dxfeed_graal_cpp_api/event/market/TimeAndSale.hpp @@ -114,7 +114,30 @@ class DXFCPP_EXPORT TimeAndSale final : public MarketEvent, public TimeSeriesEve static void freeGraalData(void *graalNative) noexcept; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the TimeAndSale object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the TimeAndSale object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Maximum allowed sequence value. + * + * @see ::setSequence() + */ + static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -132,23 +155,6 @@ class DXFCPP_EXPORT TimeAndSale final : public MarketEvent, public TimeSeriesEve */ static void freeGraal(void *graalNative); - public: - /** - * Maximum allowed sequence value. - * - * @see ::setSequence() - */ - static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; - - /// The alias to a type of shared pointer to the TimeAndSale object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the TimeAndSale object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new time and sale event with default values. TimeAndSale() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/event/market/Trade.hpp b/include/dxfeed_graal_cpp_api/event/market/Trade.hpp index 302e1a441..74f04b153 100644 --- a/include/dxfeed_graal_cpp_api/event/market/Trade.hpp +++ b/include/dxfeed_graal_cpp_api/event/market/Trade.hpp @@ -78,7 +78,23 @@ class DXFCPP_EXPORT Trade final : public TradeBase { void fillGraalData(void *graalNative) const noexcept override; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the Trade object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the Trade object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -96,16 +112,6 @@ class DXFCPP_EXPORT Trade final : public TradeBase { */ static void freeGraal(void *graalNative); - public: - /// The alias to a type of shared pointer to the Trade object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the Trade object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new trade event with default values. Trade() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/event/market/TradeETH.hpp b/include/dxfeed_graal_cpp_api/event/market/TradeETH.hpp index b00261ae9..9ffb7fd96 100644 --- a/include/dxfeed_graal_cpp_api/event/market/TradeETH.hpp +++ b/include/dxfeed_graal_cpp_api/event/market/TradeETH.hpp @@ -103,7 +103,23 @@ class DXFCPP_EXPORT TradeETH final : public TradeBase { void fillGraalData(void *graalNative) const noexcept override; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the TradeETH object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the TradeETH object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -121,16 +137,6 @@ class DXFCPP_EXPORT TradeETH final : public TradeBase { */ static void freeGraal(void *graalNative); - public: - /// The alias to a type of shared pointer to the TradeETH object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the TradeETH object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new trade event with default values. TradeETH() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/event/misc/Message.hpp b/include/dxfeed_graal_cpp_api/event/misc/Message.hpp index 51b635fda..51c87dd74 100644 --- a/include/dxfeed_graal_cpp_api/event/misc/Message.hpp +++ b/include/dxfeed_graal_cpp_api/event/misc/Message.hpp @@ -7,10 +7,11 @@ DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251) -#include #include #include #include +#include +#include #include "../../internal/Common.hpp" #include "../EventTypeEnum.hpp" @@ -19,9 +20,196 @@ DXFCPP_BEGIN_NAMESPACE struct EventMapper; -// TODO: implement [EN-8236] +/** + * Message event with application-specific attachment. Messages are never conflated and are delivered to + * all connected subscribers. There is no built-in persistence for messages. They are lost when subscribers + * are not connected to the message publisher, so they shall be only used for notification purposes in + * addition to persistence mechanism. + * + *

Implementation details

+ * + * This event is implemented on top of QDS record `Message`. + */ +class DXFCPP_EXPORT Message : public EventTypeWithSymbol { + friend struct EventMapper; -class DXFCPP_EXPORT Message {}; + std::optional eventSymbol_{}; + std::int64_t eventTime_{}; + std::optional attachment_{}; + + void fillData(void *graalNative); + void fillGraalData(void *graalNative) const; + static void freeGraalData(void *graalNative) noexcept; + + public: + /// The alias to a type of shared pointer to the Message object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the Message object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); + + /** + * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). + * Fills the dxFeed Graal SDK structure's fields by the data of the current entity (recursively if necessary). + * Returns the pointer to the filled structure. + * + * @return The pointer to the filled dxFeed Graal SDK structure + */ + void *toGraal() const override; + + /** + * Releases the memory occupied by the dxFeed Graal SDK structure (recursively if necessary). + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + */ + static void freeGraal(void *graalNative); + + /** + * Creates new message with default values. + */ + Message() noexcept = default; + + /** + * Creates new message with the specified event symbol. + * @param eventSymbol event symbol. + */ + explicit Message(std::string eventSymbol) noexcept : eventSymbol_{std::move(eventSymbol)} { + } + + /** + * Creates new message with the specified event symbol and attachment. + * @param eventSymbol event symbol. + * @param attachment attachment. + */ + Message(std::string eventSymbol, std::string attachment) noexcept + : eventSymbol_{std::move(eventSymbol)}, attachment_{std::move(attachment)} { + } + + /** + * Returns symbol of this event. + * + * @return symbol of this event or dxfcpp::String::NUL (`std::string{""}`) + */ + const std::string &getEventSymbol() const & noexcept override { + if (!eventSymbol_) { + return dxfcpp::String::NUL; + } + + return eventSymbol_.value(); + } + + /** + * Returns symbol of this event. + * + * @return symbol of this event or `std::nullopt`. + */ + const std::optional &getEventSymbolOpt() const & noexcept override { + return eventSymbol_; + } + + /** + * Changes symbol of this event. + * + * @param eventSymbol The symbol of this event. + */ + void setEventSymbol(const std::string &eventSymbol) noexcept override { + // TODO: check invalid utf-8 [EN-8233] + eventSymbol_ = eventSymbol; + } + + /** + * Changes event's symbol and returns the current message. + * + * @param eventSymbol The symbol of this event. + * @return The current message. + */ + Message &withEventSymbol(const std::string &eventSymbol) noexcept { + Message::setEventSymbol(eventSymbol); + + return *this; + } + + /// + std::int64_t getEventTime() const noexcept override { + return eventTime_; + } + + /// + void setEventTime(std::int64_t eventTime) noexcept override { + eventTime_ = eventTime; + } + + /** + * Changes event's creation time and returns the current message. + * + * @param eventTime the difference, measured in milliseconds, between the event creation time and + * midnight, January 1, 1970 UTC. + * @return The current message. + */ + Message &withEventTime(std::int64_t eventTime) noexcept { + Message::setEventTime(eventTime); + + return *this; + } + + /** + * Returns attachment. + * + * @return attachment. + */ + const std::string &getAttachment() const & { + if (!attachment_) { + return dxfcpp::String::NUL; + } + + return attachment_.value(); + } + + /** + * Returns attachment of this event. + * + * @return attachment of this event or `std::nullopt`. + */ + const std::optional &getAttachmentOpt() const & noexcept { + return attachment_; + } + + /** + * Changes attachment. + * + * @param attachment attachment. + */ + void setAttachment(std::string attachment) { + attachment_ = std::move(attachment); + } + + /** + * Changes attachment. and returns the current message. + * + * @param attachment attachment. + * + * @return The current message. + */ + Message &withAttachment(std::string attachment) noexcept { + Message::setAttachment(std::move(attachment)); + + return *this; + } + + std::string toString() const noexcept override; +}; DXFCPP_END_NAMESPACE diff --git a/include/dxfeed_graal_cpp_api/event/option/Greeks.hpp b/include/dxfeed_graal_cpp_api/event/option/Greeks.hpp index 33d256b71..52dab6b95 100644 --- a/include/dxfeed_graal_cpp_api/event/option/Greeks.hpp +++ b/include/dxfeed_graal_cpp_api/event/option/Greeks.hpp @@ -81,7 +81,30 @@ class DXFCPP_EXPORT Greeks final : public MarketEvent, public TimeSeriesEvent, p void fillGraalData(void *graalNative) const noexcept override; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the Greeks object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the Greeks object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); + + /** + * Maximum allowed sequence value. + * + * @see ::setSequence() + */ + static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -99,23 +122,6 @@ class DXFCPP_EXPORT Greeks final : public MarketEvent, public TimeSeriesEvent, p */ static void freeGraal(void *graalNative); - public: - /** - * Maximum allowed sequence value. - * - * @see ::setSequence() - */ - static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; - - /// The alias to a type of shared pointer to the Greeks object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the Greeks object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new greeks event with default values. Greeks() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/event/option/Series.hpp b/include/dxfeed_graal_cpp_api/event/option/Series.hpp index ec3c5338b..6c88e11fa 100644 --- a/include/dxfeed_graal_cpp_api/event/option/Series.hpp +++ b/include/dxfeed_graal_cpp_api/event/option/Series.hpp @@ -89,7 +89,30 @@ class DXFCPP_EXPORT Series final : public MarketEvent, public IndexedEvent { void fillGraalData(void *graalNative) const noexcept override; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the Series object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the Series object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Maximum allowed sequence value. + * + * @see ::setSequence() + */ + static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -107,23 +130,6 @@ class DXFCPP_EXPORT Series final : public MarketEvent, public IndexedEvent { */ static void freeGraal(void *graalNative); - public: - /** - * Maximum allowed sequence value. - * - * @see ::setSequence() - */ - static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; - - /// The alias to a type of shared pointer to the Series object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the Series object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new series event with default values. Series() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/event/option/TheoPrice.hpp b/include/dxfeed_graal_cpp_api/event/option/TheoPrice.hpp index 7fd57c585..1f36fb78e 100644 --- a/include/dxfeed_graal_cpp_api/event/option/TheoPrice.hpp +++ b/include/dxfeed_graal_cpp_api/event/option/TheoPrice.hpp @@ -88,7 +88,30 @@ class DXFCPP_EXPORT TheoPrice final : public MarketEvent, public TimeSeriesEvent void fillGraalData(void *graalNative) const noexcept override; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the TheoPrice object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the TheoPrice object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Maximum allowed sequence value. + * + * @see ::setSequence() + */ + static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -106,23 +129,6 @@ class DXFCPP_EXPORT TheoPrice final : public MarketEvent, public TimeSeriesEvent */ static void freeGraal(void *graalNative); - public: - /** - * Maximum allowed sequence value. - * - * @see ::setSequence() - */ - static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; - - /// The alias to a type of shared pointer to the TheoPrice object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the TheoPrice object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new theoprice event with default values. TheoPrice() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/event/option/Underlying.hpp b/include/dxfeed_graal_cpp_api/event/option/Underlying.hpp index 0a9f39524..162b18902 100644 --- a/include/dxfeed_graal_cpp_api/event/option/Underlying.hpp +++ b/include/dxfeed_graal_cpp_api/event/option/Underlying.hpp @@ -84,7 +84,30 @@ class DXFCPP_EXPORT Underlying final : public MarketEvent, public TimeSeriesEven void fillGraalData(void *graalNative) const noexcept override; public: - static std::shared_ptr fromGraal(void *graalNative); + /// The alias to a type of shared pointer to the Underlying object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the Underlying object + using Unique = std::unique_ptr; + + /// Type identifier and additional information about the current event class. + static const EventTypeEnum &TYPE; + + /** + * Maximum allowed sequence value. + * + * @see ::setSequence() + */ + static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). @@ -102,23 +125,6 @@ class DXFCPP_EXPORT Underlying final : public MarketEvent, public TimeSeriesEven */ static void freeGraal(void *graalNative); - public: - /** - * Maximum allowed sequence value. - * - * @see ::setSequence() - */ - static constexpr std::uint32_t MAX_SEQUENCE = (1U << 22U) - 1U; - - /// The alias to a type of shared pointer to the Underlying object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the Underlying object - using Unique = std::unique_ptr; - - /// Type identifier and additional information about the current event class. - static const EventTypeEnum &TYPE; - /// Creates new underlying event with default values. Underlying() noexcept = default; diff --git a/include/dxfeed_graal_cpp_api/internal/detail/Formatter.hpp b/include/dxfeed_graal_cpp_api/internal/detail/Formatter.hpp new file mode 100644 index 000000000..a5887e9f7 --- /dev/null +++ b/include/dxfeed_graal_cpp_api/internal/detail/Formatter.hpp @@ -0,0 +1,29 @@ +// Copyright (c) 2024 Devexperts LLC. +// SPDX-License-Identifier: MPL-2.0 + +#pragma once + +#include "../Conf.hpp" + +#include "../../event/EventType.hpp" + +DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251) + +#include +#include +#include +#include +#include + +DXFCPP_BEGIN_NAMESPACE + +DXFCPP_END_NAMESPACE + +template <> struct fmt::formatter : ostream_formatter {}; + +template <> struct fmt::formatter> : ostream_formatter {}; + +template +struct fmt::formatter::value, char>> : ostream_formatter {}; + +DXFCXX_DISABLE_MSC_WARNINGS_POP() \ No newline at end of file diff --git a/include/dxfeed_graal_cpp_api/internal/utils/StringUtils.hpp b/include/dxfeed_graal_cpp_api/internal/utils/StringUtils.hpp index e8f342c83..44559eab5 100644 --- a/include/dxfeed_graal_cpp_api/internal/utils/StringUtils.hpp +++ b/include/dxfeed_graal_cpp_api/internal/utils/StringUtils.hpp @@ -106,7 +106,7 @@ DXFCPP_EXPORT std::string formatTimeStampWithMillisWithTimeZone(std::int64_t tim DXFCPP_EXPORT char *createCString(const std::string &s); -DXFCPP_EXPORT char *createCString(const std::optional &s) noexcept; +DXFCPP_EXPORT char *createCString(const std::optional &s); template requires requires { std::is_same_v getName())>, std::string>; } diff --git a/include/dxfeed_graal_cpp_api/ipf/InstrumentProfile.hpp b/include/dxfeed_graal_cpp_api/ipf/InstrumentProfile.hpp index 0b2795c23..1392a80c9 100644 --- a/include/dxfeed_graal_cpp_api/ipf/InstrumentProfile.hpp +++ b/include/dxfeed_graal_cpp_api/ipf/InstrumentProfile.hpp @@ -92,12 +92,34 @@ class DXFCPP_EXPORT InstrumentProfile final : public SharedEntity { } public: - static std::shared_ptr fromGraal(void *graalNative); - static std::vector> fromGraalList(void *graalList); + /// The alias to a type of shared pointer to the InstrumentProfile object + using Ptr = std::shared_ptr; + + /// The alias to a type of unique pointer to the InstrumentProfile object + using Unique = std::unique_ptr; + + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ + static Ptr fromGraal(void *graalNative); /** - * Allocates memory for the dxFeed Graal SDK structure (recursively if necessary). - * Fills the dxFeed Graal SDK structure's fields by the data of the current entity (recursively if necessary). + * Creates a vector of objects of the current type and fills it with data from the the dxFeed Graal SDK list of + * structures. + * + * @param graalList The pointer to the dxFeed Graal SDK list of structures. + * @return The vector of objects of current type + * @throws std::invalid_argument + */ + static std::vector fromGraalList(void *graalList); + + /** + * Allocates memory for the dxFeed Graal SDK structure. + * Fills the dxFeed Graal SDK structure's fields by the data of the current entity. * Returns the pointer to the filled structure. * * @return The pointer to the filled dxFeed Graal SDK structure @@ -105,18 +127,12 @@ class DXFCPP_EXPORT InstrumentProfile final : public SharedEntity { void *toGraal() const; /** - * Releases the memory occupied by the dxFeed Graal SDK structure (recursively if necessary). + * Releases the memory occupied by the dxFeed Graal SDK structure. * * @param graalNative The pointer to the dxFeed Graal SDK structure. */ static void freeGraal(void *graalNative); - /// The alias to a type of shared pointer to the InstrumentProfile object - using Ptr = std::shared_ptr; - - /// The alias to a type of unique pointer to the InstrumentProfile object - using Unique = std::unique_ptr; - /** * Creates new instrument profile with default values. */ diff --git a/include/dxfeed_graal_cpp_api/symbols/StringSymbol.hpp b/include/dxfeed_graal_cpp_api/symbols/StringSymbol.hpp index 71d478d9d..39f2256fe 100644 --- a/include/dxfeed_graal_cpp_api/symbols/StringSymbol.hpp +++ b/include/dxfeed_graal_cpp_api/symbols/StringSymbol.hpp @@ -82,6 +82,13 @@ struct DXFCPP_EXPORT StringSymbol final { */ static void freeGraal(void *graalNative); + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ static StringSymbol fromGraal(void *graalNative); /** diff --git a/include/dxfeed_graal_cpp_api/symbols/SymbolWrapper.hpp b/include/dxfeed_graal_cpp_api/symbols/SymbolWrapper.hpp index f4e869740..b6bc4feb7 100644 --- a/include/dxfeed_graal_cpp_api/symbols/SymbolWrapper.hpp +++ b/include/dxfeed_graal_cpp_api/symbols/SymbolWrapper.hpp @@ -222,6 +222,13 @@ struct DXFCPP_EXPORT SymbolWrapper final { */ static void freeGraal(void *graalNative); + /** + * Creates an object of the current type and fills it with data from the the dxFeed Graal SDK structure. + * + * @param graalNative The pointer to the dxFeed Graal SDK structure. + * @return The object of current type. + * @throws std::invalid_argument + */ static SymbolWrapper fromGraal(void *graalNative); /** diff --git a/src/event/EventMapper.cpp b/src/event/EventMapper.cpp index 3f7f21e86..f0dc7a486 100644 --- a/src/event/EventMapper.cpp +++ b/src/event/EventMapper.cpp @@ -11,6 +11,9 @@ #include #include +#include +#include + DXFCPP_BEGIN_NAMESPACE std::vector> EventMapper::fromGraalList(void *graalNativeList) { @@ -26,7 +29,7 @@ std::vector> EventMapper::fromGraalList(void *graalNa for (std::size_t i = 0; i < static_cast(list->size); i++) { auto *e = list->elements[i]; - // TODO: implement other types + // TODO: implement other types [EN-8235] // TODO: type traits switch (e->clazz) { case DXFG_EVENT_QUOTE: @@ -70,6 +73,8 @@ std::vector> EventMapper::fromGraalList(void *graalNa case DXFG_EVENT_CONFIGURATION: break; case DXFG_EVENT_MESSAGE: + result.emplace_back(Message::fromGraal(e)); + break; case DXFG_EVENT_TIME_AND_SALE: result.emplace_back(TimeAndSale::fromGraal(e)); @@ -131,7 +136,7 @@ void EventMapper::freeGraalList(void *graalList) { if (list->elements[elementIndex]) { auto *e = list->elements[elementIndex]; - // TODO: implement other types [EN-8235] [EN-8236] + // TODO: implement other types [EN-8235] // TODO: type traits switch (e->clazz) { case DXFG_EVENT_QUOTE: @@ -175,6 +180,8 @@ void EventMapper::freeGraalList(void *graalList) { case DXFG_EVENT_CONFIGURATION: break; case DXFG_EVENT_MESSAGE: + Message::freeGraal(static_cast(e)); + break; case DXFG_EVENT_TIME_AND_SALE: TimeAndSale::freeGraal(static_cast(e)); @@ -278,7 +285,7 @@ bool EventMapper::freeGraalListElements(void *graalList, std::ptrdiff_t count) { if (list->elements[i]) { auto *e = list->elements[i]; - // TODO: implement other types [EN-8235] [EN-8236] + // TODO: implement other types [EN-8235] // TODO: type traits switch (e->clazz) { case DXFG_EVENT_QUOTE: @@ -322,6 +329,8 @@ bool EventMapper::freeGraalListElements(void *graalList, std::ptrdiff_t count) { case DXFG_EVENT_CONFIGURATION: break; case DXFG_EVENT_MESSAGE: + Message::freeGraal(static_cast(e)); + break; case DXFG_EVENT_TIME_AND_SALE: TimeAndSale::freeGraal(static_cast(e)); diff --git a/src/event/EventTypeEnum.cpp b/src/event/EventTypeEnum.cpp index c287410c2..d1a074a04 100644 --- a/src/event/EventTypeEnum.cpp +++ b/src/event/EventTypeEnum.cpp @@ -50,7 +50,7 @@ const std::vector> EventTypeEnum::AL std::cref(TRADE), std::cref(TRADE_ETH), // std::cref(CONFIGURATION), - // std::cref(MESSAGE), + std::cref(MESSAGE), std::cref(TIME_AND_SALE), std::cref(ORDER), std::cref(ANALYTIC_ORDER), diff --git a/src/event/misc/Message.cpp b/src/event/misc/Message.cpp new file mode 100644 index 000000000..397f61e10 --- /dev/null +++ b/src/event/misc/Message.cpp @@ -0,0 +1,121 @@ +// Copyright (c) 2024 Devexperts LLC. +// SPDX-License-Identifier: MPL-2.0 + +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +DXFCPP_BEGIN_NAMESPACE + +const EventTypeEnum &Message::TYPE = EventTypeEnum::MESSAGE; + +void Message::fillData(void *graalNative) { + if (graalNative == nullptr) { + return; + } + + auto graalMessage = static_cast(graalNative); + + if (graalMessage->event_symbol != nullptr) { + setEventSymbol(dxfcpp::toString(graalMessage->event_symbol)); + } + + if (graalMessage->attachment != nullptr) { + setAttachment(dxfcpp::toString(dxfcpp::bit_cast(graalMessage->attachment))); + } +} + +void Message::fillGraalData(void *graalNative) const { + if (graalNative == nullptr) { + return; + } + + auto graalMessage = static_cast(graalNative); + + graalMessage->event_type.clazz = dxfg_event_clazz_t::DXFG_EVENT_MESSAGE; + graalMessage->event_symbol = createCString(eventSymbol_); + graalMessage->event_time = eventTime_; + graalMessage->attachment = dxfcpp::bit_cast(createCString(attachment_)); +} + +void Message::freeGraalData(void *graalNative) noexcept { + if (graalNative == nullptr) { + return; + } + + auto graalMessage = static_cast(graalNative); + + delete[] graalMessage->event_symbol; + + if (graalMessage->attachment != nullptr) { + delete[] dxfcpp::bit_cast(graalMessage->attachment); + } +} + +std::shared_ptr Message::fromGraal(void *graalNative) { + if (!graalNative) { + throw std::invalid_argument("Unable to create Message. The `graalNative` parameter is nullptr"); + } + + if (static_cast(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_MESSAGE) { + throw std::invalid_argument( + fmt::format("Unable to create Message. Wrong event class {}! Expected: {}.", + std::to_string(static_cast(static_cast(graalNative)->clazz)), + std::to_string(static_cast(dxfg_event_clazz_t::DXFG_EVENT_MESSAGE)))); + } + + auto message = std::make_shared(); + + message->fillData(graalNative); + + return message; +} + +void *Message::toGraal() const { + if constexpr (Debugger::isDebug) { + Debugger::debug(toString() + "::toGraal()"); + } + + auto *graalMessage = new dxfg_message_t{}; + + fillGraalData(static_cast(graalMessage)); + + return static_cast(graalMessage); +} + +void Message::freeGraal(void *graalNative) { + if (!graalNative) { + return; + } + + if (static_cast(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_MESSAGE) { + throw std::invalid_argument( + fmt::format("Unable to free Message's Graal data. Wrong event class {}! Expected: {}.", + std::to_string(static_cast(static_cast(graalNative)->clazz)), + std::to_string(static_cast(dxfg_event_clazz_t::DXFG_EVENT_MESSAGE)))); + } + + auto graalMessage = static_cast(graalNative); + + freeGraalData(graalNative); + + delete graalMessage; +} + +std::string Message::toString() const noexcept { + return fmt::format("Message{{{}, eventTime={}, attachment={}}}", getEventSymbol(), + TimeFormat::DEFAULT_WITH_MILLIS.format(getEventTime()), attachment_.value_or(String::NUL)); +} + +DXFCPP_END_NAMESPACE \ No newline at end of file diff --git a/src/internal/utils/StringUtils.cpp b/src/internal/utils/StringUtils.cpp index 942dd2fb9..88067962a 100644 --- a/src/internal/utils/StringUtils.cpp +++ b/src/internal/utils/StringUtils.cpp @@ -205,17 +205,13 @@ char *createCString(const std::string &s) { char *cString = new char[s.size() + 1]; - if (!cString) { - return nullptr; - } - std::copy(s.begin(), s.end(), cString); cString[s.size()] = '\0'; return cString; } -DXFCPP_EXPORT char *createCString(const std::optional &s) noexcept { +DXFCPP_EXPORT char *createCString(const std::optional &s) { if (!s) { return nullptr; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 868bc6c98..12672f471 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,6 +22,7 @@ set(DXFC_TEST_INCLUDE_DIRS ../include ../third_party/doctest-2.4.11) set(DXFC_TEST_SOURCES exceptions/ExceptionsTest.cpp api/CandleSymbolTest.cpp + api/DataIntegrityTest.cpp api/DXEndpointTest.cpp api/DXPublisherTest.cpp api/EventsTest.cpp @@ -39,7 +40,7 @@ foreach (DXFC_TEST_SOURCE ${DXFC_TEST_SOURCES}) add_executable(${DXFC_TEST_BASENAME} ${DXFC_TEST_SOURCE}) target_include_directories(${DXFC_TEST_BASENAME} PRIVATE ${DXFC_TEST_INCLUDE_DIRS}) - target_link_libraries(${DXFC_TEST_BASENAME} PRIVATE dxfcxx::static) + target_link_libraries(${DXFC_TEST_BASENAME} PRIVATE dxfcxx::static fmt::fmt-header-only) if (DXFCXX_FEATURE_STACKTRACE) LinkStacktrace(${DXFC_TEST_BASENAME}) diff --git a/tests/api/DataIntegrityTest.cpp b/tests/api/DataIntegrityTest.cpp new file mode 100644 index 000000000..1aa98008d --- /dev/null +++ b/tests/api/DataIntegrityTest.cpp @@ -0,0 +1,110 @@ +// Copyright (c) 2024 Devexperts LLC. +// SPDX-License-Identifier: MPL-2.0 + +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN + +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include +#include +#include +#include + +using namespace dxfcpp; +using namespace std::literals; + +using stringOpt = std::optional; + +struct DataIntegrityTestFixture { + DXEndpoint::Ptr endpoint{}; + DXFeed::Ptr feed{}; + DXPublisher::Ptr pub{}; + + DataIntegrityTestFixture() { + endpoint = DXEndpoint::newBuilder() + ->withRole(DXEndpoint::Role::LOCAL_HUB) + ->withProperty(DXEndpoint::DXFEED_WILDCARD_ENABLE_PROPERTY, "true") + ->build(); + feed = endpoint->getFeed(); + pub = endpoint->getPublisher(); + } + + ~DataIntegrityTestFixture() { + endpoint->awaitProcessed(); + endpoint->close(); + } +}; + +struct DataIntegrityLocalAddressTestFixture { + DXEndpoint::Ptr pubEndpoint{}; + DXPublisher::Ptr pub{}; + DXEndpoint::Ptr feedEndpoint{}; + DXFeed::Ptr feed{}; + + DataIntegrityLocalAddressTestFixture() { + pubEndpoint = DXEndpoint::newBuilder() + ->withRole(DXEndpoint::Role::PUBLISHER) + ->build(); + pubEndpoint->connect(":7766"); + pub = pubEndpoint->getPublisher(); + feedEndpoint = DXEndpoint::newBuilder() + ->withRole(DXEndpoint::Role::FEED) + ->build(); + feedEndpoint->connect("127.0.0.1:7766"); + feed = feedEndpoint->getFeed(); + } + + ~DataIntegrityLocalAddressTestFixture() { + feedEndpoint->close(); + pubEndpoint->close(); + } +}; + +struct DataIntegrityRemoteTestFixture { + DXEndpoint::Ptr endpoint{}; + DXFeed::Ptr feed{}; + + DataIntegrityRemoteTestFixture() { + endpoint = DXEndpoint::newBuilder() + ->withRole(DXEndpoint::Role::FEED) + ->withProperty(DXEndpoint::DXFEED_WILDCARD_ENABLE_PROPERTY, "true") + ->build(); + endpoint->connect("127.0.0.1:7777"); + feed = endpoint->getFeed(); + } + + ~DataIntegrityRemoteTestFixture() { + endpoint->awaitProcessed(); + endpoint->close(); + } +}; + +TEST_CASE_FIXTURE(DataIntegrityTestFixture, "Test Message" * doctest::should_fail() ) { + auto sub = feed->createSubscription(Message::TYPE); + + auto message = std::make_shared("TEST", "Attachment2"); + + sub->addEventListener([message = message](const std::vector> & messages) { + for (auto&& m : messages) { + fmt::println("{}", m->toString()); + + REQUIRE(message->getAttachment() == m->getAttachment()); + } + }); + + sub->addSymbols("TEST"); + + pub->publishEvents(message); + + std::this_thread::sleep_for(2s); +} From 0a377f4e74c31d7cef940876e046ea2a5a585172 Mon Sep 17 00:00:00 2001 From: ttldtor Date: Thu, 4 Apr 2024 22:49:20 +0300 Subject: [PATCH 2/2] Message --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e3628a76..0e38023e6 100644 --- a/README.md +++ b/README.md @@ -482,7 +482,7 @@ versions): - [Message](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/misc/Message.html) is an event with an application-specific attachment - [ ] dxFeed Graal C API - - [ ] dxFeed Graal C++ API + - [x] dxFeed Graal C++ API - [OptionSale](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/OptionSale.html) is an event that represents a trade or another market event with the price (for example, market open/close price, etc.) for each option symbol listed under the specified Underlying