Skip to content

Commit

Permalink
[EN-7314] Implement the DXPublisher
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyKalin committed Aug 20, 2023
1 parent fa3da24 commit 7fad6a4
Show file tree
Hide file tree
Showing 36 changed files with 735 additions and 91 deletions.
1 change: 0 additions & 1 deletion include/dxfeed_graal_cpp_api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "internal/Conf.hpp"

#include "dxfeed_graal_cpp_api/internal/utils/EventListUtils.hpp"
#include "internal/CEntryPointErrors.hpp"
#include "internal/Common.hpp"
#include "internal/Enum.hpp"
Expand Down
17 changes: 14 additions & 3 deletions include/dxfeed_graal_cpp_api/api/DXPublisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include "DXFeedSubscription.hpp"

#include "../event/EventMapper.hpp"

#include <memory>
#include <mutex>
#include <unordered_set>
Expand All @@ -33,6 +35,9 @@ struct DXFCPP_EXPORT DXPublisher : SharedEntity {

static std::shared_ptr<DXPublisher> create(void *feedHandle) noexcept;

//TODO: implement
void publishEventsImpl(void *graalEventsList) const noexcept;

protected:
DXPublisher() noexcept : handler_{} {
if constexpr (Debugger::isDebug) {
Expand All @@ -55,19 +60,25 @@ struct DXFCPP_EXPORT DXPublisher : SharedEntity {
*/
static std::shared_ptr<DXPublisher> getInstance() noexcept;


/**
*
* @tparam C The Collection type
*/
template <typename C>
void publishEvents(C&& c) noexcept {

void publishEvents(C&& collection) noexcept {
publishEvents(std::begin(collection), std::end(collection));
}

template <typename EventIt>
void publishEvents(EventIt begin, EventIt end) noexcept {
if constexpr (Debugger::isDebug) {
Debugger::debug(toString() + "::publishEvents(events = " + elementsToString(begin, end) + ")");
}

auto *list = EventMapper::toGraalList(begin, end);

publishEventsImpl(list);
EventMapper::freeGraalList(list);
}


Expand Down
48 changes: 48 additions & 0 deletions include/dxfeed_graal_cpp_api/event/EventMapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,54 @@ namespace dxfcpp {

struct DXFCPP_EXPORT EventMapper {
static std::vector<std::shared_ptr<EventType>> fromGraalList(void *graalNativeList) noexcept;

// TODO: check that EventIt is iterator of EventType* or shared_ptr<EventType> or T* or shared_ptr<T>, where T is
// child of EventType
template <typename EventIt> static void *toGraalList(EventIt begin, EventIt end) noexcept {
if constexpr (Debugger::isDebug) {
Debugger::debug("EventMapper::toGraalList(symbols = " + elementsToString(begin, end) + ")");
}

auto size = calculateGraalListSize(std::distance(begin, end));

// Zero size is needed, for example, to clear the list of symbols.
auto *list = newGraalList(size);

if (!list || size == 0) {
return list;
}

std::ptrdiff_t elementIdx = 0;
bool needToFree = false;

for (auto it = begin; it != end && elementIdx < size; it++, elementIdx++) {
if constexpr (requires { it->toGraal(); }) {
needToFree = setGraalListElement(list, elementIdx, it->toGraal()) == false;
} else if constexpr (requires { *it->toGraal(); }) {
needToFree = setGraalListElement(list, elementIdx, *it->toGraal()) == false;
}

if (needToFree) {
break;
}
}

if (needToFree) {
freeGraalListElements(list, elementIdx);

return nullptr;
}

return list;
}

static void freeGraalList(void *graalList) noexcept;

private:
static std::ptrdiff_t calculateGraalListSize(std::ptrdiff_t initSize) noexcept;
static void *newGraalList(std::ptrdiff_t size) noexcept;
static bool setGraalListElement(void *graalList, std::ptrdiff_t elementIdx, void *element) noexcept;
static bool freeGraalListElements(void *graalList, std::ptrdiff_t count) noexcept;
};

} // namespace dxfcpp
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/candle/Candle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class DXFCPP_EXPORT Candle final : public EventTypeWithSymbol<CandleSymbol>,
Data data_{};

static std::shared_ptr<Candle> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
/**
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/market/AnalyticOrder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class DXFCPP_EXPORT AnalyticOrder final : public Order {
void fillData(void *graalNative) noexcept override;

static std::shared_ptr<AnalyticOrder> fromGraal(void *graalNative) noexcept;
//TODO: implement (virtual?)
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
static const EventTypeEnum &TYPE;
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/market/OptionSale.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class DXFCPP_EXPORT OptionSale final : public MarketEvent, public IndexedEvent {
Data data_{};

static std::shared_ptr<OptionSale> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
/**
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/market/Order.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class DXFCPP_EXPORT Order : public OrderBase {
void fillData(void *graalNative) noexcept override;

static std::shared_ptr<Order> fromGraal(void *graalNative) noexcept;
//TODO: implement (virtual?)
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
static const EventTypeEnum &TYPE;
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/market/Profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class DXFCPP_EXPORT Profile final : public MarketEvent, public LastingEvent {
Data data_{};

static std::shared_ptr<Profile> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
static const EventTypeEnum &TYPE;
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/market/Quote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class DXFCPP_EXPORT Quote final : public MarketEvent, public LastingEvent {
}

static std::shared_ptr<Quote> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
/**
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/market/SpreadOrder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class DXFCPP_EXPORT SpreadOrder : public OrderBase {
void fillData(void *graalNative) noexcept override;

static std::shared_ptr<SpreadOrder> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
static const EventTypeEnum &TYPE;
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/market/Summary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class DXFCPP_EXPORT Summary final : public MarketEvent, public LastingEvent {
Data data_{};

static std::shared_ptr<Summary> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
static const EventTypeEnum &TYPE;
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/market/TimeAndSale.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class DXFCPP_EXPORT TimeAndSale final : public MarketEvent, public TimeSeriesEve
Data data_{};

static std::shared_ptr<TimeAndSale> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
/**
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/market/Trade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class DXFCPP_EXPORT Trade final : public TradeBase {
friend struct EventMapper;

static std::shared_ptr<Trade> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
static const EventTypeEnum &TYPE;
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/market/TradeETH.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class DXFCPP_EXPORT TradeETH final : public TradeBase {
friend struct EventMapper;

static std::shared_ptr<TradeETH> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
static const EventTypeEnum &TYPE;
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/option/Greeks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class DXFCPP_EXPORT Greeks final : public MarketEvent, public TimeSeriesEvent, p
Data data_{};

static std::shared_ptr<Greeks> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
/**
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/option/Series.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class DXFCPP_EXPORT Series final : public MarketEvent, public IndexedEvent {
Data data_{};

static std::shared_ptr<Series> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
/**
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/option/TheoPrice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class DXFCPP_EXPORT TheoPrice final : public MarketEvent, public TimeSeriesEvent
Data data_{};

static std::shared_ptr<TheoPrice> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
/**
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/event/option/Underlying.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class DXFCPP_EXPORT Underlying final : public MarketEvent, public TimeSeriesEven
Data data_{};

static std::shared_ptr<Underlying> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

public:
/**
Expand Down
71 changes: 0 additions & 71 deletions include/dxfeed_graal_cpp_api/internal/utils/EventListUtils.hpp

This file was deleted.

6 changes: 6 additions & 0 deletions src/api/DXPublisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <fmt/format.h>
#include <fmt/ostream.h>
#include <fmt/std.h>
#include "dxfeed_graal_cpp_api/api/DXPublisher.hpp"

namespace dxfcpp {

Expand Down Expand Up @@ -44,4 +45,9 @@ std::string DXPublisher::toString() const noexcept {
return fmt::format("DXPublisher{{{}}}", handler_.toString());
}

//TODO: implement
void DXPublisher::publishEventsImpl(void *graalEventsList) const noexcept {

}

}
Loading

0 comments on commit 7fad6a4

Please sign in to comment.