1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
20
23
31
34
35int main(
int argc,
char * argv[])
36{
37
44 > cfg{"TCPDirectGettingStarted", argc, argv};
45
46 try
47 {
49
52
53
55
56 class TcpDirectListener :
public Listener
57 {
58 public:
60 : traderLogonRequest_(
Helper::createTraderLogonRequest(cfg.traderId(), cfg.traderPwd()))
61 , order_(
Helper::createOrder(cfg.traderId()))
62 {
63 }
64
65 void onTraderLogonReport(const Messaging::TraderLogonReport msg, Session* session) override
66 {
67 Listener::onTraderLogonReport(msg, session);
68
69 try
70 {
71 traderLoggedOn.get_future().get();
72 }
73 catch(const std::exception& e)
74 {
75 onError(SessionErrorReason::UnsuccessfulLogonReportInReplyOnLogonRequest, e.what(), session, msg);
76 return;
77 }
78
79 session->
send(order_);
80 }
81
82 void onStateChange(SessionStateId::Enum newState, SessionStateId::Enum prevState, Session * session) override
83 {
84 Listener::onStateChange(newState, prevState, session);
85
86 switch(newState)
87 {
88 case SessionStateId::Established:
89 {
90
91
92 session->
send(traderLogonRequest_);
93 break;
94 }
95
96 case SessionStateId::Disconnected:
97 finished_ = true;
98 break;
99
100 default:
101 break;
102 }
103 }
104
106
107 void onError(
108 SessionErrorReason::Enum reason, const std::string & text, Session * session, Messaging::SbeMessage msg) override
109 {
110 Listener::onError(reason, text, session, msg);
111 finished_ = true;
112 }
113
114 bool finished() const noexcept {return finished_;}
115
116 private:
117 bool finished_ {false};
118 MessageHolder<TraderLogonRequest> traderLogonRequest_;
119 MessageHolder<NewOrderRequest> order_;
120 }
121 listener(cfg);
122
123
125
126
127
128 attr.
set(
"interface", cfg.nif());
129
131
132
134 bgwSession->connectAsync(bgwCredentials);
135
136 std::clog << "\nPress <Ctrl+C> to disconnect the BGW session and terminate the application." << std::endl;
137
138 while(!listener.finished())
139 {
140
141
143
145 break;
146 }
147
148 bgwSession->disconnectAsync();
149
152 }
153 catch(const std::exception & ex)
154 {
155 std::cerr << "\nEXCEPTION: " << ex.what() << std::endl;
156 return 1;
157 }
158
159 return 0;
160}
#define ONIXS_ICEBOE_NAMESPACE
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE
int main(int argc, char *argv[])
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 onError(const Messaging::Error msg, Session *) override
Called when an Error message is received from the counterparty.
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)
std::unique_ptr< T > makeUnique(Args &&...args)
static ONIXS_ICEBOE_FORCEINLINE bool interruptDetected() noexcept
static void manageSignals() noexcept