Files
ios2024/code/userprog/synchconsole.h
施羿廷 ba9ef819ba HW1
2024-10-04 19:53:08 +00:00

55 lines
1.6 KiB
C++

// synchconsole.h
// Data structures for synchronized access to the keyboard
// and console display devices.
//
// NOTE: this abstraction is not completely implemented.
//
// Copyright (c) 1992-1996 The Regents of the University of California.
// All rights reserved. See copyright.h for copyright notice and limitation
// of liability and disclaimer of warranty provisions.
#ifndef SYNCHCONSOLE_H
#define SYNCHCONSOLE_H
#include "copyright.h"
#include "utility.h"
#include "callback.h"
#include "console.h"
#include "synch.h"
// The following two classes define synchronized input and output to
// a console device
class SynchConsoleInput : public CallBackObj {
public:
SynchConsoleInput(char *inputFile); // Initialize the console device
~SynchConsoleInput(); // Deallocate console device
char GetChar(); // Read a character, waiting if necessary
private:
ConsoleInput *consoleInput; // the hardware keyboard
Lock *lock; // only one reader at a time
Semaphore *waitFor; // wait for callBack
void CallBack(); // called when a keystroke is available
};
class SynchConsoleOutput : public CallBackObj {
public:
SynchConsoleOutput(char *outputFile); // Initialize the console device
~SynchConsoleOutput();
void PutChar(char ch); // Write a character, waiting if necessary
void PutString(char *ch);
private:
ConsoleOutput *consoleOutput;// the hardware display
Lock *lock; // only one writer at a time
Semaphore *waitFor; // wait for callBack
void CallBack(); // called when more data can be written
};
#endif // SYNCHCONSOLE_H