From 421a701c93c6bd8afda7285b670ba3f264b10128 Mon Sep 17 00:00:00 2001 From: chatty Date: Tue, 28 Nov 2000 17:07:43 +0000 Subject: Added class UchMultiplexer --- comm/Multiplexer.h | 66 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 27 deletions(-) (limited to 'comm') diff --git a/comm/Multiplexer.h b/comm/Multiplexer.h index b89344b..ee52c91 100644 --- a/comm/Multiplexer.h +++ b/comm/Multiplexer.h @@ -12,10 +12,12 @@ * $CurLog$ */ -#ifndef Multiplexer_H_ -#define Multiplexer_H_ +#ifndef UchMultiplexer_H_ +#define UchMultiplexer_H_ -#include "Channel.h" +//#include "dnn/Multiplexer.h" +#include "Loop.h" +#include "../UCH/Channel.h" #include #include "ccu/Timer.h" @@ -25,80 +27,90 @@ extern char* StrReprBuf; // Because of the coercion defined for FILDES -> int, // most arguments of type ints can be FILDES, UchChannel, ... // An array of pointers to channels is kept in the object; -// we use smart pointers to handle deletion cleanly. // The masks for reading/writing are kept consistent with the IOMode of // the channels, as long as it is not changed by a direct access to the channel // operator[] returns a pointer and cannot be used as an lhs of an assignment. // -enum MPX_RES { isMpxEmpty, isMpxTerminated, isMpxError, isMpxAborted }; +// WARNING: when the Multiplexer is deleted, the Channels it still +// has in its channel set are not Removed; instead UchChannel::Removed +// is called -class UchBaseMultiplexer : public CcuSmartData { +typedef DnnMpxHook UchMpxHook; + +class UchBaseMultiplexer : public DnnBaseMultiplexer { friend class UchBaseTimeOut; friend class UchBaseSignalHandler; - +friend class UchChannel; protected: - pUchChannel* Channels; + bool Add (UchChannel*); + bool Remove (int); + + UchChannel** Channels; CcuTimerSet Timers; short ReadCount; short WriteCount; short SelectCount; - bool Looping; - bool SigFired; + bool SigFired; + int* NbSignals; UchBaseSignalHandler** Handlers; - int* NbSignals; void HandleSignal (UchBaseSignalHandler&); void HandleDeferredSignals (); inline CcuTimerSet* GetTimerSet () { return &Timers; } -virtual void SetMasks (int, IOMODE); +virtual void SetMasks (int, IOMODE); virtual void SetTimeOut (Millisecond) = 0; virtual void SuppressTimeOut () = 0; virtual void AddSignalHook (); -virtual MPX_RES Loop () = 0; public: UchBaseMultiplexer (); ~UchBaseMultiplexer (); -inline pUchChannel operator [] (int fd) { if (fd < 0) return pUchChannel (0); else return Channels [fd]; } - void Add (UchChannel*); -inline void Add (const UchChannel& ch) { Add (ch.Copy ()); } - void Remove (int); + UchChannel* operator [] (int); + void RemoveAll (); void SetMode (int, IOMODE); MPX_RES Run (); + +#if 0 void Abort (); void Close (); -}; +#endif -PointerClass (pUchBaseMultiplexer, UchBaseMultiplexer) +}; class UchMultiplexer : public UchBaseMultiplexer { protected: - fd_set ReadMask; - fd_set WriteMask; - fd_set SelectMask; + fd_set ReadMask; + fd_set WriteMask; + fd_set SelectMask; + CcuList Hooks; + CcuList FinalHooks; + bool Looping; Millisecond TimeOut; - int fd0; // used by HandleSelect and LoopScan void SetMasks (int, IOMODE); void SetTimeOut (Millisecond); void SuppressTimeOut (); MPX_RES Loop (); - + void ExecHooks (bool = false); public: UchMultiplexer (); ~UchMultiplexer (); - bool HandleSelect (); - int Scan (bool nointr = true, bool poll = false); MPX_RES LoopScan (bool nointr = true); -inline void LoopEnd () { Looping = false; } + void Stop (); char* StrRepr (char* = StrReprBuf); + void AddHook (DnnMpxHook*, bool = false); + void RemoveHook (DnnMpxHook*, bool = false); + void AddFinalHook (DnnMpxHook*); + void RemoveFinalHook (DnnMpxHook*); }; #endif /* Multiplexer_H_ */ + + -- cgit v1.1