Skip to content

Commit

Permalink
[EN-7587] Implement FetchDailyCandles sample
Browse files Browse the repository at this point in the history
IsolatedDXFeedSubscription::getSymbols
IsolatedDXFeedSubscription::setSymbols
IsolatedDXFeedSubscription::getDecoratedSymbols
  • Loading branch information
AnatolyKalin committed Jun 17, 2024
1 parent 4b48f6e commit 6d8b0e8
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,6 @@ DXFCPP_BEGIN_NAMESPACE

namespace isolated::api::IsolatedDXFeedSubscription {

/*


int32_t dxfg_DXFeedSubscription_isClosed(graal_isolatethread_t *thread, dxfg_subscription_t *sub);

dxfg_event_clazz_list_t* dxfg_DXFeedSubscription_getEventTypes(graal_isolatethread_t *thread, dxfg_subscription_t
*sub);

int32_t dxfg_DXFeedSubscription_containsEventType(graal_isolatethread_t *thread, dxfg_subscription_t
*sub, dxfg_event_clazz_t eventClazz);

dxfg_symbol_list* dxfg_DXFeedSubscription_getSymbols(graal_isolatethread_t *thread, dxfg_subscription_t *sub);

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

int32_t dxfg_DXFeedSubscription_setSymbols(graal_isolatethread_t *thread, dxfg_subscription_t *sub,
dxfg_symbol_list *symbols);

dxfg_symbol_list* dxfg_DXFeedSubscription_getDecoratedSymbols(graal_isolatethread_t *thread, dxfg_subscription_t
*sub);

dxfg_executor_t* dxfg_DXFeedSubscription_getExecutor(graal_isolatethread_t *thread, dxfg_subscription_t *sub);

int32_t dxfg_DXFeedSubscription_setExecutor(graal_isolatethread_t *thread, dxfg_executor_t *executor);

*/

/**
* Calls the Graal SDK function `dxfg_DXFeedSubscription_new` in isolation.
*
Expand Down Expand Up @@ -153,9 +125,8 @@ void /* int32_t */ clear(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFe

// 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.
* Calls the Graal SDK function `dxfg_DXFeedSubscription_isClosed` in isolation.
*
* @param sub The subscription's handle.
* @return `true` if subscription is closed.
Expand All @@ -165,6 +136,51 @@ void /* int32_t */ clear(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFe
*/
bool /* int32_t */ isClosed(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFeedSubscription> &sub);

// dxfg_event_clazz_list_t* dxfg_DXFeedSubscription_getEventTypes(graal_isolatethread_t *thread, dxfg_subscription_t
// *sub);

// int32_t dxfg_DXFeedSubscription_containsEventType(graal_isolatethread_t *thread, dxfg_subscription_t *sub,
// dxfg_event_clazz_t eventClazz);

/**
* Calls the Graal SDK function `dxfg_DXFeedSubscription_getSymbols` in isolation.
*
* @param sub The subscription's handle.
* @return The subscription's symbols.
* @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.
*/
std::vector<SymbolWrapper> /* dxfg_symbol_list* */ getSymbols(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFeedSubscription> &sub);

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

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

/**
* Calls the Graal SDK function `dxfg_DXFeedSubscription_getDecoratedSymbols` in isolation.
*
* @param sub The subscription's handle.
* @return The subscription's decorated symbols.
* @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.
*/
std::vector<SymbolWrapper> /* dxfg_symbol_list* */ getDecoratedSymbols(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFeedSubscription> &sub);

// dxfg_executor_t* dxfg_DXFeedSubscription_getExecutor(graal_isolatethread_t *thread, dxfg_subscription_t *sub);

// int32_t dxfg_DXFeedSubscription_setExecutor(graal_isolatethread_t *thread, dxfg_executor_t *executor);

/**
* Calls the Graal SDK function `dxfg_DXFeedSubscription_addChangeListener` in isolation.
*
Expand Down
52 changes: 3 additions & 49 deletions src/api/DXFeedSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,61 +102,15 @@ void DXFeedSubscription::removeSymbolsImpl(void *graalSymbolList) const {
}

void DXFeedSubscription::setSymbolsImpl(void *graalSymbolList) const {
if (!handle_) {
return;
}

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

std::vector<SymbolWrapper> DXFeedSubscription::getSymbolsImpl() const {
if (!handle_) {
return {};
}

dxfg_symbol_list *list = runIsolatedOrElse(
[handle = static_cast<dxfg_subscription_t *>(handle_.get())](auto threadHandle) {
return dxfg_DXFeedSubscription_getSymbols(static_cast<graal_isolatethread_t *>(threadHandle), handle);
},
nullptr);

auto result = SymbolWrapper::SymbolListUtils::fromGraalList(static_cast<void *>(list));

runIsolatedOrElse(
[list](auto threadHandle) {
return dxfg_CList_symbol_release(static_cast<graal_isolatethread_t *>(threadHandle), list) == 0;
},
false);

return result;
return isolated::api::IsolatedDXFeedSubscription::getSymbols(handle_);
}

std::vector<SymbolWrapper> DXFeedSubscription::getDecoratedSymbolsImpl() const {
if (!handle_) {
return {};
}

dxfg_symbol_list *list = runIsolatedOrElse(
[handle = static_cast<dxfg_subscription_t *>(handle_.get())](auto threadHandle) {
return dxfg_DXFeedSubscription_getDecoratedSymbols(static_cast<graal_isolatethread_t *>(threadHandle),
handle);
},
nullptr);

auto result = SymbolWrapper::SymbolListUtils::fromGraalList(static_cast<void *>(list));

runIsolatedOrElse(
[list](auto threadHandle) {
return dxfg_CList_symbol_release(static_cast<graal_isolatethread_t *>(threadHandle), list) == 0;
},
false);

return result;
return isolated::api::IsolatedDXFeedSubscription::getDecoratedSymbols(handle_);
}

void DXFeedSubscription::closeImpl() const {
Expand Down
48 changes: 48 additions & 0 deletions src/isolated/api/IsolatedDXFeedSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,54 @@ bool /* int32_t */ isClosed(/* dxfg_subscription_t * */ const JavaObjectHandle<D
static_cast<dxfg_subscription_t *>(sub.get())) == 1;
}

std::vector<SymbolWrapper> /* dxfg_symbol_list* */ getSymbols(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFeedSubscription> &sub) {
if (!sub) {
throw std::invalid_argument(
"Unable to execute function `dxfg_DXFeedSubscription_getSymbols`. The `sub` handle is invalid");
}

dxfg_symbol_list *list = runGraalFunctionAndThrowIfNullptr(
dxfg_DXFeedSubscription_getSymbols, static_cast<dxfg_subscription_t *>(sub.get()));

auto result = SymbolWrapper::SymbolListUtils::fromGraalList(static_cast<void *>(list));

runGraalFunctionAndThrowIfLessThanZero(dxfg_CList_symbol_release, list);

return result;
}

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

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

runGraalFunctionAndThrowIfLessThanZero(dxfg_DXFeedSubscription_setSymbols,
static_cast<dxfg_subscription_t *>(sub.get()),
static_cast<dxfg_symbol_list *>(symbols));
}

std::vector<SymbolWrapper> /* dxfg_symbol_list* */ getDecoratedSymbols(/* dxfg_subscription_t * */ const JavaObjectHandle<DXFeedSubscription> &sub) {
if (!sub) {
throw std::invalid_argument(
"Unable to execute function `dxfg_DXFeedSubscription_getDecoratedSymbols`. The `sub` handle is invalid");
}

dxfg_symbol_list *list = runGraalFunctionAndThrowIfNullptr(
dxfg_DXFeedSubscription_getDecoratedSymbols, static_cast<dxfg_subscription_t *>(sub.get()));

auto result = SymbolWrapper::SymbolListUtils::fromGraalList(static_cast<void *>(list));

runGraalFunctionAndThrowIfLessThanZero(dxfg_CList_symbol_release, list);

return result;
}

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 6d8b0e8

Please sign in to comment.