Skip to content

Commit

Permalink
[EN-7587] Implement FetchDailyCandles sample
Browse files Browse the repository at this point in the history
IsolatedDXFeedSubscription::addSymbol
  • Loading branch information
AnatolyKalin committed Jun 10, 2024
1 parent 0e919c8 commit c2f8ebd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
9 changes: 1 addition & 8 deletions include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,7 @@ class DXFCPP_EXPORT DXFeedSubscription : public RequireMakeShared<DXFeedSubscrip
* event listeners and subscription change listeners and makes sure that no more listeners
* can be added.
*/
void close() const {
if constexpr (Debugger::isDebug) {
// ReSharper disable once CppDFAUnreachableCode
Debugger::debug(toString() + "::close()");
}

closeImpl();
}
void close() const;

/**
* Adds listener for events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ namespace isolated::api::IsolatedDXFeedSubscription {

/*
int32_t dxfg_DXFeedSubscription_addEventListener(graal_isolatethread_t *thread, dxfg_subscription_t
*sub, dxfg_feed_event_listener_t *listener);
int32_t dxfg_DXFeedSubscription_removeEventListener(graal_isolatethread_t *thread, dxfg_subscription_t
*sub, dxfg_feed_event_listener_t *listener);
Expand Down Expand Up @@ -113,6 +110,21 @@ void /* int32_t */
addEventListener(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFeedSubscription> &sub,
/* dxfg_feed_event_listener_t * */ const JavaObjectHandle<DXFeedEventListener> &listener);

// int32_t dxfg_DXFeedSubscription_removeEventListener(graal_isolatethread_t *thread, dxfg_subscription_t *sub, dxfg_feed_event_listener_t *listener);

// int32_t dxfg_DXFeedSubscription_addSymbol(graal_isolatethread_t *thread, dxfg_subscription_t *sub, dxfg_symbol_t *symbol);

/**
* Calls the Graal SDK function `dxfg_DXFeedSubscription_addSymbol` in isolation.
*
* @param sub The subscription's handle.
* @param symbol The symbol.
* @throws std::invalid_argument if DXFeedSubscription's handle is invalid or the symbol is nullptr.
* @throws JavaException if something happened with the dxFeed API backend.
* @throws GraalException if something happened with the GraalVM.
*/
void /* int32_t */ addSymbol(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFeedSubscription> &sub, /* dxfg_symbol_t * */ void* symbol);

/**
* Calls the Graal SDK function `dxfg_DXFeedSubscription_addChangeListener` in isolation.
*
Expand Down
22 changes: 11 additions & 11 deletions src/api/DXFeedSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct DXFeedSubscription::Impl {

sub->onEvent_(events);
}
};
}
};

void DXFeedSubscription::attach(std::shared_ptr<DXFeed> feed) {
Expand All @@ -44,6 +44,15 @@ void DXFeedSubscription::detach(std::shared_ptr<DXFeed> feed) {
feed->detachSubscription(sharedAs<DXFeedSubscription>());
}

void DXFeedSubscription::close() const {
if constexpr (Debugger::isDebug) {
// ReSharper disable once CppDFAUnreachableCode
Debugger::debug(toString() + "::close()");
}

closeImpl();
}

std::size_t DXFeedSubscription::addChangeListener(std::shared_ptr<ObservableSubscriptionChangeListener> listener) {
isolated::api::IsolatedDXFeedSubscription::addChangeListener(handle_, listener->getHandle());

Expand Down Expand Up @@ -77,16 +86,7 @@ void DXFeedSubscription::removeChangeListener(std::size_t changeListenerId) {
}

void DXFeedSubscription::addSymbolImpl(void *graalSymbol) const {
if (!handle_) {
return;
}

runIsolatedOrElse(
[handle = static_cast<dxfg_subscription_t *>(handle_.get()), graalSymbol](auto threadHandle) {
return dxfg_DXFeedSubscription_addSymbol(static_cast<graal_isolatethread_t *>(threadHandle), handle,
static_cast<dxfg_symbol_t *>(graalSymbol)) == 0;
},
false);
isolated::api::IsolatedDXFeedSubscription::addSymbol(handle_, graalSymbol);
}

void DXFeedSubscription::addSymbolsImpl(void *graalSymbolList) const {
Expand Down
17 changes: 17 additions & 0 deletions src/isolated/api/IsolatedDXFeedSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ addEventListener(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFeedSubscr
static_cast<dxfg_feed_event_listener_t *>(listener.get()));
}

void /* int32_t */ addSymbol(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFeedSubscription> &sub,
/* dxfg_symbol_t * */ void *symbol) {
if (!sub) {
throw std::invalid_argument(
"Unable to execute function `dxfg_DXFeedSubscription_addSymbol`. The `sub` handle is invalid");
}

if (!symbol) {
throw std::invalid_argument("Unable to execute function `dxfg_DXFeedSubscription_addSymbol`. The "
"`symbol` is nullptr");
}

runGraalFunctionAndThrowIfLessThanZero(dxfg_DXFeedSubscription_addSymbol,
static_cast<dxfg_subscription_t *>(sub.get()),
static_cast<dxfg_symbol_t *>(symbol));
}

void /* int32_t */ addChangeListener(
/* dxfg_subscription_t * */ const JavaObjectHandle<DXFeedSubscription> &sub,
/* dxfg_observable_subscription_change_listener_t * */ const JavaObjectHandle<ObservableSubscriptionChangeListener>
Expand Down

0 comments on commit c2f8ebd

Please sign in to comment.