-#ifndef TAPE_BLOCK_H
-#define TAPE_BLOCK_H
-
-#include <string>
-#include <vector>
+/******************************************************************************
+ *
+ * LDC2 source code
+ *
+ * $Date: 2007/03/26 01:00:40 $
+ * $Author: hachti $
+ *
+ * $Log: tape_block.hh,v $
+ * Revision 2.0 2007/03/26 01:00:40 hachti
+ * *** empty log message ***
+ *
+ *
+ ******************************************************************************/
+
+#ifndef TAPE_BLOCK_HH
+#define TAPE_BLOCK_HH
using namespace std;
* That may be some kind of data block or a end of tape mark.
*/
class tape_block{
-
+
public: // types
-
- /*!
- *\brief 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.
*/
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;
-
+
+ /*!
+ *\brief Local base class for exceptions.
+ */
+ class exception {
+ protected:
+ exception();
+ public:
+ virtual ~exception();
+ tape_block * get_block();
+ protected:
+ tape_block * m_broken_block;
+ };
+
+ /*!
+ *\brief Checksum error exception.
+ */
+ class checksum_error_exception
+ : public exception {
+ public:
+ checksum_error_exception(tape_block * block);
+ };
+
+ /*!
+ *\brief EOF while reading block exception.
+ */
+ class eof_illegal_exception
+ : public exception {
+ public:
+ eof_illegal_exception(tape_block * block);
+ };
+
+ /*!
+ *\brief EOF after reading block exception.
+ */
+ 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 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 &);
-
- tb_state_t get_state();
+
virtual int get_type();
virtual int get_subtype();
virtual vector<string> 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<string> get_exported_symbols();
+ virtual vector<string> get_called_symbols();
+ 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
tape_block (int fd_p,
void(*input_start)(void *)=0,
int init_words(void);
int test_checksum();
-
+
protected: // members
int block_type; //!< Type of this block.
- tb_state_t init_state; //!< Initialisation state.
+ 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.
int poolsize; //!< Amount of data malloc'ed
}; // class tape_block
-
#endif