summaryrefslogtreecommitdiff
path: root/comm/MsgStream.cc
diff options
context:
space:
mode:
Diffstat (limited to 'comm/MsgStream.cc')
-rw-r--r--comm/MsgStream.cc97
1 files changed, 47 insertions, 50 deletions
diff --git a/comm/MsgStream.cc b/comm/MsgStream.cc
index 3a84eba..52d8623 100644
--- a/comm/MsgStream.cc
+++ b/comm/MsgStream.cc
@@ -16,9 +16,8 @@
#include "Message.h"
#include "error.h"
-
-/*?class UchMsgStream
-An object of class \typ{UchMsgStream} is a stream that sends and receives messages:
+/*?class IvlMsgStream
+An object of class \typ{IvlMsgStream} is a stream that sends and receives messages:
we call it a message stream.
Messages are sent with the function \fun{Send}.
@@ -26,7 +25,7 @@ Output messages are normally buffered to increase performance, but synchronous m
The output buffer can be flushed by the application, or by the stream itself if needed
(for instance when the buffer is full, or when a synchronous communication is needed).
-Incoming messages are handled by the virtual function \fun{HandleRead} of class \typ{UchChannel}:
+Incoming messages are handled by the virtual function \fun{HandleRead} of class \typ{IvlChannel}:
it is redefined so that incoming bytes are packed into messages.
When a full message is available, \fun{HandleRead} calls the virtual
function \fun{DecodeMessage} that instantiates a message, then calls the virtual function \fun{Activate} for that
@@ -57,7 +56,7 @@ The output mode can be switched to a synchronous mode where each message is sent
% This is mainly useful for debugging purposes.
\medskip
-To use a message stream, a program needs to derive the class \typ{UchMsgStream}
+To use a message stream, a program needs to derive the class \typ{IvlMsgStream}
in order to redefine the virtual functions \fun{DecodeMessage} and \fun{DecodeAnswer}.
\fun{DecodeMessage} treats the incoming message, and will probably call \fun{Send} and \fun{Ask}.
The top level of the program needs just call \fun{HandleRead} in a forever loop.
@@ -65,13 +64,13 @@ The top level of the program needs just call \fun{HandleRead} in a forever loop.
Most of the time, a program will use several message streams
(for instance to manage several clients).
In this case a channel set is the best way to implement the application:
-the definitions in the class \typ{UchMsgStream} of the functions
+the definitions in the class \typ{IvlMsgStream} of the functions
\fun{HandleRead}, \fun{HandleWrite} and \fun{HandleSelect} make it easy
-to use this class in combination with the class \typ{UchMultiplexer}.
+to use this class in combination with the class \typ{IvlMultiplexer}.
The virtual function \fun{HandeWrite} of channels is redefined to flush the output buffer.
The virtual function \fun{HandleSelect} of channels is redefined to handle the incoming messages
that were buffered while waiting for an answer.
-As for the single stream situation, you need just derive the class \fun{UchMsgStream} to
+As for the single stream situation, you need just derive the class \fun{IvlMsgStream} to
redefine the virtual functions \fun{DecodeMessage} and \fun{DecodeAnswer}.
?*/
@@ -79,10 +78,10 @@ redefine the virtual functions \fun{DecodeMessage} and \fun{DecodeAnswer}.
// ---- no locked sync mode ...
/*?
-These constructors are similar to those of class \typ{UchSocket}.
+These constructors are similar to those of class \typ{IvlSocket}.
?*/
-UchMsgStream :: UchMsgStream (UchAddress* bindTo, UchAddress* connectTo)
-: UchBufStream (bindTo, connectTo),
+IvlMsgStream :: IvlMsgStream (IvlAddress* bindTo, IvlAddress* connectTo)
+: IvlBufStream (bindTo, connectTo),
Buffered ()
{
State = WAITING;
@@ -92,27 +91,26 @@ UchMsgStream :: UchMsgStream (UchAddress* bindTo, UchAddress* connectTo)
// *** this copy constructor might be automatically generated
/*?nodoc?*/
-UchMsgStream :: UchMsgStream (const UchMsgStream& ms)
-: UchBufStream (ms), Buffered (*(UchMsgBuffer*)&ms.Buffered)
+IvlMsgStream :: IvlMsgStream (const IvlMsgStream& ms)
+: IvlBufStream (ms), Buffered (*(IvlMsgBuffer*)&ms.Buffered)
{
State = ms.State;
BufferedMessages = ms.BufferedMessages;
WaitingReply = ms.WaitingReply;
}
-
/*?nodoc?*/
-UchMsgStream :: ~UchMsgStream ()
+IvlMsgStream :: ~IvlMsgStream ()
{
Buffered.Clear ();
}
#if 0
/*?nodoc?*/
-UchChannel*
-UchMsgStream :: Copy () const
+IvlChannel*
+IvlMsgStream :: Copy () const
{
- return new UchMsgStream (*this);
+ return new IvlMsgStream (*this);
}
#endif
@@ -132,8 +130,8 @@ UchMsgStream :: Copy () const
/*!
Return a message when it's been fully read.
!*/
-UchMessage*
-UchMsgStream :: Process (UchMsgBuffer& buf, bool waitAnswer)
+IvlMessage*
+IvlMsgStream :: Process (IvlMsgBuffer& buf, bool waitAnswer)
{
for (;;) {
switch (State) {
@@ -175,8 +173,8 @@ UchMsgStream :: Process (UchMsgBuffer& buf, bool waitAnswer)
case DONE:
if (waitAnswer) {
if (InType == ANS) {
- UchMsgBuffer fake (buf, InLength);
- UchMessage* ans = DecodeAnswer (fake);
+ IvlMsgBuffer fake (buf, InLength);
+ IvlMessage* ans = DecodeAnswer (fake);
buf.Flush (InLength);
State = WAITING;
return ans;
@@ -189,8 +187,8 @@ UchMsgStream :: Process (UchMsgBuffer& buf, bool waitAnswer)
} else {
if (InType == MSG || InType == ASK) {
// pass a fake buffer to the handler
- UchMsgBuffer fake (buf, InLength);
- UchMessage* msg = DecodeMessage (fake);
+ IvlMsgBuffer fake (buf, InLength);
+ IvlMessage* msg = DecodeMessage (fake);
if (! msg || !msg->Activate (*this, WaitingReply))
return 0;
// *** these returns break the assumption that
@@ -209,7 +207,7 @@ UchMsgStream :: Process (UchMsgBuffer& buf, bool waitAnswer)
/*?nodoc?*/
void
-UchMsgStream :: HandleRead ()
+IvlMsgStream :: HandleRead ()
{
if (BufferedMessages) {
Process (Buffered, false);
@@ -224,7 +222,7 @@ UchMsgStream :: HandleRead ()
#if 0
/*?nodoc?*/
bool
-UchMsgStream :: HandleSelect ()
+IvlMsgStream :: HandleSelect ()
{
if (BufferedMessages) {
Process (Buffered, false);
@@ -238,13 +236,13 @@ UchMsgStream :: HandleSelect ()
This virtual function is called whenever a complete message is in the buffer.
The buffer contains exactly one message, so that you can use \com{buf.ReadMsg (msg)}
to extract the message from the buffer.
-\fun{DecodeMessage} must return the extracted message. The default version returns a dummy \typ{UchMessage}.
+\fun{DecodeMessage} must return the extracted message. The default version returns a dummy \typ{IvlMessage}.
If it returns false, it will be called again with the same arguments next time data arrives on this channel.
The function \typ{MyClient}::\fun{DecodeMessage}
may look like:
\begin{ccode}
-UchMessage*
-MyClient :: DecodeMessage (UchMsgBuffer& buffer)
+IvlMessage*
+MyClient :: DecodeMessage (IvlMsgBuffer& buffer)
{
MyRequest* m = 0;
lword type;
@@ -263,10 +261,10 @@ MyClient :: DecodeMessage (UchMsgBuffer& buffer)
}
\end{ccode}
?*/
-UchMessage*
-UchMsgStream :: DecodeMessage (UchMsgBuffer&)
+IvlMessage*
+IvlMsgStream :: DecodeMessage (IvlMsgBuffer&)
{
- return new UchMessage;
+ return new IvlMessage;
}
/*?
@@ -276,7 +274,7 @@ This also happens when the message stream is in synchronous mode,
or if the output buffer has exceeded its flush size (see \fun{FlushSize}).
?*/
void
-UchMsgStream :: Send (UchMessage& msg, bool flush)
+IvlMsgStream :: Send (IvlMessage& msg, bool flush)
{
OutBuffer.WriteByte (MSG);
WriteMsg (msg);
@@ -285,15 +283,15 @@ UchMsgStream :: Send (UchMessage& msg, bool flush)
}
void
-UchMsgStream :: WriteMsg (UchMessage& msg)
+IvlMsgStream :: WriteMsg (IvlMessage& msg)
{
OutBuffer.WriteMsg (msg);
}
bool
-UchMsgStream :: ReadMsg (UchMessage& msg)
+IvlMsgStream :: ReadMsg (IvlMessage& msg)
{
- UchMsgBuffer& buf = BufferedMessages ? Buffered : InBuffer;
+ IvlMsgBuffer& buf = BufferedMessages ? Buffered : InBuffer;
int l = buf.BufLength (); // store current offset in the buffer
lword msglen;
buf >> msglen;
@@ -316,18 +314,18 @@ Send a message and wait for an answer.
Incoming messages that are received while waiting for the answer are kept for later processing.
The answer message is returned by calling the virtual function \fun{DecodeAnswer}.
?*/
-UchMessage*
-UchMsgStream :: Ask (UchMessage& msg)
+IvlMessage*
+IvlMsgStream :: Ask (IvlMessage& msg)
{
if (WaitingReply) {
- ::Error (ErrWarn, "UchMsgStream::Ask", "cannot ask before replying");
+ ::Error (ErrWarn, "IvlMsgStream::Ask", "cannot ask before replying");
return 0;
}
OutBuffer.WriteByte (ASK);
WriteMsg (msg);
Flush ();
- UchMessage* ans = 0;
+ IvlMessage* ans = 0;
do {
if (ReadInput () <= 0)
return 0;
@@ -341,10 +339,10 @@ UchMsgStream :: Ask (UchMessage& msg)
This function must be used instead of \fun{Send} to send a reply to a message sent by \fun{Ask}.
?*/
void
-UchMsgStream :: Reply (UchMessage& msg)
+IvlMsgStream :: Reply (IvlMessage& msg)
{
if (! WaitingReply) {
- ::Error (ErrWarn, "UchMsgStream::Reply", "out of phase reply discarded");
+ ::Error (ErrWarn, "IvlMsgStream::Reply", "out of phase reply discarded");
return;
}
OutBuffer.WriteByte ((byte) ANS);
@@ -353,13 +351,12 @@ UchMsgStream :: Reply (UchMessage& msg)
WaitingReply = false;
}
-
/*?
This function is called by \fun{Ask} when the answer is in the buffer,
in order to convert it into an object usable by the application.
?*/
-UchMessage*
-UchMsgStream :: DecodeAnswer (UchMsgBuffer&)
+IvlMessage*
+IvlMsgStream :: DecodeAnswer (IvlMsgBuffer&)
{
return 0;
}
@@ -368,14 +365,14 @@ UchMsgStream :: DecodeAnswer (UchMsgBuffer&)
Send a buffer containing a message.
If \var{flush} is true, the output buffer will be flushed.
This also happens when the message stream is in synchronous mode,
-or if the output UchMsgBuffer.has exceeded its flush size (see \fun{FlushSize}).
+or if the output IvlMsgBuffer.has exceeded its flush size (see \fun{FlushSize}).
The buffer {\em must} contain a converted message.
This can be used for instance from inside \fun{DecodeMessage} to resend
the incoming message to another client, without having to convert
the buffer to a message.
?*/
void
-UchMsgStream :: Send (UchMsgBuffer& buf, bool flush)
+IvlMsgStream :: Send (IvlMsgBuffer& buf, bool flush)
{
OutBuffer.WriteByte ((byte) MSG);
OutBuffer.WriteBuf (buf.Buffer (), buf.BufLength ());
@@ -390,12 +387,12 @@ in asynchronous mode. By default the flush size is the maximum size of the
output buffer. As a consequence, it is changed by \fun{OutBuffer}.
?*/
void
-UchMsgStream :: FlushSize (int n)
+IvlMsgStream :: FlushSize (int n)
{ }
/*?nextdoc?*/
void
-UchMsgStream :: SetSyncMode (bool s)
+IvlMsgStream :: SetSyncMode (bool s)
{ }
/*?
@@ -406,7 +403,7 @@ because it makes more system calls to transfer data;
however synchronous mode can be useful for debugging applications.
?*/
bool
-UchMsgStream :: GetSyncMode ()
+IvlMsgStream :: GetSyncMode ()
{ }
#endif /* DOC */