OnixS C++ ICE Binary Order Entry Handler 1.2.3
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::Gateway & gateway () const noexcept

Detailed Description

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

Definition at line 93 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 96 of file Emulator.h.

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

◆ ~GatewayEmulatorThread()

template<class Listener>
~GatewayEmulatorThread ( )
inline

Definition at line 127 of file Emulator.h.

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

Member Function Documentation

◆ gateway()

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

Definition at line 145 of file Emulator.h.

146 {
147 return gateway_;
148 }

◆ wait()

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

Definition at line 135 of file Emulator.h.

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