Skip to content

Commit

Permalink
[EN-7587] Implement FetchDailyCandles sample
Browse files Browse the repository at this point in the history
IsolatedDXFeed
  • Loading branch information
ttldtor committed Jun 29, 2024
1 parent 349dd21 commit 4637843
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 20 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ set(dxFeedGraalCxxApi_Exceptions_Sources
)

set(dxFeedGraalCxxApi_Isolated_Sources
src/isolated/api/IsolatedDXFeed.cpp
src/isolated/api/IsolatedDXEndpoint.cpp
src/isolated/api/IsolatedDXFeedSubscription.cpp
src/isolated/api/IsolatedDXPublisher.cpp
Expand Down
1 change: 1 addition & 0 deletions include/dxfeed_graal_cpp_api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251 4996)
#include "exceptions/JavaException.hpp"
#include "exceptions/GraalException.hpp"

#include "isolated/api/IsolatedDXFeed.hpp"
#include "isolated/api/IsolatedDXEndpoint.hpp"
#include "isolated/api/IsolatedDXFeedSubscription.hpp"
#include "isolated/api/IsolatedDXPublisher.hpp"
Expand Down
21 changes: 13 additions & 8 deletions include/dxfeed_graal_cpp_api/api/DXFeed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251)
#include "../internal/Handler.hpp"
#include "../internal/Isolate.hpp"
#include "../internal/JavaObjectHandle.hpp"
#include "../promise/Promise.hpp"

#include "DXFeedSubscription.hpp"

Expand Down Expand Up @@ -146,7 +147,7 @@ struct DXFCPP_EXPORT DXFeed : SharedEntity {
*
* @return The DXFeed instance
*/
static std::shared_ptr<DXFeed> getInstance() noexcept;
static std::shared_ptr<DXFeed> getInstance();

/**
* Attaches the given subscription to this feed. This method does nothing if the
Expand All @@ -164,7 +165,7 @@ struct DXFCPP_EXPORT DXFeed : SharedEntity {
* @param subscription The subscription.
* @see DXFeedSubscription
*/
void attachSubscription(std::shared_ptr<DXFeedSubscription> subscription) noexcept;
void attachSubscription(std::shared_ptr<DXFeedSubscription> subscription);

/**
* Detaches the given subscription from this feed. This method does nothing if the
Expand All @@ -178,7 +179,7 @@ struct DXFCPP_EXPORT DXFeed : SharedEntity {
* @param subscription The subscription.
* @see DXFeedSubscription
*/
void detachSubscription(std::shared_ptr<DXFeedSubscription> subscription) noexcept;
void detachSubscription(std::shared_ptr<DXFeedSubscription> subscription);

/**
* Detaches the given subscription from this feed and clears data delivered to this subscription
Expand All @@ -188,7 +189,7 @@ struct DXFCPP_EXPORT DXFeed : SharedEntity {
* @param subscription The subscription.
* @see DXFeed::detachSubscription()
*/
void detachSubscriptionAndClear(std::shared_ptr<DXFeedSubscription> subscription) noexcept;
void detachSubscriptionAndClear(std::shared_ptr<DXFeedSubscription> subscription);

/**
* Creates new subscription for a single event type that is <i>attached</i> to this feed.
Expand All @@ -202,7 +203,7 @@ struct DXFCPP_EXPORT DXFeed : SharedEntity {
* @param eventType The type of event
* @return The new subscription
*/
std::shared_ptr<DXFeedSubscription> createSubscription(const EventTypeEnum &eventType) noexcept;
std::shared_ptr<DXFeedSubscription> createSubscription(const EventTypeEnum &eventType);

/**
* Creates new subscription for multiple event types that is <i>attached</i> to this feed.
Expand Down Expand Up @@ -235,7 +236,7 @@ struct DXFCPP_EXPORT DXFeed : SharedEntity {
* @return The new subscription
*/
template <typename EventTypeIt>
std::shared_ptr<DXFeedSubscription> createSubscription(EventTypeIt begin, EventTypeIt end) noexcept {
std::shared_ptr<DXFeedSubscription> createSubscription(EventTypeIt begin, EventTypeIt end) {
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::createSubscription(eventTypes = " + namesToString(begin, end) + ")");
}
Expand All @@ -259,7 +260,7 @@ struct DXFCPP_EXPORT DXFeed : SharedEntity {
* @param eventTypes The initializer list of event types
* @return The new subscription
*/
std::shared_ptr<DXFeedSubscription> createSubscription(std::initializer_list<EventTypeEnum> eventTypes) noexcept;
std::shared_ptr<DXFeedSubscription> createSubscription(std::initializer_list<EventTypeEnum> eventTypes);

/**
* Creates new subscription for multiple event types that is <i>attached</i> to this feed.
Expand All @@ -281,7 +282,7 @@ struct DXFCPP_EXPORT DXFeed : SharedEntity {
* @return The new subscription
*/
template <typename EventTypesCollection>
std::shared_ptr<DXFeedSubscription> createSubscription(EventTypesCollection &&eventTypes) noexcept {
std::shared_ptr<DXFeedSubscription> createSubscription(EventTypesCollection &&eventTypes) {
if constexpr (Debugger::isDebug) {
Debugger::debug(toString() + "::createSubscription(eventTypes = " +
namesToString(std::begin(eventTypes), std::end(eventTypes)) + ")");
Expand All @@ -294,6 +295,10 @@ struct DXFCPP_EXPORT DXFeed : SharedEntity {
return sub;
}

Promise<std::vector<std::shared_ptr<TimeSeriesEvent>>> getTimeSeriesPromise(const EventTypeEnum &eventType,
const SymbolWrapper &symbol, std::int64_t fromTime,
std::int64_t toTime);

std::string toString() const noexcept override;
};

Expand Down
41 changes: 41 additions & 0 deletions include/dxfeed_graal_cpp_api/internal/JavaObjectHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,47 @@ template <typename T> struct JavaObjectHandle {
std::unique_ptr<void, decltype(&deleter)> impl_;
};

template <typename T> struct JavaObjectHandleList {
#if DXFCPP_DEBUG == 1
static auto getDebugName() {
return std::string("JavaObjectHandleList<") + typeid(T).name() + ">";
}
#endif

using Type = T;

static DXFCPP_EXPORT void deleter(void *handle) noexcept;
explicit JavaObjectHandleList(void *handle = nullptr) noexcept : impl_{handle, &deleter} {
if constexpr (Debugger::isDebug) {
Debugger::debug(getDebugName() + "(handle = " + dxfcpp::toString(handle) + ")");
}
}

JavaObjectHandleList(const JavaObjectHandleList &) = delete;
JavaObjectHandleList(JavaObjectHandleList &&) noexcept = default;
JavaObjectHandleList &operator=(const JavaObjectHandleList &) = delete;
JavaObjectHandleList &operator=(JavaObjectHandleList &&) noexcept = default;
virtual ~JavaObjectHandleList() noexcept = default;

[[nodiscard]] std::string toString() const noexcept {
if (impl_)
return dxfcpp::toString(impl_.get());
else
return "nullptr";
}

[[nodiscard]] void *get() const noexcept {
return impl_.get();
}

explicit operator bool() const noexcept {
return static_cast<bool>(impl_);
}

private:
std::unique_ptr<void, decltype(&deleter)> impl_;
};

DXFCPP_END_NAMESPACE

DXFCXX_DISABLE_MSC_WARNINGS_POP()
48 changes: 48 additions & 0 deletions include/dxfeed_graal_cpp_api/isolated/api/IsolatedDXFeed.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2024 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0

#pragma once

#include "../../internal/Conf.hpp"

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251)

#include "../../api/DXFeed.hpp"

DXFCPP_BEGIN_NAMESPACE

namespace isolated::api::IsolatedDXFeed {

/*
dxfg_feed_t* dxfg_DXFeed_getInstance(graal_isolatethread_t *thread);
dxfg_subscription_t* dxfg_DXFeed_createSubscription(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_event_clazz_t eventClazz);
dxfg_subscription_t* dxfg_DXFeed_createSubscription2(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_event_clazz_list_t *eventClazzes);
dxfg_time_series_subscription_t* dxfg_DXFeed_createTimeSeriesSubscription(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_event_clazz_t eventClazz);
dxfg_time_series_subscription_t* dxfg_DXFeed_createTimeSeriesSubscription2(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_event_clazz_list_t *eventClazzes);
int32_t dxfg_DXFeed_attachSubscription(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_subscription_t *sub);
int32_t dxfg_DXFeed_detachSubscription(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_subscription_t *sub);
int32_t dxfg_DXFeed_detachSubscriptionAndClear(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_subscription_t *sub);
dxfg_event_type_t* dxfg_DXFeed_getLastEventIfSubscribed(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_event_clazz_t eventClazz, dxfg_symbol_t *symbol);
dxfg_event_type_list* dxfg_DXFeed_getIndexedEventsIfSubscribed(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_event_clazz_t eventClazz, dxfg_symbol_t *symbol, const char *source);
dxfg_event_type_list* dxfg_DXFeed_getTimeSeriesIfSubscribed(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_event_clazz_t eventClazz, dxfg_symbol_t *symbol, int64_t from_time, int64_t to_time);
// use dxfg_EventType_new to create an empty structure so that java tries to free up memory when replacing subjects
int32_t dxfg_DXFeed_getLastEvent(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_event_type_t *event);
int32_t dxfg_DXFeed_getLastEvents(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_event_type_list *events);
dxfg_promise_event_t* dxfg_DXFeed_getLastEventPromise(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_event_clazz_t eventClazz, dxfg_symbol_t *symbol);
dxfg_promise_list* dxfg_DXFeed_getLastEventsPromises(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_event_clazz_t eventClazz, dxfg_symbol_list *symbols);
dxfg_promise_events_t* dxfg_DXFeed_getIndexedEventsPromise(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_event_clazz_t eventClazz, dxfg_symbol_t *symbol, dxfg_indexed_event_source_t* source);
dxfg_promise_events_t* dxfg_DXFeed_getTimeSeriesPromise(graal_isolatethread_t *thread, dxfg_feed_t *feed, dxfg_event_clazz_t clazz, dxfg_symbol_t *symbol, int64_t fromTime, int64_t toTime);
*/


/* dxfg_promise_events_t* */ void* getTimeSeriesPromise(/* dxfg_feed_t * */ const JavaObjectHandle<DXFeed>& feed, /* dxfg_event_clazz_t */ const EventTypeEnum &eventType, /* dxfg_symbol_t * */ const SymbolWrapper &symbol, std::int64_t fromTime,
std::int64_t toTime);


}

DXFCPP_END_NAMESPACE

DXFCXX_DISABLE_MSC_WARNINGS_POP()
49 changes: 45 additions & 4 deletions include/dxfeed_graal_cpp_api/promise/Promise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,57 @@

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251)

#include <memory>
#include <vector>

DXFCPP_BEGIN_NAMESPACE

template <typename T>
struct Promise {};
struct TimeSeriesEvent;
struct LastingEvent;

struct PromiseImpl {

};

template <typename T> struct Promise {
};

template <class T, class U>
concept Derived = std::is_base_of_v<U, T>;

template <>
struct Promise<std::shared_ptr<LastingEvent>> {
template <Derived<LastingEvent> T> struct Promise<std::shared_ptr<T>> {

};

template <Derived<TimeSeriesEvent> T> struct Promise<std::shared_ptr<T>> {

};

template <Derived<TimeSeriesEvent> T> struct Promise<std::vector<std::shared_ptr<T>>> {

};


//
// Promise<std::shared_ptr<LastingEvent>> x{};
// auto _ = x.z();
//
// template <typename T, typename Enable = void> struct PromiseSFINAE {
// int x() {
// return {};
// }
// };
//
// template <typename T>
// struct PromiseSFINAE<T, typename std::enable_if<std::is_base_of<LastingEvent, typename T::element_type>::value>::type> {
// int z() {
// return 0;
// }
// };
//
// PromiseSFINAE<std::shared_ptr<LastingEvent>> xx{};
// auto __ = xx.z();

DXFCPP_END_NAMESPACE

DXFCXX_DISABLE_MSC_WARNINGS_POP()
23 changes: 16 additions & 7 deletions src/api/DXFeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

DXFCPP_BEGIN_NAMESPACE

std::shared_ptr<DXFeed> DXFeed::getInstance() noexcept {
std::shared_ptr<DXFeed> DXFeed::getInstance() {
if constexpr (Debugger::isDebug) {
Debugger::debug("DXFeed::getInstance()");
}

return DXEndpoint::getInstance()->getFeed();
}

void DXFeed::attachSubscription(std::shared_ptr<DXFeedSubscription> subscription) noexcept {
void DXFeed::attachSubscription(std::shared_ptr<DXFeedSubscription> subscription) {
if constexpr (Debugger::isDebug) {
Debugger::debug(toString() + "::attachSubscription(" + subscription->toString() + ")");
}
Expand All @@ -43,7 +43,7 @@ void DXFeed::attachSubscription(std::shared_ptr<DXFeedSubscription> subscription
}
}

void DXFeed::detachSubscription(std::shared_ptr<DXFeedSubscription> subscription) noexcept {
void DXFeed::detachSubscription(std::shared_ptr<DXFeedSubscription> subscription) {
if constexpr (Debugger::isDebug) {
Debugger::debug(toString() + "::detachSubscription(" + subscription->toString() + ")");
}
Expand All @@ -62,7 +62,7 @@ void DXFeed::detachSubscription(std::shared_ptr<DXFeedSubscription> subscription
}
}

void DXFeed::detachSubscriptionAndClear(std::shared_ptr<DXFeedSubscription> subscription) noexcept {
void DXFeed::detachSubscriptionAndClear(std::shared_ptr<DXFeedSubscription> subscription) {
if constexpr (Debugger::isDebug) {
Debugger::debug(toString() + "::detachSubscriptionAndClear(" + subscription->toString() + ")");
}
Expand All @@ -81,7 +81,7 @@ void DXFeed::detachSubscriptionAndClear(std::shared_ptr<DXFeedSubscription> subs
}
}

std::shared_ptr<DXFeedSubscription> DXFeed::createSubscription(const EventTypeEnum &eventType) noexcept {
std::shared_ptr<DXFeedSubscription> DXFeed::createSubscription(const EventTypeEnum &eventType) {
if constexpr (Debugger::isDebug) {
Debugger::debug(toString() + "::createSubscription(eventType = " + eventType.getName() + ")");
}
Expand All @@ -93,8 +93,7 @@ std::shared_ptr<DXFeedSubscription> DXFeed::createSubscription(const EventTypeEn
return sub;
}

std::shared_ptr<DXFeedSubscription>
DXFeed::createSubscription(std::initializer_list<EventTypeEnum> eventTypes) noexcept {
std::shared_ptr<DXFeedSubscription> DXFeed::createSubscription(std::initializer_list<EventTypeEnum> eventTypes) {
if constexpr (Debugger::isDebug) {
Debugger::debug(toString() + "::createSubscription(eventTypes = " +
namesToString(eventTypes.begin(), eventTypes.end()) + ")");
Expand Down Expand Up @@ -122,6 +121,16 @@ std::shared_ptr<DXFeed> DXFeed::create(void *feedHandle) {
return feed;
}

Promise<std::vector<std::shared_ptr<TimeSeriesEvent>>> DXFeed::getTimeSeriesPromise(const EventTypeEnum &eventType,
const SymbolWrapper &symbol,
std::int64_t fromTime,
std::int64_t toTime) {

// TODO: impelement

return {};
}

std::string DXFeed::toString() const noexcept {
return fmt::format("DXFeed{{{}}}", handle_.toString());
}
Expand Down
26 changes: 25 additions & 1 deletion src/internal/JavaObjectHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,31 @@ template <typename T> void JavaObjectHandle<T>::deleter(void *handle) noexcept {
dxfcpp::ignore_unused(result);

if constexpr (Debugger::isDebug) {
Debugger::debug(getDebugName() + "::deleter(handle = " + dxfcpp::toString(handle) + ") -> " + dxfcpp::toString(result));
Debugger::debug(getDebugName() + "::deleter(handle = " + dxfcpp::toString(handle) + ") -> " +
dxfcpp::toString(result));
}
}

template <typename T> void JavaObjectHandleList<T>::deleter(void *handle) noexcept {
auto result = runIsolatedOrElse(
[handle = handle](auto threadHandle) {
if constexpr (Debugger::isDebug) {
Debugger::debug(getDebugName() + "::deleter(handle = " + dxfcpp::toString(handle) + ")");
}

if (handle) {
return dxfg_CList_JavaObjectHandler_release(static_cast<graal_isolatethread_t *>(threadHandle),
static_cast<dxfg_java_object_handler_list *>(handle)) == 0;
}

return true;
},
false);
dxfcpp::ignore_unused(result);

if constexpr (Debugger::isDebug) {
Debugger::debug(getDebugName() + "::deleter(handle = " + dxfcpp::toString(handle) + ") -> " +
dxfcpp::toString(result));
}
}

Expand Down
Loading

0 comments on commit 4637843

Please sign in to comment.