diff options
Diffstat (limited to 'src/programchain.h')
-rw-r--r-- | src/programchain.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/programchain.h b/src/programchain.h new file mode 100644 index 0000000..e73d659 --- /dev/null +++ b/src/programchain.h | |||
@@ -0,0 +1,98 @@ | |||
1 | #ifndef PROGRAMCHAIN_H | ||
2 | #define PROGRAMCHAIN_H | ||
3 | |||
4 | #include "bu/list.h" | ||
5 | #include "bu/linkmessage.h" | ||
6 | |||
7 | namespace Bu | ||
8 | { | ||
9 | class ProgramLink; | ||
10 | /** | ||
11 | * The Program Chain links together program "chunks" to more easily facilitate | ||
12 | * a generalized program loop with modular extensions. | ||
13 | *@author Mike Buland | ||
14 | */ | ||
15 | class ProgramChain | ||
16 | { | ||
17 | public: | ||
18 | /** | ||
19 | * Construct an empty chain. | ||
20 | */ | ||
21 | ProgramChain(); | ||
22 | |||
23 | /** | ||
24 | * Destroy your chain. | ||
25 | */ | ||
26 | virtual ~ProgramChain(); | ||
27 | |||
28 | /** | ||
29 | * Adds a link to the end of the chain. | ||
30 | *@param pLink A pointer to the link to add to the chain. | ||
31 | *@returns True if adding the link was successful, otherwise false | ||
32 | *@author Mike Buland | ||
33 | */ | ||
34 | bool addLink( Bu::ProgramLink *pLink ); | ||
35 | |||
36 | /** | ||
37 | * Gets a link by name. | ||
38 | *@param lpName The name of the link you're looking for. Every link has a | ||
39 | * name, apparently. | ||
40 | *@returns A pointer to the specified ProgramLink, or NULL if none were | ||
41 | * found matching your criteria. | ||
42 | *@author Mike Buland | ||
43 | */ | ||
44 | class ProgramLink *getLink( const char *lpName ); | ||
45 | |||
46 | /** | ||
47 | * Gets the very first link in the chain. | ||
48 | *@returns A pointer to the first link in the chain. | ||
49 | *@author Mike Buland | ||
50 | */ | ||
51 | class ProgramLink *getBaseLink(); | ||
52 | |||
53 | /** | ||
54 | * Runs through the chain once. Useful if you want to have more control | ||
55 | * over the operation of the chain. | ||
56 | *@returns true if every link returned true. If at least one link returns | ||
57 | * false, then returns false. | ||
58 | *@author Mike Buland | ||
59 | */ | ||
60 | bool execChainOnce(); | ||
61 | |||
62 | /** | ||
63 | * Enters the master chain loop, looping over the entire chain and | ||
64 | * executing every link's TimeSlice routine in order, over and over, until | ||
65 | * a link returns a false value. | ||
66 | *@returns False, always. It returns true unless a link returned false, | ||
67 | * but loops until a link does return false. | ||
68 | *@author Mike Buland | ||
69 | **/ | ||
70 | bool enterChainLoop(); | ||
71 | |||
72 | /** | ||
73 | * Broadcasts an Immediate Response Message to all active links, save the | ||
74 | * sender. Whatever link first responds with a non-null response message | ||
75 | * will have it's messages sent back to the broadcasting link as the returns | ||
76 | * of this function call. Therefore it is very important that all message | ||
77 | * processing code is handled in a fairly timely fasion. | ||
78 | *@param pMsgOut The message to broadcast in hopes of a response. | ||
79 | *@param pSender The message that sent out the message and doesn't want to | ||
80 | * receive it's own message. This should always just be "this". | ||
81 | *@returns The message that was returned by the first link to return a | ||
82 | * non-null response. If all messages return null responses then this also | ||
83 | * returns null. Please note that whoever calls this will be responsible | ||
84 | * for deleting the message returned by it, if non-null. | ||
85 | */ | ||
86 | class LinkMessage *broadcastIRM( LinkMessage *pMsgOut, ProgramLink *pSender ); | ||
87 | |||
88 | private: | ||
89 | /** | ||
90 | * Shuts down all operation no matter what point in the operation we were. | ||
91 | */ | ||
92 | void emergencyShutdown(); | ||
93 | Bu::List<Bu::ProgramLink *> lLink; /**< The linked list that contains all of the links. */ | ||
94 | }; | ||
95 | } | ||
96 | |||
97 | |||
98 | #endif | ||