48 auto report = gateway->createIpReport(request.
users()[0].userId(),
toStrRef(host_), port_,
toStrRef(
"emulator_token"));
50 gateway->send(report, gateway->outSeqNum());
54 const std::string host_{};
58class GatewayListener final :
public ONIXS_ICEBOE_NAMESPACE::Testing::ClientMessageListener
65 gateway->send(
report_, gateway->outSeqNum());
81 .orderStatus(OrderStatusEnum::Fill)
83 .memo(
"HelloFromEmulator")
90template <
class Listener>
95 : gateway_(licenseStores, port, host.c_str(), std::chrono::seconds{10}, std::chrono::seconds{10})
96 , clientMessageListener_(std::move(clientMessageListener))
98 std::promise<void> emulatorTaskPromise;
99 emulatorTaskDone_ = emulatorTaskPromise.get_future();
103 [&](std::promise<void>& p)
107 gateway_.run(*clientMessageListener_, &stopRequested_);
110 catch (
const std::exception& ex)
112 std::cerr <<
"Exception in Emulator's thread: " << ex.what() <<
'.' << std::endl;
113 p.set_exception(std::current_exception());
117 std::cerr <<
"UNKNOWN Exception in Emulator's thread." << std::endl;
118 p.set_exception(std::current_exception());
121 std::move(emulatorTaskPromise)))
127 stopRequested_.store(
true);
129 if(emulatorTaskDone_.valid())
130 emulatorTaskDone_.wait_for(std::chrono::seconds(10));
133 void wait(std::chrono::seconds timeout = std::chrono::seconds(10))
135 if(emulatorTaskDone_.valid())
137 std::future<void> f = std::move(emulatorTaskDone_);
149 std::atomic<bool> stopRequested_ {
false};
150 Testing::Gateway gateway_;
151 std::unique_ptr<Listener> clientMessageListener_;
152 std::future<void> emulatorTaskDone_;
163 throw std::runtime_error(
"Emulator is not supported for TCPDirect.");
166 std::clog <<
"!Emulator is used!" << std::endl;
168 auto bgwSessionGatewayListener = std::make_unique<GatewayListener>();
169 auto bgwSessionEmulatorThread = std::make_unique<GatewayEmulatorThread<GatewayListener>>(settings.
licenseStores(),
"127.0.0.1", 0, std::move(bgwSessionGatewayListener));
171 auto busSessionGatewayListener = std::make_unique<BusSessionGatewayListener>(bgwSessionEmulatorThread->gateway().host(), bgwSessionEmulatorThread->gateway().port());
172 auto busSessionEmulatorThread = std::make_unique<GatewayEmulatorThread<BusSessionGatewayListener>>(settings.
licenseStores(),
"127.0.0.1", cfg.
port(), std::move(busSessionGatewayListener));
174 return std::make_pair(std::move(busSessionEmulatorThread), std::move(bgwSessionEmulatorThread));
#define ONIXS_ICEBOE_NAMESPACE
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE
Contains the SimpleOpenFramingHeader, the SBE message, and the data buffer.
bool empty() const noexcept
const LicenseStores & licenseStores() const noexcept
BusSessionGatewayListener(const std::string &host, Port port)
void onIPRequest(const IPRequest request, OnixS::ICE::BOE::Testing::Gateway *gateway) override
Called when a IPRequest message is received.
GatewayEmulatorThread(const SessionSettings::LicenseStores &licenseStores, const std::string &host, Port port, std::unique_ptr< Listener > clientMessageListener)
void wait(std::chrono::seconds timeout=std::chrono::seconds(10))
const Testing::Gateway & gateway() const noexcept
void updateReport(const NewOrderRequest &order)
void onNewOrderRequest(const NewOrderRequest order, OnixS::ICE::BOE::Testing::Gateway *gateway) override
Called when a NewOrderRequest message is received.
MessageHolder< ExecutionReport_New > report_
std::vector< std::string > LicenseStores
Folders that contain license file(s).
StrRef toStrRef(const std::string &str)
Constructs a StrRef instance over th std::string content.
std::pair< std::unique_ptr< GatewayEmulatorThread< BusSessionGatewayListener > >, std::unique_ptr< GatewayEmulatorThread< GatewayListener > > > createEmulator(const SessionSettings &settings, const ConnectivityConfiguration &cfg, bool tcpDirect=false)
Request IP Address, Port, and Session Tokens for Binary Order Gateways.
Users users() const noexcept
auto clOrdId() const noexcept
Provides access to clOrdID field.
auto side() const noexcept
Provides access to side field.
auto originatorUserId() const noexcept
Provides access to originatorUserID field.
auto symbol() const noexcept
Provides access to symbol field.
auto ordType() const noexcept
Provides access to ordType field.