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