summaryrefslogtreecommitdiff
path: root/comm/MsgStream.h
blob: 154980b4332dff569c7f17d4ec41eee836591442 (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
/*
 *	Ivy League
 *
 *	Message streams
 *
 *	Copyright 1990-2000
 *	Laboratoire de Recherche en Informatique (LRI)
 *	Centre d'Etudes de la Navigation Aerienne (CENA)
 *
 *	original code by Michel Beaudouin-Lafon,
 *	modified by Stephane Chatty
 *
 *	$Id$
 *
 */

#ifndef MsgStream_H_
#define MsgStream_H_

#include "BufStream.h"
class IvlMessage;

class IvlMsgStream : public IvlBufStream {
protected:
enum	STATE		{ WAITING, GOT_TYPE, GOT_LENGTH, DONE};
enum	TYPE		{ MSG = 1, ASK, ANS, SYNC, ASYNC, OK };
	STATE		State;
	bool		BufferedMessages;
	IvlMsgBuffer	Buffered;
	bool		WaitingReply;
	int		InLength;
	byte		InType;

	IvlMessage*		Process (IvlMsgBuffer&, bool);
		IvlMsgStream (const IvlMsgStream&);
	void	WriteMsg (IvlMessage&);
	bool	ReadMsg (IvlMessage&);

public:
		IvlMsgStream (IvlAddress* = 0, IvlAddress* = 0);
		~IvlMsgStream ();

	void		HandleRead ();
virtual	IvlMessage*	DecodeMessage (IvlMsgBuffer&);
virtual	IvlMessage*	DecodeAnswer (IvlMsgBuffer&);
	void		Send (IvlMessage&, bool = false);
	IvlMessage*	Ask (IvlMessage&);
	void		Reply (IvlMessage&);
	void		Send (IvlMsgBuffer&, bool = false);
};

#endif /* MsgStream_H_ */