diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-05-01 17:11:04 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-05-01 17:11:04 +0000 |
commit | f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54 (patch) | |
tree | 53cec4864776e07950e3c72f2a990a1017d08045 /src/programchain.cpp | |
download | libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.gz libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.bz2 libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.xz libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.zip |
libbu++ is finally laid out the way it should be, trunk, branches, and tags.
Diffstat (limited to '')
-rw-r--r-- | src/programchain.cpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/programchain.cpp b/src/programchain.cpp new file mode 100644 index 0000000..4e53ac8 --- /dev/null +++ b/src/programchain.cpp | |||
@@ -0,0 +1,113 @@ | |||
1 | /*************************************************************************** | ||
2 | programchain.cpp - description | ||
3 | ------------------- | ||
4 | begin : Sat Sep 6 2003 | ||
5 | copyright : (C) 2003 by Mike Buland | ||
6 | email : eichlan@yf-soft.com | ||
7 | ***************************************************************************/ | ||
8 | |||
9 | /*************************************************************************** | ||
10 | * * | ||
11 | * This program is free software; you can redistribute it and/or modify * | ||
12 | * it under the terms of the GNU General Public License as published by * | ||
13 | * the Free Software Foundation; either version 2 of the License, or * | ||
14 | * (at your option) any later version. * | ||
15 | * * | ||
16 | ***************************************************************************/ | ||
17 | |||
18 | #include <stdlib.h> | ||
19 | #include "programchain.h" | ||
20 | |||
21 | ProgramChain::ProgramChain() | ||
22 | { | ||
23 | pLog = MultiLog::getLog(); | ||
24 | pLog->LineLog( MultiLog::LStatus, "Program Chain Initialized." ); | ||
25 | } | ||
26 | |||
27 | ProgramChain::~ProgramChain() | ||
28 | { | ||
29 | } | ||
30 | |||
31 | bool ProgramChain::addLink( ProgramLink *pLink ) | ||
32 | { | ||
33 | if( pLink->init() == false ) | ||
34 | { | ||
35 | emergencyShutdown(); | ||
36 | return false; | ||
37 | } | ||
38 | |||
39 | lLink.append( pLink ); | ||
40 | |||
41 | pLink->setChain( this ); | ||
42 | |||
43 | return true; | ||
44 | } | ||
45 | |||
46 | ProgramLink *ProgramChain::getLink( const char *lpName ) | ||
47 | { | ||
48 | char a; | ||
49 | a = lpName[0]; | ||
50 | return NULL; | ||
51 | } | ||
52 | |||
53 | ProgramLink *ProgramChain::getBaseLink() | ||
54 | { | ||
55 | return NULL; | ||
56 | } | ||
57 | |||
58 | bool ProgramChain::execChainOnce() | ||
59 | { | ||
60 | int nLen = lLink.getSize(); | ||
61 | for( int j = 0; j < nLen; j++ ) | ||
62 | { | ||
63 | if( ((ProgramLink *)lLink[j])->timeSlice() == false ) | ||
64 | { | ||
65 | pLog->LineLog( MultiLog::LInfo, "Shutting down due to signal from link #%d", j ); | ||
66 | emergencyShutdown(); | ||
67 | return false; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | return true; | ||
72 | } | ||
73 | |||
74 | bool ProgramChain::enterChainLoop() | ||
75 | { | ||
76 | for(;;) | ||
77 | { | ||
78 | if( execChainOnce() == false ) | ||
79 | { | ||
80 | return false; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | return true; | ||
85 | } | ||
86 | |||
87 | void ProgramChain::emergencyShutdown() | ||
88 | { | ||
89 | int nLen = lLink.getSize(); | ||
90 | for( int j = 0; j < nLen; j++ ) | ||
91 | { | ||
92 | ((ProgramLink *)lLink[j])->deInit(); | ||
93 | delete (ProgramLink *)lLink[j]; | ||
94 | } | ||
95 | lLink.empty(); | ||
96 | } | ||
97 | |||
98 | LinkMessage *ProgramChain::broadcastIRM( LinkMessage *pMsgOut, ProgramLink *pSender ) | ||
99 | { | ||
100 | int nLen = lLink.getSize(); | ||
101 | for( int j = 0; j < nLen; j++ ) | ||
102 | { | ||
103 | LinkMessage *pMsg = ((ProgramLink *)lLink[j])->processIRM( pMsgOut ); | ||
104 | if( pMsg != NULL ) | ||
105 | { | ||
106 | delete pMsgOut; | ||
107 | return pMsg; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | delete pMsgOut; | ||
112 | return NULL; | ||
113 | } | ||