From 618df147e19d12075f351930d6bf85e9b171c99c Mon Sep 17 00:00:00 2001 From: chatty Date: Tue, 27 Jul 1993 14:02:13 +0000 Subject: Initial revision --- comm/TkMultiplexer.cc | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 comm/TkMultiplexer.cc (limited to 'comm/TkMultiplexer.cc') 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 + +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; +} -- cgit v1.1