-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
67 lines (53 loc) · 2.22 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "AsyncCallback.h"
#include "SelfTestEngine.h"
#include <iostream>
#include <chrono>
// main.cpp
// @see https://github.com/endurodave/StateMachineWithThreads
// David Lafreniere, Aug 2020.
// Other related respositories:
// https://github.com/endurodave/StateMachine
// https://github.com/endurodave/StateMachineWithDelegates
// https://github.com/endurodave/C_StateMachineWithThreads
// https://github.com/endurodave/C_StateMachine
using namespace std;
// A thread to capture self-test status callbacks for output to the "user interface"
WorkerThread userInterfaceThread("UserInterface");
// Simple flag to exit main loop
BOOL selfTestEngineCompleted = FALSE;
//------------------------------------------------------------------------------
// SelfTestEngineStatusCallback
//------------------------------------------------------------------------------
void SelfTestEngineStatusCallback(const SelfTestStatus& status, void* userData)
{
// Output status message to the console "user interface"
cout << status.message.c_str() << endl;
}
//------------------------------------------------------------------------------
// SelfTestEngineCompleteCallback
//------------------------------------------------------------------------------
void SelfTestEngineCompleteCallback(const NoData& data, void* userData)
{
selfTestEngineCompleted = TRUE;
}
//------------------------------------------------------------------------------
// main
//------------------------------------------------------------------------------
int main(void)
{
// Create the worker threads
userInterfaceThread.CreateThread();
SelfTestEngine::GetInstance().GetThread().CreateThread();
// Register for self-test engine callbacks
SelfTestEngine::StatusCallback.Register(&SelfTestEngineStatusCallback, &userInterfaceThread);
SelfTestEngine::GetInstance().CompletedCallback.Register(&SelfTestEngineCompleteCallback, &userInterfaceThread);
// Start self-test engine
SelfTestEngine::GetInstance().Start();
// Wait for self-test engine to complete
while (!selfTestEngineCompleted)
std::this_thread::sleep_for(std::chrono::milliseconds(10));
// Exit the worker threads
userInterfaceThread.ExitThread();
SelfTestEngine::GetInstance().GetThread().ExitThread();
return 0;
}