From 218a7a289559bf0f902cf38803a01a6801635d60 Mon Sep 17 00:00:00 2001 From: ttldtor Date: Fri, 26 Jul 2024 12:47:47 +0300 Subject: [PATCH] [MDAPI-37][C++] Retrieve latest events from feed Fix IsolatedDXFeed::getLastEvent --- samples/cpp/DxFeedSample/src/main.cpp | 4 +--- src/isolated/api/IsolatedDXFeed.cpp | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/samples/cpp/DxFeedSample/src/main.cpp b/samples/cpp/DxFeedSample/src/main.cpp index e2e59bfb..129784c2 100644 --- a/samples/cpp/DxFeedSample/src/main.cpp +++ b/samples/cpp/DxFeedSample/src/main.cpp @@ -62,7 +62,7 @@ void testTradeSnapshots(const std::string &symbol) { sub->addSymbols(symbol); while (true) { - std::cout << feed->getLastEvent(std::make_shared(symbol))->toString() + "\n"; + std::cout << "LAST: " + feed->getLastEvent(std::make_shared(symbol))->toString() + "\n"; std::this_thread::sleep_for(1000ms); } } @@ -94,8 +94,6 @@ DxFeedSample testQuoteListener(symbol); testQuoteAndTradeListener(symbol); testTradeSnapshots(symbol); - - //std::cin.get(); } catch (const RuntimeException &e) { std::cerr << e << '\n'; } diff --git a/src/isolated/api/IsolatedDXFeed.cpp b/src/isolated/api/IsolatedDXFeed.cpp index 1498a873..3e6e0df6 100644 --- a/src/isolated/api/IsolatedDXFeed.cpp +++ b/src/isolated/api/IsolatedDXFeed.cpp @@ -11,24 +11,30 @@ DXFCPP_BEGIN_NAMESPACE namespace isolated::api::IsolatedDXFeed { - // dxfg_DXFeed_getLastEvent -/* int32_t */ std::shared_ptr getLastEvent(/* dxfg_feed_t * */ const JavaObjectHandle& feed, /* dxfg_event_type_t * */ const StringLikeWrapper& symbolName, const EventTypeEnum& eventType) { +/* int32_t */ std::shared_ptr getLastEvent(/* dxfg_feed_t * */ const JavaObjectHandle &feed, + /* dxfg_event_type_t * */ const StringLikeWrapper &symbolName, + const EventTypeEnum &eventType) { if (!feed) { throw InvalidArgumentException( "Unable to execute function `dxfg_DXFeed_getLastEvent`. The `feed` handle is invalid"); } - auto e = event::IsolatedEventType::toUnique(event::IsolatedEventType::create(symbolName, eventType)); + const auto e = event::IsolatedEventType::toUnique(event::IsolatedEventType::create(symbolName, eventType)); + + runGraalFunctionAndThrowIfMinusOne(dxfg_DXFeed_getLastEvent, static_cast(feed.get()), + static_cast(e.get())); return EventMapper::fromGraal(e.get()); } /* -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); +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); */