OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
ExternalThreadMode.cpp
Go to the documentation of this file.
1/*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable ONIXS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
20
21#include <iostream>
22
23using namespace ONIXS_ICEBOE_NAMESPACE;
25
26#include <Settings/Defaults.h>
27#include <Common/Helpers.h>
28#include <Common/Listener.h>
29#include <Common/Settings.h>
30#include <Common/Signal.h>
31#include <Common/Emulator.h>
32
33using namespace Samples;
34
35int main(int argc, char * argv[])
36{
37 // `--help` to show options.
38 const AppConfiguration<
40 > cfg{"ExternalThreadMode", argc, argv};
41
42 try
43 {
45
46 auto settings = fillSettings(cfg);
47 const auto emulator = createEmulator(settings, cfg);
48
49 // Request Binary Order Gateway credentials from Binary Utility Service Gateway.
50 const auto bgwCredentials = receiveBgwCredentials(settings, cfg.host(), cfg.port());
51
52 Listener listener;
53 TcpStandardStack stack;
54
55 settings.threadingModel(ThreadingModel::External);
56
57 // A 'BGW' session.
58 const auto bgwSession= std::make_unique<BgwSession>(stack, settings, &listener, cfg.storage());
59 const auto connectTask = bgwSession->connectAsync(bgwCredentials);
60
61 while (!connectTask.is_ready())
62 stack.dispatchEvents();
63
64 bgwSession->send(Helper::createTraderLogonRequest(cfg.traderId(), cfg.traderPwd()));
65 Samples::wait(stack, listener.traderLoggedOn).get();
66
67 bgwSession->send(Helper::createOrder(cfg.traderId()));
68
69 std::clog << "\nPress <Ctrl+C> to disconnect the BGW session and terminate the application." << std::endl;
70
72 stack.dispatchEvents();
73
74 bgwSession->send(Helper::createTraderLogoutRequest(cfg.traderId()));
75
76 const auto disconnectTask = bgwSession->disconnectAsync("The BGW session is disconnected");
77
78 while (!disconnectTask.is_ready() || !stack.isQuiescent())
79 stack.dispatchEvents();
80 }
81 catch(const std::exception & ex)
82 {
83 std::cerr << "\nEXCEPTION: " << ex.what() << std::endl;
84 return 1;
85 }
86
87 return 0;
88}
#define ONIXS_ICEBOE_NAMESPACE
Definition ABI.h:113
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE
Definition ABI.h:114
int main(int argc, char *argv[])
A high-level wrapper over the TCP standard stack.
ONIXS_ICEBOE_FORCEINLINE void dispatchEvents() override
Processes events on a stack and performs the necessary handling.
ONIXS_ICEBOE_FORCEINLINE bool isQuiescent() const override
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
@ External
Session events are handled by rolling an event loop in a user thread.
static ONIXS_ICEBOE_FORCEINLINE bool interruptDetected() noexcept
Definition Signal.h:52
static void manageSignals() noexcept
Definition Signal.h:46