/* * The Unix Channel * * by Michel Beaudouin-Lafon * * Copyright 1990-1995 * Laboratoire de Recherche en Informatique (LRI) * * Messages * * $Id$ * $CurLog$ */ #include "cplus_bugs.h" #include "Message.h" #include "MsgStream.h" #include "IOS.h" /*?class UchMessage \typ{UchMessage} 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?*/ UchMessage :: UchMessage () { } /*?nodoc?*/ UchMessage :: ~UchMessage () { } /*? 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{UchMsgBuffer::Append} functions or \fun{operator $<<$}. The default implementation does nothing. ?*/ void UchMessage :: WriteTo (UchIOS&) { } /*? 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{UchMsgBuffer::Get} functions or \fun{operator $>>$}. The default implementation does nothing. ?*/ void UchMessage :: ReadFrom (UchIOS&, 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{UchMessage} this function does nothing and returns true; if \var{ask} is true, it replies immediately with an empty message. ?*/ bool UchMessage :: Activate (UchMsgStream& s, bool ask) { if (ask) { UchMessage dummy; s.Reply (dummy); } return true; }