#if !defined SERIAL_H
#define SERIAL_H

#include <iostream.h>

class ComBuffer;	// forward declaration

// This class represents everything needed for the 
// template parameter.  It has a default constructor,
// open, close, read, write, seek, and status.
class SerialStream {
public:
// Default constructor.  Initialize an unopened stream
    SerialStream() 
        : port(-1)
    { 
    }
// Destructor.  calls close.
    ~SerialStream()
    {
        close();
    }
// The open function sets up the default serial port
// parameters, and hook up the interrupts.  The name
// is check for "COM1" and "COM2".  mode and prot are
// ignored.
    int open(const char *name, int mode, int prot);
// Read fills buf with len characters from the
// circular buffer.  This class and any class that 
// cannot seek should be unbuffered, so read typically
// asks for one character at a time.
    int read(char *buf, size_t len);
// Write sends the characters in buf to the port.
    int write(char *buf, size_t len);
// Seek is a dummy function and always retruns error.
    long seek(long, ios::seek_dir) { return -1; }
// close set the port number to -1 for open testing.
    int close();
// This function is the status function.
    operator const void *() { return port == -1 ? 0 : 
                                            this; }
private:
    int port;
    ComBuffer *buffPtr;
};

#endif

