diff options
Diffstat (limited to '')
-rw-r--r-- | src/programchain.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/programchain.cpp b/src/programchain.cpp new file mode 100644 index 0000000..0bb7a77 --- /dev/null +++ b/src/programchain.cpp | |||
@@ -0,0 +1,97 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include "bu/programchain.h" | ||
3 | #include "bu/programlink.h" | ||
4 | |||
5 | using namespace Bu; | ||
6 | |||
7 | Bu::ProgramChain::ProgramChain() | ||
8 | { | ||
9 | } | ||
10 | |||
11 | Bu::ProgramChain::~ProgramChain() | ||
12 | { | ||
13 | } | ||
14 | |||
15 | bool Bu::ProgramChain::addLink( ProgramLink *pLink ) | ||
16 | { | ||
17 | if( pLink->init() == false ) | ||
18 | { | ||
19 | emergencyShutdown(); | ||
20 | return false; | ||
21 | } | ||
22 | |||
23 | lLink.append( pLink ); | ||
24 | |||
25 | pLink->setChain( this ); | ||
26 | |||
27 | return true; | ||
28 | } | ||
29 | |||
30 | ProgramLink *Bu::ProgramChain::getLink( const char *lpName ) | ||
31 | { | ||
32 | char a; | ||
33 | a = lpName[0]; | ||
34 | return NULL; | ||
35 | } | ||
36 | |||
37 | ProgramLink *Bu::ProgramChain::getBaseLink() | ||
38 | { | ||
39 | return NULL; | ||
40 | } | ||
41 | |||
42 | bool Bu::ProgramChain::execChainOnce() | ||
43 | { | ||
44 | for( Bu::List<Bu::ProgramLink *>::iterator i = lLink.begin(); | ||
45 | i != lLink.end(); i++ ) | ||
46 | { | ||
47 | if( (*i)->timeSlice() == false ) | ||
48 | { | ||
49 | emergencyShutdown(); | ||
50 | return false; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | return true; | ||
55 | } | ||
56 | |||
57 | bool Bu::ProgramChain::enterChainLoop() | ||
58 | { | ||
59 | for(;;) | ||
60 | { | ||
61 | if( execChainOnce() == false ) | ||
62 | { | ||
63 | return false; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | return true; | ||
68 | } | ||
69 | |||
70 | void Bu::ProgramChain::emergencyShutdown() | ||
71 | { | ||
72 | for( Bu::List<Bu::ProgramLink *>::iterator i = lLink.begin(); | ||
73 | i != lLink.end(); i++ ) | ||
74 | { | ||
75 | (*i)->deInit(); | ||
76 | delete *i; | ||
77 | } | ||
78 | lLink.clear(); | ||
79 | } | ||
80 | |||
81 | LinkMessage *Bu::ProgramChain::broadcastIRM( LinkMessage *pMsgOut, ProgramLink *pSender ) | ||
82 | { | ||
83 | for( Bu::List<Bu::ProgramLink *>::iterator i = lLink.begin(); | ||
84 | i != lLink.end(); i++ ) | ||
85 | { | ||
86 | LinkMessage *pMsg = (*i)->processIRM( pMsgOut ); | ||
87 | if( pMsg != NULL ) | ||
88 | { | ||
89 | delete pMsgOut; | ||
90 | return pMsg; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | delete pMsgOut; | ||
95 | return NULL; | ||
96 | } | ||
97 | |||