Made ilink3 gw wait for start() before its starts.

This commit is contained in:
Pedro Pinto committed 2020-07-03 14:11:22 -04:00
1 parent 07d14f877b
commit fca808fe0d
1 file changed
+24 -18
@@ -5,12 +5,12 @@
#include "lib/jetfix/common/OutFIX.h"
#include "lib/jetfix/store/session_name.h"
#include "lib/orderman/actors/GLBXExecutionGateway.h"
#include "lib/orderman/actors/ilink3/IL3MessageFramer.h"
#include "lib/orderman/actors/ilink3/IL3Reactor.h"
#include "lib/orderman/actors/ilink3/ILinkGW.h"
#include "lib/orderman/actors/ilink3/SessionStore.h"
#include "lib/orderman/events/NewSecuritiesEvent.h"
#include "lib/orderman/orderman_utils/fix_order_codec.h"
#include "lib/orderman/actors/ilink3/IL3MessageFramer.h"
namespace bts {
namespace orderman {
@@ -31,7 +31,7 @@ struct GLBXiLink3ExecutionGateway::PImpl {
on_gw_status_change(), on_cancel_reject(), perf_log(log),
sec_oracle(o), securities(), securities_by_descriptor(),
gw_name(cfg.name()), session_store(), gw(), connection(nullptr),
connection_failures(0) {
connection_failures(0), started(false) {
TCPEndpoint endpoint{cfg.socket_connect_host_ip(),
(ushort)cfg.socket_connect_port()};
connection = &reactor.register_connection({endpoint});
@@ -56,6 +56,7 @@ struct GLBXiLink3ExecutionGateway::PImpl {
std::optional<ILinkGW> gw;
IL3Connection *connection;
size_t connection_failures;
bool started;
};
GLBXiLink3ExecutionGateway::GLBXiLink3ExecutionGateway(
@@ -67,20 +68,25 @@ GLBXiLink3ExecutionGateway::GLBXiLink3ExecutionGateway(
GLBXiLink3ExecutionGateway::~GLBXiLink3ExecutionGateway() {}
void GLBXiLink3ExecutionGateway::start() {}
void GLBXiLink3ExecutionGateway::start() {
bts_assert(!me->started);
me->started = true;
}
void GLBXiLink3ExecutionGateway::dispatch_incoming_fix_messages() {
switch (me->state) {
case State::WAITING_FOR_SECURITIES:
break;
case State::PAUSED:
on_time();
break;
case State::READY:
case State::CONNECTING:
me->reactor.do_work();
me->gw->on_time();
break;
if (me->started) {
switch (me->state) {
case State::WAITING_FOR_SECURITIES:
break;
case State::PAUSED:
on_time();
break;
case State::READY:
case State::CONNECTING:
me->reactor.do_work();
me->gw->on_time();
break;
}
}
}
@@ -133,7 +139,8 @@ void GLBXiLink3ExecutionGateway::connect(jetfix::SessionName const &sn) {
store->async_store_raw_msg(d, msg);
};
me->gw.emplace(*me->connection, me->framer, &me->sec_oracle, me->session_store->starting_session_descriptor(), c, me->cfg);
me->gw.emplace(*me->connection, me->framer, &me->sec_oracle,
me->session_store->starting_session_descriptor(), c, me->cfg);
me->gw->subscribe_cancel_reject([this](auto k, auto const &msg) {
bts_assert(me->state == State::READY || me->state == State::CONNECTING);
@@ -145,9 +152,8 @@ void GLBXiLink3ExecutionGateway::connect(jetfix::SessionName const &sn) {
me->on_exe_report(*er, {});
});
me->gw->subscribe_session([this](auto const &s) {
me->session_store->async_update_session(s);
});
me->gw->subscribe_session(
[this](auto const &s) { me->session_store->async_update_session(s); });
me->gw->subscribe_state([this](auto gw_state) {
LOG(iLink3, Info, "Internal gateway state change in {}. State is now {}",