Skip to content

Commit

Permalink
InstrumentProfileConnection::setUpdatePeriod
Browse files Browse the repository at this point in the history
  • Loading branch information
ttldtor committed Oct 14, 2023
1 parent b6bf518 commit 051f67d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions include/dxfeed_graal_cpp_api/isolated/Isolated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions samples/cpp/DxFeedLiveIpfSample/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion src/internal/Isolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,22 @@ std::int64_t InstrumentProfileConnection::getUpdatePeriod(
return dxfg_InstrumentProfileConnection_getUpdatePeriod(
dxfcpp::bit_cast<graal_isolatethread_t *>(threadHandle), instrumentProfileConnectionHandle);
},
0, dxfcpp::bit_cast<dxfg_ipf_connection_t *>(instrumentProfileConnectionHandle))
0, dxfcpp::bit_cast<dxfg_ipf_connection_t *>(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<graal_isolatethread_t *>(threadHandle), instrumentProfileConnectionHandle,
updatePeriod) == 0;
},
false, dxfcpp::bit_cast<dxfg_ipf_connection_t *>(instrumentProfileConnectionHandle), updatePeriod);
}

bool InstrumentProfileList::release(/* dxfg_instrument_profile_list * */ void *graalInstrumentProfileList) noexcept {
Expand Down
8 changes: 8 additions & 0 deletions src/ipf/live/InstrumentProfileConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 051f67d

Please sign in to comment.