summaryrefslogtreecommitdiff
path: root/src/programchain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/programchain.cpp')
-rw-r--r--src/programchain.cpp97
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
5using namespace Bu;
6
7Bu::ProgramChain::ProgramChain()
8{
9}
10
11Bu::ProgramChain::~ProgramChain()
12{
13}
14
15bool 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
30ProgramLink *Bu::ProgramChain::getLink( const char *lpName )
31{
32 char a;
33 a = lpName[0];
34 return NULL;
35}
36
37ProgramLink *Bu::ProgramChain::getBaseLink()
38{
39 return NULL;
40}
41
42bool 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
57bool Bu::ProgramChain::enterChainLoop()
58{
59 for(;;)
60 {
61 if( execChainOnce() == false )
62 {
63 return false;
64 }
65 }
66
67 return true;
68}
69
70void 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
81LinkMessage *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