diff --git a/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp b/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp index af56ba90..ce0e9994 100644 --- a/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp +++ b/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp @@ -272,14 +272,7 @@ class DXFCPP_EXPORT DXFeedSubscription : public RequireMakeShared &sub, /* dxfg_feed_event_listener_t * */ const JavaObjectHandle &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 &sub, /* dxfg_symbol_t * */ void* symbol); + /** * Calls the Graal SDK function `dxfg_DXFeedSubscription_addChangeListener` in isolation. * diff --git a/src/api/DXFeedSubscription.cpp b/src/api/DXFeedSubscription.cpp index 05072525..e6b62633 100644 --- a/src/api/DXFeedSubscription.cpp +++ b/src/api/DXFeedSubscription.cpp @@ -25,7 +25,7 @@ struct DXFeedSubscription::Impl { sub->onEvent_(events); } - }; + } }; void DXFeedSubscription::attach(std::shared_ptr feed) { @@ -44,6 +44,15 @@ void DXFeedSubscription::detach(std::shared_ptr feed) { feed->detachSubscription(sharedAs()); } +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 listener) { isolated::api::IsolatedDXFeedSubscription::addChangeListener(handle_, listener->getHandle()); @@ -77,16 +86,7 @@ void DXFeedSubscription::removeChangeListener(std::size_t changeListenerId) { } void DXFeedSubscription::addSymbolImpl(void *graalSymbol) const { - if (!handle_) { - return; - } - - runIsolatedOrElse( - [handle = static_cast(handle_.get()), graalSymbol](auto threadHandle) { - return dxfg_DXFeedSubscription_addSymbol(static_cast(threadHandle), handle, - static_cast(graalSymbol)) == 0; - }, - false); + isolated::api::IsolatedDXFeedSubscription::addSymbol(handle_, graalSymbol); } void DXFeedSubscription::addSymbolsImpl(void *graalSymbolList) const { diff --git a/src/isolated/api/IsolatedDXFeedSubscription.cpp b/src/isolated/api/IsolatedDXFeedSubscription.cpp index aeb9b845..f4d37317 100644 --- a/src/isolated/api/IsolatedDXFeedSubscription.cpp +++ b/src/isolated/api/IsolatedDXFeedSubscription.cpp @@ -54,6 +54,23 @@ addEventListener(/* dxfg_subscription_t * */ const JavaObjectHandle(listener.get())); } +void /* int32_t */ addSymbol(/* dxfg_subscription_t * */ const JavaObjectHandle &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(sub.get()), + static_cast(symbol)); +} + void /* int32_t */ addChangeListener( /* dxfg_subscription_t * */ const JavaObjectHandle &sub, /* dxfg_observable_subscription_change_listener_t * */ const JavaObjectHandle