OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
GatewayEmulatorThread< Listener > Class Template Reference

Public Member Functions

 GatewayEmulatorThread (const SessionSettings::LicenseStores &licenseStores, const std::string &host, Port port, std::unique_ptr< Listener > clientMessageListener)
 ~GatewayEmulatorThread ()
void wait (std::chrono::seconds timeout=std::chrono::seconds(10))
const Testing::Gatewaygateway () const noexcept

Detailed Description

template<class Listener>
class Samples::GatewayEmulatorThread< Listener >

Definition at line 91 of file Emulator.h.

Constructor & Destructor Documentation

◆ GatewayEmulatorThread()

template<class Listener>
GatewayEmulatorThread ( const SessionSettings::LicenseStores & licenseStores,
const std::string & host,
Port port,
std::unique_ptr< Listener > clientMessageListener )
inline

Definition at line 94 of file Emulator.h.

95 : gateway_(licenseStores, port, host.c_str(), std::chrono::seconds{10}, std::chrono::seconds{10})
96 , clientMessageListener_(std::move(clientMessageListener))
97 {
98 std::promise<void> emulatorTaskPromise;
99 emulatorTaskDone_ = emulatorTaskPromise.get_future();
100
101 std::thread(
102 std::bind(
103 [&](std::promise<void>& p)
104 {
105 try
106 {
107 gateway_.run(*clientMessageListener_, &stopRequested_);
108 p.set_value();
109 }
110 catch (const std::exception& ex)
111 {
112 std::cerr << "Exception in Emulator's thread: " << ex.what() << '.' << std::endl;
113 p.set_exception(std::current_exception());
114 }
115 catch (...)
116 {
117 std::cerr << "UNKNOWN Exception in Emulator's thread." << std::endl;
118 p.set_exception(std::current_exception());
119 }
120 },
121 std::move(emulatorTaskPromise)))
122 .detach();
123 }

◆ ~GatewayEmulatorThread()

template<class Listener>
~GatewayEmulatorThread ( )
inline

Definition at line 125 of file Emulator.h.

126 {
127 stopRequested_.store(true);
128
129 if(emulatorTaskDone_.valid())
130 emulatorTaskDone_.wait_for(std::chrono::seconds(10));
131 }

Member Function Documentation

◆ gateway()

template<class Listener>
const Testing::Gateway & gateway ( ) const
inlinenoexcept

Definition at line 143 of file Emulator.h.

144 {
145 return gateway_;
146 }

◆ wait()

template<class Listener>
void wait ( std::chrono::seconds timeout = std::chrono::seconds(10))
inline

Definition at line 133 of file Emulator.h.

134 {
135 if(emulatorTaskDone_.valid())
136 {
137 std::future<void> f = std::move(emulatorTaskDone_);
138 f.wait_for(timeout);
139 f.get();
140 }
141 }