Skip to content

Commit

Permalink
[EN-7587] Implement FetchDailyCandles sample
Browse files Browse the repository at this point in the history
IsolatedDXFeedSubscription::clear
IsolatedDXFeedSubscription::isClosed
  • Loading branch information
AnatolyKalin committed Jun 17, 2024
1 parent 5d4c1c4 commit 4b48f6e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ namespace isolated::api::IsolatedDXFeedSubscription {

/*
int32_t dxfg_DXFeedSubscription_clear(graal_isolatethread_t *thread, dxfg_subscription_t *sub);
int32_t dxfg_DXFeedSubscription_attach(graal_isolatethread_t *thread, dxfg_subscription_t *sub,
dxfg_feed_t *feed);
int32_t dxfg_DXFeedSubscription_detach(graal_isolatethread_t *thread, dxfg_subscription_t *sub,
dxfg_feed_t *feed);
int32_t dxfg_DXFeedSubscription_isClosed(graal_isolatethread_t *thread, dxfg_subscription_t *sub);
Expand Down Expand Up @@ -146,6 +139,32 @@ void /* int32_t */ removeSymbol(/* dxfg_subscription_t * */ const JavaObjectHand
void /* int32_t */ removeSymbols(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFeedSubscription> &sub,
/* dxfg_symbol_list * */ void *symbols);

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

// int32_t dxfg_DXFeedSubscription_attach(graal_isolatethread_t *thread, dxfg_subscription_t *sub, dxfg_feed_t *feed);

// int32_t dxfg_DXFeedSubscription_detach(graal_isolatethread_t *thread, dxfg_subscription_t *sub, dxfg_feed_t *feed);

// int32_t dxfg_DXFeedSubscription_isClosed(graal_isolatethread_t *thread, dxfg_subscription_t *sub);
/**
* Calls the Graal SDK function `dxfg_DXFeedSubscription_clear` in isolation.
*
* @param sub The subscription's handle.
* @return `true` if subscription is closed.
* @throws std::invalid_argument if DXFeedSubscription's handle is invalid.
* @throws JavaException if something happened with the dxFeed API backend.
* @throws GraalException if something happened with the GraalVM.
*/
bool /* int32_t */ isClosed(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFeedSubscription> &sub);

/**
* Calls the Graal SDK function `dxfg_DXFeedSubscription_addChangeListener` in isolation.
*
Expand Down
20 changes: 2 additions & 18 deletions src/api/DXFeedSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,27 +164,11 @@ void DXFeedSubscription::closeImpl() const {
}

void DXFeedSubscription::clearImpl() const {
if (!handle_) {
return;
}

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

bool DXFeedSubscription::isClosedImpl() const {
if (!handle_) {
return false;
}

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

DXFeedSubscription::DXFeedSubscription(LockExternalConstructionTag)
Expand Down
20 changes: 20 additions & 0 deletions src/isolated/api/IsolatedDXFeedSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ void /* int32_t */ removeSymbols(/* dxfg_subscription_t * */ const JavaObjectHan
static_cast<dxfg_symbol_list *>(symbols));
}

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

runGraalFunctionAndThrowIfLessThanZero(dxfg_DXFeedSubscription_clear,
static_cast<dxfg_subscription_t *>(sub.get()));
}

bool /* int32_t */ isClosed(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFeedSubscription> &sub) {
if (!sub) {
throw std::invalid_argument(
"Unable to execute function `dxfg_DXFeedSubscription_isClosed`. The `sub` handle is invalid");
}

return runGraalFunctionAndThrowIfLessThanZero(dxfg_DXFeedSubscription_isClosed,
static_cast<dxfg_subscription_t *>(sub.get())) == 1;
}

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 4b48f6e

Please sign in to comment.