summaryrefslogtreecommitdiff
path: root/comm/Multiplexer.h
diff options
context:
space:
mode:
authorchatty1993-04-07 11:50:31 +0000
committerchatty1993-04-07 11:50:31 +0000
commitba066c34dde204aa192d03a23a81356374d93731 (patch)
tree39391f6235d2cf8a59a0634ac5ea430cdd21f5d4 /comm/Multiplexer.h
parent05ab076e1c2a9ca16472f9a6b47b8d22914b3783 (diff)
downloadivy-league-ba066c34dde204aa192d03a23a81356374d93731.zip
ivy-league-ba066c34dde204aa192d03a23a81356374d93731.tar.gz
ivy-league-ba066c34dde204aa192d03a23a81356374d93731.tar.bz2
ivy-league-ba066c34dde204aa192d03a23a81356374d93731.tar.xz
Initial revision
Diffstat (limited to 'comm/Multiplexer.h')
-rw-r--r--comm/Multiplexer.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/comm/Multiplexer.h b/comm/Multiplexer.h
new file mode 100644
index 0000000..0c30bfd
--- /dev/null
+++ b/comm/Multiplexer.h
@@ -0,0 +1,83 @@
+/*
+ * The Unix Channel
+ *
+ * by Michel Beaudouin-Lafon
+ *
+ * Copyright 1990-1993
+ * Laboratoire de Recherche en Informatique (LRI)
+ *
+ * Channel sets, or multiplexers
+ *
+ * $Id$
+ * $CurLog$
+ */
+
+#ifndef Multiplexer_H_
+#define Multiplexer_H_
+
+#include "Channel.h"
+#include <sys/types.h>
+#include "ccu/Timer.h"
+
+extern char* StrReprBuf;
+
+// This class defines channel sets for multiplexing i/o
+// 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.
+//
+class UchMultiplexer : public CcuSmartData {
+friend class UchBaseTimeOut;
+
+protected:
+ pUchChannel* Channels;
+ CcuTimerSet Timers;
+ fd_set ReadMask;
+ fd_set WriteMask;
+ fd_set SelectMask;
+ short ReadCount;
+ short WriteCount;
+ short SelectCount;
+ bool Looping;
+ Millisecond TimeOut;
+ int fd0; // used by HandleSelect and LoopScan
+
+ void SetMasks (int, IOMODE);
+inline CcuTimerSet* GetTimerSet () { return &Timers; }
+inline void SetTimeOut (Millisecond t) { TimeOut = t; }
+inline void SuppressTimeOut () {TimeOut = -1; }
+
+public:
+ UchMultiplexer ();
+ ~UchMultiplexer ();
+
+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);
+ void RemoveAll ();
+ void SetMode (int, IOMODE);
+
+ bool HandleSelect ();
+virtual int Scan (bool nointr = TRUE, bool poll = FALSE);
+virtual int LoopScan (bool nointr = TRUE);
+inline void LoopEnd () { Looping = FALSE; }
+
+ char* StrRepr (char* = StrReprBuf);
+
+protected:
+/*? public ?*/
+virtual void AddNotify (UchChannel*);
+virtual void RemoveNotify (UchChannel*);
+virtual void SetModeNotify (UchChannel*, IOMODE);
+};
+
+PointerClass (pUchMultiplexer, UchMultiplexer)
+
+#endif /* Multiplexer_H_ */
+