connectionDevice.h

Go to the documentation of this file.
00001 #ifndef CONNECTION_DEVICE_H
00002 #define CONNECTION_DEVICE_H
00003 
00013 #include "ringBufferTemplate.h"
00014 #include <exception>
00015 #include <string>
00016 
00017 
00021 class ConnectionDevice {
00022   std::string device_name;
00023   long baudrate_value;
00024 
00033   virtual int raw_connect(const char* device, long baudrate) = 0;
00034 
00038   virtual void raw_disconnect(void) = 0;
00039   virtual int raw_setBaudrate(long baudrate) = 0;
00040 
00049   virtual int raw_send(const char* data, int len) = 0;
00050   virtual void raw_flush(void) = 0;
00051   virtual void raw_check(int size, long timeout = 0) = 0;
00052   void check(int size, long timeout = 0);
00053   ConnectionDevice(const ConnectionDevice& rhs);
00054 
00055 protected:
00056   enum { BufferSize = 4096 };
00057   RingBuffer<char> *recv_buffer; 
00059 public:
00060   enum {
00061     NotConnected = -2,
00062     DeviceOpenFail = -3,
00063     InvalidBaudrate = -4,
00064     BaudrateAdjustFail = -5,
00065     RecvTimeout = -6,
00066     LibraryInitFail = -7,
00067     RetryFail = -8,
00068     FailCheckVersion = -9,
00069   };
00070 
00076   ConnectionDevice(int buffer_size = BufferSize-1);
00077   virtual ~ConnectionDevice(void);
00078 
00082   virtual const char* what(void) = 0;
00083 
00092   int connect(const char* device, long baudrate);
00093 
00097   void disconnect(void);
00098 
00106   int setBaudrate(long baudrate);
00107 
00114   virtual bool isConnected(void) = 0;
00115 
00119   void flush(void);
00120 
00129   int send(const char* data, int len);
00130 
00140   virtual int recv(char* data, int maxlen, long timeout = 0);
00141 
00152   int copy(char *data, int maxlen);
00153 
00159   int size(void);
00160 
00166   int capacity(void);
00167 
00173   const char* getDevice(void);
00174 
00180   long getBaudrate(void);
00181 };
00182 
00183 
00187 class ConnectionDevice_Exception : public std::exception {
00188   std::string error_message;
00189 
00190 public:
00196   ConnectionDevice_Exception(const char* message) : error_message(message) {}
00197   virtual ~ConnectionDevice_Exception(void) throw () {}
00198 
00202   virtual const char* what(void) const throw() {
00203     return error_message.c_str();
00204   }
00205 };
00206 
00207 #endif /* !CONNECTION_DEVICE_H */
00208 

Generated on Mon Apr 13 22:52:05 2009 by  doxygen 1.5.7.1