summaryrefslogtreecommitdiff
path: root/comm/Message.cc
blob: 8933507ed708c9a7326868277eca92bfb70bc881 (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
/*
 *	Ivy League
 *
 *	Messages
 *
 *	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 and Stephane Sire
 *
 *	$Id$
 *
 */

#include "cplus_bugs.h"

#include "Message.h"
#include "MsgStream.h"
#include "IOS.h"

/*?class IvlMessage
\typ{IvlMessage} is the abstract base class for messages.
Each subclass must redefine the virtual functions \fun{WriteTo} and \fun{ReadFrom},
so that messages can be added to and retrieved from buffers.
?*/

/*?nodoc?*/
IvlMessage :: IvlMessage ()
{
}

/*?nodoc?*/
IvlMessage :: ~IvlMessage ()
{
}

/*?
This virtual function must write a message into a buffer.
Usually, the implementation of this function in a derived class starts by calling
the same function of its base class, because a derived class inherits the fields
of its base class and adds its own fields.
Data is usually appended to the buffer by the \fun{IvlMsgBuffer::Append}
functions or \fun{operator $<<$}.
The default implementation does nothing.
?*/
void
IvlMessage :: WriteTo (IvlIOS&)
{
}

/*?
This virtual function must extract data from the buffer to create the message.
At most \var{len} bytes should be read from the buffer.
Usually, the implementation of this function in a derived class starts by calling
the same function of its base class, because a derived class inherits the fields
of its base class and adds its own fields.
Data is usually retrieved from the buffer by the \fun{IvlMsgBuffer::Get}
functions or \fun{operator $>>$}.
The default implementation does nothing.
?*/
void
IvlMessage :: ReadFrom (IvlIOS&, lword)
{
}

/*?
This virtual function must be redefined in derived classes to support the handling of messages
after they have been loaded from a buffer. 
\var{ask} is true if the message was sent with \fun{Ask}.
In this case an answer must be sent back with \fun{Reply}.
Messages can be sent before replying; they will be buffered by the receiver for later processing.
But you cannot use \fun{Ask} before replying.
In the class \typ{IvlMessage} this function does nothing and returns true;
if \var{ask} is true, it replies immediately with an empty message.
?*/
bool
IvlMessage :: Activate (IvlMsgStream& s, bool ask)
{
	if (ask) {
		IvlMessage dummy;
		s.Reply (dummy);
	}
	return true;
}