Skip to content

Commit

Permalink
InstrumentProfileConnection::getState
Browse files Browse the repository at this point in the history
  • Loading branch information
ttldtor committed Oct 14, 2023
1 parent 051f67d commit 8b1f3fd
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,54 @@ class DXFCPP_EXPORT InstrumentProfileConnection final : public SharedEntity {
/// The alias to a type of unique pointer to the InstrumentProfileConnection object
using Unique = std::unique_ptr<InstrumentProfileConnection>;

/**
* Instrument profile connection state.
*/
enum class State : std::int32_t {
/**
* Instrument profile connection is not started yet.
* @ref InstrumentProfileConnection::start() "start" was not invoked yet.
*/
NOT_CONNECTED,

/**
* Connection is being established.
*/
CONNECTING,

/**
* Connection was established.
*/
CONNECTED,

/**
* Initial instrument profiles snapshot was fully read (this state is set only once).
*/
COMPLETED,

/**
* Instrument profile connection was @ref InstrumentProfileConnection::close() "closed".
*/
CLOSED
};

static auto stateToString(State state) noexcept {
switch (state) {
case State::NOT_CONNECTED:
return "NOT_CONNECTED";
case State::CONNECTING:
return "CONNECTING";
case State::CONNECTED:
return "CONNECTED";
case State::COMPLETED:
return "COMPLETED";
case State::CLOSED:
return "CLOSED";
}

return "";
}

/**
* Creates instrument profile connection with a specified address and collector.
* Address may be just "<host>:<port>" of server, URL, or a file path.
Expand Down Expand Up @@ -91,6 +139,13 @@ class DXFCPP_EXPORT InstrumentProfileConnection final : public SharedEntity {
void setUpdatePeriod(std::chrono::milliseconds updatePeriod) const noexcept {
setUpdatePeriod(updatePeriod.count());
}

/**
* Returns state of this instrument profile connections.
*
* @return The state of this instrument profile connections.
*/
State getState() const noexcept;
};

} // namespace dxfcpp
3 changes: 2 additions & 1 deletion include/dxfeed_graal_cpp_api/isolated/Isolated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ 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);
static bool setUpdatePeriod(/* dxfg_ipf_connection_t * */ void* instrumentProfileConnectionHandle, std::int64_t updatePeriod) noexcept;
static dxfcpp::InstrumentProfileConnection::State getState(/* dxfg_ipf_connection_t * */ void* instrumentProfileConnectionHandle) noexcept;
};

struct InstrumentProfileList {
Expand Down
34 changes: 33 additions & 1 deletion src/internal/Isolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ std::int64_t InstrumentProfileConnection::getUpdatePeriod(
}

bool InstrumentProfileConnection::setUpdatePeriod(/* dxfg_ipf_connection_t * */ void *instrumentProfileConnectionHandle,
std::int64_t updatePeriod) {
std::int64_t updatePeriod) noexcept {
if (!instrumentProfileConnectionHandle) {
return false;
}
Expand All @@ -378,6 +378,38 @@ bool InstrumentProfileConnection::setUpdatePeriod(/* dxfg_ipf_connection_t * */
false, dxfcpp::bit_cast<dxfg_ipf_connection_t *>(instrumentProfileConnectionHandle), updatePeriod);
}

static dxfcpp::InstrumentProfileConnection::State graalStateToState(dxfg_ipf_connection_state_t state) {
switch (state) {
case DXFG_IPF_CONNECTION_STATE_NOT_CONNECTED:
return dxfcpp::InstrumentProfileConnection::State::NOT_CONNECTED;
case DXFG_IPF_CONNECTION_STATE_CONNECTING:
return dxfcpp::InstrumentProfileConnection::State::CONNECTING;
case DXFG_IPF_CONNECTION_STATE_CONNECTED:
return dxfcpp::InstrumentProfileConnection::State::CONNECTED;
case DXFG_IPF_CONNECTION_STATE_COMPLETED:
return dxfcpp::InstrumentProfileConnection::State::COMPLETED;
case DXFG_IPF_CONNECTION_STATE_CLOSED:
return dxfcpp::InstrumentProfileConnection::State::CLOSED;
}

return dxfcpp::InstrumentProfileConnection::State::NOT_CONNECTED;
}

dxfcpp::InstrumentProfileConnection::State
InstrumentProfileConnection::getState(/* dxfg_ipf_connection_t * */ void *instrumentProfileConnectionHandle) noexcept {
if (!instrumentProfileConnectionHandle) {
return dxfcpp::InstrumentProfileConnection::State::CLOSED;
}

return runIsolatedOrElse(
[](auto threadHandle, auto &&instrumentProfileConnectionHandle) {
return graalStateToState(dxfg_InstrumentProfileConnection_getState(
dxfcpp::bit_cast<graal_isolatethread_t *>(threadHandle), instrumentProfileConnectionHandle));
},
dxfcpp::InstrumentProfileConnection::State::CLOSED,
dxfcpp::bit_cast<dxfg_ipf_connection_t *>(instrumentProfileConnectionHandle));
}

bool InstrumentProfileList::release(/* dxfg_instrument_profile_list * */ void *graalInstrumentProfileList) noexcept {
if (!graalInstrumentProfileList) {
return false;
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 @@ -65,4 +65,12 @@ void InstrumentProfileConnection::setUpdatePeriod(std::int64_t updatePeriod) con
isolated::ipf::InstrumentProfileConnection::setUpdatePeriod(handle_.get(), updatePeriod);
}

InstrumentProfileConnection::State InstrumentProfileConnection::getState() const noexcept {
if (!handle_) {
return InstrumentProfileConnection::State::CLOSED;
}

return isolated::ipf::InstrumentProfileConnection::getState(handle_.get());
}

} // namespace dxfcpp

0 comments on commit 8b1f3fd

Please sign in to comment.