Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Deprecated/old_18mar_diff/nto/Device.hpp

Go to the documentation of this file.
00001 
00002 You must wrap around the Standard C function:
00003 
00004 open()
00005 close()
00006 read()
00007 write()
00008 select()
00009 
00010 raw/unraw
00011 
00012 You should check for errors and the class should
00013 know it's file descriptor, name, etc.
00014 
00015 // Device.hpp -- Interface for generic devices
00016 
00017 #ifndef  DEVICE_HPP
00018 #define  DEVICE_HPP
00019 
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include <string.h>
00023 #include <errno.h>
00024 
00025 #include <time.h>
00026 #include <fcntl.h>
00027 #include <unistd.h>
00028 
00029 
00030 #include <pthread.h>
00031 #include <sys/neutrino.h>
00032 
00033 #include <sys/stat.h>
00034 #include <sys/select.h>
00035 #include <sys/ioctl.h>
00036 #include <sys/types.h>
00037 #include <sys/uio.h>
00038 
00039 #include <sys/termio.h>
00040 
00041 
00042 #define CONSOLE  "/dev/con1"
00043 #define SERIAL   "/dev/ser1"
00044 
00045 class Device {
00046 public:
00047 
00048   // Constructor
00049   Device( const char* name = CONSOLE,
00050           int  flags  = O_RDWR,
00051           bool openit = true    );
00052 
00053   // Destructor
00054   virtual ~Device();
00055 
00056   void Open();   // open  the file, reopen if already opened.
00057   void Close();  // close the file
00058 
00059   // Access functions
00060   void Read(        void* buf, size_t sz );  // read wrapper
00061   void Write( const void* buf, size_t sz );  // write wrapper
00062 
00063   // Specific simple case of R/W
00064   inline char ReadChar();
00065   inline void WriteChar( char c );
00066 
00067   // Data available ?
00068   int  Select();
00069 
00070   // Mode setting functions
00071   void Raw();     // Raw mode
00072   void Cooked();  // Normal mode
00073 
00074   // Query functions
00075 
00076   inline const char* getName() const;
00077 
00078   inline bool isOpen()   const;   // Open/Close
00079   inline bool getMode()  const;   // Raw/Normal
00080   inline int  getFlags() const;   // Read, Write, RW ?
00081 
00082 private:
00083   // Disable these...
00084   Device( const Device& );
00085   const Device& operator=( const Device& );
00086 
00087 protected:
00088 
00089 int fd;              // File descriptor
00090 
00091 bool opened;         // State variables
00092 bool mode;
00093 
00094 int oflag;           // Open flags
00095 
00096 fd_set rfd;          // Select stuff
00097 struct timeval tv;
00098 
00099 char name[   20 ];   // Name of the device
00100 char buffer[ 80 ];   // Temp buffer
00101 
00102 };
00103 
00104 #endif
00105 
00106 > Can you please explain to me what Device class should be like?
00107 > Can you show me a clear sample
00108 > Device class like what should each function does in the class?
00109 
00110 
00111 class Keyboard : public Driver {
00112  // getch, getche, kbhit, kbd speed
00113 };
00114 
00115 class SerialPort : public Driver {
00116  // modem speed, termios stuff, 8N1, etc.
00117 };
00118 
00119 You need another class Chat or
00120 two other class SerialThread,
00121 ConsoleThread for Read blocking states...
00122 
00123 Sincerly,
00124 Fred.
00125 

Generated on Sun Oct 14 18:46:22 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001