diff options
author | chatty | 1993-07-27 14:02:13 +0000 |
---|---|---|
committer | chatty | 1993-07-27 14:02:13 +0000 |
commit | 618df147e19d12075f351930d6bf85e9b171c99c (patch) | |
tree | 03b308ed0d9dca857732ffeba66d22805bd1ca0c /comm/TkMultiplexer.cc | |
parent | 9b053fc3871b44405f558b84d031346e46d734f1 (diff) | |
download | ivy-league-618df147e19d12075f351930d6bf85e9b171c99c.zip ivy-league-618df147e19d12075f351930d6bf85e9b171c99c.tar.gz ivy-league-618df147e19d12075f351930d6bf85e9b171c99c.tar.bz2 ivy-league-618df147e19d12075f351930d6bf85e9b171c99c.tar.xz |
Initial revision
Diffstat (limited to 'comm/TkMultiplexer.cc')
-rw-r--r-- | comm/TkMultiplexer.cc | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/comm/TkMultiplexer.cc b/comm/TkMultiplexer.cc new file mode 100644 index 0000000..3272851 --- /dev/null +++ b/comm/TkMultiplexer.cc @@ -0,0 +1,117 @@ +/* + * The Unix Channel + * + * by Michel Beaudouin-Lafon and Stephane Chatty + * + * Copyright 1990-1993 + * Laboratoire de Recherche en Informatique (LRI) + * Centre d'Etudes de la Navigation Aerienne + * + * Tk-based multiplexers + * + * $Id$ + * $CurLog$ + */ + +#include "TkMultiplexer.h" +#include "error.h" + +#include <memory.h> + +static void +ioHandler (ClientData client_data, int mask) +{ + UchChannel* ch = (UchChannel*) client_data; + if (mask & TK_WRITABLE) + ch->HandleWrite (); + if (mask & TK_READABLE) + ch->HandleRead (); +} + +UchTkMultiplexer :: UchTkMultiplexer () +: UchBaseMultiplexer () +{ + memset (Active, 0, NFILE * sizeof (bool)); +} + + +UchTkMultiplexer :: ~UchTkMultiplexer () +{ +} + +void +UchTkMultiplexer :: SetMasks (int fd, IOMODE mode) +{ + UchChannel* ch = Channels [fd]; + if (!ch) + return; + + /* remove if already there */ + if (Active [fd]) { + Tk_DeleteFileHandler (fd); + ReadCount--; + } + + /* add channel */ + int mask = 0; + + if (mode & IORead) + mask |= TK_READABLE; + + if (mode & IOWrite) + mask |= TK_WRITABLE; + + if (mode & IOSelect) + Error (ErrWarn, "AddChannel", "select condition ignored"); + + if (mask) { + Tk_CreateFileHandler (fd, mask, ioHandler, (ClientData) ch); + ReadCount++; + Active [fd] = TRUE; + } +} + +void +UchTkMultiplexer :: FireTimers (ClientData mpx) +{ + CcuCoreTimer::Fire (((UchTkMultiplexer*) mpx)->GetTimerSet ()); +} + +void +UchTkMultiplexer :: SetTimeOut (Millisecond delay) +{ + TimeOut = Tk_CreateTimerHandler (int (delay), &UchTkMultiplexer::FireTimers, (ClientData) this); +} + +void +UchTkMultiplexer :: SuppressTimeOut () +{ + Tk_DeleteTimerHandler (TimeOut); + TimeOut = 0; +} + +void +UchTkMultiplexer :: FireSignals (ClientData mpx) +{ + ((UchTkMultiplexer*) mpx)->HandleDeferredSignals (); +} + +void +UchTkMultiplexer :: AddSignalHook () +{ + Tk_DoWhenIdle (&UchTkMultiplexer::FireSignals, (ClientData) this); +} + +MPX_RES +UchTkMultiplexer :: Loop () +{ + Looping = TRUE; + + Tk_MainLoop (); + + if (Looping) { + Looping = FALSE; + return isMpxEmpty; + } + return isMpxTerminated; +} |