94{
95
101 > cfg{ "Session Scheduler", argc, argv };
102
103 try
104 {
106
108
110
111
112 BusSession busSession(sessionSettings, &sessionStateChangeTracer_);
113
114
115 BgwSession bgwSession(sessionSettings, &sessionStateChangeTracer_);
116
117
122
123
124 std::atomic<bool> stopSchedulerThread{ false };
125 std::thread schedulerThread([&]()
126 {
127 const int spinWaitMicrosecondPause = 1000;
128 while (!stopSchedulerThread)
129 {
130 scheduler.dispatchEvents();
132 }
133 });
134
135 std::cout << "Scheduling BUS session " << busSession.toString() << " for automatic connection." << std::endl;
138 scheduler.add(&busSession, sessionScheduleForBus, sessionConnectivityForBus);
139
140 std::cout << "Scheduling BGW session " << bgwSession.toString() << " for automatic connection." << std::endl;
141
143 scheduler.add(&bgwSession, sessionScheduleForBgw, &busSession);
144
145 std::cout << "Waiting for activity on scheduled sessions " << bgwSession.toString() << '.' << std::endl << std::endl;
146
147
149
151
152 std::cout << std::endl << "Removing sessions from scheduling service." << std::endl;
153
154
155 scheduler.remove(&busSession);
156 scheduler.remove(&bgwSession);
157
158 stopSchedulerThread = true;
159 schedulerThread.join();
160
161 std::cout << std::endl << "Done." << std::endl;
162 }
163 catch(const std::exception & ex)
164 {
165 std::cerr << "Error: " << ex.what() << std::endl;
166 return 1;
167 }
168
169 return 0;
170}
SessionSchedule constructShortTimeActivitySchedule(int delayInSeconds=5)
void waitUntilState(Session *session, SessionStateId::Enum state, unsigned pollMs=1000)
Connection-related settings.
SessionSchedulerListener * eventListener() const noexcept
static void spinWait(size_t microseconds)
Executes a single instruction during the given number of microseconds.
std::pair< std::unique_ptr< GatewayEmulatorThread< BusSessionGatewayListener > >, std::unique_ptr< GatewayEmulatorThread< GatewayListener > > > createEmulator(const SessionSettings &settings, const ConnectivityConfiguration &cfg, bool tcpDirect=false)
SessionSettings fillSettings(const LogonConfiguration &logonCfg, const ConnectivityConfiguration &connCfg, const SettingsConfiguration &settingsCfg)
@ Established
Session is fully established.
@ Disconnected
Session is disconnected.