00001 // synchconsole.h 00002 // Data structures for synchronized access to the keyboard 00003 // and console display devices. 00004 // 00005 // NOTE: this abstraction is not completely implemented. 00006 // 00007 // Copyright (c) 1992-1996 The Regents of the University of California. 00008 // All rights reserved. See copyright.h for copyright notice and limitation 00009 // of liability and disclaimer of warranty provisions. 00010 00011 #ifndef SYNCHCONSOLE_H 00012 #define SYNCHCONSOLE_H 00013 00014 #include "copyright.h" 00015 #include "utility.h" 00016 #include "callback.h" 00017 #include "console.h" 00018 #include "synch.h" 00019 00020 // The following two classes define synchronized input and output to 00021 // a console device 00022 00023 class SynchConsoleInput : public CallBackObj { 00024 public: 00025 SynchConsoleInput(char *inputFile); // Initialize the console device 00026 ~SynchConsoleInput(); // Deallocate console device 00027 00028 char GetChar(); // Read a character, waiting if necessary 00029 00030 private: 00031 ConsoleInput *consoleInput; // the hardware keyboard 00032 Lock *lock; // only one reader at a time 00033 Semaphore *waitFor; // wait for callBack 00034 00035 void CallBack(); // called when a keystroke is available 00036 }; 00037 00038 class SynchConsoleOutput : public CallBackObj { 00039 public: 00040 SynchConsoleOutput(char *outputFile); // Initialize the console device 00041 ~SynchConsoleOutput(); 00042 00043 void PutChar(char ch); // Write a character, waiting if necessary 00044 00045 private: 00046 ConsoleOutput *consoleOutput;// the hardware display 00047 Lock *lock; // only one writer at a time 00048 Semaphore *waitFor; // wait for callBack 00049 00050 void CallBack(); // called when more data can be written 00051 }; 00052 00053 #endif // SYNCHCONSOLE_H