35{
36
43 > cfg{"TCPDirectGettingStarted", argc, argv};
44
45 try
46 {
48
51
52
54
55 class TcpDirectListener :
public Listener
56 {
57 public:
58 explicit TcpDirectListener(const LogonConfiguration& cfg)
59 : traderLogonRequest_(Helper::createTraderLogonRequest(cfg.traderId(), cfg.traderPwd()))
60 , order_(Helper::createOrder(cfg.traderId()))
61 {
62 }
63
65 {
67
68 try
69 {
70 traderLoggedOn.get_future().get();
71 }
72 catch(const std::exception& e)
73 {
75 return;
76 }
77
78 session->
send(order_);
79 }
80
82 {
84
85 switch(newState)
86 {
88 {
89
90
91 session->
send(traderLogonRequest_);
92 break;
93 }
94
96 finished_ = true;
97 break;
98
99 default:
100 break;
101 }
102 }
103
105
108 {
110 finished_ = true;
111 }
112
113 bool finished() const noexcept {return finished_;}
114
115 private:
116 bool finished_ {false};
117 MessageHolder<TraderLogonRequest> traderLogonRequest_;
118 MessageHolder<NewOrderRequest> order_;
119 }
120 listener(cfg);
121
122
124
125
126
127 attr.
set(
"interface", cfg.nif());
128
130
131
132 const auto bgwSession= std::make_unique<BgwSession>(stack, settings, &listener, cfg.storage());
133 bgwSession->connectAsync(bgwCredentials);
134
135 std::clog << "\nPress <Ctrl+C> to disconnect the BGW session and terminate the application." << std::endl;
136
137 while(!listener.finished())
138 {
139
140
142
144 break;
145 }
146
147 bgwSession->disconnectAsync();
148
151 }
152 catch(const std::exception & ex)
153 {
154 std::cerr << "\nEXCEPTION: " << ex.what() << std::endl;
155 return 1;
156 }
157
158 return 0;
159}
Session & send(Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &msg, Messaging::Timestamp sendingTime=UtcWatch::now())
Sends the message.
TCPDirect Attributes to pass configuration details (a wrapper around the zf_attr struct).
void set(const std::string &name, const std::string &value)
Sets the attribute to the given value.
A high-level wrapper over the TCPDirect network stack.
bool isQuiescent() const noexcept override
void dispatchEvents() noexcept override
This function processes events on a stack and performs the necessary handling.
void onStateChange(SessionStateId::Enum newState, SessionStateId::Enum prevState, Session *) override
Called when the session changes its state.
void onError(const Messaging::Error msg, Session *) override
Called when an Error message is received from the counterparty.
void onTraderLogonReport(const Messaging::TraderLogonReport msg, Session *) override
Called when a TraderLogonReport message is received.
std::pair< std::unique_ptr< GatewayEmulatorThread< BusSessionGatewayListener > >, std::unique_ptr< GatewayEmulatorThread< GatewayListener > > > createEmulator(const SessionSettings &settings, const ConnectivityConfiguration &cfg, bool tcpDirect=false)
BgwCredentials receiveBgwCredentials(SessionSettings settings, std::string host, Port port)
SessionSettings fillSettings(const LogonConfiguration &logonCfg, const ConnectivityConfiguration &connCfg, const SettingsConfiguration &settingsCfg)
@ UnsuccessfulLogonReportInReplyOnLogonRequest
The unsuccessful Logon Report message is received in reply to the LogonRequest message.
@ Established
Session is fully established.
@ Disconnected
Session is disconnected.
static ONIXS_ICEBOE_FORCEINLINE bool interruptDetected() noexcept
static void manageSignals() noexcept