From: Mikko L. <laz...@us...> - 2004-06-13 10:29:08
|
Update of /cvsroot/rtk/rtk/rtk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14903 Modified Files: Buffer.h File.h IO.h debug.h error.h error_codes.h Log Message: - Some IO changes - Use ERROR things in File - Buffer is now IO Index: error_codes.h =================================================================== RCS file: /cvsroot/rtk/rtk/rtk/error_codes.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** error_codes.h 18 Jan 2004 20:17:07 -0000 1.1 --- error_codes.h 13 Jun 2004 10:28:57 -0000 1.2 *************** *** 3,9 **** #else ! ERROR_CODE0(UNKNOWN) ! ERROR_CODE1(OUT_OF_MEMORY, RunTime) ! ERROR_CODE1(FILE_NOT_FOUND, IO) #endif --- 3,17 ---- #else ! ERROR_CODE(UNKNOWN, RunTime) ! ERROR_CODE(OPERATION_FAILED, RunTime) ! ERROR_CODE(NOT_IMPLEMENTED, RunTime) ! ERROR_CODE(OUT_OF_MEMORY, RunTime) ! ERROR_CODE(FILE_NOT_FOUND, IO) ! ERROR_CODE(ALREADY_OPEN, IO) ! ERROR_CODE(DEVICE_NOT_OPEN, IO) ! ERROR_CODE(DEVICE_WRITE_PROTECTED, IO) ! ERROR_CODE(DEVICE_READ_PROTECTED, IO) ! ERROR_CODE(CANNOT_CLOSE_EXTERNAL, IO) ! ERROR_CODE(ACCESS_DENIED, IO) #endif Index: debug.h =================================================================== RCS file: /cvsroot/rtk/rtk/rtk/debug.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** debug.h 28 Feb 2004 07:39:44 -0000 1.3 --- debug.h 13 Jun 2004 10:28:57 -0000 1.4 *************** *** 15,19 **** // Define macros for each package/module/section ! #define D_CORE 0x00000001 #define D_ALL 0xffffffff --- 15,20 ---- // Define macros for each package/module/section ! #define D_CORE (1<<1) ! #define D_IO (1<<2) #define D_ALL 0xffffffff Index: File.h =================================================================== RCS file: /cvsroot/rtk/rtk/rtk/File.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** File.h 13 Jun 2004 07:51:25 -0000 1.4 --- File.h 13 Jun 2004 10:28:57 -0000 1.5 *************** *** 121,132 **** * Set new access mode. * If file is already open, it must be re-opened ! * to make this take effect. */ ! void SetMode(int mode); /** * Return current IO access. */ ! int GetMode() const { return _mode; } /** --- 121,132 ---- * Set new access mode. * If file is already open, it must be re-opened ! * to make new mode take effect. */ ! void SetMode(uint mode); /** * Return current IO access. */ ! uint GetMode() const { return _mode; } /** *************** *** 134,147 **** * Returns true on success. */ ! virtual bool Open(); /** * Try to close file. ! * Returns true on success. */ ! virtual bool Close(); ! ! /** Return true if file is open. */ ! virtual bool IsOpen() const; /** --- 134,144 ---- * Returns true on success. */ ! virtual int Open(); /** * Try to close file. ! * Returns SUCCESS on success. */ ! virtual int Close(); /** *************** *** 151,155 **** * @param buffer_len Size of input buffer */ ! virtual int Read(void *buffer, int buffer_len); /** --- 148,152 ---- * @param buffer_len Size of input buffer */ ! virtual long Read(void *buffer, long buffer_len); /** *************** *** 159,163 **** * @param buffer_len Size of input buffer */ ! virtual int Write(void *buffer, int buffer_len); /** --- 156,160 ---- * @param buffer_len Size of input buffer */ ! virtual long Write(void *buffer, long buffer_len); /** *************** *** 173,176 **** --- 170,176 ---- virtual long Tell(); + /** Return size of the IO device. Return RTK error code if failed. */ + virtual long GetSize(); + /** * Return true, passed to end-of-file. *************** *** 182,186 **** * Returns 0 on succes, -1 on error */ ! virtual bool Flush(); /** --- 182,186 ---- * Returns 0 on succes, -1 on error */ ! virtual int Flush(); /** *************** *** 193,197 **** private: String _filename; ! int _mode; void *_handle; bool _eos; --- 193,197 ---- private: String _filename; ! uint _mode; void *_handle; bool _eos; Index: error.h =================================================================== RCS file: /cvsroot/rtk/rtk/rtk/error.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** error.h 18 Jan 2004 20:17:07 -0000 1.1 --- error.h 13 Jun 2004 10:28:57 -0000 1.2 *************** *** 32,52 **** //////////////////////////////////////////////////////////////////////////////// ! #define ERROR_CODE0(name) EC_ ## name, ! #define ERROR_CODE1(name,type) EC_ ## name, enum { ! EC_NO_ERROR = 0, ! #include "error_codes.h" EC_LAST_ERROR }; ! #undef ERROR_CODE0 ! #undef ERROR_CODE1 // if not using exceptions, errors are returned as negative integers #define ERROR_RET long // a macro for returning a success value #define RETURN_SUCCESS return (0) // a macro for returning an error #define ERROR_RETURN(name) return -EC_ ## name #undef INC_ERROR_CODES --- 32,54 ---- //////////////////////////////////////////////////////////////////////////////// ! #define ERROR_CODE(name,type) EC_ ## name, enum { ! EC_SUCCESS = 0, ! # include "error_codes.h" EC_LAST_ERROR }; ! #undef ERROR_CODE // if not using exceptions, errors are returned as negative integers #define ERROR_RET long + // a macro for returning a success value #define RETURN_SUCCESS return (0) + // a macro for returning an error #define ERROR_RETURN(name) return -EC_ ## name + #define SUCCESS(val) ((val) > -1) + #undef INC_ERROR_CODES Index: IO.h =================================================================== RCS file: /cvsroot/rtk/rtk/rtk/IO.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** IO.h 13 Jun 2004 07:51:25 -0000 1.9 --- IO.h 13 Jun 2004 10:28:57 -0000 1.10 *************** *** 45,48 **** --- 45,49 ---- #include "rtkdef.h" + #include "error.h" #include "Mutex.h" *************** *** 62,68 **** */ enum AccessFlags { ! CAN_READ = 1, ///< IO has read access. ! CAN_WRITE = 2, ///< IO has write access. ! CAN_SEEK = 4 ///< IO is seekable. }; --- 63,71 ---- */ enum AccessFlags { ! CAN_READ = (1<<1), ///< IO has read access. ! CAN_WRITE = (1<<2), ///< IO has write access. ! CAN_SEEK = (1<<3), ///< IO is seekable. ! ! OPENED = (1<<4) ///< IO device is opened (internal) }; *************** *** 89,120 **** /** Return true if device has read permission */ ! bool CanRead() const { return TestFlag(CAN_READ, _flags); } /** Return true if device has write permission */ ! bool CanWrite() const { return TestFlag(CAN_WRITE, _flags); } /** Return true if device can seek in stream */ ! bool CanSeek() const { return TestFlag(CAN_SEEK, _flags); } /** Return true if IO stream is open. */ ! virtual bool IsOpen() const { return false; } ! /** READ, Return -1 on error */ ! virtual int Read(void *buffer, int buffer_len) { return -1; } ! /** WRITE, Return -1 on error */ ! virtual int Write(void *buffer, int buffer_len) { return -1; } ! /** SEEK, Return -1 on error */ ! virtual long Seek(long pos, int method=BEGIN) { return -1; } ! /** Current position in stream. Return -1 on error */ ! virtual long Tell() { return -1; } ! /** Is end-of-stream. Return -1 on error */ ! virtual bool IsEos() { return true; } /** Flushes the buffer. Return -1 on error */ ! virtual bool Flush() { return 0; } /** Sets Mutex object for IO */ --- 92,138 ---- /** Return true if device has read permission */ ! bool CanRead() const { return TestFlag(CAN_READ, _flags); } /** Return true if device has write permission */ ! bool CanWrite() const { return TestFlag(CAN_WRITE, _flags); } /** Return true if device can seek in stream */ ! bool CanSeek() const { return TestFlag(CAN_SEEK, _flags); } /** Return true if IO stream is open. */ ! bool IsOpen() const { return (_flags & OPENED) == OPENED; } ! /** ! * Try to open IO device. Return ALREADY_OPEN, if device is already open. ! * Returns SUCCESS on success. ! */ ! virtual int Open() = 0; ! /** ! * Try to close IO device. ! * Returns SUCCESS on success. ! */ ! virtual int Close() = 0; ! /** READ, Return RTK error code if failed. */ ! virtual long Read(void *buffer, long buffer_len) { ERROR_RETURN(NOT_IMPLEMENTED); } ! /** WRITE, Return RTK error code if failed. */ ! virtual long Write(void *buffer, long buffer_len) { ERROR_RETURN(NOT_IMPLEMENTED); } ! /** SEEK, Return RTK error code if failed. */ ! virtual long Seek(long pos, int method=BEGIN) { ERROR_RETURN(NOT_IMPLEMENTED); } ! ! /** Current position in stream. Return RTK error code if failed. */ ! virtual long Tell() { ERROR_RETURN(NOT_IMPLEMENTED); } ! ! /** Return size of the IO device. Return RTK error code if failed. */ ! virtual long GetSize() { ERROR_RETURN(NOT_IMPLEMENTED); } ! ! /** Is end-of-stream. */ ! virtual bool IsEos() = 0; /** Flushes the buffer. Return -1 on error */ ! virtual int Flush() { ERROR_RETURN(NOT_IMPLEMENTED); } /** Sets Mutex object for IO */ *************** *** 122,130 **** /** Gets Mutex object from IO */ ! Mutex* GetMutex() const { return _mutex; } protected: IO() : _flags(0), _mutex(0) { } /** Set access flags. */ void flags(uint f) { _flags = f; } --- 140,151 ---- /** Gets Mutex object from IO */ ! Mutex* GetMutex() { return _mutex; } protected: IO() : _flags(0), _mutex(0) { } + void SetOpen() { _flags |= OPENED; } + void ClearOpen() { _flags &= ~OPENED; } + /** Set access flags. */ void flags(uint f) { _flags = f; } *************** *** 137,141 **** uint _flags; ! private: Mutex* _mutex; /// Mutex - by default not set --- 158,162 ---- uint _flags; ! private: Mutex* _mutex; /// Mutex - by default not set Index: Buffer.h =================================================================== RCS file: /cvsroot/rtk/rtk/rtk/Buffer.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Buffer.h 12 Jun 2004 22:48:29 -0000 1.9 --- Buffer.h 13 Jun 2004 10:28:57 -0000 1.10 *************** *** 52,124 **** #include "rtkdef.h" ! namespace Rtk { ! /** Dynamic Buffer implementation. ! * @author de...@rt... */ ! class RTK_API Buffer ! { ! uchar* _data; /// Internal pointer to Buffer memory-block. ! ulong _allocated; /// Size of Buffer object in bytes. ! ulong _size; /// Number of data-bytes in Buffer object. ! ! /** ! * Allocates arg_num bytes and returns pointer to new memory block. ! * @returns uchar* pointer to new memory block. ! */ ! uchar* Allocate(ulong arg_num); ! ! public: ! /** ! * Default Buffer constructor. ! */ ! Buffer(): _size(0), _data(0), _allocated(0) { } ! ! virtual ~Buffer(); ! ! /** ! * Clear the buffer and free all it's resources. ! */ ! void Clear(); ! /** ! * Returns pointer to internal data memory-block. ! * @returns pointer to the data buffer. ! * @note return value value may be NULL, if buffer is not allocated yet ! */ ! const uchar* Data() const { return _data; } ! ! /** Returns current number of written data bytes in Buffer. ! * @returns ulong current size of Buffer. ! */ ! ulong GetSize() const { return _size; } ! ! /** Returns number of bytes allocated by Buffer currently ! * @returns ulong current internal size of Buffer. ! */ ! ulong GetAllocated() const { return _allocated; } ! ! /** ! * Resizes Buffer. ! * @returns int 0 if everything OK. ! */ ! int SetSize(ulong arg_size); ! ! /** Writes one single byte to the Buffer object ! * @param c uchar Byte to be written. ! */ ! void Write(uchar c) { *Allocate(1) = c; ++_size; } ! ! /** ! * Writes arbitrary number of bytes to the Buffer object. ! */ ! void Write(const uchar* arg_byte_array, ulong arg_num); ! void Fill(uchar arg_char); - // This should be removed after testing... - void From(IO* arg_io); - void To(IO* arg_io); - }; // Buffer }; // Rtk namespace --- 52,139 ---- #include "rtkdef.h" ! namespace Rtk { ! ! /** Dynamic Buffer implementation. ! * @author de...@rt... ! */ ! class RTK_API Buffer : public IO { ! public: ! /** ! * Default Buffer constructor. */ ! Buffer(): _size(0), _data(0), _allocated(0), _pos(0) { } ! virtual ~Buffer(); ! ! virtual int Open() { SetOpen(); RETURN_SUCCESS; } ! virtual int Close() { ClearOpen(); RETURN_SUCCESS; } ! ! /** READ, Return RTK error code if failed. */ ! virtual long Read(void *buffer, long buffer_len); ! ! /** WRITE, Return RTK error code if failed. */ ! virtual long Write(void *buffer, long buffer_len); ! ! /** SEEK, Return RTK error code if failed. */ ! virtual long Seek(long pos, int method=BEGIN); ! ! /** Current position in stream. Return RTK error code if failed. */ ! virtual long Tell(); ! ! /** Return size of the IO device. Return RTK error code if failed. */ ! virtual long GetSize() { return _size; } ! ! /** Is end-of-stream. */ ! virtual bool IsEos() { return (_pos == _size); } ! ! /** ! * Clear the buffer and free all it's resources. ! */ ! void Clear(); ! ! /** ! * Returns pointer to internal data memory-block. ! * @returns pointer to the data buffer. ! * @note return value value may be NULL, if buffer is not allocated yet ! */ ! const uchar* Data() const { return _data; } ! ! /** Returns number of bytes allocated by Buffer currently ! * @returns ulong current internal size of Buffer. ! */ ! ulong GetAllocated() const { return _allocated; } ! ! /** ! * Resizes Buffer. ! * @returns int 0 if everything OK. ! */ ! int SetSize(ulong arg_size); ! ! /** Writes one single byte to the Buffer object ! * @param c uchar Byte to be written. ! */ ! void Write(uchar c) { *Allocate(1) = c; ++_size; } ! ! void Fill(uchar arg_char); ! ! // This should be removed after testing... ! void From(IO* arg_io); ! void To(IO* arg_io); ! ! private: ! uchar* _data; /// Internal pointer to Buffer memory-block. ! ulong _allocated; /// Size of Buffer object in bytes. ! ulong _size; /// Number of data-bytes in Buffer object. ! ulong _pos; ! /** ! * Allocates arg_num bytes and returns pointer to new memory block. ! * @returns uchar* pointer to new memory block. ! */ ! uchar* Allocate(ulong arg_num); ! ! }; // Buffer }; // Rtk namespace |