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