aboutsummaryrefslogtreecommitdiff
path: root/src/programlink.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/programlink.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/programlink.h b/src/programlink.h
new file mode 100644
index 0000000..7c31a18
--- /dev/null
+++ b/src/programlink.h
@@ -0,0 +1,100 @@
1#ifndef PROGRAMLINK_H
2#define PROGRAMLINK_H
3
4#include "bu/linkmessage.h"
5#include "bu/programchain.h"
6
7namespace Bu
8{
9 /**
10 * Program Link is the base class for any object that will be a piece of the
11 * main program chain loop.
12 *@author Mike Buland
13 */
14 class ProgramLink
15 {
16 friend class Bu::ProgramChain;
17 public:
18 /**
19 * Construct a program link.
20 */
21 ProgramLink();
22
23 /**
24 * Deconstruct.
25 */
26 virtual ~ProgramLink();
27
28 /**
29 * Initialization code required for a link that wasn't performed in the
30 * constructor.
31 *@returns true if initialization was successful. A false value will halt
32 * the chain.
33 */
34 virtual bool init()=0;
35
36 /**
37 * DeInitialization code that should happen, but doesn't belong in the
38 * destructor.
39 *@returns true means everything worked, false means failure, but is
40 * meaningless.
41 */
42 virtual bool deInit()=0;
43
44 /**
45 * Executed once per link per chain pass. Contains the guts of the program.
46 *@returns true if everything went well. A false value will halt the chain.
47 */
48 virtual bool timeSlice()=0;
49
50 /**
51 * This must be handled in order to process Instant Response Messages.
52 * This function should return null on all messages that it doesn't
53 * understand how to handle, and construct new messages to return to sender
54 * in the cases where it does understand.
55 *@param pMsgIn The message that must be processed.
56 *@returns Either a new message in cases where a response is required,
57 * or null if nothing needs to be done by this link.
58 */
59 virtual LinkMessage *processIRM( LinkMessage *pMsgIn ) = 0;
60
61 /**
62 * Broadcast a LinkMessage to all other links in the system. Each other
63 * link will get a call of their processIRM function. If the message gets
64 * a response then you will regain control immediately, otherwise the system
65 * will give all other Links a chance to respond before returning NULL.
66 *@param pMsgOut The message to broadcast.
67 *@returns The message response, or NULL if no Link understood your message.
68 */
69 LinkMessage *sendIRM( LinkMessage *pMsgOut );
70
71 private:
72 /**
73 * Set which chain we're assosiated with. This is how IRM messages make
74 * it out to the rest of the world.
75 *@param pNewChain A pointer to the containing program chain.
76 */
77 void setChain( class ProgramChain *pNewChain );
78
79 /**
80 * The pointer to the containing chain.
81 */
82 class ProgramChain *pChain;
83 /*
84 void postMessage( LinkMessage *pMsg, int nLvl );
85 LinkMessage *getMessage( int nLvl );
86
87 enum
88 {
89 msgToChain,
90 msgToLink
91 };
92
93 private:
94 Queue qMsgToChain;
95 Queue qMsgToLink;
96 */
97 };
98}
99
100#endif