OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
ThreadPoolMode.cpp File Reference

Go to the source code of this file.

Functions

int main (int argc, char *argv[])

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 33 of file ThreadPoolMode.cpp.

34{
35 // `--help` to show options.
36 const AppConfiguration<
38 > cfg{"ThreadPoolMode", argc, argv};
39
40 try
41 {
43
44 auto settings = fillSettings(cfg);
45 const auto emulator = createEmulator(settings, cfg);
46
47 // Request Binary Order Gateway credentials from Binary Utility Service Gateway.
48 const auto bgwCredentials = receiveBgwCredentials(settings, cfg.host(), cfg.port());
49
50 settings.threadingModel(ThreadingModel::Pool);
51
52 ServiceFactory factory{settings};
53 Listener listener;
54 const auto bgwSession= std::make_unique<BgwSession>(factory, settings, &listener, cfg.storage());
55
56 bgwSession->connect(bgwCredentials);
57 bgwSession->send(Helper::createTraderLogonRequest(cfg.traderId(), cfg.traderPwd()));
58
59 Samples::wait(listener.traderLoggedOn).get();
60
61 bgwSession->send(Helper::createOrder(cfg.traderId()));
62
63 SignalHelper::waitUntilKey("disconnect the BGW session and terminate the application");
64
65 bgwSession->send(Helper::createTraderLogoutRequest(cfg.traderId())).disconnect();
66 }
67 catch(const std::exception & ex)
68 {
69 std::cerr << "\nEXCEPTION: " << ex.what() << std::endl;
70 return 1;
71 }
72
73 return 0;
74}
static MessageHolder< NewOrderRequest > createOrder(const std::string &traderId)
Definition Helpers.h:104
static MessageHolder< TraderLogoutRequest > createTraderLogoutRequest(const std::string &traderId)
Definition Helpers.h:95
static MessageHolder< TraderLogonRequest > createTraderLogonRequest(const std::string &traderId, const std::string &traderPwd)
Definition Helpers.h:77
std::promise< void > traderLoggedOn
Definition Listener.h:223
std::pair< std::unique_ptr< GatewayEmulatorThread< BusSessionGatewayListener > >, std::unique_ptr< GatewayEmulatorThread< GatewayListener > > > createEmulator(const SessionSettings &settings, const ConnectivityConfiguration &cfg, bool tcpDirect=false)
Definition Emulator.h:157
BgwCredentials receiveBgwCredentials(SessionSettings settings, std::string host, Port port)
Definition Listener.h:264
SessionSettings fillSettings(const LogonConfiguration &logonCfg, const ConnectivityConfiguration &connCfg, const SettingsConfiguration &settingsCfg)
Definition Settings.h:32
std::future< T > wait(Stack &stack, std::promise< T > &promise, std::chrono::seconds timeout=std::chrono::seconds{30})
Definition Listener.h:227
@ Pool
Sessions share a thread pool.
static void waitUntilKey(const std::string &message)
Definition Signal.h:57
static void manageSignals() noexcept
Definition Signal.h:46