aboutsummaryrefslogtreecommitdiff
path: root/src/old/programlink.h
blob: f93edcc98292a69e1150fe54fe651940aa3638af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef PROGRAMLINK_H
#define PROGRAMLINK_H

class ProgramLink;
#include "queue.h"
#include "linkmessage.h"
#include "programchain.h"

/**
 * Program Link is the base class for any object that will be a piece of the
 * main program chain loop.
 *@author Mike Buland
 */
class ProgramLink
{
friend class ProgramChain;
public:
	/**
	 * Construct a program link.
	 */
	ProgramLink();

	/**
	 * Deconstruct.
	 */
	virtual ~ProgramLink();

	/**
	 * Initialization code required for a link that wasn't performed in the
	 * constructor.
	 *@returns true if initialization was successful.  A false value will halt
	 * the chain.
	 */
	virtual bool init()=0;

	/**
	 * DeInitialization code that should happen, but doesn't belong in the
	 * destructor.
	 *@returns true means everything worked, false means failure, but is
	 * meaningless.
	 */
	virtual bool deInit()=0;

	/**
	 * Executed once per link per chain pass.  Contains the guts of the program.
	 *@returns true if everything went well.  A false value will halt the chain.
	 */
	virtual bool timeSlice()=0;

	/**
	 * This must be handled in order to process Instant Response Messages.
     * This function should return null on all messages that it doesn't
     * understand how to handle, and construct new messages to return to sender
	 * in the cases where it does understand.
	 *@param pMsgIn The message that must be processed.
	 *@returns Either a new message in cases where a response is required,
	 * or null if nothing needs to be done by this link.
	 */
	virtual LinkMessage *processIRM( LinkMessage *pMsgIn ) = 0;

	/**
	 * Broadcast a LinkMessage to all other links in the system.  Each other
	 * link will get a call of their processIRM function.  If the message gets
	 * a response then you will regain control immediately, otherwise the system
	 * will give all other Links a chance to respond before returning NULL.
	 *@param pMsgOut The message to broadcast.
	 *@returns The message response, or NULL if no Link understood your message.
	 */
	LinkMessage *sendIRM( LinkMessage *pMsgOut );

private:
	/**
	 * Set which chain we're assosiated with.  This is how IRM messages make
	 * it out to the rest of the world.
	 *@param pNewChain A pointer to the containing program chain.
	 */
	void setChain( class ProgramChain *pNewChain );

	/**
	 * The pointer to the containing chain.
	 */
	class ProgramChain *pChain;
/*
	void postMessage( LinkMessage *pMsg, int nLvl );
	LinkMessage *getMessage( int nLvl );

	enum
	{
		msgToChain,
		msgToLink
	};

private:
	Queue qMsgToChain;
	Queue qMsgToLink;
*/
};

#endif