X-Git-Url: http://gitweb.hachti.de/?a=blobdiff_plain;f=pc-tools%2Fldc2%2Fsrc%2Ftape_block.hh;h=64f13fd1ba0920831b55992e54612cbdc36f169f;hb=7ced2dbeb1a104912fbdd041ce18b0e29a72d893;hp=8c1231f389a3cda158e683b4443577887139564b;hpb=97b26985c0190e2fded0f098819a23e892b381f0;p=h316.git diff --git a/pc-tools/ldc2/src/tape_block.hh b/pc-tools/ldc2/src/tape_block.hh index 8c1231f..64f13fd 100644 --- a/pc-tools/ldc2/src/tape_block.hh +++ b/pc-tools/ldc2/src/tape_block.hh @@ -1,150 +1,147 @@ -#ifndef TAPE_BLOCK_H -#define TAPE_BLOCK_H +/****************************************************************************** + * + * LDC2 source code + * + * $Date: 2007/12/23 15:25:11 $ + * $Author: hachti $ + * + * $Log: tape_block.hh,v $ + * Revision 2.1 2007/12/23 15:25:11 hachti + * *** empty log message *** + * + * Revision 2.0 2007-03-26 01:00:40 hachti + * *** empty log message *** + * + * + ******************************************************************************/ + +#ifndef TAPE_BLOCK_HH +#define TAPE_BLOCK_HH +using namespace std; /*! - *\brief Tape data block base class + *\brief Tape data block base class. * * This class represents a Honeywell paper tape block. * That may be some kind of data block or a end of tape mark. */ class tape_block{ - + public: // types - - /*! - * The block's initialisation state - */ - typedef enum { - TBS_OK, //!< Block successfully initialised - TBS_EOF_LEGAL, //!< Legal EOF while initialising - TBS_EOF_ILLEGAL, //!< Illegal EOF while initialising - TBS_CHECKSUM, //!< Checksum error - TBS_IOERR, //!< I/O-Error while reading - TBS_DEFAULT //!< Block not initialised. - } tb_state_t; - + /*! - * Tape block types + * Tape block types. */ typedef enum { TBT_DATA=0x10, //!< Data block TBT_EOT, //!< End of tape block - TBT_DISCARD //!< Invalid block, check block_type + TBT_BROKEN, //!< A broken block } tb_type_t; - -protected: // methods - /*! - *\brief Protected default constructor - */ - tape_block(); - -public: // methods - - tape_block(tape_block &); - - /*! - *\brief Read-in constructor for file descriptor - * - * This constructor is used to read in the block's data via a file - * descriptor.\\ - * This is done in the following way:\\ - * - input_start() is called.\\ - * - Data is read from fd. Stops on end of file or end of block - * or IO error. On EOF or IO error input_stop() is NOT called.\\ - * - If there was no IO error the block's checksum is calculated - * and checked.\ - * - The block's type field is initialised.\\ - * - input_stop() is called.\\ - *\param fd_p A pointer to the device descriptor where - * the data is taken from \\ - *\param input_stop A pointer to a function called at the end of input\\ - *\param input_start A pointer to a function called at the beginning - * of input\\ - *\param start_stop_arg A pointer passed to input_start and input_stop(). - */ - tape_block (int fd_p, - void(*input_start)(void *)=0, - void (*input_stop)(void *)=0, - void * start_stop_arg=0 - ); - + /*! - * The virtual destructor + *\brief Local base class for exceptions. */ - virtual ~tape_block(); - + class exception { + protected: + exception(); + public: + virtual ~exception(); + tape_block * get_block(); + protected: + tape_block * m_broken_block; + }; + /*! - *\brief Query the block's state. - * - * If the state is not TBS_OK, the block must be discarded. - *\return The block's initialisation state + *\brief Checksum error exception. */ - tb_state_t get_state(); - + class checksum_error_exception + : public exception { + public: + checksum_error_exception(tape_block * block); + }; + /*! - *\brief Get size of the internal raw data buffer - *\return The size of the internal raw data buffer + *\brief EOF while reading block exception. */ - int get_raw_size(); - + class eof_illegal_exception + : public exception { + public: + eof_illegal_exception(tape_block * block); + }; + /*! - *\brief Access internal raw data buffer - * - * The raw data buffer contains all block data except the \\ - * block start delimiter and block end delimiter. - *\return Pointer to internal raw data buffer of the block + *\brief EOF after reading block exception. */ - unsigned char * get_raw_data(); - - /* - *\brief Determine the block's type - * - * This routine returns the block's type.\\ - *\retval TBT_DATA if it's a data block - *\retval TBT_EOT if it's an end of tape mark - *\retval TBR_DISCARD if the block is unusable - * - *\note This function is virtual. That means that if the tape block in - * question is of the subtype data_block which overwrites this method, - * it will return the block type contained in the upper 4 bits of the - * first data word! Try to avoid testing for TBT_DATA. - */ - virtual int get_type(); + class eof_legal_exception + : public exception { + public: + eof_legal_exception(int bytes_consumed); + int get_consumed(); + private: + int bytes_consumed; + tape_block * get_block(); + }; /*! - *\brief Determine the block's subtype - * - * Some data block types have a subtype. This can be determined this way. - *\return Block subtype if the block object is of a suitable subclass + *\brief IO error exception. */ + class io_error_exception + : exception { + public: + io_error_exception(); + private: + tape_block * get_block(); + }; + +public: // methods + virtual ~tape_block(); + + tape_block(tape_block &); + void operator=(tape_block &); + + virtual int get_type(); virtual int get_subtype(); - + virtual vector get_description(); + int get_raw_size(); + int get_discarded_bytes(); + unsigned char * get_raw_data(); + virtual int dump_to_fd(int fd); + virtual bool is_endblock(); + virtual vector get_exported_symbols(); + virtual vector get_called_symbols(); + virtual vector dump_contents(); + virtual bool has_known_type(); + + static tape_block * gen_from_fd(int fd, + void(*input_start)(void *)=0, + void (*input_stop)(void *)=0, + void * start_stop_arg=0 + ); + +protected: // methods + tape_block(); + string get_typestring(); + private: // methods - /*! - *\brief Initialize word representation of data - *\retval 0 on success - *\retval 1 on error - */ + tape_block (int fd_p, + void(*input_start)(void *)=0, + void (*input_stop)(void *)=0, + void * start_stop_arg=0 + ); + int init_words(void); - - /*! - *\brief Calculate and check checksum - *\retval 0 on success - *\retval 1 on error - */ int test_checksum(); - + protected: // members - int block_type; //!< type of this block - tb_state_t init_state; //!< Initialisation state - int data_read; //!< Total data consumption during intialisation - unsigned char * raw_data; //!< Raw block data in bytes - int raw_size; //!< Size of the raw data - unsigned short * word_data; //!< Data organized in machine words - int word_size; //!< Size of the blocks in machine words - -}; // tape_block - + int block_type; //!< Type of this block. + bool m_has_known_type; //!< Block is of a documented type. + int discarded_bytes; //!< Amount of bytes discarded before beginning. + unsigned char * raw_data; //!< Raw block data in bytes. + int raw_size; //!< Size of the raw data. + unsigned short * word_data; //!< Data organized in machine words. + int word_size; //!< Size of the blocks in machine words. + int poolsize; //!< Amount of data malloc'ed +}; // class tape_block #endif