/* * The Unix Channel * * by Michel Beaudouin-Lafon * * Copyright 1990-1993 * Laboratoire de Recherche en Informatique (LRI) * * UchMessage streams * * $Id$ * $CurLog$ */ #ifndef MsgStream_H_ #define MsgStream_H_ #include "Stream.h" #include "ccu/SmartPointer.h" #include "MsgBuffer.h" class UchMessage; class UchMsgStream : public UchStream { private: protected: UchMsgBuffer InBuffer; int InSize; UchMsgBuffer OutBuffer; int OutSize; enum STATE { WAITING, GOT_TYPE, GOT_LENGTH, DONE}; enum TYPE { MSG = 1, ASK, ANS, SYNC, ASYNC, OK }; STATE State; bool BufferedMessages; UchMsgBuffer Buffered; bool WaitingForAnswer; bool WaitingReply; int InLength; byte InType; bool Sync; void ProcessInput (UchMsgBuffer&, bool); int ReadInput (); public: UchMsgStream (); UchMsgStream (const UchMsgStream&); UchMsgStream (UchAddress*, UchAddress*); ~UchMsgStream (); void InputBuffer (int min, int grow, int max); void OutputBuffer (int min, int grow, int max); inline void FlushSize (int n) { OutSize = n; } UchChannel* Copy () const; void HandleRead (); void HandleWrite (); bool HandleSelect (); inline bool GetSyncMode () { return Sync; } inline void SetSyncMode (bool s) { Sync = s; Flush (); } virtual bool NewMessage (UchMsgBuffer&, bool); virtual void* ConvertAnswer (UchMsgBuffer&); virtual void Delete (); void Send (UchMessage&, bool = FALSE); void* Ask (UchMessage&); void Reply (UchMessage&); void Flush (); void Send (UchMsgBuffer&, bool = FALSE); }; #endif /* MsgStream_H_ */