From 051f67d2246e70ebab2d3eaed45375bbb9bf73a8 Mon Sep 17 00:00:00 2001 From: ttldtor Date: Sat, 14 Oct 2023 21:25:36 +0300 Subject: [PATCH] InstrumentProfileConnection::setUpdatePeriod --- .../ipf/live/InstrumentProfileConnection.hpp | 31 +++++++++++++++++++ .../isolated/Isolated.hpp | 1 + samples/cpp/DxFeedLiveIpfSample/src/main.cpp | 5 +-- src/internal/Isolate.cpp | 17 +++++++++- src/ipf/live/InstrumentProfileConnection.cpp | 8 +++++ 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/include/dxfeed_graal_cpp_api/ipf/live/InstrumentProfileConnection.hpp b/include/dxfeed_graal_cpp_api/ipf/live/InstrumentProfileConnection.hpp index e897c78c..a3552753 100644 --- a/include/dxfeed_graal_cpp_api/ipf/live/InstrumentProfileConnection.hpp +++ b/include/dxfeed_graal_cpp_api/ipf/live/InstrumentProfileConnection.hpp @@ -60,6 +60,37 @@ class DXFCPP_EXPORT InstrumentProfileConnection final : public SharedEntity { * @return The update period in milliseconds. */ std::int64_t getUpdatePeriod() const noexcept; + + /** + * Returns update period in milliseconds as chrono::duration + * It is period of an update check when the instrument profiles source does not support live updates + * and/or when connection is dropped. + * Default update period is 1 minute, unless overridden in an + * @ref InstrumentProfileConnection::createConnection() "address string". + * + * @return The update period in milliseconds as chrono::duration. + */ + std::chrono::milliseconds getUpdatePeriodAsDuration() const noexcept { + return std::chrono::milliseconds(getUpdatePeriod()); + } + + /** + * Changes the update period in milliseconds. + * + * @param updatePeriod The update period in milliseconds. + * @see InstrumentProfileConnection::getUpdatePeriod() + */ + void setUpdatePeriod(std::int64_t updatePeriod) const noexcept; + + /** + * Changes the update period in milliseconds as chrono::duration. + * + * @param updatePeriod The update period in milliseconds as chrono::duration. + * @see InstrumentProfileConnection::getUpdatePeriod() + */ + void setUpdatePeriod(std::chrono::milliseconds updatePeriod) const noexcept { + setUpdatePeriod(updatePeriod.count()); + } }; } // namespace dxfcpp \ No newline at end of file diff --git a/include/dxfeed_graal_cpp_api/isolated/Isolated.hpp b/include/dxfeed_graal_cpp_api/isolated/Isolated.hpp index 51f16631..2312a741 100644 --- a/include/dxfeed_graal_cpp_api/isolated/Isolated.hpp +++ b/include/dxfeed_graal_cpp_api/isolated/Isolated.hpp @@ -43,6 +43,7 @@ struct InstrumentProfileConnection { static /* dxfg_ipf_connection_t* */ void* createConnection(const std::string& address, /* dxfg_ipf_collector_t* */ void* instrumentProfileCollectorHandle) noexcept; static std::string getAddress(/* dxfg_ipf_connection_t * */ void* instrumentProfileConnectionHandle) noexcept; static std::int64_t getUpdatePeriod(/* dxfg_ipf_connection_t * */ void* instrumentProfileConnectionHandle) noexcept; + static bool setUpdatePeriod(/* dxfg_ipf_connection_t * */ void* instrumentProfileConnectionHandle, std::int64_t updatePeriod); }; struct InstrumentProfileList { diff --git a/samples/cpp/DxFeedLiveIpfSample/src/main.cpp b/samples/cpp/DxFeedLiveIpfSample/src/main.cpp index 283702f0..eacbe091 100644 --- a/samples/cpp/DxFeedLiveIpfSample/src/main.cpp +++ b/samples/cpp/DxFeedLiveIpfSample/src/main.cpp @@ -39,8 +39,9 @@ int main(int argc, char *argv[]) { auto collector = InstrumentProfileCollector::create(); auto connection = InstrumentProfileConnection::createConnection(url, collector); -// // Update period can be used to re-read IPF files, not needed for services supporting IPF "live-update" -// connection->setUpdatePeriod(std::chrono::seconds(60)); + // Update period can be used to re-read IPF files, not needed for services supporting IPF "live-update" + connection->setUpdatePeriod(std::chrono::seconds(60)); + // connection->addStateChangeListener( // [](InstrumentProfileConnection::State /* oldState */, InstrumentProfileConnection::State newState) { // std::cout << "Connection state: " + InstrumentProfileConnection::stateToString(newState) << std::endl; diff --git a/src/internal/Isolate.cpp b/src/internal/Isolate.cpp index 394d1dc7..3ef8f741 100644 --- a/src/internal/Isolate.cpp +++ b/src/internal/Isolate.cpp @@ -360,7 +360,22 @@ std::int64_t InstrumentProfileConnection::getUpdatePeriod( return dxfg_InstrumentProfileConnection_getUpdatePeriod( dxfcpp::bit_cast(threadHandle), instrumentProfileConnectionHandle); }, - 0, dxfcpp::bit_cast(instrumentProfileConnectionHandle)) + 0, dxfcpp::bit_cast(instrumentProfileConnectionHandle)); +} + +bool InstrumentProfileConnection::setUpdatePeriod(/* dxfg_ipf_connection_t * */ void *instrumentProfileConnectionHandle, + std::int64_t updatePeriod) { + if (!instrumentProfileConnectionHandle) { + return false; + } + + return runIsolatedOrElse( + [](auto threadHandle, auto &&instrumentProfileConnectionHandle, auto &&updatePeriod) { + return dxfg_InstrumentProfileConnection_setUpdatePeriod( + dxfcpp::bit_cast(threadHandle), instrumentProfileConnectionHandle, + updatePeriod) == 0; + }, + false, dxfcpp::bit_cast(instrumentProfileConnectionHandle), updatePeriod); } bool InstrumentProfileList::release(/* dxfg_instrument_profile_list * */ void *graalInstrumentProfileList) noexcept { diff --git a/src/ipf/live/InstrumentProfileConnection.cpp b/src/ipf/live/InstrumentProfileConnection.cpp index 1b8203fa..d4b7b2a3 100644 --- a/src/ipf/live/InstrumentProfileConnection.cpp +++ b/src/ipf/live/InstrumentProfileConnection.cpp @@ -57,4 +57,12 @@ std::int64_t InstrumentProfileConnection::getUpdatePeriod() const noexcept { return isolated::ipf::InstrumentProfileConnection::getUpdatePeriod(handle_.get()); } +void InstrumentProfileConnection::setUpdatePeriod(std::int64_t updatePeriod) const noexcept { + if (!handle_) { + return; + } + + isolated::ipf::InstrumentProfileConnection::setUpdatePeriod(handle_.get(), updatePeriod); +} + } // namespace dxfcpp \ No newline at end of file