Main Page   Compound List   File List   Compound Members   File Members  

Console Class Reference

#include <console.h>

List of all members.

Public Methods

 Console (char *readFile, char *writeFile, VoidFunctionPtr readAvail, VoidFunctionPtr writeDone, int callArg)
 ~Console ()
void PutChar (char ch)
char GetChar ()
void WriteDone ()
void CheckCharAvail ()

Private Attributes

int readFileNo
int writeFileNo
VoidFunctionPtr writeHandler
VoidFunctionPtr readHandler
int handlerArg
bool putBusy
char incoming


Constructor & Destructor Documentation

Console::Console char *    readFile,
char *    writeFile,
VoidFunctionPtr    readAvail,
VoidFunctionPtr    writeDone,
int    callArg
 

Definition at line 39 of file console.cc.

References ConsoleReadInt, ConsoleReadPoll, ConsoleTime, FALSE, handlerArg, incoming, NULL, OpenForReadWrite, OpenForWrite, putBusy, readFileNo, readHandler, TRUE, VoidFunctionPtr, writeFileNo, and writeHandler.

00041 {
00042     if (readFile == NULL)
00043         readFileNo = 0;                                 // keyboard = stdin
00044     else
00045         readFileNo = OpenForReadWrite(readFile, TRUE);  // should be read-only
00046     if (writeFile == NULL)
00047         writeFileNo = 1;                                // display = stdout
00048     else
00049         writeFileNo = OpenForWrite(writeFile);
00050 
00051     // set up the stuff to emulate asynchronous interrupts
00052     writeHandler = writeDone;
00053     readHandler = readAvail;
00054     handlerArg = callArg;
00055     putBusy = FALSE;
00056     incoming = EOF;
00057 
00058     // start polling for incoming packets
00059     interrupt->Schedule(ConsoleReadPoll, (int)this, ConsoleTime, ConsoleReadInt);
00060 }

Console::~Console  
 

Definition at line 67 of file console.cc.

References Close, readFileNo, and writeFileNo.

00068 {
00069     if (readFileNo != 0)
00070         Close(readFileNo);
00071     if (writeFileNo != 1)
00072         Close(writeFileNo);
00073 }


Member Function Documentation

void Console::CheckCharAvail  
 

Definition at line 87 of file console.cc.

References ConsoleReadInt, ConsoleReadPoll, ConsoleTime, incoming, PollFile, Read, and readFileNo.

Referenced by ConsoleReadPoll.

00088 {
00089     char c;
00090 
00091     // schedule the next time to poll for a packet
00092     interrupt->Schedule(ConsoleReadPoll, (int)this, ConsoleTime, 
00093                         ConsoleReadInt);
00094 
00095     // do nothing if character is already buffered, or none to be read
00096     if ((incoming != EOF) || !PollFile(readFileNo))
00097         return;   
00098 
00099     // otherwise, read character and tell user about it
00100     Read(readFileNo, &c, sizeof(char));
00101     incoming = c ;
00102     stats->numConsoleCharsRead++;
00103     (*readHandler)(handlerArg); 
00104 }

char Console::GetChar  
 

Definition at line 128 of file console.cc.

References incoming.

Referenced by ConsoleTest, and SynchConsole::ReadLine.

00129 {
00130    char ch = incoming;
00131 
00132    incoming = EOF;
00133    return ch;
00134 }

void Console::PutChar char    ch
 

Definition at line 143 of file console.cc.

References ASSERT, ConsoleTime, ConsoleWriteDone, ConsoleWriteInt, FALSE, putBusy, TRUE, WriteFile, and writeFileNo.

Referenced by ConsoleTest, and SynchConsole::WriteLine.

00144 {
00145     ASSERT(putBusy == FALSE);
00146     WriteFile(writeFileNo, &ch, sizeof(char));
00147     putBusy = TRUE;
00148     interrupt->Schedule(ConsoleWriteDone, (int)this, ConsoleTime,
00149                                         ConsoleWriteInt);
00150 }

void Console::WriteDone  
 

Definition at line 114 of file console.cc.

References FALSE, and putBusy.

Referenced by ConsoleWriteDone.

00115 {
00116     putBusy = FALSE;
00117     stats->numConsoleCharsWritten++;
00118     (*writeHandler)(handlerArg);
00119 }


Member Data Documentation

int Console::handlerArg [private]
 

Definition at line 66 of file console.h.

Referenced by Console.

char Console::incoming [private]
 

Definition at line 70 of file console.h.

Referenced by CheckCharAvail, Console, and GetChar.

bool Console::putBusy [private]
 

Definition at line 68 of file console.h.

Referenced by Console, PutChar, and WriteDone.

int Console::readFileNo [private]
 

Definition at line 60 of file console.h.

Referenced by CheckCharAvail, Console, and ~Console.

VoidFunctionPtr Console::readHandler [private]
 

Definition at line 64 of file console.h.

Referenced by Console.

int Console::writeFileNo [private]
 

Definition at line 61 of file console.h.

Referenced by Console, PutChar, and ~Console.

VoidFunctionPtr Console::writeHandler [private]
 

Definition at line 62 of file console.h.

Referenced by Console.


The documentation for this class was generated from the following files:
Generated on Mon Feb 10 09:54:53 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees