d2ca3df4c0e90a65bf62845e65bff59b9341c17b
[h316.git] / pc-tools / ldc2 / src / tape_block.hh
1 #ifndef TAPE_BLOCK_H
2 #define TAPE_BLOCK_H
3
4 #include <string>
5 #include <vector>
6
7 using namespace std;
8
9 /*!
10 *\brief Tape data block base class.
11 *
12 * This class represents a Honeywell paper tape block.
13 * That may be some kind of data block or a end of tape mark.
14 */
15 class tape_block{
16
17 public: // types
18
19 /*!
20 *\brief Initialisation state.
21 */
22 typedef enum {
23 TBS_OK, //!< Block successfully initialised
24 TBS_EOF_LEGAL, //!< Legal EOF while initialising
25 TBS_EOF_ILLEGAL, //!< Illegal EOF while initialising
26 TBS_CHECKSUM, //!< Checksum error
27 TBS_IOERR, //!< I/O-Error while reading
28 TBS_DEFAULT //!< Block not initialised.
29 } tb_state_t;
30
31 /*!
32 * Tape block types.
33 */
34 typedef enum {
35 TBT_DATA=0x10, //!< Data block
36 TBT_EOT, //!< End of tape block
37 TBT_DISCARD //!< Invalid block, check block_type
38 } tb_type_t;
39
40 public: // methods
41 virtual ~tape_block();
42
43 tape_block(tape_block &);
44 void operator=(tape_block &);
45
46 tb_state_t get_state();
47 virtual int get_type();
48 virtual int get_subtype();
49 virtual vector<string> get_description();
50 int get_raw_size();
51 unsigned char * get_raw_data();
52
53 static tape_block * gen_from_fd(int fd,
54 void(*input_start)(void *)=0,
55 void (*input_stop)(void *)=0,
56 void * start_stop_arg=0
57 );
58
59 protected: // methods
60 tape_block();
61 string get_typestring();
62
63 private: // methods
64 tape_block (int fd_p,
65 void(*input_start)(void *)=0,
66 void (*input_stop)(void *)=0,
67 void * start_stop_arg=0
68 );
69
70 int init_words(void);
71 int test_checksum();
72
73 protected: // members
74 int block_type; //!< Type of this block.
75 tb_state_t init_state; //!< Initialisation state.
76 int data_read; //!< Total data consumption during intialisation.
77 unsigned char * raw_data; //!< Raw block data in bytes.
78 int raw_size; //!< Size of the raw data.
79 unsigned short * word_data; //!< Data organized in machine words.
80 int word_size; //!< Size of the blocks in machine words.
81 }; // class tape_block
82
83
84 #endif