File: MessageBuffer.h

package info (click to toggle)
abyss 2.3.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,284 kB
  • sloc: cpp: 78,182; ansic: 6,512; makefile: 2,252; perl: 672; sh: 509; haskell: 412; python: 4
file content (83 lines) | stat: -rw-r--r-- 2,104 bytes parent folder | download | duplicates (6)
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
#ifndef MESSAGE_BUFFER_H
#define MESSAGE_BUFFER_H 1

class MessageBuffer;

#include "CommLayer.h"
#include "Messages.h"
#include <vector>

typedef std::vector<Message*> MsgBuffer;
typedef std::vector<MsgBuffer> MessageQueues;

enum SendMode
{
	SM_BUFFERED,
	SM_IMMEDIATE
};

/** A buffer of Message. */
class MessageBuffer : public CommLayer
{
	public:
		typedef SequenceCollectionHash Graph;
		typedef graph_traits<Graph>::vertex_descriptor V;
		typedef Graph::Symbol Symbol;
		typedef Graph::SymbolSet SymbolSet;
		typedef Graph::SymbolSetPair SymbolSetPair;

		MessageBuffer();

		void sendCheckPointMessage(int argument = 0)
		{
			assert(transmitBufferEmpty());
			CommLayer::sendCheckPointMessage(argument);
		}

		void sendControlMessage(APControl command, int argument = 0)
		{
			assert(transmitBufferEmpty());
			CommLayer::sendControlMessage(command, argument);
		}

		void sendControlMessageToNode(int dest,
				APControl command, int argument = 0)
		{
			assert(transmitBufferEmpty());
			CommLayer::sendControlMessageToNode(dest,
					command, argument);
		}

		void sendSeqAddMessage(int nodeID, const V& seq);
		void sendSeqRemoveMessage(int nodeID, const V& seq);
		void sendSetFlagMessage(int nodeID,
				const V& seq, SeqFlag flag);
		void sendRemoveExtension(int nodeID,
				const V& seq, extDirection dir, SymbolSet ext);
		void sendSeqDataRequest(int nodeID,
				IDType group, IDType id, const V& seq);
		void sendSeqDataResponse(int nodeID,
				IDType group, IDType id, const V& seq,
				SymbolSetPair extRec, int multiplicity);
		void sendSetBaseExtension(int nodeID,
				const V& seq, extDirection dir, Symbol base);

		void flush();
		void queueMessage
			(int nodeID, Message* message, SendMode mode);

		// clear out a queue
		void clearQueue(int nodeID);
		bool transmitBufferEmpty() const;

		// check if a queue is full, if so, send the messages if the
		// immediate mode flag is set, send even if the queue is not
		// full.
		void checkQueueForSend(int nodeID, SendMode mode);

	private:
		static const size_t MAX_MESSAGES = 100;
		MessageQueues m_msgQueues;
};

#endif