summaryrefslogtreecommitdiff
path: root/comm/MsgStream.h
blob: 7660ae86255322de52bc4ef5e7f30de13e5a56dd (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 UchMessage;

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

	UchMessage*		Process (UchMsgBuffer&, bool);
		UchMsgStream (const UchMsgStream&);
	void	WriteMsg (UchMessage&);
	bool	ReadMsg (UchMessage&);

public:
		UchMsgStream (UchAddress* = 0, UchAddress* = 0);
		~UchMsgStream ();

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

#endif /* MsgStream_H_ */