*** empty log message ***
[h316.git] / pc-tools / ldc2 / src / tape_block.hh
index c1084e9e5c4bdb17c6825ffda63c4fe7875854c3..3022a6a46d64210ec42df912de98e10ef730a5f9 100644 (file)
@@ -1,8 +1,5 @@
-#ifndef TAPE_BLOCK_H
-#define TAPE_BLOCK_H
-
-#include <string>
-#include <vector>
+#ifndef TAPE_BLOCK_HH
+#define TAPE_BLOCK_HH
 
 using namespace std;
 
@@ -13,37 +10,79 @@ 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();
@@ -56,11 +95,11 @@ public: // methods
                                  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,
@@ -70,10 +109,9 @@ private:   // methods
   
   int init_words(void);
   int test_checksum(); 
-
+  
 protected: // members
   int block_type;             //!< Type of this block.
-  tb_state_t init_state;      //!< Initialisation state.
   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.
@@ -82,5 +120,4 @@ protected: // members
   int poolsize;               //!< Amount of data malloc'ed 
 }; // class tape_block
 
-
 #endif