summaryrefslogtreecommitdiff
path: root/comm/MsgStream.h
blob: d3e613e7ee33fb2fa002f5f020a0926f7ff73c7e (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
/*
 *	The Unix Channel
 *
 *	by Michel Beaudouin-Lafon
 *
 *	Copyright 1990-1997
 *	Laboratoire de Recherche en Informatique (LRI)
 *
 *	Message streams
 *
 *	$Id$
 *	$CurLog$
 */

#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_ */