-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathsimplechain.cpp
84 lines (65 loc) · 1.99 KB
/
simplechain.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* \file simplechain.cpp
*/
#include <mipcomponentchain.h>
#include <mipcomponent.h>
#include <miptime.h>
#include <mipaveragetimer.h>
#include <mipmessagedumper.h>
#include <iostream>
#include <string>
#include <cstdlib>
void checkError(bool returnValue, const MIPComponent &component)
{
if (returnValue == true)
return;
std::cerr << "An error occured in component: " << component.getComponentName() << std::endl;
std::cerr << "Error description: " << component.getErrorString() << std::endl;
exit(-1);
}
void checkError(bool returnValue, const MIPComponentChain &chain)
{
if (returnValue == true)
return;
std::cerr << "An error occured in chain: " << chain.getName() << std::endl;
std::cerr << "Error description: " << chain.getErrorString() << std::endl;
exit(-1);
}
class MyChain : public MIPComponentChain
{
public:
MyChain(const std::string &chainName) : MIPComponentChain(chainName)
{
}
private:
void onThreadExit(bool error, const std::string &errorComponent, const std::string &errorDescription)
{
if (!error)
return;
std::cerr << "An error occured in the background thread." << std::endl;
std::cerr << " Component: " << errorComponent << std::endl;
std::cerr << " Error description: " << errorDescription << std::endl;
}
};
int main(void)
{
// We'll initialize the timer to generate messages after 0.5 seconds.
MIPAverageTimer timer(MIPTime(0.5));
MIPMessageDumper msgDump;
MyChain chain("Simple chain");
bool returnValue;
// The timing component and message dumper don't require further
// initialization, so we'll just add them to the chain.
returnValue = chain.setChainStart(&timer);
checkError(returnValue, chain);
returnValue = chain.addConnection(&timer, &msgDump);
checkError(returnValue, chain);
// Now, we can start the chain.
returnValue = chain.start();
checkError(returnValue, chain);
// We'll wait five seconds before stopping the chain.
MIPTime::wait(MIPTime(5.0));
returnValue = chain.stop();
checkError(returnValue, chain);
return 0;
}